World Builder  1.1.0-pre
A geodynamic initial conditions generator
uniform_raw.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 #include <vector>
30 
31 namespace WorldBuilder
32 {
33 
34  using namespace Utilities;
35 
36  namespace Features
37  {
38  namespace ContinentalPlateModels
39  {
40  namespace Velocity
41  {
42  UniformRaw::UniformRaw(WorldBuilder::World *world_)
43  :
44  min_depth(NaN::DSNAN),
45  max_depth(NaN::DSNAN),
46  velocity({{NaN::DSNAN,NaN::DSNAN,NaN::DSNAN}}),
47  operation(Operations::REPLACE)
48  {
49  this->world = world_;
50  this->name = "uniform raw";
51  }
52 
54  = default;
55 
56  void
57  UniformRaw::declare_entries(Parameters &prm, const std::string & /*unused*/)
58  {
59  // Document plugin and require entries if needed.
60  // Add `velocity` to the required parameters.
61  prm.declare_entry("", Types::Object({"velocity"}),
62  "Uniform velocity model. Set the velocity to a constant value.");
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("velocity", Types::Array(Types::Double(0.0),3,3),
72  "The velocity in meter per year");
73 
74  }
75 
76  void
77  UniformRaw::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates)
78  {
79 
80  min_depth_surface = Objects::Surface(prm.get("min depth",coordinates));
82  max_depth_surface = Objects::Surface(prm.get("max depth",coordinates));
84  operation = string_operations_to_enum(prm.get<std::string>("operation"));
85  std::vector<double> velocity_vec = prm.get_vector<double>("velocity");
86  velocity[0] = velocity_vec[0];
87  velocity[1] = velocity_vec[1];
88  velocity[2] = velocity_vec[2];
89  }
90 
91 
92  std::array<double,3>
93  UniformRaw::get_velocity(const Point<3> & /*position_in_cartesian_coordinates*/,
94  const Objects::NaturalCoordinate &position_in_natural_coordinates,
95  const double depth,
96  const double /*gravity*/,
97  std::array<double,3> velocity_,
98  const double /*feature_min_depth*/,
99  const double /*feature_max_depth*/) const
100  {
101  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;
102  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;
103  if (depth <= max_depth_local && depth >= min_depth_local)
104  {
105  if (depth <= max_depth && depth >= min_depth)
106  {
107  //std::cout << "velocity_ = " << velocity_[0] << ":" << velocity_[1] << ":" << velocity_[2] << ", velocity = " << velocity[0] << ":" << velocity[1] << ":" << velocity[2] << ", apply = " << apply_operation(operation,velocity_[0],velocity[0])<< std::endl;
108  return {{
109  apply_operation(operation,velocity_[0],velocity[0]),
110  apply_operation(operation,velocity_[1],velocity[1]),
111  apply_operation(operation,velocity_[2],velocity[2])
112  }
113  };
114  }
115  }
116  return velocity_;
117  }
118 
120  } // namespace Velocity
121  } // namespace ContinentalPlateModels
122  } // namespace Features
123 } // namespace WorldBuilder
124 
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform_raw.cc:57
const double DSNAN
Definition: nan.h:41
#define WB_REGISTER_FEATURE_CONTINENTAL_PLATE_VELOCITY_MODEL(classname, name)
Definition: interface.h:151
Operations string_operations_to_enum(const std::string &operation)
std::array< double, 3 > get_velocity(const Point< 3 > &position, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const double gravity, std::array< double, 3 > velocity, const double feature_min_depth, const double feature_max_depth) const override final
Definition: uniform_raw.cc:93
void parse_entries(Parameters &prm, const std::vector< Point< 2 >> &coordinates) override final
Definition: uniform_raw.cc:77
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)