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