ASPECT
interface.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 - 2024 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>
30 #include <deal.II/dofs/dof_handler.h>
31 #include <deal.II/lac/affine_constraints.h>
32 #include <deal.II/base/index_set.h>
33 #include <deal.II/base/mg_level_object.h>
34 #include <deal.II/lac/la_parallel_vector.h>
35 #include <deal.II/multigrid/mg_constrained_dofs.h>
36 #include <deal.II/multigrid/mg_transfer_matrix_free.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
106  Tensor<1,dim>
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  };
141 
142 
143 
149  template <int dim>
150  class MeshDeformationHandler: public SimulatorAccess<dim>
151  {
152  public:
160 
164  ~MeshDeformationHandler() override;
165 
171  void initialize();
172 
177  void set_assemblers(const SimulatorAccess<dim> &simulator_access,
178  aspect::Assemblers::Manager<dim> &assemblers) const;
179 
184  void update();
185 
193  void execute();
194 
199  void setup_dofs();
200 
204  static
205  void declare_parameters (ParameterHandler &prm);
206 
210  void parse_parameters (ParameterHandler &prm);
211 
216  template <class Archive>
217  void save (Archive &ar,
218  const unsigned int version) const;
219 
224  template <class Archive>
225  void load (Archive &ar,
226  const unsigned int version);
227 
228  BOOST_SERIALIZATION_SPLIT_MEMBER()
229 
230 
247  static
248  void
249  register_mesh_deformation
250  (const std::string &name,
251  const std::string &description,
252  void (*declare_parameters_function) (ParameterHandler &),
253  std::unique_ptr<Interface<dim>> (*factory_function) ());
254 
259  const std::map<types::boundary_id, std::vector<std::string>> &
260  get_active_mesh_deformation_names () const;
261 
266  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
267  get_active_mesh_deformation_models () const;
268 
273  const std::set<types::boundary_id> &
274  get_active_mesh_deformation_boundary_indicators () const;
275 
280  const std::set<types::boundary_id> &
281  get_boundary_indicators_requiring_stabilization () const;
282 
288  const std::set<types::boundary_id> &
289  get_free_surface_boundary_indicators () const;
290 
294  double get_free_surface_theta () const;
295 
310  const LinearAlgebra::Vector &
311  get_initial_topography () const;
312 
317  const LinearAlgebra::Vector &
318  get_mesh_displacements () const;
319 
323  const DoFHandler<dim> &
324  get_mesh_deformation_dof_handler () const;
325 
335  template <typename MeshDeformationType,
336  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
337  bool
338  has_matching_mesh_deformation_object () const;
339 
351  template <typename MeshDeformationType,
352  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
353  const MeshDeformationType &
354  get_matching_mesh_deformation_object () const;
355 
356 
362  const Mapping<dim> &
363  get_level_mapping(const unsigned int level) const;
364 
374  static
375  void
376  write_plugin_graph (std::ostream &output_stream);
377 
381  DeclException1 (ExcMeshDeformationNameNotFound,
382  std::string,
383  << "Could not find entry <"
384  << arg1
385  << "> among the names of registered mesh deformation objects.");
386 
387  private:
395  void make_initial_constraints ();
396 
409  void make_constraints ();
410 
415  void compute_mesh_displacements ();
416 
421  void compute_mesh_displacements_gmg ();
422 
438  void set_initial_topography ();
439 
443  void interpolate_mesh_velocity ();
444 
448  void update_multilevel_deformation ();
449 
455 
460  const FESystem<dim> mesh_deformation_fe;
461 
466 
473 
481 
486 
496 
506 
511 
516 
521  AffineConstraints<double> mesh_velocity_constraints;
522 
527  AffineConstraints<double> mesh_vertex_constraints;
528 
533  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
534 
539  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
540 
547 
553 
560  std::set<types::boundary_id> zero_mesh_deformation_boundary_indicators;
561 
567  std::set<types::boundary_id> free_surface_boundary_indicators;
568 
573  std::set<types::boundary_id> boundary_indicators_requiring_stabilization;
574 
576 
583 
587  MGLevelObject<std::unique_ptr<Mapping<dim>>> level_mappings;
588 
592  MGLevelObject<::LinearAlgebra::distributed::Vector<double>> level_displacements;
593 
598 
602  MGConstrainedDoFs mg_constrained_dofs;
603 
604  friend class Simulator<dim>;
605  friend class SimulatorAccess<dim>;
606  };
607 
608 
609  template <int dim>
610  template <class Archive>
612  const unsigned int) const
613  {
614  // let all the mesh deformation plugins save their data in a map and then
615  // serialize that
616  //TODO: for now we assume the same plugins are active before and after restart.
617  std::map<std::string,std::string> saved_text;
618  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
619  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
620  p->save (saved_text);
621 
622  ar &saved_text;
623  }
624 
625 
626  template <int dim>
627  template <class Archive>
629  const unsigned int)
630  {
631  // get the map back out of the stream; then let the mesh deformation plugins
632  // that we currently have get their data from there. note that this
633  // may not be the same set ofmesh deformation plugins we had when we saved
634  // their data
635  std::map<std::string,std::string> saved_text;
636  ar &saved_text;
637 
638  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
639  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
640  p->load (saved_text);
641  }
642 
643 
644 
645 
646  template <int dim>
647  template <typename MeshDeformationType, typename>
648  inline
649  bool
651  {
652  for (const auto &object_iterator : mesh_deformation_objects)
653  for (const auto &p : object_iterator.second)
654  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
655  return true;
656 
657  return false;
658  }
659 
660 
661 
662  template <int dim>
663  template <typename MeshDeformationType, typename>
664  inline
665  const MeshDeformationType &
667  {
668  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
669  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
670  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
671  "that could not be found in the current model. Activate this "
672  "mesh deformation in the input file."));
673 
674  for (const auto &object_iterator : mesh_deformation_objects)
675  for (const auto &p : object_iterator.second)
676  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
677  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
678 
679  // We will never get here, because we had the Assert above. Just to avoid warnings.
680  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
681  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
682 
683  }
684 
685 
692  template <int dim>
693  std::string
695 
696 
697 
705 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
706  template class classname<2>; \
707  template class classname<3>; \
708  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
709  { \
710  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
711  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
712  name, description); \
713  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
714  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
715  name, description); \
716  }
717  }
718 }
719 
720 #endif
virtual void parse_parameters(ParameterHandler &prm)
const Simulator< dim > * simulator
::TrilinosWrappers::MPI::BlockVector BlockVector
Definition: global.h:269
ApplyStabilization(const double stabilization_theta)
std::set< types::boundary_id > prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:546
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:592
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:573
::TrilinosWrappers::MPI::Vector Vector
Definition: global.h:263
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:521
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:552
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:527
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:587
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:539
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:472
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:533
MGTransferMF< dim, double > mg_transfer
Definition: interface.h:597
std::string get_valid_model_names_pattern()
::MGTransferMatrixFree< dim, NumberType > MGTransferMF
Definition: compat.h:63
void load(Archive &ar, const unsigned int version)
Definition: interface.h:628
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:567
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:611
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:560
static void declare_parameters(ParameterHandler &prm)
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.")