ASPECT
world.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_world_h
22 #define _aspect_particle_world_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 
36 
39 
40 #include <deal.II/base/timer.h>
41 #include <deal.II/base/array_view.h>
42 
43 #include <boost/serialization/unique_ptr.hpp>
44 
45 namespace aspect
46 {
47  template<int dim>
48  struct SimulatorSignals;
49 
50  namespace Particle
51  {
52  using namespace dealii;
53  using namespace ::Particles;
54 
55  namespace Generator
56  {
57  template <int dim>
58  class Interface;
59  }
60 
61 
62  namespace Property
63  {
64  template <int dim>
65  class Manager;
66  }
67 
68  namespace internal
69  {
70  template <int dim>
72  }
73 
85  template <int dim>
86  class World : public SimulatorAccess<dim>
87  {
88  public:
92  World();
93 
97  ~World() override;
98 
102  void initialize();
103 
109  const Property::Manager<dim> &
110  get_property_manager() const;
111 
117  const Particles::ParticleHandler<dim> &
118  get_particle_handler() const;
119 
131  Particles::ParticleHandler<dim> &
132  get_particle_handler();
133 
152  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
153  Particles::ParticleHandler<dim> &to_particle_handler) const;
154 
160  void backup_particles ();
161 
168  void restore_particles ();
169 
170 
174  void setup_initial_state ();
175 
182  get_interpolator() const;
183 
187  void generate_particles();
191  void initialize_particles();
192 
200  void advance_timestep();
201 
213  types::particle_index n_global_particles() const;
214 
225  void
226  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
227 
233 #if DEAL_II_VERSION_GTE(9,6,0)
234  unsigned int
235  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
236  const CellStatus status);
237 #else
238  unsigned int
239  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
240  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
241 #endif
242 
246  void update_particles();
247 
251  template <class Archive>
252  void serialize (Archive &ar, const unsigned int version);
253 
257  virtual
258  void
259  save (std::ostringstream &os) const;
260 
264  virtual
265  void
266  load (std::istringstream &is);
267 
271  static
272  void
273  declare_parameters (ParameterHandler &prm);
274 
278  virtual
279  void
280  parse_parameters (ParameterHandler &prm);
281 
282  private:
284  {
285  enum Kind
286  {
287  no_balancing = 0x0,
288  remove_particles = 0x1,
289  add_particles = 0x2,
290  repartition = 0x4,
291  remove_and_add_particles = remove_particles | add_particles
292  };
293  };
294 
298  std::unique_ptr<Generator::Interface<dim>> generator;
299 
303  std::unique_ptr<Integrator::Interface<dim>> integrator;
304 
308  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
309 
314  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
315 
322  Particles::ParticleHandler<dim> particle_handler_backup;
323 
329  std::unique_ptr<Property::Manager<dim>> property_manager;
330 
335 
349 
362 
371  unsigned int particle_weight;
372 
381 
388  std::map<types::subdomain_id, unsigned int>
389  get_subdomain_id_to_neighbor_map() const;
390 
396  void
397  apply_particle_per_cell_bounds();
398 
403  void advect_particles();
404 
408  void
409  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
410  const typename ParticleHandler<dim>::particle_iterator &end_particle);
411 
415  void
416  local_update_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
417  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
418  const typename ParticleHandler<dim>::particle_iterator &end_particle);
419 
428  void
429  local_update_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
430  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
431  const typename ParticleHandler<dim>::particle_iterator &end_particle,
433 
442  void
443  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
444  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
445  const typename ParticleHandler<dim>::particle_iterator &end_particle);
446 
460  void
461  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
462  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
463  const typename ParticleHandler<dim>::particle_iterator &end_particle,
465 
470  void
471  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
472  ParticleHandler<dim> &particle_handler,
473  const bool connect_to_checkpoint_signals = true) const;
474  };
475 
476  /* -------------------------- inline and template functions ---------------------- */
477 
478  template <int dim>
479  template <class Archive>
480  void World<dim>::serialize (Archive &ar, const unsigned int)
481  {
482  // Note that although Boost claims to handle serialization of pointers
483  // correctly, at least for the case of unique_ptr it seems to not work.
484  // It works correctly when archiving the content of the pointer instead.
485  ar
486  &(*particle_handler)
487  ;
488  }
489  }
490 }
491 
492 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: world.h:480
unsigned int min_particles_per_cell
Definition: world.h:348
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: world.h:314
unsigned int max_particles_per_cell
Definition: world.h:361
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: world.h:308
unsigned int particle_weight
Definition: world.h:371
std::unique_ptr< Generator::Interface< dim > > generator
Definition: world.h:298
void declare_parameters(ParameterHandler &prm)
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: world.h:303
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: world.h:329
ParticleLoadBalancing::Kind particle_load_balancing
Definition: world.h:334
bool update_ghost_particles
Definition: world.h:380
Particles::ParticleHandler< dim > particle_handler_backup
Definition: world.h:322
Definition: compat.h:42