FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
mean_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#pragma once
6
7// includes, FEAT
8#include <kernel/lafem/dense_vector_blocked.hpp>
9
10namespace FEAT
11{
12 namespace LAFEM
13 {
19 template<typename DT_, typename IT_, int BlockSize_>
21 {
22 public:
31
33 template <typename DT2_ = DT_, typename IT2_ = IT_, int BlockSize2_ = BlockSize_>
35
37 template <typename DataType2_, typename IndexType2_, int BS2_>
39
40 protected:
49
50 public:
51 // default CTOR
53 _vec_prim(),
54 _vec_dual(),
55 _volume(),
56 _sol_mean()
57 {
58 }
59
69 explicit MeanFilterBlocked(VectorType && vec_prim, VectorType && vec_dual, ValueType sol_mean = ValueType(0)) :
70 _vec_prim(std::forward<VectorType>(vec_prim)),
71 _vec_dual(std::forward<VectorType>(vec_dual)),
72 _volume(_vec_prim.dot_blocked(_vec_dual)),
73 _sol_mean(sol_mean)
74 {
75 if(!_vec_prim.empty())
76 {
77 XASSERTM(_volume.norm_euclid_sqr() > Math::eps<DataType>(), "domain volume must not be zero");
78 }
79 }
80
93 explicit MeanFilterBlocked(VectorType && vec_prim, VectorType && vec_dual, ValueType sol_mean, ValueType volume) :
94 _vec_prim(std::forward<VectorType>(vec_prim)),
95 _vec_dual(std::forward<VectorType>(vec_dual)),
96 _volume(volume),
97 _sol_mean(sol_mean)
98 {
99 if(!_vec_prim.empty())
100 {
101 XASSERTM(_volume.norm_euclid_sqr() > Math::eps<DataType>(), "domain volume must not be zero");
102 }
103 }
104
107 _vec_prim(std::move(other._vec_prim)),
108 _vec_dual(std::move(other._vec_dual)),
109 _volume(other._volume),
110 _sol_mean(other._sol_mean)
111 {
112 }
113
116 {
117 if(this != &other)
118 {
119 _vec_prim = std::forward<VectorType>(other._vec_prim);
120 _vec_dual = std::forward<VectorType>(other._vec_dual);
121 _volume = other._volume;
122 _sol_mean = other._sol_mean;
123 }
124 return *this;
125 }
126
129 {
130 }
131
137 {
138 return MeanFilterBlocked(_vec_prim.clone(clone_mode), _vec_dual.clone(clone_mode), _sol_mean, _volume);
139 }
140
145 void clone(const MeanFilterBlocked & other, CloneMode clone_mode = CloneMode::Deep)
146 {
147 _vec_prim.clone(other.get_vec_prim(), clone_mode);
148 _vec_dual.clone(other.get_vec_dual(), clone_mode);
149 _volume = other._volume;
150 _sol_mean = other._sol_mean;
151 }
152
154 template<typename DT2_, typename IT2_, int BlockSize2_>
156 {
157 _vec_prim.convert(other.get_vec_prim());
158 _vec_dual.convert(other.get_vec_dual());
159 _volume = DataType(other.get_volume());
160 _sol_mean = DataType(other.get_sol_mean());
161 if(!_vec_prim.empty())
162 {
163 XASSERTM(_volume.norm_euclid_sqr() > Math::eps<DataType>(), "domain volume must not be zero");
164 }
165 }
166
168 void clear()
169 {
172 _volume.clear();
173 _sol_mean.clear();
174 }
175
177 VectorType & get_vec_prim()
178 {
179 return _vec_prim;
180 }
181
182 const VectorType & get_vec_prim() const
183 {
184 return _vec_prim;
185 }
186
187 VectorType & get_vec_dual()
188 {
189 return _vec_dual;
190 }
191
192 const VectorType & get_vec_dual() const
193 {
194 return _vec_dual;
195 }
196
197 ValueType get_volume() const
198 {
199 return _volume;
200 }
201
202 ValueType get_sol_mean() const
203 {
204 return _sol_mean;
205 }
207
214 void filter_rhs(VectorType& vector) const
215 {
216 // subtract to dual integral mean zero
217 if(!_vec_prim.empty())
218 {
219 ValueType tmp(vector.dot_blocked(_vec_prim));
220 for(int i(0); i<ValueType::n; ++i)
221 {
222 tmp(i) /= -_volume(i);
223 }
224 vector.axpy_blocked(_vec_dual, tmp);
225 }
226 }
227
234 void filter_sol(VectorType& vector) const
235 {
236 // given: v=vec_prim, w=vec_dual, vol=v*w, input: x
237 // note that int(v) = v*w and int(x) = x*w
238 // we want:
239 // 1/vol * int (x + alpha*v) = sol_mean
240 // <==> int(x) + alpha*int(v) = sol_mean*vol
241 // <==> x*w + alpha*v*w = sol_mean*v*w
242 // <==> alpha*v*w = sol_mean*v*w - x*w
243 // <==> alpha = sol_mean - (x*w/v*w)
244 if(!_vec_prim.empty())
245 {
246 ValueType tmp(vector.dot_blocked(_vec_dual));
247 for(int i(0); i<ValueType::n; ++i)
248 {
249 tmp(i)= _sol_mean(i) - tmp(i) * DT_(DT_(1)/_volume(i));
250 }
251 vector.axpy_blocked(_vec_prim, tmp);
252 }
253 }
254
261 void filter_def(VectorType& vector) const
262 {
263 // same as rhs
264 filter_rhs(vector);
265 }
266
273 void filter_cor(VectorType& vector) const
274 {
275 // subtract to primal integral mean zero
276 if(!_vec_prim.empty())
277 {
278 ValueType tmp(vector.dot_blocked(_vec_dual));
279 for(int i(0); i<ValueType::n; ++i)
280 {
281 tmp(i) /= -_volume(i);
282 }
283 vector.axpy_blocked(_vec_prim, tmp);
284 }
285 }
286
293 template<typename MT_>
294 void filter_mat(MT_& DOXY(matrix)) const
295 {
296 // nothing to do here
297 }
298 }; // class MeanFilterBlocked<...>
299 } // namespace LAFEM
300} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
bool empty() const
Checks whether the container is empty.
Definition: container.hpp:1165
virtual void clear()
Free all allocated arrays.
Definition: container.hpp:875
Blocked Dense data vector class template.
void convert(const DenseVectorBlocked< DT2_, IT2_, BlockSize_ > &other)
Conversion method.
ValueType dot_blocked(const DenseVectorBlocked &x) const
Calculate .
DenseVectorBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Clone operation.
void axpy_blocked(const DenseVectorBlocked &x, const ValueType alpha)
Calculate .
Mean Filter Blocked class template.
MeanFilterBlocked(VectorType &&vec_prim, VectorType &&vec_dual, ValueType sol_mean, ValueType volume)
Constructor.
void filter_def(VectorType &vector) const
Applies the filter onto a defect vector.
void filter_cor(VectorType &vector) const
Applies the filter onto a correction vector.
void filter_mat(MT_ &matrix) const
Applies the filter onto a system matrix.
MeanFilterBlocked(VectorType &&vec_prim, VectorType &&vec_dual, ValueType sol_mean=ValueType(0))
Constructor.
void filter_sol(VectorType &vector) const
Applies the filter onto the solution vector.
ValueType _sol_mean
desired solution vector mean
void clear()
Clears this filter.
VectorType::ValueType ValueType
value-type typedef
void clone(const MeanFilterBlocked &other, CloneMode clone_mode=CloneMode::Deep)
Clones data from another MeanFilterBlocked.
void convert(const MeanFilterBlocked< DT2_, IT2_, BlockSize2_ > &other)
Conversion method.
VectorType::IndexType IndexType
index-type typedef
void filter_rhs(VectorType &vector) const
Applies the filter onto the right-hand-side vector.
MeanFilterBlocked clone(CloneMode clone_mode=CloneMode::Deep) const
Creates a clone of itself.
DenseVectorBlocked< DT_, IT_, BlockSize_ > VectorType
vector-type typedef
MeanFilterBlocked(MeanFilterBlocked &&other)
move ctor
VectorType::DataType DataType
data-type typedef
VectorType _vec_dual
dual weighting vector
VectorType _vec_prim
primal weighting vector
MeanFilterBlocked & operator=(MeanFilterBlocked &&other)
move-assign operator
virtual ~MeanFilterBlocked()
virtual destructor
Tiny Vector class template.
static constexpr int n
the length of the vector
CUDA_HOST_DEVICE DataType norm_euclid_sqr() const
Computes the squared euclid norm of this vector.
FEAT namespace.
Definition: adjactor.hpp:12