World Builder  1.1.0-pre
A geodynamic initial conditions generator
half_space_model.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/consts.h"
24 #include "world_builder/nan.h"
32 #include "world_builder/world.h"
33 #include <cstdint>
34 
35 
36 namespace WorldBuilder
37 {
38  using namespace Utilities;
39 
40  namespace Features
41  {
42  namespace OceanicPlateModels
43  {
44  namespace Temperature
45  {
46  HalfSpaceModel::HalfSpaceModel(WorldBuilder::World *world_)
47  :
48  min_depth(NaN::DSNAN),
49  max_depth(NaN::DSNAN),
50  top_temperature(NaN::DSNAN),
51  bottom_temperature(NaN::DSNAN),
52  operation(Operations::REPLACE)
53  {
54  this->world = world_;
55  this->name = "half space model";
56  }
57 
59  = default;
60 
61  void
62  HalfSpaceModel::declare_entries(Parameters &prm, const std::string & /*unused*/)
63  {
64  // Document plugin and require entries if needed.
65  // Add `ridge coordinates`, `spreading velocity`, `max depth` to the required parameters.
66  prm.declare_entry("", Types::Object({"ridge coordinates", "spreading velocity", "max depth"}),
67  "Half space cooling mode");
68 
69  // Declare entries of this plugin
71  "The depth in meters from which the temperature of this feature is present.");
72 
73  prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(), 2.))),
74  "The depth in meters to which the temperature of this feature is present."
75  "Because half-space reaches background temperature asymptotically, "
76  "this value should be ~2 times the nominal plate thickness of 100 km" );
77 
78  prm.declare_entry("top temperature", Types::Double(293.15),
79  "The actual surface temperature in degree Kelvin for this feature.");
80 
81  prm.declare_entry("bottom temperature", Types::Double(-1),
82  "The mantle temperature for the half-space cooling model"
83  "in degree Kelvin for this feature. If the model has an adiabatic gradient"
84  "this should be the mantle potential temperature, and T = Tad + Thalf. ");
85 
86  prm.declare_entry("spreading velocity", Types::OneOf(Types::Double(0.05),Types::Array(Types::ValueAtPoints(0.05, std::numeric_limits<uint64_t>::max()))),
87  "The spreading velocity of the plate in meter per year. "
88  "This is the velocity with which one side moves away from the ridge.");
89 
90  prm.declare_entry("ridge coordinates", Types::Array(Types::Array(Types::Point<2>(), 2),1),
91  "An list of ridges. Each ridge is a lists of at least 2 2d points which "
92  "define the location of the ridge. You need to define at least one ridge."
93  "So the an example with two ridges is "
94  "[[[10,20],[20,30],[10,40]],[[50,10],[60,10]]].");
95  }
96 
97  void
98  HalfSpaceModel::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
99  {
100 
101  min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
103  max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
105  operation = string_operations_to_enum(prm.get<std::string>("operation"));
106  top_temperature = prm.get<double>("top temperature");
107  bottom_temperature = prm.get<double>("bottom temperature");
108  spreading_velocities = prm.get_value_at_array("spreading velocity");
109 
110  mid_oceanic_ridges = prm.get_vector<std::vector<Point<2>>>("ridge coordinates");
111  const double dtr = prm.coordinate_system->natural_coordinate_system() == spherical ? Consts::PI / 180.0 : 1.0;
112  for (auto &ridge_coordinates : mid_oceanic_ridges)
113  for (auto &ridge_coordinate : ridge_coordinates)
114  {
115  ridge_coordinate *= dtr;
116  }
117 
118  unsigned int ridge_point_index = 0;
119  for (const auto &mid_oceanic_ridge : mid_oceanic_ridges)
120  {
121  std::vector<double> spreading_rates_for_ridge;
122  for (unsigned int index_y = 0; index_y < mid_oceanic_ridge.size(); index_y++)
123  {
124  if (spreading_velocities.second.size() <= 1)
125  {
126  spreading_rates_for_ridge.push_back(spreading_velocities.second[0]);
127  }
128  else
129  {
130  spreading_rates_for_ridge.push_back(spreading_velocities.second[ridge_point_index]);
131  }
132  ridge_point_index += 1;
133  }
134  spreading_velocities_at_each_ridge_point.push_back(spreading_rates_for_ridge);
135  }
136  }
137 
138  double
140  const Objects::NaturalCoordinate &position_in_natural_coordinates,
141  const double depth,
142  const double gravity_norm,
143  double temperature_,
144  const double /*feature_min_depth*/,
145  const double /*feature_max_depth*/) const
146  {
147  if (depth <= max_depth && depth >= min_depth)
148  {
149  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;
150  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;
151  if (depth <= max_depth_local && depth >= min_depth_local)
152  {
153  Objects::NaturalCoordinate position_in_natural_coordinates_at_min_depth = Objects::NaturalCoordinate(position,
155  position_in_natural_coordinates_at_min_depth.get_ref_depth_coordinate() += depth-min_depth;
156  std::vector<std::vector<double>> subducting_plate_velocities = {{0}};
157  std::vector<double> ridge_migration_times = {0.0};
158 
159  double bottom_temperature_local = bottom_temperature;
160 
161  if (bottom_temperature_local < 0)
162  {
163  bottom_temperature_local = this->world->potential_mantle_temperature *
164  std::exp(((this->world->thermal_expansion_coefficient* gravity_norm) /
165  this->world->specific_heat) * depth);
166  }
167 
168  std::vector<double> ridge_parameters = Utilities::calculate_ridge_distance_and_spreading(mid_oceanic_ridges,
171  position_in_natural_coordinates_at_min_depth,
172  subducting_plate_velocities,
173  ridge_migration_times);
174 
175 
176 
177  const double thermal_diffusivity = this->world->thermal_diffusivity;
178  const double age = ridge_parameters[1] / ridge_parameters[0];
179 
180  double temperature = bottom_temperature_local;
181 
182  temperature = temperature + (age > 0 ? (top_temperature - bottom_temperature_local)*std::erfc(depth/(2*std::sqrt(thermal_diffusivity*age))) : 0.);
183 
184  WBAssert(!std::isnan(temperature), "Temperature inside half-space cooling model is not a number: " << temperature
185  << ". Relevant variables: bottom_temperature_local = " << bottom_temperature_local
186  << ", top_temperature = " << top_temperature
187  << ", max_depth = " << max_depth
188  << ", spreading_velocity = " << ridge_parameters[0]
189  << ", thermal_diffusivity = " << thermal_diffusivity
190  << ", age = " << age << '.');
191  WBAssert(std::isfinite(temperature), "Temperature inside half-space cooling model is not a finite: " << temperature << ". Relevant variables: bottom_temperature_local = " << bottom_temperature_local
192  << ", top_temperature = " << top_temperature
193  << ", spreading_velocity = " << ridge_parameters[0]
194  << ", thermal_diffusivity = " << thermal_diffusivity
195  << ", age = " << age << '.');
196 
197 
198  return apply_operation(operation,temperature_,temperature);
199 
200  }
201  }
202  return temperature_;
203  }
204 
206  } // namespace Temperature
207  } // namespace OceanicPlateModels
208  } // namespace Features
209 } // namespace WorldBuilder
210 
const double DSNAN
Definition: nan.h:41
double potential_mantle_temperature
Definition: world.h:268
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
Operations string_operations_to_enum(const std::string &operation)
std::vector< double > calculate_ridge_distance_and_spreading(std::vector< std::vector< Point< 2 >>> mid_oceanic_ridges, std::vector< std::vector< double >> mid_oceanic_spreading_velocities, const std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > &coordinate_system, const Objects::NaturalCoordinate &position_in_natural_coordinates_at_min_depth, const std::vector< std::vector< double >> &subducting_plate_velocities, const std::vector< double > &ridge_migration_times)
Definition: utilities.cc:1290
#define WBAssert(condition, message)
Definition: assert.h:27
#define WB_REGISTER_FEATURE_OCEANIC_PLATE_TEMPERATURE_MODEL(classname, name)
Definition: interface.h:151
void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates) override final
double thermal_diffusivity
Definition: world.h:293
static void declare_entries(Parameters &prm, const std::string &parent_name="")
SurfaceValueInfo local_value(const Point< 2 > &check_point) const
Definition: surface.cc:149
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
Definition: parameters.h:268
double thermal_expansion_coefficient
Definition: world.h:283
std::pair< std::vector< double >, std::vector< double > > get_value_at_array(const std::string &name)
Definition: parameters.cc:719
double apply_operation(const Operations operation, const double old_value, const double new_value)
constexpr double PI
Definition: consts.h:30
void declare_entry(const std::string &name, const Types::Interface &type, const std::string &documentation)
Definition: parameters.cc:197
Parameters parameters
Definition: world.h:253
std::vector< T > get_vector(const std::string &name)
T get(const std::string &name)
std::pair< std::vector< double >, std::vector< double > > spreading_velocities