ExaDG
Loading...
Searching...
No Matches
navier_stokes_calculators.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_OPERATORS_NAVIER_STOKES_CALCULATORS_H_
23#define EXADG_OPERATORS_NAVIER_STOKES_CALCULATORS_H_
24
25// deal.II
26#include <deal.II/lac/la_parallel_vector.h>
27
28// ExaDG
29#include <exadg/incompressible_navier_stokes/spatial_discretization/operators/viscous_operator.h>
30#include <exadg/matrix_free/integrators.h>
31
32namespace ExaDG
33{
34/*
35 * Calculator for the divergence of a vector field u(x) defined as the scalar quantity
36
37 * div(u) := sum_i=1,...,dim { d u(i) / d x(i) }.
38 */
39template<int dim, typename Number>
40class DivergenceCalculator
41{
42public:
43 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
44
45 typedef DivergenceCalculator<dim, Number> This;
46
47 typedef CellIntegrator<dim, dim, Number> CellIntegratorVector;
48 typedef CellIntegrator<dim, 1, Number> CellIntegratorScalar;
49
50 typedef dealii::VectorizedArray<Number> scalar;
51
52 DivergenceCalculator();
53
54 void
55 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
56 unsigned int const dof_index_vector_in,
57 unsigned int const dof_index_scalar_in,
58 unsigned int const quad_index_in);
59
60 /*
61 * Compute the right-hand side of an L2 projection of the divergence of the vector field.
62 */
63 void
64 compute_projection_rhs(VectorType & dst_scalar_valued,
65 VectorType const & src_vector_valued) const;
66
67private:
68 void
69 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
70 VectorType & dst_scalar_valued,
71 VectorType const & src_vector_valued,
72 std::pair<unsigned int, unsigned int> const & cell_range) const;
73
74 dealii::MatrixFree<dim, Number> const * matrix_free;
75
76 unsigned int dof_index_vector;
77 unsigned int dof_index_scalar;
78 unsigned int quad_index;
79};
80
81/*
82 * Calculator for the shear rate according to
83 * [Galdi et al., 2008, Hemodynamical Flows: Modeling, Analysis and Simulation]
84 * of a vector field u(x) defined as the scalar quantity
85 *
86 * sqrt(2 * trace(sym_grad(u)^2)) = sqrt(2 * sym_grad(u) : sym_grad(u))
87 * where
88 * sym_grad(u) := 0.5 * (grad(u) + grad(u)^T)
89 *
90 * is the symmetric part of the vector field's gradient.
91 */
92template<int dim, typename Number>
93class ShearRateCalculator
94{
95private:
96 typedef ShearRateCalculator<dim, Number> This;
97
98 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
99
100 typedef dealii::VectorizedArray<Number> scalar;
101 typedef dealii::SymmetricTensor<2, dim, dealii::VectorizedArray<Number>> symmetric_tensor;
102
103 typedef std::pair<unsigned int, unsigned int> Range;
104
105 typedef CellIntegrator<dim, dim, Number> CellIntegratorVector;
106 typedef CellIntegrator<dim, 1, Number> CellIntegratorScalar;
107
108public:
109 ShearRateCalculator();
110
111 void
112 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
113 unsigned int const dof_index_vector_in,
114 unsigned int const dof_index_scalar_in,
115 unsigned int const quad_index_in);
116
117 /*
118 * Compute the right-hand side of an L2 projection of the shear rate of the vector field.
119 */
120 void
121 compute_projection_rhs(VectorType & dst_scalar_valued,
122 VectorType const & src_vector_valued) const;
123
124private:
125 void
126 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
127 VectorType & dst_scalar_valued,
128 VectorType const & src_vector_valued,
129 Range const & cell_range) const;
130
131 dealii::MatrixFree<dim, Number> const * matrix_free;
132
133 unsigned int dof_index_vector;
134 unsigned int dof_index_scalar;
135 unsigned int quad_index;
136};
137
138/*
139 * Calculator for the vorticity of a vector field u(x) defined as
140 *
141 * omega := curl(u)
142 *
143 * 2D : omega = - d u(1) / d x(2) + d u(2) / d x(1)
144 *
145 * 3D : omega(1) = d u(3) / d x(2) - d u(2) / d x(3)
146 * omega(2) = d u(1) / d x(3) - d u(3) / d x(1)
147 * omega(3) = d u(2) / d x(1) - d u(1) / d x(2)
148 *
149 * which is scalar-valued in 2D and vector-valued in 3D. Therefore, we always write into a
150 * vector-valued destination vector with `dim` components, filling only the first component in 2D.
151 * The second component in the solution vector in the 2D case corresponds to projecting the zero
152 * function into the finite element space.
153 */
154template<int dim, typename Number>
155class VorticityCalculator
156{
157public:
158 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
159
160 typedef VorticityCalculator<dim, Number> This;
161
162 typedef CellIntegrator<dim, dim, Number> CellIntegratorVector;
163
164 typedef dealii::Tensor<1, dim, dealii::VectorizedArray<Number>> vector;
165
166 VorticityCalculator();
167
168 void
169 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
170 unsigned int const dof_index_vector_in,
171 unsigned int const quad_index_in);
172
173 /*
174 * Compute the right-hand side of an L2 projection of the vorticity of the vector field.
175 */
176 void
177 compute_projection_rhs(VectorType & dst_vector_valued,
178 VectorType const & src_vector_valued) const;
179
180private:
181 void
182 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
183 VectorType & dst_vector_valued,
184 VectorType const & src_vector_valued,
185 std::pair<unsigned int, unsigned int> const & cell_range) const;
186
187 dealii::MatrixFree<dim, Number> const * matrix_free;
188 unsigned int dof_index_vector;
189 unsigned int quad_index;
190};
191
192/*
193 * Calculator to project the viscosity coefficients stored in the `ViscousKernel` into the finite
194 * element space. Note that the viscosity is *not updated* but only accessed.
195 */
196template<int dim, typename Number>
197class ViscosityCalculator
198{
199private:
200 typedef ViscosityCalculator<dim, Number> This;
201
202 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
203
204 typedef dealii::VectorizedArray<Number> scalar;
205
206 typedef std::pair<unsigned int, unsigned int> Range;
207
208 typedef CellIntegrator<dim, 1, Number> CellIntegratorScalar;
209
210public:
211 ViscosityCalculator();
212
213 void
214 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
215 unsigned int const dof_index_scalar_in,
216 unsigned int const quad_index_in,
217 IncNS::Operators::ViscousKernel<dim, Number> const & viscous_kernel_in);
218
219 /*
220 * Compute the right-hand side of an L2 projection of the stored viscosity.
221 */
222 void
223 compute_projection_rhs(VectorType & dst_scalar_valued) const;
224
225private:
226 void
227 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
228 VectorType & dst_scalar_valued,
229 VectorType const & src_scalar_valued,
230 Range const & cell_range) const;
231
232 dealii::MatrixFree<dim, Number> const * matrix_free;
233
234 unsigned int dof_index_scalar;
235 unsigned int quad_index;
236
238};
239
240template<int dim, typename Number>
241class MagnitudeCalculator
242{
243private:
244 typedef MagnitudeCalculator<dim, Number> This;
245
246 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
247
248 typedef dealii::VectorizedArray<Number> scalar;
249
250 typedef std::pair<unsigned int, unsigned int> Range;
251
252 typedef CellIntegrator<dim, dim, Number> IntegratorVector;
253 typedef CellIntegrator<dim, 1, Number> IntegratorScalar;
254
255public:
256 MagnitudeCalculator();
257
258 void
259 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
260 unsigned int const dof_index_vector_in,
261 unsigned int const dof_index_scalar_in,
262 unsigned int const quad_index_in);
263
264 /*
265 * Compute the right-hand side of an L2 projection of the magnitude of the vector field.
266 */
267 void
268 compute_projection_rhs(VectorType & dst_scalar_valued,
269 VectorType const & src_vector_valued) const;
270
271private:
272 void
273 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
274 VectorType & dst_scalar_valued,
275 VectorType const & src_vector_valued,
276 Range const & cell_range) const;
277
278 dealii::MatrixFree<dim, Number> const * matrix_free;
279
280 unsigned int dof_index_vector;
281 unsigned int dof_index_scalar;
282 unsigned int quad_index;
283};
284
285/*
286 * Calculator to project the Q-criterion into the finite element space.
287 */
288template<int dim, typename Number>
289class QCriterionCalculator
290{
291private:
292 typedef QCriterionCalculator<dim, Number> This;
293
294 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
295
296 typedef dealii::VectorizedArray<Number> scalar;
297 typedef dealii::Tensor<2, dim, dealii::VectorizedArray<Number>> tensor;
298
299 typedef std::pair<unsigned int, unsigned int> Range;
300
301 typedef CellIntegrator<dim, dim, Number> CellIntegratorVector;
302 typedef CellIntegrator<dim, 1, Number> CellIntegratorScalar;
303
304public:
305 QCriterionCalculator();
306
307 void
308 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
309 unsigned int const dof_index_vector_in,
310 unsigned int const dof_index_scalar_in,
311 unsigned int const quad_index_in,
312 bool const compressible_flow);
313
314 /*
315 * Compute the right-hand side of an L2 projection of the QCriterion of the vector field.
316 */
317 void
318 compute_projection_rhs(VectorType & dst_scalar_valued,
319 VectorType const & src_vector_valued) const;
320
321private:
322 void
323 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
324 VectorType & dst_scalar_valued,
325 VectorType const & src_vector_valued,
326 Range const & cell_range) const;
327
328 dealii::MatrixFree<dim, Number> const * matrix_free;
329
330 unsigned int dof_index_vector;
331 unsigned int dof_index_scalar;
332 unsigned int quad_index;
333 bool compressible_flow;
334};
335
336} // namespace ExaDG
337
338#endif /* EXADG_OPERATORS_NAVIER_STOKES_CALCULATORS_H_ */
Definition viscous_operator.h:64
Definition driver.cpp:33