ExaDG
Loading...
Searching...
No Matches
gradient_operator.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_INCOMPRESSIBLE_NAVIER_STOKES_SPATIAL_DISCRETIZATION_OPERATORS_GRADIENT_OPERATOR_H_
23#define EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SPATIAL_DISCRETIZATION_OPERATORS_GRADIENT_OPERATOR_H_
24
25// ExaDG
26#include <exadg/incompressible_navier_stokes/spatial_discretization/operators/weak_boundary_conditions.h>
27#include <exadg/incompressible_navier_stokes/user_interface/parameters.h>
28#include <exadg/matrix_free/integrators.h>
29#include <exadg/operators/mapping_flags.h>
30
31namespace ExaDG
32{
33namespace IncNS
34{
35namespace Operators
36{
37template<int dim, typename Number>
39{
40private:
41 typedef CellIntegrator<dim, 1, Number> CellIntegratorP;
42
43 typedef dealii::VectorizedArray<Number> scalar;
44 typedef dealii::Tensor<1, dim, dealii::VectorizedArray<Number>> vector;
45
46public:
47 static MappingFlags
48 get_mapping_flags()
49 {
50 MappingFlags flags;
51
52 flags.cells = dealii::update_JxW_values | dealii::update_gradients;
53 flags.inner_faces = dealii::update_JxW_values | dealii::update_normal_vectors;
54 flags.boundary_faces =
55 dealii::update_JxW_values | dealii::update_quadrature_points | dealii::update_normal_vectors;
56
57 return flags;
58 }
59
60 /*
61 * This function implements the central flux as numerical flux function.
62 */
63 inline DEAL_II_ALWAYS_INLINE //
64 scalar
65 calculate_flux(scalar const & value_m, scalar const & value_p) const
66 {
67 return 0.5 * (value_m + value_p);
68 }
69
70 /*
71 * Volume flux, i.e., the term occurring in the volume integral for
72 * weak formulation (performing integration-by-parts)
73 */
74 inline DEAL_II_ALWAYS_INLINE //
75 scalar
76 get_volume_flux_weak(CellIntegratorP & pressure, unsigned int const q) const
77 {
78 // minus sign due to integration by parts
79 return -pressure.get_value(q);
80 }
81
82 /*
83 * Volume flux, i.e., the term occurring in the volume integral for
84 * strong formulation (no integration-by-parts, or integration-by-parts performed twice)
85 */
86 inline DEAL_II_ALWAYS_INLINE //
87 vector
88 get_volume_flux_strong(CellIntegratorP & pressure, unsigned int const q) const
89 {
90 return pressure.get_gradient(q);
91 }
92};
93} // namespace Operators
94
95template<int dim>
96struct GradientOperatorData
97{
98 GradientOperatorData()
99 : dof_index_velocity(0),
100 dof_index_pressure(1),
101 quad_index(0),
102 integration_by_parts(true),
103 use_boundary_data(true),
104 formulation(FormulationPressureGradientTerm::Weak)
105 {
106 }
107
108 unsigned int dof_index_velocity;
109 unsigned int dof_index_pressure;
110
111 unsigned int quad_index;
112
113 bool integration_by_parts;
114 bool use_boundary_data;
115
116 FormulationPressureGradientTerm formulation;
117
118 std::shared_ptr<BoundaryDescriptorP<dim> const> bc;
119};
120
121template<int dim, typename Number>
122class GradientOperator
123{
124public:
125 typedef GradientOperator<dim, Number> This;
126
127 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
128
129 typedef dealii::VectorizedArray<Number> scalar;
130 typedef dealii::Tensor<1, dim, dealii::VectorizedArray<Number>> vector;
131
132 typedef std::pair<unsigned int, unsigned int> Range;
133
134 typedef CellIntegrator<dim, dim, Number> CellIntegratorU;
135 typedef CellIntegrator<dim, 1, Number> CellIntegratorP;
136
137 typedef FaceIntegrator<dim, dim, Number> FaceIntegratorU;
138 typedef FaceIntegrator<dim, 1, Number> FaceIntegratorP;
139
140 GradientOperator();
141
142 void
143 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
144 GradientOperatorData<dim> const & data_in);
145
146 void
147 set_scaling_factor_pressure(double const & scaling_factor);
148
150 get_operator_data() const;
151
152 // homogeneous operator
153 void
154 apply(VectorType & dst, VectorType const & src) const;
155
156 void
157 apply_add(VectorType & dst, VectorType const & src) const;
158
159 // inhomogeneous operator
160 void
161 rhs(VectorType & dst, Number const evaluation_time) const;
162
163 void
164 rhs_bc_from_dof_vector(VectorType & dst, VectorType const & pressure_bc) const;
165
166 void
167 rhs_add(VectorType & dst, Number const evaluation_time) const;
168
169 // full operator, i.e., homogeneous and inhomogeneous contributions
170 void
171 evaluate(VectorType & dst, VectorType const & src, Number const evaluation_time) const;
172
173 void
174 evaluate_add(VectorType & dst, VectorType const & src, Number const evaluation_time) const;
175
176 void
177 evaluate_bc_from_dof_vector(VectorType & dst,
178 VectorType const & src,
179 VectorType const & pressure_bc) const;
180
181private:
182 void
183 do_cell_integral_weak(CellIntegratorP & pressure, CellIntegratorU & velocity) const;
184
185 void
186 do_cell_integral_strong(CellIntegratorP & pressure, CellIntegratorU & velocity) const;
187
188 void
189 do_face_integral(FaceIntegratorP & pressure_m,
190 FaceIntegratorP & pressure_p,
191 FaceIntegratorU & velocity_m,
192 FaceIntegratorU & velocity_p) const;
193
194 void
195 do_boundary_integral(FaceIntegratorP & pressure,
196 FaceIntegratorU & velocity,
197 OperatorType const & operator_type,
198 dealii::types::boundary_id const & boundary_id) const;
199
200 void
201 do_boundary_integral_from_dof_vector(FaceIntegratorP & pressure,
202 FaceIntegratorP & pressure_exterior,
203 FaceIntegratorU & velocity,
204 OperatorType const & operator_type,
205 dealii::types::boundary_id const & boundary_id) const;
206
207 void
208 cell_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
209 VectorType & dst,
210 VectorType const & src,
211 Range const & cell_range) const;
212
213 void
214 face_loop(dealii::MatrixFree<dim, Number> const & matrix_free,
215 VectorType & dst,
216 VectorType const & src,
217 Range const & face_range) const;
218
219 void
220 boundary_face_loop_hom_operator(dealii::MatrixFree<dim, Number> const & matrix_free,
221 VectorType & dst,
222 VectorType const & src,
223 Range const & face_range) const;
224
225 void
226 boundary_face_loop_full_operator(dealii::MatrixFree<dim, Number> const & matrix_free,
227 VectorType & dst,
228 VectorType const & src,
229 Range const & face_range) const;
230
231 void
232 cell_loop_inhom_operator(dealii::MatrixFree<dim, Number> const & matrix_free,
233 VectorType & dst,
234 VectorType const & src,
235 Range const & cell_range) const;
236
237 void
238 face_loop_inhom_operator(dealii::MatrixFree<dim, Number> const & matrix_free,
239 VectorType & dst,
240 VectorType const & src,
241 Range const & face_range) const;
242
243 void
244 boundary_face_loop_inhom_operator(dealii::MatrixFree<dim, Number> const & matrix_free,
245 VectorType & dst,
246 VectorType const & src,
247 Range const & face_range) const;
248
249 void
250 boundary_face_loop_inhom_operator_bc_from_dof_vector(
251 dealii::MatrixFree<dim, Number> const & matrix_free,
252 VectorType & dst,
253 VectorType const & src,
254 Range const & face_range) const;
255
256 void
257 boundary_face_loop_full_operator_bc_from_dof_vector(
258 dealii::MatrixFree<dim, Number> const & matrix_free,
259 VectorType & dst,
260 VectorType const & src,
261 Range const & face_range) const;
262
263 dealii::MatrixFree<dim, Number> const * matrix_free;
264
266
267 mutable double time;
268
269 // if the continuity equation of the incompressible Navier-Stokes
270 // equations is scaled by a constant factor, the system of equations
271 // is solved for a modified pressure p^* = 1/scaling_factor * p. Hence,
272 // when applying the gradient operator to this modified pressure we have
273 // to make sure that we also apply the correct boundary conditions for p^*,
274 // i.e., g_p^* = 1/scaling_factor * g_p
275 double inverse_scaling_factor_pressure;
276
278
279 // needed if pressure Dirichlet boundary condition is evaluated from dof vector
280 mutable VectorType const * pressure_bc;
281};
282
283} // namespace IncNS
284} // namespace ExaDG
285
286#endif /* EXADG_INCOMPRESSIBLE_NAVIER_STOKES_SPATIAL_DISCRETIZATION_OPERATORS_GRADIENT_OPERATOR_H_ \
287 */
Definition gradient_operator.h:39
Definition driver.cpp:33
Definition gradient_operator.h:97
Definition mapping_flags.h:31