ASPECT
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>
32 
33 #include <deal.II/matrix_free/fe_point_evaluation.h>
34 
39 
43 
44 #include <deal.II/base/timer.h>
45 #include <deal.II/base/array_view.h>
46 
47 #include <boost/serialization/unique_ptr.hpp>
48 
49 #include <random>
50 #include <vector>
51 
52 namespace aspect
53 {
54  template <int dim>
55  struct SimulatorSignals;
56 
57  namespace Particle
58  {
59  using namespace ::Particles;
60 
61  namespace Generator
62  {
63  template <int dim>
64  class Interface;
65  }
66 
67 
68  namespace Property
69  {
70  template <int dim>
71  class Manager;
72  }
73 
85  template <int dim>
86  class Manager : public SimulatorAccess<dim>
87  {
88  public:
92  Manager();
93 
97  ~Manager() override;
98 
103  Manager(Manager &&) noexcept;
104 
108  void initialize();
109 
113  void update();
114 
120  const Property::Manager<dim> &
121  get_property_manager() const;
122 
128  const Particles::ParticleHandler<dim> &
129  get_particle_handler() const;
130 
142  Particles::ParticleHandler<dim> &
143  get_particle_handler();
144 
163  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
164  Particles::ParticleHandler<dim> &to_particle_handler) const;
165 
171  void backup_particles ();
172 
179  void restore_particles ();
180 
181 
185  void setup_initial_state ();
186 
192  const Interpolator::Interface<dim> &
193  get_interpolator() const;
194 
198  void generate_particles();
202  void initialize_particles();
203 
211  void advance_timestep();
212 
224  types::particle_index n_global_particles() const;
225 
236  void
237  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
238 
244 #if DEAL_II_VERSION_GTE(9,6,0)
245  unsigned int
246  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
247  const CellStatus status);
248 #else
249  unsigned int
250  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
251  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
252 #endif
253 
257  void update_particles();
258 
262  template <class Archive>
263  void serialize (Archive &ar, const unsigned int version);
264 
268  virtual
269  void
270  save (std::ostringstream &os) const;
271 
275  virtual
276  void
277  load (std::istringstream &is);
278 
282  static
283  void
284  declare_parameters (ParameterHandler &prm);
285 
292  virtual
293  void
294  parse_parameters (ParameterHandler &prm, const unsigned int particle_manager);
295 
296  private:
298  {
299  enum Kind
300  {
301  no_balancing = 0x0,
302  remove_particles = 0x1,
303  add_particles = 0x2,
304  repartition = 0x4,
305  remove_and_add_particles = remove_particles | add_particles
306  };
307  };
308 
312  enum class DeletionAlgorithm
313  {
314  random,
315  point_density_function,
316  };
317 
322 
326  double bandwidth;
327 
331  std::unique_ptr<Generator::Interface<dim>> generator;
332 
336  std::unique_ptr<Integrator::Interface<dim>> integrator;
337 
342 
346  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
347 
352  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
353 
360  Particles::ParticleHandler<dim> particle_handler_backup;
361 
367  std::unique_ptr<Property::Manager<dim>> property_manager;
368 
373 
378 
392 
405 
414  unsigned int particle_weight;
415 
422  std::map<types::subdomain_id, unsigned int>
423  get_subdomain_id_to_neighbor_map() const;
424 
430  void
431  apply_particle_per_cell_bounds();
432 
437  void advect_particles();
438 
442  void
443  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
444  const typename ParticleHandler<dim>::particle_iterator &end_particle);
445 
456  void
457  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
458  small_vector<Point<dim>> &positions,
459  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
460  SolutionEvaluator<dim> &evaluator);
461 
470  void
471  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
472  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
473  const typename ParticleHandler<dim>::particle_iterator &end_particle,
474  SolutionEvaluator<dim> &evaluators);
475 
480  void
481  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
482  ParticleHandler<dim> &particle_handler,
483  const bool connect_to_checkpoint_signals = true) const;
484 
493  std::vector<typename Particles::ParticleHandler<dim>::particle_iterator_range>
494  get_neighboring_particle_ranges(const typename Triangulation<dim>::active_cell_iterator &cell,
495  const typename Particles::ParticleHandler<dim> &particle_handler,
496  typename GridTools::Cache<dim> &grid_cache);
497  };
498 
499  /* -------------------------- inline and template functions ---------------------- */
500 
501  template <int dim>
502  template <class Archive>
503  void Manager<dim>::serialize (Archive &ar, const unsigned int)
504  {
505  // Note that although Boost claims to handle serialization of pointers
506  // correctly, at least for the case of unique_ptr it seems to not work.
507  // It works correctly when archiving the content of the pointer instead.
508  ar
509  &(*particle_handler)
510  ;
511  }
512  }
513 }
514 
515 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:503
ParticlePDF< dim >::KernelFunction kernel_function
Definition: manager.h:321
unsigned int max_particles_per_cell
Definition: manager.h:404
unsigned int min_particles_per_cell
Definition: manager.h:391
unsigned int particle_weight
Definition: manager.h:414
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:331
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:336
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:352
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:360
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:367
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:346
DeletionAlgorithm deletion_algorithm
Definition: manager.h:377
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:372
std::mt19937 random_number_generator
Definition: manager.h:341
boost::container::small_vector< T, N > small_vector
Definition: global.h:252