ASPECT
interface.h
Go to the documentation of this file.
1 // ------------------------------------------------------
2 //
3 // SPDX-License-Identifier: GPL-2.0-or-later
4 //
5 // SPDX-FileCopyrightText: Copyright (C) 2011-2026 by the ASPECT authors.
6 //
7 // This file is part of ASPECT.
8 //
9 // Detailed license information governing the source code and
10 // contributions can be found in the folder LICENSES and in
11 // LICENSE and CONTRIBUTING.md at the top level directory.
12 //
13 // ------------------------------------------------------
14 
15 
16 #ifndef _aspect_mesh_deformation_interface_h
17 #define _aspect_mesh_deformation_interface_h
18 
19 #include <aspect/plugins.h>
21 #include <aspect/global.h>
22 
23 #include <deal.II/fe/fe_system.h>
26 #include <deal.II/base/index_set.h>
31 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
33 
34 namespace aspect
35 {
36  namespace Assemblers
37  {
44  template <int dim>
46  public SimulatorAccess<dim>
47  {
48  public:
49  ApplyStabilization(const double stabilization_theta);
50 
51  void
54 
55  private:
61  const double free_surface_theta;
62  };
63  }
64 
65  template <int dim> class Simulator;
66 
71  namespace MeshDeformation
72  {
82  template <int dim>
84  {
85  public:
89  virtual bool needs_surface_stabilization() const;
90 
91 
99  virtual
101  compute_initial_deformation_on_boundary(const types::boundary_id boundary_indicator,
102  const Point<dim> &position) const;
103 
104 
115  virtual
116  void
117  compute_initial_deformation_as_constraints(const Mapping<dim> &mapping,
118  const DoFHandler<dim> &mesh_deformation_dof_handler,
119  const types::boundary_id boundary_indicator,
120  AffineConstraints<double> &constraints) const;
121 
129  virtual
130  void
131  compute_velocity_constraints_on_boundary(const DoFHandler<dim> &mesh_deformation_dof_handler,
132  AffineConstraints<double> &mesh_velocity_constraints,
133  const std::set<types::boundary_id> &boundary_ids) const;
134 
149  virtual
150  double
151  boundary_composition (const types::boundary_id boundary_indicator,
152  const Point<dim> &position,
153  const unsigned int compositional_field) const;
154  };
155 
156 
157 
163  template <int dim>
164  class MeshDeformationHandler: public SimulatorAccess<dim>
165  {
166  public:
174 
178  ~MeshDeformationHandler() override;
179 
185  void initialize();
186 
191  void set_assemblers(const SimulatorAccess<dim> &simulator_access,
192  aspect::Assemblers::Manager<dim> &assemblers) const;
193 
198  void update();
199 
207  void execute();
208 
213  void setup_dofs();
214 
218  static
220 
225 
230  template <class Archive>
231  void save (Archive &ar,
232  const unsigned int version) const;
233 
238  template <class Archive>
239  void load (Archive &ar,
240  const unsigned int version);
241 
242  BOOST_SERIALIZATION_SPLIT_MEMBER()
243 
244 
261  static
262  void
263  register_mesh_deformation
264  (const std::string &name,
265  const std::string &description,
266  void (*declare_parameters_function) (ParameterHandler &),
267  std::unique_ptr<Interface<dim>> (*factory_function) ());
268 
273  const std::map<types::boundary_id, std::vector<std::string>> &
274  get_active_mesh_deformation_names () const;
275 
280  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
281  get_active_mesh_deformation_models () const;
282 
287  const std::set<types::boundary_id> &
288  get_active_mesh_deformation_boundary_indicators () const;
289 
295  const std::set<types::boundary_id> &
296  get_tangential_velocity_with_active_mesh_deformation_boundary_indicators () const;
297 
303  const std::set<types::boundary_id> &
304  get_tangential_velocity_without_active_mesh_deformation_boundary_indicators () const;
305 
310  const std::set<types::boundary_id> &
311  get_boundary_indicators_requiring_stabilization () const;
312 
318  const std::set<types::boundary_id> &
319  get_free_surface_boundary_indicators () const;
320 
324  double get_free_surface_theta () const;
325 
340  const LinearAlgebra::Vector &
341  get_initial_topography () const;
342 
347  const LinearAlgebra::Vector &
348  get_mesh_displacements () const;
349 
353  const DoFHandler<dim> &
354  get_mesh_deformation_dof_handler () const;
355 
365  template <typename MeshDeformationType,
366  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
367  bool
368  has_matching_mesh_deformation_object () const;
369 
381  template <typename MeshDeformationType,
382  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
383  const MeshDeformationType &
384  get_matching_mesh_deformation_object () const;
385 
386 
392  const Mapping<dim> &
393  get_level_mapping(const unsigned int level) const;
394 
402  double
403  boundary_composition (const types::boundary_id boundary_indicator,
404  const Point<dim> &position,
405  const unsigned int compositional_field) const;
406 
416  static
417  void
418  write_plugin_graph (std::ostream &output_stream);
419 
423  DeclException1 (ExcMeshDeformationNameNotFound,
424  std::string,
425  << "Could not find entry <"
426  << arg1
427  << "> among the names of registered mesh deformation objects.");
428 
429  private:
441  void make_initial_constraints (const double initial_deformation_scale);
442 
455  void make_constraints ();
456 
461  void compute_mesh_displacements ();
462 
467  void compute_mesh_displacements_gmg ();
468 
477  unsigned int get_mapping_degree () const;
478 
484  template <unsigned int mesh_deformation_fe_degree>
485  void compute_mesh_displacements_gmg_for_degree();
486 
493  void check_mesh_deformation ();
494 
499  template <unsigned int mesh_deformation_fe_degree,
500  typename SystemOperatorType>
501  void solve_mesh_deformation_local_smoothing(
502  const SystemOperatorType &laplace_operator,
503  const ::LinearAlgebra::distributed::Vector<double> &rhs,
505 
510  template <unsigned int mesh_deformation_fe_degree,
511  typename SystemOperatorType>
512  void solve_mesh_deformation_global_coarsening(
513  const SystemOperatorType &laplace_operator,
514  const ::LinearAlgebra::distributed::Vector<double> &rhs,
516 
523  std::set<types::boundary_id>
524  get_dirichlet_mesh_deformation_boundary_ids() const;
525 
532  create_distributed_mesh_displacements() const;
533 
538  void setup_local_smoothing_multigrid();
539 
544  void setup_global_coarsening_multigrid();
545 
561  void set_initial_topography ();
562 
566  void interpolate_mesh_velocity ();
567 
572  void update_local_smoothing_multigrid();
573 
578  void update_global_coarsening_multigrid();
579 
585 
591 
596 
603 
611 
616 
626 
636 
641 
646 
652 
658 
663  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
664 
669  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
670 
677 
684 
691 
697 
704  std::set<types::boundary_id> zero_mesh_deformation_boundary_indicators;
705 
711  std::set<types::boundary_id> free_surface_boundary_indicators;
712 
717  std::set<types::boundary_id> boundary_indicators_requiring_stabilization;
718 
720 
729 
734 
739 
751 
757 
766 
773 
778 
783 
790 
797  std::unique_ptr<MGTransferType<dim, double>> local_smoothing_mg_transfer;
798 
805  std::unique_ptr<GCMGTransferType<dim, double>> global_coarsening_mg_transfer;
806 
807  friend class Simulator<dim>;
808  friend class SimulatorAccess<dim>;
809  };
810 
811 
812  template <int dim>
813  template <class Archive>
815  const unsigned int) const
816  {
817  // let all the mesh deformation plugins save their data in a map and then
818  // serialize that
819  //TODO: for now we assume the same plugins are active before and after restart.
820  std::map<std::string,std::string> saved_text;
821  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
822  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
823  p->save (saved_text);
824 
825  ar &saved_text;
826  }
827 
828 
829  template <int dim>
830  template <class Archive>
832  const unsigned int)
833  {
834  // get the map back out of the stream; then let the mesh deformation plugins
835  // that we currently have get their data from there. note that this
836  // may not be the same set ofmesh deformation plugins we had when we saved
837  // their data
838  std::map<std::string,std::string> saved_text;
839  ar &saved_text;
840 
841  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
842  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
843  p->load (saved_text);
844  }
845 
846 
847 
848 
849  template <int dim>
850  template <typename MeshDeformationType, typename>
851  inline
852  bool
854  {
855  for (const auto &object_iterator : mesh_deformation_objects)
856  for (const auto &p : object_iterator.second)
857  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
858  return true;
859 
860  return false;
861  }
862 
863 
864 
865  template <int dim>
866  template <typename MeshDeformationType, typename>
867  inline
868  const MeshDeformationType &
870  {
871  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
872  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
873  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
874  "that could not be found in the current model. Activate this "
875  "mesh deformation in the input file."));
876 
877  for (const auto &object_iterator : mesh_deformation_objects)
878  for (const auto &p : object_iterator.second)
879  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
880  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
881 
882  // We will never get here, because we had the Assert above. Just to avoid warnings.
883  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
884  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
885 
886  }
887 
888 
895  template <int dim>
896  std::string
898 
899 
900 
908 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
909  template class classname<2>; \
910  template class classname<3>; \
911  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
912  { \
913  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
914  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
915  name, description); \
916  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
917  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
918  name, description); \
919  }
920  }
921 }
922 
923 #endif
virtual void parse_parameters(ParameterHandler &prm)
std::vector< index_type > data
ApplyStabilization(const double stabilization_theta)
std::set< types::boundary_id > prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:676
std::unique_ptr< MGTransferType< dim, double > > local_smoothing_mg_transfer
Definition: interface.h:797
#define AssertThrow(cond, exc)
std::set< types::boundary_id > tangential_velocity_without_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:690
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:782
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:717
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:651
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:696
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:657
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:777
virtual void load(const std::map< std::string, std::string > &status_strings)
std::map< types::boundary_id, std::vector< std::string > > mesh_deformation_object_names
Definition: interface.h:669
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:602
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:663
std::string get_valid_model_names_pattern()
unsigned int level
MGLevelObject< MGTwoLevelTransfer< dim, ::LinearAlgebra::distributed::Vector< double > > > global_coarsening_two_level_transfers
Definition: interface.h:772
std::set< types::boundary_id > tangential_velocity_with_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:683
std::unique_ptr< GCMGTransferType< dim, double > > global_coarsening_mg_transfer
Definition: interface.h:805
MGLevelObject< DoFHandler< dim > > global_coarsening_dof_handlers
Definition: interface.h:756
void load(Archive &ar, const unsigned int version)
Definition: interface.h:831
MGLevelObject< AffineConstraints< double > > global_coarsening_constraints
Definition: interface.h:765
static ::ExceptionBase & ExcMessage(std::string arg1)
void execute(internal::Assembly::Scratch::ScratchBase< dim > &scratch, internal::Assembly::CopyData::CopyDataBase< dim > &data) const override
virtual void save(std::map< std::string, std::string > &status_strings) const
std::set< types::boundary_id > free_surface_boundary_indicators
Definition: interface.h:711
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:814
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:704
static void declare_parameters(ParameterHandler &prm)
ObserverPointer< const Simulator< dim >, SimulatorAccess< dim > > simulator
DeclException1(ProbabilityFunctionNegative, Point< dim >,<< "Your probability density function in the particle generator " "returned a negative probability density for the following position: "<< arg1<< ". Please check your function expression.")