ExaDG
Loading...
Searching...
No Matches
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 INCLUDE_CONVECTION_DIFFUSION_DG_CONVECTION_DIFFUSION_OPERATION_H_
23#define INCLUDE_CONVECTION_DIFFUSION_DG_CONVECTION_DIFFUSION_OPERATION_H_
24
25// deal.II
26#include <deal.II/fe/fe_dgq.h>
27#include <deal.II/fe/fe_system.h>
28
29// ExaDG
30#include <exadg/convection_diffusion/spatial_discretization/interface.h>
31#include <exadg/convection_diffusion/spatial_discretization/operators/combined_operator.h>
32#include <exadg/convection_diffusion/user_interface/boundary_descriptor.h>
33#include <exadg/convection_diffusion/user_interface/field_functions.h>
34#include <exadg/convection_diffusion/user_interface/parameters.h>
35#include <exadg/grid/grid.h>
36#include <exadg/matrix_free/matrix_free_data.h>
37#include <exadg/operators/inverse_mass_operator.h>
38#include <exadg/operators/mass_operator.h>
39#include <exadg/operators/rhs_operator.h>
40#include <exadg/operators/solution_transfer.h>
41#include <exadg/solvers_and_preconditioners/preconditioners/preconditioner_base.h>
42
43namespace ExaDG
44{
45namespace ConvDiff
46{
47template<int dim, typename Number>
48class Operator : public dealii::Subscriptor, public Interface::Operator<Number>
49{
50private:
51 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
52
53public:
54 /*
55 * Constructor.
56 */
57 Operator(std::shared_ptr<Grid<dim> const> grid,
58 std::shared_ptr<dealii::Mapping<dim> const> mapping,
59 std::shared_ptr<MultigridMappings<dim, Number>> const multigrid_mappings,
60 std::shared_ptr<BoundaryDescriptor<dim> const> boundary_descriptor,
61 std::shared_ptr<FieldFunctions<dim> const> field_functions,
62 Parameters const & param,
63 std::string const & field,
64 MPI_Comm const & mpi_comm);
65
66
67 void
68 fill_matrix_free_data(MatrixFreeData<dim, Number> & matrix_free_data) const;
69
73 void
74 setup();
75
84 void
85 setup(std::shared_ptr<dealii::MatrixFree<dim, Number> const> matrix_free_in,
86 std::shared_ptr<MatrixFreeData<dim, Number> const> matrix_free_data_in,
87 std::string const & dof_index_velocity_external_in = "");
88
89 /*
90 * Call this setup() function for setup after adaptive mesh refinement.
91 */
92 void
93 setup_after_coarsening_and_refinement();
94
95 /*
96 * Initialization of dof-vector.
97 */
98 void
99 initialize_dof_vector(VectorType & src) const final;
100
101 /*
102 * Initialization of velocity dof-vector (in case of numerical velocity field).
103 */
104 void
105 initialize_dof_vector_velocity(VectorType & src) const final;
106
107 /*
108 * Obtain velocity dof-vector by interpolation of specified analytical velocity field.
109 */
110 void
111 interpolate_velocity(VectorType & velocity, double const time) const;
112
113 /*
114 * Obtain velocity dof-vector by L2-projection using the specified analytical velocity field.
115 */
116 void
117 project_velocity(VectorType & velocity, double const time) const final;
118
119 /*
120 * Prescribe initial conditions using a specified analytical function.
121 */
122 void
123 prescribe_initial_conditions(VectorType & src, double const evaluation_time) const final;
124
125 /*
126 * This function is used in case of explicit time integration:
127 *
128 * It evaluates the right-hand side operator, the convective and diffusive terms (subsequently
129 * multiplied by -1.0 in order to shift these terms to the right-hand side of the equations) and
130 * finally applies the inverse mass operator.
131 */
132 void
133 evaluate_explicit_time_int(VectorType & dst,
134 VectorType const & src,
135 double const evaluation_time,
136 VectorType const * velocity = nullptr) const final;
137
138 /*
139 * This function evaluates the convective term which is needed when using an explicit formulation
140 * for the convective term.
141 */
142 void
143 evaluate_convective_term(VectorType & dst,
144 VectorType const & src,
145 double const evaluation_time,
146 VectorType const * velocity = nullptr) const;
147
148 /*
149 * This function calculates the inhomogeneous parts of all operators arising e.g. from
150 * inhomogeneous boundary conditions or the solution at previous instants of time occurring in the
151 * discrete time derivative term.
152 *
153 * Note that the convective operator only has a contribution to the right-hand side if it is
154 * formulated implicitly in time. In case of an explicit treatment the whole convective operator
155 * (call function evaluate_convective_term() instead of rhs()) has to be added to the right-hand
156 * side of the equations.
157 */
158 void
159 rhs(VectorType & dst,
160 double const evaluation_time = 0.0,
161 VectorType const * velocity = nullptr) const final;
162
163 /*
164 * This function applies the mass operator to the src-vector and writes the result to the
165 * dst-vector.
166 */
167 void
168 apply_mass_operator(VectorType & dst, VectorType const & src) const;
169
170 /*
171 * This function applies the mass operator to the src-vector and adds the result to the
172 * dst-vector.
173 */
174 void
175 apply_mass_operator_add(VectorType & dst, VectorType const & src) const;
176
177 /*
178 * This function applies the convective operator to the src-vector and writes the result to the
179 * dst-vector. It is needed for throughput measurements of the matrix-free implementation.
180 */
181 void
182 apply_convective_term(VectorType & dst, VectorType const & src) const;
183
184 void
185 update_convective_term(double const evaluation_time, VectorType const * velocity = nullptr) const;
186
187 /*
188 * This function applies the diffusive operator to the src-vector and writes the result to the
189 * dst-vector. It is needed for throughput measurements of the matrix-free implementation.
190 */
191 void
192 apply_diffusive_term(VectorType & dst, VectorType const & src) const;
193
194 /*
195 * This function applies the combined mass-convection-diffusion operator to the src-vector
196 * and writes the result to the dst-vector. It is needed for throughput measurements of the
197 * matrix-free implementation.
198 */
199 void
200 apply_conv_diff_operator(VectorType & dst, VectorType const & src) const;
201
202 void
203 update_conv_diff_operator(double const evaluation_time,
204 double const scaling_factor,
205 VectorType const * velocity = nullptr);
206
207 /*
208 * Updates spatial operators after grid has been moved.
209 */
210 void
211 update_after_grid_motion(bool const update_matrix_free);
212
213 /*
214 * Prepare and interpolation in adaptive mesh refinement.
215 */
216 void
217 prepare_coarsening_and_refinement(std::vector<VectorType *> & vectors);
218
219 void
220 interpolate_after_coarsening_and_refinement(std::vector<VectorType *> & vectors);
221
222 /*
223 * This function solves the linear system of equations in case of implicit time integration or
224 * steady-state problems (potentially involving the mass, convective, and diffusive
225 * operators).
226 */
227 unsigned int
228 solve(VectorType & sol,
229 VectorType const & rhs,
230 bool const update_preconditioner,
231 double const scaling_factor = -1.0,
232 double const time = -1.0,
233 VectorType const * velocity = nullptr) final;
234
235 /*
236 * Calculate time step size according to maximum efficiency criterion
237 */
238 double
239 calculate_time_step_max_efficiency(unsigned int const order_time_integrator) const final;
240
241 /*
242 * Calculate time step size according to CFL criterion
243 */
244
245 // global CFL criterion
246 double
247 calculate_time_step_cfl_global(double const time) const final;
248
249 // local CFL criterion: use numerical velocity field
250 double
251 calculate_time_step_cfl_numerical_velocity(VectorType const & velocity) const final;
252
253 // local CFL criterion: use analytical velocity field
254 double
255 calculate_time_step_cfl_analytical_velocity(double const time) const final;
256
257 /*
258 * Calculate time step size according to diffusion term
259 */
260 double
261 calculate_time_step_diffusion() const final;
262
263 /*
264 * Setters and getters.
265 */
266
267 dealii::MatrixFree<dim, Number> const &
268 get_matrix_free() const;
269
270 dealii::DoFHandler<dim> const &
271 get_dof_handler() const;
272
273 dealii::DoFHandler<dim> const &
274 get_dof_handler_velocity() const;
275
276 dealii::types::global_dof_index
277 get_number_of_dofs() const;
278
279 std::string
280 get_dof_name() const;
281
282 unsigned int
283 get_dof_index() const;
284
285 unsigned int
286 get_quad_index() const;
287
288 std::shared_ptr<dealii::Mapping<dim> const>
289 get_mapping() const;
290
291 dealii::AffineConstraints<Number> const &
292 get_constraints() const;
293
294private:
295 void
296 do_setup();
297
301 void
302 initialize_dof_handler_and_constraints();
303
307 void
308 setup_operators();
309
313 double
314 calculate_maximum_velocity(double const time) const;
315
319 double
320 calculate_minimum_element_length() const;
321
322 bool
323 needs_own_dof_handler_velocity() const;
324
325 std::string
326 get_quad_name() const;
327
328 std::string
329 get_quad_name_overintegration() const;
330
331 std::string
332 get_dof_name_velocity() const;
333
334 /*
335 * Dof index for velocity (in case of numerical velocity field)
336 */
337 unsigned int
338 get_dof_index_velocity() const;
339
340 unsigned int
341 get_quad_index_overintegration() const;
342
343 /*
344 * Initializes the preconditioner.
345 */
346 void
347 setup_preconditioner();
348
349 /*
350 * Initializes the solver.
351 */
352 void
353 setup_solver();
354
355 /*
356 * Grid
357 */
358 std::shared_ptr<Grid<dim> const> grid;
359
360 /*
361 * SolutionTransfer for adaptive mesh refinement.
362 */
363 std::shared_ptr<ExaDG::SolutionTransfer<dim, VectorType>> solution_transfer;
364
365 /*
366 * Grid motion for ALE formulations
367 */
368 std::shared_ptr<dealii::Mapping<dim> const> mapping;
369
370 std::shared_ptr<MultigridMappings<dim, Number>> const multigrid_mappings;
371
372 /*
373 * User interface: Boundary conditions and field functions.
374 */
375 std::shared_ptr<BoundaryDescriptor<dim> const> boundary_descriptor;
376 std::shared_ptr<FieldFunctions<dim> const> field_functions;
377
378 /*
379 * List of parameters.
380 */
381 Parameters const & param;
382
383 std::string const field;
384
385 /*
386 * Basic finite element ingredients.
387 */
388 std::shared_ptr<dealii::FiniteElement<dim>> fe;
389 dealii::DoFHandler<dim> dof_handler;
390
391 /*
392 * Numerical velocity field.
393 */
394 std::shared_ptr<dealii::FiniteElement<dim>> fe_velocity;
395 std::shared_ptr<dealii::DoFHandler<dim>> dof_handler_velocity;
396
397 /*
398 * Constraints.
399 */
400 dealii::AffineConstraints<Number> affine_constraints;
401
402 std::string const dof_index_std = "conv_diff";
403 std::string const dof_index_velocity = "conv_diff_velocity";
404
405 std::string const quad_index_std = "conv_diff";
406 std::string const quad_index_overintegration = "conv_diff_overintegration";
407
408 std::string dof_index_velocity_external;
409
410 /*
411 * Matrix-free operator evaluation.
412 */
413 std::shared_ptr<dealii::MatrixFree<dim, Number> const> matrix_free;
414 std::shared_ptr<MatrixFreeData<dim, Number> const> matrix_free_data;
415
416 // If we want to be able to update the mapping, we need a pointer to a non-const MatrixFree
417 // object. In case this object is created, we let the above object called matrix_free point to
418 // matrix_free_own_storage. This variable is needed for ALE formulations.
419 std::shared_ptr<dealii::MatrixFree<dim, Number>> matrix_free_own_storage;
420
421 /*
422 * Basic operators.
423 */
424 std::shared_ptr<Operators::ConvectiveKernel<dim, Number>> convective_kernel;
425 std::shared_ptr<Operators::DiffusiveKernel<dim, Number>> diffusive_kernel;
426
427 MassOperator<dim, 1, Number> mass_operator;
428 InverseMassOperator<dim, 1, Number> inverse_mass_operator;
429 ConvectiveOperator<dim, Number> convective_operator;
430 DiffusiveOperator<dim, Number> diffusive_operator;
431 RHSOperator<dim, Number> rhs_operator;
432
433 /*
434 * Combined operator.
435 */
436 CombinedOperator<dim, Number> combined_operator;
437
438 /*
439 * Solvers and preconditioners
440 */
441 std::shared_ptr<PreconditionerBase<Number>> preconditioner;
442 std::shared_ptr<Krylov::SolverBase<VectorType>> iterative_solver;
443
444 /*
445 * MPI
446 */
447 MPI_Comm const mpi_comm;
448
449 /*
450 * Output to screen.
451 */
452 dealii::ConditionalOStream pcout;
453};
454
455} // namespace ConvDiff
456} // namespace ExaDG
457
458#endif /* INCLUDE_CONVECTION_DIFFUSION_DG_CONVECTION_DIFFUSION_OPERATION_H_ */
Definition combined_operator.h:56
Definition convective_operator.h:552
Definition diffusive_operator.h:232
Definition interface.h:39
Definition operator.h:49
void setup()
Definition operator.cpp:315
Definition parameters.h:46
Definition grid.h:40
Definition inverse_mass_operator.h:53
Definition mass_operator.h:41
Definition grid.h:84
Definition rhs_operator.h:107
Definition driver.cpp:33
Definition boundary_descriptor.h:46
Definition field_functions.h:31
Definition matrix_free_data.h:40