Fluid structure interaction suite
moonolith_tools.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 moonolith_tools_include_h
17 #define moonolith_tools_include_h
18 
19 #include <deal.II/base/config.h>
20 
21 #ifdef DEAL_II_WITH_PARMOONOLITH
22 
23 # include <deal.II/base/point.h>
24 # include <deal.II/base/quadrature.h>
25 
26 # include <deal.II/fe/mapping.h>
27 
29 # include <deal.II/grid/grid_tools.h>
31 # include <deal.II/grid/tria.h>
32 
33 # include <moonolith_build_quadrature.hpp>
34 # include <moonolith_convex_decomposition.hpp>
35 # include <moonolith_intersect_polyhedra.hpp>
36 # include <moonolith_map_quadrature.hpp>
37 # include <moonolith_mesh_io.hpp>
38 # include <moonolith_par_l2_transfer.hpp>
39 # include <moonolith_polygon.hpp>
40 # include <moonolith_vector.hpp>
41 # include <par_moonolith.hpp>
42 
43 # include <array>
44 # include <cassert>
45 # include <cmath>
46 # include <fstream>
47 # include <iostream>
48 # include <sstream>
49 
50 namespace moonolith
51 {
55  using namespace dealii;
56  template <int dim, typename NumberType>
57  inline dealii::Point<dim, NumberType>
58  to_dealii(const moonolith::Vector<NumberType, dim> &p)
59  {
60  dealii::Point<dim, NumberType> result;
61  for (unsigned int i = 0; i < dim; ++i)
62  result[i] = p[i];
63  return result;
64  }
65 
69  template <int dim, typename NumberType>
70  inline moonolith::Vector<NumberType, dim>
71  to_moonolith(const dealii::Point<dim, NumberType> &p)
72  {
73  moonolith::Vector<NumberType, dim> result;
74  for (unsigned int i = 0; i < dim; ++i)
75  result[i] = p[i];
76  return result;
77  }
78 
79 
83  template <int dim>
84  inline dealii::Quadrature<dim>
85  to_dealii(const moonolith::Quadrature<double, dim> &q)
86  {
87  const auto points = q.points;
88  const auto weights = q.weights;
89  const unsigned int quad_size = points.size();
90  std::vector<dealii::Point<dim>> dealii_points(quad_size);
91  std::vector<double> dealii_weights(quad_size);
92  for (unsigned int i = 0; i < quad_size; ++i)
93  {
94  dealii_points[i] = to_dealii(points[i]);
95  dealii_weights[i] = weights[i];
96  }
97  return dealii::Quadrature<dim>(dealii_points, dealii_weights);
98  }
99 
100 
104  template <int dim>
105  inline Line<double, dim>
106  to_moonolith(const typename Triangulation<1, dim>::cell_iterator &cell,
107  const Mapping<1, dim> &mapping)
108  {
109  const auto vertices = mapping.get_vertices(cell);
110  Line<double, dim> line;
111  line.p0 = to_moonolith(vertices[0]);
112  line.p1 = to_moonolith(vertices[1]);
113  return line;
114  }
115 
116 
120  template <int spacedim>
121  inline Polygon<double, spacedim>
122  to_moonolith(const typename Triangulation<2, spacedim>::cell_iterator &cell,
123  const Mapping<2, spacedim> &mapping)
124  {
125  static_assert(2 <= spacedim, "2 must be <= spacedim");
126  const auto vertices = mapping.get_vertices(cell);
127  Polygon<double, spacedim> poly;
128 
129  if (vertices.size() == 3)
130  poly.points = {to_moonolith(vertices[0]),
131  to_moonolith(vertices[1]),
132  to_moonolith(vertices[2])};
133  else if (vertices.size() == 4)
134  poly.points = {to_moonolith(vertices[0]),
135  to_moonolith(vertices[1]),
136  to_moonolith(vertices[3]),
137  to_moonolith(vertices[2])};
138  else
139  Assert(false, ExcNotImplemented());
140 
141  return poly;
142  }
143 
147  inline Polyhedron<double>
148  to_moonolith(const typename Triangulation<3, 3>::cell_iterator &cell,
149  const Mapping<3, 3> &mapping)
150  {
151  const auto vertices = mapping.get_vertices(cell);
152  Polyhedron<double> poly;
153 
154  if (vertices.size() == 4) // Tetrahedron
155  {
156  poly.el_index = {0, 2, 1, 0, 3, 2, 0, 1, 3, 1, 2, 3};
157  poly.el_ptr = {0, 3, 6, 9, 12};
158 
159  poly.points = {to_moonolith(vertices[0]),
160  to_moonolith(vertices[1]),
161  to_moonolith(vertices[2]),
162  to_moonolith(vertices[3])};
163 
164  poly.fix_ordering();
165  }
166  else if (vertices.size() == 8) // Hexahedron
167  {
168  make_cube(to_moonolith(vertices[0]), to_moonolith(vertices[7]), poly);
169  poly.points = {to_moonolith(vertices[0]),
170  to_moonolith(vertices[1]),
171  to_moonolith(vertices[3]),
172  to_moonolith(vertices[2]),
173  to_moonolith(vertices[4]),
174  to_moonolith(vertices[5]),
175  to_moonolith(vertices[7]),
176  to_moonolith(vertices[6])};
177  poly.fix_ordering();
178  }
179  else if (vertices.size() == 5) // Piramid
180  {
181  poly.el_index = {0, 1, 3, 2, 0, 1, 4, 1, 3, 4, 3, 4, 2, 0, 4, 2};
182  poly.el_ptr = {0, 4, 7, 10, 13, 16};
183 
184  poly.points = {to_moonolith(vertices[0]),
185  to_moonolith(vertices[1]),
186  to_moonolith(vertices[2]),
187  to_moonolith(vertices[3]),
188  to_moonolith(vertices[4])};
189 
190  poly.fix_ordering();
191  }
192  else if (vertices.size() == 6) // Wedge
193  {
194  poly.el_index = {0, 1, 2, 0, 1, 4, 3, 1, 4, 5, 2, 0, 2, 5, 3, 3, 4, 5};
195  poly.el_ptr = {0, 3, 7, 11, 15, 18};
196 
197  poly.points = {to_moonolith(vertices[0]),
198  to_moonolith(vertices[1]),
199  to_moonolith(vertices[2]),
200  to_moonolith(vertices[3]),
201  to_moonolith(vertices[4]),
202  to_moonolith(vertices[5])};
203 
204  poly.fix_ordering();
205  }
206  return poly;
207  }
208 
223  template <int spacedim, int dim, class T1, class T2>
224  inline moonolith::Quadrature<double, spacedim>
225  compute_intersection(const moonolith::Quadrature<double, dim> &ref_quad,
226  const T1 &t1,
227  const T2 &t2)
228  {
229  BuildQuadrature<T1, T2> intersect;
231  intersect.apply(ref_quad, t1, t2, out);
232  return out;
233  }
234 
235 
252  template <int dim0, int dim1, int spacedim>
253  inline dealii::Quadrature<spacedim>
255  const typename Triangulation<dim0, spacedim>::cell_iterator &cell0,
256  const typename Triangulation<dim1, spacedim>::cell_iterator &cell1,
257  const unsigned int degree,
258  const Mapping<dim0, spacedim> &mapping0,
259  const Mapping<dim1, spacedim> &mapping1)
260  {
261  const auto t0 = to_moonolith(cell0, mapping0);
262  const auto t1 = to_moonolith(cell1, mapping1);
263  moonolith::Quadrature<Real, std::min(dim0, dim1)> ref_quad;
264  moonolith::Gauss::get(degree, ref_quad);
265  auto mquad = compute_intersection<spacedim>(ref_quad, t0, t1);
266  return to_dealii(mquad);
267  }
268 } // namespace moonolith
269 
270 #endif
271 #endif
virtual boost::container::small_vector< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
Point< 3 > vertices[4]
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
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,...
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)