Loading...
Searching...
No Matches
block_preconditioner_2x2.hpp
Go to the documentation of this file.
1#pragma once
2
6
8
9/// @brief Block-diagonal preconditioner for 2x2 block operators.
10///
11/// Satisfies the SolverLike concept (see solver.hpp).
12/// Applies separate preconditioners to the (1,1) and (2,2) blocks.
13/// The block-diagonal preconditioner solves:
14/// \f[
15/// \begin{pmatrix}
16/// P_{11} & 0 \\
17/// 0 & P_{22}
18/// \end{pmatrix}
19/// \begin{pmatrix}
20/// x_1 \\ x_2
21/// \end{pmatrix}
22/// =
23/// \begin{pmatrix}
24/// b_1 \\ b_2
25/// \end{pmatrix}
26/// \f]
27/// where \f$ P_{11} \f$ and \f$ P_{22} \f$ are preconditioners for the (1,1) and (2,2) blocks, respectively.
28/// @tparam OperatorT Operator type (must satisfy Block2x2OperatorLike).
29/// @tparam Block11T Type of the (1,1) operator of the preconditioner to be (approximately) inverted
30/// @tparam Block22T Type of the (2,2) operator of the preconditioner to be (approximately) inverted
31/// @tparam Block11Preconditioner Preconditioner for the (1,1) block (must satisfy SolverLike).
32/// @tparam Block22Preconditioner Preconditioner for the (2,2) block (must satisfy SolverLike).
33template <
34 Block2x2OperatorLike OperatorT,
35 OperatorLike Block11T,
36 OperatorLike Block22T,
37 SolverLike Block11Preconditioner,
38 SolverLike Block22Preconditioner >
40{
41 public:
42 /// @brief Operator type to be solved.
43 using OperatorType = OperatorT;
44 /// @brief Solution vector type (must be Block2VectorLike).
46 /// @brief Right-hand side vector type (must be Block2VectorLike).
48
49 /// @brief Static assertions to ensure block vector types.
50 static_assert(
52 "The solution vector of the BlockPreconditioner2x2 must be Block2VectorLike." );
53 static_assert(
55 "The RHS vector of the BlockPreconditioner2x2 must be Block2VectorLike." );
56
57 static_assert( std::is_same_v< SrcOf< Block11T >, typename SrcOf< OperatorT >::Block1Type > );
58 static_assert( std::is_same_v< SrcOf< Block22T >, typename SrcOf< OperatorT >::Block2Type > );
59
60 static_assert( std::is_same_v< DstOf< Block11T >, typename DstOf< OperatorT >::Block1Type > );
61 static_assert( std::is_same_v< DstOf< Block22T >, typename DstOf< OperatorT >::Block2Type > );
62
63 /// @brief Construct a block-diagonal preconditioner with given block preconditioners.
64 ///
65 /// When calling solve( A, x, b ) with this preconditioner, the two passed solvers are applied to the two block
66 /// passed in the constructor here. This does NOT use the (1, 1) and (2, 2) blocks of the A block in the solve()
67 /// call.
68 ///
69 /// @param block11 The (1, 1) block to approximate the inverse to.
70 /// @param block22 The (2, 2) block to approximate the inverse to.
71 /// @param block11_preconditioner Preconditioner for the (1,1) block.
72 /// @param block22_preconditioner Preconditioner for the (2,2) block.
74 const Block11T& block11,
75 const Block22T& block22,
76 const Block11Preconditioner& block11_preconditioner,
77 const Block22Preconditioner& block22_preconditioner )
78 : block11_( block11 )
79 , block22_( block22 )
80 , block11_preconditioner_( block11_preconditioner )
81 , block22_preconditioner_( block22_preconditioner )
82 {}
83
84 /// @brief Solve the block-diagonal preconditioner system.
85 ///
86 /// Applies the block11 and block22 preconditioners to the respective blocks.
87 ///
88 /// @param A Is ignored. The two solvers are applied to the operators passed in the constructor.
89 /// @param x Solution block vector (output).
90 /// @param b Right-hand side block vector (input).
92 {
93 solve( block11_preconditioner_, block11_, x.block_1(), b.block_1() );
94 solve( block22_preconditioner_, block22_, x.block_2(), b.block_2() );
95 }
96
97 private:
98 Block11T block11_; ///< (1,1) block of operator.
99 Block22T block22_; ///< (2,2) block of operator.
100
101 Block11Preconditioner block11_preconditioner_; ///< Preconditioner for (1,1) block.
102 Block22Preconditioner block22_preconditioner_; ///< Preconditioner for (2,2) block.
103};
104
105/// @brief Static assertion: BlockDiagonalPreconditioner2x2 satisfies SolverLike concept.
106static_assert( SolverLike< BlockDiagonalPreconditioner2x2<
110 detail::DummySolver< linalg::detail::DummyConcreteBlock2x2Operator::Block11Type >,
111 detail::DummySolver< linalg::detail::DummyConcreteBlock2x2Operator::Block22Type > > > );
112
113/// @brief Block-triangular preconditioner for 2x2 block operators.
114///
115/// Satisfies the SolverLike concept (see solver.hpp).
116/// Applies separate preconditioners to the (1,1) and (2,2) blocks.
117/// The block-triangular preconditioner solves:
118/// \f[
119/// \begin{pmatrix}
120/// P_{11} & B^T \\
121/// 0 & P_{22}
122/// \end{pmatrix}
123/// \begin{pmatrix}
124/// x_1 \\ x_2
125/// \end{pmatrix}
126/// =
127/// \begin{pmatrix}
128/// b_1 \\ b_2
129/// \end{pmatrix}
130/// \f]
131/// where \f$ P_{11} \f$ and \f$ P_{22} \f$ are preconditioners for the (1,1) and (2,2) blocks, respectively.
132/// @tparam OperatorT Operator type (must satisfy Block2x2OperatorLike).
133/// @tparam Block11T Type of the (1,1) operator of the preconditioner to be (approximately) inverted
134/// @tparam Block22T Type of the (2,2) operator of the preconditioner to be (approximately) inverted
135/// @tparam Block12T Type of the (1,2) operator of the preconditioner/Stokes operator, the gradient block
136/// @tparam Block11Preconditioner Preconditioner for the (1,1) block (must satisfy SolverLike).
137/// @tparam Block22Preconditioner Preconditioner for the (2,2) block (must satisfy SolverLike).
138template <
139 Block2x2OperatorLike OperatorT,
140 OperatorLike Block11T,
141 OperatorLike Block22T,
142 OperatorLike Block12T,
143 SolverLike Block11Preconditioner,
144 SolverLike Block22Preconditioner >
146{
147 public:
148 /// @brief Operator type to be solved.
149 using OperatorType = OperatorT;
150 /// @brief Solution vector type (must be Block2VectorLike).
152 /// @brief Right-hand side vector type (must be Block2VectorLike).
154
155 /// @brief Static assertions to ensure block vector types.
156 static_assert(
158 "The solution vector of the BlockPreconditioner2x2 must be Block2VectorLike." );
159 static_assert(
161 "The RHS vector of the BlockPreconditioner2x2 must be Block2VectorLike." );
162
163 static_assert( std::is_same_v< SrcOf< Block11T >, typename SrcOf< OperatorT >::Block1Type > );
164 static_assert( std::is_same_v< SrcOf< Block22T >, typename SrcOf< OperatorT >::Block2Type > );
165
166 static_assert( std::is_same_v< DstOf< Block11T >, typename DstOf< OperatorT >::Block1Type > );
167 static_assert( std::is_same_v< DstOf< Block22T >, typename DstOf< OperatorT >::Block2Type > );
168
169 /// @brief Construct a block-triangular preconditioner with given block preconditioners and the gradient block.
170 ///
171 /// When calling solve( A, x, b ) with this preconditioner, the two passed solvers are applied to the two block
172 /// passed in the constructor here. This does NOT use the (1, 1) and (2, 2) blocks of the A block in the solve()
173 /// call.
174 ///
175 /// @param block11 The (1, 1) block to approximate the inverse to.
176 /// @param block22 The (2, 2) block to approximate the inverse to.
177 /// @param block12 The (1, 2) gradient block.
178 /// @param block11_preconditioner Preconditioner for the (1,1) block.
179 /// @param block22_preconditioner Preconditioner for the (2,2) block.
181 const Block11T& block11,
182 const Block22T& block22,
183 const Block12T& block12,
185 const Block11Preconditioner& block11_preconditioner,
186 const Block22Preconditioner& block22_preconditioner )
187 : block11_( block11 )
188 , block22_( block22 )
189 , block12_( block12 )
190 , tmp_( tmp )
191 , block11_preconditioner_( block11_preconditioner )
192 , block22_preconditioner_( block22_preconditioner )
193 {}
194
195 /// @brief Solve the block-triangular preconditioner system by block-backward substitution.
196 ///
197 /// First, solve for the pressure block (second block row) by applying the schur preconditioner.
198 /// Backward substitute the result into the first block row, multiply by 12/gradient block.
199 /// Obtain the velocity solution by solving the 11 block/applying the velocity preconditioner.
200 /// The Schur complement has a negative sign which is implemented in between.
201 ///
202 /// @param A Is ignored. The two solvers are applied to the operators passed in the constructor.
203 /// @param x Solution block vector (output).
204 /// @param b Right-hand side block vector (input).
206 {
207 // solve schur op
208 solve( block22_preconditioner_, block22_, x.block_2(), b.block_2() );
209
210 // apply gradient op / 12Block to schur-preconditioned pressure
211 apply( block12_, x.block_2(), tmp_.block_1() );
212
213 // compute velocity residual
214 lincomb( tmp_.block_1(), { 1, 1 }, { tmp_.block_1(), b.block_1() } );
215
216 // schur comp has negative sign
217 lincomb( x.block_2(), { -1 }, { x.block_2() } );
218
219 // apply velocity preconditioner
220 solve( block11_preconditioner_, block11_, x.block_1(), tmp_.block_1() );
221 }
222
223 private:
224 Block11T block11_; ///< (1,1) block of operator.
225 Block22T block22_; ///< (2,2) block of operator.
226 Block12T block12_; ///< (1,2) block of operator.
227
229
230 Block11Preconditioner block11_preconditioner_; ///< Preconditioner for (1,1) block.
231 Block22Preconditioner block22_preconditioner_; ///< Preconditioner for (2,2) block.
232};
233
234/// @brief Static assertion: BlockDiagonalPreconditioner2x2 satisfies SolverLike concept.
235static_assert( SolverLike< BlockTriangularPreconditioner2x2<
240 detail::DummySolver< linalg::detail::DummyConcreteBlock2x2Operator::Block11Type >,
241 detail::DummySolver< linalg::detail::DummyConcreteBlock2x2Operator::Block22Type > > > );
242} // namespace terra::linalg::solvers
Dummy block 2x2 operator for concept checks. Contains four DummyConcreteOperator blocks.
Definition operator.hpp:203
DummyConcreteOperator Block22Type
Definition operator.hpp:211
DummyConcreteOperator Block12Type
Definition operator.hpp:209
DummyConcreteOperator Block11Type
Definition operator.hpp:208
Block-diagonal preconditioner for 2x2 block operators.
Definition block_preconditioner_2x2.hpp:40
OperatorT OperatorType
Operator type to be solved.
Definition block_preconditioner_2x2.hpp:43
void solve_impl(OperatorType &A, SolutionVectorType &x, const RHSVectorType &b)
Solve the block-diagonal preconditioner system.
Definition block_preconditioner_2x2.hpp:91
SrcOf< OperatorType > SolutionVectorType
Solution vector type (must be Block2VectorLike).
Definition block_preconditioner_2x2.hpp:45
BlockDiagonalPreconditioner2x2(const Block11T &block11, const Block22T &block22, const Block11Preconditioner &block11_preconditioner, const Block22Preconditioner &block22_preconditioner)
Static assertions to ensure block vector types.
Definition block_preconditioner_2x2.hpp:73
DstOf< OperatorType > RHSVectorType
Right-hand side vector type (must be Block2VectorLike).
Definition block_preconditioner_2x2.hpp:47
Static assertion: BlockDiagonalPreconditioner2x2 satisfies SolverLike concept.
Definition block_preconditioner_2x2.hpp:146
SrcOf< OperatorType > SolutionVectorType
Solution vector type (must be Block2VectorLike).
Definition block_preconditioner_2x2.hpp:151
void solve_impl(OperatorType &A, SolutionVectorType &x, const RHSVectorType &b)
Solve the block-triangular preconditioner system by block-backward substitution.
Definition block_preconditioner_2x2.hpp:205
DstOf< OperatorType > RHSVectorType
Right-hand side vector type (must be Block2VectorLike).
Definition block_preconditioner_2x2.hpp:153
BlockTriangularPreconditioner2x2(const Block11T &block11, const Block22T &block22, const Block12T &block12, SolutionVectorType &tmp, const Block11Preconditioner &block11_preconditioner, const Block22Preconditioner &block22_preconditioner)
Static assertions to ensure block vector types.
Definition block_preconditioner_2x2.hpp:180
OperatorT OperatorType
Operator type to be solved.
Definition block_preconditioner_2x2.hpp:149
Concept for types that behave like block 2-vectors. Extends VectorLike and requires block types and a...
Definition vector.hpp:47
Concept for types that behave like block 2x2 operators. Extends OperatorLike and requires block types...
Definition operator.hpp:117
Concept for types that behave like linear operators.
Definition operator.hpp:57
Concept for types that behave like linear solvers. Requires exposing OperatorType and a solve_impl me...
Definition solver.hpp:19
Definition block_preconditioner_2x2.hpp:7
void solve(Solver &solver, Operator &A, SolutionVector &x, const RHSVector &b)
Solve a linear system using the given solver and operator. Calls the solver's solve_impl method.
Definition solver.hpp:51
void lincomb(Vector &y, const std::vector< ScalarOf< Vector > > &c, const std::vector< Vector > &x, const ScalarOf< Vector > &c0)
Compute a linear combination of vectors. Implements: .
Definition vector.hpp:72
Operator::SrcVectorType SrcOf
Alias for the source vector type of an operator.
Definition operator.hpp:145
void apply(LinearForm &L, typename LinearForm::DstVectorType &dst)
Apply a linear form and write to a destination vector.
Definition linear_form.hpp:37
Operator::DstVectorType DstOf
Alias for the destination vector type of an operator.
Definition operator.hpp:149