ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2019 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  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 
192  template <typename InitialCompositionType>
194  InitialCompositionType *
195  find_initial_composition_model () const;
196 
203  template <typename InitialCompositionType>
204  bool
205  has_matching_initial_composition_model () const;
206 
215  template <typename InitialCompositionType>
216  const InitialCompositionType &
217  get_matching_initial_composition_model () const;
218 
228  static
229  void
230  write_plugin_graph (std::ostream &output_stream);
231 
235  DeclException1 (ExcInitialCompositionNameNotFound,
236  std::string,
237  << "Could not find entry <"
238  << arg1
239  << "> among the names of registered initial composition objects.");
240  private:
245  std::list<std::unique_ptr<Interface<dim>>> initial_composition_objects;
246 
251  std::vector<std::string> model_names;
252 
259  std::vector<aspect::Utilities::Operator> model_operators;
260  };
261 
262 
263 
274  template <int dim>
275  template <typename InitialCompositionType>
276  inline
277  InitialCompositionType *
279  {
280  for (const auto &p : initial_composition_objects)
281  if (InitialCompositionType *x = dynamic_cast<InitialCompositionType *> ( p.get()) )
282  return x;
283  return nullptr;
284  }
285 
286 
287  template <int dim>
288  template <typename InitialCompositionType>
289  inline
290  bool
292  {
293  for (const auto &p : initial_composition_objects)
294  if (Plugins::plugin_type_matches<InitialCompositionType>(*p))
295  return true;
296  return false;
297  }
298 
299 
300  template <int dim>
301  template <typename InitialCompositionType>
302  inline
303  const InitialCompositionType &
305  {
306  AssertThrow(has_matching_initial_composition_model<InitialCompositionType> (),
307  ExcMessage("You asked InitialComposition::Manager::get_initial_composition_model() for a "
308  "initial composition model of type <" + boost::core::demangle(typeid(InitialCompositionType).name()) + "> "
309  "that could not be found in the current model. Activate this "
310  "initial composition model in the input file."));
311 
312  typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator initial_composition_model;
313  for (const auto &p : initial_composition_objects)
314  if (Plugins::plugin_type_matches<InitialCompositionType>(*p))
315  return Plugins::get_plugin_as_type<InitialCompositionType>(*p);
316 
317  // We will never get here, because we had the Assert above. Just to avoid warnings.
318  return Plugins::get_plugin_as_type<InitialCompositionType>(*(*initial_composition_model));
319  }
320 
321 
330  template <int dim>
331  std::string
333 
334 
335 
343 #define ASPECT_REGISTER_INITIAL_COMPOSITION_MODEL(classname,name,description) \
344  template class classname<2>; \
345  template class classname<3>; \
346  namespace ASPECT_REGISTER_INITIAL_COMPOSITION_MODEL_ ## classname \
347  { \
348  aspect::internal::Plugins::RegisterHelper<aspect::InitialComposition::Interface<2>,classname<2>> \
349  dummy_ ## classname ## _2d (&aspect::InitialComposition::Manager<2>::register_initial_composition, \
350  name, description); \
351  aspect::internal::Plugins::RegisterHelper<aspect::InitialComposition::Interface<3>,classname<3>> \
352  dummy_ ## classname ## _3d (&aspect::InitialComposition::Manager<3>::register_initial_composition, \
353  name, description); \
354  }
355  }
356 }
357 
358 
359 #endif
StructuredDataLookup< dim > DEAL_II_DEPRECATED
std::list< std::unique_ptr< Interface< dim > > > initial_composition_objects
Definition: interface.h:245
void write_plugin_graph(std::ostream &output_stream)
DEAL_II_DEPRECATED InitialCompositionType * find_initial_composition_model() const
const InitialCompositionType & get_matching_initial_composition_model() const
Definition: interface.h:304
std::string get_valid_model_names_pattern()
void declare_parameters(ParameterHandler &prm)
std::vector< std::string > model_names
Definition: interface.h:251
std::vector< aspect::Utilities::Operator > model_operators
Definition: interface.h:259
bool has_matching_initial_composition_model() const
Definition: interface.h:291
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.")