FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
filter_chain.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
9#include <kernel/lafem/meta_element.hpp>
10
11namespace FEAT
12{
13 namespace LAFEM
14 {
26 template<
27 typename First_,
28 typename... Rest_>
30 {
31 template<typename,typename...>
32 friend class FilterChain;
33
34 typedef FilterChain<Rest_...> RestClass;
35
36 public:
38 static constexpr int num_blocks = FilterChain<Rest_...>::num_blocks + 1;
39
41 typedef typename First_::DataType DataType;
43 typedef typename First_::IndexType IndexType;
44
45 typedef typename First_::VectorType VectorType;
46
48 template <typename DT2_ = DataType, typename IT2_ = IndexType>
50 typename First_::template FilterType<DT2_, IT2_>,
51 typename Rest_::template FilterType<DT2_, IT2_>...>;
52
54 template <typename DT2_ = DataType, typename IT2_ = IndexType>
56
57 // ensure that all sub-vector have the same and data-type
58 static_assert(std::is_same<DataType, typename RestClass::DataType>::value,
59 "sub-filters have different data-types");
60 static_assert(std::is_same<IndexType, typename RestClass::IndexType>::value,
61 "sub-filters have different index-types");
62
63 protected:
65 First_ _first;
68
70 explicit FilterChain(First_&& the_first, RestClass&& the_rest) :
71 _first(std::move(the_first)),
72 _rest(std::move(the_rest))
73 {
74 }
75
76 public:
79 {
80 }
81
83 explicit FilterChain(First_&& the_first, Rest_&&... the_rest) :
84 _first(std::move(the_first)),
85 _rest(std::move(the_rest...))
86 {
87 }
88
91 _first(std::move(other._first)),
92 _rest(std::move(other._rest))
93 {
94 }
95
98 {
99 if(this != &other)
100 {
101 _first = std::move(other._first);
102 _rest = std::move(other._rest);
103 }
104 return *this;
105 }
106
109 {
110 return FilterChain(_first.clone(clone_mode), _rest.clone(clone_mode));
111 }
112
114 void clone(const FilterChain & other, CloneMode clone_mode = CloneMode::Deep)
115 {
116 _first.clone(other._first.get_filter_vector(), clone_mode);
117 _rest.clone(other._rest, clone_mode);
118 }
119
120 template<typename... SubFilter2_>
121 void convert(const FilterChain<SubFilter2_...>& other)
122 {
123 _first.convert(other._first);
124 _rest.convert(other._rest);
125 }
126
128 std::size_t bytes() const
129 {
130 return _first.bytes() + _rest.bytes();
131 }
132
134 First_& first()
135 {
136 return _first;
137 }
138
139 const First_& first() const
140 {
141 return _first;
142 }
143
144 RestClass& rest()
145 {
146 return _rest;
147 }
148
149 const RestClass& rest() const
150 {
151 return _rest;
152 }
154
155 template<int i_>
156 typename TupleElement<i_, First_, Rest_...>::Type& at()
157 {
158 static_assert((0 <= i_) && (i_ < num_blocks), "invalid sub-filter index");
159 return TupleElement<i_, First_, Rest_...>::get(*this);
160 }
161
163 template<int i_>
164 typename TupleElement<i_, First_, Rest_...>::Type const& at() const
165 {
166 static_assert((0 <= i_) && (i_ < num_blocks), "invalid sub-filter index");
168 }
169
171 template<typename Vector_>
172 void filter_rhs(Vector_& vector) const
173 {
174 first().filter_rhs(vector);
175 rest().filter_rhs(vector);
176 }
177
179 template<typename Vector_>
180 void filter_sol(Vector_& vector) const
181 {
182 first().filter_sol(vector);
183 rest().filter_sol(vector);
184 }
185
187 template<typename Vector_>
188 void filter_def(Vector_& vector) const
189 {
190 first().filter_def(vector);
191 rest().filter_def(vector);
192 }
193
195 template<typename Vector_>
196 void filter_cor(Vector_& vector) const
197 {
198 first().filter_cor(vector);
199 rest().filter_cor(vector);
200 }
201
203 template<typename Matrix_>
204 void filter_mat(Matrix_& matrix) const
205 {
206 first().filter_mat(matrix);
207 rest().filter_mat(matrix);
208 }
209 }; // class FilterChain
210
212 template<typename First_>
213 class FilterChain<First_>
214 {
215 template<typename,typename...>
216 friend class FilterChain;
217
218 public:
219 static constexpr int num_blocks = 1;
220
222 typedef typename First_::DataType DataType;
224 typedef typename First_::IndexType IndexType;
225
226 template <typename DT2_ = DataType, typename IT2_ = IndexType>
227 using FilterType = FilterChain<typename First_::template FilterType<DT2_, IT2_> >;
228
229 protected:
231 First_ _first;
232
233 public:
235 FilterChain()
236 {
237 }
238
240 explicit FilterChain(First_&& the_first) :
241 _first(std::move(the_first))
242 {
243 }
244
246 FilterChain(FilterChain&& other) :
247 _first(std::move(other._first))
248 {
249 }
250
252 FilterChain& operator=(FilterChain&& other)
253 {
254 if(this != &other)
255 {
256 _first = std::move(other._first);
257 }
258 return *this;
259 }
260
262 FilterChain clone(CloneMode clone_mode = CloneMode::Deep) const
263 {
264 return FilterChain(_first.clone(clone_mode));
265 }
266
268 void clone(const FilterChain & other, CloneMode clone_mode = CloneMode::Deep)
269 {
270 _first.clone(other._first.get_filter_vector(), clone_mode);
271 }
272
273 template<typename SubFilter2_>
274 void convert(const FilterChain<SubFilter2_>& other)
275 {
276 _first.convert(other._first);
277 }
278
280 std::size_t bytes() const
281 {
282 return _first.bytes();
283 }
284
285 First_& first()
286 {
287 return _first;
288 }
289
290 const First_& first() const
291 {
292 return _first;
293 }
294
295 template<int i_>
296 typename TupleElement<i_, First_>::Type& at()
297 {
298 static_assert(i_ == 0, "invalid sub-filter index");
299 return first();
300 }
301
302 template<int i_>
303 typename TupleElement<i_, First_>::Type const& at() const
304 {
305 static_assert(i_ == 0, "invalid sub-filter index");
306 return first();
307 }
308
310 template<typename Vector_>
311 void filter_rhs(Vector_& vector) const
312 {
313 first().filter_rhs(vector);
314 }
315
317 template<typename Vector_>
318 void filter_sol(Vector_& vector) const
319 {
320 first().filter_sol(vector);
321 }
322
324 template<typename Vector_>
325 void filter_def(Vector_& vector) const
326 {
327 first().filter_def(vector);
328 }
329
331 template<typename Vector_>
332 void filter_cor(Vector_& vector) const
333 {
334 first().filter_cor(vector);
335 }
336
338 template<typename Matrix_>
339 void filter_mat(Matrix_& matrix) const
340 {
341 first().filter_mat(matrix);
342 }
343 }; // class FilterChain
345 } // namespace LAFEM
346} // namespace FEAT
Filter Chainclass template.
First_::DataType DataType
sub-filter data-type
void filter_cor(Vector_ &vector) const
Applies the filter onto a correction vector.
void filter_sol(Vector_ &vector) const
Applies the filter onto the solution vector.
FilterChain & operator=(FilterChain &&other)
move-assign operator
First_::IndexType IndexType
sub-filter index-type
RestClass _rest
all remaining sub-filters
FilterChain clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
FilterChain< typename First_::template FilterType< DT2_, IT2_ >, typename Rest_::template FilterType< DT2_, IT2_ >... > FilterType
Our 'base' class type.
void filter_mat(Matrix_ &matrix) const
Applies the filter onto a system matrix.
void clone(const FilterChain &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another FilterChain.
TupleElement< i_, First_, Rest_... >::Type const & at() const
First_ _first
the first sub-filter
void filter_rhs(Vector_ &vector) const
Applies the filter onto the right-hand-side vector.
FilterChain(First_ &&the_first, RestClass &&the_rest)
data-emplacement ctor; this one is protected for a reason
std::size_t bytes() const
Returns the total amount of bytes allocated.
FilterChain(First_ &&the_first, Rest_ &&... the_rest)
sub-filter emplacement ctor
static constexpr int num_blocks
number of vector blocks
FilterChain(FilterChain &&other)
move-ctor
void filter_def(Vector_ &vector) const
Applies the filter onto a defect vector.
@ other
generic/other permutation strategy
@ rest
restriction (multigrid)
FEAT namespace.
Definition: adjactor.hpp:12
Tuple container element helper class template.