ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 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 #ifndef _aspect_particle_generator_interface_h
22 #define _aspect_particle_generator_interface_h
23 
24 #include <aspect/plugins.h>
26 
27 #include <deal.II/particles/particle.h>
28 #include <deal.II/particles/generators.h>
29 #include <deal.II/base/parameter_handler.h>
30 #include <deal.II/base/exceptions.h>
31 
32 #include <random>
33 
34 #include <map>
35 
36 namespace aspect
37 {
38  namespace Particle
39  {
46  namespace Generator
47  {
48  using namespace ::Particles;
49  using ::Particles::Particle;
50 
54  DeclExceptionMsg (ExcParticlePointNotInDomain,
55  "You requested to generate a particle at a position that "
56  "is not owned by this process, therefore the "
57  "Particle::Generator::Interface::generate_particle() function "
58  "refused to create it. You can circumvent this error message "
59  "by catching the ExcParticlePointNotInDomain exception and "
60  "do whatever you think is appropriate in this case.");
61 
67  template <int dim>
68  class Interface : public SimulatorAccess<dim>
69  {
70  public:
74  Interface ();
75 
80  ~Interface () override = default;
81 
87  virtual
88  void
89  initialize ();
90 
106  virtual
107  void
108  generate_particles(std::multimap<Particles::internal::LevelInd, Particle<dim>> &particles);
109 
121  virtual
122  void
123  generate_particles(Particles::ParticleHandler<dim> &particle_handler);
124 
131  std::pair<Particles::internal::LevelInd,Particle<dim>>
132  generate_particle (const typename parallel::distributed::Triangulation<dim>::active_cell_iterator &cell,
133  const types::particle_index id);
134 
135 
142  static
143  void
144  declare_parameters (ParameterHandler &prm);
145 
152  virtual
153  void
154  parse_parameters (ParameterHandler &prm);
155 
156  protected:
169  std::pair<Particles::internal::LevelInd,Particle<dim>>
170  generate_particle(const Point<dim> &position,
171  const types::particle_index id) const;
172 
193  Particles::ParticleIterator<dim>
194  insert_particle_at_position(const Point<dim> &position,
195  const types::particle_index id,
196  Particles::ParticleHandler<dim> &particle_handler) const;
197 
203  };
204 
220  template <int dim>
221  void
222  register_particle_generator (const std::string &name,
223  const std::string &description,
224  void (*declare_parameters_function) (ParameterHandler &),
225  std::unique_ptr<Interface<dim>> (*factory_function) ());
226 
237  template <int dim>
238  std::unique_ptr<Interface<dim>>
239  create_particle_generator (ParameterHandler &prm);
240 
246  template <int dim>
247  void
248  declare_parameters (ParameterHandler &prm);
249 
250 
260  template <int dim>
261  void
262  write_plugin_graph (std::ostream &output_stream);
263 
264 
272 #define ASPECT_REGISTER_PARTICLE_GENERATOR(classname, name, description) \
273  template class classname<2>; \
274  template class classname<3>; \
275  namespace ASPECT_REGISTER_PARTICLE_GENERATOR_ ## classname \
276  { \
277  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Generator::Interface<2>,classname<2 >> \
278  dummy_ ## classname ## _2d (&aspect::Particle::Generator::register_particle_generator<2>, \
279  name, description); \
280  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Generator::Interface<3>,classname<3>> \
281  dummy_ ## classname ## _3d (&aspect::Particle::Generator::register_particle_generator<3>, \
282  name, description); \
283  }
284  }
285  }
286 }
287 
288 #endif
Particles::ParticleIterator< dim > insert_particle_at_position(const Point< dim > &position, const types::particle_index id, Particles::ParticleHandler< dim > &particle_handler) const
StructuredDataLookup< dim > DEAL_II_DEPRECATED
static void declare_parameters(ParameterHandler &prm)
std::pair< Particles::internal::LevelInd, Particle< dim > > generate_particle(const typename parallel::distributed::Triangulation< dim >::active_cell_iterator &cell, const types::particle_index id)
DeclExceptionMsg(ExcParticlePointNotInDomain, "You requested to generate a particle at a position that " "is not owned by this process, therefore the " "Particle::Generator::Interface::generate_particle() function " "refused to create it. You can circumvent this error message " "by catching the ExcParticlePointNotInDomain exception and " "do whatever you think is appropriate in this case.")
virtual void parse_parameters(ParameterHandler &prm)
void register_particle_generator(const std::string &name, const std::string &description, void(*declare_parameters_function)(ParameterHandler &), std::unique_ptr< Interface< dim >>(*factory_function)())
void write_plugin_graph(std::ostream &output_stream)
std::unique_ptr< Interface< dim > > create_particle_generator(ParameterHandler &prm)
virtual DEAL_II_DEPRECATED void generate_particles(std::multimap< Particles::internal::LevelInd, Particle< dim >> &particles)