From 14c636c85b3bf59444fcc0b60e1a6b7143f1c12d Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Tue, 21 Jan 2025 10:33:01 +0100 Subject: [PATCH] refactor to have a geometry type for each feature. --- doc/world_builder_declarations.schema.json | 69 +++++++++++++++--- doc/world_builder_declarations_closed.md | 56 ++++++++++++++- doc/world_builder_declarations_open.md | 62 +++++++++++++++- ...late.h => continental_plate_coordinates.h} | 10 +-- .../features/{fault.h => fault_coordinates.h} | 10 +-- ...tle_layer.h => mantle_layer_coordinates.h} | 10 +-- ...ic_plate.h => oceanic_plate_coordinates.h} | 10 +-- .../features/{plume.h => plume_coordinates.h} | 10 +-- ...plate.h => subducting_plate_coordinates.h} | 10 +-- ...te.cc => continental_plate_coordinates.cc} | 34 ++++----- .../{fault.cc => fault_coordinates.cc} | 46 ++++++------ source/world_builder/features/interface.cc | 20 +++++- ...e_layer.cc => mantle_layer_coordinates.cc} | 34 ++++----- ..._plate.cc => oceanic_plate_coordinates.cc} | 34 ++++----- .../{plume.cc => plume_coordinates.cc} | 38 +++++----- ...ate.cc => subducting_plate_coordinates.cc} | 46 ++++++------ source/world_builder/parameters.cc | 72 ++++++++++++++----- source/world_builder/world.cc | 2 +- tests/gwb-dat/app_continental_plate_3d.wb | 2 +- tests/unit_tests/unit_test_world_builder.cc | 24 +++---- 20 files changed, 415 insertions(+), 184 deletions(-) rename include/world_builder/features/{continental_plate.h => continental_plate_coordinates.h} (95%) rename include/world_builder/features/{fault.h => fault_coordinates.h} (97%) rename include/world_builder/features/{mantle_layer.h => mantle_layer_coordinates.h} (95%) rename include/world_builder/features/{oceanic_plate.h => oceanic_plate_coordinates.h} (95%) rename include/world_builder/features/{plume.h => plume_coordinates.h} (96%) rename include/world_builder/features/{subducting_plate.h => subducting_plate_coordinates.h} (97%) rename source/world_builder/features/{continental_plate.cc => continental_plate_coordinates.cc} (91%) rename source/world_builder/features/{fault.cc => fault_coordinates.cc} (96%) rename source/world_builder/features/{mantle_layer.cc => mantle_layer_coordinates.cc} (91%) rename source/world_builder/features/{oceanic_plate.cc => oceanic_plate_coordinates.cc} (91%) rename source/world_builder/features/{plume.cc => plume_coordinates.cc} (94%) rename source/world_builder/features/{subducting_plate.cc => subducting_plate_coordinates.cc} (96%) diff --git a/doc/world_builder_declarations.schema.json b/doc/world_builder_declarations.schema.json index edbe87072..2ead29f00 100644 --- a/doc/world_builder_declarations.schema.json +++ b/doc/world_builder_declarations.schema.json @@ -170,7 +170,7 @@ "items": { "defaultSnippets": [ { - "label": "add a 'continental plate'", + "label": "add a 'continental plate coordinates'", "body": { "model": "continental plate", "name": "${1:My Plate}", @@ -178,7 +178,7 @@ } }, { - "label": "add a 'fault'", + "label": "add a 'fault coordinates'", "body": { "model": "fault", "name": "${1:My Fault}", @@ -188,7 +188,7 @@ } }, { - "label": "add a 'mantle layer'", + "label": "add a 'mantle layer coordinates'", "body": { "model": "mantle layer", "name": "${1:My Mantle Layer}", @@ -198,7 +198,7 @@ } }, { - "label": "add a 'oceanic plate'", + "label": "add a 'oceanic plate coordinates'", "body": { "model": "oceanic plate", "name": "${1:My Oceanic Plate}", @@ -208,17 +208,17 @@ } }, { - "label": "add a 'plume'", + "label": "add a 'plume coordinates'", "body": { "model": "plume", - "name": "${1:My Plume}", + "name": "${1:My PlumeCoordinates}", "coordinates": [], "temperature models": [], "composition models": [] } }, { - "label": "add a 'subducting plate'", + "label": "add a 'subducting plate coordinates'", "body": { "model": "subducting plate", "name": "${1:My Subducting Plate}", @@ -245,6 +245,14 @@ "continental plate" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates" + ] + }, "name": { "default value": "", "type": "string", @@ -1787,6 +1795,15 @@ "fault" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates", + "coordinates" + ] + }, "name": { "default value": "", "type": "string", @@ -4713,6 +4730,15 @@ "mantle layer" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates", + "coordinates" + ] + }, "name": { "default value": "", "type": "string", @@ -6098,6 +6124,15 @@ "oceanic plate" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates", + "coordinates" + ] + }, "name": { "default value": "", "type": "string", @@ -8151,7 +8186,7 @@ }, { "type": "object", - "description": "Plume object. Requires properties `model` and `coordinates`.", + "description": "PlumeCoordinates object. Requires properties `model` and `coordinates`.", "additionalProperties": false, "required": [ "model" @@ -8165,6 +8200,15 @@ "plume" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates", + "coordinates" + ] + }, "name": { "default value": "", "type": "string", @@ -8770,6 +8814,15 @@ "subducting plate" ] }, + "geometry type": { + "default value": "coordinates", + "type": "string", + "description": "The model geometry type", + "enum": [ + "coordinates", + "coordinates" + ] + }, "name": { "default value": "", "type": "string", diff --git a/doc/world_builder_declarations_closed.md b/doc/world_builder_declarations_closed.md index 04ba1d5f0..e2e938432 100644 --- a/doc/world_builder_declarations_closed.md +++ b/doc/world_builder_declarations_closed.md @@ -253,6 +253,15 @@ - **enum**:[continental plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/1/geometry type +:name: closed_features_items_oneOf_1_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/1/name :name: closed_features_items_oneOf_1_name @@ -2631,6 +2640,15 @@ - **enum**:[fault] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/2/geometry type +:name: closed_features_items_oneOf_2_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/2/name :name: closed_features_items_oneOf_2_name @@ -6660,6 +6678,15 @@ - **enum**:[mantle layer] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/3/geometry type +:name: closed_features_items_oneOf_3_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/3/name :name: closed_features_items_oneOf_3_name @@ -8802,6 +8829,15 @@ - **enum**:[oceanic plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/4/geometry type +:name: closed_features_items_oneOf_4_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/4/name :name: closed_features_items_oneOf_4_name @@ -11987,7 +12023,7 @@ :name: closed_features_items_oneOf_5 - **type**:object -- **description**:Plume object. Requires properties `model` and `coordinates`. +- **description**:PlumeCoordinates object. Requires properties `model` and `coordinates`. - **additionalProperties**:false - **required**:[model] @@ -12000,6 +12036,15 @@ - **enum**:[plume] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/5/geometry type +:name: closed_features_items_oneOf_5_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/5/name :name: closed_features_items_oneOf_5_name @@ -12842,6 +12887,15 @@ - **enum**:[subducting plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/6/geometry type +:name: closed_features_items_oneOf_6_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/6/name :name: closed_features_items_oneOf_6_name diff --git a/doc/world_builder_declarations_open.md b/doc/world_builder_declarations_open.md index 186bb4db5..46f862b9b 100644 --- a/doc/world_builder_declarations_open.md +++ b/doc/world_builder_declarations_open.md @@ -284,6 +284,16 @@ - **enum**:[continental plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/1/geometry type +:open: +:name: open_features_items_oneOf_1_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/1/name :open: :name: open_features_items_oneOf_1_name @@ -2979,6 +2989,16 @@ - **enum**:[fault] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/2/geometry type +:open: +:name: open_features_items_oneOf_2_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/2/name :open: :name: open_features_items_oneOf_2_name @@ -7473,6 +7493,16 @@ - **enum**:[mantle layer] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/3/geometry type +:open: +:name: open_features_items_oneOf_3_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/3/name :open: :name: open_features_items_oneOf_3_name @@ -9901,6 +9931,16 @@ - **enum**:[oceanic plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/4/geometry type +:open: +:name: open_features_items_oneOf_4_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/4/name :open: :name: open_features_items_oneOf_4_name @@ -13514,7 +13554,7 @@ :name: open_features_items_oneOf_5 - **type**:object -- **description**:Plume object. Requires properties `model` and `coordinates`. +- **description**:PlumeCoordinates object. Requires properties `model` and `coordinates`. - **additionalProperties**:false - **required**:[model] @@ -13528,6 +13568,16 @@ - **enum**:[plume] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/5/geometry type +:open: +:name: open_features_items_oneOf_5_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/5/name :open: :name: open_features_items_oneOf_5_name @@ -14467,6 +14517,16 @@ - **enum**:[subducting plate] :::::::::::::::::::: +::::::::::::::::::::{dropdown} /features/items/oneOf/6/geometry type +:open: +:name: open_features_items_oneOf_6_geometry-type + +- **default value**:coordinates +- **type**:string +- **description**:The model geometry type +- **enum**:[coordinates, coordinates] +:::::::::::::::::::: + ::::::::::::::::::::{dropdown} /features/items/oneOf/6/name :open: :name: open_features_items_oneOf_6_name diff --git a/include/world_builder/features/continental_plate.h b/include/world_builder/features/continental_plate_coordinates.h similarity index 95% rename from include/world_builder/features/continental_plate.h rename to include/world_builder/features/continental_plate_coordinates.h index eff6d10b9..bbcb68a85 100644 --- a/include/world_builder/features/continental_plate.h +++ b/include/world_builder/features/continental_plate_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_H -#define WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_H +#ifndef WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_COORDINATES_H +#define WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_COORDINATES_H #include "world_builder/features/interface.h" @@ -58,18 +58,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class ContinentalPlate final: public Interface + class ContinentalPlateCoordinates final: public Interface { public: /** * constructor */ - ContinentalPlate(WorldBuilder::World *world); + ContinentalPlateCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~ContinentalPlate() override final; + ~ContinentalPlateCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/include/world_builder/features/fault.h b/include/world_builder/features/fault_coordinates.h similarity index 97% rename from include/world_builder/features/fault.h rename to include/world_builder/features/fault_coordinates.h index 61e06e502..c95e36c0a 100644 --- a/include/world_builder/features/fault.h +++ b/include/world_builder/features/fault_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_FAULT_H -#define WORLD_BUILDER_FEATURES_FAULT_H +#ifndef WORLD_BUILDER_FEATURES_FAULT_COORDINATES_H +#define WORLD_BUILDER_FEATURES_FAULT_COORDINATES_H #include "world_builder/features/fault_models/composition/interface.h" @@ -63,18 +63,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class Fault final: public Interface + class FaultCoordinates final: public Interface { public: /** * constructor */ - Fault(WorldBuilder::World *world); + FaultCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~Fault() override final; + ~FaultCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/include/world_builder/features/mantle_layer.h b/include/world_builder/features/mantle_layer_coordinates.h similarity index 95% rename from include/world_builder/features/mantle_layer.h rename to include/world_builder/features/mantle_layer_coordinates.h index 6c259facb..65b7e5cb3 100644 --- a/include/world_builder/features/mantle_layer.h +++ b/include/world_builder/features/mantle_layer_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_MANTLE_LAYER_H -#define WORLD_BUILDER_FEATURES_MANTLE_LAYER_H +#ifndef WORLD_BUILDER_FEATURES_MANTLE_LAYER_COORDINATES_H +#define WORLD_BUILDER_FEATURES_MANTLE_LAYER_COORDINATES_H #include "world_builder/features/interface.h" @@ -58,18 +58,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class MantleLayer final: public Interface + class MantleLayerCoordinates final: public Interface { public: /** * constructor */ - MantleLayer(WorldBuilder::World *world); + MantleLayerCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~MantleLayer() override final; + ~MantleLayerCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/include/world_builder/features/oceanic_plate.h b/include/world_builder/features/oceanic_plate_coordinates.h similarity index 95% rename from include/world_builder/features/oceanic_plate.h rename to include/world_builder/features/oceanic_plate_coordinates.h index a7267bedd..2237db53c 100644 --- a/include/world_builder/features/oceanic_plate.h +++ b/include/world_builder/features/oceanic_plate_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_OCEANIC_PLATE_H -#define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_H +#ifndef WORLD_BUILDER_FEATURES_OCEANIC_PLATE_COORDINATES_H +#define WORLD_BUILDER_FEATURES_OCEANIC_PLATE_COORDINATES_H #include "world_builder/features/interface.h" @@ -58,18 +58,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class OceanicPlate final: public Interface + class OceanicPlateCoordinates final: public Interface { public: /** * constructor */ - OceanicPlate(WorldBuilder::World *world); + OceanicPlateCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~OceanicPlate() override final; + ~OceanicPlateCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/include/world_builder/features/plume.h b/include/world_builder/features/plume_coordinates.h similarity index 96% rename from include/world_builder/features/plume.h rename to include/world_builder/features/plume_coordinates.h index ccd80ed0e..16c9cb6c3 100644 --- a/include/world_builder/features/plume.h +++ b/include/world_builder/features/plume_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_PLUME_H -#define WORLD_BUILDER_FEATURES_PLUME_H +#ifndef WORLD_BUILDER_FEATURES_PLUME_COORDINATES_H +#define WORLD_BUILDER_FEATURES_PLUME_COORDINATES_H #include "world_builder/features/interface.h" @@ -58,18 +58,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class Plume final: public Interface + class PlumeCoordinates final: public Interface { public: /** * constructor */ - Plume(WorldBuilder::World *world); + PlumeCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~Plume() override final; + ~PlumeCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/include/world_builder/features/subducting_plate.h b/include/world_builder/features/subducting_plate_coordinates.h similarity index 97% rename from include/world_builder/features/subducting_plate.h rename to include/world_builder/features/subducting_plate_coordinates.h index 6b1cfde97..5cac22b9a 100644 --- a/include/world_builder/features/subducting_plate.h +++ b/include/world_builder/features/subducting_plate_coordinates.h @@ -17,8 +17,8 @@ along with this program. If not, see . */ -#ifndef WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_H -#define WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_H +#ifndef WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_COORDINATES_H +#define WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_COORDINATES_H #include "world_builder/features/subducting_plate_models/composition/interface.h" @@ -64,18 +64,18 @@ namespace WorldBuilder * the returned temperature or composition of the temperature and composition * functions of this class will be. */ - class SubductingPlate final: public Interface + class SubductingPlateCoordinates final: public Interface { public: /** * constructor */ - SubductingPlate(WorldBuilder::World *world); + SubductingPlateCoordinates(WorldBuilder::World *world); /** * Destructor */ - ~SubductingPlate() override final; + ~SubductingPlateCoordinates() override final; /** * declare and read in the world builder file into the parameters class diff --git a/source/world_builder/features/continental_plate.cc b/source/world_builder/features/continental_plate_coordinates.cc similarity index 91% rename from source/world_builder/features/continental_plate.cc rename to source/world_builder/features/continental_plate_coordinates.cc index 38d2e2b51..1cbd67559 100644 --- a/source/world_builder/features/continental_plate.cc +++ b/source/world_builder/features/continental_plate_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/continental_plate.h" +#include "world_builder/features/continental_plate_coordinates.h" #include "world_builder/features/continental_plate_models/composition/interface.h" @@ -44,19 +44,19 @@ namespace WorldBuilder namespace Features { - ContinentalPlate::ContinentalPlate(WorldBuilder::World *world_) + ContinentalPlateCoordinates::ContinentalPlateCoordinates(WorldBuilder::World *world_) : min_depth(NaN::DSNAN), max_depth(NaN::DSNAN) { this->world = world_; - this->name = "continental plate"; + this->name = "continental plate coordinates"; } - ContinentalPlate::~ContinentalPlate() + ContinentalPlateCoordinates::~ContinentalPlateCoordinates() = default; - void ContinentalPlate::make_snippet(Parameters &prm) + void ContinentalPlateCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -72,9 +72,9 @@ namespace WorldBuilder void - ContinentalPlate::declare_entries(Parameters &prm, - const std::string & /*unused*/, - const std::vector &required_entries) + ContinentalPlateCoordinates::declare_entries(Parameters &prm, + const std::string & /*unused*/, + const std::vector &required_entries) { @@ -100,7 +100,7 @@ namespace WorldBuilder } void - ContinentalPlate::parse_entries(Parameters &prm) + ContinentalPlateCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -190,13 +190,13 @@ namespace WorldBuilder void - ContinentalPlate::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + ContinentalPlateCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { if (depth <= max_depth && depth >= min_depth && WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(), @@ -308,7 +308,7 @@ namespace WorldBuilder } } - WB_REGISTER_FEATURE(ContinentalPlate, continental plate) + WB_REGISTER_FEATURE(ContinentalPlateCoordinates, continental plate coordinates) } // namespace Features } // namespace WorldBuilder diff --git a/source/world_builder/features/fault.cc b/source/world_builder/features/fault_coordinates.cc similarity index 96% rename from source/world_builder/features/fault.cc rename to source/world_builder/features/fault_coordinates.cc index f75124cbd..cd1bca1d4 100644 --- a/source/world_builder/features/fault.cc +++ b/source/world_builder/features/fault_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/fault.h" +#include "world_builder/features/fault_coordinates.h" #include "glm/glm.h" @@ -39,7 +39,7 @@ namespace WorldBuilder namespace Features { - Fault::Fault(WorldBuilder::World *world_) + FaultCoordinates::FaultCoordinates(WorldBuilder::World *world_) : reference_point(0,0,cartesian) { @@ -47,12 +47,12 @@ namespace WorldBuilder this->name = "fault"; } - Fault::~Fault() + FaultCoordinates::~FaultCoordinates() = default; - void Fault::make_snippet(Parameters &prm) + void FaultCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -70,9 +70,9 @@ namespace WorldBuilder void - Fault::declare_entries(Parameters &prm, - const std::string &parent_name, - const std::vector &required_entries) + FaultCoordinates::declare_entries(Parameters &prm, + const std::string &parent_name, + const std::vector &required_entries) { // This statement is needed because of the recursion associated with @@ -84,6 +84,8 @@ namespace WorldBuilder else { prm.declare_entry("", Types::Object(required_entries), "Fault object. Requires properties `model` and `coordinates`."); + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); } prm.declare_entry("min depth", Types::Double(0), "The depth to which this feature is present"); @@ -115,7 +117,7 @@ namespace WorldBuilder if (parent_name != "items") { // This only happens if we are not in sections - prm.declare_entry("sections", Types::Array(Types::PluginSystem("",Features::Fault::declare_entries, {"coordinate"}, false)),"A list of feature properties for a coordinate."); + prm.declare_entry("sections", Types::Array(Types::PluginSystem("",Features::FaultCoordinates::declare_entries, {"coordinate"}, false)),"A list of feature properties for a coordinate."); } else { @@ -129,7 +131,7 @@ namespace WorldBuilder } void - Fault::parse_entries(Parameters &prm) + FaultCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -182,7 +184,7 @@ namespace WorldBuilder // now search whether a section is present, if so, replace the default segments. - std::vector > sections_vector; + std::vector > sections_vector; prm.get_unique_pointers("sections", sections_vector); prm.enter_subsection("sections"); @@ -462,20 +464,20 @@ namespace WorldBuilder const BoundingBox<2> & - Fault::get_surface_bounding_box () const + FaultCoordinates::get_surface_bounding_box () const { return surface_bounding_box; } void - Fault::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + FaultCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { // The 'depth coordinate' is the z-coordinate in Cartesian coordinates, and radius in spherical coordinates. // The depth input parameter is the distance from the surface to the position, @@ -780,9 +782,9 @@ namespace WorldBuilder } Objects::PlaneDistances - Fault::distance_to_feature_plane(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth) const + FaultCoordinates::distance_to_feature_plane(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth) const { // The depth variable is the distance from the surface to the position, the depth // coordinate is the distance from the bottom of the model to the position and @@ -815,7 +817,7 @@ namespace WorldBuilder /** * Register plugin */ - WB_REGISTER_FEATURE(Fault, fault) + WB_REGISTER_FEATURE(FaultCoordinates, fault coordinates) } // namespace Features } // namespace WorldBuilder diff --git a/source/world_builder/features/interface.cc b/source/world_builder/features/interface.cc index 0678ad063..5474ebdbc 100644 --- a/source/world_builder/features/interface.cc +++ b/source/world_builder/features/interface.cc @@ -103,8 +103,26 @@ namespace WorldBuilder { prm.declare_entry("", Types::Object(required_entries), "feature object"); - prm.declare_entry("model", Types::String("",it.first), + std::string model_name = it.first; + std::vector geometry_types = {" coordinates"}; + + for (auto &geometry_type : geometry_types) + { + // TODO: now just remove all, maybe only find last position of coordinates and remove it. + size_t pos = 0; + while ((pos = model_name.find(geometry_type, pos)) != std::string::npos) + { + model_name.replace(pos, geometry_type.length(), ""); + pos += 0; + } + } + + + prm.declare_entry("model", Types::String("",model_name), "The model name of the feature determining its type."); + + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); prm.declare_entry("name", Types::String(""), "The name which the user has given to the feature. " "This is mostly used for documentation purposes, and should in most cases be unique, " diff --git a/source/world_builder/features/mantle_layer.cc b/source/world_builder/features/mantle_layer_coordinates.cc similarity index 91% rename from source/world_builder/features/mantle_layer.cc rename to source/world_builder/features/mantle_layer_coordinates.cc index 1aada09ef..3d8d03405 100644 --- a/source/world_builder/features/mantle_layer.cc +++ b/source/world_builder/features/mantle_layer_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/mantle_layer.h" +#include "world_builder/features/mantle_layer_coordinates.h" #include "world_builder/features/mantle_layer_models/composition/interface.h" @@ -40,18 +40,18 @@ namespace WorldBuilder namespace Features { - MantleLayer::MantleLayer(WorldBuilder::World *world_) + MantleLayerCoordinates::MantleLayerCoordinates(WorldBuilder::World *world_) { this->world = world_; this->name = "mantle layer"; } - MantleLayer::~MantleLayer() + MantleLayerCoordinates::~MantleLayerCoordinates() = default; - void MantleLayer::make_snippet(Parameters &prm) + void MantleLayerCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -69,12 +69,14 @@ namespace WorldBuilder void - MantleLayer::declare_entries(Parameters &prm, - const std::string &/*parent_name*/, - const std::vector &required_entries) + MantleLayerCoordinates::declare_entries(Parameters &prm, + const std::string &/*parent_name*/, + const std::vector &required_entries) { prm.declare_entry("", Types::Object(required_entries), "Mantle layer object. Requires properties `model` and `coordinates`."); + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); prm.declare_entry("min depth", Types::OneOf(Types::Double(0),Types::Array(Types::ValueAtPoints(0., 2.))), "The depth from which this feature is present"); prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits::max(), 2.))), @@ -94,7 +96,7 @@ namespace WorldBuilder } void - MantleLayer::parse_entries(Parameters &prm) + MantleLayerCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -181,13 +183,13 @@ namespace WorldBuilder void - MantleLayer::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + MantleLayerCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { if (depth <= max_depth && depth >= min_depth && WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(), @@ -302,7 +304,7 @@ namespace WorldBuilder } } - WB_REGISTER_FEATURE(MantleLayer, mantle layer) + WB_REGISTER_FEATURE(MantleLayerCoordinates, mantle layer coordinates) } // namespace Features } // namespace WorldBuilder diff --git a/source/world_builder/features/oceanic_plate.cc b/source/world_builder/features/oceanic_plate_coordinates.cc similarity index 91% rename from source/world_builder/features/oceanic_plate.cc rename to source/world_builder/features/oceanic_plate_coordinates.cc index 7d55af1dc..49d3654f8 100644 --- a/source/world_builder/features/oceanic_plate.cc +++ b/source/world_builder/features/oceanic_plate_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/oceanic_plate.h" +#include "world_builder/features/oceanic_plate_coordinates.h" #include "world_builder/features/oceanic_plate_models/composition/interface.h" #include "world_builder/features/oceanic_plate_models/grains/interface.h" @@ -40,7 +40,7 @@ namespace WorldBuilder namespace Features { - OceanicPlate::OceanicPlate(WorldBuilder::World *world_) + OceanicPlateCoordinates::OceanicPlateCoordinates(WorldBuilder::World *world_) : min_depth(NaN::DSNAN), max_depth(NaN::DSNAN) @@ -49,12 +49,12 @@ namespace WorldBuilder this->name = "oceanic plate"; } - OceanicPlate::~OceanicPlate() + OceanicPlateCoordinates::~OceanicPlateCoordinates() = default; - void OceanicPlate::make_snippet(Parameters &prm) + void OceanicPlateCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -86,12 +86,14 @@ namespace WorldBuilder void - OceanicPlate::declare_entries(Parameters &prm, - const std::string & /*unused*/, - const std::vector &required_entries) + OceanicPlateCoordinates::declare_entries(Parameters &prm, + const std::string & /*unused*/, + const std::vector &required_entries) { prm.declare_entry("", Types::Object(required_entries), "Oceanic plate object. Requires properties `model` and `coordinates`."); + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); prm.declare_entry("min depth", Types::OneOf(Types::Double(0),Types::Array(Types::ValueAtPoints(0., 2.))), "The depth from which this feature is present"); prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits::max(), 2.))), @@ -111,7 +113,7 @@ namespace WorldBuilder } void - OceanicPlate::parse_entries(Parameters &prm) + OceanicPlateCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -199,13 +201,13 @@ namespace WorldBuilder void - OceanicPlate::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + OceanicPlateCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { if (depth <= max_depth && depth >= min_depth && WorldBuilder::Utilities::polygon_contains_point(coordinates, Point<2>(position_in_natural_coordinates.get_surface_coordinates(), @@ -323,7 +325,7 @@ namespace WorldBuilder /** * Register plugin */ - WB_REGISTER_FEATURE(OceanicPlate, oceanic plate) + WB_REGISTER_FEATURE(OceanicPlateCoordinates, oceanic plate coordinates) } // namespace Features } // namespace WorldBuilder diff --git a/source/world_builder/features/plume.cc b/source/world_builder/features/plume_coordinates.cc similarity index 94% rename from source/world_builder/features/plume.cc rename to source/world_builder/features/plume_coordinates.cc index c4025a48f..506161447 100644 --- a/source/world_builder/features/plume.cc +++ b/source/world_builder/features/plume_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/plume.h" +#include "world_builder/features/plume_coordinates.h" #include "world_builder/features/plume_models/composition/interface.h" @@ -44,7 +44,7 @@ namespace WorldBuilder namespace Features { - Plume::Plume(WorldBuilder::World *world_) + PlumeCoordinates::PlumeCoordinates(WorldBuilder::World *world_) : min_depth(NaN::DSNAN), max_depth(NaN::DSNAN) @@ -53,12 +53,12 @@ namespace WorldBuilder this->name = "plume"; } - Plume::~Plume() + PlumeCoordinates::~PlumeCoordinates() = default; - void Plume::make_snippet(Parameters &prm) + void PlumeCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -67,7 +67,7 @@ namespace WorldBuilder Pointer((path + "/body").c_str()).Set(declarations,"object"); Pointer((path + "/body/model").c_str()).Set(declarations,"plume"); - Pointer((path + "/body/name").c_str()).Set(declarations,"${1:My Plume}"); + Pointer((path + "/body/name").c_str()).Set(declarations,"${1:My PlumeCoordinates}"); Pointer((path + "/body/coordinates").c_str()).Create(declarations).SetArray(); Pointer((path + "/body/temperature models").c_str()).Create(declarations).SetArray(); Pointer((path + "/body/composition models").c_str()).Create(declarations).SetArray(); @@ -76,12 +76,14 @@ namespace WorldBuilder void - Plume::declare_entries(Parameters &prm, - const std::string & /*unused*/, - const std::vector &required_entries) + PlumeCoordinates::declare_entries(Parameters &prm, + const std::string & /*unused*/, + const std::vector &required_entries) { - prm.declare_entry("", Types::Object(required_entries), "Plume object. Requires properties `model` and `coordinates`."); + prm.declare_entry("", Types::Object(required_entries), "PlumeCoordinates object. Requires properties `model` and `coordinates`."); + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); prm.declare_entry("min depth", Types::Double(0), "The depth from which this feature is present, in other words, the " "depth of the tip of the plume. If the first entry in the cross " @@ -118,7 +120,7 @@ namespace WorldBuilder } void - Plume::parse_entries(Parameters &prm) + PlumeCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -251,13 +253,13 @@ namespace WorldBuilder void - Plume::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + PlumeCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { // Figure out if the point is within the plume auto upper = std::upper_bound(depths.begin(), depths.end(), depth); @@ -440,7 +442,7 @@ namespace WorldBuilder } } - WB_REGISTER_FEATURE(Plume, plume) + WB_REGISTER_FEATURE(PlumeCoordinates, plume coordinates) } // namespace Features } // namespace WorldBuilder \ No newline at end of file diff --git a/source/world_builder/features/subducting_plate.cc b/source/world_builder/features/subducting_plate_coordinates.cc similarity index 96% rename from source/world_builder/features/subducting_plate.cc rename to source/world_builder/features/subducting_plate_coordinates.cc index 3e3a7a531..8b6602adf 100644 --- a/source/world_builder/features/subducting_plate.cc +++ b/source/world_builder/features/subducting_plate_coordinates.cc @@ -17,7 +17,7 @@ along with this program. If not, see . */ -#include "world_builder/features/subducting_plate.h" +#include "world_builder/features/subducting_plate_coordinates.h" #include "glm/glm.h" @@ -39,7 +39,7 @@ namespace WorldBuilder namespace Features { - SubductingPlate::SubductingPlate(WorldBuilder::World *world_) + SubductingPlateCoordinates::SubductingPlateCoordinates(WorldBuilder::World *world_) : reference_point(0,0,cartesian) { @@ -47,12 +47,12 @@ namespace WorldBuilder this->name = "subducting plate"; } - SubductingPlate::~SubductingPlate() + SubductingPlateCoordinates::~SubductingPlateCoordinates() = default; - void SubductingPlate::make_snippet(Parameters &prm) + void SubductingPlateCoordinates::make_snippet(Parameters &prm) { using namespace rapidjson; Document &declarations = prm.declarations; @@ -84,9 +84,9 @@ namespace WorldBuilder void - SubductingPlate::declare_entries(Parameters &prm, - const std::string &parent_name, - const std::vector &required_entries) + SubductingPlateCoordinates::declare_entries(Parameters &prm, + const std::string &parent_name, + const std::vector &required_entries) { // This statement is needed because of the recursion associated with // the sections entry. @@ -97,6 +97,8 @@ namespace WorldBuilder else { prm.declare_entry("", Types::Object(required_entries), "Subducting slab object. Requires properties `model` and `coordinates`."); + prm.declare_entry("geometry type", Types::String("coordinates","coordinates"), + "The model geometry type"); } @@ -135,7 +137,7 @@ namespace WorldBuilder if (parent_name != "items") { // This only happens if we are not in sections - prm.declare_entry("sections", Types::Array(Types::PluginSystem("",Features::SubductingPlate::declare_entries, {"coordinate"}, false)),"A list of feature properties for a coordinate."); + prm.declare_entry("sections", Types::Array(Types::PluginSystem("",Features::SubductingPlateCoordinates::declare_entries, {"coordinate"}, false)),"A list of feature properties for a coordinate."); } else { @@ -149,7 +151,7 @@ namespace WorldBuilder } void - SubductingPlate::parse_entries(Parameters &prm) + SubductingPlateCoordinates::parse_entries(Parameters &prm) { const CoordinateSystem coordinate_system = prm.coordinate_system->natural_coordinate_system(); @@ -202,7 +204,7 @@ namespace WorldBuilder // now search whether a section is present, if so, replace the default segments. - std::vector > sections_vector; + std::vector > sections_vector; prm.get_unique_pointers("sections", sections_vector); prm.enter_subsection("sections"); @@ -488,20 +490,20 @@ namespace WorldBuilder const BoundingBox<2> & - SubductingPlate::get_surface_bounding_box () const + SubductingPlateCoordinates::get_surface_bounding_box () const { return surface_bounding_box; } void - SubductingPlate::properties(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth, - const std::vector> &properties, - const double gravity_norm, - const std::vector &entry_in_output, - std::vector &output) const + SubductingPlateCoordinates::properties(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth, + const std::vector> &properties, + const double gravity_norm, + const std::vector &entry_in_output, + std::vector &output) const { // The depth variable is the distance from the surface to the position, the depth // coordinate is the distance from the bottom of the model to the position and @@ -813,9 +815,9 @@ namespace WorldBuilder } Objects::PlaneDistances - SubductingPlate::distance_to_feature_plane(const Point<3> &position_in_cartesian_coordinates, - const Objects::NaturalCoordinate &position_in_natural_coordinates, - const double depth) const + SubductingPlateCoordinates::distance_to_feature_plane(const Point<3> &position_in_cartesian_coordinates, + const Objects::NaturalCoordinate &position_in_natural_coordinates, + const double depth) const { // The depth variable is the distance from the surface to the position, the depth // coordinate is the distance from the bottom of the model to the position and @@ -848,7 +850,7 @@ namespace WorldBuilder /** * Register plugin */ - WB_REGISTER_FEATURE(SubductingPlate, subducting plate) + WB_REGISTER_FEATURE(SubductingPlateCoordinates, subducting plate coordinates) } // namespace Features } // namespace WorldBuilder diff --git a/source/world_builder/parameters.cc b/source/world_builder/parameters.cc index 5e1b9d382..2423f3cc0 100644 --- a/source/world_builder/parameters.cc +++ b/source/world_builder/parameters.cc @@ -18,11 +18,13 @@ */ +#include "world_builder/features/continental_plate_coordinates.h" #include "world_builder/features/continental_plate_models/composition/interface.h" #include "world_builder/features/continental_plate_models/velocity/interface.h" #include "world_builder/features/continental_plate_models/grains/interface.h" #include "world_builder/features/continental_plate_models/temperature/interface.h" -#include "world_builder/features/fault.h" +#include "world_builder/features/fault_coordinates.h" +#include "world_builder/features/interface.h" #include "world_builder/features/mantle_layer_models/composition/interface.h" #include "world_builder/features/mantle_layer_models/grains/interface.h" #include "world_builder/features/mantle_layer_models/temperature/interface.h" @@ -35,7 +37,7 @@ #include "world_builder/features/plume_models/grains/interface.h" #include "world_builder/features/plume_models/temperature/interface.h" #include "world_builder/features/plume_models/velocity/interface.h" -#include "world_builder/features/subducting_plate.h" +#include "world_builder/features/subducting_plate_coordinates.h" #include "world_builder/features/subducting_plate_models/velocity/interface.h" #include "world_builder/gravity_model/interface.h" #include "world_builder/types/object.h" @@ -47,6 +49,7 @@ #include "rapidjson/mystwriter.h" #include "rapidjson/prettywriter.h" +#include #include #include @@ -1779,9 +1782,9 @@ namespace WorldBuilder { const std::string base = (strict_base + "/").append(name).append("/").append(std::to_string(i)); - const std::string value = Pointer((base + "/model").c_str()).Get(parameters)->GetString(); + std::string value_model = Pointer((base + "/model").c_str()).Get(parameters)->GetString(); - vector.push_back(std::move(T::create(value, &world))); + vector.push_back(std::move(T::create(value_model, &world))); } } else @@ -1792,9 +1795,11 @@ namespace WorldBuilder return true; } + + template<> bool - Parameters::get_unique_pointers(const std::string &name, std::vector > &vector) + Parameters::get_unique_pointers(const std::string &name, std::vector > &vector) { vector.resize(0); const std::string strict_base = this->get_full_json_path(); @@ -1804,7 +1809,25 @@ namespace WorldBuilder for (size_t i = 0; i < array->Size(); ++i ) { - vector.push_back(std::make_unique(&world)); + const std::string base = (strict_base + "/").append(name).append("/").append(std::to_string(i)); + + std::string value_model = Pointer((base + "/model").c_str()).Get(parameters)->GetString(); + + const Value *value_geometry_type_pointer = Pointer((base + "/geometry type").c_str()).Get(parameters); + + // The declarations are note yet declared, so I can't use default values. + // If no geometry type is declared, assume the geometry type is coordinates + if (value_geometry_type_pointer != nullptr) + { + value_model += " "; + value_model += value_geometry_type_pointer->GetString(); + } + else + { + value_model += " coordinates"; + } + + vector.push_back(std::move(Features::Interface::create(value_model, &world))); } } else @@ -1817,7 +1840,7 @@ namespace WorldBuilder template<> bool - Parameters::get_unique_pointers(const std::string &name, std::vector > &vector) + Parameters::get_unique_pointers(const std::string &name, std::vector > &vector) { vector.resize(0); const std::string strict_base = this->get_full_json_path(); @@ -1827,7 +1850,30 @@ namespace WorldBuilder for (size_t i = 0; i < array->Size(); ++i ) { - vector.push_back(std::make_unique(&world)); + vector.push_back(std::make_unique(&world)); + } + } + else + { + return false; + } + + return true; + } + + template<> + bool + Parameters::get_unique_pointers(const std::string &name, std::vector > &vector) + { + vector.resize(0); + const std::string strict_base = this->get_full_json_path(); + if (Pointer((strict_base + "/" + name).c_str()).Get(parameters) != nullptr) + { + Value *array = Pointer((strict_base + "/" + name).c_str()).Get(parameters); + + for (size_t i = 0; i < array->Size(); ++i ) + { + vector.push_back(std::make_unique(&world)); } } else @@ -2090,16 +2136,6 @@ namespace WorldBuilder template std::unique_ptr Parameters::get_unique_pointer(const std::string &name); - - /** - * Todo: Returns a vector of pointers to the Point<3> Type based on the provided name. - * Note that the variable with this name has to be loaded before this function is called. - */ - template bool - Parameters::get_unique_pointers(const std::string &name, - std::vector > &vector); - - /** * Todo: Returns a vector of pointers to the Point<3> Type based on the provided name. * Note that the variable with this name has to be loaded before this function is called. diff --git a/source/world_builder/world.cc b/source/world_builder/world.cc index 5bfd422f4..bfa6a0ea9 100644 --- a/source/world_builder/world.cc +++ b/source/world_builder/world.cc @@ -21,7 +21,7 @@ #include "world_builder/config.h" -#include "world_builder/features/subducting_plate.h" +#include "world_builder/features/subducting_plate_coordinates.h" #include "world_builder/gravity_model/interface.h" #include "world_builder/nan.h" #include "world_builder/point.h" diff --git a/tests/gwb-dat/app_continental_plate_3d.wb b/tests/gwb-dat/app_continental_plate_3d.wb index 30277d589..6d8dbc1c2 100644 --- a/tests/gwb-dat/app_continental_plate_3d.wb +++ b/tests/gwb-dat/app_continental_plate_3d.wb @@ -5,7 +5,7 @@ "gravity model":{"model":"uniform", "magnitude":10}, "features": [ - {"model":"continental plate", "name":"First continental plate", "max depth":250e3, "coordinates":[[-1e3,500e3],[500e3,500e3],[500e3,1000e3],[-1e3,1000e3]], + {"model":"continental plate", "geometry type": "coordinates","name":"First continental plate", "max depth":250e3, "coordinates":[[-1e3,500e3],[500e3,500e3],[500e3,1000e3],[-1e3,1000e3]], "temperature models":[{"model":"uniform", "max depth":75e3, "temperature":150}, {"model":"uniform", "min depth":75e3, "max depth":150e3, "temperature":100}, {"model":"uniform", "min depth":150e3, "max depth":225e3, "temperature":50}], diff --git a/tests/unit_tests/unit_test_world_builder.cc b/tests/unit_tests/unit_test_world_builder.cc index dfd56e54f..678388356 100644 --- a/tests/unit_tests/unit_test_world_builder.cc +++ b/tests/unit_tests/unit_test_world_builder.cc @@ -28,7 +28,7 @@ #include "world_builder/coordinate_systems/cartesian.h" #include "world_builder/coordinate_systems/interface.h" #include "world_builder/coordinate_systems/invalid.h" -#include "world_builder/features/continental_plate.h" +#include "world_builder/features/continental_plate_coordinates.h" #include "world_builder/features/interface.h" #include "world_builder/grains.h" #include "world_builder/objects/natural_coordinate.h" @@ -1155,7 +1155,7 @@ TEST_CASE("WorldBuilder Features: Interface") Contains("Internal error: Plugin with name '!not_implemented_feature!' is not found. " "The size of factories is ")); - const std::unique_ptr interface = Features::Interface::create("continental plate", &world); + const std::unique_ptr interface = Features::Interface::create("continental plate coordinates", &world); } @@ -1167,7 +1167,7 @@ TEST_CASE("WorldBuilder Features: Distance to Feature Plane") const std::string file_name = WorldBuilder::Data::WORLD_BUILDER_SOURCE_DIR + "/tests/data/subducting_plate_constant_angles_cartesian.wb"; WorldBuilder::World world1(file_name); { - std::unique_ptr subducting_plate = Features::Interface::create("Subducting Plate", &world1); + std::unique_ptr subducting_plate = Features::Interface::create("Subducting Plate coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -1196,7 +1196,7 @@ TEST_CASE("WorldBuilder Features: Distance to Feature Plane") const std::string file_name2 = WorldBuilder::Data::WORLD_BUILDER_SOURCE_DIR + "/tests/data/fault_constant_angles_cartesian.wb"; WorldBuilder::World world2(file_name2); { - std::unique_ptr fault = Features::Interface::create("Fault", &world2); + std::unique_ptr fault = Features::Interface::create("Fault coordinates", &world2); world2.parameters.enter_subsection("features"); world2.parameters.enter_subsection("2"); @@ -1234,7 +1234,7 @@ TEST_CASE("WorldBuilder Features: Continental Plate") // Check continental plate directly { - std::unique_ptr continental_plate = Features::Interface::create("continental plate", &world1); + std::unique_ptr continental_plate = Features::Interface::create("continental plate coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -1481,7 +1481,7 @@ TEST_CASE("WorldBuilder Features: Mantle layer") // Check mantle layer directly { - std::unique_ptr mantle_layer = Features::Interface::create("mantle layer", &world1); + std::unique_ptr mantle_layer = Features::Interface::create("mantle layer coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -1728,7 +1728,7 @@ TEST_CASE("WorldBuilder Features: Oceanic Plate") // Check continental plate directly { - std::unique_ptr oceanic_plate = Features::Interface::create("oceanic plate", &world1); + std::unique_ptr oceanic_plate = Features::Interface::create("oceanic plate coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -1937,7 +1937,7 @@ TEST_CASE("WorldBuilder Features: Oceanic Plate") WorldBuilder::World world2(file_name); // Check continental plate directly - const std::unique_ptr oceanic_plate = Features::Interface::create("oceanic plate", &world2); + const std::unique_ptr oceanic_plate = Features::Interface::create("oceanic plate coordinates", &world2); // Check continental plate through the world const double dtr = Consts::PI / 180.0; @@ -2115,7 +2115,7 @@ TEST_CASE("WorldBuilder Features: Subducting Plate") // Check continental plate directly (upper case should automatically turn into lower case). { - std::unique_ptr subducting_plate = Features::Interface::create("Subducting Plate", &world1); + std::unique_ptr subducting_plate = Features::Interface::create("Subducting Plate Coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -2615,7 +2615,7 @@ TEST_CASE("WorldBuilder Features: Fault") // Check continental plate directly (upper case should automatically turn into lower case). { - std::unique_ptr fault = Features::Interface::create("Fault", &world1); + std::unique_ptr fault = Features::Interface::create("Fault Coordinates", &world1); world1.parameters.enter_subsection("features"); world1.parameters.enter_subsection("2"); @@ -2884,7 +2884,7 @@ TEST_CASE("WorldBuilder Features: Fault") WorldBuilder::World world3(file_name); // Check fault directly (upper case should automatically turn into lower case). - const std::unique_ptr continental_plate = Features::Interface::create("Fault", &world3); + const std::unique_ptr continental_plate = Features::Interface::create("Fault Coordinates", &world3); // Check fault through the world position = {{0,0,800e3}}; @@ -3563,7 +3563,7 @@ TEST_CASE("WorldBuilder Types: Coordinate System") TEST_CASE("WorldBuilder Types: PluginSystem") { #define TYPE PluginSystem - Types::TYPE type("test", Features::ContinentalPlate::declare_entries, std::vector {{"test required"}}, false); + Types::TYPE type("test", Features::ContinentalPlateCoordinates::declare_entries, std::vector {{"test required"}}, false); CHECK(type.default_value == "test"); CHECK(type.required_entries[0] == "test required"); CHECK(type.allow_multiple == false);