Fluid structure interaction suite
non_matching_coupling.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 #ifndef parsed_tools_non_matching_coupling_h
16 #define parsed_tools_non_matching_coupling_h
17 
18 #include <deal.II/base/config.h>
19 
21 
24 
26 
29 
31 
33 
35 #include "compute_intersections.h"
37 
38 namespace ParsedTools
39 {
47  template <int dim, int spacedim>
48  class NonMatchingCoupling : public dealii::ParameterAcceptor
49  {
50  public:
54  enum class CouplingType
55  {
56  // interpolation = 1 << 0, //<! Use interpolation for the coupling
58  1 << 1, //< Approximate L2-projection, using quadrature formulas on the
59  // embedded domain to drive the projection.
60  // approximate_H1 = 1 << 2, //< Approximate H1-projection,
61  // using quadrature
62  // // formulas on the embedded domain
63  // to drive the
64  // // projection.
65  exact_L2 = 1 << 3, //< Exact L2-projection, using
66  // quadratures on the
67  // intersection to drive the
68  // projection
69  // exact_H1 = 1 << 4, //< Exact H1-projection,
70  // using quadratures on the
71  // // intersection to drive
72  // the projection
73  //
74  };
75 
79  enum class RefinementStrategy
80  {
82  none = 1 << 1,
84  refine_space = 1 << 2,
86  refine_embedded = 1 << 3,
87  };
88 
93  const std::string &section_name = "",
94  const dealii::ComponentMask &embedded_mask = dealii::ComponentMask(),
95  const dealii::ComponentMask &space_mask = dealii::ComponentMask(),
99  const unsigned int space_pre_refinement = 0,
100  const unsigned int embedded_post_refinement = 0,
101  const std::string &quadrature_type = "gauss",
102  const unsigned int quadrature_order = 2,
103  const unsigned int quadrature_repetitions = 1,
104  double quadrature_tolerance = 1e-9);
105 
106 
111  void
112  initialize(const dealii::GridTools::Cache<spacedim, spacedim> &space_cache,
113  const dealii::DoFHandler<spacedim, spacedim> &space_dh,
114  const dealii::AffineConstraints<double> &space_constraints,
115  const dealii::GridTools::Cache<dim, spacedim> &embedded_cache,
116  const dealii::DoFHandler<dim, spacedim> &embedded_dh,
117  const dealii::AffineConstraints<double> &embedded_constraints);
118 
125  template <typename SparsityType>
126  void
127  assemble_sparsity(SparsityType &sparsity_pattern) const;
128 
132  template <typename MatrixType>
133  void
134  assemble_matrix(MatrixType &matrix) const;
135 
142  get_coupling_type() const;
143 
147  void
149  dealii::Triangulation<spacedim, spacedim> &space_tria,
150  dealii::Triangulation<dim, spacedim> &embedded_tria,
151  const bool apply_delta_refinements = true) const;
152 
156  boost::signals2::signal<void()> embedded_post_refinemnt_signal;
157 
161  boost::signals2::signal<void()> space_post_refinemnt_signal;
162 
163  protected:
167  const dealii::ComponentMask embedded_mask;
168 
172  const dealii::ComponentMask space_mask;
173 
177  dealii::Quadrature<dim> embedded_quadrature;
178 
183 
188 
192  unsigned int space_pre_refinement;
193 
198 
203 
207  unsigned int quadrature_order;
208 
213 
217  dealii::SmartPointer<const dealii::GridTools::Cache<spacedim, spacedim>,
220 
224  dealii::SmartPointer<const dealii::DoFHandler<spacedim, spacedim>,
227 
231  dealii::SmartPointer<const dealii::AffineConstraints<double>,
234 
238  dealii::SmartPointer<const dealii::GridTools::Cache<dim, spacedim>,
241 
245  dealii::SmartPointer<const dealii::DoFHandler<dim, spacedim>,
248 
252  dealii::SmartPointer<const dealii::AffineConstraints<double>,
255 
263 
267  mutable std::vector<std::tuple<
268  typename dealii::Triangulation<spacedim, spacedim>::cell_iterator,
269  typename dealii::Triangulation<dim, spacedim>::cell_iterator,
270  dealii::Quadrature<spacedim>>>
272  };
273 
274 
275 #ifndef DOXYGEN
276  // Template instantiations
277  template <int dim, int spacedim>
278  template <typename MatrixType>
279  void
281  {
282  const auto &space_mapping = space_cache->get_mapping();
283  const auto &embedded_mapping = embedded_cache->get_mapping();
284  if (coupling_type == CouplingType::approximate_L2)
285  {
286  dealii::NonMatching::create_coupling_mass_matrix(*space_cache,
287  *space_dh,
288  *embedded_dh,
289  embedded_quadrature,
290  matrix,
291  *space_constraints,
292  space_mask,
293  embedded_mask,
294  embedded_mapping,
295  *embedded_constraints);
296  }
297  else if (coupling_type == CouplingType::exact_L2)
298  {
299  if (cells_and_quads.empty() == true)
301  *space_cache,
302  *embedded_cache,
303  this->quadrature_order,
304  this->quadrature_tolerance);
305 
308  *space_dh,
309  *embedded_dh,
310  cells_and_quads,
311  matrix,
312  *space_constraints,
313  space_mask,
314  embedded_mask,
315  space_mapping,
316  embedded_mapping,
317  *embedded_constraints);
318  }
319  }
320 
321 
322 
323  template <int dim, int spacedim>
324  template <typename SparsityType>
325  void
327  {
328  Assert(space_dh, dealii::ExcNotInitialized());
329 
330  if (coupling_type == CouplingType::approximate_L2)
331  {
332  const auto &embedded_mapping = embedded_cache->get_mapping();
333 
334  dealii::NonMatching::create_coupling_sparsity_pattern(
335  *space_cache,
336  *space_dh,
337  *embedded_dh,
338  embedded_quadrature,
339  dsp,
340  *space_constraints,
341  space_mask,
342  embedded_mask,
343  embedded_mapping,
344  *embedded_constraints);
345  }
346  else if (coupling_type == CouplingType::exact_L2)
347  {
348  cells_and_quads.clear();
349  cells_and_quads =
351  *embedded_cache,
352  this->quadrature_order,
353  this->quadrature_tolerance);
356  cells_and_quads,
357  *space_dh,
358  *embedded_dh,
359  dsp,
360  *space_constraints,
361  space_mask,
362  embedded_mask,
363  *embedded_constraints);
364  }
365  else
366  {
367  AssertThrow(false,
369  "The requested coupling type is not implemented."));
370  }
371  }
372 
373 #endif
374 
375 } // namespace ParsedTools
376 
377 #endif
const std::string section_name
Wrapper around several functions in the NonMatching namespace.
boost::signals2::signal< void()> embedded_post_refinemnt_signal
Signals that embedded grid has been just refined.
SmartPointer< const DoFHandler< dim, spacedim >, NonMatchingCoupling< dim, spacedim > > embedded_dh
Embedded dof handler.
SmartPointer< const GridTools::Cache< dim, spacedim >, NonMatchingCoupling< dim, spacedim > > embedded_cache
Embedded cache.
unsigned int space_pre_refinement
Pre refinement to apply on the space mesh.
const ComponentMask space_mask
Space component mask.
void adjust_grid_refinements(Triangulation< spacedim, spacedim > &space_tria, Triangulation< dim, spacedim > &embedded_tria, const bool apply_delta_refinements=true) const
Adjust grid refinements according to the selected strategy.
std::vector< std::tuple< typename Triangulation< spacedim, spacedim >::cell_iterator, typename Triangulation< dim, spacedim >::cell_iterator, Quadrature< spacedim > > > cells_and_quads
Store cache information.
void assemble_sparsity(SparsityType &sparsity_pattern) const
Build the coupling sparsity pattern.
void assemble_matrix(MatrixType &matrix) const
Assemble the coupling matrix.
NonMatchingCoupling(const std::string &section_name="", const ComponentMask &embedded_mask=ComponentMask(), const ComponentMask &space_mask=ComponentMask(), const CouplingType coupling_type=CouplingType::approximate_L2, const RefinementStrategy refinement_strategy=RefinementStrategy::refine_embedded, const unsigned int space_pre_refinement=0, const unsigned int embedded_post_refinement=0, const std::string &quadrature_type="gauss", const unsigned int quadrature_order=2, const unsigned int quadrature_repetitions=1, double quadrature_tolerance=1e-9)
Constructor.
void initialize(const GridTools::Cache< spacedim, spacedim > &space_cache, const DoFHandler< spacedim, spacedim > &space_dh, const AffineConstraints< double > &space_constraints, const GridTools::Cache< dim, spacedim > &embedded_cache, const DoFHandler< dim, spacedim > &embedded_dh, const AffineConstraints< double > &embedded_constraints)
Initialize the class and return a linear operator representing the coupling matrix.
RefinementStrategy refinement_strategy
Refinement strategy.
CouplingType
Types of coupling that can used in non-matching coupling.
unsigned int embedded_quadrature_repetitions
Number of iterations of the base embedded quadrature.
CouplingType get_coupling_type() const
Get the coupling type object.
double quadrature_tolerance
Quadrature tolerance.
SmartPointer< const GridTools::Cache< spacedim, spacedim >, NonMatchingCoupling< dim, spacedim > > space_cache
Space cache.
unsigned int embedded_post_refinement
Post refinement to apply on the embedded mesh.
std::string embedded_quadrature_type
Embedded quadrature type.
const ComponentMask embedded_mask
Embedded component mask.
SmartPointer< const DoFHandler< spacedim, spacedim >, NonMatchingCoupling< dim, spacedim > > space_dh
Space dof handler.
@ refine_embedded
Force embedded grid to be locally smaller than embedded grid.
@ refine_space
Force space grid to be locally smaller than embedded grid.
boost::signals2::signal< void()> space_post_refinemnt_signal
Signals that the space grid has been just refined.
Quadrature< dim > embedded_quadrature
Embedded quadrature rule.
SmartPointer< const AffineConstraints< double >, NonMatchingCoupling< dim, spacedim > > space_constraints
Space constraints.
CouplingType coupling_type
Coupling type.
SmartPointer< const AffineConstraints< double >, NonMatchingCoupling< dim, spacedim > > embedded_constraints
Embedded constraints.
unsigned int quadrature_order
Order of the base embedded quadrature.
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
We collect in this namespace some wrappers around commonly used deal.II classes, derived from the Par...
RefinementStrategy
Refinement strategy implemented in the GridRefinement class.
Quadrature< spacedim > compute_intersection(const typename Triangulation< dim0, spacedim >::cell_iterator &cell0, const typename Triangulation< dim1, spacedim >::cell_iterator &cell1, const unsigned int degree, const Mapping< dim0, spacedim > &mapping0=(ReferenceCells::get_hypercube< dim0 >() .template get_default_linear_mapping< dim0, spacedim >()), const Mapping< dim1, spacedim > &mapping1=(ReferenceCells::get_hypercube< dim1 >() .template get_default_linear_mapping< dim1, spacedim >()))
Intersect cell0 and cell1 and construct a Quadrature<spacedim> of degree degreeover the intersection,...
void create_coupling_sparsity_pattern_with_exact_intersections(const std::vector< std::tuple< typename Triangulation< dim0, spacedim >::cell_iterator, typename Triangulation< dim1, spacedim >::cell_iterator, Quadrature< spacedim >>> &intersections_info, const DoFHandler< dim0, spacedim > &space_dh, const DoFHandler< dim1, spacedim > &immersed_dh, Sparsity &sparsity, const AffineConstraints< number > &constraints=AffineConstraints< number >(), const ComponentMask &space_comps=ComponentMask(), const ComponentMask &immersed_comps=ComponentMask(), const AffineConstraints< number > &immersed_constraints=AffineConstraints< number >())
Create a coupling sparsity pattern of two non-matching, overlapped grids.
void assemble_coupling_mass_matrix_with_exact_intersections(const DoFHandler< dim0, spacedim > &, const DoFHandler< dim1, spacedim > &, const std::vector< std::tuple< typename Triangulation< dim0, spacedim >::cell_iterator, typename Triangulation< dim1, spacedim >::cell_iterator, Quadrature< spacedim >>> &, Matrix &matrix, const AffineConstraints< typename Matrix::value_type > &, const ComponentMask &, const ComponentMask &, const Mapping< dim0, spacedim > &, const Mapping< dim1, spacedim > &, const AffineConstraints< typename Matrix::value_type > &)
Create the coupling mass matrix for non-matching, overlapping grids in an "exact" way,...