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 
32 #include <deal.II/matrix_free/fe_point_evaluation.h>
33 
38 
41 
42 #include <deal.II/base/timer.h>
43 #include <deal.II/base/array_view.h>
44 
45 #include <boost/serialization/unique_ptr.hpp>
46 
47 namespace aspect
48 {
49  template <int dim>
50  struct SimulatorSignals;
51 
52  namespace Particle
53  {
54  using namespace dealii;
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 
70  namespace internal
71  {
77  template <int dim>
79  {
80  public:
84  virtual ~SolutionEvaluators() = default;
85 
92  virtual void
93  reinit(const typename DoFHandler<dim>::active_cell_iterator &cell,
94  const ArrayView<Point<dim>> &positions,
95  const ArrayView<double> &solution_values,
96  const UpdateFlags update_flags) = 0;
97 
104  virtual void get_solution(const unsigned int evaluation_point,
105  Vector<double> &solution) = 0;
106 
113  virtual void get_gradients(const unsigned int evaluation_point,
114  std::vector<Tensor<1, dim>> &gradients) = 0;
115 
120  virtual FEPointEvaluation<dim, dim> &
121  get_velocity_or_fluid_velocity_evaluator(const bool use_fluid_velocity) = 0;
122 
126  virtual NonMatching::MappingInfo<dim> &
127  get_mapping_info() = 0;
128  };
129 
133  template <int dim>
134  std::unique_ptr<internal::SolutionEvaluators<dim>>
135  construct_solution_evaluators(const SimulatorAccess<dim> &simulator_access,
136  const UpdateFlags update_flags);
137  }
138 
150  template <int dim>
151  class World : public SimulatorAccess<dim>
152  {
153  public:
157  World();
158 
162  ~World() override;
163 
167  void initialize();
168 
172  void update();
173 
179  const Property::Manager<dim> &
180  get_property_manager() const;
181 
187  const Particles::ParticleHandler<dim> &
188  get_particle_handler() const;
189 
201  Particles::ParticleHandler<dim> &
202  get_particle_handler();
203 
222  void copy_particle_handler (const Particles::ParticleHandler<dim> &from_particle_handler,
223  Particles::ParticleHandler<dim> &to_particle_handler) const;
224 
230  void backup_particles ();
231 
238  void restore_particles ();
239 
240 
244  void setup_initial_state ();
245 
252  get_interpolator() const;
253 
257  void generate_particles();
261  void initialize_particles();
262 
270  void advance_timestep();
271 
283  types::particle_index n_global_particles() const;
284 
295  void
296  connect_to_signals(aspect::SimulatorSignals<dim> &signals);
297 
303 #if DEAL_II_VERSION_GTE(9,6,0)
304  unsigned int
305  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
306  const CellStatus status);
307 #else
308  unsigned int
309  cell_weight(const typename parallel::distributed::Triangulation<dim>::cell_iterator &cell,
310  const typename parallel::distributed::Triangulation<dim>::CellStatus status);
311 #endif
312 
316  void update_particles();
317 
321  template <class Archive>
322  void serialize (Archive &ar, const unsigned int version);
323 
327  virtual
328  void
329  save (std::ostringstream &os) const;
330 
334  virtual
335  void
336  load (std::istringstream &is);
337 
341  static
342  void
343  declare_parameters (ParameterHandler &prm);
344 
350  virtual
351  void
352  parse_parameters (ParameterHandler &prm, const unsigned int world_index);
353 
354  private:
356  {
357  enum Kind
358  {
359  no_balancing = 0x0,
360  remove_particles = 0x1,
361  add_particles = 0x2,
362  repartition = 0x4,
363  remove_and_add_particles = remove_particles | add_particles
364  };
365  };
366 
370  std::unique_ptr<Generator::Interface<dim>> generator;
371 
375  std::unique_ptr<Integrator::Interface<dim>> integrator;
376 
380  std::unique_ptr<Interpolator::Interface<dim>> interpolator;
381 
386  std::unique_ptr<Particles::ParticleHandler<dim>> particle_handler;
387 
394  Particles::ParticleHandler<dim> particle_handler_backup;
395 
401  std::unique_ptr<Property::Manager<dim>> property_manager;
402 
407 
421 
434 
443  unsigned int particle_weight;
444 
453 
460  std::map<types::subdomain_id, unsigned int>
461  get_subdomain_id_to_neighbor_map() const;
462 
468  void
469  apply_particle_per_cell_bounds();
470 
475  void advect_particles();
476 
480  void
481  local_initialize_particles(const typename ParticleHandler<dim>::particle_iterator &begin_particle,
482  const typename ParticleHandler<dim>::particle_iterator &end_particle);
483 
487  void
488  local_update_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
490 
499  void
500  local_advect_particles(const typename DoFHandler<dim>::active_cell_iterator &cell,
501  const typename ParticleHandler<dim>::particle_iterator &begin_particle,
502  const typename ParticleHandler<dim>::particle_iterator &end_particle,
504 
509  void
510  connect_particle_handler_signals(aspect::SimulatorSignals<dim> &signals,
511  ParticleHandler<dim> &particle_handler,
512  const bool connect_to_checkpoint_signals = true) const;
513  };
514 
515  /* -------------------------- inline and template functions ---------------------- */
516 
517  template <int dim>
518  template <class Archive>
519  void World<dim>::serialize (Archive &ar, const unsigned int)
520  {
521  // Note that although Boost claims to handle serialization of pointers
522  // correctly, at least for the case of unique_ptr it seems to not work.
523  // It works correctly when archiving the content of the pointer instead.
524  ar
525  &(*particle_handler)
526  ;
527  }
528  }
529 }
530 
531 #endif
void serialize(Archive &ar, const unsigned int version)
Definition: world.h:519
std::unique_ptr< internal::SolutionEvaluators< dim > > construct_solution_evaluators(const SimulatorAccess< dim > &simulator_access, const UpdateFlags update_flags)
unsigned int min_particles_per_cell
Definition: world.h:420
std::unique_ptr< Particles::ParticleHandler< dim > > particle_handler
Definition: world.h:386
unsigned int max_particles_per_cell
Definition: world.h:433
std::unique_ptr< Interpolator::Interface< dim > > interpolator
Definition: world.h:380
unsigned int particle_weight
Definition: world.h:443
std::unique_ptr< Generator::Interface< dim > > generator
Definition: world.h:370
void declare_parameters(ParameterHandler &prm)
std::unique_ptr< Integrator::Interface< dim > > integrator
Definition: world.h:375
std::unique_ptr< Property::Manager< dim > > property_manager
Definition: world.h:401
Definition: compat.h:59
ParticleLoadBalancing::Kind particle_load_balancing
Definition: world.h:406
bool update_ghost_particles
Definition: world.h:452
Particles::ParticleHandler< dim > particle_handler_backup
Definition: world.h:394
Definition: compat.h:42