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_dense_vec.hpp>
15#include <kernel/lafem/arch/unit_filter_dense_csr.hpp>
16#include <kernel/lafem/arch/unit_filter_dense_weak_csr.hpp>
17
18namespace FEAT
19{
20 namespace LAFEM
21 {
27 template<
28 typename DT_,
29 typename IT_ = Index>
31 {
32 public:
34 typedef DT_ DataType;
36 typedef IT_ IndexType;
37
40
42 template <typename DT2_ = DT_, typename IT2_ = IT_>
44
46 template <typename DataType2_, typename IndexType2_>
48
49 static constexpr bool is_global = false;
50 static constexpr bool is_local = true;
51
52 private:
55
56 public:
59 _sv()
60 {
61 }
62
69 explicit UnitFilter(Index size_in, Index num_nzes_in) :
70 _sv(size_in, num_nzes_in)
71 {
72 }
73
81 explicit UnitFilter(Index size_in, DenseVector<DT_, IT_> & values, DenseVector<IT_, IT_> & indices) :
82 _sv(size_in, values, indices)
83 {
84 }
85
93 _sv(std::forward<SparseVector<DT_, IT_>>(sv))
94 {
95 }
96
97 explicit UnitFilter(Index size_in, const std::map<IT_, DT_>& map) :
98 _sv(size_in, map)
99 {
100 }
101
104 _sv(std::forward<SparseVector<DT_, IT_>>(other._sv))
105 {
106 }
107
110 {
111 if(this != &other)
112 {
113 _sv = std::forward<SparseVector<DT_, IT_>>(other._sv);
114 }
115 return *this;
116 }
117
119 virtual ~UnitFilter()
120 {
121 }
122
125 {
126 UnitFilter other;
127 other.clone(*this, clone_mode);
128 return other;
129 }
130
132 void clone(const UnitFilter & other, CloneMode clone_mode = CloneMode::Deep)
133 {
134 _sv.clone(other.get_filter_vector(), clone_mode);
135 }
136
138 template<typename DT2_, typename IT2_>
140 {
141 _sv.convert(other.get_filter_vector());
142 }
143
145 void clear()
146 {
147 _sv.clear();
148 }
149
151 std::size_t bytes() const
152 {
153 return _sv.bytes();
154 }
155
157 SparseVector<DT_, IT_>& get_filter_vector()
158 {
159 return _sv;
160 }
161
162 const SparseVector<DT_, IT_>& get_filter_vector() const
163 {
164 return _sv;
165 }
167
169 Index size() const
170 {
171 return _sv.size();
172 }
173
176 {
177 return _sv.size_raw();
178 }
179
182 {
183 return _sv.num_nzes();
184 }
185
188 {
189 return _sv.num_nzes_raw();
190 }
191
193 bool empty() const
194 {
195 return _sv.empty();
196 }
197
199 bool hollow() const
200 {
201 return _sv.hollow();
202 }
203
206 {
207 return _sv.elements_arbiter();
208 }
209
212 {
213 return _sv.elements_arbiter();
214 }
215
218 {
219 return _sv.elements_view_r(loc);
220 }
221
224 {
225 return _sv.elements_view_w(loc);
226 }
227
230 {
231 return _sv.elements_view_rw(loc);
232 }
233
244 {
245 return _sv.elements_view(loc, acc);
246 }
247
250 {
251 return _sv.indices_arbiter();
252 }
253
256 {
257 return _sv.indices_arbiter();
258 }
259
262 {
263 return _sv.indices_view_r(loc);
264 }
265
268 {
269 return _sv.indices_view_w(loc);
270 }
271
274 {
275 return _sv.indices_view_rw(loc);
276 }
277
288 {
289 return _sv.indices_view(loc, acc);
290 }
291
294 {
295 _sv.permute(perm);
296 }
297
298#ifdef DOXYGEN
299 // The following documentation block is visible to Doxygen only. The actual implementation is matrix type
300 // specific and provided below.
301
309 void filter_mat(MatrixType & matrix) const
310 {
311 }
312
320 void filter_offdiag_row_mat(MatrixType & matrix) const
321 {
322 }
323
331 void filter_offdiag_col_mat(MatrixType & matrix) const
332 {
333 }
334
335#endif
337 void filter_mat(SparseMatrixCSR<DT_, IT_> & matrix) const
338 {
339 if(_sv.hollow())
340 return;
341
342 XASSERTM(_sv.size() == matrix.num_rows(), "Matrix size does not match!");
343
344 Arch::UnitFilterDenseCSR::template exec<DT_, IT_>(matrix.val_arbiter(), matrix.row_ptr_arbiter(), matrix.col_idx_arbiter(),
345 _sv.indices_arbiter(), _sv.num_nzes(), true, 1);
346 }
347
348 void filter_offdiag_row_mat(SparseMatrixCSR<DT_, IT_> & matrix) const
349 {
350 if(_sv.hollow())
351 return;
352
353 XASSERTM(_sv.size() == matrix.num_rows(), "Matrix size does not match!");
354
355 Arch::UnitFilterDenseCSR::template exec<DT_, IT_>(matrix.val_arbiter(), matrix.row_ptr_arbiter(), matrix.col_idx_arbiter(),
356 _sv.indices_arbiter(), _sv.num_nzes(), false, 1);
357 }
358
359 void filter_offdiag_col_mat(SparseMatrixCSR<DT_, IT_> &) const
360 {
361 // nothing to do here
362 }
363
364 template<int block_width_>
365 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, 1, block_width_> & matrix) const
366 {
367 if(_sv.hollow())
368 return;
369
370 XASSERTM(_sv.size() == matrix.num_rows(), "Matrix size does not match!");
371
372 Arch::UnitFilterDenseCSR::template exec<DT_, IT_>(matrix.val_arbiter(), matrix.row_ptr_arbiter(), matrix.col_idx_arbiter(),
373 _sv.indices_arbiter(), _sv.num_nzes(), false, block_width_);
374 }
375
376 template<int block_height_>
377 void filter_offdiag_row_mat(SparseMatrixBCSR<DT_, IT_, block_height_, 1> &) const
378 {
379 // nothing to do here
380 }
382
399 {
400 if(_sv.hollow())
401 return;
402
403 XASSERTM(_sv.size() == matrix_a.num_rows(), "Matrix size does not match!");
404 XASSERTM(_sv.size() == matrix_m.num_rows(), "Matrix size does not match!");
405 XASSERTM(matrix_a.num_cols() == matrix_m.num_cols(), "matrix A and M must share their layout");
406 XASSERTM(matrix_a.num_nzes() == matrix_m.num_nzes(), "matrix A and M must share their layout");
407
408 Arch::UnitFilterDenseWeakCSR::template exec<DT_, IT_>(
409 matrix_a.val_arbiter(), matrix_m.val_arbiter(), matrix_a.row_ptr_arbiter(),
410 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes());
411 }
412
413
421 {
422 if(_sv.hollow())
423 return;
424
425 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
426
427 Arch::UnitFilterDenseVec::template exec<DT_, IT_>(vector.elements_arbiter(),
428 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), false);
429 }
430
438 {
439 // same as rhs
440 filter_rhs(vector);
441 }
442
450 {
451 if(_sv.hollow())
452 return;
453
454 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
455
456 Arch::UnitFilterDenseVec::template exec<DT_, IT_>(vector.elements_arbiter(),
457 _sv.elements_arbiter(), _sv.indices_arbiter(), _sv.num_nzes(), true);
458 }
459
467 {
468 // same as def
469 filter_def(vector);
470 }
471 }; // class UnitFilter<...>
472 } // namespace LAFEM
473} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
CSR based sparse matrix.
Memory::Arbiter & val_arbiter()
Returns a reference to the values array arbiter.
Index num_cols() const
Retrieve matrix column count.
Index num_rows() const
Retrieve matrix row count.
Memory::Arbiter & col_idx_arbiter()
Returns a reference to the column-index array arbiter.
Index num_nzes() const
Retrieve non zero element count.
Memory::Arbiter & row_ptr_arbiter()
Returns a reference to the row-pointer array arbiter.
Sparse vector class template.
Unit Filter class template.
Definition: unit_filter.hpp:31
Memory::Arbiter & indices_arbiter()
Returns a reference to the indices memory arbiter.
UnitFilter clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
UnitFilter()
default constructor
Definition: unit_filter.hpp:58
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.
UnitFilter(Index size_in, Index num_nzes_in)
Constructor.
Definition: unit_filter.hpp:69
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:39
void permute(Adjacency::Permutation &perm)
Permute internal vector according to the given Permutation.
SparseVector< DT_, IT_ > _sv
SparseVector, containing all entries of the unit filter.
Definition: unit_filter.hpp:54
void filter_mat(MatrixType &matrix) const
Applies the filter onto a system matrix.
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.
Memory::TypedView< DT_ > elements_view_rw(Memory::Location loc=Memory::Location::main)
Creates a read-write memory view for the elements array for a given memory location.
Index num_nzes() const
Returns the number of non-zero entries in the filter.
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.
Memory::TypedView< DT_ > elements_view_w(Memory::Location loc=Memory::Location::main)
Creates a write-only memory view for the elements array for a given memory location.
UnitFilter(Index size_in, DenseVector< DT_, IT_ > &values, DenseVector< IT_, IT_ > &indices)
Constructor.
Definition: unit_filter.hpp:81
Index size() const
Returns the total native size of the filter.
void filter_offdiag_col_mat(MatrixType &matrix) const
Filter the non-diagonal entries, column wise.
Index num_nzes_raw() const
Returns the raw number of non-zero entries in the filter.
void filter_offdiag_row_mat(MatrixType &matrix) const
Filter the non-diagonal entries, row wise.
Memory::TypedView< DT_ > elements_view(Memory::Location loc, Memory::Access acc)
Creates a memory view for the elements array.
UnitFilter & operator=(UnitFilter &&other)
move-assignment operator
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.
Memory::TypedView< DT_ > 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.
virtual ~UnitFilter()
virtual destructor
const Memory::Arbiter & indices_arbiter() const
Returns a const reference to the indices memory arbiter.
Memory::TypedView< IT_ > indices_view(Memory::Location loc, Memory::Access acc)
Creates a memory view for the indices array.
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
Memory::Arbiter & elements_arbiter()
Returns a reference to the elements memory arbiter.
bool empty() const
Checks whether the size of the filter is zero.
bool hollow() const
Checks whether the filter does not contain any non-zero elements.
UnitFilter(SparseVector< DT_, IT_ > &&sv)
Constructor.
Definition: unit_filter.hpp:92
DT_ DataType
data-type typedef
Definition: unit_filter.hpp:34
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.
IT_ IndexType
index-type typedef
Definition: unit_filter.hpp:36
Index size_raw() const
Returns the total raw size of the filter.
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.
void clear()
Clears the underlying data (namely the SparseVector)
const Memory::Arbiter & elements_arbiter() const
Returns a const reference to the elements memory arbiter.
Memory arbiter class.
Typed memory view class.
Access
Memory access enumeration.
Location
Memory location enumeration.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.