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>
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 namespace aspect
49 {
50  template <int dim>
51  struct SimulatorSignals;
52 
53  namespace Particle
54  {
55  using namespace ::Particles;
56 
57  namespace Generator
58  {
59  template <int dim>
60  class Interface;
61  }
62 
63 
64  namespace Property
65  {
66  template <int dim>
67  class Manager;
68  }
69 
81  template <int dim>
82  class Manager : public SimulatorAccess<dim>
83  {
84  public:
88  Manager();
89 
93  ~Manager() override;
94 
99  Manager(Manager &&) noexcept;
100 
104  void initialize();
105 
109  void update();
110 
116  const Property::Manager<dim> &
117  get_property_manager() const;
118 
124  const Particles::ParticleHandler<dim> &
125  get_particle_handler() const;
126 
138  Particles::ParticleHandler<dim> &
139  get_particle_handler();
140 
159  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
160  Particles::ParticleHandler<dim> &to_particle_handler) const;
161 
167  void backup_particles ();
168 
175  void restore_particles ();
176 
177 
181  void setup_initial_state ();
182 
188  const Interpolator::Interface<dim> &
189  get_interpolator() const;
190 
194  void generate_particles();
198  void initialize_particles();
199 
207  void advance_timestep();
208 
220  types::particle_index n_global_particles() const;
221 
232  void
233  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
234 
240 #if DEAL_II_VERSION_GTE(9,6,0)
241  unsigned int
242  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
243  const CellStatus status);
244 #else
245  unsigned int
246  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
247  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
248 #endif
249 
253  void update_particles();
254 
258  template <class Archive>
259  void serialize (Archive &ar, const unsigned int version);
260 
264  virtual
265  void
266  save (std::ostringstream &os) const;
267 
271  virtual
272  void
273  load (std::istringstream &is);
274 
278  static
279  void
280  declare_parameters (ParameterHandler &prm);
281 
288  virtual
289  void
290  parse_parameters (ParameterHandler &prm, const unsigned int particle_manager);
291 
292  private:
294  {
295  enum Kind
296  {
297  no_balancing = 0x0,
298  remove_particles = 0x1,
299  add_particles = 0x2,
300  repartition = 0x4,
301  remove_and_add_particles = remove_particles | add_particles
302  };
303  };
304 
308  std::unique_ptr<Generator::Interface<dim>> generator;
309 
313  std::unique_ptr<Integrator::Interface<dim>> integrator;
314 
318  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
319 
324  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
325 
332  Particles::ParticleHandler<dim> particle_handler_backup;
333 
339  std::unique_ptr<Property::Manager<dim>> property_manager;
340 
345 
359 
372 
381  unsigned int particle_weight;
382 
389  std::map<types::subdomain_id, unsigned int>
390  get_subdomain_id_to_neighbor_map() const;
391 
397  void
398  apply_particle_per_cell_bounds();
399 
404  void advect_particles();
405 
409  void
410  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
411  const typename ParticleHandler<dim>::particle_iterator &end_particle);
412 
423  void
424  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
425  small_vector<Point<dim>> &positions,
426  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
427  SolutionEvaluator<dim> &evaluator);
428 
437  void
438  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
439  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
440  const typename ParticleHandler<dim>::particle_iterator &end_particle,
441  SolutionEvaluator<dim> &evaluators);
442 
447  void
448  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
449  ParticleHandler<dim> &particle_handler,
450  const bool connect_to_checkpoint_signals = true) const;
451  };
452 
453  /* -------------------------- inline and template functions ---------------------- */
454 
455  template <int dim>
456  template <class Archive>
457  void Manager<dim>::serialize (Archive &ar, const unsigned int)
458  {
459  // Note that although Boost claims to handle serialization of pointers
460  // correctly, at least for the case of unique_ptr it seems to not work.
461  // It works correctly when archiving the content of the pointer instead.
462  ar
463  &(*particle_handler)
464  ;
465  }
466  }
467 }
468 
469 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:457
unsigned int max_particles_per_cell
Definition: manager.h:371
unsigned int min_particles_per_cell
Definition: manager.h:358
unsigned int particle_weight
Definition: manager.h:381
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:308
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:313
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:324
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:332
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:339
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:318
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:344
Definition: compat.h:59
boost::container::small_vector< T, N > small_vector
Definition: global.h:251