ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2022 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_heating_model_interface_h
23 #define _aspect_heating_model_interface_h
24 
25 #include <aspect/plugins.h>
28 #include <aspect/utilities.h>
29 
30 #include <deal.II/base/point.h>
31 #include <deal.II/base/parameter_handler.h>
32 
33 #include <boost/core/demangle.hpp>
34 #include <typeinfo>
35 
36 
37 namespace aspect
38 {
39  template <int dim> class SimulatorAccess;
46  namespace HeatingModel
47  {
48  using namespace dealii;
49 
57  {
68  HeatingModelOutputs (const unsigned int n_points,
69  const unsigned int n_comp);
70 
78  std::vector<double> heating_source_terms;
79 
99  std::vector<double> rates_of_temperature_change;
100 
105  std::vector<double> lhs_latent_heat_terms;
106 
112  void
113  reset ();
114  };
115 
121  template <int dim>
122  class Interface
123  {
124  public:
129  virtual ~Interface() = default;
130 
136  virtual
137  void
138  initialize ();
139 
151  virtual
152  void
153  update ();
154 
170  virtual
171  void
172  evaluate (const MaterialModel::MaterialModelInputs<dim> &material_model_inputs,
173  const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs,
174  HeatingModel::HeatingModelOutputs &heating_model_outputs) const;
175 
180  virtual
181  double
182  specific_heating_rate (const double temperature,
183  const double pressure,
184  const std::vector<double> &compositional_fields,
185  const Point<dim> &position) const;
186 
193  static
194  void
195  declare_parameters (ParameterHandler &prm);
196 
203  virtual
204  void
205  parse_parameters (ParameterHandler &prm);
206 
207 
214  virtual
215  void
216  create_additional_material_model_outputs(MaterialModel::MaterialModelOutputs<dim> &outputs) const;
217 
224  virtual
225  void
226  create_additional_material_model_inputs(MaterialModel::MaterialModelInputs<dim> &inputs) const;
227  };
228 
229 
236  template <int dim>
237  class Manager : public ::aspect::SimulatorAccess<dim>
238  {
239  public:
244  ~Manager () override;
245 
250  bool
251  adiabatic_heating_enabled() const;
252 
257  bool
258  shear_heating_enabled() const;
259 
264  static
265  void
266  declare_parameters (ParameterHandler &prm);
267 
268 
274  void
275  parse_parameters (ParameterHandler &prm);
276 
281  void
282  update ();
283 
284 
290  void
291  evaluate (const MaterialModel::MaterialModelInputs<dim> &material_model_inputs,
292  const MaterialModel::MaterialModelOutputs<dim> &material_model_outputs,
293  HeatingModel::HeatingModelOutputs &heating_model_outputs) const;
294 
300  virtual
301  void
302  create_additional_material_model_inputs_and_outputs(MaterialModel::MaterialModelInputs<dim> &material_model_inputs,
303  MaterialModel::MaterialModelOutputs<dim> &material_model_outputs) const;
304 
305 
325  static
326  void
327  register_heating_model (const std::string &name,
328  const std::string &description,
329  void (*declare_parameters_function) (ParameterHandler &),
330  std::unique_ptr<Interface<dim>> (*factory_function) ());
331 
332 
337  const std::vector<std::string> &
338  get_active_heating_model_names () const;
339 
344  const std::list<std::unique_ptr<Interface<dim>>> &
345  get_active_heating_models () const;
346 
354  template <typename HeatingModelType>
356  HeatingModelType *
357  find_heating_model () const;
358 
365  template <typename HeatingModelType>
366  bool
367  has_matching_heating_model () const;
368 
377  template <typename HeatingModelType>
378  const HeatingModelType &
379  get_matching_heating_model () const;
380 
381 
391  static
392  void
393  write_plugin_graph (std::ostream &output_stream);
394 
398  DeclException1 (ExcHeatingModelNameNotFound,
399  std::string,
400  << "Could not find entry <"
401  << arg1
402  << "> among the names of registered heating model objects.");
403  private:
408  std::list<std::unique_ptr<Interface<dim>>> heating_model_objects;
409 
414  std::vector<std::string> model_names;
415  };
416 
417 
418 
419  template <int dim>
420  template <typename HeatingModelType>
421  inline
422  HeatingModelType *
424  {
425  for (auto &p : heating_model_objects)
426  if (HeatingModelType *x = dynamic_cast<HeatingModelType *> (p.get()))
427  return x;
428  return nullptr;
429  }
430 
431 
432  template <int dim>
433  template <typename HeatingModelType>
434  inline
435  bool
437  {
438  for (const auto &p : heating_model_objects)
439  if (Plugins::plugin_type_matches<HeatingModelType>(*p))
440  return true;
441  return false;
442  }
443 
444 
445  template <int dim>
446  template <typename HeatingModelType>
447  inline
448  const HeatingModelType &
450  {
451  AssertThrow(has_matching_heating_model<HeatingModelType> (),
452  ExcMessage("You asked HeatingModel::Manager::get_heating_model() for a "
453  "heating model of type <" + boost::core::demangle(typeid(HeatingModelType).name()) + "> "
454  "that could not be found in the current model. Activate this "
455  "heating model in the input file."));
456 
457  typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator heating_model;
458  for (typename std::list<std::unique_ptr<Interface<dim>>>::const_iterator
459  p = heating_model_objects.begin();
460  p != heating_model_objects.end(); ++p)
461  if (Plugins::plugin_type_matches<HeatingModelType>(*(*p)))
462  return Plugins::get_plugin_as_type<HeatingModelType>(*(*p));
463 
464  // We will never get here, because we had the Assert above. Just to avoid warnings.
465  return Plugins::get_plugin_as_type<HeatingModelType>(*(*heating_model));
466  }
467 
468 
475  template <int dim>
476  std::string
478 
479 
487 #define ASPECT_REGISTER_HEATING_MODEL(classname,name,description) \
488  template class classname<2>; \
489  template class classname<3>; \
490  namespace ASPECT_REGISTER_HEATING_MODEL_ ## classname \
491  { \
492  aspect::internal::Plugins::RegisterHelper<aspect::HeatingModel::Interface<2>,classname<2>> \
493  dummy_ ## classname ## _2d (&aspect::HeatingModel::Manager<2>::register_heating_model, \
494  name, description); \
495  aspect::internal::Plugins::RegisterHelper<aspect::HeatingModel::Interface<3>,classname<3>> \
496  dummy_ ## classname ## _3d (&aspect::HeatingModel::Manager<3>::register_heating_model, \
497  name, description); \
498  }
499  }
500 }
501 
502 
503 #endif
std::list< std::unique_ptr< Interface< dim > > > heating_model_objects
Definition: interface.h:408
const HeatingModelType & get_matching_heating_model() const
Definition: interface.h:449
std::vector< double > heating_source_terms
Definition: interface.h:78
bool has_matching_heating_model() const
Definition: interface.h:436
std::vector< double > rates_of_temperature_change
Definition: interface.h:99
StructuredDataLookup< dim > DEAL_II_DEPRECATED
void write_plugin_graph(std::ostream &output_stream)
DEAL_II_DEPRECATED HeatingModelType * find_heating_model() const
std::string get_valid_model_names_pattern()
std::vector< double > lhs_latent_heat_terms
Definition: interface.h:105
void declare_parameters(ParameterHandler &prm)
Definition: compat.h:88
std::vector< std::string > model_names
Definition: interface.h:414
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.")