World Builder  0.1.0-pre
A geodyanmic initial conditions generator
continental_plate.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018 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 
20 #include <boost/algorithm/string.hpp>
21 
24 #include <world_builder/assert.h>
25 #include <world_builder/nan.h>
27 
28 
29 namespace WorldBuilder
30 {
31  using namespace Utilities;
32 
33  namespace Features
34  {
35  ContinentalPlate::ContinentalPlate(WorldBuilder::World *world_)
36  :
37  temperature_submodule_depth(NaN::DSNAN),
38  temperature_submodule_temperature(NaN::DSNAN),
39  composition_submodule_depth(NaN::DSNAN),
40  composition_submodule_composition(NaN::ISNAN)
41  {
42  this->world = world_;
43  this->name = "continental plate";
44  }
45 
47  { }
48 
49 
50  void
52  {
53  Parameters &prm = this->world->parameters;
54  //prm.enter_subsection("continental plate");
55  {
56 
57  prm.load_entry("name", true, Types::String("","The name which the user has given to the feature."));
58  name = prm.get_string("name");
59  bool set = prm.load_entry("coordinates", true, Types::Array(
60  Types::Point<2>(Point<2>(0,0),"desciption point cross section"),
61  "An array of Points representing an array of coordinates where the feature is located."));
62 
63  WBAssertThrow(set == true, "A list of coordinates is required for every feature.");
64 
65  std::vector<const Types::Point<2>* > typed_coordinates = prm.get_array<const Types::Point<2> >("coordinates");
66 
67  coordinates.resize(typed_coordinates.size());
68  for (unsigned int i = 0; i < typed_coordinates.size(); ++i)
69  {
70  coordinates[i] = typed_coordinates[i]->value;
71  }
72 
73  prm.enter_subsection("temperature submodule");
74  {
75  prm.load_entry("name", true, Types::String("","The name of the temperature submodule."));
77 
78  if (temperature_submodule_name == "constant")
79  {
80  prm.load_entry("depth", true, Types::Double(NaN::DSNAN,"The depth to which the temperature of this feature is present."));
81  temperature_submodule_depth = prm.get_double("depth");
82 
83  prm.load_entry("temperature", true, Types::Double(0,"The temperature which this feature should have"));
84  temperature_submodule_temperature = prm.get_double("temperature");
85  }
86 
87  }
88  prm.leave_subsection();
89 
90  prm.enter_subsection("composition submodule");
91  {
92  prm.load_entry("name", true, Types::String("","The name of the composition submodule used."));
94 
95  if (composition_submodule_name == "constant")
96  {
97  prm.load_entry("depth", true, Types::Double(NaN::DSNAN,"The depth to which the composition of this feature is present."));
98  composition_submodule_depth = prm.get_double("depth");
99 
100  prm.load_entry("composition", true, Types::UnsignedInt(0,"The number of the composition that is present there."));
101  composition_submodule_composition = prm.get_unsigned_int("composition");
102  }
103  }
104  prm.leave_subsection();
105 
106  }
107  //prm.leave_subsection();
108  }
109 
110 
111  double
113  const double depth,
114  const double /*gravity*/,
115  double temperature) const
116  {
117  if (temperature_submodule_name == "constant")
118  {
120  // The constant temperature module should be used for this.
121  if (depth <= temperature_submodule_depth &&
123  {
124  // We are in the the area where the contintal plate is defined. Set the constant temperature.
125  return temperature_submodule_temperature;
126  }
127 
128  }
129  else if (temperature_submodule_name == "none")
130  {
131  return temperature;
132  }
133  else
134  {
135  WBAssertThrow(false,"Given temperature module does not exist: " + temperature_submodule_name);
136  }
137 
138  return temperature;
139  }
140 
141  bool
143  const double depth,
144  const unsigned int composition_number,
145  bool composition) const
146  {
147  if (composition_submodule_name == "constant")
148  {
150  // The constant temperature module should be used for this.
151  if (depth <= composition_submodule_depth &&
153  {
154  // We are in the the area where the contintal plate is defined. Set the constant temperature.
155  if (composition_submodule_composition == composition_number)
156  {
157  return true;
158  }
159  }
160 
161  }
162  else if (composition_submodule_name == "none")
163  {
164  return composition;
165  }
166  else
167  {
168  WBAssertThrow(false,"Given composition module does not exist: " + composition_submodule_name);
169  }
170 
171  return composition;
172  }
173  }
174 }
175 
virtual bool composition(const Point< 3 > &position, const double depth, const unsigned int composition_number, bool temperature) const
const std::array< double, 2 > get_surface_coordinates() const
Definition: utilities.cc:240
const double DSNAN
Definition: nan.h:29
virtual double temperature(const Point< 3 > &position, const double depth, const double gravity, double temperature) const
const Types::Array & get_array(const std::string &name) const
Definition: parameters.cc:551
virtual void decare_entries(std::string &path)
std::string get_string(const std::string &name) const
Definition: parameters.cc:524
void enter_subsection(const std::string name)
Definition: parameters.cc:495
bool load_entry(const std::string &name, const bool required, const Types::Interface &type)
Definition: parameters.cc:56
WorldBuilder::World * world
Definition: interface.h:90
#define WBAssertThrow(condition, message)
Definition: assert.h:41
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
Definition: parameters.h:321
bool polygon_contains_point(const std::vector< Point< 2 > > &point_list, const Point< 2 > &point)
Definition: utilities.cc:32
const double ISNAN
Definition: nan.h:34
Parameters parameters
Definition: world.h:72
unsigned int get_unsigned_int(const std::string &name) const
Definition: parameters.cc:508
std::vector< Point< 2 > > coordinates
Definition: interface.h:100
double get_double(const std::string &name) const
Definition: parameters.cc:516