World Builder  1.1.0-pre
A geodynamic initial conditions generator
linear.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"
27 #include "world_builder/world.h"
28 
29 
30 namespace WorldBuilder
31 {
32  using namespace Utilities;
33 
34  namespace Features
35  {
36  namespace FaultModels
37  {
38  namespace Temperature
39  {
41  :
42  min_depth(NaN::DSNAN),
43  max_depth(NaN::DSNAN),
44  center_temperature(NaN::DSNAN),
45  side_temperature(NaN::DSNAN),
46  operation(Operations::REPLACE)
47  {
48  this->world = world_;
49  this->name = "linear";
50  }
51 
53  = default;
54 
55  void
56  Linear::declare_entries(Parameters &prm, const std::string & /*unused*/)
57  {
58  // Document plugin and require entries if needed.
59  // Add `max distance fault` center to the required parameters.
60  prm.declare_entry("", Types::Object({"max distance fault center"}),
61  "Linear temperature model. Can be set to use an adiabatic temperature at the boundaries.");
62 
63  // Declare entries of this plugin
64  prm.declare_entry("min distance fault center", Types::Double(0),
65  "The minimum distance to the center of the fault. This determines where the linear temperature starts.");
66 
67  prm.declare_entry("max distance fault center", Types::Double(std::numeric_limits<double>::max()),
68  "The minimum distance to the center of the fault. This determines where the linear temperature end.");
69 
70  prm.declare_entry("center temperature", Types::Double(293.15),
71  "The temperature at the center of this feature in degree Kelvin."
72  "If the value is below zero, the an adiabatic temperature is used.");
73 
74  prm.declare_entry("side temperature", Types::Double(-1),
75  "The temperature at the sides of this feature in degree Kelvin. "
76  "If the value is below zero, an adiabatic temperature is used.");
77 
78  }
79 
80  void
82  {
83  min_depth = prm.get<double>("min distance fault center");
84  max_depth = prm.get<double>("max distance fault center");
85  WBAssert(max_depth >= min_depth, "max depth needs to be larger or equal to min depth.");
86  operation = string_operations_to_enum(prm.get<std::string>("operation"));
87  center_temperature = prm.get<double>("center temperature");
88  side_temperature = prm.get<double>("side temperature");
89  }
90 
91 
92  double
93  Linear::get_temperature(const Point<3> & /*position_in_cartesian_coordinates*/,
94  const double /*depth*/,
95  const double gravity_norm,
96  double temperature_,
97  const double /*feature_min_depth*/,
98  const double /*feature_max_depth*/,
100  const AdditionalParameters & /*additional_parameters*/) const
101  {
102 
103  if (std::fabs(distance_from_planes.distance_from_plane) <= max_depth && std::fabs(distance_from_planes.distance_from_plane) >= min_depth)
104  {
105  const double min_depth_local = min_depth;
106  const double max_depth_local = max_depth;
107 
108  double center_temperature_local = center_temperature;
109  if (center_temperature_local < 0)
110  {
111  center_temperature_local = this->world->potential_mantle_temperature *
112  std::exp(((this->world->thermal_expansion_coefficient * gravity_norm) /
113  this->world->specific_heat) * min_depth_local);
114  }
115 
116  double side_temperature_local = side_temperature;
117  if (side_temperature_local < 0)
118  {
119  side_temperature_local = this->world->potential_mantle_temperature *
120  std::exp(((this->world->thermal_expansion_coefficient * gravity_norm) /
121  this->world->specific_heat) * max_depth_local);
122  }
123 
124  const double new_temperature = center_temperature_local +
125  (std::fabs(distance_from_planes.distance_from_plane) - min_depth_local) *
126  ((side_temperature_local - center_temperature_local) / (max_depth_local - min_depth_local));
127 
128  return apply_operation(operation,temperature_,new_temperature);
129 
130  }
131 
132  return temperature_;
133  }
134 
136  } // namespace Temperature
137  } // namespace FaultModels
138  } // namespace Features
139 } // namespace WorldBuilder
140 
#define WB_REGISTER_FEATURE_FAULT_TEMPERATURE_MODEL(classname, name)
Definition: interface.h:155
const double DSNAN
Definition: nan.h:41
double get_temperature(const Point< 3 > &position, const double depth, const double gravity, double temperature, const double feature_min_depth, const double feature_max_depth, const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes &distance_from_planes, const AdditionalParameters &additional_parameters) const override final
Definition: linear.cc:93
double potential_mantle_temperature
Definition: world.h:268
Operations string_operations_to_enum(const std::string &operation)
#define WBAssert(condition, message)
Definition: assert.h:27
void parse_entries(Parameters &prm) override final
Definition: linear.cc:81
double thermal_expansion_coefficient
Definition: world.h:283
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)
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: linear.cc:56