23 #include "world_builder/config.h" 42 #define OMPI_SKIP_MPICXX 1 43 #define MPICH_SKIP_MPICXX 48 #ifdef WB_USE_FP_EXCEPTIONS 55 using namespace Utilities;
57 World::World(std::string filename,
bool has_output_dir,
const std::string &output_dir,
unsigned long random_number_seed,
const bool limit_debug_consistency_checks_)
60 surface_coord_conversions(
invalid),
62 random_number_engine(random_number_seed),
63 limit_debug_consistency_checks(limit_debug_consistency_checks_)
67 #ifdef WB_USE_FP_EXCEPTIONS 70 feclearexcept(FE_DIVBYZERO|FE_INVALID);
73 feenableexcept(FE_DIVBYZERO|FE_INVALID);
79 MPI_Initialized(&mpi_initialized);
80 if (mpi_initialized == 0)
87 MPI_Comm_rank(MPI_COMM_WORLD, &
MPI_RANK);
88 MPI_Comm_size(MPI_COMM_WORLD, &
MPI_SIZE);
118 "The potential temperature of the mantle at the surface in Kelvin.");
120 "The temperature at the surface in Kelvin.");
122 "Force the provided surface temperature to be set at the surface");
124 "The thermal expansion coefficient in $K^{-1}$.");
126 "The specific heat in $J kg^{-1} K^{-1}.$");
128 "The thermal diffusivity in $m^{2} s^{-1}$.");
131 "This enforces a maximum distance (in degree for spherical coordinates " 132 "or meter in cartesian coordinates) between coordinates in the model. " 133 "If the distance is larger, extra points are added by interpolation. " 134 "Requires interpolation to be not 'none'.");
137 "What type of interpolation should be used to enforce the minimum points per " 138 "distance parameter. Options are none, linear, monotone spline and " 139 "continuous monotone spline interpolation.");
149 "This allows the input of a preferred random number seed to generate random numbers." 150 " If no input is given, this value is -1 and triggers the use of default seed = 1.");
167 WBAssertThrow((prm.
get<std::string>(
"version") == Version::MAJOR +
"." + Version::MINOR),
168 "The major and minor version combination for which is input file was written " 169 "is not the same as the version of the World Builder you are running. This means " 170 "That there may have been incompatible changes made between the versions. \n\n" 171 "Verify those changes and whether they affect your model. If this is not " 172 "the case, adjust the version number in the input file. \n\nThe provided version " 173 "number is \"" << prm.
get<std::string>(
"version") <<
"\", while the used world builder " 174 "has (major.minor) version \"" << Version::MAJOR <<
"." << Version::MINOR <<
"\". " 175 "If you created this file from scratch, fill set the version number to \"" <<
176 Version::MAJOR <<
"." << Version::MINOR <<
"\" to continue. If you got the world builder " 177 "file from somewhere, make sure that the output is what you expect it to be, because " 178 "backwards incompatible changes may have been made to the code.");
199 const bool set_cross_section = prm.
check_entry(
"cross section");
203 if (set_cross_section)
206 const std::vector<Point<2> > cross_section_natural = prm.
get_vector<
Point<2> >(
"cross section");
208 WBAssertThrow(cross_section_natural.size() == 2,
"The cross section should contain two points, but it contains " 211 for (
const auto &it : cross_section_natural)
233 surface_temperature = prm.
get<
double>(
"surface temperature");
248 const int local_seed = prm.
get<
int>(
"random number seed");
259 for (
unsigned int i = 0; i < prm.
features.size(); ++i)
263 prm.
features[i]->parse_entries(prm);
276 unsigned int n_output_entries = 0;
282 n_output_entries += 1;
285 n_output_entries += 1;
289 n_output_entries +=
property[2]*10;
294 n_output_entries += 1;
299 n_output_entries += 3;
304 "Internal error: Unimplemented property provided. " <<
305 "Only temperature (1), composition (2), grains (3), tag (4) or velocity (5) are allowed. " 306 "Provided property number was: " << property[0]);
309 return n_output_entries;
317 const std::vector<std::array<unsigned int,3>> &
properties)
const 320 WBAssertThrow(
dim == 2,
"This function can only be called when the cross section " 321 "variable in the world builder file has been set. Dim is " 326 Point<2> point_natural(point[0], point[1],coordinate_system);
329 point_natural[1] = std::sqrt(point[0]*point[0]+point[1]*point[1]);
330 point_natural[0] = std::atan2(point[1],point[0]);
333 Point<3> coord_3d(coordinate_system);
336 coord_3d[0] = point_natural[1];
338 coord_3d[2] =
cross_section[0][1] + point_natural[0] * surface_coord_conversions[1];
343 coord_3d[1] =
cross_section[0][1] + point_natural[0] * surface_coord_conversions[1];
344 coord_3d[2] = point_natural[1];
351 unsigned int counter = 0;
381 vector[1] = results[counter+2];
383 results[counter+1] = results[counter+2];
384 results[counter+2] = 0;
391 "Internal error: Unimplemented property provided by internal process. " <<
392 "Only temperature (1), composition (2), grains (3), tag (4) or velocity (5) are allowed. " 393 "Provided property number was: " << property[0]);
405 const std::vector<std::array<unsigned int,3>> &
properties)
const 412 "Inconsistent input. Please check whether the radius in the spherical coordinates is consistent with the radius of the planet as defined " 413 <<
"in the program that uses the Geodynamic World Builder. This is a debug check in GWB and can be disabled by setting " 414 <<
"limit_debug_consistency_checks to true. " 416 <<
", point = " << point_[0] <<
" " << point_[1] <<
" " << point_[2]
417 <<
", radius-point.norm() = " << this->
parameters.
coordinate_system->max_model_depth()-sqrt(point_[0]*point_[0]+point_[1]*point_[1]+point_[2]*point_[2]));
422 std::vector<double> output;
423 std::vector<size_t> entry_in_output;
424 std::vector<std::array<unsigned int,3>> properties_local;
426 for (
unsigned int i_property = 0; i_property <
properties.size(); ++i_property)
433 entry_in_output.emplace_back(output.size());
440 entry_in_output.emplace_back(output.size());
443 properties_local.emplace_back(
properties[i_property]);
446 entry_in_output.emplace_back(output.size());
447 output.emplace_back(0.);
448 properties_local.emplace_back(
properties[i_property]);
452 entry_in_output.emplace_back(output.size());
453 const std::vector<double> tmp_vector(
properties[i_property][2]*10,0.);
454 output.insert(output.end(), tmp_vector.begin(), tmp_vector.end());
455 properties_local.emplace_back(
properties[i_property]);
460 entry_in_output.emplace_back(output.size());
461 output.emplace_back(-1);
462 properties_local.emplace_back(
properties[i_property]);
467 entry_in_output.emplace_back(output.size());
468 output.emplace_back(0);
469 output.emplace_back(0);
470 output.emplace_back(0);
471 properties_local.emplace_back(
properties[i_property]);
476 "Internal error: Unimplemented property provided. " <<
477 "Only temperature (1), composition (2), grains (3), tag (4) or velocity (5) are allowed. " 478 "Provided property number was: " <<
properties[i_property][0]);
483 it->properties(point, natural_coordinate, depth, properties_local, gravity_norm, entry_in_output, output);
491 const double depth)
const 493 return properties(point, depth, {{{1,0,0}}})[0];
501 return properties(point, depth, {{{1,0,0}}})[0];
506 const double depth)
const 508 return properties(point, depth, {{{1,0,0}}})[0];
516 return properties(point, depth, {{{1,0,0}}})[0];
522 const unsigned int composition_number)
const 524 return properties(point, depth, {{{2,composition_number,0}}})[0];
530 const unsigned int composition_number)
const 532 return properties(point, depth, {{{2,composition_number,0}}})[0];
540 const unsigned int composition_number,
541 size_t number_of_grains)
const 543 return WorldBuilder::grains(
properties(point, depth, {{{3,composition_number,
static_cast<unsigned int>(number_of_grains)}}}),
static_cast<unsigned int>(number_of_grains),0);
549 const unsigned int composition_number,
550 size_t number_of_grains)
const 552 return WorldBuilder::grains(
properties(point, depth, {{{3,composition_number,
static_cast<unsigned int>(number_of_grains)}}}),
static_cast<unsigned int>(number_of_grains),0);
564 const std::string &name)
const 571 "Inconsistent input. Please check whether the radius in the spherical coordinates is consistent with the radius of the planet as defined " 572 <<
"in the program that uses the Geodynamic World Builder. This is a debug check in GWB and can be disabled by setting " 573 <<
"limit_debug_consistency_checks to true. " 575 <<
", point = " << point_[0] <<
" " << point_[1] <<
" " << point_[2]
576 <<
", radius-point.norm() = " << this->
parameters.
coordinate_system->max_model_depth()-sqrt(point_[0]*point_[0]+point_[1]*point_[1]+point_[2]*point_[2]));
583 if (it->get_name() == name)
585 plane_distances = it->distance_to_feature_plane(point, natural_coordinate, depth);
589 return plane_distances;
bool check_entry(const std::string &name) const
void parse_entries(Parameters &prm)
Objects::PlaneDistances distance_to_plane(const std::array< double, 3 > &point, const double depth, const std::string &name) const
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
double composition(const std::array< double, 2 > &point, const double depth, const unsigned int composition_number) const
double maximum_distance_between_coordinates
bool approx(double a, double b, double error_factor=1e4)
void enter_subsection(const std::string &name)
std::unique_ptr< WorldBuilder::GravityModel::Interface > gravity_model
double potential_mantle_temperature
std::mt19937 & get_random_number_engine()
bool limit_debug_consistency_checks
std::vector< double > properties(const std::array< double, 2 > &point, const double depth, const std::vector< std::array< unsigned int, 3 >> &properties) const
std::unique_ptr< T > get_unique_pointer(const std::string &name)
Point< 2 > surface_coord_conversions
static void declare_entries(Parameters &prm)
void initialize(std::string &filename, bool has_output_dir=false, const std::string &output_dir="")
World(std::string filename, bool has_output_dir=false, const std::string &output_dir="", unsigned long random_number_seed=1, const bool limit_debug_consistency_checks=true)
const std::array< double, dim > & get_array() const
unsigned int properties_output_size(const std::vector< std::array< unsigned int, 3 >> &properties) const
double temperature(const std::array< double, 2 > &point, const double depth) const
#define WBAssert(condition, message)
WorldBuilder::grains grains(const std::array< double, 2 > &point, const double depth, const unsigned int composition_number, size_t number_of_grains) const
std::mt19937 random_number_engine
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
double thermal_diffusivity
double surface_temperature
#define WBAssertThrow(condition, message)
bool get_unique_pointers(const std::string &name, std::vector< std::unique_ptr< T > > &vector)
bool force_surface_temperature
std::vector< std::unique_ptr< WorldBuilder::Features::Interface > > features
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
double thermal_expansion_coefficient
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
void declare_entry(const std::string &name, const Types::Interface &type, const std::string &documentation)
std::vector< Point< 2 > > cross_section
std::vector< T > get_vector(const std::string &name)
T get(const std::string &name)