FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
slip_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_bcsr.hpp>
11#include <kernel/lafem/dense_vector_blocked.hpp>
12#include <kernel/lafem/sparse_vector_blocked.hpp>
13#include <kernel/lafem/arch/slip_filter.hpp>
14
15namespace FEAT
16{
17 namespace LAFEM
18 {
62 template<
63 typename DT_,
64 typename IT_,
65 int BlockSize_>
67 {
68 public:
70 typedef DT_ DataType;
72 typedef IT_ IndexType;
74 static constexpr int BlockSize = BlockSize_;
79
81 template <typename DT2_ = DT_, typename IT2_ = IT_>
83
85 template <typename DT2_ = DT_, typename IT2_ = IT_>
87
88 static_assert(BlockSize > 1, "BlockSize has to be >= 2 in SlipFilter!");
89
90 private:
95
96 public:
99 _nu(),
100 _sv()
101 {
102 }
103
114 explicit SlipFilter(Index num_vertices, Index num_dofs) :
115 _nu(num_vertices),
116 _sv(num_dofs)
117 {
118 }
119
122 _nu(std::move(other._nu)),
123 _sv(std::move(other._sv))
124 {
125 }
126
129 {
130 if(this != &other)
131 {
132 _sv = std::forward<decltype(other._sv)>(other._sv);
133 _nu = std::forward<decltype(other._nu)>(other._nu);
134 }
135 return *this;
136 }
137
139 virtual ~SlipFilter()
140 {
141 }
142
145 {
146 SlipFilter other;
147 other.clone(*this, clone_mode);
148 return other;
149 }
150
152 void clone(const SlipFilter & other, CloneMode clone_mode = CloneMode::Deep)
153 {
154 _nu.clone(other.get_nu(), clone_mode);
155 _sv.clone(other.get_filter_vector(), clone_mode);
156 }
157
159 template<typename DT2_, typename IT2_, int BS_>
161 {
162 _nu.convert(other.get_nu());
163 _sv.convert(other.get_filter_vector());
164 }
165
167 void clear()
168 {
169 _nu.clear();
170 _sv.clear();
171 }
172
174 std::size_t bytes() const
175 {
176 return _nu.bytes() + _sv.bytes();
177 }
178
181 {
182 return _sv;
183 }
184 const SparseVectorBlocked<DT_, IT_, BlockSize>& get_filter_vector() const
185 {
186 return _sv;
187 }
188
189 SparseVectorBlocked<DT_, IT_, BlockSize>& get_nu()
190 {
191 return _nu;
192 }
193 const SparseVectorBlocked<DT_, IT_, BlockSize>& get_nu() const
194 {
195 return _nu;
196 }
198
206 void add(IndexType idx, ValueType val)
207 {
208 _sv(idx, val);
209 }
210
212 Index size() const
213 {
214 return _sv.size();
215 }
216
219 {
220 return _sv.used_elements();
221 }
222
225 {
226 return _sv.indices();
227 }
228
230 const IT_* get_indices() const
231 {
232 return _sv.indices();
233 }
234
237 {
238 return _sv.elements();
239 }
240
242 const ValueType* get_values() const
243 {
244 return _sv.elements();
245 }
246
247 bool empty() const
248 {
249 return _sv.used_elements() <= Index(0);
250 }
251
258 void filter_rhs(VectorType& vector) const
259 {
260 if(_sv.empty())
261 return;
262 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
263 if(_sv.used_elements() > Index(0))
264 Arch::SlipFilter::template filter_rhs<BlockSize_>
265 (vector.template elements<Perspective::pod>(), _sv.template elements<Perspective::pod>(), _sv.indices(), _sv.used_elements());
266 }
267
274 void filter_sol(VectorType& vector) const
275 {
276 if(_sv.empty())
277 return;
278 // same as rhs
279 filter_rhs(vector);
280 }
281
288 void filter_def(VectorType& vector) const
289 {
290 if(_sv.empty())
291 return;
292 XASSERTM(_sv.size() == vector.size(), "Vector size does not match!");
293 if(_sv.used_elements() > Index(0))
294 Arch::SlipFilter::template filter_def<BlockSize_>
295 (vector.template elements<Perspective::pod>(), _sv.template elements<Perspective::pod>(), _sv.indices(), _sv.used_elements() );
296 }
297
304 void filter_cor(VectorType& vector) const
305 {
306 // same as def
307 filter_def(vector);
308 }
309 }; // class SlipFilter<...>
310 } // namespace LAFEM
311} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
FEAT Kernel base header.
Blocked Dense data vector class template.
Index size() const
The number of elements.
Slip Filter class template.
Definition: slip_filter.hpp:67
void convert(const SlipFilter< DT2_, IT2_, BS_ > &other)
Converts data from another UnitFilter.
SparseVectorBlocked< DT_, IT_, BlockSize_ > _nu
This will contain the pointwise outer unit normal in all vertices.
Definition: slip_filter.hpp:92
SlipFilter(SlipFilter &&other)
move-ctor
DenseVectorBlocked< DT_, IT_, BlockSize_ > VectorType
Our supported vector type.
Definition: slip_filter.hpp:78
SparseVectorBlocked< DT_, IT_, BlockSize_ > _sv
This will contain the data for filtering.
Definition: slip_filter.hpp:94
Index used_elements() const
static constexpr int BlockSize
The block size.
Definition: slip_filter.hpp:74
DT_ DataType
data-type typedef
Definition: slip_filter.hpp:70
void add(IndexType idx, ValueType val)
Adds one element to the filter.
void clone(const SlipFilter &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another SlipFilter.
void filter_def(VectorType &vector) const
Applies the filter onto a defect vector.
std::size_t bytes() const
Returns the total amount of bytes allocated.
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
SlipFilter(Index num_vertices, Index num_dofs)
Constructor.
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
void clear()
Clears the underlying data (namely the SparseVector)
SlipFilter & operator=(SlipFilter &&other)
move-assignment operator
const IT_ * get_indices() const
ValueType * get_values()
IT_ IndexType
index-type typedef
Definition: slip_filter.hpp:72
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
SlipFilter clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
const ValueType * get_values() const
Tiny::Vector< DataType, BlockSize > ValueType
Value type.
Definition: slip_filter.hpp:76
virtual ~SlipFilter()
virtual destructor
SlipFilter()
default constructor
Definition: slip_filter.hpp:98
Sparse vector class template.
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.