ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2026 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 
22 #ifndef _aspect_mesh_deformation_interface_h
23 #define _aspect_mesh_deformation_interface_h
24 
25 #include <aspect/plugins.h>
27 #include <aspect/global.h>
28 
29 #include <deal.II/fe/fe_system.h>
32 #include <deal.II/base/index_set.h>
36 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
38 
39 namespace aspect
40 {
41  namespace Assemblers
42  {
49  template <int dim>
51  public SimulatorAccess<dim>
52  {
53  public:
54  ApplyStabilization(const double stabilization_theta);
55 
56  void
59 
60  private:
66  const double free_surface_theta;
67  };
68  }
69 
70  template <int dim> class Simulator;
71 
76  namespace MeshDeformation
77  {
87  template <int dim>
89  {
90  public:
94  virtual bool needs_surface_stabilization() const;
95 
96 
104  virtual
106  compute_initial_deformation_on_boundary(const types::boundary_id boundary_indicator,
107  const Point<dim> &position) const;
108 
109 
120  virtual
121  void
122  compute_initial_deformation_as_constraints(const Mapping<dim> &mapping,
123  const DoFHandler<dim> &mesh_deformation_dof_handler,
124  const types::boundary_id boundary_indicator,
125  AffineConstraints<double> &constraints) const;
126 
134  virtual
135  void
136  compute_velocity_constraints_on_boundary(const DoFHandler<dim> &mesh_deformation_dof_handler,
137  AffineConstraints<double> &mesh_velocity_constraints,
138  const std::set<types::boundary_id> &boundary_ids) const;
139 
154  virtual
155  double
156  boundary_composition (const types::boundary_id boundary_indicator,
157  const Point<dim> &position,
158  const unsigned int compositional_field) const;
159  };
160 
161 
162 
168  template <int dim>
169  class MeshDeformationHandler: public SimulatorAccess<dim>
170  {
171  public:
179 
183  ~MeshDeformationHandler() override;
184 
190  void initialize();
191 
196  void set_assemblers(const SimulatorAccess<dim> &simulator_access,
197  aspect::Assemblers::Manager<dim> &assemblers) const;
198 
203  void update();
204 
212  void execute();
213 
218  void setup_dofs();
219 
223  static
225 
230 
235  template <class Archive>
236  void save (Archive &ar,
237  const unsigned int version) const;
238 
243  template <class Archive>
244  void load (Archive &ar,
245  const unsigned int version);
246 
247  BOOST_SERIALIZATION_SPLIT_MEMBER()
248 
249 
266  static
267  void
268  register_mesh_deformation
269  (const std::string &name,
270  const std::string &description,
271  void (*declare_parameters_function) (ParameterHandler &),
272  std::unique_ptr<Interface<dim>> (*factory_function) ());
273 
278  const std::map<types::boundary_id, std::vector<std::string>> &
279  get_active_mesh_deformation_names () const;
280 
285  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
286  get_active_mesh_deformation_models () const;
287 
292  const std::set<types::boundary_id> &
293  get_active_mesh_deformation_boundary_indicators () const;
294 
300  const std::set<types::boundary_id> &
301  get_tangential_velocity_with_active_mesh_deformation_boundary_indicators () const;
302 
308  const std::set<types::boundary_id> &
309  get_tangential_velocity_without_active_mesh_deformation_boundary_indicators () const;
310 
315  const std::set<types::boundary_id> &
316  get_boundary_indicators_requiring_stabilization () const;
317 
323  const std::set<types::boundary_id> &
324  get_free_surface_boundary_indicators () const;
325 
329  double get_free_surface_theta () const;
330 
345  const LinearAlgebra::Vector &
346  get_initial_topography () const;
347 
352  const LinearAlgebra::Vector &
353  get_mesh_displacements () const;
354 
358  const DoFHandler<dim> &
359  get_mesh_deformation_dof_handler () const;
360 
370  template <typename MeshDeformationType,
371  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
372  bool
373  has_matching_mesh_deformation_object () const;
374 
386  template <typename MeshDeformationType,
387  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
388  const MeshDeformationType &
389  get_matching_mesh_deformation_object () const;
390 
391 
397  const Mapping<dim> &
398  get_level_mapping(const unsigned int level) const;
399 
407  double
408  boundary_composition (const types::boundary_id boundary_indicator,
409  const Point<dim> &position,
410  const unsigned int compositional_field) const;
411 
421  static
422  void
423  write_plugin_graph (std::ostream &output_stream);
424 
428  DeclException1 (ExcMeshDeformationNameNotFound,
429  std::string,
430  << "Could not find entry <"
431  << arg1
432  << "> among the names of registered mesh deformation objects.");
433 
434  private:
446  void make_initial_constraints (const double initial_deformation_scale);
447 
460  void make_constraints ();
461 
466  void compute_mesh_displacements ();
467 
472  void compute_mesh_displacements_gmg ();
473 
482  unsigned int get_mapping_degree () const;
483 
489  template <unsigned int mesh_deformation_fe_degree>
490  void compute_mesh_displacements_gmg_for_degree();
491 
498  void check_mesh_deformation ();
499 
504  template <unsigned int mesh_deformation_fe_degree,
505  typename SystemOperatorType>
506  void solve_mesh_deformation_local_smoothing(
507  const SystemOperatorType &laplace_operator,
508  const ::LinearAlgebra::distributed::Vector<double> &rhs,
510 
515  void setup_local_smoothing_multigrid();
516 
532  void set_initial_topography ();
533 
537  void interpolate_mesh_velocity ();
538 
543  void update_local_smoothing_multigrid();
544 
550 
556 
561 
568 
576 
581 
591 
601 
606 
611 
617 
623 
628  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
629 
634  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
635 
642 
649 
656 
662 
669  std::set<types::boundary_id> zero_mesh_deformation_boundary_indicators;
670 
676  std::set<types::boundary_id> free_surface_boundary_indicators;
677 
682  std::set<types::boundary_id> boundary_indicators_requiring_stabilization;
683 
685 
694 
699 
704 
716 
721 
726 
732 
733  friend class Simulator<dim>;
734  friend class SimulatorAccess<dim>;
735  };
736 
737 
738  template <int dim>
739  template <class Archive>
741  const unsigned int) const
742  {
743  // let all the mesh deformation plugins save their data in a map and then
744  // serialize that
745  //TODO: for now we assume the same plugins are active before and after restart.
746  std::map<std::string,std::string> saved_text;
747  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
748  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
749  p->save (saved_text);
750 
751  ar &saved_text;
752  }
753 
754 
755  template <int dim>
756  template <class Archive>
758  const unsigned int)
759  {
760  // get the map back out of the stream; then let the mesh deformation plugins
761  // that we currently have get their data from there. note that this
762  // may not be the same set ofmesh deformation plugins we had when we saved
763  // their data
764  std::map<std::string,std::string> saved_text;
765  ar &saved_text;
766 
767  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
768  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
769  p->load (saved_text);
770  }
771 
772 
773 
774 
775  template <int dim>
776  template <typename MeshDeformationType, typename>
777  inline
778  bool
780  {
781  for (const auto &object_iterator : mesh_deformation_objects)
782  for (const auto &p : object_iterator.second)
783  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
784  return true;
785 
786  return false;
787  }
788 
789 
790 
791  template <int dim>
792  template <typename MeshDeformationType, typename>
793  inline
794  const MeshDeformationType &
796  {
797  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
798  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
799  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
800  "that could not be found in the current model. Activate this "
801  "mesh deformation in the input file."));
802 
803  for (const auto &object_iterator : mesh_deformation_objects)
804  for (const auto &p : object_iterator.second)
805  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
806  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
807 
808  // We will never get here, because we had the Assert above. Just to avoid warnings.
809  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
810  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
811 
812  }
813 
814 
821  template <int dim>
822  std::string
824 
825 
826 
834 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
835  template class classname<2>; \
836  template class classname<3>; \
837  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
838  { \
839  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
840  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
841  name, description); \
842  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
843  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
844  name, description); \
845  }
846  }
847 }
848 
849 #endif
virtual void parse_parameters(ParameterHandler &prm)
MGTransferType< dim, double > local_smoothing_mg_transfer
Definition: interface.h:731
std::vector< index_type > data
ApplyStabilization(const double stabilization_theta)
std::set< types::boundary_id > prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:641
#define AssertThrow(cond, exc)
std::set< types::boundary_id > tangential_velocity_without_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:655
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:725
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:682
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:616
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:661
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:622
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:720
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:634
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:567
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:628
std::string get_valid_model_names_pattern()
unsigned int level
std::set< types::boundary_id > tangential_velocity_with_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:648
void load(Archive &ar, const unsigned int version)
Definition: interface.h:757
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:676
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:740
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:669
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.")