Debian Codegraph @

include/deal.II/matrix_free/util.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2020 - 2024 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15
16 #ifndef dealii_matrix_free_util_h
17 #define dealii_matrix_free_util_h
18
19
20 #include <deal.II/base/config.h>
21
22 #include <deal.II/base/quadrature.h>
23 #include <deal.II/base/quadrature_lib.h>
24
25 #include <deal.II/fe/fe_simplex_p.h>
26
27 #include <deal.II/grid/reference_cell.h>
28
29 #include <deal.II/hp/q_collection.h>
30
31 DEAL_II_NAMESPACE_OPEN
32
33
34 namespace internal
35 {
36 namespace MatrixFreeFunctions
37 {
38 /**
39 * Given a quadrature rule @p quad defined on a cell, return the type of
40 * the cell and a collection of lower-dimensional quadrature rules that
41 * are defined on each face.
42 */
43 template <int dim>
44 inline std::pair<ReferenceCell, dealii::hp::QCollection<dim - 1>>
45 get_face_quadrature_collection(const Quadrature<dim> &quad,
46 const bool do_assert = true)
47 {
48 if (dim == 2 || dim == 3)
49 {
50 for (unsigned int i = 1; i <= 4; ++i)
51 if (quad == QGaussSimplex<dim>(i))
52 return {ReferenceCells::get_simplex<dim>(),
53 dealii::hp::QCollection<dim - 1>(
54 QGaussSimplex<dim - 1>(i))};
55
56 for (unsigned int i = 1; i <= 5; ++i)
57 if (quad == QWitherdenVincentSimplex<dim>(i))
58 return {ReferenceCells::get_simplex<dim>(),
59 dealii::hp::QCollection<dim - 1>(
60 QWitherdenVincentSimplex<dim - 1>(i))};
61
62 for (unsigned int i = 1; i <= 3; ++i)
63 {
64 const FE_SimplexP<dim> fe(i);
65 if (quad == Quadrature<dim>(fe.get_unit_support_points()))
66 return {ReferenceCells::get_simplex<dim>(),
67 dealii::hp::QCollection<dim - 1>(Quadrature<dim - 1>(
68 fe.get_unit_face_support_points()))};
69 }
70 }
71
72 if (dim == 3)
73 for (unsigned int i = 1; i <= 3; ++i)
74 if (quad == QGaussWedge<dim>(i))
75 {
76 QGauss<dim - 1> quad(i);
77 QGaussSimplex<dim - 1> tri(i);
78
79 return {
80 ReferenceCells::Wedge,
81 dealii::hp::QCollection<dim - 1>(tri, tri, quad, quad, quad)};
82 }
83
84 if (dim == 3)
85 for (unsigned int i = 1; i <= 2; ++i)
86 if (quad == QGaussPyramid<dim>(i))
87 {
88 QGauss<dim - 1> quad(i);
89 QGaussSimplex<dim - 1> tri(i);
90
91 return {
92 ReferenceCells::Pyramid,
93 dealii::hp::QCollection<dim - 1>(quad, tri, tri, tri, tri)};
94 }
95
96 // note: handle hypercubes last since normally this function is not
97 // called for hypercubes
98 for (unsigned int i = 1; i <= 5; ++i)
99 if (quad == QGauss<dim>(i))
100 return {ReferenceCells::get_hypercube<dim>(),
101 dealii::hp::QCollection<dim - 1>(QGauss<dim - 1>(i))};
102
103 if (do_assert)
104 AssertThrow(false, ExcNotImplemented());
105
106 return {ReferenceCells::Invalid, dealii::hp::QCollection<dim - 1>()};
107 }
108
109
110
111 /**
112 * Return face quadrature rules. In contrast to
113 * get_face_quadrature_collection(), it does not return the quadrature
114 * face for each face but returns one of each type. The first entry
115 * of the returned pair might contain a quadrature rule defined on lines and
116 * quadrilaterals, while the second entry might contain a quadrature rule
117 * defined on a triangle.
118 */
119 template <int dim>
120 inline std::pair<Quadrature<dim - 1>, Quadrature<dim - 1>>
121 get_unique_face_quadratures(const Quadrature<dim> &quad)
122 {
123 AssertThrow(
124 quad.size() > 0,
125 ExcMessage(
126 "There is nothing useful you can do with a MatrixFree/FEEvaluation "
127 "object when using a quadrature formula with zero "
128 "quadrature points!"));
129
130 if (dim == 2 || dim == 3)
131 {
132 for (unsigned int i = 1; i <= 4; ++i)
133 if (quad == QGaussSimplex<dim>(i))
134 {
135 if (dim == 2)
136 return {QGaussSimplex<dim - 1>(i), // line!
137 Quadrature<dim - 1>()};
138 else
139 return {Quadrature<dim - 1>(), QGaussSimplex<dim - 1>(i)};
140 }
141
142 for (unsigned int i = 1; i <= 5; ++i)
143 if (quad == QWitherdenVincentSimplex<dim>(i))
144 {
145 if (dim == 2)
146 return {QWitherdenVincentSimplex<dim - 1>(i), // line!
147 Quadrature<dim - 1>()};
148 else
149 return {Quadrature<dim - 1>(),
150 QWitherdenVincentSimplex<dim - 1>(i)};
151 }
152
153 for (unsigned int i = 1; i <= 3; ++i)
154 {
155 const FE_SimplexP<dim> fe(i);
156 if (quad == Quadrature<dim>(fe.get_unit_support_points()))
157 {
158 if (dim == 2)
159 return {Quadrature<dim - 1>(
160 fe.get_unit_face_support_points()), // line!
161 Quadrature<dim - 1>()};
162 else
163 return {Quadrature<dim - 1>(),
164 Quadrature<dim - 1>(
165 fe.get_unit_face_support_points())};
166 }
167 }
168 }
169
170 if (dim == 3)
171 for (unsigned int i = 1; i <= 3; ++i)
172 if (quad == QGaussWedge<dim>(i))
173 return {QGauss<dim - 1>(i), QGaussSimplex<dim - 1>(i)};
174
175 if (dim == 3)
176 for (unsigned int i = 1; i <= 2; ++i)
177 if (quad == QGaussPyramid<dim>(i))
178 return {QGauss<dim - 1>(i), QGaussSimplex<dim - 1>(i)};
179
180 // note: handle hypercubes last since normally this function is not
181 // called for hypercubes
182 for (unsigned int i = 1; i <= 5; ++i)
183 if (quad == QGauss<dim>(i))
184 return {QGauss<dim - 1>(i), Quadrature<dim - 1>()};
185
186 AssertThrow(false, ExcNotImplemented());
187
188 return {Quadrature<dim - 1>(), Quadrature<dim - 1>()};
189 }
190
191 inline DEAL_II_ALWAYS_INLINE unsigned int
192 indicate_power_of_two(const unsigned int vectorization_length)
193 {
194 unsigned int vectorization_length_bits = 0;
195 unsigned int my_length = vectorization_length;
196 while (my_length >>= 1)
197 ++vectorization_length_bits;
198 return 1 << vectorization_length_bits;
199 }
200
201 } // end of namespace MatrixFreeFunctions
202 } // end of namespace internal
203
204 DEAL_II_NAMESPACE_CLOSE
205
206 #endif