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_boundary_velocity_interface_h
23 #define _aspect_boundary_velocity_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 {
45  namespace BoundaryVelocity
46  {
47  using namespace dealii;
48 
54  template <int dim>
55  class Interface : public Plugins::InterfaceBase
56  {
57  public:
70  virtual
71  Tensor<1,dim>
72  boundary_velocity (const types::boundary_id boundary_indicator,
73  const Point<dim> &position) const = 0;
74  };
75 
81  template <int dim>
82  class Manager : public SimulatorAccess<dim>
83  {
84  public:
89  ~Manager () override;
90 
100  virtual
101  void
102  update ();
103 
109  Tensor<1,dim>
110  boundary_velocity (const types::boundary_id boundary_indicator,
111  const Point<dim> &position) const;
112 
130  static
131  void
132  register_boundary_velocity (const std::string &name,
133  const std::string &description,
134  void (*declare_parameters_function) (ParameterHandler &),
135  std::unique_ptr<Interface<dim>> (*factory_function) ());
136 
137 
150  const std::map<types::boundary_id, std::pair<std::string,std::vector<std::string>>> &
151  get_active_boundary_velocity_names () const;
152 
162  const std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryVelocity::Interface<dim>>>> &
163  get_active_boundary_velocity_conditions () const;
164 
169  const std::set<types::boundary_id> &
170  get_zero_boundary_velocity_indicators () const;
171 
176  const std::set<types::boundary_id> &
177  get_tangential_boundary_velocity_indicators () const;
178 
183  static
184  void
185  declare_parameters (ParameterHandler &prm);
186 
192  void
193  parse_parameters (ParameterHandler &prm);
194 
204  template <typename BoundaryVelocityType,
205  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,BoundaryVelocityType>::value>>
206  bool
207  has_matching_boundary_velocity_model () const;
208 
220  template <typename BoundaryVelocityType,
221  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,BoundaryVelocityType>::value>>
222  const BoundaryVelocityType &
223  get_matching_boundary_velocity_model () const;
224 
234  static
235  void
236  write_plugin_graph (std::ostream &output_stream);
237 
238 
242  DeclException1 (ExcBoundaryVelocityNameNotFound,
243  std::string,
244  << "Could not find entry <"
245  << arg1
246  << "> among the names of registered boundary velocity objects.");
247  private:
252  std::map<types::boundary_id,std::vector<std::unique_ptr<BoundaryVelocity::Interface<dim>>>> boundary_velocity_objects;
253 
262  std::map<types::boundary_id, std::pair<std::string,std::vector<std::string>>> boundary_velocity_indicators;
263 
268  std::set<types::boundary_id> zero_velocity_boundary_indicators;
269 
274  std::set<types::boundary_id> tangential_velocity_boundary_indicators;
275  };
276 
277 
278 
279  template <int dim>
280  template <typename BoundaryVelocityType, typename>
281  inline
282  bool
284  {
285  for (const auto &boundary : boundary_velocity_objects)
286  for (const auto &p : boundary.second)
287  if (Plugins::plugin_type_matches<BoundaryVelocityType>(*p))
288  return true;
289  return false;
290  }
291 
292 
293  template <int dim>
294  template <typename BoundaryVelocityType, typename>
295  inline
296  const BoundaryVelocityType &
298  {
299  AssertThrow(has_matching_boundary_velocity_model<BoundaryVelocityType> (),
300  ExcMessage("You asked BoundaryVelocity::Manager::get_boundary_velocity_model() for a "
301  "boundary velocity model of type <" + boost::core::demangle(typeid(BoundaryVelocityType).name()) + "> "
302  "that could not be found in the current model. Activate this "
303  "boundary velocity model in the input file."));
304 
305  for (const auto &boundary : boundary_velocity_objects)
306  for (const auto &p : boundary)
307  if (Plugins::plugin_type_matches<BoundaryVelocityType>(*p))
308  return Plugins::get_plugin_as_type<BoundaryVelocityType>(*p);
309 
310  // We will never get here, because we had the Assert above. Just to avoid warnings.
311  return Plugins::get_plugin_as_type<BoundaryVelocityType>(**(boundary_velocity_objects.begin()));
312  }
313 
314 
321  template <int dim>
322  std::string
324 
325 
333 #define ASPECT_REGISTER_BOUNDARY_VELOCITY_MODEL(classname, name, description) \
334  template class classname<2>; \
335  template class classname<3>; \
336  namespace ASPECT_REGISTER_BOUNDARY_VELOCITY_MODEL_ ## classname \
337  { \
338  aspect::internal::Plugins::RegisterHelper<aspect::BoundaryVelocity::Interface<2>,classname<2>> \
339  dummy_ ## classname ## _2d (&aspect::BoundaryVelocity::Manager<2>::register_boundary_velocity, \
340  name, description); \
341  aspect::internal::Plugins::RegisterHelper<aspect::BoundaryVelocity::Interface<3>,classname<3>> \
342  dummy_ ## classname ## _3d (&aspect::BoundaryVelocity::Manager<3>::register_boundary_velocity, \
343  name, description); \
344  }
345  }
346 }
347 
348 
349 #endif
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > tangential_velocity_boundary_indicators
Definition: interface.h:274
std::map< types::boundary_id, std::pair< std::string, std::vector< std::string > > > boundary_velocity_indicators
Definition: interface.h:262
std::string get_valid_model_names_pattern()
std::map< types::boundary_id, std::vector< std::unique_ptr< BoundaryVelocity::Interface< dim > > > > boundary_velocity_objects
Definition: interface.h:252
bool has_matching_boundary_velocity_model() const
Definition: interface.h:283
Definition: compat.h:59
const BoundaryVelocityType & get_matching_boundary_velocity_model() const
Definition: interface.h:297
void declare_parameters(ParameterHandler &prm)
Definition: compat.h:42
std::set< types::boundary_id > zero_velocity_boundary_indicators
Definition: interface.h:268
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.")