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
10#include <kernel/lafem/forward.hpp>
12#include <kernel/util/type_traits.hpp>
13#include <kernel/lafem/container.hpp>
14#include <kernel/adjacency/graph.hpp>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
40 template < typename DT_, typename IT_ = Index>
41 class MatrixMirrorBuffer : public Container<DT_, IT_>
42 {
43 public:
44
46 typedef DT_ DataType;
48 typedef IT_ IndexType;
50 typedef DT_ ValueType;
52 template <typename DT2_ = DT_, typename IT2_ = IT_>
54
56 template <typename DataType2_, typename IndexType2_>
58
64 explicit MatrixMirrorBuffer() :
65 Container<DT_, IT_> (0)
66 {
67 }
68
79 MatrixMirrorBuffer(Index rows_in, Index columns_in, Index used_elements_in, Index entries_per_nonzero_in) :
80 Container<DT_, IT_>(rows_in * columns_in)
81 {
82 this->_scalar_index.push_back(rows_in);
83 this->_scalar_index.push_back(columns_in);
84 this->_scalar_index.push_back(used_elements_in);
85 this->_scalar_index.push_back(entries_per_nonzero_in);
86
87 this->_indices.push_back(MemoryPool::template allocate_memory<IT_>(used_elements()));
88 this->_indices_size.push_back(used_elements());
89
90 this->_indices.push_back(MemoryPool::template allocate_memory<IT_>(rows() + 1));
91 this->_indices_size.push_back(rows() + 1);
92
93 this->_elements.push_back(MemoryPool::template allocate_memory<DT_>(used_elements() * entries_per_nonzero()));
95 }
96
104 explicit MatrixMirrorBuffer(const Adjacency::Graph & graph, Index entries_per_nonzero_in) :
105 Container<DT_, IT_>(0)
106 {
107 Index num_rows = graph.get_num_nodes_domain();
108 Index num_cols = graph.get_num_nodes_image();
109 Index num_nnze = graph.get_num_indices();
110
111 // create temporary vectors
112 LAFEM::DenseVector<IT_, IT_> vrow_ptr(num_rows+1);
113 LAFEM::DenseVector<IT_, IT_> vcol_idx(num_nnze);
114 LAFEM::DenseVector<DT_, IT_> vdata(num_nnze * entries_per_nonzero_in, DT_(0));
115
116 const Index * dom_ptr(graph.get_domain_ptr());
117 const Index * img_idx(graph.get_image_idx());
118 IT_ * prow_ptr(vrow_ptr.elements());
119 IT_ * pcol_idx(vcol_idx.elements());
120
121 // build row-end
122 prow_ptr[0] = IT_(dom_ptr[0]);
123 for(Index i(0); i < num_rows; ++i)
124 prow_ptr[i+1] = IT_(dom_ptr[i+1]);
125
126 // build col-idx
127 for(Index i(0); i < num_nnze; ++i)
128 pcol_idx[i] = IT_(img_idx[i]);
129
130 // build the matrix
131 this->move(MatrixMirrorBuffer<DT_, IT_>(num_rows, num_cols, entries_per_nonzero_in, vcol_idx, vdata, vrow_ptr));
132 }
133
147 explicit MatrixMirrorBuffer(const Index rows_in, const Index columns_in, Index entries_per_nonzero_in,
148 DenseVector<IT_, IT_> & col_ind_in, DenseVector<DT_, IT_> & val_in, DenseVector<IT_, IT_> & row_ptr_in) :
149 Container<DT_, IT_>(rows_in * columns_in)
150 {
151 XASSERT(val_in.size() % entries_per_nonzero_in == 0);
152 XASSERT(val_in.size() == col_ind_in.size() * entries_per_nonzero_in);
153
154 this->_scalar_index.push_back(rows_in);
155 this->_scalar_index.push_back(columns_in);
156 this->_scalar_index.push_back(col_ind_in.size());
157 this->_scalar_index.push_back(entries_per_nonzero_in);
158
159 this->_elements.push_back(val_in.elements());
160 this->_elements_size.push_back(val_in.size());
161 this->_indices.push_back(col_ind_in.elements());
162 this->_indices_size.push_back(col_ind_in.size());
163 this->_indices.push_back(row_ptr_in.elements());
164 this->_indices_size.push_back(row_ptr_in.size());
165
166 for (Index i(0) ; i < this->_elements.size() ; ++i)
168 for (Index i(0) ; i < this->_indices.size() ; ++i)
170 }
171
179 template <typename DT2_ = DT_, typename IT2_ = IT_>
180 explicit MatrixMirrorBuffer(std::vector<char> input) :
181 Container<DT_, IT_>(0)
182 {
183 deserialize<DT2_, IT2_>(input);
184 }
185
194 Container<DT_, IT_>(std::forward<MatrixMirrorBuffer>(other))
195 {
196 }
197
206 {
207 this->move(std::forward<MatrixMirrorBuffer>(other));
208
209 return *this;
210 }
211
220 {
222 t.clone(*this, clone_mode);
223 return t;
224 }
225
234 template<typename DT2_, typename IT2_>
236 {
237 Container<DT_, IT_>::clone(other, clone_mode);
238 }
239
247 template <typename DT2_, typename IT2_>
249 {
250 this->assign(other);
251 }
252
260 template <typename DT2_ = DT_, typename IT2_ = IT_>
261 void deserialize(std::vector<char> input)
262 {
263 this->template _deserialize<DT2_, IT2_>(FileMode::fm_csr, input);
264 }
265
273 template <typename DT2_ = DT_, typename IT2_ = IT_>
274 std::vector<char> serialize() const
275 {
276 return this->template _serialize<DT2_, IT2_>(FileMode::fm_csr);
277 }
278
284 template <Perspective = Perspective::native>
285 Index rows() const
286 {
287 return this->_scalar_index.at(1);
288 }
289
295 template <Perspective = Perspective::native>
297 {
298 return this->_scalar_index.at(2);
299 }
300
306 template <Perspective = Perspective::native>
308 {
309 return this->_scalar_index.at(3);
310 }
311
317 template <Perspective = Perspective::native>
319 {
320 return this->_scalar_index.at(4);
321 }
322
330 template <Perspective = Perspective::native>
332 {
333 return this->_scalar_index.at(3) * this->_scalar_index.at(4);
334 }
335
341 IT_ * col_ind()
342 {
343 if (this->_indices.size() == 0)
344 return nullptr;
345
346 return this->_indices.at(0);
347 }
348
349 IT_ const * col_ind() const
350 {
351 if (this->_indices.size() == 0)
352 return nullptr;
353
354 return this->_indices.at(0);
355 }
356
362 DT_ * val()
363 {
364 if (this->_elements.size() == 0)
365 return nullptr;
366
367 return this->_elements.at(0);
368 }
369
370 DT_ const * val() const
371 {
372 if (this->_elements.size() == 0)
373 return nullptr;
374
375 return this->_elements.at(0);
376 }
377
383 IT_ * row_ptr()
384 {
385 if (this->_indices.size() == 0)
386 return nullptr;
387
388 return this->_indices.at(1);
389 }
390
391 IT_ const * row_ptr() const
392 {
393 if (this->_indices.size() == 0)
394 return nullptr;
395
396 return this->_indices.at(1);
397 }
398
399 }; //MatrixMirrorBuffer
400
401 } // namespace LAFEM
402} // 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:220
std::vector< DT_ * > _elements
List of pointers to all datatype dependent arrays.
Definition: container.hpp:226
std::vector< Index > _elements_size
List of corresponding datatype array sizes.
Definition: container.hpp:230
Index size() const
Returns the containers size.
Definition: container.hpp:1136
void assign(const Container< DT2_, IT2_ > &other)
Assignment operation.
Definition: container.hpp:280
std::vector< IT_ * > _indices
List of pointers to all IT_ dependent arrays.
Definition: container.hpp:228
void clone(const Container &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Definition: container.hpp:902
void move(Container &&other)
Assignment move operation.
Definition: container.hpp:989
std::vector< Index > _indices_size
List of corresponding IT_ array sizes.
Definition: container.hpp:232
std::vector< Index > _scalar_index
List of scalars with datatype index.
Definition: container.hpp:234
Dense data vector class template.
DT_ * elements()
Get a pointer to the data array.
Matrix Mirror Buffer class template.
void convert(const MatrixMirrorBuffer< DT2_, IT2_ > &other)
Conversion method.
MatrixMirrorBuffer clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
MatrixMirrorBuffer(MatrixMirrorBuffer &&other)
Move Constructor.
MatrixMirrorBuffer(std::vector< char > input)
Constructor.
Index val_size() const
Retrieve total length of value array.
DT_ * val()
Retrieve non zero element array.
Index columns() const
Retrieve matrix column count.
IT_ * row_ptr()
Retrieve row start index array.
IT_ * col_ind()
Retrieve column indices array.
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.
Index entries_per_nonzero() const
Retrieve entries per non zero element count.
std::vector< char > serialize() const
Serialization of complete container entity.
Index used_elements() const
Retrieve non zero element count.
MatrixMirrorBuffer(const Adjacency::Graph &graph, Index entries_per_nonzero_in)
Constructor.
MatrixMirrorBuffer(const Index rows_in, const Index columns_in, Index entries_per_nonzero_in, DenseVector< IT_, IT_ > &col_ind_in, DenseVector< DT_, IT_ > &val_in, DenseVector< IT_, IT_ > &row_ptr_in)
Constructor.
void clone(const MatrixMirrorBuffer< DT2_, IT2_ > &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Index rows() const
Retrieve matrix row count.
void deserialize(std::vector< char > input)
Deserialization of complete container entity.
static void increase_memory(void *address)
increase memory counter
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.