FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
power_col_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 PowerColMatrix;
46
48 typedef PowerColMatrix<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;
62 typedef typename SubMatrixType::VectorTypeR VectorTypeR;
64 template <typename DT2_ = DataType, typename IT2_ = IndexType>
66
68 static constexpr int num_row_blocks = blocks_;
70 static constexpr int num_col_blocks = 1;
71
72 protected:
77
79 explicit PowerColMatrix(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 PowerColMatrix(FileMode mode, const String& filename)
114 {
115 read_from(mode, filename);
116 }
117
128 explicit PowerColMatrix(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, const 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 powercolmatrix coordinate real general") == String::npos)
167 XABORTM("Input-file is not a complatible file");
168
169 PowerColMatrix 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 powercolmatrix coordinate real general\n";
225 for (Index i(1); i <= blocks_; ++i)
226 {
227 file << filename << "_pc" << 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 + "_pc" + stringify(length + 1 - blocks_) + suffix);
246 _rest.write_out_submatrices(mode, directory, prefix, suffix, length);
247 }
248
253 {
254 return PowerColMatrix(_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(j_ == 0, "invalid sub-matrix index");
279 static_assert((0 <= i_) && (i_ < blocks_), "invalid sub-matrix index");
281 }
282
284 template<int i_, int j_>
285 const SubMatrixType& at() const
286 {
287 static_assert(j_ == 0, "invalid sub-matrix index");
288 static_assert((0 <= i_) && (i_ < blocks_), "invalid sub-matrix index");
290 }
291
301 SubMatrixType& get(int i, int j)
302 {
303 XASSERTM((j == 0) && (0 <= i) && (i < blocks_), "invalid sub-matrix index");
304 return (i == 0) ? _first : _rest.get(i-1, j);
305 }
306
308 const SubMatrixType& get(int i, int j) const
309 {
310 XASSERTM((j == 0) && (0 <= i) && (i < blocks_), "invalid sub-matrix index");
311 return (i == 0) ? _first : _rest.get(i-1, j);
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() + rest().num_rows();
355 }
356
357 Index num_rows_raw() const
358 {
359 return first().num_rows_raw() + rest().num_rows_raw();
360 }
361
369 {
370 return rest().num_cols();
371 }
372
373 Index num_cols_raw() const
374 {
375 return 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("PowerColMatrix<") + 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.first(), x);
442 rest().apply(r.rest(), x);
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> r_first(r, first().num_rows(), 0);
451 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
452
453 first().apply(r_first, x);
454 rest().apply(r_rest, x);
455 }
456
469 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
470 {
471 first().apply_transposed(r, x.first());
472 rest().apply_transposed(r, x.rest(), r, DataType(1));
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> x_first(x, first().num_rows(), 0);
481 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
482
483 first().apply_transposed(r, x_first);
484 rest().apply_transposed(r, x_rest, r, DataType(1));
485 }
486
503 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
504 {
505 first().apply(r.first(), x, y.first(), alpha);
506 rest().apply(r.rest(), x, y.rest(), 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> r_first(r, first().num_rows(), 0);
517 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
518
519 DenseVector<DataType, IndexType> y_first(y, first().num_rows(), 0);
520 DenseVector<DataType, IndexType> y_rest(y, rest().num_rows(), first().num_rows());
521
522 first().apply(r_first, x, y_first, alpha);
523 rest().apply(r_rest, x, y_rest, alpha);
524 }
525
542 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
543 {
544 first().apply_transposed(r, x.first(), y, alpha);
545 rest().apply_transposed(r, x.rest(), r, alpha);
546 }
547
549 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
550 {
551 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
552 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
553 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
554
555 DenseVector<DataType, IndexType> x_first(x, first().num_rows(), 0);
556 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
557
558 first().apply_transposed(r, x_first, y, alpha);
559 rest().apply_transposed(r, x_rest, r, 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 PowerColMatrix& x) const
582 {
583 return this->first().same_layout(x.first()) && this->rest().same_layout(x.rest());
584 }
585
588 {
589 return VectorTypeL(first().create_vector_l(), rest().create_vector_l());
590 }
591
594 {
595 return first().create_vector_r();
596 }
597
599 Index row_degree(const Index row) const
600 {
601 const Index first_rows = first().num_rows_raw();
602 if(row < first_rows)
603 return first().row_degree(row);
604 else
605 return rest().row_degree(row - first_rows);
606 }
607
608 template<typename IT2_>
609 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
610 {
611 const Index first_rows = first().num_rows_raw();
612 if(row < first_rows)
613 return first().get_row_col_indices(row, pcol_idx, col_offset);
614 else
615 return rest().get_row_col_indices(row - first_rows, pcol_idx, col_offset);
616 }
617
618 template<typename DT2_>
619 Index get_row_values(const Index row, DT2_ * const pvals) const
620 {
621 const Index first_rows = first().num_rows_raw();
622 if(row < first_rows)
623 return first().get_row_values(row, pvals);
624 else
625 return rest().get_row_values(row - first_rows, pvals);
626 }
627
628 template<typename DT2_>
629 Index set_row_values(const Index row, const DT2_ * const pvals)
630 {
631 const Index first_rows = first().num_rows_raw();
632 if(row < first_rows)
633 return first().set_row_values(row, pvals);
634 else
635 return rest().set_row_values(row - first_rows, pvals);
636 }
637
639
641 std::uint64_t get_checkpoint_size(SerialConfig& config)
642 {
643 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
644 }
645
647 void restore_from_checkpoint_data(std::vector<char> & data)
648 {
649 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
650 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
651 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
652 std::vector<char> buffer_first(start, last_of_first);
653 _first.restore_from_checkpoint_data(buffer_first);
654
655 data.erase(std::begin(data), last_of_first);
657 }
658
660 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
661 {
662 std::size_t old_size = data.size();
663 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
664 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
665 char* csize = reinterpret_cast<char*>(&ireal_size);
666 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
667 {
668 data[old_size + i] = csize[i];
669 }
670
671 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
672 }
673
681 template <typename SubType2_>
683 {
684 this->first().convert(source.first());
685 this->rest().convert(source.rest());
686 }
687
688 template <typename SubType2_>
689 void copy(const PowerColMatrix<SubType2_, blocks_> & source)
690 {
691 this->first().copy(source.first());
692 this->rest().copy(source.rest());
693 }
694
695 template <typename SubType2_>
696 void copy_to(PowerColMatrix<SubType2_, blocks_> & target) const
697 {
698 this->first().copy_to(target.first());
699 this->rest().copy_to(target.rest());
700 }
701 };
702
704 template<typename SubType_>
705 class PowerColMatrix<SubType_, 1>
706 {
707 template<typename, int>
708 friend class PowerColMatrix;
709
710 public:
711 typedef SubType_ SubMatrixType;
712 typedef typename SubMatrixType::DataType DataType;
713 typedef typename SubMatrixType::IndexType IndexType;
715 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
717 typedef PowerVector<typename SubMatrixType::VectorTypeL, 1> VectorTypeL;
719 typedef typename SubMatrixType::VectorTypeR VectorTypeR;
721 template <typename DT2_ = DataType, typename IT2_ = IndexType>
722 using ContainerType = PowerColMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
723
724 static constexpr int num_row_blocks = 1;
725 static constexpr int num_col_blocks = 1;
726
727 protected:
729
731 explicit PowerColMatrix(SubMatrixType&& the_first) :
732 _first(std::move(the_first))
733 {
734 }
735
736 public:
738 PowerColMatrix()
739 {
740 }
741
743 explicit PowerColMatrix(const SparseLayout<IndexType, layout_id>& layout) :
744 _first(layout)
745 {
746 }
747
749 PowerColMatrix(PowerColMatrix&& other) :
750 _first(std::move(other._first))
751 {
752 }
753
755 explicit PowerColMatrix(FileMode mode, String filename)
756 {
757 read_from(mode, filename);
758 }
759
761 explicit PowerColMatrix(FileMode mode, std::istream& file, String directory = "")
762 {
763 String line;
764 do {
765 if (file.eof())
766 XABORTM("Wrong Input-file");
767 std::getline(file, line);
768 line.trim_me();
769 } while (line.find("%%") == 0 || line == "");
770
771 SubMatrixType tmp_first(mode, directory + line);
772 _first = std::move(tmp_first);
773 }
774
775 void read_from(FileMode mode, String filename)
776 {
777 String directory;
778 auto found = filename.rfind("/");
779 if (found != std::string::npos)
780 {
781 directory = filename.substr(0, found + 1);
782 }
783
784 std::ifstream file(filename.c_str(), std::ifstream::in);
785 if (! file.is_open())
786 XABORTM("Unable to open Matrix file " + filename);
787
788 PowerColMatrix other(mode, file, directory);
789
790 _first = std::move(other._first);
791
792 file.close();
793 }
794
796 PowerColMatrix& operator=(PowerColMatrix&& other)
797 {
798 if(this != &other)
799 {
800 _first = std::move(other._first);
801 }
802 return *this;
803 }
804
806 PowerColMatrix(const PowerColMatrix&) = delete;
808 PowerColMatrix& operator=(const PowerColMatrix&) = delete;
809
811 virtual ~PowerColMatrix()
812 {
813 }
814
815 void write_out(FileMode mode, String filename) const
816 {
817 std::ofstream file(filename.c_str(), std::ofstream::out);
818 if (! file.is_open())
819 XABORTM("Unable to open Matrix file " + filename);
820
821 String suffix, directory;
822 auto found = filename.rfind(".");
823 if (found != std::string::npos)
824 {
825 suffix = filename.substr(found);
826 filename.erase(found);
827 }
828 found = filename.rfind("/");
829 if (found != std::string::npos)
830 {
831 directory = filename.substr(0, found + 1);
832 filename.erase(0, found + 1);
833 }
834
835 file << "%%MatrixMarket powercolmatrix coordinate real general\n";
836 file << filename << "_pc" << 1 << suffix << "\n";
837
838 file.close();
839
840 this->write_out_submatrices(mode, directory, filename, suffix);
841 }
842
843 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
844 {
845 _first.write_out(mode, directory + prefix + "_pc" + stringify(length) + suffix);
846 }
847
848 PowerColMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
849 {
850 return PowerColMatrix(_first.clone(mode));
851 }
852
854 std::size_t bytes() const
855 {
856 return _first.bytes();
857 }
858
859 template<int i, int j>
861 {
862 static_assert(i == 0, "invalid sub-matrix index");
863 static_assert(j == 0, "invalid sub-matrix index");
864 return _first;
865 }
866
867 template<int i, int j>
868 const SubMatrixType& at() const
869 {
870 static_assert(i == 0, "invalid sub-matrix index");
871 static_assert(j == 0, "invalid sub-matrix index");
872 return _first;
873 }
874
875 SubMatrixType& get(int i, int j)
876 {
877 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
878 return _first;
879 }
880
881 const SubMatrixType& get(int i, int j) const
882 {
883 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
884 return _first;
885 }
886
887 SubMatrixType& first()
888 {
889 return _first;
890 }
891
892 const SubMatrixType& first() const
893 {
894 return _first;
895 }
896
897 int row_blocks() const
898 {
899 return 1;
900 }
901
902 int col_blocks() const
903 {
904 return 1;
905 }
906
907 Index num_rows() const
908 {
909 return first().num_rows();
910 }
911
912 Index num_cols() const
913 {
914 return first().num_cols();
915 }
916
917 Index num_nzes() const
918 {
919 return first().num_nzes();
920 }
921
922 Index num_rows_raw() const
923 {
924 return first().num_rows_raw();
925 }
926
927 Index num_cols_raw() const
928 {
929 return first().num_cols_raw();
930 }
931
932 Index num_nzes_raw() const
933 {
934 return first().num_nzes_raw();
935 }
936
937 static String name()
938 {
939 return String("PowerColMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
940 }
941
942 void format()
943 {
944 first().format();
945 }
946
947 void format(DataType value)
948 {
949 first().format(value);
950 }
951
952 void clear()
953 {
954 first().clear();
955 }
956
957 void apply(VectorTypeL& r, const VectorTypeR& x) const
958 {
959 first().apply(r.first(), x);
960 }
961
962 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
963 {
964 first().apply(r, x);
965 }
966
967 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
968 {
969 first().apply(r.first(), x, y.first(), alpha);
970 }
971
972 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
973 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
974 {
975 first().apply(r, x, y, alpha);
976 }
977
978 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
979 {
980 first().apply_transposed(r, x.first());
981 }
982
983 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
984 {
985 first().apply_transposed(r, x);
986 }
987
988 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
989 {
990 first().apply_transposed(r, x.first(), y, alpha);
991 }
992
993 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
994 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
995 {
996 first().apply_transposed(r, x, y, alpha);
997 }
998
1005 DataType max_rel_diff(const PowerColMatrix& x) const
1006 {
1007 return this->first().max_rel_diff(x.first());
1008 }
1009
1012 {
1013 return VectorTypeL(first().create_vector_l());
1014 }
1015
1018 {
1019 return VectorTypeR(first().create_vector_r());
1020 }
1021
1022 Index row_degree(const Index row) const
1023 {
1024 return first().row_degree(row);
1025 }
1026
1027 template<typename IT2_>
1028 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1029 {
1030 return first().get_row_col_indices(row, pcol_idx, col_offset);
1031 }
1032
1033 template<typename DT2_>
1034 Index get_row_values(const Index row, DT2_ * const pvals) const
1035 {
1036 return first().get_row_values(row, pvals);
1037 }
1038
1039 template<typename DT2_>
1040 Index set_row_values(const Index row, const DT2_ * const pvals)
1041 {
1042 return first().set_row_values(row, pvals);
1043 }
1044
1046 std::uint64_t get_checkpoint_size(SerialConfig& config)
1047 {
1048 return _first.get_checkpoint_size(config);
1049 }
1050
1052 void restore_from_checkpoint_data(std::vector<char> & data)
1053 {
1054 _first.restore_from_checkpoint_data(data);
1055 }
1056
1058 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1059 {
1060 return _first.set_checkpoint_data(data, config);
1061 }
1062
1070 template <typename SubType2_>
1071 void convert(const PowerColMatrix<SubType2_, 1> & source)
1072 {
1073 this->first().convert(source.first());
1074 }
1075
1076 template <typename SubType2_>
1077 void copy(const PowerColMatrix<SubType2_, 1> & source)
1078 {
1079 this->first().copy(source.first());
1080 }
1081
1082 template <typename SubType2_>
1083 void copy_to(PowerColMatrix<SubType2_, 1> & target) const
1084 {
1085 this->first().copy_to(target.first());
1086 }
1087
1096 bool same_layout(const PowerColMatrix& x) const
1097 {
1098 return this->first().same_layout(x.first());
1099 }
1100 };
1102 } // namespace LAFEM
1103} // 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-Col-Matrix meta class template.
PowerColMatrix(const PowerColMatrix &)=delete
deleted copy-ctor
PowerColMatrix< typename SubType_::template ContainerType< DT2_, IT2_ >, blocks_ > ContainerType
Our 'base' class type.
PowerColMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a deep copy of this matrix.
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
void restore_from_checkpoint_data(std::vector< char > &data)
Extract object from checkpoint.
SubMatrixType _first
the last sub-matrix
PowerVector< typename SubMatrixType::VectorTypeL, blocks_ > VectorTypeL
Compatible L-vector type.
std::uint64_t get_checkpoint_size(SerialConfig &config)
Calculate size.
const SubMatrixType & get(int i, int j) const
Returns a sub-matrix block.
void apply(VectorTypeL &r, const VectorTypeR &x, const VectorTypeL &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
PowerColMatrix & operator=(const PowerColMatrix &)=delete
deleted copy-assign operator
void write_out(FileMode mode, String filename) const
Write out matrix to file.
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
SubMatrixType::DataType DataType
sub-matrix data type
Index num_cols() const
Returns the total number of columns in this matrix.
PowerColMatrix(PowerColMatrix &&other)
move ctor
PowerColMatrix(FileMode mode, const String &filename)
Constructor.
SubType_ SubMatrixType
sub-matrix type
virtual ~PowerColMatrix()
virtual destructor
Index num_nzes() const
Returns the total number of non-zeros in this matrix.
Index num_rows() const
Returns the total number of rows in this matrix.
static constexpr int num_row_blocks
number of row blocks (vertical size)
SubMatrixType & get(int i, int j)
Returns a sub-matrix block.
std::uint64_t set_checkpoint_data(std::vector< char > &data, SerialConfig &config)
PowerColMatrix(const SparseLayout< IndexType, layout_id > &layout)
sub-matrix layout ctor
void apply_transposed(VectorTypeR &r, const VectorTypeL &x) const
Applies this matrix onto a vector.
static String name()
Returns a descriptive string for this container.
PowerColMatrix(SubMatrixType &&the_first, RestClass &&the_rest)
base-class constructor; this one is protected for a reason
RestClass _rest
the remaining part
SubMatrixType::IndexType IndexType
sub-matrix index type
PowerColMatrix(FileMode mode, std::istream &file, String directory="")
Constructor.
PowerColMatrix & operator=(PowerColMatrix &&other)
move-assign operator
bool same_layout(const PowerColMatrix &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
void apply_transposed(VectorTypeR &r, const VectorTypeL &x, const VectorTypeR &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
void write_out_submatrices(FileMode mode, String directory, String prefix, String suffix, Index length=blocks_) const
Write out submatrices to file.
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Applies this matrix onto a vector.
static constexpr int num_col_blocks
number of column blocks (horizontal size)
std::size_t bytes() const
Returns the total amount of bytes allocated.
void clear()
Free all allocated arrays.
DataType max_rel_diff(const PowerColMatrix &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
SubMatrixType::VectorTypeR VectorTypeR
Compatible R-vector type.
const SubMatrixType & at() const
Returns a sub-matrix block.
void convert(const PowerColMatrix< SubType2_, blocks_ > &source)
Conversion method.
SubMatrixType & at()
Returns a sub-matrix block.
PowerColMatrix< SubType_, blocks_-1 > RestClass
rest-class typedef
static constexpr SparseLayoutId layout_id
sub-matrix layout type
void format()
Reset all elements of the container to a given value or zero if missing.
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.