World Builder  1.1.0-pre
A geodynamic initial conditions generator
interface.h
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 
20 #ifndef WORLD_BUILDER_FEATURES_PLUME_MODELS_VELOCITY_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_PLUME_MODELS_VELOCITY_INTERFACE_H
22 
23 
26 
27 
28 namespace WorldBuilder
29 {
30  class World;
31  class Parameters;
32  template <unsigned int dim> class Point;
33 
38  namespace Features
39  {
40 
41  namespace PlumeModels
42  {
43  namespace Velocity
44  {
45  class ObjectFactory;
46 
47  class Interface
48  {
49  public:
53  Interface();
54 
58  virtual
59  ~Interface();
60 
64  static
65  void declare_entries(Parameters &prm,
66  const std::string &parent_name,
67  const std::vector<std::string> &required_entries);
68 
72  virtual
73  void parse_entries(Parameters &prm) = 0;
74 
75 
82  virtual
83  std::array<double,3> get_velocity(const Point<3> &position,
84  const Objects::NaturalCoordinate &position_in_natural_coordinates,
85  const double depth,
86  const double gravity,
87  std::array<double,3> velocity,
88  const double feature_min_depth,
89  const double feature_max_depth,
90  const double relative_distance_from_center) const = 0;
95  static void registerType(const std::string &name,
96  void ( * /*declare_entries*/)(Parameters &, const std::string &),
97  ObjectFactory *factory);
98 
99 
104  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
105 
109  std::string get_name() const
110  {
111  return name;
112  };
113 
114  protected:
119 
123  std::string name;
124 
125  private:
126  static std::map<std::string, ObjectFactory *> &get_factory_map()
127  {
128  static std::map<std::string, ObjectFactory *> factories;
129  return factories;
130  }
131 
132  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
133  {
134  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
135  return declares;
136  }
137 
138  };
139 
140 
145  {
146  public:
147  virtual std::unique_ptr<Interface> create(World *world) = 0;
148  };
149 
155 #define WB_REGISTER_FEATURE_PLUME_VELOCITY_MODEL(classname,name) \
156  class classname##Factory : public ObjectFactory { \
157  public: \
158  classname##Factory() \
159  { \
160  Interface::registerType(#name, classname::declare_entries, this); \
161  } \
162  std::unique_ptr<Interface> create(World *world) override final { \
163  return std::unique_ptr<Interface>(new classname(world)); \
164  } \
165  }; \
166  static classname##Factory global_##classname##Factory;
167 
168  } // namespace Velocity
169  } // namespace PlumeModels
170  } // namespace Features
171 } // namespace WorldBuilder
172 
173 #endif
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:41
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:126
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:132
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:71
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &), ObjectFactory *factory)
Definition: interface.cc:62
virtual 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 double relative_distance_from_center) const =0