FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
power_mirror.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/vector_mirror.hpp>
10
11namespace FEAT
12{
13 namespace LAFEM
14 {
16 namespace Intern
17 {
18 // PowerMirror helper class: this implements the actual recursion for the gather/scatter methods
19 template<int i_>
20 struct PowerMirrorHelper
21 {
22 template<typename SM_, typename BV_, typename PV_>
23 static void gather(const SM_& sm, BV_& bv, const PV_& pv, const Index bo)
24 {
25 sm.gather(bv, pv.first(), bo);
26 PowerMirrorHelper<i_-1>::gather(sm, bv, pv.rest(), bo + sm.buffer_size(pv.first()));
27 }
28 template<typename SM_, typename PV_, typename BV_, typename AT_>
29 static void scatter_axpy(const SM_& sm, PV_& pv, const BV_& bv, const AT_ a, const Index bo)
30 {
31 sm.scatter_axpy(pv.first(), bv, a, bo);
32 PowerMirrorHelper<i_-1>::scatter_axpy(sm, pv.rest(), bv, a, bo + sm.buffer_size(pv.first()));
33 }
34 template<typename SM_, typename PV_>
35 static Index buffer_size(const SM_& sm, PV_& pv)
36 {
37 return sm.buffer_size(pv.first()) + PowerMirrorHelper<i_-1>::buffer_size(sm, pv.rest());
38 }
39 template<typename SM_, typename Pv_>
40 static Index mask_scatter(const SM_& sm, const Pv_& pv, std::vector<int>& mask, const int value, const Index offset)
41 {
42 Index nf = sm.mask_scatter(pv.first(), mask, value, offset);
43 Index nr = PowerMirrorHelper<i_-1>::mask_scatter(sm, pv.rest(), mask, value, offset + nf);
44 return nf + nr;
45 }
46 template<typename SM_, typename Pv_>
47 static Index mask_scatter_raw(const SM_& sm, const Pv_& pv, std::vector<int>& mask, const int value, const Index offset)
48 {
49 Index nf = sm.mask_scatter_raw(pv.first(), mask, value, offset);
50 Index nr = PowerMirrorHelper<i_-1>::mask_scatter_raw(sm, pv.rest(), mask, value, offset + nf);
51 return nf + nr;
52 }
53 };
54
55 template<>
56 struct PowerMirrorHelper<1>
57 {
58 template<typename SM_, typename BV_, typename PV_>
59 static void gather(const SM_& sm, BV_& bv, const PV_& pv, const Index bo)
60 {
61 sm.gather(bv, pv.first(), bo);
62 }
63 template<typename SM_, typename PV_, typename BV_, typename AT_>
64 static void scatter_axpy(const SM_& sm, PV_& pv, const BV_& bv, const AT_ a, const Index bo)
65 {
66 sm.scatter_axpy(pv.first(), bv, a, bo);
67 }
68 template<typename SM_, typename PV_>
69 static Index buffer_size(const SM_& sm, PV_& pv)
70 {
71 return sm.buffer_size(pv.first());
72 }
73 template<typename SM_, typename Pv_>
74 static Index mask_scatter(const SM_& sm, const Pv_& pv, std::vector<int>& mask, const int value, const Index offset)
75 {
76 return sm.mask_scatter(pv.first(), mask, value, offset);
77 }
78 template<typename SM_, typename Pv_>
79 static Index mask_scatter_raw(const SM_& sm, const Pv_& pv, std::vector<int>& mask, const int value, const Index offset)
80 {
81 return sm.mask_scatter_raw(pv.first(), mask, value, offset);
82 }
83 };
84 } // namespace Intern
86
104 template<typename SubMirror_, int count_>
106 {
107 public:
108 static_assert(count_ > 0, "invalid block size");
109
111 typedef SubMirror_ SubMirrorType;
113 typedef typename SubMirrorType::DataType DataType;
115 typedef typename SubMirrorType::IndexType IndexType;
116
118 static constexpr int num_blocks = count_;
119
121 template <typename DT2_ = DataType, typename IT2_ = IndexType>
123
125 template <typename DataType2_, typename IndexType2_>
127
130
133 {
134 }
135
137 explicit PowerMirror(SubMirrorType&& sub_mirror) :
138 _sub_mirror(std::move(sub_mirror))
139 {
140 }
141
144 _sub_mirror(std::move(other._sub_mirror))
145 {
146 }
147
150 {
151 if(this != &other)
152 {
153 _sub_mirror = std::move(other._sub_mirror);
154 }
155 return *this;
156 }
157
164 {
165 return PowerMirror(_sub_mirror.clone(clone_mode));
166 }
167
174 template<typename SubMirror2_>
176 {
177 this->_sub_mirror.convert(other._sub_mirror);
178 }
179
188 template<typename SubVector_>
190 {
191 return PowerMirror(SubMirrorType::make_hollow(tmpl_vec.first()));
192 }
193
195 std::size_t bytes() const
196 {
197 return _sub_mirror.bytes();
198 }
199
205 bool empty() const
206 {
207 return this->_sub_mirror.empty();
208 }
209
215 bool hollow() const
216 {
217 return this->_sub_mirror.hollow();
218 }
219
226 template<typename SubVector_>
228 {
229 return Intern::PowerMirrorHelper<count_>::buffer_size(_sub_mirror, vector);
230 }
231
238 template<typename SubVector_>
240 {
242 }
243
253 template<int i_>
255 {
256 static_assert((0 <= i_) && (i_ < count_), "invalid sub-mirror index");
257 return _sub_mirror;
258 }
259
261 template<int i_>
262 const SubMirrorType& at() const
263 {
264 static_assert((0 <= i_) && (i_ < count_), "invalid sub-mirror index");
265 return _sub_mirror;
266 }
267
278 {
279 XASSERTM((0 <= i) && (i < count_), "invalid sub-mirror index");
280 return _sub_mirror;
281 }
282
284 const SubMirrorType& get(int i) const
285 {
286 XASSERTM((0 <= i) && (i < count_), "invalid sub-mirror index");
287 return _sub_mirror;
288 }
289
291 template<typename Tv_>
292 void gather(
295 const Index buffer_offset = Index(0)) const
296 {
297 Intern::PowerMirrorHelper<count_>::gather(_sub_mirror, buffer, vector, buffer_offset);
298 }
299
301 template<typename Tv_>
305 const DataType alpha = DataType(1),
306 const Index buffer_offset = Index(0)) const
307 {
308 Intern::PowerMirrorHelper<count_>::scatter_axpy(_sub_mirror, vector, buffer, alpha, buffer_offset);
309 }
310
312 template<typename Tv_>
313 Index mask_scatter(const LAFEM::PowerVector<Tv_, count_>& vector, std::vector<int>& mask,
314 const int value, const Index offset = Index(0)) const
315 {
316 return Intern::PowerMirrorHelper<count_>::mask_scatter(_sub_mirror, vector, mask, value, offset);
317 }
318
320 template<typename Tv_>
321 Index mask_scatter_raw(const LAFEM::PowerVector<Tv_, count_>& vector, std::vector<int>& mask,
322 const int value, const Index offset = Index(0)) const
323 {
324 return Intern::PowerMirrorHelper<count_>::mask_scatter_raw(_sub_mirror, vector, mask, value, offset);
325 }
326 }; // class PowerMirror<...>
327 } // namespace LAFEM
328} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Dense data vector class template.
PowerVector meta-mirror class template.
const SubMirrorType & at() const
Returns a sub-mirror block.
PowerMirror & operator=(PowerMirror &&other)
move-assign operator
Index mask_scatter(const LAFEM::PowerVector< Tv_, count_ > &vector, std::vector< int > &mask, const int value, const Index offset=Index(0)) const
Updates a scatter mask vector for this mirror.
Index mask_scatter_raw(const LAFEM::PowerVector< Tv_, count_ > &vector, std::vector< int > &mask, const int value, const Index offset=Index(0)) const
static PowerMirror make_hollow(const PowerVector< SubVector_, count_ > &tmpl_vec)
Creates and returns an empty mirror.
PowerMirror(SubMirrorType &&sub_mirror)
sub-mirror move-ctor
void gather(LAFEM::DenseVector< DataType, IndexType > &buffer, const LAFEM::PowerVector< Tv_, count_ > &vector, const Index buffer_offset=Index(0)) const
Gathers the buffer entries from a DenseVector.
PowerMirror(PowerMirror &&other)
move-ctor
DenseVector< DataType, IndexType > create_buffer(const PowerVector< SubVector_, count_ > &vector) const
Creates a new buffer vector for a PowerVector.
Index buffer_size(const PowerVector< SubVector_, count_ > &vector) const
Computes the required buffer size for a PowerVector.
SubMirrorType::IndexType IndexType
sub-mirror index-type
SubMirrorType & at()
Returns a sub-mirror block.
SubMirrorType::DataType DataType
sub-mirror data-type
PowerMirror clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
bool hollow() const
Checks whether the mirror is hollow.
std::size_t bytes() const
Returns the total amount of bytes allocated.
SubMirrorType & get(int i)
Returns a sub-mirror block.
bool empty() const
Checks whether the mirror is empty.
SubMirrorType _sub_mirror
the one and only sub-mirror object
const SubMirrorType & get(int i) const
Returns a sub-mirror block.
void convert(const PowerMirror< SubMirror2_, count_ > &other)
Conversion method.
SubMirror_ SubMirrorType
sub-mirror type
void scatter_axpy(LAFEM::PowerVector< Tv_, count_ > &vector, const LAFEM::DenseVector< DataType, IndexType > &buffer, const DataType alpha=DataType(1), const Index buffer_offset=Index(0)) const
Scatters the buffer entries onto a DenseVector.
static constexpr int num_blocks
total number of sub-mirror blocks
Power-Vector meta class template.
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.