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 #if DEAL_II_VERSION_GTE(9,6,0)
265  unsigned int
266  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
267  const CellStatus status);
268 #else
269  unsigned int
270  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
272 #endif
273 
277  void update_particles();
278 
282  template <class Archive>
283  void serialize (Archive &ar, const unsigned int version);
284 
288  virtual
289  void
290  save (std::ostringstream &os) const;
291 
295  virtual
296  void
297  load (std::istringstream &is);
298 
302  static
303  void
305 
313  virtual
314  void
315  parse_parameters (ParameterHandler &prm);
316 
322  get_particle_velocity_choice() const;
323 
324  private:
325 
331 
333  {
334  enum Kind
335  {
336  no_balancing = 0x0,
337  remove_particles = 0x1,
338  add_particles = 0x2,
339  repartition = 0x4,
340  remove_and_add_particles = remove_particles | add_particles
341  };
342  };
343 
347  enum class DeletionAlgorithm
348  {
349  random,
350  point_density_function,
351  };
352 
356  enum class AdditionAlgorithm
357  {
358  random,
359  histogram,
360  point_density_function,
361  monte_carlo,
362  };
363 
371 
379 
384 
388  double bandwidth;
389 
393  std::unique_ptr<Generator::Interface<dim>> generator;
394 
398  std::unique_ptr<Integrator::Interface<dim>> integrator;
399 
410 
414  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
415 
420  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
421 
429 
435  std::unique_ptr<Property::Manager<dim>> property_manager;
436 
441 
446 
451 
456 
470 
483 
492  unsigned int particle_weight;
493 
500  std::map<types::subdomain_id, unsigned int>
501  get_subdomain_id_to_neighbor_map() const;
502 
508  void
509  apply_particle_per_cell_bounds();
510 
515  void advect_particles();
516 
520  void
521  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
522  const typename ParticleHandler<dim>::particle_iterator &end_particle);
523 
534  void
535  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
536  small_vector<Point<dim>> &positions,
537  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
538  SolutionEvaluator<dim> &evaluator);
539 
548  void
549  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
550  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
551  const typename ParticleHandler<dim>::particle_iterator &end_particle,
552  SolutionEvaluator<dim> &evaluators);
553 
558  void
559  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
560  ParticleHandler<dim> &particle_handler,
561  const bool connect_to_checkpoint_signals = true) const;
562 
571  std::vector<typename Particles::ParticleHandler<dim>::particle_iterator_range>
572  get_neighboring_particle_ranges(const typename Triangulation<dim>::active_cell_iterator &cell,
573  const typename Particles::ParticleHandler<dim> &particle_handler,
574  typename GridTools::Cache<dim> &grid_cache);
575  };
576 
577  /* -------------------------- inline and template functions ---------------------- */
578 
579  template <int dim>
580  template <class Archive>
581  void Manager<dim>::serialize (Archive &ar, const unsigned int)
582  {
583  ar &particle_manager_index;
584 
585  // Note that although Boost claims to handle serialization of pointers
586  // correctly, at least for the case of unique_ptr it seems to not work.
587  // It works correctly when archiving the content of the pointer instead.
588  ar
589  &(*particle_handler)
590  ;
591  }
592  }
593 }
594 
595 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:581
ParticlePDF< dim >::KernelFunction kernel_function
Definition: manager.h:383
unsigned int max_particles_per_cell
Definition: manager.h:482
unsigned int min_particles_per_cell
Definition: manager.h:469
unsigned int particle_weight
Definition: manager.h:492
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:393
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:398
ParticleVelocity particle_velocity
Definition: manager.h:455
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:420
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:428
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:435
unsigned int addition_granularity_pdf
Definition: manager.h:370
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:414
unsigned int particle_manager_index
Definition: manager.h:330
AdditionAlgorithm addition_algorithm
Definition: manager.h:450
DeletionAlgorithm deletion_algorithm
Definition: manager.h:445
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:440
void random(DoFHandler< dim, spacedim > &dof_handler)
ParticleIterator< dim, spacedim > particle_iterator
unsigned int addition_granularity_histogram
Definition: manager.h:378
std::mt19937 random_number_generator
Definition: manager.h:409
boost::container::small_vector< T, N > small_vector
Definition: global.h:261
CellStatus
typename ::Triangulation< dim, spacedim >::cell_iterator cell_iterator