Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
copy_data.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021, 2023-2024, 2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_copy_data_h
5#define lethe_copy_data_h
6
7#include <deal.II/lac/full_matrix.h>
8#include <deal.II/lac/lapack_full_matrix.h>
9#include <deal.II/lac/vector.h>
10
11#include <vector>
12
13using namespace dealii;
14
15/**
16 * @brief Class responsible for storing the information calculated using the assembly of regular (meaning
17 * non-stabilized) equations. It is also used to
18 * initialize, zero (reset) and store the cell_matrix, the cell_rhs and the
19 * dof indices associated with the dofs of the cell.
20 **/
21
23{
24public:
25 /**
26 * @brief Constructor. Allocates the memory for the cell_matrix, cell_rhs and the local_dof_indices
27 *
28 * @param n_dofs Number of degrees of freedom per cell in the problem
29 */
30 CopyData(const unsigned int n_dofs)
31 : local_matrix(n_dofs, n_dofs)
32 , local_rhs(n_dofs)
33 , local_dof_indices(n_dofs){};
34
35 /**
36 * @brief Resets the cell_matrix and the cell_rhs to zero
37 */
38 void
40 {
41 local_matrix = 0;
42 local_rhs = 0;
43 }
44
45 FullMatrix<double> local_matrix;
46 Vector<double> local_rhs;
47 std::vector<types::global_dof_index> local_dof_indices;
48
49 // Boolean used to indicate if the cell being assembled is local or not
50 // This information is used to indicate to the copy_local_to_global function
51 // if it should indeed copy or not.
53};
54
55
56/**
57 * @brief Class responsible for storing the information calculated using the assembly of stabilized
58 * scalar equations. Like the CopyData class, this class is used to initialize,
59 * zero (reset) and store the cell_matrix and the cell_rhs.
60 * Contrary to the regular CopyData class, this class
61 * also stores the strong_residual and the strong_jacobian of the equation being
62 * assembled. This is useful for equations that implement residual-based
63 * stabilization such as SUPG. This class is specialized for single component
64 * equations because the strong jacobian is stored using a Vector<double>
65 **/
67{
68public:
69 /**
70 * @brief Constructor. Allocates the memory for the cell_matrix, cell_rhs
71 * and dof-indices using the number of dofs and the strong_residual using the
72 * number of quadrature points and, the strong_jacobian using both
73 *
74 * @param n_dofs Number of degrees of freedom per cell in the problem
75 *
76 * @param n_q_points Number of quadrature points
77 */
78 StabilizedMethodsCopyData(const unsigned int n_dofs,
79 const unsigned int n_q_points)
80 : local_matrix(n_dofs, n_dofs)
81 , local_rhs(n_dofs)
82 , local_dof_indices(n_dofs)
83 , strong_residual(n_q_points)
84 , strong_jacobian(n_q_points, Vector<double>(n_dofs)){};
85
86
87 /**
88 * @brief Resets the cell_matrix, cell_rhs, strong_residual
89 * and strong_jacobian to zero
90 */
91 void
93 {
94 local_matrix = 0;
95 local_rhs = 0;
96
98 for (auto &jacobian : strong_jacobian)
99 {
100 jacobian = 0;
101 }
102 }
103
104 FullMatrix<double> local_matrix;
105 Vector<double> local_rhs;
106 std::vector<types::global_dof_index> local_dof_indices;
107 Vector<double> strong_residual;
108 std::vector<Vector<double>> strong_jacobian;
109
110 // Boolean used to indicate if the cell being assembled is local or not
111 // This information is used to indicate to the copy_local_to_global function
112 // if it should indeed copy or not.
114};
115
116
117
118/**
119 * @brief Responsible for storing the information calculated using the discontinuous
120 * galerkin (DG) assembly of stabilized scalar equations. Like the
121 * StabilizedCopyData class, this class is used to initialize, zero (reset) and
122 * store the cell_matrix and the cell_rhs while having support for stabilized
123 * terms. However, it also has to support the storage of information at internal
124 * faces. This is required for the DG methods.
125 **/
127{
128public:
129 /**
130 * @brief Constructor. Allocates the memory using the base class Constructor.
131 * @param[in] n_dofs Number of degrees of freedom per cell in the problem
132 *
133 * @param[in] n_q_points Number of quadrature points
134 */
135 StabilizedDGMethodsCopyData(const unsigned int n_dofs,
136 const unsigned int n_q_points)
137 : StabilizedMethodsCopyData(n_dofs, n_q_points){};
138
139
140 // Data structure for internal face contributions
142 {
143 FullMatrix<double> face_matrix;
144 Vector<double> face_rhs;
145
146 std::vector<types::global_dof_index> joint_dof_indices;
147 };
148
149 std::vector<CopyDataFace> face_data;
150};
151
152/**
153 * @brief Class responsible for storing the information calculated using the assembly of stabilized
154 * Tensor<1,dim> equations. Like the CopyData class, this class is used to
155 * initialize, zero (reset) and store the cell_matrix and the cell_rhs. Contrary
156 * to the regular CopyData class, this class also stores the strong_residual and
157 * the strong_jacobian of the equation being assembled. This is useful for
158 * equations that implement residual-based stabilization such as SUPG. This
159 * class is specialized for Tensor<1,dim> equations because the strong
160 * jacobian is stored using a Tensor<1,dim>
161 **/
162
163
164template <int dim>
166{
167public:
168 /**
169 * @brief Constructor. Allocates the memory for the cell_matrix and cell_rhs
170 * using the number of dofs and the strong_residual using the number of
171 * quadrature points and, the strong_jacobian using both
172 *
173 * @param n_dofs Number of degrees of freedom per cell in the problem
174 *
175 * @param n_q_points Number of quadrature points
176 */
177 StabilizedMethodsTensorCopyData(const unsigned int n_dofs,
178 const unsigned int n_q_points)
179 : local_matrix(n_dofs, n_dofs)
180 , local_rhs(n_dofs)
181 , local_dof_indices(n_dofs)
182 , strong_residual(n_q_points)
183 , strong_jacobian(n_q_points, std::vector<Tensor<1, dim>>(n_dofs)){};
184
185 /**
186 * @brief Resets the cell_matrix, cell_rhs, strong_residual
187 * and strong_jacobian to zero
188 */
189 void
191 {
192 local_matrix = 0;
193 local_rhs = 0;
194
195 for (unsigned int q = 0; q < strong_jacobian.size(); ++q)
196 {
197 strong_residual[q] = 0;
198
199 for (unsigned int i = 0; i < strong_jacobian[q].size(); ++i)
200 strong_jacobian[q][i] = 0;
201 }
202 }
203
204 FullMatrix<double> local_matrix;
205 Vector<double> local_rhs;
206 std::vector<types::global_dof_index> local_dof_indices;
207 std::vector<Tensor<1, dim>> strong_residual;
208 std::vector<std::vector<Tensor<1, dim>>> strong_jacobian;
209
210
211 // Boolean used to indicate if the cell being assembled is local or not
212 // This information is used to indicate to the copy_local_to_global function
213 // if it should indeed copy or not.
216};
217
218
219/**
220 * @brief Class responsible for storing the local system of an ultraweak Discontinuous
221 * Petrov-Galerkin (DPG) discretization. The assemblers fill the uncondensed
222 * local system: the Gram matrix of the test space \f$G\f$, the matrices of the
223 * bilinear form in the cell interior \f$B\f$ and on the skeleton \f$\hat{B}\f$,
224 * and the load vector \f$l\f$. The solver then condenses this system on the
225 * skeleton unknowns using the operators \f$M_1 = B^\dagger G^{-1} B\f$,
226 * \f$M_2 = B^\dagger G^{-1} \hat{B}\f$, \f$M_3 = \hat{B}^\dagger G^{-1}
227 *\hat{B}\f$, and the vectors \f$M_4 l = B^\dagger G^{-1} l\f$ and \f$M_5 l =
228 *\hat{B}^\dagger G^{-1} l\f$, and stores either the condensed skeleton system
229 *(assembly) or the reconstructed interior solution (interior reconstruction).
230 **/
232{
233public:
234 /**
235 * @brief Constructor. Allocates the memory of all the local matrices and
236 * vectors from the number of degrees of freedom per cell of each finite
237 * element space.
238 *
239 * @param[in] n_dofs_test Number of degrees of freedom per cell of the test
240 * space.
241 *
242 * @param[in] n_dofs_trial_interior Number of degrees of freedom per cell of
243 * the interior trial space.
244 *
245 * @param[in] n_dofs_trial_skeleton Number of degrees of freedom per cell of
246 * the skeleton trial space.
247 */
248 DPGCopyData(const unsigned int n_dofs_test,
249 const unsigned int n_dofs_trial_interior,
250 const unsigned int n_dofs_trial_skeleton)
251 : G_matrix(n_dofs_test, n_dofs_test)
252 , B_matrix(n_dofs_test, n_dofs_trial_interior)
253 , B_hat_matrix(n_dofs_test, n_dofs_trial_skeleton)
254 , l_vector(n_dofs_test)
255 , G_inverse_B(n_dofs_test, n_dofs_trial_interior)
256 , G_inverse_B_hat(n_dofs_test, n_dofs_trial_skeleton)
257 , M1_matrix(n_dofs_trial_interior, n_dofs_trial_interior)
258 , M2_matrix(n_dofs_trial_interior, n_dofs_trial_skeleton)
259 , M3_matrix(n_dofs_trial_skeleton, n_dofs_trial_skeleton)
260 , M4_l(n_dofs_trial_interior)
261 , M5_l(n_dofs_trial_skeleton)
262 , M1_inverse_M2(n_dofs_trial_interior, n_dofs_trial_skeleton)
263 , tmp_matrix_M2M1M2(n_dofs_trial_skeleton, n_dofs_trial_skeleton)
264 , local_matrix(n_dofs_trial_skeleton, n_dofs_trial_skeleton)
265 , local_rhs(n_dofs_trial_skeleton)
266 , local_dof_indices(n_dofs_trial_skeleton)
267 , local_skeleton_solution(n_dofs_trial_skeleton)
268 , local_interior_rhs(n_dofs_trial_interior)
269 , local_interior_solution(n_dofs_trial_interior)
270 , tmp_vector_reconstruction(n_dofs_test)
271 , local_residual(n_dofs_test)
272 , local_dof_indices_trial_interior(n_dofs_trial_interior)
275 , cell_is_local(false){};
276
277 /**
278 * @brief Resets the uncondensed local system to zero. The \f$M_1\f$ matrix
279 * is also reset since LAPACKFullMatrix keeps track of its factorization
280 * status and forbids writing into it or factorizing it again once it has
281 * been factorized.
282 */
283 void
285 {
286 G_matrix = 0;
287 B_matrix = 0;
288 B_hat_matrix = 0;
289 l_vector = 0;
290 M1_matrix = 0;
291 }
292
293 // Local Gram matrix
294 LAPACKFullMatrix<double> G_matrix;
295 // Local interior bilinear form matrix
296 LAPACKFullMatrix<double> B_matrix;
297 // Local skeleton bilinear form matrix
298 LAPACKFullMatrix<double> B_hat_matrix;
299 // Local load vector
300 Vector<double> l_vector;
301
302 // Solution of G X = B with the Cholesky factorization of G
303 LAPACKFullMatrix<double> G_inverse_B;
304 // Solution of G X = B_hat with the Cholesky factorization of G
305 LAPACKFullMatrix<double> G_inverse_B_hat;
306
307 // Static condensation matrix 1 \f$M_1 = B^\dagger G^{-1} B\f$
308 LAPACKFullMatrix<double> M1_matrix;
309 // Static condensation matrix 2 \f$M_2 = B^\dagger G^{-1} \hat{B}\f$
310 LAPACKFullMatrix<double> M2_matrix;
311 // Static condensation matrix 3 \f$M_3 = \hat{B}^\dagger G^{-1} \hat{B}\f$
312 LAPACKFullMatrix<double> M3_matrix;
313 // Static condensation vector \f$M_4 l = B^\dagger G^{-1} l\f$
314 Vector<double> M4_l;
315 // Static condensation vector \f$M_5 l = \hat{B}^\dagger G^{-1} l\f$
316 Vector<double> M5_l;
317 // Solution of M_1 X = M_2 with the Cholesky factorization of M_1
318 LAPACKFullMatrix<double> M1_inverse_M2;
319 // Temporary matrix product M_2^\dagger M_1^{-1} M_2
320 LAPACKFullMatrix<double> tmp_matrix_M2M1M2;
321
322 // Cell condensed skeleton system
323 FullMatrix<double> local_matrix;
324 // Cell condensed skeleton right-hand side
325 Vector<double> local_rhs;
326 // Cell dof indices of the skeleton trial space
327 std::vector<types::global_dof_index> local_dof_indices;
328
329 // Cell skeleton solution
331 // Cell interior right-hand side
332 Vector<double> local_interior_rhs;
333 // Cell interior solution
335 // Temporary vector of the test space used for the products B_hat *
336 // x_skeleton and B * x_interior of the interior reconstruction
338 // Cell error representation function (Riesz representation of the residual)
339 Vector<double> local_residual;
340 // Cell dof indices of the interior trial space
341 std::vector<types::global_dof_index> local_dof_indices_trial_interior;
342 // Squared norm of the DPG residual, which is the DPG error indicator of the
343 // cell
345 // Index of the active cell being assembled
346 unsigned int active_cell_index;
347
348 // Boolean used to indicate if the cell being assembled is local or not
349 // This information is used to indicate to the copy_local_to_global function
350 // if it should indeed copy or not. It replaces the call to the function
351 // cell->is_locally_owned().
353};
354
355
356#endif
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:47
bool cell_is_local
Definition copy_data.h:52
FullMatrix< double > local_matrix
Definition copy_data.h:45
Vector< double > local_rhs
Definition copy_data.h:46
CopyData(const unsigned int n_dofs)
Constructor. Allocates the memory for the cell_matrix, cell_rhs and the local_dof_indices.
Definition copy_data.h:30
void reset()
Resets the cell_matrix and the cell_rhs to zero.
Definition copy_data.h:39
LAPACKFullMatrix< double > M3_matrix
Definition copy_data.h:312
void reset()
Resets the uncondensed local system to zero. The matrix is also reset since LAPACKFullMatrix keeps t...
Definition copy_data.h:284
FullMatrix< double > local_matrix
Definition copy_data.h:323
LAPACKFullMatrix< double > G_inverse_B_hat
Definition copy_data.h:305
Vector< double > l_vector
Definition copy_data.h:300
Vector< double > local_residual
Definition copy_data.h:339
LAPACKFullMatrix< double > B_hat_matrix
Definition copy_data.h:298
LAPACKFullMatrix< double > M1_matrix
Definition copy_data.h:308
Vector< double > tmp_vector_reconstruction
Definition copy_data.h:337
LAPACKFullMatrix< double > M2_matrix
Definition copy_data.h:310
LAPACKFullMatrix< double > G_inverse_B
Definition copy_data.h:303
Vector< double > local_skeleton_solution
Definition copy_data.h:330
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:327
bool cell_is_local
Definition copy_data.h:352
Vector< double > local_interior_rhs
Definition copy_data.h:332
std::vector< types::global_dof_index > local_dof_indices_trial_interior
Definition copy_data.h:341
Vector< double > local_interior_solution
Definition copy_data.h:334
Vector< double > M5_l
Definition copy_data.h:316
double local_residual_norm_squared
Definition copy_data.h:344
DPGCopyData(const unsigned int n_dofs_test, const unsigned int n_dofs_trial_interior, const unsigned int n_dofs_trial_skeleton)
Constructor. Allocates the memory of all the local matrices and vectors from the number of degrees of...
Definition copy_data.h:248
LAPACKFullMatrix< double > M1_inverse_M2
Definition copy_data.h:318
LAPACKFullMatrix< double > G_matrix
Definition copy_data.h:294
LAPACKFullMatrix< double > B_matrix
Definition copy_data.h:296
unsigned int active_cell_index
Definition copy_data.h:346
LAPACKFullMatrix< double > tmp_matrix_M2M1M2
Definition copy_data.h:320
Vector< double > M4_l
Definition copy_data.h:314
Vector< double > local_rhs
Definition copy_data.h:325
std::vector< CopyDataFace > face_data
Definition copy_data.h:149
StabilizedDGMethodsCopyData(const unsigned int n_dofs, const unsigned int n_q_points)
Constructor. Allocates the memory using the base class Constructor.
Definition copy_data.h:135
Vector< double > local_rhs
Definition copy_data.h:105
Vector< double > strong_residual
Definition copy_data.h:107
FullMatrix< double > local_matrix
Definition copy_data.h:104
void reset()
Resets the cell_matrix, cell_rhs, strong_residual and strong_jacobian to zero.
Definition copy_data.h:92
std::vector< Vector< double > > strong_jacobian
Definition copy_data.h:108
StabilizedMethodsCopyData(const unsigned int n_dofs, const unsigned int n_q_points)
Constructor. Allocates the memory for the cell_matrix, cell_rhs and dof-indices using the number of d...
Definition copy_data.h:78
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:106
FullMatrix< double > local_matrix
Definition copy_data.h:204
StabilizedMethodsTensorCopyData(const unsigned int n_dofs, const unsigned int n_q_points)
Constructor. Allocates the memory for the cell_matrix and cell_rhs using the number of dofs and the s...
Definition copy_data.h:177
void reset()
Resets the cell_matrix, cell_rhs, strong_residual and strong_jacobian to zero.
Definition copy_data.h:190
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:206
std::vector< Tensor< 1, dim > > strong_residual
Definition copy_data.h:207
std::vector< std::vector< Tensor< 1, dim > > > strong_jacobian
Definition copy_data.h:208
std::vector< types::global_dof_index > joint_dof_indices
Definition copy_data.h:146