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"
30 
31 
32 namespace WorldBuilder
33 {
34 
35  using namespace Utilities;
36 
37  namespace Features
38  {
39  using namespace FeatureUtilities;
40  namespace ContinentalPlateModels
41  {
42  namespace Composition
43  {
44  Uniform::Uniform(WorldBuilder::World *world_)
45  :
46  min_depth(NaN::DSNAN),
47  max_depth(NaN::DSNAN)
48  {
49  this->world = world_;
50  this->name = "uniform";
51  }
52 
54  = default;
55 
56  void
57  Uniform::declare_entries(Parameters &prm, const std::string & /*unused*/)
58  {
59  // Document plugin and require entries if needed.
60  // Add compositions to the required parameters.
61  prm.declare_entry("", Types::Object({"compositions"}),
62  "Uniform compositional model. Sets constant compositional field.");
63 
64  // Declare entries of this plugin
66  "The depth in meters from which the composition of this feature is present.");
67 
68  prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()),Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(), 2.))),
69  "The depth in meters to which the composition of this feature is present.");
70 
71  prm.declare_entry("compositions", Types::Array(Types::UnsignedInt(),0),
72  "A list with the labels of the composition which are present there.");
73 
74  prm.declare_entry("fractions", Types::Array(Types::Double(1.0),1),
75  "TA list of compositional fractions corresponding to the compositions list.");
76 
77  prm.declare_entry("operation", Types::String("replace", std::vector<std::string> {"replace", "replace defined only", "add", "subtract"}),
78  "Whether the value should replace any value previously defined at this location (replace) or "
79  "add the value to the previously define value. Replacing implies that all compositions not "
80  "explicitly defined are set to zero. To only replace the defined compositions use the replace only defined option.");
81 
82  }
83 
84  void
85  Uniform::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
86  {
87  min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
89  max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
91 
92  compositions = prm.get_vector<unsigned int>("compositions");
93  fractions = prm.get_vector<double>("fractions");
94  operation = string_operations_to_enum(prm.get<std::string>("operation"));
95 
96  WBAssertThrow(compositions.size() == fractions.size(),
97  "There are not the same amount of compositions and fractions.");
98  }
99 
100 
101  double
102  Uniform::get_composition(const Point<3> & /*position_in_cartesian_coordinates*/,
103  const Objects::NaturalCoordinate &position_in_natural_coordinates,
104  const double depth,
105  const unsigned int composition_number,
106  double composition,
107  const double /*feature_min_depth*/,
108  const double /*feature_max_depth*/) const
109  {
110  if (depth <= max_depth && depth >= min_depth)
111  {
112  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;
113  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;
114  if (depth <= max_depth_local && depth >= min_depth_local)
115  {
116  for (unsigned int i =0; i < compositions.size(); ++i)
117  {
118  if (compositions[i] == composition_number)
119  {
120  return apply_operation(operation,composition,fractions[i]);
121  }
122  }
123 
124  if (operation == Operations::REPLACE)
125  return 0.0;
126  }
127  }
128  return composition;
129  }
131  } // namespace Composition
132  } // namespace ContinentalPlateModels
133  } // namespace Features
134 } // namespace WorldBuilder
135 
136 
const double DSNAN
Definition: nan.h:41
#define WB_REGISTER_FEATURE_CONTINENTAL_PLATE_COMPOSITION_MODEL(classname, name)
Definition: interface.h:146
void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates) override final
Definition: uniform.cc:85
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:102
#define WBAssertThrow(condition, message)
Definition: assert.h:40
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:57
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)
T get(const std::string &name)