FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
power_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#include <kernel/lafem/power_vector.hpp>
9#include <kernel/lafem/meta_element.hpp>
10
11namespace FEAT
12{
13 namespace LAFEM
14 {
31 template<
32 typename SubFilter_,
33 int count_>
35 {
36 // Note: the case = 1 is specialized below
37 static_assert(count_ > 1, "invalid block size");
38
39 // declare this class template as a friend for recursive inheritance
40 template<typename,int>
41 friend class PowerFilter;
42
44 typedef PowerFilter<SubFilter_, count_-1> RestClass;
45
46 public:
48 typedef SubFilter_ SubFilterType;
50 typedef typename SubFilter_::DataType DataType;
52 typedef typename SubFilter_::IndexType IndexType;
53
55 static constexpr int num_blocks = count_;
56
59
61 template <typename DT2_ = DataType, typename IT2_ = IndexType>
63
65 template <typename DataType2_, typename IndexType2_>
67
68 protected:
73
75 explicit PowerFilter(SubFilterType&& the_first, RestClass&& the_rest) :
76 _first(std::move(the_first)),
77 _rest(std::move(the_rest))
78 {
79 }
80
81 public:
84 {
85 }
86
89 _first(std::move(other._first)),
90 _rest(std::move(other._rest))
91 {
92 }
93
96 {
97 if(this != &other)
98 {
99 _first = std::move(other._first);
100 _rest = std::move(other._rest);
101 }
102 return *this;
103 }
104
107 {
108 return PowerFilter(first().clone(clone_mode), rest().clone(clone_mode));
109 }
110
112 void clone(const PowerFilter & other, CloneMode clone_mode = CloneMode::Deep)
113 {
114 _first.clone(other._first.get_filter_vector(), clone_mode);
115 _rest.clone(other._rest, clone_mode);
116 }
117
119 template<typename SubFilter2_>
121 {
122 _first.convert(other._first);
123 _rest.convert(other._rest);
124 }
125
127 std::size_t bytes() const
128 {
129 return _first.bytes() + _rest.bytes();
130 }
131
133 SubFilterType& first()
134 {
135 return _first;
136 }
137
138 const SubFilterType& first() const
139 {
140 return _first;
141 }
142
143 RestClass& rest()
144 {
145 return _rest;
146 }
147
148 const RestClass& rest() const
149 {
150 return _rest;
151 }
153
154 template<int i_>
155 SubFilterType& at()
156 {
157 static_assert((0 <= i_) && (i_ < count_), "invalid sub-filter index");
158 return PowerElement<i_, SubFilterType>::get(*this);
159 }
160
161 template<int i_>
162 const SubFilterType& at() const
163 {
164 static_assert((0 <= i_) && (i_ < count_), "invalid sub-filter index");
165 return PowerElement<i_, SubFilterType>::get(*this);
166 }
167
178 {
179 XASSERTM((0 <= i) && (i < count_), "invalid sub-filter index");
180 return (i == 0) ? _first : _rest.get(i-1);
181 }
182
184 const SubFilterType& get(int i) const
185 {
186 XASSERTM((0 <= i) && (i < count_), "invalid sub-filter index");
187 return (i == 0) ? _first : _rest.get(i-1);
188 }
189
191 void filter_rhs(VectorType& vector) const
192 {
193 first().filter_rhs(vector.first());
194 rest().filter_rhs(vector.rest());
195 }
196
198 void filter_sol(VectorType& vector) const
199 {
200 first().filter_sol(vector.first());
201 rest().filter_sol(vector.rest());
202 }
203
205 void filter_def(VectorType& vector) const
206 {
207 first().filter_def(vector.first());
208 rest().filter_def(vector.rest());
209 }
210
212 void filter_cor(VectorType& vector) const
213 {
214 first().filter_cor(vector.first());
215 rest().filter_cor(vector.rest());
216 }
217 }; // class PowerFilter<...>
218
220 template<typename SubFilter_>
221 class PowerFilter<SubFilter_, 1>
222 {
223 template<typename,int>
224 friend class PowerFilter;
225
226 public:
227 typedef SubFilter_ SubFilterType;
228 typedef typename SubFilter_::DataType DataType;
229 typedef typename SubFilter_::IndexType IndexType;
230
231 static constexpr int num_blocks = 1;
232
233 typedef PowerVector<typename SubFilter_::VectorType, 1> VectorType;
234
235 template <typename DT2_ = DataType, typename IT2_ = IndexType>
236 using FilterType = PowerFilter<typename SubFilterType::template FilterType<DT2_, IT2_>, Index(1)>;
237
239 template <typename DataType2_, typename IndexType2_>
240 using FilterTypeByDI = FilterType<DataType2_, IndexType2_>;
241
242 protected:
244
245 explicit PowerFilter(SubFilterType&& the_first) :
246 _first(std::move(the_first))
247 {
248 }
249
250 public:
251 PowerFilter()
252 {
253 }
254
256 PowerFilter(PowerFilter&& other) :
257 _first(std::move(other._first))
258 {
259 }
260
261 PowerFilter& operator=(PowerFilter&& other)
262 {
263 if(this != &other)
264 {
265 _first = std::move(other._first);
266 }
267 return *this;
268 }
269
271 PowerFilter clone(CloneMode clone_mode = CloneMode::Deep) const
272 {
273 return PowerFilter(first().clone(clone_mode));
274 }
275
277 void clone(const PowerFilter & other, CloneMode clone_mode = CloneMode::Deep)
278 {
279 _first.clone(other._first.get_filter_vector(), clone_mode);
280 }
281
282 template<typename SubFilter2_>
283 void convert(const PowerFilter<SubFilter2_, 1>& other)
284 {
285 _first.convert(other._first);
286 }
287
289 std::size_t bytes() const
290 {
291 return _first.bytes();
292 }
293
294 SubFilterType& first()
295 {
296 return _first;
297 }
298
299 const SubFilterType& first() const
300 {
301 return _first;
302 }
303
304 template<int i_>
305 SubFilterType& at()
306 {
307 static_assert(i_ != 0, "invalid sub-filter index");
308 return _first;
309 }
310
311 template<int i_>
312 const SubFilterType& at() const
313 {
314 static_assert(i_ != 0, "invalid sub-filter index");
315 return _first;
316 }
317
318 SubFilterType& get(int i)
319 {
320 XASSERTM(i == 0, "invalid sub-filter index");
321 return _first;
322 }
323
324 const SubFilterType& get(int i) const
325 {
326 XASSERTM(i == 0, "invalid sub-filter index");
327 return _first;
328 }
329
330 void filter_rhs(VectorType& vector) const
331 {
332 first().filter_rhs(vector.first());
333 }
334
335 void filter_sol(VectorType& vector) const
336 {
337 first().filter_sol(vector.first());
338 }
339
340 void filter_def(VectorType& vector) const
341 {
342 first().filter_def(vector.first());
343 }
344
345 void filter_cor(VectorType& vector) const
346 {
347 first().filter_cor(vector.first());
348 }
349 };
351 } // namespace LAFEM
352} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
PowerVector meta-filter class template.
SubFilter_ SubFilterType
sub-filter type
PowerFilter(PowerFilter &&other)
move CTOR
PowerFilter(SubFilterType &&the_first, RestClass &&the_rest)
base-class ctor; for internal use only
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
SubFilter_::IndexType IndexType
sub-filter index-type
static constexpr int num_blocks
number of filter blocks
PowerFilter< typename SubFilterType::template FilterType< DT2_, IT2_ >, count_ > FilterType
Our 'base' class type.
PowerFilter & operator=(PowerFilter &&other)
move-assign operator
const SubFilterType & get(int i) const
Returns a sub-filter block.
PowerVector< typename SubFilter_::VectorType, count_ > VectorType
vector type
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 convert(const PowerFilter< SubFilter2_, count_ > &other)
Conversion method.
SubFilter_::DataType DataType
sub-filter data-type
FilterType< DataType2_, IndexType2_ > FilterTypeByDI
this typedef lets you create a filter with different Data and Index types
PowerFilter< SubFilter_, count_-1 > RestClass
base-class typedef
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
RestClass _rest
the remaining part
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
PowerFilter clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
void clone(const PowerFilter &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another PowerFilter.
SubFilterType _first
the first sub-filter
SubFilterType & get(int i)
Returns a sub-filter block.
Power-Vector meta class template.
@ other
generic/other permutation strategy
@ rest
restriction (multigrid)
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.