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_block_bcsr.hpp>
15#include <kernel/lafem/arch/unit_filter_block_vec.hpp>
16#include <kernel/lafem/arch/unit_filter_block_weak_bcsr.hpp>
17
18namespace FEAT
19{
20 namespace LAFEM
21 {
45 template<
46 typename DT_,
47 typename IT_,
48 int block_size_>
50 {
51 public:
53 typedef DT_ DataType;
55 typedef IT_ IndexType;
57 static constexpr int block_size = block_size_;
62
64 template <typename DT2_ = DT_, typename IT2_ = IT_>
66
68 template <typename DataType2_, typename IndexType2_>
70
71 static constexpr bool is_global = false;
72 static constexpr bool is_local = true;
73
74 static_assert(block_size > 1, "block_size has to be >= 2 in UnitFilterBlocked!");
75
76 private:
79
82
83 public:
86 _sv(),
87 _ignore_nans(false)
88 {
89 }
90
100 explicit UnitFilterBlocked(Index num_entries, Index num_nonzeros, bool ignore_nans = false) :
101 _sv(num_entries, num_nonzeros),
102 _ignore_nans(ignore_nans)
103 {
104 }
105
113 explicit UnitFilterBlocked(Index size_in,
115 DenseVector<IT_, IT_> & indices, bool ignore_nans = false) :
116 _sv(size_in, values, indices),
117 _ignore_nans(ignore_nans)
118 {
119 XASSERTM(values.size() == indices.size(), "Vector size mismatch!");
120 }
121
124 _sv(std::move(other._sv)),
126 {
127 }
128
131 {
132 if(this != &other)
133 {
134 _sv = std::forward<decltype(other._sv)>(other._sv);
135 _ignore_nans = other._ignore_nans;
136 }
137 return *this;
138 }
139
142 {
143 }
144
147 {
148 UnitFilterBlocked other;
149 other.clone(*this, clone_mode);
150 return other;
151 }
152
154 void clone(const UnitFilterBlocked & other, CloneMode clone_mode = CloneMode::Deep)
155 {
156 _sv.clone(other.get_filter_vector(), clone_mode);
157 _ignore_nans = other.get_ignore_nans();
158 }
159
161 template<typename DT2_, typename IT2_, int BS_>
163 {
164 _sv.convert(other.get_filter_vector());
165 _ignore_nans = other.get_ignore_nans();
166 }
167
169 void clear()
170 {
171 _sv.clear();
172 }
173
175 std::size_t bytes() const
176 {
177 return _sv.bytes();
178 }
179
182 {
183 return _sv;
184 }
185 const SparseVectorBlocked<DT_, IT_, block_size>& get_filter_vector() const
186 {
187 return _sv;
188 }
190
197 void set_ignore_nans(bool ignore_nans)
198 {
199 _ignore_nans = ignore_nans;
200 }
201
203 bool get_ignore_nans() const
204 {
205 return _ignore_nans;
206 }
207
209 Index size() const
210 {
211 return _sv.size();
212 }
213
216 {
217 return _sv.size_raw();
218 }
219
222 {
223 return _sv.num_nzes();
224 }
225
228 {
229 return _sv.num_nzes_raw();
230 }
231
233 bool empty() const
234 {
235 return _sv.empty();
236 }
237
239 bool hollow() const
240 {
241 return _sv.hollow();
242 }
243
246 {
247 return _sv.elements_arbiter();
248 }
249
252 {
253 return _sv.elements_arbiter();
254 }
255
258 {
259 return _sv.elements_view_r(loc);
260 }
261
264 {
265 return _sv.elements_view_w(loc);
266 }
267
270 {
271 return _sv.elements_view_rw(loc);
272 }
273
284 {
285 return _sv.elements_view(loc, acc);
286 }
287
290 {
291 return _sv.indices_arbiter();
292 }
293
296 {
297 return _sv.indices_arbiter();
298 }
299
302 {
303 return _sv.indices_view_r(loc);
304 }
305
308 {
309 return _sv.indices_view_w(loc);
310 }
311
314 {
315 return _sv.indices_view_rw(loc);
316 }
317
328 {
329 return _sv.indices_view(loc, acc);
330 }
331
332#ifdef DOXYGEN
333 // The following documentation block is visible to Doxygen only. The actual implementation is matrix type
334 // specific and provided below.
335
349 void filter_mat(MatrixType & matrix) const
350 {
351 }
352
366 void filter_offdiag_row_mat(MatrixType & matrix) const
367 {
368 }
369
383 void filter_offdiag_col_mat(MatrixType & matrix) const
384 {
385 }
386
387#endif
389 template<int block_width_>
391 {
392 if(_sv.hollow())
393 return;
394
395 XASSERTM(_sv.size() == matrix.num_rows(), "Matrix size does not match!");
396
397 Arch::UnitFilterBlockBCSR::template exec<DT_, IT_, block_size_, block_width_>(matrix.val_arbiter(), matrix.row_ptr_arbiter(),
398 matrix.col_idx_arbiter(), _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), true, _ignore_nans);
399 }
400
401 template<int block_width_>
402 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, block_size_, block_width_> & matrix) const
403 {
404 if(_sv.hollow())
405 return;
406
407 XASSERTM(_sv.size() == matrix.num_rows(), "Matrix size does not match!");
408
409 Arch::UnitFilterBlockBCSR::template exec<DT_, IT_, block_size_, block_width_>(
410 matrix.val_arbiter(), matrix.row_ptr_arbiter(), matrix.col_idx_arbiter(),
411 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), false, _ignore_nans);
412 }
413
414 template<int block_width_>
415 void filter_offdiag_col_mat(SparseMatrixBCSR<DT_, IT_, block_size_, block_width_> &) const
416 {
417 // nothing to do here
418 }
420
421
437 template<int block_width_>
440 {
441 if(_sv.hollow())
442 return;
443
444 XASSERTM(matrix_a.val_arbiter() != matrix_m.val_arbiter(), "Matrices are not allowed to hold the same data");
445
446 XASSERTM(_sv.size() == matrix_a.num_rows(), "Matrix size does not match!");
447 XASSERTM(_sv.size() == matrix_m.num_rows(), "Matrix size does not match!");
448 XASSERTM(matrix_a.num_cols() == matrix_m.num_cols(), "matrix A and M must share their layout");
449 XASSERTM(matrix_a.num_nzes() == matrix_m.num_nzes(), "matrix A and M must share their layout");
450
451 Arch::UnitFilterBlockWeakBCSR::template exec<DT_, IT_, block_size_, block_width_>(
452 matrix_a.val_arbiter(), matrix_m.val_arbiter(), matrix_a.row_ptr_arbiter(),
453 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), _ignore_nans);
454 }
455
456
463 void filter_rhs(VectorType& vector) const
464 {
465 if(_sv.hollow())
466 return;
467
468 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
469
470 Arch::UnitFilterBlockVec::template exec<DT_, IT_, block_size_>(vector.elements_arbiter(),
471 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), false, _ignore_nans);
472 }
473
480 void filter_sol(VectorType& vector) const
481 {
482 // same as rhs
483 filter_rhs(vector);
484 }
485
492 void filter_def(VectorType& vector) const
493 {
494 if(_sv.hollow())
495 return;
496
497 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
498
499 Arch::UnitFilterBlockVec::template exec<DT_, IT_, block_size_>(vector.elements_arbiter(),
500 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), true, _ignore_nans);
501 }
502
509 void filter_cor(VectorType& vector) const
510 {
511 // same as def
512 filter_def(vector);
513 }
514 }; // class UnitFilterBlocked<...>
515 } // namespace LAFEM
516} // namespace FEAT
#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:1051
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:885
Blocked Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
CSR based blocked sparse matrix.
Memory::Arbiter & val_arbiter()
Returns a reference to the values array arbiter.
Index num_rows() const
Retrieve matrix row count.
Index num_nzes() const
Retrieve non zero element count.
Memory::Arbiter & row_ptr_arbiter()
Returns a reference to the row-pointer array arbiter.
Index num_cols() const
Retrieve matrix column count.
Memory::Arbiter & col_idx_arbiter()
Returns a reference to the column-index array arbiter.
Sparse vector class template.
bool hollow() const
Checks whether the sparse vector does not contain any non-zero elements.
Index size() const
Returns the native size of the sparse vector.
bool empty() const
Checks whether the size of the sparse vector is zero.
Index num_nzes_raw() const
Returns the raw number of non-zero elements in the sparse vector.
void convert(const SparseVectorBlocked< DT2_, IT2_, block_size_ > &other)
Conversion method.
Index num_nzes() const
Returns the number of non-zero elements in the sparse vector.
SparseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
Index size_raw() const
Returns the raw size of the sparse vector.
Unit Filter Blocked class template.
UnitFilterBlocked(Index num_entries, Index num_nonzeros, bool ignore_nans=false)
Constructor.
std::size_t bytes() const
Returns the total amount of bytes allocated.
Memory::TypedView< IT_ > indices_view_w(Memory::Location loc=Memory::Location::main)
Creates a write-only memory view for the indices array for a given memory location.
void filter_offdiag_col_mat(MatrixType &matrix) const
Filter the non-diagonal column entries.
void convert(const UnitFilterBlocked< DT2_, IT2_, BS_ > &other)
Converts data from another UnitFilter.
Memory::TypedView< ValueType > elements_view_w(Memory::Location loc=Memory::Location::main)
Creates a write-only memory view for the elements array for a given memory location.
Memory::TypedView< IT_ > indices_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the indices array for a given memory location.
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
UnitFilterBlocked()
default constructor
Index num_nzes_raw() const
Returns the raw number of non-zero entries in the filter.
Memory::Arbiter & indices_arbiter()
Returns a reference to the indices memory arbiter.
Index size_raw() const
Returns the total raw size of the filter.
UnitFilterBlocked & operator=(UnitFilterBlocked &&other)
move-assignment operator
DenseVectorBlocked< DataType, IndexType, block_size > VectorType
Our supported vector type.
void filter_mat(MatrixType &matrix) const
Applies the filter onto a system matrix.
void clone(const UnitFilterBlocked &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another UnitFilterBlocked.
Tiny::Vector< DataType, block_size > ValueType
Value type.
const Memory::Arbiter & elements_arbiter() const
Returns a const reference to the elements memory arbiter.
Memory::TypedView< IT_ > indices_view(Memory::Location loc, Memory::Access acc)
Creates a memory view for the indices array.
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
bool empty() const
Checks whether the size of the filter is zero.
UnitFilterBlocked(UnitFilterBlocked &&other)
move-ctor
Index num_nzes() const
Returns the number of non-zero entries in the filter.
const Memory::Arbiter & indices_arbiter() const
Returns a const reference to the indices memory arbiter.
void filter_weak_matrix_rows(SparseMatrixBCSR< DT_, IT_, block_size_, block_width_ > &matrix_a, const SparseMatrixBCSR< DT_, IT_, block_size_, block_width_ > &matrix_m) const
Replaces the rows of the system matrix by scaled rows of another matrix.
void clear()
Clears the underlying data (namely the SparseVector)
Memory::TypedView< IT_ > indices_view_rw(Memory::Location loc=Memory::Location::main)
Creates a read-write memory view for the indices array for a given memory location.
bool hollow() const
Checks whether the filter does not contain any non-zero elements.
Memory::TypedView< ValueType > elements_view_r(Memory::Location loc=Memory::Location::main) const
Creates a read-only memory view for the elements array for a given memory location.
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
Memory::Arbiter & elements_arbiter()
Returns a reference to the elements memory arbiter.
void filter_offdiag_row_mat(MatrixType &matrix) const
Filter the non-diagonal row entries.
Memory::TypedView< ValueType > elements_view(Memory::Location loc, Memory::Access acc)
Creates a memory view for the elements array.
bool get_ignore_nans() const
Specifies whether the filter should ignore NaNs filter values.
Index size() const
Returns the total native size of the filter.
void set_ignore_nans(bool ignore_nans)
Specifies whether the filter should ignore NaN filter values.
SparseVectorBlocked< DataType, IndexType, block_size > _sv
SparseVector, containing all entries of the unit filter.
void filter_def(VectorType &vector) const
Applies the filter onto a defect vector.
bool _ignore_nans
ignore NaNs in filter values
UnitFilterBlocked(Index size_in, DenseVectorBlocked< DT_, IT_, block_size_ > &values, DenseVector< IT_, IT_ > &indices, bool ignore_nans=false)
Constructor.
UnitFilterBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
virtual ~UnitFilterBlocked()
virtual destructor
static constexpr int block_size
The block size.
Memory::TypedView< ValueType > elements_view_rw(Memory::Location loc=Memory::Location::main)
Creates a read-write memory view for the elements array for a given memory location.
Memory arbiter class.
Typed memory view class.
Tiny Vector class template.
Access
Memory access enumeration.
Location
Memory location enumeration.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.