From 6b24038c1790246cc841cd90337a8dc1a904794e Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Mon, 8 Nov 2021 14:12:10 -0800 Subject: [PATCH 1/4] Allow for correct processing of default values in coordinate system. --- source/parameters.cc | 46 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/source/parameters.cc b/source/parameters.cc index 311754e45..362556eed 100644 --- a/source/parameters.cc +++ b/source/parameters.cc @@ -1383,7 +1383,51 @@ namespace WorldBuilder } else if (type == "object") { - collapse += "/properties"; + // normal objects just have properties, but some have oneOf + if (Pointer((base_path + "/oneOf").c_str()).Get(declarations) != nullptr) + { + // it has a structure with oneOf. Find out which of the entries is needed. + // This means we have to take a sneak peak to figure out how to get to the + // next value. + size_t size = Pointer((base_path + "/oneOf").c_str()).Get(declarations)->Size(); +#ifdef debug + bool found = false; +#endif + size_t index = 0; + for (; index < size; ++index) + { + std::string declarations_string = Pointer((base_path + "/oneOf/" + std::to_string(index) + + "/properties/model/enum/0").c_str()).Get(declarations)->GetString(); + + // we need to get the json path relevant for the current declaration string + // we are interested in, which requires an offset of 2. + WBAssert(Pointer((get_full_json_path(i+2) + "/model").c_str()).Get(parameters) != nullptr, "Could not find model in: " << get_full_json_path(i+2) + "/model"); + std::string parameters_string = Pointer((get_full_json_path(i+2) + "/model").c_str()).Get(parameters)->GetString(); + + // currently in our case these are always objects, so go directly to find the option we need. + if (declarations_string == parameters_string) + { + // found it for index i; +#ifdef debug + found = true; +#endif + break; + } + } +#ifdef debug + WBAssert(found == true, + "Internal error: This is an array with several possible values, " + "but could not find the correct value " << collapse + "/" + path[i] + "/items/oneOf"); +#endif + collapse += "/" + path[i] + "/oneOf/" + std::to_string(index) + "/properties"; + // add one to i, to skip the array + ++i; + + } + else + { + collapse += "/properties"; + } } else { From 904ac21c43cb61fab3cd8057752cadffff85fde9 Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Sun, 24 Oct 2021 15:33:25 -0700 Subject: [PATCH 2/4] Add max_model_depth variable to cartesian and spherical geometries with a get function and a radius input parameter for the spherical geometry model to define the max_model_depth. --- .../world_builder/coordinate_systems/cartesian.h | 6 ++++++ .../world_builder/coordinate_systems/interface.h | 7 +++++++ .../world_builder/coordinate_systems/spherical.h | 13 ++++++++++++- source/coordinate_systems/cartesian.cc | 7 +++++++ source/coordinate_systems/spherical.cc | 16 ++++++++++++++-- 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/include/world_builder/coordinate_systems/cartesian.h b/include/world_builder/coordinate_systems/cartesian.h index 9b63e0d28..8e4e7c2a0 100644 --- a/include/world_builder/coordinate_systems/cartesian.h +++ b/include/world_builder/coordinate_systems/cartesian.h @@ -101,6 +101,12 @@ namespace WorldBuilder */ double distance_between_points_at_same_depth(const Point<3> &point_1, const Point<3> &point_2) const override final; + /** + * Returns the max model depth. This always returns infinity for Cartesian + * models. + */ + virtual + double max_model_depth() const override final; private: diff --git a/include/world_builder/coordinate_systems/interface.h b/include/world_builder/coordinate_systems/interface.h index c1068797f..6a44304d2 100644 --- a/include/world_builder/coordinate_systems/interface.h +++ b/include/world_builder/coordinate_systems/interface.h @@ -106,6 +106,13 @@ namespace WorldBuilder virtual double distance_between_points_at_same_depth(const Point<3> &point_1, const Point<3> &point_2) const = 0; + /** + * Returns the max model depth. This should be the infinity for Cartesian + * models and the radius in spherical models. + */ + virtual + double max_model_depth() const = 0; + /** * A function to register a new type. This is part of the automatic * registration of the object factory. diff --git a/include/world_builder/coordinate_systems/spherical.h b/include/world_builder/coordinate_systems/spherical.h index 46dddbfb9..dcf5a4229 100644 --- a/include/world_builder/coordinate_systems/spherical.h +++ b/include/world_builder/coordinate_systems/spherical.h @@ -105,13 +105,24 @@ namespace WorldBuilder */ double distance_between_points_at_same_depth(const Point<3> &point_1, const Point<3> &point_2) const override final; + /** + * Returns the max model depth. This returns the radius in spherical + * models. + */ + virtual + double max_model_depth() const override final; + /** * What depth method the spherical coordinates use. */ DepthMethod used_depth_method; private: - + /** + * The maximum depth of the model. In the spherical case that is equal to the + * radius of the sphere. + */ + double radius_sphere; }; } // namespace CoordinateSystems } // namespace WorldBuilder diff --git a/source/coordinate_systems/cartesian.cc b/source/coordinate_systems/cartesian.cc index 81d03a4a3..d8247a7c5 100644 --- a/source/coordinate_systems/cartesian.cc +++ b/source/coordinate_systems/cartesian.cc @@ -83,6 +83,13 @@ namespace WorldBuilder return point_at_depth.norm(); } + + double + Cartesian::max_model_depth() const + { + return std::numeric_limits::infinity(); + } + /** * Register plugin */ diff --git a/source/coordinate_systems/spherical.cc b/source/coordinate_systems/spherical.cc index 8d3be980f..cda843d1a 100644 --- a/source/coordinate_systems/spherical.cc +++ b/source/coordinate_systems/spherical.cc @@ -21,6 +21,7 @@ #include "world_builder/types/object.h" +#include "world_builder/types/double.h" #include "world_builder/utilities.h" namespace WorldBuilder @@ -40,7 +41,7 @@ namespace WorldBuilder { // Add depth method to the requried parameters. - prm.declare_entry("", Types::Object({"depth method"}), "Coordinate sysetm object"); + prm.declare_entry("", Types::Object({"depth method"}), "Coordinate system object"); prm.declare_entry("depth method", @@ -49,6 +50,10 @@ namespace WorldBuilder R"('begin segment' and 'begin at end segment'. See the manual section on coordinate systems for )" R"(more info.)"); + prm.declare_entry("radius", + Types::Double(6371000.), + R"(The radius of the sphere.)"); + } @@ -71,7 +76,7 @@ namespace WorldBuilder "coordinates. The available options are 'starting point', 'begin segment' and 'begin at end segment'. " "The option 'continuous' is not yet available."); - //std::cout << "string_depth_method = " << string_depth_method << std::endl; + radius_sphere = prm.get("radius"); } prm.leave_subsection(); } @@ -133,6 +138,13 @@ namespace WorldBuilder return radius * std::atan2(top, bottom); } + + double + Spherical::max_model_depth() const + { + return radius_sphere; + } + /** * Register plugin */ From bd65c9147f1c30af8a7b23536140b98c5401b835 Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Mon, 8 Nov 2021 14:48:03 -0800 Subject: [PATCH 3/4] add unit test for max_model_depth --- tests/unit_tests/unit_test_world_builder.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/unit_test_world_builder.cc b/tests/unit_tests/unit_test_world_builder.cc index 83f07ead4..b3cd0cabe 100644 --- a/tests/unit_tests/unit_test_world_builder.cc +++ b/tests/unit_tests/unit_test_world_builder.cc @@ -3823,9 +3823,12 @@ TEST_CASE("WorldBuilder Parameters") { // First test a world builder file with a cross section defined std::string file = WorldBuilder::Data::WORLD_BUILDER_SOURCE_DIR + "/tests/data/type_data.json"; - std::string file_name = WorldBuilder::Data::WORLD_BUILDER_SOURCE_DIR + "/tests/data/subducting_plate_different_angles_spherical.wb"; + std::string file_name = WorldBuilder::Data::WORLD_BUILDER_SOURCE_DIR + "/tests/data/subducting_plate_different_angles_cartesian.wb"; WorldBuilder::World world(file_name); + world.parse_entries(world.parameters); + CHECK(std::isinf(world.parameters.coordinate_system->max_model_depth())); + Parameters prm(world); prm.initialize(file); @@ -7344,6 +7347,8 @@ TEST_CASE("WorldBuilder Utilities function: distance_point_from_curved_planes sp WorldBuilder::World world(file_name); const double dtr = Utilities::const_pi/180.0; + world.parse_entries(world.parameters); + CHECK(world.parameters.coordinate_system->max_model_depth() == Approx(6371000.)); // slab goes down and up again // origin std::array position = {{6371000 - 0, 0 * dtr, 0 * dtr}}; From eec02737013330056a19eb9322e4091c8e774e3b Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Mon, 8 Nov 2021 14:52:39 -0800 Subject: [PATCH 4/4] add changelog entry for new max model depth parameter. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ed2b395f..125f2aea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The option for a temperature model for an oceanic plate with a constant age using the plate model. \[Haoyuan Li; 2021-10-29; [#344](https://github.com/GeodynamicWorldBuilder/WorldBuilder/pull/344)\] - The cmake targets to easily switch between debug and release mode \[Menno Fraters; 2021-10-31; [#361](https://github.com/GeodynamicWorldBuilder/WorldBuilder/pull/361)\] - A new depth method for the spherical coordinate system called begin at end segment. This adds the spherical correction to the end of the segment instead of the beginning, resulting in a smoother transition between segments. \[Menno Fraters; 2021-11-06; [#364](https://github.com/GeodynamicWorldBuilder/WorldBuilder/pull/364), [#365](https://github.com/GeodynamicWorldBuilder/WorldBuilder/pull/365)\] +- A new input parameter and accociated functions which define the maximum depth of a model. This allows the world builder to create a complete picture of the world. \[Menno Fraters; 2021-11-08; [#367](https://github.com/GeodynamicWorldBuilder/WorldBuilder/pull/367) and [#331](https://github.com/GeodynamicWorldBuilder/WorldBuilder/issues/331)\] ### Changed - The World Builder Visualizer will now use zlib compression for vtu files by default. If zlib is not available binary output will be used. \[Menno Fraters; 2021-06-26; [#282](github.com/GeodynamicWorldBuilder/WorldBuilder/pull/282)\]