ExaDG
Loading...
Searching...
No Matches
inverse_mass_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_OPERATORS_INVERSE_MASS_OPERATOR_H_
23#define EXADG_OPERATORS_INVERSE_MASS_OPERATOR_H_
24
25// deal.II
26#include <deal.II/fe/fe_data.h>
27#include <deal.II/lac/la_parallel_vector.h>
28#include <deal.II/matrix_free/operators.h>
29
30// ExaDG
31#include <exadg/grid/grid_data.h>
32#include <exadg/matrix_free/integrators.h>
33#include <exadg/operators/inverse_mass_parameters.h>
34#include <exadg/operators/mass_operator.h>
35#include <exadg/operators/variable_coefficients.h>
36#include <exadg/solvers_and_preconditioners/preconditioners/block_jacobi_preconditioner.h>
37#include <exadg/solvers_and_preconditioners/preconditioners/jacobi_preconditioner.h>
38#include <exadg/solvers_and_preconditioners/preconditioners/preconditioner_amg.h>
39
40namespace ExaDG
41{
42template<typename Number>
43struct InverseMassOperatorData
44{
45 InverseMassOperatorData()
46 : dof_index(0),
47 quad_index(0),
48 coefficient_is_variable(false),
49 consider_inverse_coefficient(false),
50 variable_coefficients(nullptr)
51 {
52 }
53
54 // Get optimal in the sense of (most likely) fastest implementation type of the inverse mass
55 // operator depending on the approximation space.
56 template<int dim>
57 static InverseMassType
58 get_optimal_inverse_mass_type(dealii::FiniteElement<dim> const & fe,
59 bool const use_affine_mapping)
60 {
61 if(fe.conforms(dealii::FiniteElementData<dim>::L2))
62 {
63 if(fe.reference_cell().is_hyper_cube() || use_affine_mapping)
64 {
65 return InverseMassType::MatrixfreeOperator;
66 }
67 else
68 {
69 return InverseMassType::ElementwiseKrylovSolver;
70 }
71 }
72 else
73 {
74 return InverseMassType::GlobalKrylovSolver;
75 }
76 }
77
78 // Parameters referring to dealii::MatrixFree
79 unsigned int dof_index;
80 unsigned int quad_index;
81
82 InverseMassParameters parameters;
83
84 // Enable variable coefficients.
85 bool coefficient_is_variable;
86
87 // Consider the regular form of the coefficient (1) or its inverse (2):
88 // (1) : (u_h , v_h * c)_Omega
89 // (2) : (u_h , v_h / c)_Omega
90 bool consider_inverse_coefficient;
91
92 VariableCoefficients<dealii::VectorizedArray<Number>> const * variable_coefficients;
93};
94
95template<int dim, int n_components, typename Number>
96class InverseMassOperator
97{
98private:
99 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
100
101 typedef InverseMassOperator<dim, n_components, Number> This;
102
103 typedef CellIntegrator<dim, n_components, Number> Integrator;
104
105 // use a template parameter of -1 to select the precompiled version of this operator
106 typedef dealii::MatrixFreeOperators::CellwiseInverseMassMatrix<dim, -1, n_components, Number>
107 InverseMassAsMatrixFreeOperator;
108
109 typedef std::pair<unsigned int, unsigned int> Range;
110
111public:
112 InverseMassOperator();
113
114 unsigned int
115 get_n_iter_global_last() const;
116
117 void
118 initialize(dealii::MatrixFree<dim, Number> const & matrix_free_in,
119 InverseMassOperatorData<Number> const inverse_mass_operator_data,
120 dealii::AffineConstraints<Number> const * constraints = nullptr);
121
126 void
127 update();
128
129 // dst = M^-1 * src
130 void
131 apply(VectorType & dst, VectorType const & src) const;
132
133 // dst = scaling_factor * (M^-1 * src)
134 void
135 apply_scale(VectorType & dst, double const scaling_factor, VectorType const & src) const;
136
137
138private:
139 void
140 cell_loop_matrix_free_operator(dealii::MatrixFree<dim, Number> const &,
141 VectorType & dst,
142 VectorType const & src,
143 Range const & cell_range) const;
144
145 void
146 cell_loop_matrix_free_operator_simplex(dealii::MatrixFree<dim, Number> const &,
147 VectorType & dst,
148 VectorType const & src,
149 Range const & cell_range) const;
150
151 dealii::MatrixFree<dim, Number> const * matrix_free;
152
153 unsigned int dof_index, quad_index;
154
155 bool is_hypercube_element;
156 std::vector<Number> inverse_mass_matrix;
157
158
160
161 // Variable coefficients not managed by this class.
162 bool coefficient_is_variable;
163 bool consider_inverse_coefficient;
164
165 VariableCoefficients<dealii::VectorizedArray<Number>> const * variable_coefficients;
166
167 // Solver and preconditioner for solving a global linear system of equations for all degrees of
168 // freedom.
169 std::shared_ptr<PreconditionerBase<Number>> global_preconditioner;
170 std::shared_ptr<Krylov::SolverBase<VectorType>> global_solver;
171
172 // Iterations needed in global Krylov solver at last inverse application.
173 mutable unsigned int n_iter_global_last = dealii::numbers::invalid_unsigned_int;
174
175 // Block-Jacobi preconditioner used as cell-wise inverse for L2-conforming spaces. In this case,
176 // the mass matrix is block-diagonal and a block-Jacobi preconditioner inverts the mass operator
177 // exactly (up to solver tolerances). The implementation of the block-Jacobi preconditioner can be
178 // matrix-based or matrix-free, depending on the parameters specified.
179 std::shared_ptr<BlockJacobiPreconditioner<MassOperator<dim, n_components, Number>>>
180 block_jacobi_preconditioner;
181
182 // MassOperator as underlying operator for the cell-wise or global iterative solves.
184};
185
186} // namespace ExaDG
187
188#endif /* EXADG_OPERATORS_INVERSE_MASS_OPERATOR_H_ */
void update()
Definition inverse_mass_operator.cpp:259
Definition mass_operator.h:53
Definition variable_coefficients.h:40
Definition driver.cpp:33
Definition inverse_mass_operator.h:44
Definition inverse_mass_parameters.h:56