Skip to content

Commit f304095

Browse files
committed
Add continental depth surface plugin.
1 parent 5809f03 commit f304095

File tree

2 files changed

+202
-0
lines changed
  • include/world_builder/features/continental_plate_models/topography
  • source/world_builder/features/continental_plate_models/topography

2 files changed

+202
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright (C) 2018-2024 by the authors of the World Builder code.
3+
4+
This file is part of the World Builder.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as published
8+
by the Free Software Foundation, either version 2 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License
17+
along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_MODELS_TOPOGRAPHY_DEPTH_SURFACE_H
21+
#define WORLD_BUILDER_FEATURES_CONTINENTAL_PLATE_MODELS_TOPOGRAPHY_DEPTH_SURFACE_H
22+
23+
24+
#include "world_builder/features/continental_plate_models/topography/interface.h"
25+
#include "world_builder/features/feature_utilities.h"
26+
#include "world_builder/objects/surface.h"
27+
28+
29+
namespace WorldBuilder
30+
{
31+
32+
namespace Features
33+
{
34+
using namespace FeatureUtilities;
35+
namespace ContinentalPlateModels
36+
{
37+
namespace Topography
38+
{
39+
/**
40+
* This class represents a continental plate and can implement submodules
41+
* for topography and composition. These submodules determine what
42+
* the returned topography or composition of the topography and composition
43+
* functions of this class will be.
44+
*/
45+
class DepthSurface final: public Interface
46+
{
47+
public:
48+
/**
49+
* constructor
50+
*/
51+
DepthSurface(WorldBuilder::World *world);
52+
53+
/**
54+
* Destructor
55+
*/
56+
~DepthSurface() override final;
57+
58+
/**
59+
* declare and read in the world builder file into the parameters class
60+
*/
61+
static
62+
void declare_entries(Parameters &prm, const std::string &parent_name = "");
63+
64+
/**
65+
* declare and read in the world builder file into the parameters class
66+
*/
67+
void parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) override final;
68+
69+
70+
/**
71+
* Returns a topography based on the given position, depth in the model,
72+
* gravity and current topography.
73+
*/
74+
double get_topography(const Point<3> &position,
75+
const Objects::NaturalCoordinate &position_in_natural_coordinates,
76+
double topography) const override final;
77+
78+
79+
private:
80+
// depth surface topography submodule parameters
81+
double min_depth;
82+
Objects::Surface min_depth_surface;
83+
double max_depth;
84+
Objects::Surface max_depth_surface;
85+
Objects::Surface topography_surface;
86+
Operations operation;
87+
88+
};
89+
} // namespace topography
90+
} // namespace ContinentalPlateModels
91+
} // namespace Features
92+
} // namespace WorldBuilder
93+
94+
#endif
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
Copyright (C) 2018-2024 by the authors of the World Builder code.
3+
4+
This file is part of the World Builder.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as published
8+
by the Free Software Foundation, either version 2 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License
17+
along with this program. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "world_builder/features/continental_plate_models/topography/depth_surface.h"
21+
22+
23+
#include "world_builder/features/continental_plate_models/topography/interface.h"
24+
#include "world_builder/nan.h"
25+
#include "world_builder/types/array.h"
26+
#include "world_builder/types/double.h"
27+
#include "world_builder/types/object.h"
28+
#include "world_builder/types/one_of.h"
29+
#include "world_builder/types/value_at_points.h"
30+
31+
namespace WorldBuilder
32+
{
33+
34+
using namespace Utilities;
35+
36+
namespace Features
37+
{
38+
namespace ContinentalPlateModels
39+
{
40+
namespace Topography
41+
{
42+
DepthSurface::DepthSurface(WorldBuilder::World *world_)
43+
:
44+
min_depth(NaN::DSNAN),
45+
max_depth(NaN::DSNAN),
46+
operation(Operations::REPLACE)
47+
{
48+
this->world = world_;
49+
this->name = "depth surface";
50+
}
51+
52+
DepthSurface::~DepthSurface()
53+
= default;
54+
55+
void
56+
DepthSurface::declare_entries(Parameters &prm, const std::string & /*unused*/)
57+
{
58+
// Document plugin and require entries if needed.
59+
// Add `topography` to the required parameters.
60+
prm.declare_entry("", Types::Object({"topography"}),
61+
"DepthSurface topography model. Set the topography to a constant value.");
62+
63+
// Declare entries of this plugin
64+
prm.declare_entry("min depth", Types::OneOf(Types::Double(0),
65+
Types::Array(Types::ValueAtPoints(0.,2)),
66+
Types::String("")),
67+
"The depth in meters from which the composition of this feature is present.");
68+
69+
prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()),
70+
Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(),2)),
71+
Types::String("")),
72+
"The depth in meters to which the composition of this feature is present.");
73+
74+
75+
prm.declare_entry("topography", Types::OneOf(Types::Double(0),
76+
Types::Array(Types::ValueAtPoints(0.,2)),
77+
Types::String("")),
78+
"The topography in meters.");
79+
80+
}
81+
82+
void
83+
DepthSurface::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
84+
{
85+
86+
min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
87+
min_depth = min_depth_surface.minimum;
88+
max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
89+
max_depth = max_depth_surface.maximum;
90+
operation = string_operations_to_enum(prm.get<std::string>("operation"));
91+
topography_surface = Objects::Surface(prm.get("topography",coordinates));
92+
}
93+
94+
95+
double
96+
DepthSurface::get_topography(const Point<3> & /*position_in_cartesian_coordinates*/,
97+
const Objects::NaturalCoordinate &position_in_natural_coordinates,
98+
double /*topography*/) const
99+
{
100+
return -topography_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
101+
}
102+
103+
WB_REGISTER_FEATURE_CONTINENTAL_PLATE_TOPOGRAPHY_MODEL(DepthSurface, depth surface)
104+
} // namespace Topography
105+
} // namespace ContinentalPlateModels
106+
} // namespace Features
107+
} // namespace WorldBuilder
108+

0 commit comments

Comments
 (0)