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 
23 #include "world_builder/world.h"
24 
25 
26 namespace WorldBuilder
27 {
28  namespace GravityModel
29  {
31  {
32  this->world = world_;
33  }
34 
36  = default;
37 
38  void
39  Uniform::declare_entries(Parameters &prm, const std::string & /*unused*/)
40  {
41  // Add depth method to the required parameters.
42  prm.declare_entry("", Types::Object(),
43  "Uniform gravity model. It returns the gravity vector in a Cartesian coordinate system at "
44  "a given position, which has a constant magitude for the whole domain. The vector points "
45  "down in cartesian coordinates and to the center of the sphere in spherical coordinates.");
46 
47  prm.declare_entry("magnitude",
48  Types::Double(9.81), "The magnitude of the gravity.");
49  }
50 
51  void
53  {
54  gravity_magnitude = prm.get<double>("magnitude");
55  }
56 
57 
58  Point<3>
60  {
61  const CoordinateSystem coordinate_system = world->parameters.coordinate_system->natural_coordinate_system();
62 
63  switch (coordinate_system)
64  {
67  break;
68 
70  return (point/point.norm())*-gravity_magnitude;
71  break;
72 
73  default:
74  WBAssertThrow(false, "Invalid coordinate system when using the gravity vector function.");
75  }
76 
78  }
79 
80 
81  double
83  {
84  return gravity_magnitude;
85  }
86 
87 
92  } // namespace GravityModel
93 } // namespace WorldBuilder
94 
virtual double gravity_norm(Point< 3 > point) const override final
Definition: uniform.cc:82
#define WB_REGISTER_GRAVITY_MODEL(classname, name)
Definition: interface.h:133
WorldBuilder::World * world
Definition: interface.h:99
const double DSNAN
Definition: nan.h:41
void parse_entries(Parameters &prm) override final
Definition: uniform.cc:52
Uniform(WorldBuilder::World *world)
Definition: uniform.cc:30
double norm() const
Definition: point.h:413
virtual Point< 3 > gravity_vector(Point< 3 > point) const override final
Definition: uniform.cc:59
static void declare_entries(Parameters &prm, const std::string &parent_name="")
Definition: uniform.cc:39
#define WBAssertThrow(condition, message)
Definition: assert.h:40
std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > coordinate_system
Definition: parameters.h:268
void declare_entry(const std::string &name, const Types::Interface &type, const std::string &documentation)
Definition: parameters.cc:197
Parameters parameters
Definition: world.h:253
T get(const std::string &name)