ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2023 by the authors of the ASPECT code.
3 
4  This file is part of ASPECT.
5 
6  ASPECT is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2, or (at your option)
9  any later version.
10 
11  ASPECT 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 General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with ASPECT; see the file LICENSE. If not see
18  <http://www.gnu.org/licenses/>.
19 */
20 
21 
22 #ifndef _aspect_initial_composition_interface_h
23 #define _aspect_initial_composition_interface_h
24 
25 #include <aspect/plugins.h>
26 #include <aspect/utilities.h>
28 
29 #include <deal.II/base/point.h>
30 #include <deal.II/base/parameter_handler.h>
31 
32 #include <boost/core/demangle.hpp>
33 #include <typeinfo>
34 
35 
36 namespace aspect
37 {
38  template <int dim> class SimulatorAccess;
39 
46  namespace InitialComposition
47  {
48  using namespace dealii;
49 
55  template <int dim>
56  class Interface
57  {
58  public:
63  virtual ~Interface() = default;
64 
70  virtual
71  void
72  initialize ();
73 
77  virtual
78  double initial_composition (const Point<dim> &position, const unsigned int n_comp) const = 0;
79 
80 
87  static
88  void
89  declare_parameters (ParameterHandler &prm);
90 
97  virtual
98  void
99  parse_parameters (ParameterHandler &prm);
100 
101  };
102 
103 
104 
110  template <int dim>
111  class Manager : public ::aspect::SimulatorAccess<dim>
112  {
113  public:
118  ~Manager () override;
119 
124  static
125  void
126  declare_parameters (ParameterHandler &prm);
127 
133  void
134  parse_parameters (ParameterHandler &prm);
135 
142  double
143  initial_composition (const Point<dim> &position,
144  const unsigned int n_comp) const;
145 
163  static
164  void
165  register_initial_composition (const std::string &name,
166  const std::string &description,
167  void (*declare_parameters_function) (ParameterHandler &),
168  std::unique_ptr<Interface<dim>> (*factory_function) ());
169 
170 
175  const std::vector<std::string> &
176  get_active_initial_composition_names () const;
177 
182  const std::list<std::unique_ptr<Interface<dim>>> &
183  get_active_initial_composition_conditions () const;
184 
194  template <typename InitialCompositionType,
195  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,InitialCompositionType>::value>>
196  bool
197  has_matching_initial_composition_model () const;
198 
210  template <typename InitialCompositionType,
211  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,InitialCompositionType>::value>>
212  const InitialCompositionType &
213  get_matching_initial_composition_model () const;
214 
224  static
225  void
226  write_plugin_graph (std::ostream &output_stream);
227 
231  DeclException1 (ExcInitialCompositionNameNotFound,
232  std::string,
233  << "Could not find entry <"
234  << arg1
235  << "> among the names of registered initial composition objects.");
236  private:
241  std::list<std::unique_ptr<Interface<dim>>> initial_composition_objects;
242 
247  std::vector<std::string> model_names;
248 
255  std::vector<aspect::Utilities::Operator> model_operators;
256  };
257 
258 
259 
260  template <int dim>
261  template <typename InitialCompositionType, typename>
262  inline
263  bool
265  {
266  for (const auto &p : initial_composition_objects)
267  if (Plugins::plugin_type_matches<InitialCompositionType>(*p))
268  return true;
269  return false;
270  }
271 
272 
273  template <int dim>
274  template <typename InitialCompositionType, typename>
275  inline
276  const InitialCompositionType &
278  {
279  AssertThrow(has_matching_initial_composition_model<InitialCompositionType> (),
280  ExcMessage("You asked InitialComposition::Manager::get_initial_composition_model() for a "
281  "initial composition model of type <" + boost::core::demangle(typeid(InitialCompositionType).name()) + "> "
282  "that could not be found in the current model. Activate this "
283  "initial composition model in the input file."));
284 
285  typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator initial_composition_model;
286  for (const auto &p : initial_composition_objects)
287  if (Plugins::plugin_type_matches<InitialCompositionType>(*p))
288  return Plugins::get_plugin_as_type<InitialCompositionType>(*p);
289 
290  // We will never get here, because we had the Assert above. Just to avoid warnings.
291  return Plugins::get_plugin_as_type<InitialCompositionType>(*(*initial_composition_model));
292  }
293 
294 
303  template <int dim>
304  std::string
306 
307 
308 
316 #define ASPECT_REGISTER_INITIAL_COMPOSITION_MODEL(classname,name,description) \
317  template class classname<2>; \
318  template class classname<3>; \
319  namespace ASPECT_REGISTER_INITIAL_COMPOSITION_MODEL_ ## classname \
320  { \
321  aspect::internal::Plugins::RegisterHelper<aspect::InitialComposition::Interface<2>,classname<2>> \
322  dummy_ ## classname ## _2d (&aspect::InitialComposition::Manager<2>::register_initial_composition, \
323  name, description); \
324  aspect::internal::Plugins::RegisterHelper<aspect::InitialComposition::Interface<3>,classname<3>> \
325  dummy_ ## classname ## _3d (&aspect::InitialComposition::Manager<3>::register_initial_composition, \
326  name, description); \
327  }
328  }
329 }
330 
331 
332 #endif
std::list< std::unique_ptr< Interface< dim > > > initial_composition_objects
Definition: interface.h:241
void write_plugin_graph(std::ostream &output_stream)
const InitialCompositionType & get_matching_initial_composition_model() const
Definition: interface.h:277
std::string get_valid_model_names_pattern()
void declare_parameters(ParameterHandler &prm)
std::vector< std::string > model_names
Definition: interface.h:247
bool has_matching_initial_composition_model() const
Definition: interface.h:264
std::vector< aspect::Utilities::Operator > model_operators
Definition: interface.h:255
Definition: compat.h:42
DeclException1(ProbabilityFunctionNegative, Point< dim >,<< "Your probability density function in the particle generator " "returned a negative probability density for the following position: "<< arg1<< ". Please check your function expression.")