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_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>
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();
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
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
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  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 
189  template <typename InitialTemperatureType>
191  InitialTemperatureType *
192  find_initial_temperature_model () const;
193 
200  template <typename InitialTemperatureType>
201  bool
202  has_matching_initial_temperature_model () const;
203 
212  template <typename InitialTemperatureType>
213  const InitialTemperatureType &
214  get_matching_initial_temperature_model () const;
215 
216 
226  static
227  void
228  write_plugin_graph (std::ostream &output_stream);
229 
233  DeclException1 (ExcInitialTemperatureNameNotFound,
234  std::string,
235  << "Could not find entry <"
236  << arg1
237  << "> among the names of registered initial temperature objects.");
238  private:
243  std::list<std::unique_ptr<Interface<dim> > > initial_temperature_objects;
244 
249  std::vector<std::string> model_names;
250 
257  std::vector<aspect::Utilities::Operator> model_operators;
258  };
259 
260 
261 
262  template <int dim>
263  template <typename InitialTemperatureType>
264  inline
265  InitialTemperatureType *
267  {
268  for (const auto &p : initial_temperature_objects)
269  if (InitialTemperatureType *x = dynamic_cast<InitialTemperatureType *> ( (*p).get()) )
270  return x;
271  return nullptr;
272  }
273 
274 
275  template <int dim>
276  template <typename InitialTemperatureType>
277  inline
278  bool
280  {
281  for (const auto &p : initial_temperature_objects)
282  if (Plugins::plugin_type_matches<InitialTemperatureType>(*p))
283  return true;
284  return false;
285  }
286 
287 
288  template <int dim>
289  template <typename InitialTemperatureType>
290  inline
291  const InitialTemperatureType &
293  {
294  AssertThrow(has_matching_initial_temperature_model<InitialTemperatureType> (),
295  ExcMessage("You asked InitialTemperature::Manager::get_initial_temperature_model() for a "
296  "initial temperature model of type <" + boost::core::demangle(typeid(InitialTemperatureType).name()) + "> "
297  "that could not be found in the current model. Activate this "
298  "initial temperature model in the input file."));
299 
300  typename std::list<std::unique_ptr<Interface<dim> > >::const_iterator initial_temperature_model;
301  for (typename std::list<std::unique_ptr<Interface<dim> > >::const_iterator
302  p = initial_temperature_objects.begin();
303  p != initial_temperature_objects.end(); ++p)
304  if (Plugins::plugin_type_matches<InitialTemperatureType>(*(*p)))
305  return Plugins::get_plugin_as_type<InitialTemperatureType>(*(*p));
306 
307  // We will never get here, because we had the Assert above. Just to avoid warnings.
308  return Plugins::get_plugin_as_type<InitialTemperatureType>(*(*initial_temperature_model));
309  }
310 
311 
318  template <int dim>
319  std::string
321 
322 
323 
331 #define ASPECT_REGISTER_INITIAL_TEMPERATURE_MODEL(classname,name,description) \
332  template class classname<2>; \
333  template class classname<3>; \
334  namespace ASPECT_REGISTER_INITIAL_TEMPERATURE_MODEL_ ## classname \
335  { \
336  aspect::internal::Plugins::RegisterHelper<aspect::InitialTemperature::Interface<2>,classname<2> > \
337  dummy_ ## classname ## _2d (&aspect::InitialTemperature::Manager<2>::register_initial_temperature, \
338  name, description); \
339  aspect::internal::Plugins::RegisterHelper<aspect::InitialTemperature::Interface<3>,classname<3> > \
340  dummy_ ## classname ## _3d (&aspect::InitialTemperature::Manager<3>::register_initial_temperature, \
341  name, description); \
342  }
343  }
344 }
345 
346 
347 #endif
StructuredDataLookup< dim > DEAL_II_DEPRECATED
std::string get_valid_model_names_pattern()
#define AssertThrow(cond, exc)
void write_plugin_graph(std::ostream &output_stream)
bool has_matching_initial_temperature_model() const
Definition: interface.h:279
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< std::string > model_names
Definition: interface.h:249
std::vector< aspect::Utilities::Operator > model_operators
Definition: interface.h:257
DEAL_II_DEPRECATED InitialTemperatureType * find_initial_temperature_model() const
std::list< std::unique_ptr< Interface< dim > > > initial_temperature_objects
Definition: interface.h:243
const InitialTemperatureType & get_matching_initial_temperature_model() const
Definition: interface.h:292
void declare_parameters(ParameterHandler &prm)
DeclException1(ExcARKodeError, int,<< "One of the SUNDIALS ARKode internal functions "<< " returned a negative error code: "<< arg1<< ". Please consult SUNDIALS manual.")