FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
null_matrix.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
9#include <kernel/lafem/dense_vector.hpp>
10#include <kernel/lafem/dense_vector_blocked.hpp>
11
12
13namespace FEAT
14{
15 namespace LAFEM
16 {
18 namespace Intern
19 {
20 template<typename DT_, typename IT_, int size_>
21 struct BlockedVectorHelper
22 {
23 static_assert(size_ > 1, "invalid block size");
24 typedef DenseVectorBlocked<DT_, IT_, size_> VectorType;
25 };
26
27 template<typename DT_, typename IT_>
28 struct BlockedVectorHelper<DT_, IT_, 1>
29 {
30 typedef DenseVector<DT_, IT_> VectorType;
31 };
32 } // namespace Intern
34
54 template<typename DT_, typename IT_, int block_height_ = 1, int block_width_ = 1>
56 {
57 static_assert(block_height_ > 0, "invalid block size");
58 static_assert(block_width_ > 0, "invalid block size");
59
60 public:
62 typedef DT_ DataType;
64 typedef IT_ IndexType;
66 static constexpr int block_height = block_height_;
68 static constexpr int block_width = block_width_;
71
73 typedef const IT_* ImageIterator;
74
76 template <typename DT2_ = DT_, typename IT2_ = IT_>
78
80 template <typename DataType2_, typename IndexType2_>
82
84 typedef typename Intern::BlockedVectorHelper<DT_, IT_, block_height_>::VectorType VectorTypeL;
86 typedef typename Intern::BlockedVectorHelper<DT_, IT_, block_width_>::VectorType VectorTypeR;
87
88 static constexpr bool is_global = false;
89 static constexpr bool is_local = true;
90
91 private:
93 Index _num_rows, _num_cols;
94
95 public:
96
102 explicit NullMatrix() :
103 _num_rows(0u), _num_cols(0u)
104 {
105 }
106
115 explicit NullMatrix(Index rows_in, Index columns_in) :
116 _num_rows(rows_in), _num_cols(columns_in)
117 {
118 }
119
128 _num_rows(other._num_rows), _num_cols(other._num_cols)
129 {
130 }
131
140 {
141 this->_num_rows = other._num_rows;
142 this->_num_cols = other._num_cols;
143
144 return *this;
145 }
146
155 NullMatrix clone(CloneMode DOXY(clone_mode) = CloneMode::Weak) const
156 {
157 return NullMatrix(_num_rows, _num_cols);
158 }
159
168 template<typename DT2_, typename IT2_>
169 void clone(
171 CloneMode DOXY(clone_mode) = CloneMode::Weak)
172 {
173 this->_num_rows = other.num_rows();
174 this->_num_cols = other.num_cols();
175 }
176
184 template <typename DT2_, typename IT2_>
186 {
187 this->_num_rows = other.num_rows();
188 this->_num_cols = other.num_cols();
189 }
190
193 {
194 return this->_num_rows;
195 }
196
199 {
200 return this->_num_cols;
201 }
202
205 {
206 return Index(0);
207 }
208
211 {
212 return this->_num_rows * Index(block_height_);
213 }
214
217 {
218 return this->_num_cols * Index(block_width_);
219 }
220
223 {
224 return Index(0);
225 }
226
232 static String name()
233 {
234 return "NullMatrix";
235 }
236
243 void resize(Index rows_in, Index columns_in)
244 {
245 this->_num_rows = rows_in;
246 this->_num_cols = columns_in;
247 }
248
254 std::size_t bytes() const
255 {
256 return std::size_t(0);
257 }
258
265 void copy(const NullMatrix & DOXY(x), bool DOXY(full) = false)
266 {
267 // nothing to do here
268 }
269
275 void format(const DT_ DOXY(value) = DT_(0))
276 {
277 // nothing to do here
278 }
279
282
292 void axpy(
293 const NullMatrix & x,
294 const NullMatrix & y,
295 const DT_ DOXY(alpha) = DT_(1))
296 {
297 XASSERTM(x.num_rows() == y.num_rows(), "Matrix rows do not match!");
298 XASSERTM(x.num_rows() == this->num_rows(), "Matrix rows do not match!");
299 XASSERTM(x.num_cols() == y.num_cols(), "Matrix columns do not match!");
300 XASSERTM(x.num_cols() == this->num_cols(), "Matrix columns do not match!");
301 XASSERTM(x.num_nzes() == y.num_nzes(), "Matrix used_elements do not match!");
302 XASSERTM(x.num_nzes() == this->num_nzes(), "Matrix used_elements do not match!");
303
304 // nothing to do here
305 }
306
313 void scale(const NullMatrix & x, const DT_ DOXY(alpha))
314 {
315 XASSERTM(x.num_rows() == this->num_rows(), "Row count does not match!");
316 XASSERTM(x.num_cols() == this->num_cols(), "Column count does not match!");
317 XASSERTM(x.num_nzes() == this->num_nzes(), "Nonzero count does not match!");
318
319 // nothing to do here
320 }
321
327 DT_ norm_frobenius() const
328 {
329 return DT_(0);
330 }
331
338 void row_norm2(VectorTypeL& row_norms) const
339 {
340 XASSERTM(row_norms.size() == this->num_rows(), "Matrix/Vector dimension mismatch");
341
342 row_norms.format();
343 }
344
351 void row_norm2sqr(VectorTypeL& row_norms) const
352 {
353 XASSERTM(row_norms.size() == this->num_rows(), "Matrix/Vector dimension mismatch");
354
355 row_norms.format();
356 }
357
366 {
368 }
369
376 {
377 x = this->transpose();
378 }
379
387 {
388 XASSERTM(r.size() == this->num_rows_raw(), "Vector size of r does not match!");
389 XASSERTM(x.size() == this->num_cols_raw(), "Vector size of x does not match!");
390
391 r.format();
392 }
393
401 {
402 XASSERTM(r.size() == this->num_cols_raw(), "Vector size of r does not match!");
403 XASSERTM(x.size() == this->num_rows_raw(), "Vector size of x does not match!");
404
405 r.format();
406 }
407
415 {
416 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
417 XASSERTM(x.size() == this->num_cols_raw(), "Vector size of x does not match!");
418
419 r.format();
420 }
421
429 {
430 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
431 XASSERTM(x.size() == this->num_rows_raw(), "Vector size of x does not match!");
432
433 r.format();
434 }
435
443 {
444 XASSERTM(r.size() == this->num_rows_raw(), "Vector size of r does not match!");
445 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
446
447 r.format();
448 }
449
457 {
458 XASSERTM(r.size() == this->num_cols_raw(), "Vector size of r does not match!");
459 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
460
461 r.format();
462 }
463
471 {
472 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
473 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
474
475 r.format();
476 }
477
485 {
486 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
487 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
488
489 r.format();
490 }
491
500 void apply(
502 const DenseVector<DT_, IT_> & x,
503 const DenseVector<DT_, IT_> & y,
504 const DT_ DOXY(alpha) = DT_(1)) const
505 {
506 XASSERTM(r.size() == this->num_rows_raw(), "Vector size of r does not match!");
507 XASSERTM(x.size() == this->num_cols_raw(), "Vector size of x does not match!");
508 XASSERTM(y.size() == this->num_rows_raw(), "Vector size of y does not match!");
509
510 r.copy(y);
511 }
512
523 const DenseVector<DT_, IT_> & x,
524 const DenseVector<DT_, IT_> & y,
525 const DT_ DOXY(alpha) = DT_(1)) const
526 {
527 XASSERTM(r.size() == this->num_cols_raw(), "Vector size of r does not match!");
528 XASSERTM(x.size() == this->num_rows_raw(), "Vector size of x does not match!");
529 XASSERTM(y.size() == this->num_cols_raw(), "Vector size of y does not match!");
530
531 r.copy(y);
532 }
533
542 void apply(
544 const DenseVector<DT_, IT_> & x,
546 const DT_ DOXY(alpha) = DT_(1)) const
547 {
548 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
549 XASSERTM(x.size() == this->num_cols_raw(), "Vector size of x does not match!");
550 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
551
552 r.copy(y);
553 }
564 const DenseVector<DT_, IT_> & x,
566 const DT_ DOXY(alpha) = DT_(1)) const
567 {
568 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
569 XASSERTM(x.size() == this->num_rows_raw(), "Vector size of x does not match!");
570 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
571
572 r.copy(y);
573 }
574
575
584 void apply(
587 const DenseVector<DT_, IT_> & y,
588 const DT_ DOXY(alpha) = DT_(1)) const
589 {
590 XASSERTM(r.size() == this->num_rows_raw(), "Vector size of r does not match!");
591 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
592 XASSERTM(y.size() == this->num_rows_raw(), "Vector size of y does not match!");
593
594 r.copy(y);
595 }
596
608 const DenseVector<DT_, IT_> & y,
609 const DT_ DOXY(alpha) = DT_(1)) const
610 {
611 XASSERTM(r.size() == this->num_cols_raw(), "Vector size of r does not match!");
612 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
613 XASSERTM(y.size() == this->num_cols_raw(), "Vector size of y does not match!");
614
615 r.copy(y);
616 }
617
626 void apply(
630 const DT_ DOXY(alpha) = DT_(1)) const
631 {
632 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
633 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
634 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
635
636 r.copy(y);
637 }
638
651 const DT_ DOXY(alpha) = DT_(1)) const
652 {
653 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
654 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
655 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
656
657 r.copy(y);
658 }
659
668 void apply(
671 const DenseVector<DT_, IT_> & y,
672 const DT_ DOXY(alpha) = DT_(1)) const
673 {
674 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
675 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
676 XASSERTM(y.size() == this->num_rows_raw(), "Vector size of y does not match!");
677
678 r.copy(y);
679 }
680
692 const DenseVector<DT_, IT_> & y,
693 const DT_ DOXY(alpha) = DT_(1)) const
694 {
695 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
696 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
697 XASSERTM(y.size() == this->num_cols_raw(), "Vector size of y does not match!");
698
699 r.copy(y);
700 }
701
703
705 void lump_rows(VectorTypeL& lump) const
706 {
707 XASSERTM(lump.size() == num_rows(), "lump vector size does not match matrix row count!");
708 lump.format();
709 }
710
721 {
722 VectorTypeL lump = create_vector_l();
723 lump_rows(lump);
724 return lump;
725 }
726
727
729 void extract_diag(VectorTypeL & diag) const
730 {
731 XASSERTM(diag.size() == num_rows(), "diag size does not match matrix row count!");
732 XASSERTM(num_rows() == num_cols(), "matrix is not square!");
733 diag.format();
734 }
735
738 {
739 VectorTypeL diag = create_vector_l();
740 extract_diag(diag);
741 return diag;
742 }
743
745 // Returns a new compatible L-Vector.
746 VectorTypeL create_vector_l() const
747 {
748 return VectorTypeL(this->num_rows());
749 }
750
751 // Returns a new compatible R-Vector.
752 VectorTypeR create_vector_r() const
753 {
754 return VectorTypeR(this->num_cols());
755 }
756
757 Index row_degree(const Index) const
758 {
759 return Index(0);
760 }
761
762 template<typename IT2_>
763 Index get_row_col_indices(const Index, IT2_ * const, const IT2_) const
764 {
765 return Index(0);
766 }
767
768 template<typename DT2_>
769 Index get_row_values(const Index, DT2_ * const) const
770 {
771 return Index(0);
772 }
773
774 template<typename DT2_>
775 Index set_row_values(const Index, const DT2_ * const)
776 {
777 return Index(0);
778 }
779
781
784 {
785 return size_t(0);
786 }
787
789 void restore_from_checkpoint_data(std::vector<char> & /*data*/)
790 {
791 // nothing to do here
792 }
793
795 void set_checkpoint_data(std::vector<char>& /*data*/)
796 {
797 // nothing to do here
798 }
799
800 /* ******************************************************************* */
801 /* A D J A C T O R I N T E R F A C E I M P L E M E N T A T I O N */
802 /* ******************************************************************* */
803 public:
806 {
807 return num_rows();
808 }
809
812 {
813 return num_cols();
814 }
815
817 inline ImageIterator image_begin(Index domain_node) const
818 {
819 XASSERTM(domain_node < num_rows(), "Domain node index out of range");
820 return nullptr;
821 }
822
824 inline ImageIterator image_end(Index domain_node) const
825 {
826 XASSERTM(domain_node < num_rows(), "Domain node index out of range");
827 return nullptr;
828 }
829 }; // class NullMatrix
830 } // namespace LAFEM
831} // namespace FEAT
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
void format()
Reset all elements of the container to a given value or zero if missing.
Definition: container.hpp:831
Blocked Dense data vector class template.
void copy(const DenseVectorBlocked &x, bool full=false)
Performs .
Index size() const
Returns the size of this vector, i.e. its number of entries.
Dense data vector class template.
void copy(const VT_ &a)
Performs .
Index size() const
Returns the size of this vector, i.e. its number of entries.
Null Matrix implementation.
Definition: null_matrix.hpp:56
Index num_cols() const
Retrieve matrix column count.
void apply(DenseVectorBlocked< DT_, IT_, block_height_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
Index num_nzes() const
Retrieve matrix non-zero element count.
void apply_transposed(DenseVectorBlocked< DT_, IT_, block_width_ > &r, const DenseVectorBlocked< DT_, IT_, block_height_ > &x) const
Calculate .
ImageIterator image_begin(Index domain_node) const
void apply_transposed(DenseVectorBlocked< DT_, IT_, block_width_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
NullMatrix(NullMatrix &&other)
Move Constructor.
DT_ DataType
Our datatype.
Definition: null_matrix.hpp:62
static String name()
Returns a descriptive string.
ImageIterator image_end(Index domain_node) const
IT_ IndexType
Our indextype.
Definition: null_matrix.hpp:64
void apply(DenseVectorBlocked< DT_, IT_, block_height_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVectorBlocked< DT_, IT_, block_height_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
VectorTypeL extract_diag() const
extract main diagonal vector from matrix
NullMatrix & operator=(NullMatrix &&other)
Move operator.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, block_height_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void format(const DT_ value=DT_(0))
Reset all elements of the container to a given value or zero if missing.
Index num_rows_raw() const
Retrieve matrix row count.
Tiny::Matrix< DataType, block_height, block_width > ValueType
Value type, meaning the type of each block.
Definition: null_matrix.hpp:70
void copy(const NullMatrix &x, bool full=false)
Performs .
NullMatrix< DT_, IT_, block_width_, block_height_ > transpose() const
Calculate .
void lump_rows(VectorTypeL &lump) const
NullMatrix()
Constructor.
static constexpr int block_height
Our block height.
Definition: null_matrix.hpp:66
void apply_transposed(DenseVectorBlocked< DT_, IT_, block_width_ > &r, const DenseVectorBlocked< DT_, IT_, block_height_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
DT_ norm_frobenius() const
Calculates the Frobenius norm of this matrix.
std::size_t bytes() const
Returns the total amount of bytes allocated.
void apply(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, block_width_ > &x) const
Calculate .
Intern::BlockedVectorHelper< DT_, IT_, block_width_ >::VectorType VectorTypeR
Compatible R-vector type.
Definition: null_matrix.hpp:86
void convert(const NullMatrix< DT2_, IT2_, block_height_, block_width_ > &other)
Conversion method.
void transpose(const NullMatrix< DT_, IT_, block_width_, block_height_ > &x)
Calculate .
void scale(const NullMatrix &x, const DT_ alpha)
Calculate .
void apply(DenseVectorBlocked< DT_, IT_, block_height_ > &r, const DenseVectorBlocked< DT_, IT_, block_width_ > &x, const DenseVectorBlocked< DT_, IT_, block_height_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
Index get_num_nodes_domain() const
NullMatrix(Index rows_in, Index columns_in)
Constructor.
void resize(Index rows_in, Index columns_in)
Resizes the matrix to different dimensions.
void extract_diag(VectorTypeL &diag) const
Index get_num_nodes_image() const
Index num_nzes_raw() const
Retrieve matrix non-zero element count.
Index num_rows() const
Retrieve matrix row count.
void apply(DenseVectorBlocked< DT_, IT_, block_height_ > &r, const DenseVectorBlocked< DT_, IT_, block_width_ > &x) const
Calculate .
void row_norm2(VectorTypeL &row_norms) const
Computes the 2-norm for every row.
Index _num_rows
matrix dimensions
Definition: null_matrix.hpp:93
void clone(const NullMatrix< DT2_, IT2_, block_height_, block_width_ > &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
NullMatrix clone(CloneMode clone_mode=CloneMode::Weak) const
Clone operation.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void apply(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x) const
Calculate .
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
VectorTypeL lump_rows() const
Returns the lumped rows vector.
void set_checkpoint_data(std::vector< char > &)
const IT_ * ImageIterator
ImageIterator typedef for Adjactor interface implementation.
Definition: null_matrix.hpp:73
void axpy(const NullMatrix &x, const NullMatrix &y, const DT_ alpha=DT_(1))
Calculate .
void apply_transposed(DenseVectorBlocked< DT_, IT_, block_width_ > &r, const DenseVector< DT_, IT_ > &x, const DenseVectorBlocked< DT_, IT_, block_width_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
uint64_t get_checkpoint_size()
Calculate size.
static constexpr int block_width
Our block width.
Definition: null_matrix.hpp:68
void restore_from_checkpoint_data(std::vector< char > &)
Extract object from checkpoint.
void apply_transposed(DenseVectorBlocked< DT_, IT_, block_width_ > &r, const DenseVectorBlocked< DT_, IT_, block_height_ > &x, const DenseVectorBlocked< DT_, IT_, block_width_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
Intern::BlockedVectorHelper< DT_, IT_, block_height_ >::VectorType VectorTypeL
Compatible L-vector type.
Definition: null_matrix.hpp:84
Index num_cols_raw() const
Retrieve matrix column count.
void apply_transposed(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, block_height_ > &x) const
Calculate .
void row_norm2sqr(VectorTypeL &row_norms) const
Computes the square of the 2-norm for every row.
void apply(DenseVector< DT_, IT_ > &r, const DenseVectorBlocked< DT_, IT_, block_width_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
void apply(DenseVectorBlocked< DT_, IT_, block_height_ > &r, const DenseVectorBlocked< DT_, IT_, block_width_ > &x, const DenseVector< DT_, IT_ > &y, const DT_ alpha=DT_(1)) const
Calculate .
String class implementation.
Definition: string.hpp:47
Tiny Matrix class template.
LAFEM common type definitions.
FEAT namespace.
Definition: adjactor.hpp:12
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.