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 #include "world_builder/nan.h"
29 
30 
31 namespace WorldBuilder
32 {
33 
34  using namespace Utilities;
35 
36  namespace Features
37  {
38  namespace OceanicPlateModels
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
64  "The depth in meters from which the composition of this feature is present.");
65  prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(), 2.))),
66  "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
79  Uniform::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
80  {
81  min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
83  max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
85  compositions = prm.get_vector<unsigned int>("compositions");
86  fractions = prm.get_vector<double>("fractions");
87  operation = string_operations_to_enum(prm.get<std::string>("operation"));
88 
89  WBAssertThrow(compositions.size() == fractions.size(),
90  "There are not the same amount of compositions and fractions.");
91  }
92 
93 
94  double
95  Uniform::get_composition(const Point<3> & /*position_in_cartesian_coordinates*/,
96  const Objects::NaturalCoordinate &position_in_natural_coordinates,
97  const double depth,
98  const unsigned int composition_number,
99  double composition,
100  const double /*feature_min_depth*/,
101  const double /*feature_max_depth*/) const
102  {
103  if (depth <= max_depth && depth >= min_depth)
104  {
105  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;
106  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;
107  if (depth <= max_depth_local && depth >= min_depth_local)
108  {
109  for (unsigned int i =0; i < compositions.size(); ++i)
110  {
111  if (compositions[i] == composition_number)
112  {
113  return apply_operation(operation,composition,fractions[i]);
114  }
115  }
116 
117  if (operation == Operations::REPLACE)
118  return 0.0;
119  }
120  }
121  return composition;
122  }
124  } // namespace Composition
125  } // namespace OceanicPlateModels
126  } // namespace Features
127 } // namespace WorldBuilder
128 
129 
#define WB_REGISTER_FEATURE_OCEANIC_PLATE_COMPOSITION_MODEL(classname, name)
Definition: interface.h:150
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:55
const double DSNAN
Definition: nan.h:41
Operations string_operations_to_enum(const std::string &operation)
double get_composition(const Point< 3 > &position, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const unsigned int composition_number, double composition, const double feature_min_depth, const double feature_max_depth) const override final
Definition: uniform.cc:95
#define WBAssertThrow(condition, message)
Definition: assert.h:40
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
std::vector< T > get_vector(const std::string &name)
void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates) override final
Definition: uniform.cc:79
T get(const std::string &name)