ASPECT
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
manager.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 - 2021 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_manager_h
22 #define _aspect_particle_manager_h
23 
24 #include <aspect/global.h>
25 
26 #include <deal.II/particles/particle.h>
27 #include <deal.II/particles/particle_accessor.h>
28 #include <deal.II/particles/particle_iterator.h>
29 #include <deal.II/particles/particle_handler.h>
30 #include <deal.II/particles/property_pool.h>
31 
32 #include <deal.II/matrix_free/fe_point_evaluation.h>
33 
38 
42 
43 #include <deal.II/base/timer.h>
44 #include <deal.II/base/array_view.h>
45 
46 #include <boost/serialization/unique_ptr.hpp>
47 
48 #include <random>
49 
50 
51 namespace aspect
52 {
53  template <int dim>
54  struct SimulatorSignals;
55 
56  namespace Particle
57  {
58  using namespace ::Particles;
59 
60  namespace Generator
61  {
62  template <int dim>
63  class Interface;
64  }
65 
66 
67  namespace Property
68  {
69  template <int dim>
70  class Manager;
71  }
72 
84  template <int dim>
85  class Manager : public SimulatorAccess<dim>
86  {
87  public:
91  Manager();
92 
96  ~Manager() override;
97 
102  Manager(Manager &&) noexcept;
103 
107  void initialize();
108 
112  void update();
113 
119  const Property::Manager<dim> &
120  get_property_manager() const;
121 
127  const Particles::ParticleHandler<dim> &
128  get_particle_handler() const;
129 
141  Particles::ParticleHandler<dim> &
142  get_particle_handler();
143 
162  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
163  Particles::ParticleHandler<dim> &to_particle_handler) const;
164 
170  void backup_particles ();
171 
178  void restore_particles ();
179 
180 
184  void setup_initial_state ();
185 
191  const Interpolator::Interface<dim> &
192  get_interpolator() const;
193 
197  void generate_particles();
201  void initialize_particles();
202 
210  void advance_timestep();
211 
223  types::particle_index n_global_particles() const;
224 
235  void
236  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
237 
243 #if DEAL_II_VERSION_GTE(9,6,0)
244  unsigned int
245  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
246  const CellStatus status);
247 #else
248  unsigned int
249  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
250  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
251 #endif
252 
256  void update_particles();
257 
261  template <class Archive>
262  void serialize (Archive &ar, const unsigned int version);
263 
267  virtual
268  void
269  save (std::ostringstream &os) const;
270 
274  virtual
275  void
276  load (std::istringstream &is);
277 
281  static
282  void
283  declare_parameters (ParameterHandler &prm);
284 
291  virtual
292  void
293  parse_parameters (ParameterHandler &prm, const unsigned int particle_manager);
294 
295  private:
297  {
298  enum Kind
299  {
300  no_balancing = 0x0,
301  remove_particles = 0x1,
302  add_particles = 0x2,
303  repartition = 0x4,
304  remove_and_add_particles = remove_particles | add_particles
305  };
306  };
307 
311  std::unique_ptr<Generator::Interface<dim>> generator;
312 
316  std::unique_ptr<Integrator::Interface<dim>> integrator;
317 
322 
326  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
327 
332  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
333 
340  Particles::ParticleHandler<dim> particle_handler_backup;
341 
347  std::unique_ptr<Property::Manager<dim>> property_manager;
348 
353 
367 
380 
389  unsigned int particle_weight;
390 
397  std::map<types::subdomain_id, unsigned int>
398  get_subdomain_id_to_neighbor_map() const;
399 
405  void
406  apply_particle_per_cell_bounds();
407 
412  void advect_particles();
413 
417  void
418  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
419  const typename ParticleHandler<dim>::particle_iterator &end_particle);
420 
431  void
432  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
433  small_vector<Point<dim>> &positions,
434  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
435  SolutionEvaluator<dim> &evaluator);
436 
445  void
446  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
447  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
448  const typename ParticleHandler<dim>::particle_iterator &end_particle,
449  SolutionEvaluator<dim> &evaluators);
450 
455  void
456  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
457  ParticleHandler<dim> &particle_handler,
458  const bool connect_to_checkpoint_signals = true) const;
459  };
460 
461  /* -------------------------- inline and template functions ---------------------- */
462 
463  template <int dim>
464  template <class Archive>
465  void Manager<dim>::serialize (Archive &ar, const unsigned int)
466  {
467  // Note that although Boost claims to handle serialization of pointers
468  // correctly, at least for the case of unique_ptr it seems to not work.
469  // It works correctly when archiving the content of the pointer instead.
470  ar
471  &(*particle_handler)
472  ;
473  }
474  }
475 }
476 
477 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:465
unsigned int max_particles_per_cell
Definition: manager.h:379
unsigned int min_particles_per_cell
Definition: manager.h:366
unsigned int particle_weight
Definition: manager.h:389
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:311
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:316
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:332
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:340
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:347
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:326
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:352
std::mt19937 random_number_generator
Definition: manager.h:321
boost::container::small_vector< T, N > small_vector
Definition: global.h:252