|
| 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/oceanic_plate_models/topography/depth_surface.h" |
| 21 | + |
| 22 | + |
| 23 | +#include "world_builder/features/oceanic_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 OceanicPlateModels |
| 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_OCEANIC_PLATE_TOPOGRAPHY_MODEL(DepthSurface, depth surface) |
| 104 | + } // namespace Topography |
| 105 | + } // namespace OceanicPlateModels |
| 106 | + } // namespace Features |
| 107 | +} // namespace WorldBuilder |
| 108 | + |
0 commit comments