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_SUBDUCTING_PLATE_MODELS_TEMPERATURE_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_MODELS_TEMPERATURE_INTERFACE_H
22 
23 #include "world_builder/grains.h"
27 
28 #include <map>
29 #include <vector>
30 
31 namespace WorldBuilder
32 {
33  class World;
34  class Parameters;
35  template <unsigned int dim> class Point;
36 
41  namespace Features
42  {
43  using namespace FeatureUtilities;
44 
45  namespace SubductingPlateModels
46  {
47  namespace Temperature
48  {
49  class ObjectFactory;
50 
51  class Interface
52  {
53  public:
57  Interface();
58 
62  virtual
63  ~Interface();
64 
68  static
69  void declare_entries(Parameters &prm,
70  const std::string &parent_name,
71  const std::vector<std::string> &required_entries);
72 
76  virtual
77  void parse_entries(Parameters &prm) = 0;
78 
79 
83  virtual
84  double get_temperature(const Point<3> &position,
85  const double depth,
86  const double gravity,
87  double temperature,
88  const double feature_min_depth,
89  const double feature_max_depth,
91  const AdditionalParameters &additional_parameters) const = 0;
96  static void registerType(const std::string &name,
97  void ( * /*declare_entries*/)(Parameters &, const std::string &),
98  ObjectFactory *factory);
99 
100 
105  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
106 
110  std::string get_name() const
111  {
112  return name;
113  };
114 
115  protected:
120 
124  std::string name;
125 
126  private:
127  static std::map<std::string, ObjectFactory *> &get_factory_map()
128  {
129  static std::map<std::string, ObjectFactory *> factories;
130  return factories;
131  }
132 
133  static std::map<std::string, void ( *)(Parameters &,const std::string &)> &get_declare_map()
134  {
135  static std::map<std::string, void ( *)(Parameters &,const std::string &)> declares;
136  return declares;
137  }
138 
139  };
140 
141 
146  {
147  public:
148  virtual std::unique_ptr<Interface> create(World *world) = 0;
149  };
150 
156 #define WB_REGISTER_FEATURE_SUBDUCTING_PLATE_TEMPERATURE_MODEL(classname,name) \
157  class classname##Factory : public ObjectFactory { \
158  public: \
159  classname##Factory() \
160  { \
161  Interface::registerType(#name, classname::declare_entries, this); \
162  } \
163  std::unique_ptr<Interface> create(World *world) override final { \
164  return std::unique_ptr<Interface>(new classname(world)); \
165  } \
166  }; \
167  static classname##Factory global_##classname##Factory;
168 
169  } // namespace Temperature
170  } // namespace SubductingPlateModels
171  } // namespace Features
172 } // namespace WorldBuilder
173 
174 #endif
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:127
static std::map< std::string, void(*)(Parameters &, const std::string &)> & get_declare_map()
Definition: interface.h:133