World Builder  1.1.0-pre
A geodynamic initial conditions generator
adiabatic.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 SubductingPlateModels
37  {
38  namespace Temperature
39  {
40  Adiabatic::Adiabatic(WorldBuilder::World *world_)
41  :
42  min_depth(NaN::DSNAN),
43  max_depth(NaN::DSNAN),
44  potential_mantle_temperature(NaN::DSNAN),
45  thermal_expansion_coefficient(NaN::DSNAN),
46  specific_heat(NaN::DSNAN),
47  operation(Operations::REPLACE)
48  {
49  this->world = world_;
50  this->name = "adiabatic";
51  }
52 
54  = default;
55 
56  void
57  Adiabatic::declare_entries(Parameters &prm, const std::string & /*unused*/)
58  {
59  // Document plugin and require entries if needed.
60  prm.declare_entry("", Types::Object(),
61  "Adiabatic temperature model. Uses global values by default.");
62 
63  // Declare entries of this plugin
64  prm.declare_entry("min distance slab top", Types::Double(0),
65  "todo The depth in meters from which the composition of this feature is present.");
66 
67  prm.declare_entry("max distance slab top", Types::Double(std::numeric_limits<double>::max()),
68  "todo The depth in meters to which the composition of this feature is present.");
69 
70  prm.declare_entry("potential mantle temperature", Types::Double(-1),
71  "The potential temperature of the mantle at the surface in Kelvin. "
72  "If the value is lower then zero, the global value is used.");
73 
74  prm.declare_entry("thermal expansion coefficient", Types::Double(-1),
75  "The thermal expansion coefficient in $K^{-1}$. "
76  "If the value is lower then zero, the global value is used.");
77 
78  prm.declare_entry("specific heat", Types::Double(-1),
79  "The specific heat in $J kg^{-1} K^{-1}$. "
80  "If the value is lower then zero, the global value is used.");
81 
82  }
83 
84  void
86  {
87 
88  min_depth = prm.get<double>("min distance slab top");
89  max_depth = prm.get<double>("max distance slab top");
90  operation = string_operations_to_enum(prm.get<std::string>("operation"));
91 
92  potential_mantle_temperature = prm.get<double>("potential mantle temperature");
95 
96 
97  thermal_expansion_coefficient = prm.get<double>("thermal expansion coefficient");
100 
101  specific_heat = prm.get<double>("specific heat");
102  if (specific_heat < 0)
104 
105  // Some assertions in debug mode can't hurt and have helped before.
107  "potential_mantle_temperature is not a number: " << potential_mantle_temperature << '.');
108  WBAssert(std::isfinite(potential_mantle_temperature),
109  "potential_mantle_temperature is not a finite: " << potential_mantle_temperature << '.');
110 
112  "thermal_expansion_coefficient is not a number: " << thermal_expansion_coefficient << '.');
114  "thermal_expansion_coefficient is not a finite: " << thermal_expansion_coefficient << '.');
115 
116  WBAssert(!std::isnan(specific_heat),
117  "specific_heat is not a number: " << specific_heat << '.');
119  "specific_heat is not a finite: " << specific_heat << '.');
120 
121  }
122 
123 
124  double
125  Adiabatic::get_temperature(const Point<3> & /*position_in_cartesian_coordinates*/,
126  const double depth,
127  const double gravity_norm,
128  double temperature_,
129  const double /*feature_min_depth*/,
130  const double /*feature_max_depth*/,
131  const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes &distance_from_planes,
132  const AdditionalParameters & /*additional_parameters*/) const
133  {
134 
135  const double distance_from_plane = distance_from_planes.distance_from_plane;
136  if (distance_from_plane <= max_depth && distance_from_plane >= min_depth)
137  {
138  const double adabatic_temperature = potential_mantle_temperature *
139  std::exp(((thermal_expansion_coefficient * gravity_norm) /
140  specific_heat) * depth);
141 
142 
143  WBAssert(!std::isnan(adabatic_temperature),
144  "adabatic_temperature is not a number: " << adabatic_temperature << ". "
145  <<"Parameters: potential_mantle_temperature = " << potential_mantle_temperature
146  <<", thermal_expansion_coefficient = " << thermal_expansion_coefficient
147  << ", gravity_norm = " << gravity_norm
148  << ", specific_heat = " << specific_heat
149  << ", depth = " << depth);
150 
151  WBAssert(std::isfinite(adabatic_temperature),
152  "adabatic_temperature is not a finite: " << adabatic_temperature << '.');
153 
154  return apply_operation(operation,temperature_,adabatic_temperature);
155  }
156 
157 
158  return temperature_;
159  }
160 
162  } // namespace Temperature
163  } // namespace SubductingPlateModels
164  } // namespace Features
165 } // namespace WorldBuilder
166 
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: adiabatic.cc:57
const double DSNAN
Definition: nan.h:41
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
double specific_heat
Definition: world.h:288
#define WB_REGISTER_FEATURE_SUBDUCTING_PLATE_TEMPERATURE_MODEL(classname, name)
Definition: interface.h:156
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: adiabatic.cc:125
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)