Fluid structure interaction suite
mapping_eulerian.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 by Luca Heltai
4 //
5 // This file is part of the FSI-suite platform, based on the deal.II library.
6 //
7 // The FSI-suite platform is free software; you can use it, redistribute it,
8 // and/or modify it under the terms of the GNU Lesser General Public License as
9 // published by the Free Software Foundation; either version 3.0 of the License,
10 // or (at your option) any later version. The full text of the license can be
11 // found in the file LICENSE at the top level of the FSI-suite platform
12 // distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef parsed_tools_mapping_fe_field_h
17 #define parsed_tools_mapping_fe_field_h
18 
19 #include <deal.II/base/config.h>
20 
22 
25 
27 
30 
32 
33 namespace ParsedTools
34 {
73  template <int dim, int spacedim = dim>
74  class MappingEulerian : public dealii::ParameterAcceptor
75  {
76  public:
78  const dealii::DoFHandler<dim, spacedim> &dh,
79  const std::string &section_name = "",
80  const std::string &initial_configuration_or_displacement = "",
81  const bool use_displacement = false,
82  const dealii::ComponentMask &mask = dealii::ComponentMask());
83 
90  template <typename VectorType>
91  void
92  initialize(VectorType &configuration_or_displacement);
93 
94 
101  template <typename VectorType>
102  void
103  initialize(VectorType &configuration_or_displacement,
104  VectorType &locally_relevant_configuration_or_displacement);
105 
109  operator const dealii::Mapping<dim, spacedim> &() const;
110 
114  const dealii::Mapping<dim, spacedim> &
115  operator()() const;
116 
117  private:
121  const dealii::SmartPointer<const dealii::DoFHandler<dim, spacedim>>
123 
127  const dealii::ComponentMask mask;
128 
133 
138 
142  std::unique_ptr<dealii::Mapping<dim, spacedim>> mapping;
143  };
144 
145 
146 // Template implementation
147 #ifndef DOXYGEN
148  template <int dim, int spacedim>
149  template <typename VectorType>
150  void
152  VectorType &configuration_or_displacement)
153  {
154  initialize(configuration_or_displacement, configuration_or_displacement);
155  }
156 
157 
158 
159  template <int dim, int spacedim>
160  template <typename VectorType>
161  void
163  VectorType &configuration_or_displacement,
164  VectorType &locally_relevant_configuration_or_displacement)
165  {
166  // Interpolate the user data
167  if (initial_configuration_or_displacement_expression != "")
168  {
169  dealii::FunctionParser<spacedim> initial_configuration(
170  initial_configuration_or_displacement_expression);
171 
172  AssertThrow(initial_configuration.n_components ==
173  dof_handler->get_fe().n_components(),
174  dealii::ExcMessage("The number of components in the "
175  "configuration expression must be equal "
176  "to the number of components in the "
177  "fe."));
178 
179 
180  dealii::VectorTools::interpolate(*dof_handler,
181  initial_configuration,
182  configuration_or_displacement,
183  mask);
184  }
185  else
186  {
187  if (use_displacement)
188  configuration_or_displacement = 0;
189  else
190  {
191  if (dof_handler->get_triangulation()
192  .all_reference_cells_are_hyper_cube())
193  dealii::VectorTools::get_position_vector(
194  *dof_handler, configuration_or_displacement, mask);
195  else
196  {
197  // Use interpolation to get the position vector.
198  const std::string id[3] = {"x", "y", "z"};
199  std::string id_expression;
200  std::string sep = "";
201  unsigned int j = 0;
202  for (unsigned int i = 0;
203  i < dof_handler->get_fe().n_components();
204  ++i)
205  {
206  if (mask[i] && j < spacedim)
207  id_expression += sep + id[j++];
208  else
209  id_expression += sep + "0";
210  sep = "; ";
211  }
212 
213  dealii::FunctionParser<spacedim> initial_configuration(
214  id_expression);
215 
216  dealii::VectorTools::interpolate(*dof_handler,
217  initial_configuration,
218  configuration_or_displacement,
219  mask);
220  }
221  }
222  }
223  // Copy to the locally relevant vector
224  locally_relevant_configuration_or_displacement =
225  configuration_or_displacement;
226 
227  if (use_displacement)
228  // Finallly initialize the mapping with our own configuration
229  // vector.
230  {
231  AssertThrow(
232  dof_handler->get_triangulation().all_reference_cells_are_hyper_cube(),
233  dealii::ExcMessage("The displacement mapping is only "
234  "supported for hypercube grids."));
235 
236  AssertThrow(mask == dealii::ComponentMask(),
238  "Using the displacement is only possible with default "
239  "component mask."));
240 
241  const auto degree = dof_handler->get_fe().degree;
242  mapping.reset(new dealii::MappingQEulerian<dim, VectorType, spacedim>(
243  degree,
244  *dof_handler,
245  locally_relevant_configuration_or_displacement));
246  }
247  else
248  {
249  // Finallly initialize the mapping with our own configuration
250  // vector.
251  mapping.reset(new dealii::MappingFEField<dim, spacedim, VectorType>(
252  *dof_handler, locally_relevant_configuration_or_displacement, mask));
253  }
254  }
255 #endif
256 
257 } // namespace ParsedTools
258 #endif
const std::string section_name
A wrapper class for MappingFEField or MappingQEulerian.
const ComponentMask mask
What components should be interpreted as the displacement.
MappingEulerian(const DoFHandler< dim, spacedim > &dh, const std::string &section_name="", const std::string &initial_configuration_or_displacement="", const bool use_displacement=false, const ComponentMask &mask=ComponentMask())
bool use_displacement
Switch from displacement to configuration.
std::unique_ptr< Mapping< dim, spacedim > > mapping
The actual mapping.
const Mapping< dim, spacedim > & operator()() const
Return a reference to the actual mapping.
const SmartPointer< const DoFHandler< dim, spacedim > > dof_handler
A pointer to the dof handler.
void initialize(VectorType &configuration_or_displacement, VectorType &locally_relevant_configuration_or_displacement)
Actually build the mapping from the given configuration or displacement.
std::string initial_configuration_or_displacement_expression
What configuration to store when the mapping is initialized.
void initialize(VectorType &configuration_or_displacement)
Actually build the mapping from the given configuration or displacement.
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
unsigned int n_components(const std::string &component_names)
Count the number of components in the given list of comma separated components.
Definition: components.cc:32
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...