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 EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_OPERATOR_H_
23#define EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_OPERATOR_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::EnableObserverPointer, 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 * De-/serialize the vectors given.
121 */
122 void
123 serialize_vectors(std::vector<VectorType const *> const & vectors) const final;
124
125 void
126 deserialize_vectors(std::vector<VectorType *> const & vectors) final;
127
128 /*
129 * Prescribe initial conditions using a specified analytical function.
130 */
131 void
132 prescribe_initial_conditions(VectorType & src, double const evaluation_time) const final;
133
134 /*
135 * This function is used in case of explicit time integration:
136 *
137 * It evaluates the right-hand side operator, the convective and diffusive terms (subsequently
138 * multiplied by -1.0 in order to shift these terms to the right-hand side of the equations) and
139 * finally applies the inverse mass operator.
140 */
141 void
142 evaluate_explicit_time_int(VectorType & dst,
143 VectorType const & src,
144 double const evaluation_time,
145 VectorType const * velocity = nullptr) const final;
146
147 /*
148 * This function evaluates the convective term which is needed when using an explicit formulation
149 * for the convective term.
150 */
151 void
152 evaluate_convective_term(VectorType & dst,
153 VectorType const & src,
154 double const evaluation_time,
155 VectorType const * velocity = nullptr) const;
156
157 /*
158 * This function calculates the inhomogeneous parts of all operators arising e.g. from
159 * inhomogeneous boundary conditions or the solution at previous instants of time occurring in the
160 * discrete time derivative term.
161 *
162 * Note that the convective operator only has a contribution to the right-hand side if it is
163 * formulated implicitly in time. In case of an explicit treatment the whole convective operator
164 * (call function evaluate_convective_term() instead of rhs()) has to be added to the right-hand
165 * side of the equations.
166 */
167 void
168 rhs(VectorType & dst,
169 double const evaluation_time = 0.0,
170 VectorType const * velocity = nullptr) const final;
171
172 /*
173 * This function applies the mass operator to the src-vector and writes the result to the
174 * dst-vector.
175 */
176 void
177 apply_mass_operator(VectorType & dst, VectorType const & src) const;
178
179 /*
180 * This function applies the mass operator to the src-vector and adds the result to the
181 * dst-vector.
182 */
183 void
184 apply_mass_operator_add(VectorType & dst, VectorType const & src) const;
185
186 /*
187 * This function applies the convective operator to the src-vector and writes the result to the
188 * dst-vector. It is needed for throughput measurements of the matrix-free implementation.
189 */
190 void
191 apply_convective_term(VectorType & dst, VectorType const & src) const;
192
193 void
194 update_convective_term(double const evaluation_time, VectorType const * velocity = nullptr) const;
195
196 /*
197 * This function applies the diffusive operator to the src-vector and writes the result to the
198 * dst-vector. It is needed for throughput measurements of the matrix-free implementation.
199 */
200 void
201 apply_diffusive_term(VectorType & dst, VectorType const & src) const;
202
203 /*
204 * This function applies the combined mass-convection-diffusion operator to the src-vector
205 * and writes the result to the dst-vector. It is needed for throughput measurements of the
206 * matrix-free implementation.
207 */
208 void
209 apply_conv_diff_operator(VectorType & dst, VectorType const & src) const;
210
211 void
212 update_conv_diff_operator(double const evaluation_time,
213 double const scaling_factor,
214 VectorType const * velocity = nullptr);
215
216 /*
217 * Updates spatial operators after grid has been moved.
218 */
219 void
220 update_after_grid_motion(bool const update_matrix_free);
221
222 /*
223 * Prepare and interpolation in adaptive mesh refinement.
224 */
225 void
226 prepare_coarsening_and_refinement(std::vector<VectorType *> & vectors);
227
228 void
229 interpolate_after_coarsening_and_refinement(std::vector<VectorType *> & vectors);
230
231 /*
232 * This function solves the linear system of equations in case of implicit time integration or
233 * steady-state problems (potentially involving the mass, convective, and diffusive
234 * operators).
235 */
236 unsigned int
237 solve(VectorType & sol,
238 VectorType const & rhs,
239 bool const update_preconditioner,
240 double const scaling_factor = -1.0,
241 double const time = -1.0,
242 VectorType const * velocity = nullptr) final;
243
244 /*
245 * Calculate time step size according to maximum efficiency criterion
246 */
247 double
248 calculate_time_step_max_efficiency(unsigned int const order_time_integrator) const final;
249
250 /*
251 * Calculate time step size according to CFL criterion
252 */
253
254 // global CFL criterion
255 double
256 calculate_time_step_cfl_global(double const time) const final;
257
258 // local CFL criterion: use numerical velocity field
259 double
260 calculate_time_step_cfl_numerical_velocity(VectorType const & velocity) const final;
261
262 // local CFL criterion: use analytical velocity field
263 double
264 calculate_time_step_cfl_analytical_velocity(double const time) const final;
265
266 /*
267 * Calculate time step size according to diffusion term
268 */
269 double
270 calculate_time_step_diffusion() const final;
271
272 /*
273 * Setters and getters.
274 */
275
276 dealii::MatrixFree<dim, Number> const &
277 get_matrix_free() const;
278
279 dealii::DoFHandler<dim> const &
280 get_dof_handler() const;
281
282 dealii::DoFHandler<dim> const &
283 get_dof_handler_velocity() const;
284
285 dealii::types::global_dof_index
286 get_number_of_dofs() const;
287
288 std::string
289 get_dof_name() const;
290
291 unsigned int
292 get_dof_index() const;
293
294 unsigned int
295 get_quad_index() const;
296
297 std::shared_ptr<dealii::Mapping<dim> const>
298 get_mapping() const;
299
300 dealii::AffineConstraints<Number> const &
301 get_constraints() const;
302
303private:
304 void
305 do_setup();
306
310 void
311 initialize_dof_handler_and_constraints();
312
316 void
317 setup_operators();
318
322 double
323 calculate_maximum_velocity(double const time) const;
324
328 double
329 calculate_minimum_element_length() const;
330
331 bool
332 needs_own_dof_handler_velocity() const;
333
334 bool
335 needs_dof_handler_mapping() const;
336
337 std::string
338 get_quad_name() const;
339
340 std::string
341 get_quad_name_overintegration() const;
342
343 std::string
344 get_dof_name_velocity() const;
345
346 /*
347 * Dof index for velocity (in case of numerical velocity field)
348 */
349 unsigned int
350 get_dof_index_velocity() const;
351
352 unsigned int
353 get_quad_index_overintegration() const;
354
355 /*
356 * Initializes the preconditioner.
357 */
358 void
359 setup_preconditioner();
360
361 /*
362 * Initializes the solver.
363 */
364 void
365 setup_solver();
366
367 /*
368 * Grid
369 */
370 std::shared_ptr<Grid<dim> const> grid;
371
372 /*
373 * SolutionTransfer for adaptive mesh refinement.
374 */
375 std::shared_ptr<ExaDG::SolutionTransfer<dim, VectorType>> solution_transfer;
376
377 /*
378 * Grid motion for ALE formulations
379 */
380 std::shared_ptr<dealii::Mapping<dim> const> mapping;
381
382 std::shared_ptr<MultigridMappings<dim, Number>> const multigrid_mappings;
383
384 /*
385 * User interface: Boundary conditions and field functions.
386 */
387 std::shared_ptr<BoundaryDescriptor<dim> const> boundary_descriptor;
388 std::shared_ptr<FieldFunctions<dim> const> field_functions;
389
390 /*
391 * List of parameters.
392 */
393 Parameters const & param;
394
395 std::string const field;
396
397 /*
398 * Basic finite element ingredients.
399 */
400 std::shared_ptr<dealii::FiniteElement<dim>> fe;
401 dealii::DoFHandler<dim> dof_handler;
402
403 /*
404 * De-/serialization of the mapping requires a vector-valued `dealii::DofHandler`.
405 */
406 std::shared_ptr<dealii::FiniteElement<dim>> fe_mapping;
407 std::shared_ptr<dealii::DoFHandler<dim>> dof_handler_mapping;
408
409 /*
410 * Numerical velocity field.
411 */
412 std::shared_ptr<dealii::FiniteElement<dim>> fe_velocity;
413 std::shared_ptr<dealii::DoFHandler<dim>> dof_handler_velocity;
414
415 /*
416 * Constraints.
417 */
418 dealii::AffineConstraints<Number> affine_constraints;
419
420 std::string const dof_index_std = "conv_diff";
421 std::string const dof_index_velocity = "conv_diff_velocity";
422
423 std::string const quad_index_std = "conv_diff";
424 std::string const quad_index_overintegration = "conv_diff_overintegration";
425
426 std::string dof_index_velocity_external;
427
428 /*
429 * Matrix-free operator evaluation.
430 */
431 std::shared_ptr<dealii::MatrixFree<dim, Number> const> matrix_free;
432 std::shared_ptr<MatrixFreeData<dim, Number> const> matrix_free_data;
433
434 // If we want to be able to update the mapping, we need a pointer to a non-const MatrixFree
435 // object. In case this object is created, we let the above object called matrix_free point to
436 // matrix_free_own_storage. This variable is needed for ALE formulations.
437 std::shared_ptr<dealii::MatrixFree<dim, Number>> matrix_free_own_storage;
438
439 /*
440 * Basic operators.
441 */
442 std::shared_ptr<Operators::ConvectiveKernel<dim, Number>> convective_kernel;
443 std::shared_ptr<Operators::DiffusiveKernel<dim, Number>> diffusive_kernel;
444
445 MassOperator<dim, 1, Number> mass_operator;
446 InverseMassOperator<dim, 1, Number> inverse_mass_operator;
447 ConvectiveOperator<dim, Number> convective_operator;
448 DiffusiveOperator<dim, Number> diffusive_operator;
449 RHSOperator<dim, Number> rhs_operator;
450
451 /*
452 * Combined operator.
453 */
454 CombinedOperator<dim, Number> combined_operator;
455
456 /*
457 * Solvers and preconditioners
458 */
459 std::shared_ptr<PreconditionerBase<Number>> preconditioner;
460 std::shared_ptr<Krylov::SolverBase<VectorType>> iterative_solver;
461
462 /*
463 * MPI
464 */
465 MPI_Comm const mpi_comm;
466
467 /*
468 * Output to screen.
469 */
470 dealii::ConditionalOStream pcout;
471};
472
473} // namespace ConvDiff
474} // namespace ExaDG
475
476#endif /* EXADG_CONVECTION_DIFFUSION_SPATIAL_DISCRETIZATION_OPERATOR_H_ */
Definition combined_operator.h:57
Definition convective_operator.h:554
Definition diffusive_operator.h:232
Definition interface.h:39
void setup()
Definition operator.cpp:329
Definition parameters.h:46
Definition grid.h:40
Definition inverse_mass_operator.h:97
Definition grid.h:84
Definition rhs_operator.h:108
Definition driver.cpp:33
Definition boundary_descriptor.h:46
Definition field_functions.h:31
Definition matrix_free_data.h:40