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 PlumeModels
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
65  prm.declare_entry("min depth", Types::Double(0),
66  "The depth in meters from which the composition of this feature is present.");
67  prm.declare_entry("max depth", Types::Double(std::numeric_limits<double>::max()),
68  "The depth in meters to which the composition of this feature is present.");
69 
70  prm.declare_entry("compositions", Types::Array(Types::UnsignedInt(),0),
71  "A list with the labels of the composition which are present there.");
72 
73  prm.declare_entry("fractions", Types::Array(Types::Double(1.0),1),
74  "TA list of compositional fractions corresponding to the compositions list.");
75 
76  prm.declare_entry("operation", Types::String("replace", std::vector<std::string> {"replace", "replace defined only", "add", "subtract"}),
77  "Whether the value should replace any value previously defined at this location (replace) or "
78  "add the value to the previously define value. Replacing implies that all compositions not "
79  "explicitly defined are set to zero. To only replace the defined compositions use the replace only defined option.");
80 
81  }
82 
83  void
85  {
86  min_depth = prm.get<double>("min depth");
87  max_depth = prm.get<double>("max depth");
88 
89  compositions = prm.get_vector<unsigned int>("compositions");
90  fractions = prm.get_vector<double>("fractions");
91  operation = string_operations_to_enum(prm.get<std::string>("operation"));
92 
93  WBAssertThrow(compositions.size() == fractions.size(),
94  "There are not the same amount of compositions and fractions.");
95  }
96 
97 
98  double
99  Uniform::get_composition(const Point<3> & /*position_in_cartesian_coordinates*/,
100  const Objects::NaturalCoordinate & /*position_in_natural_coordinates*/,
101  const double depth,
102  const unsigned int composition_number,
103  double composition,
104  const double /*feature_min_depth*/,
105  const double /*feature_max_depth*/) const
106  {
107  if (depth <= max_depth && depth >= min_depth)
108  {
109 
110  for (unsigned int i =0; i < compositions.size(); ++i)
111  {
112  if (compositions[i] == composition_number)
113  {
114  return apply_operation(operation,composition,fractions[i]);
115  }
116  }
117 
118  if (operation == Operations::REPLACE)
119  return 0.0;
120  }
121  return composition;
122  }
124  } // namespace Composition
125  } // namespace PlumeModels
126  } // namespace Features
127 } // namespace WorldBuilder
128 
129 
void parse_entries(Parameters &prm) override final
Definition: uniform.cc:84
const double DSNAN
Definition: nan.h:41
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:99
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:57
#define WB_REGISTER_FEATURE_PLUME_COMPOSITION_MODEL(classname, name)
Definition: interface.h:146
Operations string_operations_to_enum(const std::string &operation)
#define WBAssertThrow(condition, message)
Definition: assert.h:40
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)