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>
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
108  const Point<dim> &position) const;
109 
110 
121  virtual
122  void
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>
151  {
152  public:
160 
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
206 
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
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>> &
261 
266  const std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> &
268 
273  const std::set<types::boundary_id> &
275 
281  const std::set<types::boundary_id> &
283 
289  const std::set<types::boundary_id> &
291 
296  const std::set<types::boundary_id> &
298 
304  const std::set<types::boundary_id> &
306 
310  double get_free_surface_theta () const;
311 
326  const LinearAlgebra::Vector &
328 
333  const LinearAlgebra::Vector &
335 
339  const DoFHandler<dim> &
341 
351  template <typename MeshDeformationType,
352  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
353  bool
355 
367  template <typename MeshDeformationType,
368  typename = typename std::enable_if_t<std::is_base_of<Interface<dim>,MeshDeformationType>::value>>
369  const MeshDeformationType &
371 
372 
378  const Mapping<dim> &
379  get_level_mapping(const unsigned int level) const;
380 
390  static
391  void
392  write_plugin_graph (std::ostream &output_stream);
393 
397  DeclException1 (ExcMeshDeformationNameNotFound,
398  std::string,
399  << "Could not find entry <"
400  << arg1
401  << "> among the names of registered mesh deformation objects.");
402 
403  private:
412 
426 
432 
438 
447  unsigned int get_mapping_degree () const;
448 
454  template <unsigned int mesh_deformation_fe_degree>
456 
473 
478 
483 
488  Simulator<dim> &sim;
489 
495 
500 
507 
515 
520 
530 
540 
545 
550 
556 
562 
567  std::map<types::boundary_id,std::vector<std::unique_ptr<Interface<dim>>>> mesh_deformation_objects;
568 
573  std::map<types::boundary_id, std::vector<std::string>> mesh_deformation_object_names;
574 
581 
588 
595 
601 
609 
616 
622 
624 
633 
638 
643 
648 
653 
658 
663 
664  friend class Simulator<dim>;
665  friend class SimulatorAccess<dim>;
666  };
667 
668 
669  template <int dim>
670  template <class Archive>
671  void MeshDeformationHandler<dim>::save (Archive &ar,
672  const unsigned int) const
673  {
674  // let all the mesh deformation plugins save their data in a map and then
675  // serialize that
676  //TODO: for now we assume the same plugins are active before and after restart.
677  std::map<std::string,std::string> saved_text;
678  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
679  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
680  p->save (saved_text);
681 
682  ar &saved_text;
683  }
684 
685 
686  template <int dim>
687  template <class Archive>
689  const unsigned int)
690  {
691  // get the map back out of the stream; then let the mesh deformation plugins
692  // that we currently have get their data from there. note that this
693  // may not be the same set ofmesh deformation plugins we had when we saved
694  // their data
695  std::map<std::string,std::string> saved_text;
696  ar &saved_text;
697 
698  for (const auto &boundary_id_and_mesh_deformation_objects : mesh_deformation_objects)
699  for (const auto &p : boundary_id_and_mesh_deformation_objects.second)
700  p->load (saved_text);
701  }
702 
703 
704 
705 
706  template <int dim>
707  template <typename MeshDeformationType, typename>
708  inline
709  bool
711  {
712  for (const auto &object_iterator : mesh_deformation_objects)
713  for (const auto &p : object_iterator.second)
714  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
715  return true;
716 
717  return false;
718  }
719 
720 
721 
722  template <int dim>
723  template <typename MeshDeformationType, typename>
724  inline
725  const MeshDeformationType &
727  {
728  AssertThrow(has_matching_mesh_deformation_object<MeshDeformationType> (),
729  ExcMessage("You asked MeshDeformation::MeshDeformationHandler::get_matching_mesh_deformation_object() for a "
730  "mesh deformation object of type <" + boost::core::demangle(typeid(MeshDeformationType).name()) + "> "
731  "that could not be found in the current model. Activate this "
732  "mesh deformation in the input file."));
733 
734  for (const auto &object_iterator : mesh_deformation_objects)
735  for (const auto &p : object_iterator.second)
736  if (Plugins::plugin_type_matches<MeshDeformationType>(*p))
737  return Plugins::get_plugin_as_type<MeshDeformationType>(*p);
738 
739  // We will never get here, because we had the Assert above. Just to avoid warnings.
740  typename std::vector<std::unique_ptr<Interface<dim>>>::const_iterator mesh_def;
741  return Plugins::get_plugin_as_type<MeshDeformationType>(*(*mesh_def));
742 
743  }
744 
745 
752  template <int dim>
753  std::string
755 
756 
757 
765 #define ASPECT_REGISTER_MESH_DEFORMATION_MODEL(classname,name,description) \
766  template class classname<2>; \
767  template class classname<3>; \
768  namespace ASPECT_REGISTER_MESH_DEFORMATION_MODEL_ ## classname \
769  { \
770  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<2>,classname<2>> \
771  dummy_ ## classname ## _2d (&aspect::MeshDeformation::MeshDeformationHandler<2>::register_mesh_deformation, \
772  name, description); \
773  aspect::internal::Plugins::RegisterHelper<aspect::MeshDeformation::Interface<3>,classname<3>> \
774  dummy_ ## classname ## _3d (&aspect::MeshDeformation::MeshDeformationHandler<3>::register_mesh_deformation, \
775  name, description); \
776  }
777  }
778 }
779 
780 #endif
void execute(internal::Assembly::Scratch::ScratchBase< dim > &scratch, internal::Assembly::CopyData::CopyDataBase< dim > &data) const override
ApplyStabilization(const double stabilization_theta)
virtual bool needs_surface_stabilization() const
virtual void compute_velocity_constraints_on_boundary(const DoFHandler< dim > &mesh_deformation_dof_handler, AffineConstraints< double > &mesh_velocity_constraints, const std::set< types::boundary_id > &boundary_ids) const
virtual void compute_initial_deformation_as_constraints(const Mapping< dim > &mapping, const DoFHandler< dim > &mesh_deformation_dof_handler, const types::boundary_id boundary_indicator, AffineConstraints< double > &constraints) const
virtual Tensor< 1, dim > compute_initial_deformation_on_boundary(const types::boundary_id boundary_indicator, const Point< dim > &position) const
LinearAlgebra::BlockVector mesh_velocity
Definition: interface.h:506
std::set< types::boundary_id > tangential_mesh_deformation_boundary_indicators
Definition: interface.h:600
const std::set< types::boundary_id > & get_boundary_indicators_requiring_stabilization() const
const std::set< types::boundary_id > & get_free_surface_boundary_indicators() const
const std::set< types::boundary_id > & get_tangential_velocity_with_active_mesh_deformation_boundary_indicators() const
AffineConstraints< double > mesh_velocity_constraints
Definition: interface.h:555
const std::map< types::boundary_id, std::vector< std::string > > & get_active_mesh_deformation_names() const
void save(Archive &ar, const unsigned int version) const
Definition: interface.h:671
AffineConstraints< double > mesh_vertex_constraints
Definition: interface.h:561
std::set< types::boundary_id > zero_mesh_deformation_boundary_indicators
Definition: interface.h:608
MeshDeformationHandler(Simulator< dim > &simulator)
MGTransferType< dim, double > mg_transfer
Definition: interface.h:657
MGLevelObject< std::unique_ptr< Mapping< dim > > > level_mappings
Definition: interface.h:647
MGLevelObject<::LinearAlgebra::distributed::Vector< double > > level_displacements
Definition: interface.h:652
const Mapping< dim > & get_level_mapping(const unsigned int level) const
const DoFHandler< dim > & get_mesh_deformation_dof_handler() const
const LinearAlgebra::Vector & get_mesh_displacements() const
std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > mesh_deformation_objects
Definition: interface.h:567
std::set< types::boundary_id > tangential_velocity_without_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:594
const MeshDeformationType & get_matching_mesh_deformation_object() const
Definition: interface.h:726
void parse_parameters(ParameterHandler &prm)
void load(Archive &ar, const unsigned int version)
Definition: interface.h:688
const LinearAlgebra::Vector & get_initial_topography() const
std::set< types::boundary_id > tangential_velocity_with_prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:587
const std::set< types::boundary_id > & get_active_mesh_deformation_boundary_indicators() const
static void write_plugin_graph(std::ostream &output_stream)
std::set< types::boundary_id > boundary_indicators_requiring_stabilization
Definition: interface.h:621
DeclException1(ExcMeshDeformationNameNotFound, std::string,<< "Could not find entry <"<< arg1<< "> among the names of registered mesh deformation objects.")
std::set< types::boundary_id > prescribed_mesh_deformation_boundary_indicators
Definition: interface.h:580
void set_assemblers(const SimulatorAccess< dim > &simulator_access, aspect::Assemblers::Manager< dim > &assemblers) const
const std::map< types::boundary_id, std::vector< std::unique_ptr< Interface< dim > > > > & get_active_mesh_deformation_models() const
std::set< types::boundary_id > free_surface_boundary_indicators
Definition: interface.h:615
static void declare_parameters(ParameterHandler &prm)
const std::set< types::boundary_id > & get_tangential_velocity_without_active_mesh_deformation_boundary_indicators() const
std::map< types::boundary_id, std::vector< std::string > > mesh_deformation_object_names
Definition: interface.h:573
static void register_mesh_deformation(const std::string &name, const std::string &description, void(*declare_parameters_function)(ParameterHandler &), std::unique_ptr< Interface< dim >>(*factory_function)())
ObserverPointer< const Simulator< dim >, SimulatorAccess< dim > > simulator
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::string get_valid_model_names_pattern()
unsigned int boundary_id