FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
transfer.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/global/muxer.hpp>
9#include <kernel/global/vector.hpp>
10#include <kernel/lafem/transfer.hpp>
11
12namespace FEAT
13{
14 namespace Global
15 {
21 template<typename LocalTransfer_, typename Mirror_>
23 {
24 public:
26 typedef LocalTransfer_ LocalTransferType;
28 typedef typename LocalTransfer_::MatrixType LocalMatrixType;
30 typedef typename LocalTransfer_::VectorType LocalVectorType;
31
34
37
39 template <typename DT2_, typename IT2_>
41 typename LocalTransfer_::template TransferTypeByDI<DT2_, IT2_>,
42 typename Mirror_::template MirrorType<DT2_, IT2_> >;
43
44 static constexpr bool is_global = true;
45 static constexpr bool is_local = false;
46
47 public:
51 LocalTransfer_ _transfer;
54
55 public:
58 _coarse_muxer(nullptr)
59 {
60 }
61
63 Transfer(Transfer&& other) :
65 _transfer(std::forward<LocalTransfer_>(other._transfer)),
66 _vec_tmp(std::forward<LocalVectorType>(other._vec_tmp))
67 {
68 }
69
79 template<typename... Args_>
80 explicit Transfer(const MuxerType* coarse_muxer, Args_&&... args) :
81 _coarse_muxer(coarse_muxer),
82 _transfer(std::forward<Args_>(args)...),
83 _vec_tmp(_transfer.get_mat_rest().create_vector_l())
84 {
85 }
86
88 virtual ~Transfer()
89 {
90 }
91
94 {
95 if(this == &other)
96 return *this;
97
98 _coarse_muxer = other._coarse_muxer;
99 _transfer = std::forward<LocalTransfer_>(other._transfer);
100 _vec_tmp = std::forward<LocalVectorType>(other._vec_tmp);
101
102 return *this;
103 }
104
106 template<typename LocalTransfer2_, typename Mirror2_>
107 void convert(MuxerType* coarse_muxer, const Transfer<LocalTransfer2_, Mirror2_>& other)
108 {
109 if((void*)this == (void*)&other)
110 return;
111
112 _coarse_muxer = coarse_muxer;
113 _transfer.convert(other._transfer);
114 _vec_tmp.convert(other._vec_tmp);
115 }
116
126 {
127 return Transfer(_coarse_muxer, _transfer.clone(clone_mode));
128 }
129
131 LocalTransfer_& local()
132 {
133 return _transfer;
134 }
135
137 const LocalTransfer_& local() const
138 {
139 return _transfer;
140 }
141
143 std::size_t bytes() const
144 {
145 return _transfer.bytes() + _vec_tmp.bytes();
146 }
147
148 void compile()
149 {
150 _transfer.compile();
151 _vec_tmp = _transfer.get_mat_rest().create_vector_l();
152 }
153
155 LocalVectorType& get_vec_temp()
156 {
157 return _vec_tmp;
158 }
159
160 LocalMatrixType& get_mat_prol()
161 {
162 return _transfer.get_mat_prol();
163 }
164
165 const LocalMatrixType& get_mat_prol() const
166 {
167 return _transfer.get_mat_prol();
168 }
169
170 LocalMatrixType& get_mat_rest()
171 {
172 return _transfer.get_mat_rest();
173 }
174
175 const LocalMatrixType& get_mat_rest() const
176 {
177 return _transfer.get_mat_rest();
178 }
179
180 LocalMatrixType& get_mat_trunc()
181 {
182 return _transfer.get_mat_trunc();
183 }
184
185 const LocalMatrixType& get_mat_trunc() const
186 {
187 return _transfer.get_mat_trunc();
188 }
190
194 bool is_ghost() const
195 {
196 return (_coarse_muxer != nullptr) && _coarse_muxer->is_ghost();
197 }
198
210 bool trunc(const VectorType& vec_fine, VectorType& vec_coarse) const
211 {
212 if((_coarse_muxer == nullptr) || (!_coarse_muxer->is_child()))
213 {
214 _transfer.trunc(vec_fine.local(), vec_coarse.local());
215 }
216 else
217 {
219 _transfer.trunc(vec_fine.local(), _vec_tmp);
220 _coarse_muxer->join(_vec_tmp, vec_coarse.local());
221 }
222 vec_coarse.sync_0();
223 return true;
224 }
225
232 bool trunc_send(const VectorType& vec_fine) const
233 {
234 XASSERT(_coarse_muxer != nullptr);
236 _transfer.trunc(vec_fine.local(), _vec_tmp);
238 return true;
239 }
240
252 bool rest(const VectorType& vec_fine, VectorType& vec_coarse) const
253 {
254 if((_coarse_muxer == nullptr) || (!_coarse_muxer->is_child()))
255 {
256 _transfer.rest(vec_fine.local(), vec_coarse.local());
257 }
258 else
259 {
261 _transfer.rest(vec_fine.local(), _vec_tmp);
262 _coarse_muxer->join(_vec_tmp, vec_coarse.local());
263 }
264 vec_coarse.sync_0();
265 return true;
266 }
267
274 bool rest_send(const VectorType& vec_fine) const
275 {
276 XASSERT(_coarse_muxer != nullptr);
278 _transfer.rest(vec_fine.local(), _vec_tmp);
280 return true;
281 }
282
294 bool prol(VectorType& vec_fine, const VectorType& vec_coarse) const
295 {
296 if((_coarse_muxer == nullptr) || (!_coarse_muxer->is_child()))
297 {
298 _transfer.prol(vec_fine.local(), vec_coarse.local());
299 }
300 else
301 {
304 _coarse_muxer->split(_vec_tmp, vec_coarse.local());
305 _transfer.prol(vec_fine.local(), _vec_tmp);
306 }
307 vec_fine.sync_0();
308 return true;
309 }
310
314 void prol_cancel() const
315 {
316 XASSERTM(false, "this function must not be called");
317 }
318
325 bool prol_recv(VectorType& vec_fine) const
326 {
327 XASSERT(_coarse_muxer != nullptr);
330 _transfer.prol(vec_fine.local(), _vec_tmp);
331 vec_fine.sync_0();
332 return true;
333 }
334 }; // class Transfer<..>
335 } // namespace Global
336} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Global multiplexer/demultiplexer implementation.
Definition: muxer.hpp:68
bool is_child() const
Specifies whether this process represents a child in the muxer.
Definition: muxer.hpp:225
void join_send(const LocalVector_ &vec_src) const
Sends a join operation to the parent process.
Definition: muxer.hpp:375
bool is_ghost() const
Specifies whether this process is a ghost in the muxer.
Definition: muxer.hpp:250
bool is_parent() const
Specifies whether this process represents a parent in the muxer.
Definition: muxer.hpp:236
void split_recv(LocalVector_ &vec_trg) const
Receives a split operation from the parent process.
Definition: muxer.hpp:449
void join(const LocalVector_ &vec_src, LocalVector_ &vec_trg) const
Performs a join operation on the parent process.
Definition: muxer.hpp:401
void split(LocalVector_ &vec_trg, const LocalVector_ &vec_src) const
Performs a split operation on the parent process.
Definition: muxer.hpp:476
Global grid-transfer operator class template.
Definition: transfer.hpp:23
bool rest_send(const VectorType &vec_fine) const
Sends the restriction for a ghost operator.
Definition: transfer.hpp:274
LocalTransfer_::MatrixType LocalMatrixType
our internal local matrix type
Definition: transfer.hpp:28
Global::Vector< LocalVectorType, Mirror_ > VectorType
our global vector type
Definition: transfer.hpp:33
const LocalTransfer_ & local() const
Definition: transfer.hpp:137
void convert(MuxerType *coarse_muxer, const Transfer< LocalTransfer2_, Mirror2_ > &other)
container conversion function
Definition: transfer.hpp:107
Global::Muxer< LocalVectorType, Mirror_ > MuxerType
our coarse grid multiplexer type
Definition: transfer.hpp:36
bool trunc(const VectorType &vec_fine, VectorType &vec_coarse) const
Applies the truncation operator.
Definition: transfer.hpp:210
Transfer clone(LAFEM::CloneMode clone_mode=LAFEM::CloneMode::Weak) const
Creates a clone of this object.
Definition: transfer.hpp:125
bool trunc_send(const VectorType &vec_fine) const
Sends the truncation for a ghost operator.
Definition: transfer.hpp:232
virtual ~Transfer()
virtual destructor
Definition: transfer.hpp:88
std::size_t bytes() const
Definition: transfer.hpp:143
Transfer & operator=(Transfer &&other)
move-assign operator
Definition: transfer.hpp:93
const MuxerType * _coarse_muxer
the coarse-level multiplexer
Definition: transfer.hpp:49
bool prol(VectorType &vec_fine, const VectorType &vec_coarse) const
Applies the prolongation operator.
Definition: transfer.hpp:294
bool rest(const VectorType &vec_fine, VectorType &vec_coarse) const
Applies the restriction operator.
Definition: transfer.hpp:252
LocalTransfer_ & local()
Definition: transfer.hpp:131
bool prol_recv(VectorType &vec_fine) const
Receives the prolongation for a ghost operator.
Definition: transfer.hpp:325
bool is_ghost() const
Checks whether this transfer is a ghost-operator.
Definition: transfer.hpp:194
void prol_cancel() const
Cancels the prolongation.
Definition: transfer.hpp:314
LocalVectorType _vec_tmp
a temporary local vector
Definition: transfer.hpp:53
Transfer(const MuxerType *coarse_muxer, Args_ &&... args)
Constructor.
Definition: transfer.hpp:80
Transfer(Transfer &&other)
move-constructor
Definition: transfer.hpp:63
Transfer()
standard constructor
Definition: transfer.hpp:57
LocalTransfer_ LocalTransferType
our local transfer
Definition: transfer.hpp:26
LocalTransfer_ _transfer
the local transfer operator
Definition: transfer.hpp:51
LocalTransfer_::VectorType LocalVectorType
our internal local vector type
Definition: transfer.hpp:30
Global vector wrapper class template.
Definition: vector.hpp:68
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
Definition: vector.hpp:122
void sync_0()
Performs a type-0 synchronization of the vector, i.e. sums up all local DOF contributions.
Definition: vector.hpp:188
FEAT namespace.
Definition: adjactor.hpp:12