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_INTERFACE_H
21 #define WORLD_BUILDER_FEATURES_INTERFACE_H
22 
23 
24 #include "world_builder/grains.h"
27 
28 namespace WorldBuilder
29 {
30  class World;
31  class Parameters;
32 
33 
34  namespace Features
35  {
36  class ObjectFactory;
37 
42  class Interface
43  {
44  public:
48  Interface();
49 
53  virtual
54  ~Interface();
55 
59  void
60  get_coordinates(const std::string &name,
61  Parameters &prm,
62  const CoordinateSystem coordinate_system);
63 
67  static
68  void declare_entries(Parameters &prm,
69  const std::string &parent_name,
70  const std::vector<std::string> &required_entries);
71 
75  virtual
76  void parse_entries(Parameters &prm) = 0;
77 
78 
82  virtual
83  void properties(const Point<3> &position_in_cartesian_coordinates,
84  const Objects::NaturalCoordinate &position_in_natural_coordinates,
85  const double depth,
86  const std::vector<std::array<unsigned int,3>> &properties,
87  const double gravity,
88  const std::vector<size_t> &entry_in_output,
89  std::vector<double> &output) const = 0;
90 
95  static void registerType(const std::string &name,
96  void ( * /*declare_entries*/)(Parameters &, const std::string &, const std::vector<std::string> &required_entries),
97  void ( *make_snippet)(Parameters &),
98  ObjectFactory *factory);
99 
100  std::string get_name() const
101  {
102  return name;
103  };
104 
105 
110  static std::unique_ptr<Interface> create(const std::string &name, WorldBuilder::World *world);
111 
116  virtual
118  distance_to_feature_plane(const Point<3> &position_in_cartesian_coordinates,
119  const Objects::NaturalCoordinate &position_in_natural_coordinates,
120  const double depth) const;
121 
122 
123  protected:
128 
132  std::string name;
133 
138  size_t tag_index;
139 
144 
150 
154  std::vector<Point<2> > coordinates;
155 
160 
161 
166 
171 
172 
173  private:
174  static std::map<std::string, ObjectFactory *> &get_factory_map()
175  {
176  static std::map<std::string, ObjectFactory *> factories;
177  return factories;
178  }
179 
180  static std::map<std::string, void ( *)(Parameters &,
181  const std::string &,
182  const std::vector<std::string>& required_entries)> &get_declare_map()
183  {
184  static std::map<std::string, void ( *)(Parameters &,
185  const std::string &,
186  const std::vector<std::string>& required_entries)> declares;
187  return declares;
188  }
189 
190  static std::map<std::string, void ( *)(Parameters &)> &get_snippet_map()
191  {
192  static std::map<std::string, void ( *)(Parameters &)> declares;
193  return declares;
194  }
195  };
196 
197 
202  {
203  public:
204  virtual std::unique_ptr<Interface> create(World *world) = 0;
205  };
206 
212 #define WB_REGISTER_FEATURE(classname,name) \
213  class classname##Factory : public ObjectFactory { \
214  public: \
215  classname##Factory() \
216  { \
217  Interface::registerType(#name, classname::declare_entries, classname::make_snippet, this); \
218  } \
219  std::unique_ptr<Interface> create(World *world) override final { \
220  return std::unique_ptr<Interface>(new classname(world)); \
221  } \
222  }; \
223  static classname##Factory global_##classname##Factory;
224 
225  } // namespace Features
226 } // namespace WorldBuilder
227 
228 #endif
static std::map< std::string, void(*)(Parameters &, const std::string &, const std::vector< std::string > &required_entries)> & get_declare_map()
Definition: interface.h:182
static std::map< std::string, void(*)(Parameters &)> & get_snippet_map()
Definition: interface.h:190
Class for circle line/spline, including interpolation on it.
Definition: bezier_curve.h:37
std::string get_name() const
Definition: interface.h:100
WorldBuilder::Objects::BezierCurve bezier_curve
Definition: interface.h:159
virtual Objects::PlaneDistances distance_to_feature_plane(const Point< 3 > &position_in_cartesian_coordinates, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth) const
Definition: interface.cc:200
static std::map< std::string, ObjectFactory * > & get_factory_map()
Definition: interface.h:174
void get_coordinates(const std::string &name, Parameters &prm, const CoordinateSystem coordinate_system)
Definition: interface.cc:140
static void registerType(const std::string &name, void(*)(Parameters &, const std::string &, const std::vector< std::string > &required_entries), void(*make_snippet)(Parameters &), ObjectFactory *factory)
static void declare_entries(Parameters &prm, const std::string &parent_name, const std::vector< std::string > &required_entries)
Definition: interface.cc:67
virtual void properties(const Point< 3 > &position_in_cartesian_coordinates, const Objects::NaturalCoordinate &position_in_natural_coordinates, const double depth, const std::vector< std::array< unsigned int, 3 >> &properties, const double gravity, const std::vector< size_t > &entry_in_output, std::vector< double > &output) const =0
static std::unique_ptr< Interface > create(const std::string &name, WorldBuilder::World *world)
Definition: interface.cc:179
WorldBuilder::World * world
Definition: interface.h:127
WorldBuilder::Utilities::InterpolationType interpolation_type
Definition: interface.h:143
std::size_t original_number_of_coordinates
Definition: interface.h:149
std::vector< Point< 2 > > coordinates
Definition: interface.h:154
virtual void parse_entries(Parameters &prm)=0