FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
unit_filter_blocked.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/util/math.hpp>
11#include <kernel/lafem/sparse_matrix_bcsr.hpp>
12#include <kernel/lafem/dense_vector_blocked.hpp>
13#include <kernel/lafem/sparse_vector_blocked.hpp>
14#include <kernel/lafem/arch/unit_filter_blocked.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
43 template<
44 typename DT_,
45 typename IT_,
46 int BlockSize_>
48 {
49 public:
51 typedef DT_ DataType;
53 typedef IT_ IndexType;
55 static constexpr int BlockSize = BlockSize_;
60
62 template <typename DT2_ = DT_, typename IT2_ = IT_>
64
66 template <typename DataType2_, typename IndexType2_>
68
69 static constexpr bool is_global = false;
70 static constexpr bool is_local = true;
71
72 static_assert(BlockSize > 1, "BlockSize has to be >= 2 in UnitFilterBlocked!");
73
74 private:
77
80
81 public:
84 _sv(),
85 _ignore_nans(false)
86 {
87 }
88
98 explicit UnitFilterBlocked(Index num_entries, bool ignore_nans = false) :
99 _sv(num_entries),
100 _ignore_nans(ignore_nans)
101 {
102 }
103
111 explicit UnitFilterBlocked(Index size_in,
113 DenseVector<IT_, IT_> & indices, bool ignore_nans = false) :
114 _sv(size_in, values, indices),
115 _ignore_nans(ignore_nans)
116 {
117 XASSERTM(values.size() == indices.size(), "Vector size mismatch!");
118 }
119
122 _sv(std::move(other._sv)),
124 {
125 }
126
129 {
130 if(this != &other)
131 {
132 _sv = std::forward<decltype(other._sv)>(other._sv);
133 _ignore_nans = other._ignore_nans;
134 }
135 return *this;
136 }
137
140 {
141 }
142
145 {
146 UnitFilterBlocked other;
147 other.clone(*this, clone_mode);
148 return other;
149 }
150
152 void clone(const UnitFilterBlocked & other, CloneMode clone_mode = CloneMode::Deep)
153 {
154 _sv.clone(other.get_filter_vector(), clone_mode);
155 _ignore_nans = other.get_ignore_nans();
156 }
157
159 template<typename DT2_, typename IT2_, int BS_>
161 {
162 _sv.convert(other.get_filter_vector());
163 _ignore_nans = other.get_ignore_nans();
164 }
165
167 void clear()
168 {
169 _sv.clear();
170 }
171
173 std::size_t bytes() const
174 {
175 return _sv.bytes();
176 }
177
180 {
181 return _sv;
182 }
183 const SparseVectorBlocked<DT_, IT_, BlockSize>& get_filter_vector() const
184 {
185 return _sv;
186 }
188
195 void set_ignore_nans(bool ignore_nans)
196 {
197 _ignore_nans = ignore_nans;
198 }
199
201 bool get_ignore_nans() const
202 {
203 return _ignore_nans;
204 }
205
213 void add(IndexType idx, ValueType val)
214 {
215 _sv(idx, val);
216 }
217
219 Index size() const
220 {
221 return _sv.size();
222 }
223
226 {
227 return _sv.used_elements();
228 }
229
232 {
233 return _sv.indices();
234 }
235
237 const IT_* get_indices() const
238 {
239 return _sv.indices();
240 }
241
244 {
245 return _sv.elements();
246 }
247
249 const ValueType* get_values() const
250 {
251 return _sv.elements();
252 }
253
256 {
257 _sv.permute(perm);
258 }
259
260#ifdef DOXYGEN
261 // The following documentation block is visible to Doxygen only. The actual implementation is matrix type
262 // specific and provided below.
263
277 void filter_mat(MatrixType & matrix) const
278 {
279 }
280
294 void filter_offdiag_row_mat(MatrixType & matrix) const
295 {
296 }
297
311 void filter_offdiag_col_mat(MatrixType & matrix) const
312 {
313 }
314
315#endif
317 template<int BlockWidth_>
319 {
320 if(_sv.used_elements() == Index(0))
321 return;
322
323 XASSERTM(_sv.size() == matrix.rows(), "Matrix size does not match!");
324
325 Arch::UnitFilterBlocked::filter_unit_mat
326 (matrix.template val<LAFEM::Perspective::pod>(), matrix.row_ptr(), matrix.col_ind(), BlockSize_, BlockWidth_,
327 _sv.template elements<LAFEM::Perspective::pod>(), _sv.indices(), _sv.used_elements(), _ignore_nans);
328 }
329
330 template<int BlockWidth_>
331 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, BlockSize_, BlockWidth_> & matrix) const
332 {
333 if(_sv.used_elements() == Index(0))
334 return;
335
336 XASSERTM(_sv.size() == matrix.rows(), "Matrix size does not match!");
337
338 Arch::UnitFilterBlocked::filter_offdiag_row_mat
339 (matrix.template val<LAFEM::Perspective::pod>(), matrix.row_ptr(), BlockSize_, BlockWidth_,
340 _sv.template elements<LAFEM::Perspective::pod>(), _sv.indices(), _sv.used_elements(), _ignore_nans);
341 }
342
343 template<int BlockWidth_>
344 void filter_offdiag_col_mat(SparseMatrixBCSR<DT_, IT_, BlockSize_, BlockWidth_> &) const
345 {
346 // nothing to do here
347 }
349
350
366 template<int BlockWidth_>
369 {
370 if(_sv.used_elements() == Index(0))
371 return;
372
373 if(matrix_a.val() == matrix_m.val())
374 {
375 XABORTM("Matrices are not allowed to hold the same data");
376 }
377
378 XASSERTM(_sv.size() == matrix_a.rows(), "Matrix size does not match!");
379 XASSERTM(_sv.size() == matrix_m.rows(), "Matrix size does not match!");
380
381 const IndexType* row_ptr(matrix_a.row_ptr());
382 const IndexType* col_idx(matrix_m.col_ind());
383 XASSERTM(row_ptr == matrix_m.row_ptr(), "matrix A and M must share their layout");
384 XASSERTM(col_idx == matrix_m.col_ind(), "matrix A and M must share their layout");
385
386 Arch::UnitFilterBlocked::filter_weak_matrix_rows
387 (matrix_a.template val<LAFEM::Perspective::pod>(), matrix_m.template val<LAFEM::Perspective::pod>(), row_ptr, BlockSize_, BlockWidth_,
388 _sv.template elements<LAFEM::Perspective::pod>(), _sv.indices(), _sv.used_elements());
389 }
390
391
398 void filter_rhs(VectorType& vector) const
399 {
400 if(_sv.used_elements() == Index(0))
401 return;
402
403 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
404 Arch::UnitFilterBlocked::filter_rhs
405 (vector.template elements<Perspective::pod>(), BlockSize_, _sv.template elements<Perspective::pod>(),
407 }
408
415 void filter_sol(VectorType& vector) const
416 {
417 // same as rhs
418 filter_rhs(vector);
419 }
420
427 void filter_def(VectorType& vector) const
428 {
429 if(_sv.used_elements() == Index(0))
430 return;
431
432 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
433 Arch::UnitFilterBlocked::filter_def
434 (vector.template elements<Perspective::pod>(), BlockSize_, _sv.template elements<Perspective::pod>(),
436 }
437
444 void filter_cor(VectorType& vector) const
445 {
446 // same as def
447 filter_def(vector);
448 }
449 }; // class UnitFilterBlocked<...>
450 } // namespace LAFEM
451} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
std::size_t bytes() const
Returns the total amount of bytes allocated.
Definition: container.hpp:1042
Index size() const
Returns the containers size.
Definition: container.hpp:1136
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:875
Blocked Dense data vector class template.
Index size() const
The number of elements.
Dense data vector class template.
CSR based blocked sparse matrix.
Index rows() const
Retrieve matrix row count.
IT_ * col_ind()
Retrieve column indices array.
IT_ * row_ptr()
Retrieve row start index array.
auto val() const -> const typename Intern::BCSRPerspectiveHelper< DT_, BlockHeight_, BlockWidth_, perspective_ >::Type *
Retrieve non zero element array.
Sparse vector class template.
Index size() const
The number of elements.
Index used_elements() const
Retrieve non zero element count.
void permute(Adjacency::Permutation &perm)
Permutate vector according to the given Permutation.
SparseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
void convert(const SparseVectorBlocked< DT2_, IT2_, BlockSize_ > &other)
Conversion method.
IT_ * indices()
Get a pointer to the non zero indices array.
auto elements() const -> const typename Intern::SparseVectorBlockedPerspectiveHelper< DT_, BlockSize_, perspective_ >::Type *
Retrieve a pointer to the data array.
Unit Filter Blocked class template.
std::size_t bytes() const
Returns the total amount of bytes allocated.
void filter_offdiag_col_mat(MatrixType &matrix) const
Filter the non-diagonal column entries.
void set_ignore_nans(bool ignore_nans)
Specifies whether the filter should ignore NaN filter values.
void filter_weak_matrix_rows(SparseMatrixBCSR< DT_, IT_, BlockSize_, BlockWidth_ > &matrix_a, const SparseMatrixBCSR< DT_, IT_, BlockSize_, BlockWidth_ > &matrix_m) const
Replaces the rows of the system matrix by scaled rows of another matrix.
UnitFilterBlocked(Index size_in, DenseVectorBlocked< DT_, IT_, BlockSize_ > &values, DenseVector< IT_, IT_ > &indices, bool ignore_nans=false)
Constructor.
static constexpr int BlockSize
The block size.
bool get_ignore_nans() const
Specifies whether the filter should ignore NaNs filter values.
Tiny::Vector< DataType, BlockSize > ValueType
Value type.
void clone(const UnitFilterBlocked &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another UnitFilterBlocked.
void permute(Adjacency::Permutation &perm)
Permutate internal vector according to the given Permutation.
UnitFilterBlocked(Index num_entries, bool ignore_nans=false)
Constructor.
void filter_offdiag_row_mat(MatrixType &matrix) const
Filter the non-diagonal row entries.
void clear()
Clears the underlying data (namely the SparseVector)
UnitFilterBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
void add(IndexType idx, ValueType val)
Adds one element to the filter.
DenseVectorBlocked< DataType, IndexType, BlockSize > VectorType
Our supported vector type.
UnitFilterBlocked & operator=(UnitFilterBlocked &&other)
move-assignment operator
SparseVectorBlocked< DataType, IndexType, BlockSize > _sv
SparseVector, containing all entries of the unit filter.
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
void convert(const UnitFilterBlocked< DT2_, IT2_, BS_ > &other)
Converts data from another UnitFilter.
virtual ~UnitFilterBlocked()
virtual destructor
void filter_mat(MatrixType &matrix) const
Applies the filter onto a system matrix.
bool _ignore_nans
ignore NaNs in filter values
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
void filter_def(VectorType &vector) const
Applies the filter onto a defect vector.
UnitFilterBlocked(UnitFilterBlocked &&other)
move-ctor
UnitFilterBlocked()
default constructor
const ValueType * get_values() const
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.