FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matrix_mirror_buffer.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
11#include <kernel/util/memory_arbiter.hpp>
12#include <kernel/util/type_traits.hpp>
13#include <kernel/adjacency/graph.hpp>
14#include <kernel/lafem/forward.hpp>
15#include <kernel/lafem/container.hpp>
16
17namespace FEAT
18{
19 namespace LAFEM
20 {
40 template<typename DT_, typename IT_>
41 class MatrixMirrorBuffer : public Container<DT_, IT_>
42 {
43 public:
45 typedef DT_ DataType;
47 typedef IT_ IndexType;
49 typedef DT_ ValueType;
51 template <typename DT2_ = DT_, typename IT2_ = IT_>
53
55 template <typename DataType2_, typename IndexType2_>
57
63 MatrixMirrorBuffer() = default;
64
75 explicit MatrixMirrorBuffer(Index rows_in, Index columns_in, Index used_elements_in, Index entries_per_nonzero_in)
76 {
77 this->_scalar_index.push_back(rows_in);
78 this->_scalar_index.push_back(columns_in);
79 this->_scalar_index.push_back(used_elements_in);
80 this->_scalar_index.push_back(entries_per_nonzero_in);
81
82 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * (num_rows() + 1)));
83 this->_indices_size.push_back(num_rows() + 1);
84
85 this->_indices.push_back(Memory::Arbiter(sizeof(IT_) * num_nzes()));
86 this->_indices_size.push_back(num_nzes());
87
88 this->_elements.push_back(Memory::Arbiter(sizeof(DT_) * (num_nzes() * entries_per_nonzero())));
89 this->_elements_size.push_back(num_nzes() * entries_per_nonzero());
90 }
91
99 explicit MatrixMirrorBuffer(const Adjacency::Graph & graph, Index entries_per_nonzero_in) :
100 MatrixMirrorBuffer(graph.get_num_nodes_domain(), graph.get_num_nodes_image(), graph.get_num_indices(), entries_per_nonzero_in)
101 {
102 const Index num_nnze = graph.get_num_indices();
103 const Index num_rows = graph.get_num_nodes_domain();
104 const Index * dom_ptr(graph.get_domain_ptr());
105 const Index * img_idx(graph.get_image_idx());
106
107 Memory::TypedView<IT_> prow_ptr = this->row_ptr_view_w();
108 Memory::TypedView<IT_> pcol_idx = this->col_idx_view_w();
109
110 FEAT_PRAGMA_OMP(parallel for)
111 for(Index i = 0; i <= num_rows; ++i)
112 prow_ptr[i] = IT_(dom_ptr[i]);
113
114 FEAT_PRAGMA_OMP(parallel for)
115 for(Index i = 0; i < num_nnze; ++i)
116 pcol_idx[i] = IT_(img_idx[i]);
117 }
118
132 explicit MatrixMirrorBuffer(const Index rows_in, const Index columns_in, Index entries_per_nonzero_in,
133 DenseVector<IT_, IT_> & col_idx_in, DenseVector<DT_, IT_> & val_in, DenseVector<IT_, IT_> & row_ptr_in)
134 {
135 XASSERT(val_in.size() % entries_per_nonzero_in == 0);
136 XASSERT(val_in.size() == col_idx_in.size() * entries_per_nonzero_in);
137
138 this->_scalar_index.push_back(rows_in);
139 this->_scalar_index.push_back(columns_in);
140 this->_scalar_index.push_back(col_idx_in.size());
141 this->_scalar_index.push_back(entries_per_nonzero_in);
142
143 this->_indices.push_back(row_ptr_in.elements_arbiter().attach());
144 this->_indices_size.push_back(row_ptr_in.size());
145 this->_indices.push_back(col_idx_in.elements_arbiter().attach());
146 this->_indices_size.push_back(col_idx_in.size());
147 this->_elements.push_back(val_in.elements_arbiter().attach());
148 this->_elements_size.push_back(val_in.size());
149 }
150
159 Container<DT_, IT_>(std::forward<MatrixMirrorBuffer>(other))
160 {
161 }
162
171 {
172 this->move(std::forward<MatrixMirrorBuffer>(other));
173 return *this;
174 }
175
184 {
186 t.clone(*this, clone_mode);
187 return t;
188 }
189
198 template<typename DT2_, typename IT2_>
200 {
201 Container<DT_, IT_>::clone(other, clone_mode);
202 }
203
211 template <typename DT2_, typename IT2_>
213 {
214 this->assign(other);
215 }
216
223 {
224 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(0);
225 }
226
233 {
234 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(1);
235 }
236
243 {
244 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(2);
245 }
246
253 {
254 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(3);
255 }
256
265 {
266 return this->_scalar_index.empty() ? Index(0) : this->_scalar_index.at(2) * this->_scalar_index.at(3);
267 }
268
269
272 {
273 return this->_indices.at(0);
274 }
275
278 {
279 return this->_indices.at(0);
280 }
281
284 {
285 return this->_indices.at(1);
286 }
287
290 {
291 return this->_indices.at(1);
292 }
293
296 {
297 return this->_elements.front();
298 }
299
302 {
303 return this->_elements.front();
304 }
305
307 {
308 if(this->_elements.empty())
309 return Memory::TypedView<DT_>();
310 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::read));
311 }
312
314 {
315 if(this->_elements.empty())
316 return Memory::TypedView<DT_>();
317 return Memory::TypedView<DT_>(this->_elements.at(0).view(loc, Memory::Access::write));
318 }
319
320 Memory::TypedView<DT_> val_view_rw(Memory::Location loc = Memory::Location::main)
321 {
322 if(this->_elements.empty())
323 return Memory::TypedView<DT_>();
324 return Memory::TypedView<IT_>(this->_elements.at(0).view(loc, Memory::Access::read_write));
325 }
326
327 Memory::TypedView<DT_> val_view(Memory::Location loc, Memory::Access acc)
328 {
329 if(this->_elements.empty())
330 return Memory::TypedView<DT_>();
331 return Memory::TypedView<IT_>(this->_elements.at(0).view(loc, acc));
332 }
333
334 Memory::TypedView<IT_> row_ptr_view_r(Memory::Location loc = Memory::Location::main) const
335 {
336 if(this->_indices.empty())
337 return Memory::TypedView<IT_>();
338 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::read));
339 }
340
341 Memory::TypedView<IT_> row_ptr_view_w(Memory::Location loc = Memory::Location::main)
342 {
343 if(this->_indices.empty())
344 return Memory::TypedView<IT_>();
345 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::write));
346 }
347
348 Memory::TypedView<IT_> row_ptr_view_rw(Memory::Location loc = Memory::Location::main)
349 {
350 if(this->_indices.empty())
351 return Memory::TypedView<IT_>();
352 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, Memory::Access::read_write));
353 }
354
355 Memory::TypedView<IT_> row_ptr_view(Memory::Location loc, Memory::Access acc)
356 {
357 if(this->_indices.empty())
358 return Memory::TypedView<IT_>();
359 return Memory::TypedView<IT_>(this->_indices.at(0).view(loc, acc));
360 }
361
362 Memory::TypedView<IT_> col_idx_view_r(Memory::Location loc = Memory::Location::main) const
363 {
364 if(this->_indices.empty())
365 return Memory::TypedView<IT_>();
366 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::read));
367 }
368
369 Memory::TypedView<IT_> col_idx_view_w(Memory::Location loc = Memory::Location::main)
370 {
371 if(this->_indices.empty())
372 return Memory::TypedView<IT_>();
373 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::write));
374 }
375
376 Memory::TypedView<IT_> col_idx_view_rw(Memory::Location loc = Memory::Location::main)
377 {
378 if(this->_indices.empty())
379 return Memory::TypedView<IT_>();
380 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, Memory::Access::read_write));
381 }
382
383 Memory::TypedView<IT_> col_idx_view(Memory::Location loc, Memory::Access acc)
384 {
385 if(this->_indices.empty())
386 return Memory::TypedView<IT_>();
387 return Memory::TypedView<IT_>(this->_indices.at(1).view(loc, acc));
388 }
389 }; // class MatrixMirrorBuffer<...>
390 } // namespace LAFEM
391} // namespace FEAT
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
Adjacency Graph implementation.
Definition: graph.hpp:34
Index * get_domain_ptr()
Returns the domain pointer array.
Definition: graph.hpp:359
Index * get_image_idx()
Returns the image node index array.
Definition: graph.hpp:374
Index get_num_indices() const
Returns the total number indices.
Definition: graph.hpp:390
Container base class.
Definition: container.hpp:224
void move(Container &&source)
Assignment move operation.
Definition: container.hpp:1007
void clone(const Container &source, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Definition: container.hpp:904
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
Definition: container.hpp:234
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
Definition: container.hpp:285
std::vector< Memory::Arbiter > _indices
List of pointers to all IT_ dependent arrays.
Definition: container.hpp:232
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
Definition: container.hpp:236
std::vector< Memory::Arbiter > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:230
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:238
Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Matrix Mirror Buffer class template.
Index num_rows() const
Retrieve matrix row count.
const Memory::Arbiter & row_ptr_arbiter() const
Returns a reference to the row-pointer array arbiter.
const Memory::Arbiter & col_idx_arbiter() const
Returns a reference to the column-index array arbiter.
const Memory::Arbiter & val_arbiter() const
Returns a reference to the values array arbiter.
Memory::Arbiter & col_idx_arbiter()
Returns a reference to the column-index array arbiter.
MatrixMirrorBuffer(const Index rows_in, const Index columns_in, Index entries_per_nonzero_in, DenseVector< IT_, IT_ > &col_idx_in, DenseVector< DT_, IT_ > &val_in, DenseVector< IT_, IT_ > &row_ptr_in)
Constructor.
void convert(const MatrixMirrorBuffer< DT2_, IT2_ > &other)
Conversion method.
MatrixMirrorBuffer clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
Memory::Arbiter & val_arbiter()
Returns a reference to the values array arbiter.
MatrixMirrorBuffer(MatrixMirrorBuffer &&other)
Move Constructor.
Index num_cols() const
Retrieve matrix column count.
Memory::Arbiter & row_ptr_arbiter()
Returns a reference to the row-pointer array arbiter.
MatrixMirrorBuffer(Index rows_in, Index columns_in, Index used_elements_in, Index entries_per_nonzero_in)
Basic Constructor.
MatrixMirrorBuffer & operator=(MatrixMirrorBuffer &&other)
Assignment move operator.
MatrixMirrorBuffer()=default
Constructor.
Index num_nzes() const
Retrieve non zero element count.
MatrixMirrorBuffer(const Adjacency::Graph &graph, Index entries_per_nonzero_in)
Constructor.
Index num_nzes_raw() const
Retrieve total length of value array.
void clone(const MatrixMirrorBuffer< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Index entries_per_nonzero() const
Retrieve entries per non zero element count.
Memory arbiter class.
Arbiter attach(std::size_t offset=0u, std::size_t size=full_size) const
Creates a new arbiter that is attached to the same memory block as this arbiter.
Typed memory view class.
Access
Memory access enumeration.
@ read_write
read-write access
@ read
read-only access
@ write
write-only access (see attention note above)
Location
Memory location enumeration.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.