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:
522  Manager ();
523 
527  ~Manager () override;
528 
533  void
534  initialize () override;
535 
540  void
541  update () override;
542 
548  void
549  initialize_one_particle (typename ParticleHandler<dim>::particle_iterator &particle) const;
550 
557  std::vector<double>
558  initialize_late_particle (const Point<dim> &particle_location,
559  const ParticleHandler<dim> &particle_handler,
560  const Interpolator::Interface<dim> &interpolator,
561  const typename parallel::distributed::Triangulation<dim>::active_cell_iterator &cell = typename parallel::distributed::Triangulation<dim>::active_cell_iterator()) const;
562 
574  void
575  update_particles (typename ParticleHandler<dim>::particle_iterator_range &particles,
576  const std::vector<Vector<double>> &solution,
577  const std::vector<std::vector<Tensor<1,dim>>> &gradients) const;
578 
591  need_update () const;
592 
599  UpdateFlags
600  get_needed_update_flags () const;
601 
606  bool
607  plugin_name_exists(const std::string &name) const;
608 
618  bool
619  check_plugin_order(const std::string &first, const std::string &second) const;
620 
624  unsigned int get_plugin_index_by_name(const std::string &name) const;
625 
635  template <typename ParticlePropertyType,
636  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,ParticlePropertyType>::value>>
637  bool
638  has_matching_property () const;
639 
651  template <typename ParticlePropertyType,
652  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,ParticlePropertyType>::value>>
653  const ParticlePropertyType &
654  get_matching_property () const;
655 
663  unsigned int
664  get_n_property_components () const;
665 
674  std::size_t
675  get_particle_size () const;
676 
684  get_data_info() const;
685 
694  unsigned int
695  get_property_component_by_name(const std::string &name) const;
696 
715  static
716  void
717  register_particle_property (const std::string &name,
718  const std::string &description,
719  void (*declare_parameters_function) (ParameterHandler &),
720  std::unique_ptr<Property::Interface<dim>> (*factory_function) ());
721 
722 
726  static
727  void
728  declare_parameters (ParameterHandler &prm);
729 
733  void
734  parse_parameters (ParameterHandler &prm) override;
735 
741  void set_particle_world_index(unsigned int particle_world_index);
742 
752  static
753  void
754  write_plugin_graph (std::ostream &output_stream);
755 
756  private:
761  std::vector<std::string> plugin_names;
762 
768  };
769 
770  /* -------------------------- inline and template functions ---------------------- */
771 
772 
773  template <int dim>
774  template <typename ParticlePropertyType, typename>
775  inline
776  bool
778  {
779  return this->template has_matching_plugin_object<ParticlePropertyType>();
780  }
781 
782 
783  template <int dim>
784  template <typename ParticlePropertyType, typename>
785  inline
786  const ParticlePropertyType &
788  {
789  return this->template get_matching_plugin_object<ParticlePropertyType>();
790  }
791 
792 
799 #define ASPECT_REGISTER_PARTICLE_PROPERTY(classname,name,description) \
800  template class classname<2>; \
801  template class classname<3>; \
802  namespace ASPECT_REGISTER_PARTICLE_PROPERTY_ ## classname \
803  { \
804  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Property::Interface<2>,classname<2>> \
805  dummy_ ## classname ## _2d (&aspect::Particle::Property::Manager<2>::register_particle_property, \
806  name, description); \
807  aspect::internal::Plugins::RegisterHelper<aspect::Particle::Property::Interface<3>,classname<3>> \
808  dummy_ ## classname ## _3d (&aspect::Particle::Property::Manager<3>::register_particle_property, \
809  name, description); \
810  }
811 
812  }
813  }
814 }
815 
816 #endif
std::string get_field_name_by_index(const unsigned int field_index) const
StructuredDataLookup< dim > DEAL_II_DEPRECATED
ParticlePropertyInformation property_information
Definition: interface.h:767
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
const ParticlePropertyType & get_matching_property() const
Definition: interface.h:787
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
void declare_parameters(ParameterHandler &prm)
std::vector< std::string > plugin_names
Definition: interface.h:761
unsigned int get_position_by_field_index(const unsigned int field_index) const