ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 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_boundary_composition_interface_h
23 #define _aspect_boundary_composition_interface_h
24 
25 #include <aspect/plugins.h>
27 #include <aspect/utilities.h>
29 
30 #include <deal.II/base/parameter_handler.h>
31 #include <deal.II/distributed/tria.h>
32 
33 #include <boost/core/demangle.hpp>
34 #include <typeinfo>
35 
36 
37 namespace aspect
38 {
45  namespace BoundaryComposition
46  {
47  using namespace dealii;
48 
54  template <int dim>
55  class Interface
56  {
57  public:
62  virtual ~Interface() = default;
63 
69  virtual void initialize ();
70 
82  virtual
83  void
84  update ();
85 
100  virtual
101  double
102  boundary_composition (const types::boundary_id boundary_indicator,
103  const Point<dim> &position,
104  const unsigned int compositional_field) const;
105 
112  static
113  void
114  declare_parameters (ParameterHandler &prm);
115 
122  virtual
123  void
124  parse_parameters (ParameterHandler &prm);
125  };
126 
132  template <int dim>
133  class Manager : public ::aspect::SimulatorAccess<dim>
134  {
135  public:
140  ~Manager () override;
141 
151  virtual
152  void
153  update ();
154 
159  static
160  void
161  declare_parameters (ParameterHandler &prm);
162 
168  void
169  parse_parameters (ParameterHandler &prm);
170 
176  double
177  boundary_composition (const types::boundary_id boundary_indicator,
178  const Point<dim> &position,
179  const unsigned int compositional_field) const;
180 
198  static
199  void
200  register_boundary_composition (const std::string &name,
201  const std::string &description,
202  void (*declare_parameters_function) (ParameterHandler &),
203  Interface<dim> *(*factory_function) ());
204 
205 
210  const std::vector<std::string> &
211  get_active_boundary_composition_names () const;
212 
217  const std::vector<std::unique_ptr<Interface<dim>>> &
218  get_active_boundary_composition_conditions () const;
219 
230  template <typename BoundaryCompositionType>
232  BoundaryCompositionType *
233  find_boundary_composition_model () const;
234 
241  template <typename BoundaryCompositionType>
242  bool
243  has_matching_boundary_composition_model () const;
244 
253  template <typename BoundaryCompositionType>
254  const BoundaryCompositionType &
255  get_matching_boundary_composition_model () const;
256 
257  /*
258  * Return a set of boundary indicators for which boundary
259  * compositions are prescribed.
260  */
261  const std::set<types::boundary_id> &
262  get_fixed_composition_boundary_indicators() const;
263 
264  /*
265  * Return whether Dirichlet boundary conditions will be applied
266  * on parts of the boundaries where material flows out.
267  */
268  bool
269  allows_fixed_composition_on_outflow_boundaries() const;
270 
280  static
281  void
282  write_plugin_graph (std::ostream &output_stream);
283 
284 
288  DeclException1 (ExcBoundaryCompositionNameNotFound,
289  std::string,
290  << "Could not find entry <"
291  << arg1
292  << "> among the names of registered boundary composition objects.");
293  private:
298  std::vector<std::unique_ptr<Interface<dim>>> boundary_composition_objects;
299 
304  std::vector<std::string> model_names;
305 
312  std::vector<aspect::Utilities::Operator> model_operators;
313 
318  std::set<types::boundary_id> fixed_composition_boundary_indicators;
319 
325  };
326 
327 
328 
329  template <int dim>
330  template <typename BoundaryCompositionType>
331  inline
332  BoundaryCompositionType *
334  {
335  for (const auto &p : boundary_composition_objects)
336  if (BoundaryCompositionType *x = dynamic_cast<BoundaryCompositionType *> ( p.get()) )
337  return x;
338  return nullptr;
339  }
340 
341 
342  template <int dim>
343  template <typename BoundaryCompositionType>
344  inline
345  bool
347  {
348  for (const auto &p : boundary_composition_objects)
349  if (Plugins::plugin_type_matches<BoundaryCompositionType>(*p))
350  return true;
351 
352  return false;
353  }
354 
355 
356 
357  template <int dim>
358  template <typename BoundaryCompositionType>
359  inline
360  const BoundaryCompositionType &
362  {
363  AssertThrow(has_matching_boundary_composition_model<BoundaryCompositionType> (),
364  ExcMessage("You asked BoundaryComposition::Manager::get_boundary_composition_model() for a "
365  "boundary composition model of type <" + boost::core::demangle(typeid(BoundaryCompositionType).name()) + "> "
366  "that could not be found in the current model. Activate this "
367  "boundary composition model in the input file."));
368 
369  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator boundary_composition_model;
370  for (typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator
371  p = boundary_composition_objects.begin();
372  p != boundary_composition_objects.end(); ++p)
373  if (Plugins::plugin_type_matches<BoundaryCompositionType>(*(*p)))
374  return Plugins::get_plugin_as_type<BoundaryCompositionType>(*(*p));
375 
376  // We will never get here, because we had the Assert above. Just to avoid warnings.
377  return Plugins::get_plugin_as_type<BoundaryCompositionType>(*(*boundary_composition_model));
378  }
379 
380 
381 
382 
389  template <int dim>
390  std::string
392 
393 
401 #define ASPECT_REGISTER_BOUNDARY_COMPOSITION_MODEL(classname, name, description) \
402  template class classname<2>; \
403  template class classname<3>; \
404  namespace ASPECT_REGISTER_BOUNDARY_COMPOSITION_MODEL_ ## classname \
405  { \
406  aspect::internal::Plugins::RegisterHelper<aspect::BoundaryComposition::Interface<2>,classname<2>> \
407  dummy_ ## classname ## _2d (&aspect::BoundaryComposition::Manager<2>::register_boundary_composition, \
408  name, description); \
409  aspect::internal::Plugins::RegisterHelper<aspect::BoundaryComposition::Interface<3>,classname<3>> \
410  dummy_ ## classname ## _3d (&aspect::BoundaryComposition::Manager<3>::register_boundary_composition, \
411  name, description); \
412  }
413  }
414 }
415 
416 
417 #endif
std::vector< aspect::Utilities::Operator > model_operators
Definition: interface.h:312
bool has_matching_boundary_composition_model() const
Definition: interface.h:346
StructuredDataLookup< dim > DEAL_II_DEPRECATED
std::vector< std::unique_ptr< Interface< dim > > > boundary_composition_objects
Definition: interface.h:298
void write_plugin_graph(std::ostream &output_stream)
DEAL_II_DEPRECATED BoundaryCompositionType * find_boundary_composition_model() const
std::vector< std::string > model_names
Definition: interface.h:304
const BoundaryCompositionType & get_matching_boundary_composition_model() const
Definition: interface.h:361
void declare_parameters(ParameterHandler &prm)
std::string get_valid_model_names_pattern()
std::set< types::boundary_id > fixed_composition_boundary_indicators
Definition: interface.h:318
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.")