FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
power_row_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
8// includes, FEAT
9#include <kernel/lafem/power_vector.hpp>
10#include <kernel/lafem/sparse_layout.hpp>
11#include <kernel/lafem/meta_element.hpp>
12#include <kernel/lafem/container.hpp>
13
14
15#include <fstream>
16
17namespace FEAT
18{
19 namespace LAFEM
20 {
35 template<
36 typename SubType_,
37 int blocks_>
39 {
40 // Note: the case = 1 is specialized below
41 static_assert(blocks_ > 1, "invalid block size");
42
43 // declare this class template as a friend for recursive inheritance
44 template<typename, int>
45 friend class PowerRowMatrix;
46
48 typedef PowerRowMatrix<SubType_, blocks_-1> RestClass;
49
50 public:
52 typedef SubType_ SubMatrixType;
54 typedef typename SubMatrixType::DataType DataType;
56 typedef typename SubMatrixType::IndexType IndexType;
58 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
60 typedef typename SubMatrixType::VectorTypeL VectorTypeL;
64 template <typename DT2_ = DataType, typename IT2_ = IndexType>
66
68 static constexpr int num_row_blocks = 1;
70 static constexpr int num_col_blocks = blocks_;
71
72 protected:
77
79 explicit PowerRowMatrix(SubMatrixType&& the_first, RestClass&& the_rest) :
80 _first(std::move(the_first)),
81 _rest(std::move(the_rest))
82 {
83 }
84
85 public:
88 {
89 }
90
93 _first(layout),
94 _rest(layout)
95 {
96 }
97
100 _first(std::move(other._first)),
101 _rest(std::move(other._rest))
102 {
103 }
104
113 explicit PowerRowMatrix(FileMode mode, String filename)
114 {
115 read_from(mode, filename);
116 }
117
128 explicit PowerRowMatrix(FileMode mode, std::istream& file, String directory = "")
129 {
130 String line;
131 do {
132 if (file.eof())
133 XABORTM("Wrong Input-file");
134 std::getline(file, line);
135 line.trim_me();
136 } while (line.find("%%") == 0 || line == "");
137
138 SubMatrixType tmp_first(mode, directory + line);
139 _first = std::move(tmp_first);
140
141 RestClass tmp_rest(mode, file, directory);
142 _rest = std::move(tmp_rest);
143 }
144
151 void read_from(FileMode mode, String filename)
152 {
153 String directory;
154 auto found = filename.rfind("/");
155 if (found != std::string::npos)
156 {
157 directory = filename.substr(0, found + 1);
158 }
159
160 std::ifstream file(filename.c_str(), std::ifstream::in);
161 if (! file.is_open())
162 XABORTM("Unable to open Matrix file " + filename);
163
164 String line;
165 std::getline(file, line);
166 if (line.find("%%MatrixMarket powerrowmatrix coordinate real general") == String::npos)
167 XABORTM("Input-file is not a complatible file");
168
169 PowerRowMatrix other(mode, file, directory);
170
171 _first = std::move(other._first);
172 _rest = std::move(other._rest);
173
174 file.close();
175 }
176
179 {
180 if(this != &other)
181 {
182 _first = std::move(other._first);
183 _rest = std::move(other._rest);
184 }
185 return *this;
186 }
187
192
195 {
196 }
197
204 void write_out(FileMode mode, String filename) const
205 {
206 std::ofstream file(filename.c_str(), std::ofstream::out);
207 if (! file.is_open())
208 XABORTM("Unable to open Matrix file " + filename);
209
210 String suffix, directory;
211 auto found = filename.rfind(".");
212 if (found != std::string::npos)
213 {
214 suffix = filename.substr(found);
215 filename.erase(found);
216 }
217 found = filename.rfind("/");
218 if (found != std::string::npos)
219 {
220 directory = filename.substr(0, found + 1);
221 filename.erase(0, found + 1);
222 }
223
224 file << "%%MatrixMarket powerrowmatrix coordinate real general\n";
225 for (Index i(1); i <= blocks_; ++i)
226 {
227 file << filename << "_pr" << i << suffix << "\n";
228 }
229
230 file.close();
231
232 this->write_out_submatrices(mode, directory, filename, suffix);
233 }
234
243 void write_out_submatrices(FileMode mode, String directory, String prefix, String suffix, Index length = blocks_) const
244 {
245 _first.write_out(mode, directory + prefix + "_pr" + stringify(length + 1 - blocks_) + suffix);
246 _rest.write_out_submatrices(mode, directory, prefix, suffix, length);
247 }
248
253 {
254 return PowerRowMatrix(_first.clone(mode), _rest.clone(mode));
255 }
256
258 std::size_t bytes() const
259 {
260 return _first.bytes() + _rest.bytes();
261 }
262
275 template<int i_, int j_>
277 {
278 static_assert(i_ == 0, "invalid sub-matrix index");
279 static_assert((0 <= j_) && (j_ < blocks_), "invalid sub-matrix index");
281 }
282
284 template<int i_, int j_>
285 const SubMatrixType& at() const
286 {
287 static_assert(i_ == 0, "invalid sub-matrix index");
288 static_assert((0 <= j_) && (j_ < blocks_), "invalid sub-matrix index");
290 }
291
301 SubMatrixType& get(int i, int j)
302 {
303 XASSERTM((i == 0) && (0 <= j) && (j < blocks_), "invalid sub-matrix index");
304 return (j == 0) ? _first : _rest.get(i, j-1);
305 }
306
308 const SubMatrixType& get(int i, int j) const
309 {
310 XASSERTM((i == 0) && (0 <= j) && (j < blocks_), "invalid sub-matrix index");
311 return (j == 0) ? _first : _rest.get(i, j-1);
312 }
313
315 SubMatrixType& first()
316 {
317 return _first;
318 }
319
320 const SubMatrixType& first() const
321 {
322 return _first;
323 }
324
325 RestClass& rest()
326 {
327 return _rest;
328 }
329
330 const RestClass& rest() const
331 {
332 return _rest;
333 }
334
335 int row_blocks() const
336 {
337 return num_row_blocks;
338 }
339
340 int col_blocks() const
341 {
342 return num_col_blocks;
343 }
345
353 {
354 return first().num_rows();
355 }
356
357 Index num_rows_raw() const
358 {
359 return first().num_rows_raw();
360 }
361
369 {
370 return first().num_cols() + rest().num_cols();
371 }
372
373 Index num_cols_raw() const
374 {
375 return first().num_cols_raw() + rest().num_cols_raw();
376 }
377
385 {
386 return first().num_nzes() + rest().num_nzes();
387 }
388
389 Index num_nzes_raw() const
390 {
391 return first().num_nzes_raw() + rest().num_nzes_raw();
392 }
393
395 static String name()
396 {
397 return String("PowerRowMatrix<") + SubMatrixType::name() + "," + stringify(blocks_) + ">";
398 }
399
406 void format()
407 {
408 first().format();
409 rest().format();
410 }
411
412 void format(DataType value)
413 {
414 first().format(value);
415 rest().format(value);
416 }
417
421 void clear()
422 {
423 first().clear();
424 rest().clear();
425 }
426
439 void apply(VectorTypeL& r, const VectorTypeR& x) const
440 {
441 first().apply(r, x.first());
442 rest().apply(r, x.rest(), r, DataType(1));
443 }
444
446 {
447 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
448 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
449
450 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
451 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
452
453 first().apply(r, x_first);
454 rest().apply(r, x_rest, r, DataType(1));
455 }
456
469 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
470 {
471 first().apply_transposed(r.first(), x);
472 rest().apply_transposed(r.rest(), x);
473 }
474
476 {
477 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
478 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
479
480 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
481 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
482
483 first().apply_transposed(r_first, x);
484 rest().apply_transposed(r_rest, x);
485 }
486
503 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
504 {
505 first().apply(r, x.first(), y, alpha);
506 rest().apply(r, x.rest(), r, alpha);
507 }
508
510 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
511 {
512 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
513 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
514 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
515
516 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
517 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
518
519 first().apply(r, x_first, y, alpha);
520 rest().apply(r, x_rest, r, alpha);
521 }
522
539 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
540 {
541 first().apply_transposed(r.first(), x, y.first(), alpha);
542 rest().apply_transposed(r.rest(), x, y.rest(), alpha);
543 }
544
546 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
547 {
548 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
549 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
550 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
551
552 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
553 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
554
555 DenseVector<DataType, IndexType> y_first(y, first().num_cols(), 0);
556 DenseVector<DataType, IndexType> y_rest(y, rest().num_cols(), first().num_cols());
557
558 first().apply(r_first, x, y_first, alpha);
559 rest().apply(r_rest, x, y_rest, alpha);
560 }
561
569 {
570 return Math::max(this->first().max_rel_diff(x.first()), this->rest().max_rel_diff(x.rest()));
571 }
572
581 bool same_layout(const PowerRowMatrix& x) const
582 {
583 return this->first().same_layout(x.first()) && (this->rest().same_layout(x.rest()));
584 }
585
588 {
589 return first().create_vector_l();
590 }
591
594 {
595 return VectorTypeR(first().create_vector_r(), rest().create_vector_r());
596 }
597
599 Index row_degree(const Index row) const
600 {
601 return first().row_degree(row) + rest().row_degree(row);
602 }
603
604 template<typename IT2_>
605 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
606 {
607 const Index first_cols = first().num_cols_raw();
608 const Index first_degree = first().get_row_col_indices(row, pcol_idx, col_offset);
609 return first_degree + rest().get_row_col_indices(row, pcol_idx + first_degree, col_offset + IT2_(first_cols));
610 }
611
612 template<typename DT2_>
613 Index get_row_values(const Index row, DT2_ * const pvals) const
614 {
615 const Index first_degree = first().get_row_values(row, pvals);
616 return first_degree + rest().get_row_values(row, pvals + first_degree);
617 }
618
619 template<typename DT2_>
620 Index set_row_values(const Index row, const DT2_ * const pvals)
621 {
622 const Index first_degree = first().set_row_values(row, pvals);
623 return first_degree + rest().set_row_values(row, pvals + first_degree);
624 }
625
627
629 std::uint64_t get_checkpoint_size(SerialConfig& config)
630 {
631 return sizeof(std::uint64_t) + _first.get_checkpoint_size(config) + _rest.get_checkpoint_size(config); //sizeof(std::uint64_t) bits needed to store lenght of checkpointed _first
632 }
633
635 void restore_from_checkpoint_data(std::vector<char> & data)
636 {
637 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
638 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
639 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
640 std::vector<char> buffer_first(start, last_of_first);
641 _first.restore_from_checkpoint_data(buffer_first);
642
643 data.erase(std::begin(data), last_of_first);
645 }
646
648 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
649 {
650 std::size_t old_size = data.size();
651 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
652 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
653 char* csize = reinterpret_cast<char*>(&ireal_size);
654 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
655 {
656 data[old_size +i] = csize[i];
657 }
658
659 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
660 }
661
669 template <typename SubType2_>
671 {
672 this->first().convert(source.first());
673 this->rest().convert(source.rest());
674 }
675
676 template <typename SubType2_>
677 void copy(const PowerRowMatrix<SubType2_, blocks_> & source)
678 {
679 this->first().copy(source.first());
680 this->rest().copy(source.rest());
681 }
682
683 template <typename SubType2_>
684 void copy_to(PowerRowMatrix<SubType2_, blocks_> & target) const
685 {
686 this->first().copy_to(target.first());
687 this->rest().copy_to(target.rest());
688 }
689 };
690
692 template<typename SubType_>
693 class PowerRowMatrix<SubType_, 1>
694 {
695 template<typename, int>
696 friend class PowerRowMatrix;
697
698 public:
699 typedef SubType_ SubMatrixType;
700 typedef typename SubMatrixType::DataType DataType;
701 typedef typename SubMatrixType::IndexType IndexType;
703 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
705 typedef typename SubMatrixType::VectorTypeL VectorTypeL;
707 typedef PowerVector<typename SubMatrixType::VectorTypeR, 1> VectorTypeR;
709 template <typename DT2_ = DataType, typename IT2_ = IndexType>
710 using ContainerType = PowerRowMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
711
712 static constexpr int num_row_blocks = 1;
713 static constexpr int num_col_blocks = 1;
714
715 protected:
717
719 explicit PowerRowMatrix(SubMatrixType&& the_first) :
720 _first(std::move(the_first))
721 {
722 }
723
724 public:
726 PowerRowMatrix()
727 {
728 }
729
731 explicit PowerRowMatrix(const SparseLayout<IndexType, layout_id>& layout) :
732 _first(layout)
733 {
734 }
735
737 PowerRowMatrix(PowerRowMatrix&& other) :
738 _first(std::move(other._first))
739 {
740 }
741
743 explicit PowerRowMatrix(FileMode mode, const String& filename)
744 {
745 read_from(mode, filename);
746 }
747
749 explicit PowerRowMatrix(FileMode mode, std::istream& file, const String& directory = "")
750 {
751 String line;
752 do {
753 if (file.eof())
754 XABORTM("Wrong Input-file");
755 std::getline(file, line);
756 line.trim_me();
757 } while (line.find("%%") == 0 || line == "");
758
759 SubMatrixType tmp_first(mode, directory + line);
760 _first = std::move(tmp_first);
761 }
762
763 void read_from(FileMode mode, const String& filename)
764 {
765 String directory;
766 auto found = filename.rfind("/");
767 if (found != std::string::npos)
768 {
769 directory = filename.substr(0, found + 1);
770 }
771
772 std::ifstream file(filename.c_str(), std::ifstream::in);
773 if (! file.is_open())
774 XABORTM("Unable to open Matrix file " + filename);
775
776 PowerRowMatrix other(mode, file, directory);
777
778 _first = std::move(other._first);
779
780 file.close();
781 }
782
784 PowerRowMatrix& operator=(PowerRowMatrix&& other)
785 {
786 if(this != &other)
787 {
788 _first = std::move(other._first);
789 }
790 return *this;
791 }
792
794 PowerRowMatrix(const PowerRowMatrix&) = delete;
796 PowerRowMatrix& operator=(const PowerRowMatrix&) = delete;
797
799 virtual ~PowerRowMatrix()
800 {
801 }
802
803 void write_out(FileMode mode, String filename) const
804 {
805 std::ofstream file(filename.c_str(), std::ofstream::out);
806 if (! file.is_open())
807 XABORTM("Unable to open Matrix file " + filename);
808
809 String suffix, directory;
810 auto found = filename.rfind(".");
811 if (found != std::string::npos)
812 {
813 suffix = filename.substr(found);
814 filename.erase(found);
815 }
816 found = filename.rfind("/");
817 if (found != std::string::npos)
818 {
819 directory = filename.substr(0, found + 1);
820 filename.erase(0, found + 1);
821 }
822
823 file << "%%MatrixMarket powerrowmatrix coordinate real general\n";
824 file << filename << "_pr" << 1 << suffix << "\n";
825
826 file.close();
827
828 this->write_out_submatrices(mode, directory, filename, suffix);
829 }
830
831 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
832 {
833 _first.write_out(mode, directory + prefix + "_pr" + stringify(length) + suffix);
834 }
835
836 PowerRowMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
837 {
838 return PowerRowMatrix(_first.clone(mode));
839 }
840
842 std::size_t bytes() const
843 {
844 return _first.bytes();
845 }
846
847
848 template<int i, int j>
850 {
851 static_assert(i == 0, "invalid sub-matrix index");
852 static_assert(j == 0, "invalid sub-matrix index");
853 return _first;
854 }
855
856 template<int i, int j>
857 const SubMatrixType& at() const
858 {
859 static_assert(i == 0, "invalid sub-matrix index");
860 static_assert(j == 0, "invalid sub-matrix index");
861 return _first;
862 }
863
864 SubMatrixType& get(int i, int j)
865 {
866 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
867 return _first;
868 }
869
870 const SubMatrixType& get(int i, int j) const
871 {
872 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
873 return _first;
874 }
875
876 SubMatrixType& first()
877 {
878 return _first;
879 }
880
881 const SubMatrixType& first() const
882 {
883 return _first;
884 }
885
886 int row_blocks() const
887 {
888 return 1;
889 }
890
891 int col_blocks() const
892 {
893 return 1;
894 }
895
896 Index num_rows() const
897 {
898 return first().num_rows();
899 }
900
901 Index num_cols() const
902 {
903 return first().num_cols();
904 }
905
906 Index num_nzes() const
907 {
908 return first().num_nzes();
909 }
910
911 Index num_rows_raw() const
912 {
913 return first().num_rows_raw();
914 }
915
916 Index num_cols_raw() const
917 {
918 return first().num_cols_raw();
919 }
920
921 Index num_nzes_raw() const
922 {
923 return first().num_nzes_raw();
924 }
925
926 static String name()
927 {
928 return String("PowerRowMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
929 }
930
931 void format()
932 {
933 first().format();
934 }
935
936 void format(DataType value)
937 {
938 first().format(value);
939 }
940
941 void clear()
942 {
943 first().clear();
944 }
945
946 void apply(VectorTypeL& r, const VectorTypeR& x) const
947 {
948 first().apply(r, x.first());
949 }
950
951 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
952 {
953 first().apply(r, x);
954 }
955
956 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
957 {
958 first().apply(r, x.first(), y, alpha);
959 }
960
961 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
962 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
963 {
964 first().apply(r, x, y, alpha);
965 }
966
967 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
968 {
969 first().apply_transposed(r.first(), x);
970 }
971
972 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
973 {
974 first().apply_transposed(r, x);
975 }
976
977 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
978 {
979 first().apply_transposed(r.first(), x, y.first(), alpha);
980 }
981
982 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
983 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
984 {
985 first().apply_transposed(r, x, y, alpha);
986 }
987
994 DataType max_rel_diff(const PowerRowMatrix& x) const
995 {
996 return this->first().max_rel_diff(x.first());
997 }
998
1007 bool same_layout(const PowerRowMatrix& x) const
1008 {
1009 return this->first().same_layout(x.first());
1010 }
1011
1014 {
1015 return VectorTypeL(first().create_vector_l());
1016 }
1017
1020 {
1021 return VectorTypeR(first().create_vector_r());
1022 }
1023
1024 Index row_degree(const Index row) const
1025 {
1026 return first().row_degree(row);
1027 }
1028
1029 template<typename IT2_>
1030 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1031 {
1032 return first().get_row_col_indices(row, pcol_idx, col_offset);
1033 }
1034
1035 template<typename DT2_>
1036 Index get_row_values(const Index row, DT2_ * const pvals) const
1037 {
1038 return first().get_row_values(row, pvals);
1039 }
1040
1041 template<typename DT2_>
1042 Index set_row_values(const Index row, const DT2_ * const pvals)
1043 {
1044 return first().set_row_values(row, pvals);
1045 }
1046
1048 std::uint64_t get_checkpoint_size(SerialConfig& config)
1049 {
1050 return _first.get_checkpoint_size(config);
1051 }
1052
1054 void restore_from_checkpoint_data(std::vector<char> & data)
1055 {
1056 _first.restore_from_checkpoint_data(data);
1057 }
1058
1060 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1061 {
1062 return _first.set_checkpoint_data(data, config);
1063 }
1064
1072 template <typename SubType2_>
1073 void convert(const PowerRowMatrix<SubType2_, 1> & source)
1074 {
1075 this->first().convert(source.first());
1076 }
1077
1078 template <typename SubType2_>
1079 void copy(const PowerRowMatrix<SubType2_, 1> & source)
1080 {
1081 this->first().copy(source.first());
1082 }
1083
1084 template <typename SubType2_>
1085 void copy_to(PowerRowMatrix<SubType2_, 1> & target) const
1086 {
1087 this->first().copy_to(target.first());
1088 }
1089 };
1091 } // namespace LAFEM
1092} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
Dense data vector class template.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Power-Row-Matrix meta class template.
Index num_rows() const
Returns the total number of rows in this matrix.
const SubMatrixType & get(int i, int j) const
Returns a sub-matrix block.
SubMatrixType & get(int i, int j)
Returns a sub-matrix block.
PowerRowMatrix< SubType_, blocks_-1 > RestClass
rest-class typedef
PowerRowMatrix(const PowerRowMatrix &)=delete
deleted copy-ctor
void convert(const PowerRowMatrix< SubType2_, blocks_ > &source)
Conversion method.
void write_out_submatrices(FileMode mode, String directory, String prefix, String suffix, Index length=blocks_) const
Write out submatrices to file.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Applies this matrix onto a vector.
SubMatrixType & at()
Returns a sub-matrix block.
bool same_layout(const PowerRowMatrix &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
Index num_cols() const
Returns the total number of columns in this matrix.
PowerRowMatrix(FileMode mode, String filename)
Constructor.
void read_from(FileMode mode, String filename)
Read in matrix from file.
void write_out(FileMode mode, String filename) const
Write out matrix to file.
PowerRowMatrix & operator=(const PowerRowMatrix &)=delete
deleted copy-assign operator
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
SubMatrixType::IndexType IndexType
sub-matrix index type
PowerVector< typename SubMatrixType::VectorTypeR, blocks_ > VectorTypeR
Compatible R-vector type.
void format()
Reset all elements of the container to a given value or zero if missing.
void apply(VectorTypeL &r, const VectorTypeR &x, const VectorTypeL &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
std::size_t bytes() const
Returns the total amount of bytes allocated.
PowerRowMatrix(PowerRowMatrix &&other)
move ctor
void restore_from_checkpoint_data(std::vector< char > &data)
Extract object from checkpoint.
Index num_nzes() const
Returns the total number of non-zeros in this matrix.
PowerRowMatrix(SubMatrixType &&the_first, RestClass &&the_rest)
base-class constructor; this one is protected for a reason
SubMatrixType::VectorTypeL VectorTypeL
Compatible L-vector type.
static constexpr int num_col_blocks
number of column blocks (horizontal size)
static constexpr int num_row_blocks
number of row blocks (vertical size)
void apply_transposed(VectorTypeR &r, const VectorTypeL &x, const VectorTypeR &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
std::uint64_t get_checkpoint_size(SerialConfig &config)
Calculate size.
SubType_ SubMatrixType
sub-matrix type
std::uint64_t set_checkpoint_data(std::vector< char > &data, SerialConfig &config)
DataType max_rel_diff(const PowerRowMatrix &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
PowerRowMatrix(const SparseLayout< IndexType, layout_id > &layout)
sub-matrix layout ctor
static String name()
Returns a descriptive string for this container.
SubMatrixType::DataType DataType
sub-matrix data type
static constexpr SparseLayoutId layout_id
sub-matrix layout type
void clear()
Free all allocated arrays.
SubMatrixType _first
the first sub-matrix
virtual ~PowerRowMatrix()
virtual destructor
PowerRowMatrix< typename SubType_::template ContainerType< DT2_, IT2_ >, blocks_ > ContainerType
Our 'base' class type.
PowerRowMatrix & operator=(PowerRowMatrix &&other)
move-assign operator
RestClass _rest
the remaining part
PowerRowMatrix(FileMode mode, std::istream &file, String directory="")
Constructor.
PowerRowMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a deep copy of this matrix.
const SubMatrixType & at() const
Returns a sub-matrix block.
void apply_transposed(VectorTypeR &r, const VectorTypeL &x) const
Applies this matrix onto a vector.
Power-Vector meta class template.
Config class for serialize parameter.
Definition: container.hpp:50
Layout scheme for sparse matrix containers.
String class implementation.
Definition: string.hpp:47
String & trim_me(const String &charset)
Trims this string.
Definition: string.hpp:359
@ other
generic/other permutation strategy
SparseLayoutId
Definition: base.hpp:63
T_ max(T_ a, T_ b)
Returns the maximum of two values.
Definition: math.hpp:137
@ rest
restriction (multigrid)
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:993
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
Power container element helper class template.