Debian Codegraph @

include/deal.II/integrators/l2.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2010 - 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 #ifndef dealii_integrators_l2_h
16 #define dealii_integrators_l2_h
17
18
19 #include <deal.II/base/config.h>
20
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/quadrature.h>
23
24 #include <deal.II/fe/fe_values.h>
25 #include <deal.II/fe/mapping.h>
26
27 #include <deal.II/lac/full_matrix.h>
28
29 #include <deal.II/meshworker/dof_info.h>
30
31 DEAL_II_NAMESPACE_OPEN
32
33 namespace LocalIntegrators
34 {
35 /**
36 * @brief Local integrators related to <i>L<sup>2</sup></i>-inner products.
37 *
38 * @ingroup Integrators
39 */
40 namespace L2
41 {
42 /**
43 * The @ref GlossMassMatrix "mass matrix" for scalar or vector values finite elements. \f[ \int_Z
44 * uv\,dx \quad \text{or} \quad \int_Z \mathbf u\cdot \mathbf v\,dx \f]
45 *
46 * Likewise, this term can be used on faces, where it computes the
47 * integrals \f[ \int_F uv\,ds \quad \text{or} \quad \int_F \mathbf u\cdot
48 * \mathbf v\,ds \f]
49 *
50 * @param M The mass matrix obtained as result.
51 * @param fe The FEValues object describing the local trial function
52 * space. #update_values and #update_JxW_values must be set.
53 * @param factor A constant that multiplies the mass matrix.
54 */
55 template <int dim>
56 DEAL_II_DEPRECATED void
57 mass_matrix(FullMatrix<double> &M,
58 const FEValuesBase<dim> &fe,
59 const double factor = 1.)
60 {
61 const unsigned int n_dofs = fe.dofs_per_cell;
62 const unsigned int n_components = fe.get_fe().n_components();
63
64 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
65 {
66 const double dx = fe.JxW(k) * factor;
67 for (unsigned int i = 0; i < n_dofs; ++i)
68 {
69 double Mii = 0.0;
70 for (unsigned int d = 0; d < n_components; ++d)
71 Mii += dx * fe.shape_value_component(i, k, d) *
72 fe.shape_value_component(i, k, d);
73
74 M(i, i) += Mii;
75
76 for (unsigned int j = i + 1; j < n_dofs; ++j)
77 {
78 double Mij = 0.0;
79 for (unsigned int d = 0; d < n_components; ++d)
80 Mij += dx * fe.shape_value_component(j, k, d) *
81 fe.shape_value_component(i, k, d);
82
83 M(i, j) += Mij;
84 M(j, i) += Mij;
85 }
86 }
87 }
88 }
89
90 /**
91 * The weighted @ref GlossMassMatrix "mass matrix" for scalar or vector values finite elements.
92 * \f[ \int_Z \omega(x) uv\,dx \quad \text{or} \quad \int_Z \omega(x)
93 * \mathbf u\cdot \mathbf v\,dx \f]
94 *
95 * Likewise, this term can be used on faces, where it computes the
96 * integrals \f[ \int_F \omega(x) uv\,ds \quad \text{or} \quad \int_F
97 * \omega(x) \mathbf u\cdot \mathbf v\,ds \f]
98 *
99 * @param M The weighted mass matrix obtained as result.
100 * @param fe The FEValues object describing the local trial function
101 * space. #update_values and #update_JxW_values must be set.
102 * @param weights The weights, $\omega(x)$, evaluated at the quadrature
103 * points in the finite element (size must be equal to the number of
104 * quadrature points in the element).
105 */
106 template <int dim>
107 DEAL_II_DEPRECATED void
108 weighted_mass_matrix(FullMatrix<double> &M,
109 const FEValuesBase<dim> &fe,
110 const std::vector<double> &weights)
111 {
112 const unsigned int n_dofs = fe.dofs_per_cell;
113 const unsigned int n_components = fe.get_fe().n_components();
114 AssertDimension(M.m(), n_dofs);
115 AssertDimension(M.n(), n_dofs);
116 AssertDimension(weights.size(), fe.n_quadrature_points);
117
118 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
119 {
120 const double dx = fe.JxW(k) * weights[k];
121 for (unsigned int i = 0; i < n_dofs; ++i)
122 {
123 double Mii = 0.0;
124 for (unsigned int d = 0; d < n_components; ++d)
125 Mii += dx * fe.shape_value_component(i, k, d) *
126 fe.shape_value_component(i, k, d);
127
128 M(i, i) += Mii;
129
130 for (unsigned int j = i + 1; j < n_dofs; ++j)
131 {
132 double Mij = 0.0;
133 for (unsigned int d = 0; d < n_components; ++d)
134 Mij += dx * fe.shape_value_component(j, k, d) *
135 fe.shape_value_component(i, k, d);
136
137 M(i, j) += Mij;
138 M(j, i) += Mij;
139 }
140 }
141 }
142 }
143
144 /**
145 * <i>L<sup>2</sup></i>-inner product for scalar functions.
146 *
147 * \f[ \int_Z fv\,dx \quad \text{or} \quad \int_F fv\,ds \f]
148 *
149 * @param result The vector obtained as result.
150 * @param fe The FEValues object describing the local trial function
151 * space. #update_values and #update_JxW_values must be set.
152 * @param input The representation of $f$ evaluated at the quadrature
153 * points in the finite element (size must be equal to the number of
154 * quadrature points in the element).
155 * @param factor A constant that multiplies the result.
156 */
157 template <int dim, typename number>
158 DEAL_II_DEPRECATED void
159 L2(Vector<number> &result,
160 const FEValuesBase<dim> &fe,
161 const std::vector<double> &input,
162 const double factor = 1.)
163 {
164 const unsigned int n_dofs = fe.dofs_per_cell;
165 AssertDimension(result.size(), n_dofs);
166 AssertDimension(fe.get_fe().n_components(), 1);
167 AssertDimension(input.size(), fe.n_quadrature_points);
168
169 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
170 for (unsigned int i = 0; i < n_dofs; ++i)
171 result(i) += fe.JxW(k) * factor * input[k] * fe.shape_value(i, k);
172 }
173
174 /**
175 * <i>L<sup>2</sup></i>-inner product for a slice of a vector valued right
176 * hand side. \f[ \int_Z \mathbf f\cdot \mathbf v\,dx \quad \text{or}
177 * \quad \int_F \mathbf f\cdot \mathbf v\,ds \f]
178 *
179 * @param result The vector obtained as result.
180 * @param fe The FEValues object describing the local trial function
181 * space. #update_values and #update_JxW_values must be set.
182 * @param input The vector valued representation of $\mathbf f$ evaluated
183 * at the quadrature points in the finite element (size of each component
184 * must be equal to the number of quadrature points in the element).
185 * @param factor A constant that multiplies the result.
186 */
187 template <int dim, typename number>
188 DEAL_II_DEPRECATED void
189 L2(Vector<number> &result,
190 const FEValuesBase<dim> &fe,
191 const ArrayView<const std::vector<double>> &input,
192 const double factor = 1.)
193 {
194 const unsigned int n_dofs = fe.dofs_per_cell;
195 const unsigned int n_components = input.size();
196
197 AssertDimension(result.size(), n_dofs);
198 AssertDimension(input.size(), fe.get_fe().n_components());
199
200 for (unsigned int k = 0; k < fe.n_quadrature_points; ++k)
201 for (unsigned int i = 0; i < n_dofs; ++i)
202 for (unsigned int d = 0; d < n_components; ++d)
203 result(i) += fe.JxW(k) * factor *
204 fe.shape_value_component(i, k, d) * input[d][k];
205 }
206
207 /**
208 * The jump matrix between two cells for scalar or vector values finite
209 * elements. Note that the factor $\gamma$ can be used to implement
210 * weighted jumps. \f[ \int_F [\gamma u][\gamma v]\,ds \quad \text{or}
211 * \int_F [\gamma \mathbf u]\cdot [\gamma \mathbf v]\,ds \f]
212 *
213 * Using appropriate weights, this term can be used to penalize violation
214 * of conformity in <i>H<sup>1</sup></i>.
215 *
216 * Note that for the parameters that follow, the external matrix refers to
217 * the flux between cells, while the internal matrix refers to entries
218 * coupling inside the cell.
219 *
220 * @param M11 The internal matrix for the first cell obtained as result.
221 * @param M12 The external matrix for the first cell obtained as result.
222 * @param M21 The external matrix for the second cell obtained as result.
223 * @param M22 The internal matrix for the second cell obtained as result.
224 * @param fe1 The FEValues object describing the local trial function
225 * space for the first cell. #update_values and #update_JxW_values must be
226 * set.
227 * @param fe2 The FEValues object describing the local trial function
228 * space for the second cell. #update_values and #update_JxW_values must be
229 * set.
230 * @param factor1 A constant that multiplies the shape functions for the
231 * first cell.
232 * @param factor2 A constant that multiplies the shape functions for the
233 * second cell.
234 */
235 template <int dim>
236 DEAL_II_DEPRECATED void
237 jump_matrix(FullMatrix<double> &M11,
238 FullMatrix<double> &M12,
239 FullMatrix<double> &M21,
240 FullMatrix<double> &M22,
241 const FEValuesBase<dim> &fe1,
242 const FEValuesBase<dim> &fe2,
243 const double factor1 = 1.,
244 const double factor2 = 1.)
245 {
246 const unsigned int n1_dofs = fe1.n_dofs_per_cell();
247 const unsigned int n2_dofs = fe2.n_dofs_per_cell();
248 const unsigned int n_components = fe1.get_fe().n_components();
249
250 Assert(n1_dofs == n2_dofs, ExcNotImplemented());
251 (void)n2_dofs;
252 AssertDimension(n_components, fe2.get_fe().n_components());
253 AssertDimension(M11.m(), n1_dofs);
254 AssertDimension(M12.m(), n1_dofs);
255 AssertDimension(M21.m(), n2_dofs);
256 AssertDimension(M22.m(), n2_dofs);
257 AssertDimension(M11.n(), n1_dofs);
258 AssertDimension(M12.n(), n2_dofs);
259 AssertDimension(M21.n(), n1_dofs);
260 AssertDimension(M22.n(), n2_dofs);
261
262 for (unsigned int k = 0; k < fe1.n_quadrature_points; ++k)
263 {
264 const double dx = fe1.JxW(k);
265
266 for (unsigned int i = 0; i < n1_dofs; ++i)
267 for (unsigned int j = 0; j < n1_dofs; ++j)
268 for (unsigned int d = 0; d < n_components; ++d)
269 {
270 const double u1 =
271 factor1 * fe1.shape_value_component(j, k, d);
272 const double u2 =
273 -factor2 * fe2.shape_value_component(j, k, d);
274 const double v1 =
275 factor1 * fe1.shape_value_component(i, k, d);
276 const double v2 =
277 -factor2 * fe2.shape_value_component(i, k, d);
278
279 M11(i, j) += dx * u1 * v1;
280 M12(i, j) += dx * u2 * v1;
281 M21(i, j) += dx * u1 * v2;
282 M22(i, j) += dx * u2 * v2;
283 }
284 }
285 }
286 } // namespace L2
287 } // namespace LocalIntegrators
288
289 DEAL_II_NAMESPACE_CLOSE
290
291 #endif