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 SubductingPlateModels
39  {
40  namespace Composition
41  {
42  Uniform::Uniform(WorldBuilder::World *world_)
43  :
44  min_depth(NaN::DSNAN),
45  max_depth(NaN::DSNAN)
46  {
47  this->world = world_;
48  this->name = "uniform";
49  }
50 
52  = default;
53 
54  void
55  Uniform::declare_entries(Parameters &prm, const std::string & /*unused*/)
56  {
57  // Document plugin and require entries if needed.
58  // Add compositions to the required parameters.
59  prm.declare_entry("", Types::Object({"compositions"}),
60  "Uniform compositional model. Sets constant compositional field.");
61 
62  // Declare entries of this plugin
63  prm.declare_entry("min distance slab top", Types::Double(0),
64  "todo The depth in meters from which the composition of this feature is present.");
65  prm.declare_entry("max distance slab top", Types::Double(std::numeric_limits<double>::max()),
66  "todo The depth in meters to which the composition of this feature is present.");
67  prm.declare_entry("compositions", Types::Array(Types::UnsignedInt(),0),
68  "A list with the labels of the composition which are present there.");
69  prm.declare_entry("fractions", Types::Array(Types::Double(1.0),1),
70  "TA list of compositional fractions corresponding to the compositions list.");
71  prm.declare_entry("operation", Types::String("replace", std::vector<std::string> {"replace", "replace defined only", "add", "subtract"}),
72  "Whether the value should replace any value previously defined at this location (replace) or "
73  "add the value to the previously define value. Replacing implies that all compositions not "
74  "explicitly defined are set to zero. To only replace the defined compositions use the replace only defined option.");
75 
76  }
77 
78  void
80  {
81  min_depth = prm.get<double>("min distance slab top");
82  max_depth = prm.get<double>("max distance slab top");
83  compositions = prm.get_vector<unsigned int>("compositions");
84  fractions = prm.get_vector<double>("fractions");
85  operation = string_operations_to_enum(prm.get<std::string>("operation"));
86 
87  WBAssertThrow(compositions.size() == fractions.size(),
88  "There are not the same amount of compositions and fractions.");
89  }
90 
91 
92  double
93  Uniform::get_composition(const Point<3> & /*position_in_cartesian_coordinates*/,
94  const double /*depth*/,
95  const unsigned int composition_number,
96  double composition,
97  const double /*feature_min_depth*/,
98  const double /*feature_max_depth*/,
100  const AdditionalParameters & /*additional_parameters*/) const
101  {
102  if (distance_from_plane.distance_from_plane <= max_depth && distance_from_plane.distance_from_plane >= min_depth)
103  {
104  for (unsigned int i =0; i < compositions.size(); ++i)
105  {
106  if (compositions[i] == composition_number)
107  {
108  return apply_operation(operation,composition,fractions[i]);
109  }
110  }
111 
112  if (operation == Operations::REPLACE)
113  return 0.0;
114  }
115  return composition;
116  }
118  } // namespace Composition
119  } // namespace SubductingPlateModels
120  } // namespace Features
121 } // namespace WorldBuilder
122 
123 
const double DSNAN
Definition: nan.h:41
Operations string_operations_to_enum(const std::string &operation)
#define WBAssertThrow(condition, message)
Definition: assert.h:40
#define WB_REGISTER_FEATURE_SUBDUCTING_PLATE_COMPOSITION_MODEL(classname, name)
Definition: interface.h:155
double apply_operation(const Operations operation, const double old_value, const double new_value)
double get_composition(const Point< 3 > &position, const double depth, const unsigned int composition_number, double composition, 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: uniform.cc:93
void declare_entry(const std::string &name, const Types::Interface &type, const std::string &documentation)
Definition: parameters.cc:197
std::vector< T > get_vector(const std::string &name)
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:55
T get(const std::string &name)