ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2022 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_property_interface_h
22 #define _aspect_particle_property_interface_h
23 
25 #include <aspect/global.h>
26 
29 
30 #include <deal.II/particles/particle.h>
31 #include <deal.II/particles/particle_handler.h>
32 #include <deal.II/particles/property_pool.h>
33 #include <deal.II/fe/fe_update_flags.h>
34 
35 #include <memory>
36 
37 namespace aspect
38 {
39  namespace Particle
40  {
41  namespace Property
42  {
43  using namespace ::Particles;
44 
80  {
81  public:
86 
99  ParticlePropertyInformation(const std::vector<std::vector<std::pair<std::string,unsigned int>>> &property_information);
100 
105  bool
106  fieldname_exists(const std::string &name) const;
107 
111  unsigned int
112  get_field_index_by_name(const std::string &name) const;
113 
117  std::string
118  get_field_name_by_index(const unsigned int field_index) const;
119 
124  unsigned int
125  get_position_by_field_name(const std::string &name) const;
126 
131  unsigned int
132  get_components_by_field_name(const std::string &name) const;
133 
139  unsigned int
140  get_position_by_field_index(const unsigned int field_index) const;
141 
146  unsigned int
147  get_components_by_field_index(const unsigned int field_index) const;
148 
154  unsigned int
155  get_position_by_plugin_index(const unsigned int plugin_index) const;
156 
161  unsigned int
162  get_components_by_plugin_index(const unsigned int plugin_index) const;
163 
168  unsigned int
169  get_fields_by_plugin_index(const unsigned int plugin_index) const;
170 
171 
175  unsigned int
176  n_plugins() const;
177 
181  unsigned int
182  n_fields() const;
183 
187  unsigned int
188  n_components() const;
189 
190  private:
194  std::vector<std::string> field_names;
195 
199  std::vector<unsigned int> components_per_field;
200 
205  std::vector<unsigned int> position_per_field;
206 
211  std::vector<unsigned int> fields_per_plugin;
212 
216  std::vector<unsigned int> components_per_plugin;
217 
222  std::vector<unsigned int> position_per_plugin;
223 
228  unsigned int number_of_components;
229 
233  unsigned int number_of_fields;
234 
238  unsigned int number_of_plugins;
239  };
240 
242  {
263  };
264 
271  {
297  };
298 
307  template <int dim>
309  {
310  public:
322  virtual
323  void
324  initialize_one_particle_property (const Point<dim> &position,
325  std::vector<double> &particle_properties) const;
326 
353  virtual
354  void
355  update_particle_properties (const unsigned int data_position,
356  const std::vector<Vector<double>> &solution,
357  const std::vector<std::vector<Tensor<1,dim>>> &gradients,
358  typename ParticleHandler<dim>::particle_iterator_range &particles) const;
359 
389  virtual
390  void
391  update_particle_property (const unsigned int data_position,
392  const Vector<double> &solution,
393  const std::vector<Tensor<1,dim>> &gradients,
394  typename ParticleHandler<dim>::particle_iterator &particle) const;
395 
396 
409  virtual
411  need_update () const;
412 
421  virtual
422  UpdateFlags
423  get_needed_update_flags () const;
424 
439  virtual
441  late_initialization_mode () const;
442 
456  virtual
457  std::vector<std::pair<std::string, unsigned int>>
458  get_property_information() const = 0;
459  };
460 
470  template <int dim>
471  class IntegratorProperties : public Interface<dim>
472  {
473  public:
479  void
480  initialize_one_particle_property (const Point<dim> &position,
481  std::vector<double> &particle_properties) const override;
482 
490  std::vector<std::pair<std::string, unsigned int>>
491  get_property_information() const override;
492 
497  void
498  parse_parameters (ParameterHandler &prm) override;
499 
500  private:
506  };
507 
508 
509 
515  template <int dim>
516  class Manager : public Plugins::ManagerBase<Interface<dim>>, public SimulatorAccess<dim>
517  {
518  public:
523  void
524  initialize () override;
525 
531  void
532  initialize_one_particle (typename ParticleHandler<dim>::particle_iterator &particle) const;
533 
540  std::vector<double>
541  initialize_late_particle (const Point<dim> &particle_location,
542  const ParticleHandler<dim> &particle_handler,
543  const Interpolator::Interface<dim> &interpolator,
544  const typename parallel::distributed::Triangulation<dim>::active_cell_iterator &cell = typename parallel::distributed::Triangulation<dim>::active_cell_iterator()) const;
545 
557  void
558  update_particles (typename ParticleHandler<dim>::particle_iterator_range &particles,
559  const std::vector<Vector<double>> &solution,
560  const std::vector<std::vector<Tensor<1,dim>>> &gradients) const;
561 
574  need_update () const;
575 
582  UpdateFlags
583  get_needed_update_flags () const;
584 
589  bool
590  plugin_name_exists(const std::string &name) const;
591 
601  bool
602  check_plugin_order(const std::string &first, const std::string &second) const;
603 
607  unsigned int get_plugin_index_by_name(const std::string &name) const;
608 
623  template <typename ParticlePropertyType,
624  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,ParticlePropertyType>::value>>
626  bool
627  has_matching_property () const;
628 
645  template <typename ParticlePropertyType,
646  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,ParticlePropertyType>::value>>
648  const ParticlePropertyType &
649  get_matching_property () const;
650 
658  unsigned int
659  get_n_property_components () const;
660 
669  std::size_t
670  get_particle_size () const;
671 
679  get_data_info() const;
680 
689  unsigned int
690  get_property_component_by_name(const std::string &name) const;
691 
710  static
711  void
712  register_particle_property (const std::string &name,
713  const std::string &description,
714  void (*declare_parameters_function) (ParameterHandler &),
715  std::unique_ptr<Property::Interface<dim>> (*factory_function) ());
716 
717 
721  static
722  void
723  declare_parameters (ParameterHandler &prm);
724 
728  void
729  parse_parameters (ParameterHandler &prm) override;
730 
736  void set_particle_world_index(unsigned int particle_world_index);
737 
747  static
748  void
749  write_plugin_graph (std::ostream &output_stream);
750 
751  private:
755  unsigned int particle_world_index;
756 
762  };
763 
764  /* -------------------------- inline and template functions ---------------------- */
765 
766 
767  template <int dim>
768  template <typename ParticlePropertyType, typename>
769  inline
770  bool
772  {
773  return this->template has_matching_active_plugin<ParticlePropertyType>();
774  }
775 
776 
777  template <int dim>
778  template <typename ParticlePropertyType, typename>
779  inline
780  const ParticlePropertyType &
782  {
783  return this->template get_matching_active_plugin<ParticlePropertyType>();
784  }
785 
786 
793 #define ASPECT_REGISTER_PARTICLE_PROPERTY(classname,name,description) \
794  template class classname<2>; \
795  template class classname<3>; \
796  namespace ASPECT_REGISTER_PARTICLE_PROPERTY_ ## classname \
797  { \
798  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Property::Interface<2>,classname<2>> \
799  dummy_ ## classname ## _2d (&aspect::Particle::Property::Manager<2>::register_particle_property, \
800  name, description); \
801  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Property::Interface<3>,classname<3>> \
802  dummy_ ## classname ## _3d (&aspect::Particle::Property::Manager<3>::register_particle_property, \
803  name, description); \
804  }
805 
806  }
807  }
808 }
809 
810 #endif
std::string get_field_name_by_index(const unsigned int field_index) const
StructuredDataLookup< dim > DEAL_II_DEPRECATED
DEAL_II_DEPRECATED const ParticlePropertyType & get_matching_property() const
ParticlePropertyInformation property_information
Definition: interface.h:761
unsigned int get_components_by_field_index(const unsigned int field_index) const
void write_plugin_graph(std::ostream &output_stream)
unsigned int get_components_by_field_name(const std::string &name) const
unsigned int get_position_by_field_name(const std::string &name) const
bool fieldname_exists(const std::string &name) const
unsigned int get_field_index_by_name(const std::string &name) const
unsigned int get_position_by_plugin_index(const unsigned int plugin_index) const
Definition: compat.h:59
unsigned int get_components_by_plugin_index(const unsigned int plugin_index) const
unsigned int get_fields_by_plugin_index(const unsigned int plugin_index) const
DEAL_II_DEPRECATED bool has_matching_property() const
void declare_parameters(ParameterHandler &prm)
unsigned int get_position_by_field_index(const unsigned int field_index) const