World Builder  1.1.0-pre
A geodynamic initial conditions generator
uniform.cc
Go to the documentation of this file.
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 
21 
22 #include "world_builder/nan.h"
28 
29 
30 namespace WorldBuilder
31 {
32 
33  using namespace Utilities;
34 
35  namespace Features
36  {
37  namespace OceanicPlateModels
38  {
39  namespace Temperature
40  {
41  Uniform::Uniform(WorldBuilder::World *world_)
42  :
43  min_depth(NaN::DSNAN),
44  max_depth(NaN::DSNAN),
45  temperature(NaN::DSNAN),
46  operation(Operations::REPLACE)
47  {
48  this->world = world_;
49  this->name = "uniform";
50  }
51 
53  = default;
54 
55  void
56  Uniform::declare_entries(Parameters &prm, const std::string & /*unused*/)
57  {
58  // Document plugin and require entries if needed.
59  // Add `temperature` and to the required parameters.
60  prm.declare_entry("", Types::Object({"temperature"}),
61  "Uniform temperature model. Set the temperature to a constant value.");
62 
63  // Declare entries of this plugin
65  "The depth in meters from which the temperature of this feature is present.");
66 
67  prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(), 2.))),
68  "The depth in meters to which the temperature of this feature is present.");
69 
70  prm.declare_entry("temperature", Types::Double(293.15),
71  "The temperature in degree Kelvin which this feature should have");
72 
73  }
74 
75  void
76  Uniform::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
77  {
78 
79  min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
81  max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
83  operation = string_operations_to_enum(prm.get<std::string>("operation"));
84  temperature = prm.get<double>("temperature");
85  }
86 
87 
88  double
89  Uniform::get_temperature(const Point<3> & /*position_in_cartesian_coordinates*/,
90  const Objects::NaturalCoordinate &position_in_natural_coordinates,
91  const double depth,
92  const double /*gravity*/,
93  double temperature_,
94  const double /*feature_min_depth*/,
95  const double /*feature_max_depth*/) const
96  {
97 
98  if (depth <= max_depth && depth >= min_depth)
99  {
100  const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
101  const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value;
102  if (depth <= max_depth_local && depth >= min_depth_local)
103  {
104  return apply_operation(operation,temperature_,temperature);
105  }
106  }
107 
108  return temperature_;
109  }
110 
112  } // namespace Temperature
113  } // namespace OceanicPlateModels
114  } // namespace Features
115 } // namespace WorldBuilder
116 
void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates) override final
Definition: uniform.cc:76
const double DSNAN
Definition: nan.h:41
Operations string_operations_to_enum(const std::string &operation)
double get_temperature(const Point< 3 > &position, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const double gravity, double temperature, const double feature_min_depth, const double feature_max_depth) const override final
Definition: uniform.cc:89
#define WB_REGISTER_FEATURE_OCEANIC_PLATE_TEMPERATURE_MODEL(classname, name)
Definition: interface.h:151
SurfaceValueInfo local_value(const Point< 2 > &check_point) const
Definition: surface.cc:149
double apply_operation(const Operations operation, const double old_value, const double new_value)
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:56
void declare_entry(const std::string &name, const Types::Interface &type, const std::string &documentation)
Definition: parameters.cc:197
T get(const std::string &name)