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>
37 #include <deal.II/multigrid/mg_transfer_global_coarsening.templates.h>
39 
40 namespace aspect
41 {
42  namespace Assemblers
43  {
50  template <int dim>
52  public SimulatorAccess<dim>
53  {
54  public:
55  ApplyStabilization(const double stabilization_theta);
56 
57  void
60 
61  private:
67  const double free_surface_theta;
68  };
69  }
70 
71  template <int dim> class Simulator;
72 
77  namespace MeshDeformation
78  {
88  template <int dim>
90  {
91  public:
95  virtual bool needs_surface_stabilization() const;
96 
97 
105  virtual
107  compute_initial_deformation_on_boundary(const types::boundary_id boundary_indicator,
108  const Point<dim> &position) const;
109 
110 
121  virtual
122  void
123  compute_initial_deformation_as_constraints(const Mapping<dim> &mapping,
124  const DoFHandler<dim> &mesh_deformation_dof_handler,
125  const types::boundary_id boundary_indicator,
126  AffineConstraints<double> &constraints) const;
127 
135  virtual
136  void
137  compute_velocity_constraints_on_boundary(const DoFHandler<dim> &mesh_deformation_dof_handler,
138  AffineConstraints<double> &mesh_velocity_constraints,
139  const std::set<types::boundary_id> &boundary_ids) const;
140 
155  virtual
156  double
157  boundary_composition (const types::boundary_id boundary_indicator,
158  const Point<dim> &position,
159  const unsigned int compositional_field) const;
160  };
161 
162 
163 
169  template <int dim>
170  class MeshDeformationHandler: public SimulatorAccess<dim>
171  {
172  public:
180 
184  ~MeshDeformationHandler() override;
185 
191  void initialize();
192 
197  void set_assemblers(const SimulatorAccess<dim> &simulator_access,
198  aspect::Assemblers::Manager<dim> &assemblers) const;
199 
204  void update();
205 
213  void execute();
214 
219  void setup_dofs();
220 
224  static
226 
231 
236  template <class Archive>
237  void save (Archive &ar,
238  const unsigned int version) const;
239 
244  template <class Archive>
245  void load (Archive &ar,
246  const unsigned int version);
247 
248  BOOST_SERIALIZATION_SPLIT_MEMBER()
249 
250 
267  static
268  void
269  register_mesh_deformation
270  (const std::string &name,
271  const std::string &description,
272  void (*declare_parameters_function) (ParameterHandler &),
273  std::unique_ptr<Interface<dim>> (*factory_function) ());
274 
279  const std::map<types::boundary_id, std::vector<std::string>> &
280  get_active_mesh_deformation_names () const;
281 
286  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
287  get_active_mesh_deformation_models () const;
288 
293  const std::set<types::boundary_id> &
294  get_active_mesh_deformation_boundary_indicators () const;
295 
301  const std::set<types::boundary_id> &
302  get_tangential_velocity_with_active_mesh_deformation_boundary_indicators () const;
303 
309  const std::set<types::boundary_id> &
310  get_tangential_velocity_without_active_mesh_deformation_boundary_indicators () const;
311 
316  const std::set<types::boundary_id> &
317  get_boundary_indicators_requiring_stabilization () const;
318 
324  const std::set<types::boundary_id> &
325  get_free_surface_boundary_indicators () const;
326 
330  double get_free_surface_theta () const;
331 
346  const LinearAlgebra::Vector &
347  get_initial_topography () const;
348 
353  const LinearAlgebra::Vector &
354  get_mesh_displacements () const;
355 
359  const DoFHandler<dim> &
360  get_mesh_deformation_dof_handler () const;
361 
371  template <typename MeshDeformationType,
372  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
373  bool
374  has_matching_mesh_deformation_object () const;
375 
387  template <typename MeshDeformationType,
388  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
389  const MeshDeformationType &
390  get_matching_mesh_deformation_object () const;
391 
392 
398  const Mapping<dim> &
399  get_level_mapping(const unsigned int level) const;
400 
408  double
409  boundary_composition (const types::boundary_id boundary_indicator,
410  const Point<dim> &position,
411  const unsigned int compositional_field) const;
412 
422  static
423  void
424  write_plugin_graph (std::ostream &output_stream);
425 
429  DeclException1 (ExcMeshDeformationNameNotFound,
430  std::string,
431  << "Could not find entry <"
432  << arg1
433  << "> among the names of registered mesh deformation objects.");
434 
435  private:
447  void make_initial_constraints (const double initial_deformation_scale);
448 
461  void make_constraints ();
462 
467  void compute_mesh_displacements ();
468 
473  void compute_mesh_displacements_gmg ();
474 
483  unsigned int get_mapping_degree () const;
484 
490  template <unsigned int mesh_deformation_fe_degree>
491  void compute_mesh_displacements_gmg_for_degree();
492 
499  void check_mesh_deformation ();
500 
516  void set_initial_topography ();
517 
521  void interpolate_mesh_velocity ();
522 
526  void update_multilevel_deformation ();
527 
533 
539 
544 
551 
559 
564 
574 
584 
589 
594 
600 
606 
611  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
612 
617  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
618 
625 
632 
639 
645 
652  std::set<types::boundary_id> zero_mesh_deformation_boundary_indicators;
653 
659  std::set<types::boundary_id> free_surface_boundary_indicators;
660 
665  std::set<types::boundary_id> boundary_indicators_requiring_stabilization;
666 
668 
677 
682 
687 
699 
704 
709 
714 
719 
720  friend class Simulator<dim>;
721  friend class SimulatorAccess<dim>;
722  };
723 
724 
725  template <int dim>
726  template <class Archive>
728  const unsigned int) const
729  {
730  // let all the mesh deformation plugins save their data in a map and then
731  // serialize that
732  //TODO: for now we assume the same plugins are active before and after restart.
733  std::map<std::string,std::string> saved_text;
734  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
735  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
736  p->save (saved_text);
737 
738  ar &saved_text;
739  }
740 
741 
742  template <int dim>
743  template <class Archive>
745  const unsigned int)
746  {
747  // get the map back out of the stream; then let the mesh deformation plugins
748  // that we currently have get their data from there. note that this
749  // may not be the same set ofmesh deformation plugins we had when we saved
750  // their data
751  std::map<std::string,std::string> saved_text;
752  ar &saved_text;
753 
754  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
755  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
756  p->load (saved_text);
757  }
758 
759 
760 
761 
762  template <int dim>
763  template <typename MeshDeformationType, typename>
764  inline
765  bool
767  {
768  for (const auto &object_iterator : mesh_deformation_objects)
769  for (const auto &p : object_iterator.second)
770  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
771  return true;
772 
773  return false;
774  }
775 
776 
777 
778  template <int dim>
779  template <typename MeshDeformationType, typename>
780  inline
781  const MeshDeformationType &
783  {
784  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
785  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
786  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
787  "that could not be found in the current model. Activate this "
788  "mesh deformation in the input file."));
789 
790  for (const auto &object_iterator : mesh_deformation_objects)
791  for (const auto &p : object_iterator.second)
792  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
793  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
794 
795  // We will never get here, because we had the Assert above. Just to avoid warnings.
796  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
797  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
798 
799  }
800 
801 
808  template <int dim>
809  std::string
811 
812 
813 
821 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
822  template class classname<2>; \
823  template class classname<3>; \
824  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
825  { \
826  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
827  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
828  name, description); \
829  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
830  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
831  name, description); \
832  }
833  }
834 }
835 
836 #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:624
MGTransferType< dim, double > mg_transfer
Definition: interface.h:713
#define AssertThrow(cond, exc)
std::set< types::boundary_id > tangential_velocity_without_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:638
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:708
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:665
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:599
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:644
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:605
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:703
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:617
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:550
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:611
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:631
void load(Archive &ar, const unsigned int version)
Definition: interface.h:744
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:659
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:727
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:652
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.")