ExaDG
Loading...
Searching...
No Matches
wrapper_elementwise_solvers.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_EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_WRAPPER_ELEMENTWISE_SOLVERS_H_
23#define INCLUDE_EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_WRAPPER_ELEMENTWISE_SOLVERS_H_
24
25// deal.II
26#include <deal.II/lac/la_parallel_vector.h>
27#include <deal.II/matrix_free/operators.h>
28
29// ExaDG
30#include <exadg/matrix_free/integrators.h>
31#include <exadg/solvers_and_preconditioners/preconditioners/elementwise_preconditioners.h>
32#include <exadg/solvers_and_preconditioners/solvers/elementwise_krylov_solvers.h>
33#include <exadg/solvers_and_preconditioners/solvers/enum_types.h>
34#include <exadg/solvers_and_preconditioners/solvers/iterative_solvers_dealii_wrapper.h>
35
36namespace ExaDG
37{
38namespace Elementwise
39{
40/*
41 * Solver data
42 */
44{
45 IterativeSolverData() : solver_type(Elementwise::Solver::CG), solver_data(SolverData())
46 {
47 }
48
49 Solver solver_type;
50
51 SolverData solver_data;
52};
53
54template<int dim,
55 int number_of_equations,
56 typename Number,
57 typename Operator,
58 typename Preconditioner>
60 : public Krylov::SolverBase<dealii::LinearAlgebra::distributed::Vector<Number>>
61{
62public:
63 typedef dealii::LinearAlgebra::distributed::Vector<Number> VectorType;
64
66
67 IterativeSolver(Operator & operator_in,
68 Preconditioner & preconditioner_in,
69 IterativeSolverData const solver_data_in)
70 : op(operator_in), preconditioner(preconditioner_in), iterative_solver_data(solver_data_in)
71 {
72 }
73
74 virtual ~IterativeSolver()
75 {
76 }
77
78 void
79 update_preconditioner(bool const update_preconditioner) const override
80 {
81 if(preconditioner.needs_update() or update_preconditioner)
82 {
83 preconditioner.update();
84 }
85 }
86
90 unsigned int
91 solve(VectorType & dst, VectorType const & src) const override
92 {
93 dst = 0;
94
95 op.get_matrix_free().cell_loop(&THIS::solve_elementwise, this, dst, src);
96
97 return 0;
98 }
99
100private:
101 void
102 solve_elementwise(dealii::MatrixFree<dim, Number> const & matrix_free,
103 VectorType & dst,
104 VectorType const & src,
105 std::pair<unsigned int, unsigned int> const & cell_range) const
106 {
107 CellIntegrator<dim, number_of_equations, Number> integrator(matrix_free,
108 op.get_dof_index(),
109 op.get_quad_index());
110
111 unsigned int const dofs_per_cell = integrator.dofs_per_cell;
112
113 dealii::AlignedVector<dealii::VectorizedArray<Number>> solution(dofs_per_cell);
114
115 // setup elementwise solver
116 if(iterative_solver_data.solver_type == Solver::CG)
117 {
118 solver = std::make_shared<
120 dofs_per_cell, iterative_solver_data.solver_data);
121 }
122 else if(iterative_solver_data.solver_type == Solver::GMRES)
123 {
124 solver = std::make_shared<
126 dofs_per_cell, iterative_solver_data.solver_data);
127 }
128 else
129 {
130 AssertThrow(false, dealii::ExcMessage("Not implemented."));
131 }
132
133 // loop over all cells and solve local problem iteratively on each cell
134 for(unsigned int cell = cell_range.first; cell < cell_range.second; ++cell)
135 {
136 integrator.reinit(cell);
137 integrator.read_dof_values(src, 0);
138
139 // initialize operator and preconditioner for current cell
140 op.setup(cell, dofs_per_cell);
141 preconditioner.setup(cell);
142
143 // call iterative solver and solve on current cell
144 solver->solve(&op, solution.begin(), integrator.begin_dof_values(), &preconditioner);
145
146 // write solution on current element to global dof vector
147 for(unsigned int j = 0; j < dofs_per_cell; ++j)
148 integrator.begin_dof_values()[j] = solution[j];
149 integrator.set_dof_values(dst, 0);
150 }
151 }
152
153 mutable std::shared_ptr<
154 Elementwise::SolverBase<dealii::VectorizedArray<Number>, Operator, Preconditioner>>
155 solver;
156
157 Operator & op;
158
159 Preconditioner & preconditioner;
160
161 IterativeSolverData const iterative_solver_data;
162};
163
164} // namespace Elementwise
165} // namespace ExaDG
166
167#endif /* INCLUDE_EXADG_SOLVERS_AND_PRECONDITIONERS_SOLVERS_WRAPPER_ELEMENTWISE_SOLVERS_H_ \
168 */
Definition wrapper_elementwise_solvers.h:61
unsigned int solve(VectorType &dst, VectorType const &src) const override
Definition wrapper_elementwise_solvers.h:91
Definition elementwise_krylov_solvers.h:231
Definition elementwise_krylov_solvers.h:356
Definition iterative_solvers_dealii_wrapper.h:40
Definition driver.cpp:33
Definition wrapper_elementwise_solvers.h:44
Definition solver_data.h:34