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 
321  enum class AdditionAlgorithm
322  {
323  random,
324  histogram,
325  point_density_function,
326  monte_carlo,
327  };
328 
336 
344 
349 
353  double bandwidth;
354 
358  std::unique_ptr<Generator::Interface<dim>> generator;
359 
363  std::unique_ptr<Integrator::Interface<dim>> integrator;
364 
369 
373  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
374 
379  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
380 
387  Particles::ParticleHandler<dim> particle_handler_backup;
388 
394  std::unique_ptr<Property::Manager<dim>> property_manager;
395 
400 
405 
410 
424 
437 
446  unsigned int particle_weight;
447 
454  std::map<types::subdomain_id, unsigned int>
455  get_subdomain_id_to_neighbor_map() const;
456 
462  void
463  apply_particle_per_cell_bounds();
464 
469  void advect_particles();
470 
474  void
475  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
476  const typename ParticleHandler<dim>::particle_iterator &end_particle);
477 
488  void
489  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
490  small_vector<Point<dim>> &positions,
491  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
492  SolutionEvaluator<dim> &evaluator);
493 
502  void
503  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
504  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
505  const typename ParticleHandler<dim>::particle_iterator &end_particle,
506  SolutionEvaluator<dim> &evaluators);
507 
512  void
513  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
514  ParticleHandler<dim> &particle_handler,
515  const bool connect_to_checkpoint_signals = true) const;
516 
525  std::vector<typename Particles::ParticleHandler<dim>::particle_iterator_range>
526  get_neighboring_particle_ranges(const typename Triangulation<dim>::active_cell_iterator &cell,
527  const typename Particles::ParticleHandler<dim> &particle_handler,
528  typename GridTools::Cache<dim> &grid_cache);
529  };
530 
531  /* -------------------------- inline and template functions ---------------------- */
532 
533  template <int dim>
534  template <class Archive>
535  void Manager<dim>::serialize (Archive &ar, const unsigned int)
536  {
537  // Note that although Boost claims to handle serialization of pointers
538  // correctly, at least for the case of unique_ptr it seems to not work.
539  // It works correctly when archiving the content of the pointer instead.
540  ar
541  &(*particle_handler)
542  ;
543  }
544  }
545 }
546 
547 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:535
ParticlePDF< dim >::KernelFunction kernel_function
Definition: manager.h:348
unsigned int max_particles_per_cell
Definition: manager.h:436
unsigned int min_particles_per_cell
Definition: manager.h:423
unsigned int particle_weight
Definition: manager.h:446
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:358
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:363
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:379
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:387
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:394
unsigned int addition_granularity_pdf
Definition: manager.h:335
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:373
AdditionAlgorithm addition_algorithm
Definition: manager.h:409
DeletionAlgorithm deletion_algorithm
Definition: manager.h:404
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:399
unsigned int addition_granularity_histogram
Definition: manager.h:343
std::mt19937 random_number_generator
Definition: manager.h:368
boost::container::small_vector< T, N > small_vector
Definition: global.h:252