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