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 
117  virtual
118  void
119  compute_velocity_constraints_on_boundary(const DoFHandler<dim> &mesh_deformation_dof_handler,
120  AffineConstraints<double> &mesh_velocity_constraints,
121  const std::set<types::boundary_id> &boundary_ids) const;
122  };
123 
124 
125 
131  template <int dim>
132  class MeshDeformationHandler: public SimulatorAccess<dim>
133  {
134  public:
142 
146  ~MeshDeformationHandler() override;
147 
153  void initialize();
154 
159  void set_assemblers(const SimulatorAccess<dim> &simulator_access,
160  aspect::Assemblers::Manager<dim> &assemblers) const;
161 
166  void update();
167 
175  void execute();
176 
181  void setup_dofs();
182 
186  static
187  void declare_parameters (ParameterHandler &prm);
188 
192  void parse_parameters (ParameterHandler &prm);
193 
198  template <class Archive>
199  void save (Archive &ar,
200  const unsigned int version) const;
201 
206  template <class Archive>
207  void load (Archive &ar,
208  const unsigned int version);
209 
210  BOOST_SERIALIZATION_SPLIT_MEMBER()
211 
212 
229  static
230  void
231  register_mesh_deformation
232  (const std::string &name,
233  const std::string &description,
234  void (*declare_parameters_function) (ParameterHandler &),
235  std::unique_ptr<Interface<dim>> (*factory_function) ());
236 
241  const std::map<types::boundary_id, std::vector<std::string>> &
242  get_active_mesh_deformation_names () const;
243 
248  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
249  get_active_mesh_deformation_models () const;
250 
255  const std::set<types::boundary_id> &
256  get_active_mesh_deformation_boundary_indicators () const;
257 
262  const std::set<types::boundary_id> &
263  get_boundary_indicators_requiring_stabilization () const;
264 
270  const std::set<types::boundary_id> &
271  get_free_surface_boundary_indicators () const;
272 
276  double get_free_surface_theta () const;
277 
292  const LinearAlgebra::Vector &
293  get_initial_topography () const;
294 
299  const LinearAlgebra::Vector &
300  get_mesh_displacements () const;
301 
305  const DoFHandler<dim> &
306  get_mesh_deformation_dof_handler () const;
307 
317  template <typename MeshDeformationType,
318  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
319  bool
320  has_matching_mesh_deformation_object () const;
321 
333  template <typename MeshDeformationType,
334  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
335  const MeshDeformationType &
336  get_matching_mesh_deformation_object () const;
337 
338 
344  const Mapping<dim> &
345  get_level_mapping(const unsigned int level) const;
346 
356  static
357  void
358  write_plugin_graph (std::ostream &output_stream);
359 
363  DeclException1 (ExcMeshDeformationNameNotFound,
364  std::string,
365  << "Could not find entry <"
366  << arg1
367  << "> among the names of registered mesh deformation objects.");
368 
369  private:
377  void make_initial_constraints ();
378 
391  void make_constraints ();
392 
397  void compute_mesh_displacements ();
398 
403  void compute_mesh_displacements_gmg ();
404 
420  void set_initial_topography ();
421 
425  void interpolate_mesh_velocity ();
426 
430  void update_multilevel_deformation ();
431 
437 
442  const FESystem<dim> mesh_deformation_fe;
443 
448 
455 
463 
468 
478 
488 
493 
498 
503  AffineConstraints<double> mesh_velocity_constraints;
504 
509  AffineConstraints<double> mesh_vertex_constraints;
510 
515  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
516 
521  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
522 
529 
535 
542  std::set<types::boundary_id> zero_mesh_deformation_boundary_indicators;
543 
549  std::set<types::boundary_id> free_surface_boundary_indicators;
550 
555  std::set<types::boundary_id> boundary_indicators_requiring_stabilization;
556 
558 
565 
569  MGLevelObject<std::unique_ptr<Mapping<dim>>> level_mappings;
570 
574  MGLevelObject<::LinearAlgebra::distributed::Vector<double>> level_displacements;
575 
580 
584  MGConstrainedDoFs mg_constrained_dofs;
585 
586  friend class Simulator<dim>;
587  friend class SimulatorAccess<dim>;
588  };
589 
590 
591  template <int dim>
592  template <class Archive>
594  const unsigned int) const
595  {
596  // let all the mesh deformation plugins save their data in a map and then
597  // serialize that
598  //TODO: for now we assume the same plugins are active before and after restart.
599  std::map<std::string,std::string> saved_text;
600  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
601  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
602  p->save (saved_text);
603 
604  ar &saved_text;
605  }
606 
607 
608  template <int dim>
609  template <class Archive>
611  const unsigned int)
612  {
613  // get the map back out of the stream; then let the mesh deformation plugins
614  // that we currently have get their data from there. note that this
615  // may not be the same set ofmesh deformation plugins we had when we saved
616  // their data
617  std::map<std::string,std::string> saved_text;
618  ar &saved_text;
619 
620  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
621  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
622  p->load (saved_text);
623  }
624 
625 
626 
627 
628  template <int dim>
629  template <typename MeshDeformationType, typename>
630  inline
631  bool
633  {
634  for (const auto &object_iterator : mesh_deformation_objects)
635  for (const auto &p : object_iterator.second)
636  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
637  return true;
638 
639  return false;
640  }
641 
642 
643 
644  template <int dim>
645  template <typename MeshDeformationType, typename>
646  inline
647  const MeshDeformationType &
649  {
650  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
651  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
652  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
653  "that could not be found in the current model. Activate this "
654  "mesh deformation in the input file."));
655 
656  for (const auto &object_iterator : mesh_deformation_objects)
657  for (const auto &p : object_iterator.second)
658  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
659  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
660 
661  // We will never get here, because we had the Assert above. Just to avoid warnings.
662  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
663  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
664 
665  }
666 
667 
674  template <int dim>
675  std::string
677 
678 
679 
687 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
688  template class classname<2>; \
689  template class classname<3>; \
690  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
691  { \
692  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
693  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
694  name, description); \
695  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
696  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
697  name, description); \
698  }
699  }
700 }
701 
702 #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:528
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:574
void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:555
::TrilinosWrappers::MPI::Vector Vector
Definition: global.h:263
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:503
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:534
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:509
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:569
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:521
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:454
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:515
MGTransferMF< dim, double > mg_transfer
Definition: interface.h:579
std::string get_valid_model_names_pattern()
::MGTransferMatrixFree< dim, NumberType > MGTransferMF
Definition: compat.h:64
void load(Archive &ar, const unsigned int version)
Definition: interface.h:610
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:549
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:593
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:542
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.")