FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
symmetric_lumped_schur_matrix.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
10
11namespace FEAT
12{
13 namespace Global
14 {
42 template
43 <
44 typename LumpedMatrixA_,
45 typename MatrixB_,
46 typename MatrixD_,
47 typename FilterA_
48 >
50 {
51 public:
53 typedef LumpedMatrixA_ LumpedMatrixTypeA;
55 typedef MatrixB_ MatrixTypeB;
57 typedef MatrixD_ MatrixTypeD;
59 typedef FilterA_ FilterTypeA;
60
62 typedef typename LumpedMatrixA_::DataType DataType;
64 typedef typename MatrixD_::VectorTypeL VectorTypeL;
66 typedef typename MatrixB_::VectorTypeR VectorTypeR;
67
69 typedef LumpedMatrixA_ VectorTypeML;
71 typedef LumpedMatrixA_ VectorTypeMR;
72
74 typedef typename MatrixD_::GateRowType GateRowType;
76 typedef typename MatrixB_::GateColType GateColType;
77
78 static constexpr bool is_global = true;
79 static constexpr bool is_local = false;
80
82 LumpedMatrixA_ inv_lumped_matrix_a;
84 const MatrixB_& matrix_b;
86 const MatrixD_& matrix_d;
88 const FilterA_& filter_a;
89
90 private:
91 // These two need to be modified even when apply() (which is const) is called
96
97 public:
114 const LumpedMatrixA_& lumped_matrix_a_,
115 const MatrixB_& matrix_b_,
116 const MatrixD_& matrix_d_,
117 const FilterA_& filter_a_) :
118 inv_lumped_matrix_a(lumped_matrix_a_.clone(LAFEM::CloneMode::Layout)),
119 matrix_b(matrix_b_),
120 matrix_d(matrix_d_),
121 filter_a(filter_a_),
122 _vec_ml(lumped_matrix_a_.clone(LAFEM::CloneMode::Layout)),
123 _vec_mr(lumped_matrix_a_.clone(LAFEM::CloneMode::Layout))
124 {
125 ASSERT(matrix_d.columns() == matrix_b.rows());
126 ASSERT(matrix_d.used_elements() == matrix_b.used_elements());
127
128 inv_lumped_matrix_a.component_invert(lumped_matrix_a_);
129 }
130
135 {
136 }
137
138 const Dist::Comm* get_comm() const
139 {
140 return inv_lumped_matrix_a.get_comm();
141 }
142
143 void update_lumped_a(const LumpedMatrixA_& lumped_matrix_a_)
144 {
145 // If these were initialized empty (as it frequently happens with Global containers), adjust the sizes
146 if(_vec_ml.local().size() == Index(0))
147 {
148 _vec_ml.local().clone(lumped_matrix_a_.local(), LAFEM::CloneMode::Layout);
149 }
150 if(_vec_mr.local().size() == Index(0))
151 {
152 _vec_mr.local().clone(lumped_matrix_a_.local(), LAFEM::CloneMode::Layout);
153 }
154 if(inv_lumped_matrix_a.local().size() == Index(0))
155 {
156 inv_lumped_matrix_a.local().clone(lumped_matrix_a_.local(), LAFEM::CloneMode::Layout);
157 }
158
159 inv_lumped_matrix_a.component_invert(lumped_matrix_a_);
160
161 }
162
172 {
173 return SymmetricSchurMatrix(inv_lumped_matrix_a.clone(mode), matrix_b.clone(mode), matrix_d.clone(mode),
174 filter_a.clone(mode));
175 }
176
183 {
184 return matrix_d.create_vector_l();
185 }
186
193 {
194 return matrix_b.create_vector_r();
195 }
196
206 {
207 return matrix_b.columns();
208 }
209
218 Index rows() const
219 {
220 return matrix_d.columns();
221 }
222
231 {
232 return inv_lumped_matrix_a.used_elements() + matrix_b.used_elements() + matrix_d.used_elements();
233 }
234
236 std::size_t bytes() const
237 {
238 return _vec_ml.bytes() + _vec_mr.bytes();
239 }
240
255 void extract_diag(VectorTypeL& diag, bool sync=true) const
256 {
257 // If we have a gate and it contains neighbors, we have to do it the complicated way
258 if(diag.get_gate() != nullptr && !diag.get_gate()->_ranks.empty() )
259 {
260 diag.format();
261
262 typename MatrixB_::LocalMatrixType matrix_b1(matrix_b.convert_to_1());
263
264 matrix_b1.add_trace_double_mat_mult(diag.local(), matrix_d.local(), inv_lumped_matrix_a.local(), DataType(1));
265 }
266 else
267 {
268 matrix_d.local().row_norm2sqr(diag.local(), inv_lumped_matrix_a.local());
269 }
270
271 if(sync)
272 {
273 diag.sync_0();
274 }
275
276 }
277
287 void apply(VectorTypeL& r, const VectorTypeR& x) const
288 {
289 matrix_b.apply(_vec_mr, x);
290
291 filter_a.filter_def(_vec_mr);
292 _vec_ml.component_product(_vec_mr, inv_lumped_matrix_a);
293 filter_a.filter_cor(_vec_ml);
294
295 matrix_d.apply(r, _vec_ml);
296 }
297
307 void preproc_rhs(VectorTypeML& r, const VectorTypeMR& x) const
308 {
309 _vec_mr.copy(x);
310 filter_a.filter_def(_vec_mr);
311 _vec_ml.component_product(_vec_mr, inv_lumped_matrix_a);
312 filter_a.filter_cor(_vec_ml);
313
314 matrix_d.apply(r, _vec_ml);
315 }
316
332 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, const DataType alpha = DataType(1)) const
333 {
334 // r <- y + alpha*(D A^(-1) B)*x
335 matrix_b.apply(_vec_mr, x);
336
337 filter_a.filter_def(_vec_mr);
338 _vec_ml.component_product(_vec_mr, inv_lumped_matrix_a);
339 filter_a.filter_cor(_vec_ml);
340
341 matrix_d.apply(r, _vec_ml, y, alpha);
342 }
343
344 //LocalMatrix convert_to_1() const
345 //{
346 // LocalMatrix locmat = _matrix.clone(LAFEM::CloneMode::Weak);
347 // if((_row_gate != nullptr) && (_col_gate != nullptr))
348 // synch_matrix(locmat, *_row_gate->_comm, _row_gate->_ranks, _row_gate->_mirrors, _col_gate->_mirrors);
349 // return locmat;
350 //}
351
352 }; // class SymmetricLumpedSchurMatrix<...>
353 } // namespace Global
354} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
FEAT Kernel base header.
Communicator class.
Definition: dist.hpp:1349
Symmetric lumped Schur complement matrix.
std::size_t bytes() const
Returns the total amount of bytes allocated.
VectorTypeL create_vector_l() const
Returns a left-vector.
void apply(VectorTypeL &r, const VectorTypeR &x, const VectorTypeL &y, const DataType alpha=DataType(1)) const
Calculate .
SymmetricLumpedSchurMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Clone operation.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Calculate .
void extract_diag(VectorTypeL &diag, bool sync=true) const
Extracts the diagonal.
MatrixB_::GateColType GateColType
The column-gate type (used by SFINAE)
MatrixB_::VectorTypeR VectorTypeR
The vector for right-multiplication with S.
VectorTypeML _vec_ml
Buffer vector for receiving v <- x^T A.
MatrixD_::GateRowType GateRowType
The row-gate type (used by SFINAE)
Index columns() const
Gets the total number of columns in this matrix.
VectorTypeR create_vector_r() const
Returns a right-vector.
VectorTypeMR _vec_mr
Buffer vector for receiving v <- A x.
SymmetricLumpedSchurMatrix(const LumpedMatrixA_ &lumped_matrix_a_, const MatrixB_ &matrix_b_, const MatrixD_ &matrix_d_, const FilterA_ &filter_a_)
Constructor.
void preproc_rhs(VectorTypeML &r, const VectorTypeMR &x) const
Calculate .
LumpedMatrixA_ LumpedMatrixTypeA
The type of A = diag(a)
MatrixD_::VectorTypeL VectorTypeL
The vector for left-multiplication with S.
Index used_elements() const
Returns the total number of non-zeros in this matrix.
LumpedMatrixA_::DataType DataType
The floating point precision.
LumpedMatrixA_ VectorTypeML
The left-vector type for A.
Index rows() const
Gets the total number of rows in this matrix.
LumpedMatrixA_ VectorTypeMR
The right-vector type for A.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.