Fluid structure interaction suite
assemble_nitsche_with_exact_intersections.cc
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 
17 #include <deal.II/base/config.h>
18 
21 
23 
24 #include <deal.II/fe/mapping.h>
25 #include <deal.II/fe/mapping_q1.h>
26 
29 #include <deal.II/grid/tria.h>
30 
31 
32 #ifdef DEAL_II_WITH_CGAL
33 
34 
36 using namespace dealii;
37 
38 namespace dealii
39 {
40  namespace NonMatching
41  {
42  template <int dim0, int dim1, int spacedim, typename Matrix>
43  void
45  const DoFHandler<dim0, spacedim> &space_dh,
46  const std::vector<std::tuple<
47  typename dealii::Triangulation<dim0, spacedim>::cell_iterator,
48  typename dealii::Triangulation<dim1, spacedim>::cell_iterator,
49  dealii::Quadrature<spacedim>>> &cells_and_quads,
50  Matrix &matrix,
51  const AffineConstraints<typename Matrix::value_type> &space_constraints,
52  const ComponentMask &space_comps,
53  const Mapping<dim0, spacedim> &space_mapping,
55  &nitsche_coefficient,
56  const double penalty)
57  {
58  AssertDimension(matrix.m(), space_dh.n_dofs());
59  AssertDimension(matrix.n(), space_dh.n_dofs());
60  Assert(dim1 <= dim0,
61  ExcMessage("This function can only work if dim1<=dim0"));
62 
63 
64 
65  const auto &space_fe = space_dh.get_fe();
66 
67  const unsigned int n_dofs_per_space_cell = space_fe.n_dofs_per_cell();
68 
69  const unsigned int n_space_fe_components = space_fe.n_components();
70 
71  FullMatrix<double> local_cell_matrix(n_dofs_per_space_cell,
72  n_dofs_per_space_cell);
73  // DoF indices
74  std::vector<types::global_dof_index> local_space_dof_indices(
75  n_dofs_per_space_cell);
76 
77 
78  const ComponentMask space_c =
79  (space_comps.size() == 0 ? ComponentMask(n_space_fe_components, true) :
80  space_comps);
81 
82 
83  AssertDimension(space_c.size(), n_space_fe_components);
84 
85  std::vector<unsigned int> space_gtl(n_space_fe_components,
87 
88  for (unsigned int i = 0, j = 0; i < n_space_fe_components; ++i)
89  {
90  if (space_c[i])
91  space_gtl[i] = j++;
92  }
93 
94 
95 
96  // Loop over vector of tuples, and gather everything together
97  double h;
98  for (const auto &infos : cells_and_quads)
99  {
100  const auto &[first_cell, second_cell, quad_formula] = infos;
101  if (first_cell->is_active())
102  {
103  local_cell_matrix = typename Matrix::value_type();
104 
105  const unsigned int n_quad_pts = quad_formula.size();
106  const auto &real_qpts = quad_formula.get_points();
107  std::vector<double> nitsche_coefficient_values(n_quad_pts);
108  nitsche_coefficient.value_list(real_qpts,
109  nitsche_coefficient_values);
110 
111  std::vector<Point<spacedim>> ref_pts_space(n_quad_pts);
112 
113  space_mapping.transform_points_real_to_unit_cell(first_cell,
114  real_qpts,
115  ref_pts_space);
116 
117  h = first_cell->diameter();
118  const auto &JxW = quad_formula.get_weights();
119  for (unsigned int q = 0; q < n_quad_pts; ++q)
120  {
121  const auto &q_ref_point = ref_pts_space[q];
122  for (unsigned int i = 0; i < n_dofs_per_space_cell; ++i)
123  {
124  const unsigned int comp_i =
125  space_dh.get_fe().system_to_component_index(i).first;
126  if (comp_i != numbers::invalid_unsigned_int)
127  {
128  for (unsigned int j = 0; j < n_dofs_per_space_cell;
129  ++j)
130  {
131  const unsigned int comp_j =
132  space_dh.get_fe()
134  .first;
135  if (space_gtl[comp_i] == space_gtl[comp_j])
136  {
137  local_cell_matrix(i, j) +=
138  nitsche_coefficient_values[q] *
139  (penalty / h) *
140  space_fe.shape_value(i, q_ref_point) *
141  space_fe.shape_value(j, q_ref_point) *
142  JxW[q];
143  }
144  }
145  }
146  }
147  }
148  typename DoFHandler<dim0, spacedim>::cell_iterator space_cell_dh(
149  *first_cell, &space_dh);
150 
151  space_cell_dh->get_dof_indices(local_space_dof_indices);
152  space_constraints.distribute_local_to_global(
153  local_cell_matrix, local_space_dof_indices, matrix);
154  }
155  }
156  }
157 
158  } // namespace NonMatching
159 } // namespace dealii
160 
161 
162 
163 #else
164 
165 
166 
167 template <int dim0, int dim1, int spacedim, typename Matrix>
168 void
171  const std::vector<
172  std::tuple<typename dealii::Triangulation<dim0, spacedim>::cell_iterator,
173  typename dealii::Triangulation<dim1, spacedim>::cell_iterator,
174  dealii::Quadrature<spacedim>>> &,
175  Matrix &,
177  const ComponentMask &,
178  const Mapping<dim0, spacedim> &)
179 {
180  Assert(false,
181  ExcMessage("This function needs CGAL to be installed, "
182  "but cmake could not find it."));
183  return {};
184 }
185 
186 
187 #endif
188 
189 
190 
191 template void
192 dealii::NonMatching::assemble_nitsche_with_exact_intersections<1, 1, 1>(
193  const DoFHandler<1, 1> &,
194  const std::vector<
195  std::tuple<typename dealii::Triangulation<1, 1>::cell_iterator,
196  typename dealii::Triangulation<1, 1>::cell_iterator,
197  dealii::Quadrature<1>>> &,
198  dealii::SparseMatrix<double> &,
199  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
200  const ComponentMask &,
201  const Mapping<1, 1> &,
202  const Function<1, double> &nitsche_coefficient,
203  const double);
204 
205 template void
206 dealii::NonMatching::assemble_nitsche_with_exact_intersections<2, 1, 2>(
207  const DoFHandler<2, 2> &,
208  const std::vector<
209  std::tuple<typename dealii::Triangulation<2, 2>::cell_iterator,
210  typename dealii::Triangulation<1, 2>::cell_iterator,
211  dealii::Quadrature<2>>> &,
212  dealii::SparseMatrix<double> &,
213  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
214  const ComponentMask &,
215  const Mapping<2, 2> &,
216  const Function<2, double> &nitsche_coefficient,
217  const double);
218 
219 
220 template void
221 dealii::NonMatching::assemble_nitsche_with_exact_intersections<2, 2, 2>(
222  const DoFHandler<2, 2> &,
223  const std::vector<
224  std::tuple<typename dealii::Triangulation<2, 2>::cell_iterator,
225  typename dealii::Triangulation<2, 2>::cell_iterator,
226  dealii::Quadrature<2>>> &,
227  dealii::SparseMatrix<double> &,
228  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
229  const ComponentMask &,
230  const Mapping<2, 2> &,
231  const Function<2, double> &nitsche_coefficient,
232  const double);
233 
234 
235 template void
236 dealii::NonMatching::assemble_nitsche_with_exact_intersections<3, 1, 3>(
237  const DoFHandler<3, 3> &,
238  const std::vector<
239  std::tuple<typename dealii::Triangulation<3, 3>::cell_iterator,
240  typename dealii::Triangulation<1, 3>::cell_iterator,
241  dealii::Quadrature<3>>> &,
242  dealii::SparseMatrix<double> &,
243  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
244  const ComponentMask &,
245  const Mapping<3, 3> &,
246  const Function<3, double> &nitsche_coefficient,
247  const double);
248 
249 template void
250 dealii::NonMatching::assemble_nitsche_with_exact_intersections<3, 2, 3>(
251  const DoFHandler<3, 3> &,
252  const std::vector<
253  std::tuple<typename dealii::Triangulation<3, 3>::cell_iterator,
254  typename dealii::Triangulation<2, 3>::cell_iterator,
255  dealii::Quadrature<3>>> &,
256  dealii::SparseMatrix<double> &,
257  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
258  const ComponentMask &,
259  const Mapping<3, 3> &,
260  const Function<3, double> &nitsche_coefficient,
261  const double);
262 
263 
264 
265 template void
266 dealii::NonMatching::assemble_nitsche_with_exact_intersections<3, 3, 3>(
267  const DoFHandler<3, 3> &,
268  const std::vector<
269  std::tuple<typename dealii::Triangulation<3, 3>::cell_iterator,
270  typename dealii::Triangulation<3, 3>::cell_iterator,
271  dealii::Quadrature<3>>> &,
272  dealii::SparseMatrix<double> &,
273  const AffineConstraints<dealii::SparseMatrix<double>::value_type> &,
274  const ComponentMask &,
275  const Mapping<3, 3> &,
276  const Function<3, double> &nitsche_coefficient,
277  const double);
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
unsigned int size() const
const FiniteElement< dim, spacedim > & get_fe(const types::fe_index index=0) const
types::global_dof_index n_dofs() const
unsigned int n_dofs_per_cell() const
std::pair< unsigned int, unsigned int > system_to_component_index(const unsigned int index) const
virtual void value_list(const std::vector< Point< dim > > &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
virtual void transform_points_real_to_unit_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const ArrayView< const Point< spacedim > > &real_points, const ArrayView< Point< dim > > &unit_points) const
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMessage(std::string arg1)
typename ActiveSelector::cell_iterator cell_iterator
void assemble_nitsche_with_exact_intersections(const DoFHandler< dim0, 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 Mapping< dim0, spacedim > &, const Function< spacedim, typename Matrix::value_type > &nitsche_coefficient=Functions::ConstantFunction< spacedim >(1.0), const double penalty=1.)
Given two non-matching, overlapping grids, this function computes the local contributions M_{ij}:= \i...
static const unsigned int invalid_unsigned_int