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 dealii;
56  using namespace ::Particles;
57 
58  namespace Generator
59  {
60  template <int dim>
61  class Interface;
62  }
63 
64 
65  namespace Property
66  {
67  template <int dim>
68  class Manager;
69  }
70 
82  template <int dim>
83  class Manager : public SimulatorAccess<dim>
84  {
85  public:
89  Manager();
90 
94  ~Manager() override;
95 
100  Manager(Manager &&) noexcept;
101 
105  void initialize();
106 
110  void update();
111 
117  const Property::Manager<dim> &
118  get_property_manager() const;
119 
125  const Particles::ParticleHandler<dim> &
126  get_particle_handler() const;
127 
139  Particles::ParticleHandler<dim> &
140  get_particle_handler();
141 
160  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
161  Particles::ParticleHandler<dim> &to_particle_handler) const;
162 
168  void backup_particles ();
169 
176  void restore_particles ();
177 
178 
182  void setup_initial_state ();
183 
189  const Interpolator::Interface<dim> &
190  get_interpolator() const;
191 
195  void generate_particles();
199  void initialize_particles();
200 
208  void advance_timestep();
209 
221  types::particle_index n_global_particles() const;
222 
233  void
234  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
235 
241 #if DEAL_II_VERSION_GTE(9,6,0)
242  unsigned int
243  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
244  const CellStatus status);
245 #else
246  unsigned int
247  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
248  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
249 #endif
250 
254  void update_particles();
255 
259  template <class Archive>
260  void serialize (Archive &ar, const unsigned int version);
261 
265  virtual
266  void
267  save (std::ostringstream &os) const;
268 
272  virtual
273  void
274  load (std::istringstream &is);
275 
279  static
280  void
281  declare_parameters (ParameterHandler &prm);
282 
289  virtual
290  void
291  parse_parameters (ParameterHandler &prm, const unsigned int particle_manager);
292 
293  private:
295  {
296  enum Kind
297  {
298  no_balancing = 0x0,
299  remove_particles = 0x1,
300  add_particles = 0x2,
301  repartition = 0x4,
302  remove_and_add_particles = remove_particles | add_particles
303  };
304  };
305 
309  std::unique_ptr<Generator::Interface<dim>> generator;
310 
314  std::unique_ptr<Integrator::Interface<dim>> integrator;
315 
319  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
320 
325  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
326 
333  Particles::ParticleHandler<dim> particle_handler_backup;
334 
340  std::unique_ptr<Property::Manager<dim>> property_manager;
341 
346 
360 
373 
382  unsigned int particle_weight;
383 
390  std::map<types::subdomain_id, unsigned int>
391  get_subdomain_id_to_neighbor_map() const;
392 
398  void
399  apply_particle_per_cell_bounds();
400 
405  void advect_particles();
406 
410  void
411  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
412  const typename ParticleHandler<dim>::particle_iterator &end_particle);
413 
424  void
425  local_update_particles(Property::ParticleUpdateInputs<dim> &inputs,
426  small_vector<Point<dim>> &positions,
427  const std::vector<EvaluationFlags::EvaluationFlags> &evaluation_flags,
428  SolutionEvaluator<dim> &evaluator);
429 
438  void
439  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
440  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
441  const typename ParticleHandler<dim>::particle_iterator &end_particle,
442  SolutionEvaluator<dim> &evaluators);
443 
448  void
449  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
450  ParticleHandler<dim> &particle_handler,
451  const bool connect_to_checkpoint_signals = true) const;
452  };
453 
454  /* -------------------------- inline and template functions ---------------------- */
455 
456  template <int dim>
457  template <class Archive>
458  void Manager<dim>::serialize (Archive &ar, const unsigned int)
459  {
460  // Note that although Boost claims to handle serialization of pointers
461  // correctly, at least for the case of unique_ptr it seems to not work.
462  // It works correctly when archiving the content of the pointer instead.
463  ar
464  &(*particle_handler)
465  ;
466  }
467  }
468 }
469 
470 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: manager.h:458
unsigned int max_particles_per_cell
Definition: manager.h:372
unsigned int min_particles_per_cell
Definition: manager.h:359
unsigned int particle_weight
Definition: manager.h:382
std::unique_ptr< Generator::Interface< dim > > generator
Definition: manager.h:309
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: manager.h:314
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: manager.h:325
Particles::ParticleHandler< dim > particle_handler_backup
Definition: manager.h:333
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: manager.h:340
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: manager.h:319
void declare_parameters(ParameterHandler &prm)
ParticleLoadBalancing::Kind particle_load_balancing
Definition: manager.h:345
Definition: compat.h:59
boost::container::small_vector< T, N > small_vector
Definition: global.h:245
Definition: compat.h:42