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 
32 
34 
39 
43 
44 #include <deal.II/base/timer.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:
96  Manager();
97 
103  Manager(const unsigned int particle_manager_index);
104 
108  ~Manager() override;
109 
114  Manager(Manager &&) noexcept;
115 
119  enum class ParticleVelocity
120  {
121  solid,
122  fluid,
123  };
124 
128  void initialize();
129 
133  void update();
134 
140  const Property::Manager<dim> &
141  get_property_manager() const;
142 
149  get_particle_handler() const;
150 
163  get_particle_handler();
164 
183  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
184  Particles::ParticleHandler<dim> &to_particle_handler) const;
185 
191  void backup_particles ();
192 
199  void restore_particles ();
200 
201 
205  void setup_initial_state ();
206 
213  get_interpolator() const;
214 
218  void generate_particles();
222  void initialize_particles();
223 
231  void advance_timestep();
232 
244  types::particle_index n_global_particles() const;
245 
256  void
257  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
258 
264  unsigned int
265  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
266  const CellStatus status);
267 
271  void update_particles();
272 
276  template <class Archive>
277  void serialize (Archive &ar, const unsigned int version);
278 
282  virtual
283  void
284  save (std::ostringstream &os) const;
285 
289  virtual
290  void
291  load (std::istringstream &is);
292 
296  static
297  void
299 
307  virtual
308  void
309  parse_parameters (ParameterHandler &prm);
310 
316  get_particle_velocity_choice() const;
317 
318  private:
319 
325 
327  {
328  enum Kind
329  {
330  no_balancing = 0x0,
331  remove_particles = 0x1,
332  add_particles = 0x2,
333  repartition = 0x4,
334  remove_and_add_particles = remove_particles | add_particles
335  };
336  };
337 
341  enum class DeletionAlgorithm
342  {
343  random,
344  point_density_function,
345  };
346 
350  enum class AdditionAlgorithm
351  {
352  random,
353  histogram,
354  point_density_function,
355  monte_carlo,
356  };
357 
365 
373 
378 
382  double bandwidth;
383 
387  std::unique_ptr<Generator::Interface<dim>> generator;
388 
392  std::unique_ptr<Integrator::Interface<dim>> integrator;
393 
404 
408  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
409 
414  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
415 
423 
429  std::unique_ptr<Property::Manager<dim>> property_manager;
430 
435 
440 
445 
450 
464 
477 
486  unsigned int particle_weight;
487 
494  std::map<types::subdomain_id, unsigned int>
495  get_subdomain_id_to_neighbor_map() const;
496 
502  void
503  apply_particle_per_cell_bounds();
504 
509  void advect_particles();
510 
514  void
515  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
516  const typename ParticleHandler<dim>::particle_iterator &end_particle);
517 
528  void
529  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
530  small_vector<Point<dim>> &positions,
531  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
532  SolutionEvaluator<dim> &evaluator);
533 
542  void
543  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
544  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
545  const typename ParticleHandler<dim>::particle_iterator &end_particle,
546  SolutionEvaluator<dim> &evaluators);
547 
552  void
553  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
554  ParticleHandler<dim> &particle_handler,
555  const bool connect_to_checkpoint_signals = true) const;
556 
565  std::vector<typename Particles::ParticleHandler<dim>::particle_iterator_range>
566  get_neighboring_particle_ranges(const typename Triangulation<dim>::active_cell_iterator &cell,
567  const typename Particles::ParticleHandler<dim> &particle_handler,
568  typename GridTools::Cache<dim> &grid_cache);
569  };
570 
571  /* -------------------------- inline and template functions ---------------------- */
572 
573  template <int dim>
574  template <class Archive>
575  void Manager<dim>::serialize (Archive &ar, const unsigned int)
576  {
577  ar &particle_manager_index;
578 
579  // Note that although Boost claims to handle serialization of pointers
580  // correctly, at least for the case of unique_ptr it seems to not work.
581  // It works correctly when archiving the content of the pointer instead.
582  ar
583  &(*particle_handler)
584  ;
585  }
586  }
587 }
588 
589 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:575
ParticlePDF< dim >::KernelFunction kernel_function
Definition: manager.h:377
unsigned int max_particles_per_cell
Definition: manager.h:476
unsigned int min_particles_per_cell
Definition: manager.h:463
unsigned int particle_weight
Definition: manager.h:486
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:387
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:392
ParticleVelocity particle_velocity
Definition: manager.h:449
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:414
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:422
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:429
unsigned int addition_granularity_pdf
Definition: manager.h:364
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:408
unsigned int particle_manager_index
Definition: manager.h:324
AdditionAlgorithm addition_algorithm
Definition: manager.h:444
DeletionAlgorithm deletion_algorithm
Definition: manager.h:439
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:434
void random(DoFHandler< dim, spacedim > &dof_handler)
ParticleIterator< dim, spacedim > particle_iterator
unsigned int addition_granularity_histogram
Definition: manager.h:372
std::mt19937 random_number_generator
Definition: manager.h:403
boost::container::small_vector< T, N > small_vector
Definition: global.h:261
CellStatus
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator