-
Notifications
You must be signed in to change notification settings - Fork 42
Add interface for topography models. #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -59,6 +59,11 @@ namespace WorldBuilder | |||||||||||||||||
| class Interface; | ||||||||||||||||||
| } // namespace GravityModel | ||||||||||||||||||
|
|
||||||||||||||||||
| namespace Topography | ||||||||||||||||||
| { | ||||||||||||||||||
| class Interface; | ||||||||||||||||||
| } // namespace GravityModel | ||||||||||||||||||
Djneu marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Topography |
||||||||||||||||||
|
|
||||||||||||||||||
| class World; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
|
@@ -275,6 +280,14 @@ namespace WorldBuilder | |||||||||||||||||
| */ | ||||||||||||||||||
| std::unique_ptr<WorldBuilder::GravityModel::Interface> gravity_model; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * A pointers to the topography model. This variable is responsible for | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pointers -> pointer |
||||||||||||||||||
| * the topography model and has ownership over it. Therefore a unique | ||||||||||||||||||
| * pointer are used. | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+284
to
+286
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a random comment as I'm looking at PRs to see what everyone has been working on :)
Suggested change
|
||||||||||||||||||
| * @see CoordinateSystem | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what are you referring to here? |
||||||||||||||||||
| */ | ||||||||||||||||||
| std::unique_ptr<WorldBuilder::Topography::Interface> topography_model; | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * This function return the current path as stored in the path variable | ||||||||||||||||||
| * as a string in json pointer format. | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,157 @@ | ||||||
| /* | ||||||
| Copyright (C) 2018-2025 by the authors of the World Builder code. | ||||||
| This file is part of the World Builder. | ||||||
| This program is free software: you can redistribute it and/or modify | ||||||
| it under the terms of the GNU Lesser General Public License as published | ||||||
| by the Free Software Foundation, either version 2 of the License, or | ||||||
| (at your option) any later version. | ||||||
| This program is distributed in the hope that it will be useful, | ||||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| GNU Lesser General Public License for more details. | ||||||
| You should have received a copy of the GNU Lesser General Public License | ||||||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
| */ | ||||||
|
|
||||||
| #ifndef WORLD_BUILDER_TOPOGRAPHY_INTERFACE_H | ||||||
| #define WORLD_BUILDER_TOPOGRAPHY_INTERFACE_H | ||||||
|
|
||||||
| #include "world_builder/topography/interface.h" | ||||||
|
|
||||||
| #include "world_builder/parameters.h" | ||||||
| #include "world_builder/types/string.h" | ||||||
| #include "world_builder/objects/natural_coordinate.h" | ||||||
|
|
||||||
|
|
||||||
| namespace WorldBuilder | ||||||
| { | ||||||
| class World; | ||||||
|
|
||||||
| namespace Topography | ||||||
| { | ||||||
|
|
||||||
| class ObjectFactory; | ||||||
|
|
||||||
| /** | ||||||
| * This class is an interface for the topography. | ||||||
| */ | ||||||
| class Interface | ||||||
| { | ||||||
| public: | ||||||
| /** | ||||||
| * Destructor | ||||||
| */ | ||||||
| virtual | ||||||
| ~Interface() = default; | ||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the topography class | ||||||
| */ | ||||||
| static | ||||||
| void declare_entries(Parameters &prm, | ||||||
| const std::string &parent_name, | ||||||
| const std::vector<std::string> &required_entries); | ||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the topography class | ||||||
| */ | ||||||
| virtual | ||||||
| void parse_entries(Parameters &prm) = 0; | ||||||
|
|
||||||
| /** | ||||||
| * A function to register a new type. This is part of the automatic | ||||||
| * registration of the object factory. | ||||||
| */ | ||||||
| static void registerType(const std::string &name, | ||||||
| void ( * /*declare_entries*/)(Parameters &, const std::string &), | ||||||
| ObjectFactory *factory); | ||||||
|
|
||||||
| /** | ||||||
| * A function to create a new type. This is part of the automatic | ||||||
| * registration of the object factory. | ||||||
| */ | ||||||
| static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world); | ||||||
|
|
||||||
| enum SurfaceType | ||||||
| { | ||||||
| reference_surface, | ||||||
| deformed_surface | ||||||
| }; | ||||||
|
|
||||||
| SurfaceType surface_type; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this variable private. The Also add documentation what this variable means. |
||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the parameters class | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment doesn't seem right? |
||||||
| */ | ||||||
| virtual | ||||||
| SurfaceType | ||||||
| get_surface_type() = 0; | ||||||
|
|
||||||
| /** | ||||||
| * Returns a temperature based on the given position, depth in the model, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * gravity and current temperature. | ||||||
| */ | ||||||
| virtual | ||||||
| double get_topography(const Point<3> &position, | ||||||
| const Objects::NaturalCoordinate &position_in_natural_coordinates, | ||||||
| const double depth) const = 0; | ||||||
|
|
||||||
| protected: | ||||||
| /** | ||||||
| * A pointer to the world class to retrieve variables. | ||||||
| */ | ||||||
| WorldBuilder::World *world; | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| private: | ||||||
| static std::map<std::string, ObjectFactory *> &get_factory_map() | ||||||
| { | ||||||
| static std::map<std::string, ObjectFactory *> factories; | ||||||
| return factories; | ||||||
| } | ||||||
|
|
||||||
| static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map() | ||||||
| { | ||||||
| static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares; | ||||||
| return declares; | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| /** | ||||||
| * A class to create new objects | ||||||
| */ | ||||||
| class ObjectFactory | ||||||
| { | ||||||
| public: | ||||||
| virtual std::unique_ptr<Interface> create(World *world) = 0; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * A macro which should be in every derived cpp file to automatically | ||||||
| * register it. Because this is a library, we need some extra measures | ||||||
| * to ensure that the static variable is actually initialized. | ||||||
| */ | ||||||
| #define WB_REGISTER_TOPOGRAPHY(klass,name) \ | ||||||
| class klass##Factory : public ObjectFactory { \ | ||||||
| public: \ | ||||||
| klass##Factory() \ | ||||||
| { \ | ||||||
| Interface::registerType(#name, klass::declare_entries, this); \ | ||||||
| } \ | ||||||
| std::unique_ptr<Interface> create(World *world) override final { \ | ||||||
| return std::unique_ptr<Interface>(new klass(world)); \ | ||||||
| } \ | ||||||
| }; \ | ||||||
| static klass##Factory global_##klass##Factory; | ||||||
|
|
||||||
| } // namespace Topography | ||||||
| } // namespace WorldBuilder | ||||||
|
|
||||||
| #endif | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,87 @@ | ||||||
| /* | ||||||
| Copyright (C) 2018-2025 by the authors of the World Builder code. | ||||||
| This file is part of the World Builder. | ||||||
| This program is free software: you can redistribute it and/or modify | ||||||
| it under the terms of the GNU Lesser General Public License as published | ||||||
| by the Free Software Foundation, either version 2 of the License, or | ||||||
| (at your option) any later version. | ||||||
| This program is distributed in the hope that it will be useful, | ||||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| GNU Lesser General Public License for more details. | ||||||
| You should have received a copy of the GNU Lesser General Public License | ||||||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
| */ | ||||||
|
|
||||||
| #ifndef WORLD_BUILDER_TOPOGRAPHY_MINIMUM_DEPTH_H | ||||||
| #define WORLD_BUILDER_TOPOGRAPHY_MINIMUM_DEPTH_H | ||||||
|
|
||||||
| #include "world_builder/topography/interface.h" | ||||||
|
|
||||||
| #include "world_builder/utilities.h" | ||||||
| #include "world_builder/objects/natural_coordinate.h" | ||||||
|
|
||||||
|
|
||||||
| namespace WorldBuilder | ||||||
| { | ||||||
|
|
||||||
| namespace Topography | ||||||
| { | ||||||
| /** | ||||||
| * This implements a minimum depth topography. The minimum depth topography | ||||||
| * finds the minimum depth of a feature and uses that for the topography. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| */ | ||||||
| class Uniform final : public Interface | ||||||
| { | ||||||
| public: | ||||||
| /** | ||||||
| * Constructor | ||||||
| */ | ||||||
| Uniform(WorldBuilder::World *world); | ||||||
|
|
||||||
| /** | ||||||
| * Destructor | ||||||
| */ | ||||||
| ~ Uniform() override final; | ||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the topography class | ||||||
| */ | ||||||
| static | ||||||
| void declare_entries(Parameters &prm, const std::string &parent_name = ""); | ||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the topography class | ||||||
| */ | ||||||
| void parse_entries(Parameters &prm) override final; | ||||||
|
|
||||||
| /** | ||||||
| * declare and read in the world builder file into the topography class | ||||||
|
Comment on lines
+52
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments are all the same, which makes them less informative. Maybe make them more specific to the functions? |
||||||
| */ | ||||||
| SurfaceType | ||||||
| get_surface_type() override final; | ||||||
|
|
||||||
| /** | ||||||
| * Returns a temperature based on the given position, depth in the model, | ||||||
| * gravity and current temperature. | ||||||
| */ | ||||||
| double get_topography(const Point<3> &position, | ||||||
| const Objects::NaturalCoordinate &position_in_natural_coordinates, | ||||||
| const double depth) const override final; | ||||||
|
|
||||||
| private: | ||||||
|
|
||||||
| /** | ||||||
| * Whether to consider a reference or deformed surface. | ||||||
| */ | ||||||
| SurfaceType surface_type; | ||||||
|
|
||||||
| }; | ||||||
| } // namespace Topography | ||||||
| } // namespace WorldBuilder | ||||||
|
|
||||||
| #endif | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| Copyright (C) 2018-2024 by the authors of the World Builder code. | ||
|
|
||
| This file is part of the World Builder. | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Lesser General Public License as published | ||
| by the Free Software Foundation, either version 2 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Lesser General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Lesser General Public License | ||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "world_builder/topography/interface.h" | ||
|
|
||
| #include "world_builder/types/object.h" | ||
|
|
||
| #include <algorithm> | ||
|
|
||
| namespace WorldBuilder | ||
| { | ||
| namespace Topography | ||
| { | ||
| void | ||
| Interface::declare_entries(Parameters &prm, const std::string &parent_name, const std::vector<std::string> &required_entries) | ||
| { | ||
|
|
||
| unsigned int counter = 0; | ||
| for (auto &it : get_declare_map()) | ||
| { | ||
| prm.enter_subsection("oneOf"); | ||
| { | ||
| prm.enter_subsection(std::to_string(counter)); | ||
| { | ||
| prm.enter_subsection("properties"); | ||
| { | ||
| prm.declare_entry("", Types::Object(required_entries), "topography"); | ||
|
|
||
| prm.declare_entry("model",Types::String("",it.first), | ||
| "The name of the model for topography to use."); | ||
|
|
||
| it.second(prm, parent_name); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
| } | ||
| prm.leave_subsection(); | ||
|
|
||
| counter++; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| void | ||
| Interface::registerType(const std::string &name, | ||
| void ( *declare_entries)(Parameters &, const std::string &), | ||
| ObjectFactory *factory) | ||
| { | ||
| get_factory_map()[name] = factory; | ||
| get_declare_map()[name] = declare_entries; | ||
| } | ||
|
|
||
| std::unique_ptr<Interface> | ||
| Interface::create(const std::string &name, WorldBuilder::World *world) | ||
| { | ||
| std::string lower_case_name; | ||
| std::transform(name.begin(), | ||
| name.end(), | ||
| std::back_inserter(lower_case_name), | ||
| ::tolower);; | ||
|
|
||
| // Have a nice assert message to check whether a plugin exists in the case | ||
| // of a debug compilation. | ||
| WBAssertThrow(get_factory_map().find(lower_case_name) != get_factory_map().end(), | ||
| "Internal error: Plugin with name '" << lower_case_name << "' is not found. " | ||
| "The size of factories is " << get_factory_map().size() << "."); | ||
|
|
||
| // Using at() because the [] will just insert values | ||
| // which is undesirable in this case. An exception is | ||
| // thrown when the name is not present. | ||
| return get_factory_map().at(lower_case_name)->create(world); | ||
| } | ||
| } // namespace Topography | ||
| } // namespace WorldBuilder | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.