FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter.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
8// includes, FEAT
10#include <kernel/lafem/sparse_matrix_csr.hpp>
11#include <kernel/lafem/sparse_matrix_bcsr.hpp>
12#include <kernel/lafem/dense_vector.hpp>
13#include <kernel/lafem/sparse_vector.hpp>
14#include <kernel/lafem/arch/unit_filter.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
25 template<
26 typename DT_,
27 typename IT_ = Index>
29 {
30 public:
32 typedef DT_ DataType;
34 typedef IT_ IndexType;
35
38
40 template <typename DT2_ = DT_, typename IT2_ = IT_>
42
44 template <typename DataType2_, typename IndexType2_>
46
47 static constexpr bool is_global = false;
48 static constexpr bool is_local = true;
49
50 private:
53
54 public:
57 _sv()
58 {
59 }
60
67 explicit UnitFilter(Index size_in) :
68 _sv(size_in)
69 {
70 }
71
79 explicit UnitFilter(Index size_in, DenseVector<DT_, IT_> & values, DenseVector<IT_, IT_> & indices) :
80 _sv(size_in, values, indices)
81 {
82 XASSERTM(values.size() == indices.size(), "Vector size mismatch!");
83 }
84
87 _sv(std::move(other._sv))
88 {
89 }
90
93 {
94 if(this != &other)
95 {
96 _sv = std::forward<decltype(other._sv)>(other._sv);
97 }
98 return *this;
99 }
100
102 virtual ~UnitFilter()
103 {
104 }
105
108 {
109 UnitFilter other;
110 other.clone(*this, clone_mode);
111 return other;
112 }
113
115 void clone(const UnitFilter & other, CloneMode clone_mode = CloneMode::Deep)
116 {
117 _sv.clone(other.get_filter_vector(), clone_mode);
118 }
119
121 template<typename DT2_, typename IT2_>
123 {
124 _sv.convert(other.get_filter_vector());
125 }
126
128 void clear()
129 {
130 _sv.clear();
131 }
132
134 std::size_t bytes() const
135 {
136 return _sv.bytes();
137 }
138
140 SparseVector<DT_, IT_>& get_filter_vector()
141 {
142 return _sv;
143 }
144
145 const SparseVector<DT_, IT_>& get_filter_vector() const
146 {
147 return _sv;
148 }
150
158 void add(IndexType idx, DataType val)
159 {
160 _sv(idx, val);
161 }
162
164 Index size() const
165 {
166 return _sv.size();
167 }
168
171 {
172 return _sv.used_elements();
173 }
174
177 {
178 return _sv.indices();
179 }
180
182 const IT_* get_indices() const
183 {
184 return _sv.indices();
185 }
186
189 {
190 return _sv.elements();
191 }
192
194 const DT_* get_values() const
195 {
196 return _sv.elements();
197 }
198
201 {
202 _sv.permute(perm);
203 }
204
205#ifdef DOXYGEN
206 // The following documentation block is visible to Doxygen only. The actual implementation is matrix type
207 // specific and provided below.
208
216 void filter_mat(MatrixType & matrix) const
217 {
218 }
219
227 void filter_offdiag_row_mat(MatrixType & matrix) const
228 {
229 }
230
238 void filter_offdiag_col_mat(MatrixType & matrix) const
239 {
240 }
241
242#endif
244 void filter_mat(SparseMatrixCSR<DT_, IT_> & matrix) const
245 {
246 if(_sv.used_elements() == Index(0))
247 return;
248
249 XASSERTM(_sv.size() == matrix.rows(), "Matrix size does not match!");
250
251 const IndexType* row_ptr(matrix.row_ptr());
252 const IndexType* col_idx(matrix.col_ind());
253 Arch::UnitFilter::filter_unit_mat(matrix.val(), row_ptr, col_idx, _sv.indices(), _sv.used_elements());
254 }
255
256 void filter_offdiag_row_mat(SparseMatrixCSR<DT_, IT_> & matrix) const
257 {
258 if(_sv.used_elements() == Index(0))
259 return;
260
261 XASSERTM(_sv.size() == matrix.rows(), "Matrix size does not match!");
262
263 const IndexType* row_ptr(matrix.row_ptr());
264 Arch::UnitFilter::filter_offdiag_row_mat(matrix.val(), row_ptr, 1, _sv.indices(), _sv.used_elements());
265 }
266
267 void filter_offdiag_col_mat(SparseMatrixCSR<DT_, IT_> &) const
268 {
269 // nothing to do here
270 }
271
272 template<int block_width_>
273 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, 1, block_width_> & matrix) const
274 {
275 if(_sv.used_elements() == Index(0))
276 return;
277
278 XASSERTM(_sv.size() == matrix.rows(), "Matrix size does not match!");
279
280 const IndexType* row_ptr(matrix.row_ptr());
281 Arch::UnitFilter::filter_offdiag_row_mat(matrix.template val<Perspective::pod>(), row_ptr, block_width_, _sv.indices(), _sv.used_elements());
282 }
283
284 template<int block_height_>
285 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, block_height_, 1> &) const
286 {
287 // nothing to do here
288 }
290
307 {
308 if(_sv.used_elements() == Index(0))
309 return;
310
311 XASSERTM(_sv.size() == matrix_a.rows(), "Matrix size does not match!");
312 XASSERTM(_sv.size() == matrix_m.rows(), "Matrix size does not match!");
313
314 const IndexType* row_ptr(matrix_a.row_ptr());
315 const IndexType* col_idx(matrix_m.col_ind());
316 XASSERTM(row_ptr == matrix_m.row_ptr(), "matrix A and M must share their layout");
317 XASSERTM(col_idx == matrix_m.col_ind(), "matrix A and M must share their layout");
318
319 DT_* val_a(matrix_a.val());
320 const DT_* val_m(matrix_m.val());
321
322 Arch::UnitFilter::filter_weak_matrix_rows(val_a, val_m, row_ptr, get_values(), get_indices(), _sv.used_elements());
323 }
324
325
333 {
334 if(_sv.used_elements() == Index(0))
335 return;
336 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
337 Arch::UnitFilter::filter_rhs(vector.elements(), _sv.elements(), _sv.indices(), _sv.used_elements());
338 }
339
347 {
348 // same as rhs
349 filter_rhs(vector);
350 }
351
359 {
360 if(_sv.used_elements() == Index(0))
361 return;
362 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
363 Arch::UnitFilter::filter_def(vector.elements(), _sv.indices(), _sv.used_elements());
364 }
365
373 {
374 // same as def
375 filter_def(vector);
376 }
377 }; // class UnitFilter<...>
378 } // namespace LAFEM
379} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Index size() const
Returns the containers size.
Definition: container.hpp:1136
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
CSR based sparse matrix.
IT_ * col_ind()
Retrieve column indices array.
DT_ * val()
Retrieve non zero element array.
Index rows() const
Retrieve matrix row count.
IT_ * row_ptr()
Retrieve row start index array.
Sparse vector class template.
Unit Filter class template.
Definition: unit_filter.hpp:29
const DT_ * get_values() const
UnitFilter clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
UnitFilter()
default constructor
Definition: unit_filter.hpp:56
void clone(const UnitFilter &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another UnitFilter.
DenseVector< DataType, IndexType > VectorType
our supported vector type
Definition: unit_filter.hpp:37
void permute(Adjacency::Permutation &perm)
Permutate internal vector according to the given Permutation.
SparseVector< DT_, IT_ > _sv
SparseVector, containing all entries of the unit filter.
Definition: unit_filter.hpp:52
void filter_mat(MatrixType &matrix) const
Applies the filter onto a system matrix.
const IT_ * get_indices() const
void filter_weak_matrix_rows(SparseMatrixCSR< DT_, IT_ > &matrix_a, const SparseMatrixCSR< DT_, IT_ > &matrix_m) const
Replaces the rows of the system matrix by scaled rows of another matrix.
void filter_def(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto a defect vector.
void filter_cor(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto a correction vector.
UnitFilter(Index size_in, DenseVector< DT_, IT_ > &values, DenseVector< IT_, IT_ > &indices)
Constructor.
Definition: unit_filter.hpp:79
void filter_offdiag_col_mat(MatrixType &matrix) const
Filter the non-diagonal entries, column wise.
void filter_offdiag_row_mat(MatrixType &matrix) const
Filter the non-diagonal entries, row wise.
UnitFilter & operator=(UnitFilter &&other)
move-assignment operator
Definition: unit_filter.hpp:92
void filter_rhs(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto the right-hand-side vector.
void convert(const UnitFilter< DT2_, IT2_ > &other)
Converts data from another UnitFilter.
Index used_elements() const
virtual ~UnitFilter()
virtual destructor
std::size_t bytes() const
Returns the total amount of bytes allocated.
void filter_sol(DenseVector< DT_, IT_ > &vector) const
Applies the filter onto the solution vector.
UnitFilter(UnitFilter &&other)
move-ctor
Definition: unit_filter.hpp:86
UnitFilter(Index size_in)
Constructor.
Definition: unit_filter.hpp:67
void add(IndexType idx, DataType val)
Adds one element to the filter.
DT_ DataType
data-type typedef
Definition: unit_filter.hpp:32
IT_ IndexType
index-type typedef
Definition: unit_filter.hpp:34
void clear()
Clears the underlying data (namely the SparseVector)
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.