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_temperature_interface_h
23 #define _aspect_initial_temperature_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 InitialTemperature
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_temperature (const Point<dim> &position) 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 
109  template <int dim>
110  class Manager : public ::aspect::SimulatorAccess<dim>
111  {
112  public:
117  ~Manager () override;
118 
123  static
124  void
125  declare_parameters (ParameterHandler &prm);
126 
132  void
133  parse_parameters (ParameterHandler &prm);
134 
140  double
141  initial_temperature (const Point<dim> &position) const;
142 
160  static
161  void
162  register_initial_temperature (const std::string &name,
163  const std::string &description,
164  void (*declare_parameters_function) (ParameterHandler &),
165  std::unique_ptr<Interface<dim>> (*factory_function) ());
166 
167 
172  const std::vector<std::string> &
173  get_active_initial_temperature_names () const;
174 
179  const std::list<std::unique_ptr<Interface<dim>>> &
180  get_active_initial_temperature_conditions () const;
181 
191  template <typename InitialTemperatureType,
192  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,InitialTemperatureType>::value>>
193  bool
194  has_matching_initial_temperature_model () const;
195 
207  template <typename InitialTemperatureType,
208  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,InitialTemperatureType>::value>>
209  const InitialTemperatureType &
210  get_matching_initial_temperature_model () const;
211 
212 
222  static
223  void
224  write_plugin_graph (std::ostream &output_stream);
225 
229  DeclException1 (ExcInitialTemperatureNameNotFound,
230  std::string,
231  << "Could not find entry <"
232  << arg1
233  << "> among the names of registered initial temperature objects.");
234  private:
239  std::list<std::unique_ptr<Interface<dim>>> initial_temperature_objects;
240 
245  std::vector<std::string> model_names;
246 
253  std::vector<aspect::Utilities::Operator> model_operators;
254  };
255 
256 
257 
258  template <int dim>
259  template <typename InitialTemperatureType, typename>
260  inline
261  bool
263  {
264  for (const auto &p : initial_temperature_objects)
265  if (Plugins::plugin_type_matches<InitialTemperatureType>(*p))
266  return true;
267  return false;
268  }
269 
270 
271  template <int dim>
272  template <typename InitialTemperatureType, typename>
273  inline
274  const InitialTemperatureType &
276  {
277  AssertThrow(has_matching_initial_temperature_model<InitialTemperatureType> (),
278  ExcMessage("You asked InitialTemperature::Manager::get_initial_temperature_model() for a "
279  "initial temperature model of type <" + boost::core::demangle(typeid(InitialTemperatureType).name()) + "> "
280  "that could not be found in the current model. Activate this "
281  "initial temperature model in the input file."));
282 
283  typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator initial_temperature_model;
284  for (typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator
285  p = initial_temperature_objects.begin();
286  p != initial_temperature_objects.end(); ++p)
287  if (Plugins::plugin_type_matches<InitialTemperatureType>(*(*p)))
288  return Plugins::get_plugin_as_type<InitialTemperatureType>(*(*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<InitialTemperatureType>(*(*initial_temperature_model));
292  }
293 
294 
301  template <int dim>
302  std::string
304 
305 
306 
314 #define ASPECT_REGISTER_INITIAL_TEMPERATURE_MODEL(classname,name,description) \
315  template class classname<2>; \
316  template class classname<3>; \
317  namespace ASPECT_REGISTER_INITIAL_TEMPERATURE_MODEL_ ## classname \
318  { \
319  aspect::internal::Plugins::RegisterHelper<aspect::InitialTemperature::Interface<2>,classname<2>> \
320  dummy_ ## classname ## _2d (&aspect::InitialTemperature::Manager<2>::register_initial_temperature, \
321  name, description); \
322  aspect::internal::Plugins::RegisterHelper<aspect::InitialTemperature::Interface<3>,classname<3>> \
323  dummy_ ## classname ## _3d (&aspect::InitialTemperature::Manager<3>::register_initial_temperature, \
324  name, description); \
325  }
326  }
327 }
328 
329 
330 #endif
bool has_matching_initial_temperature_model() const
Definition: interface.h:262
std::string get_valid_model_names_pattern()
void write_plugin_graph(std::ostream &output_stream)
const InitialTemperatureType & get_matching_initial_temperature_model() const
Definition: interface.h:275
std::vector< std::string > model_names
Definition: interface.h:245
std::vector< aspect::Utilities::Operator > model_operators
Definition: interface.h:253
std::list< std::unique_ptr< Interface< dim > > > initial_temperature_objects
Definition: interface.h:239
void declare_parameters(ParameterHandler &prm)
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.")