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
352 template <Perspective perspective_ = Perspective::native>
353 Index rows() const
354 {
355 return first().template rows<perspective_>();
356 }
357
364 template <Perspective perspective_ = Perspective::native>
366 {
367 return first().template columns<perspective_>() + rest().template columns<perspective_>();
368 }
369
376 template <Perspective perspective_ = Perspective::native>
378 {
379 return first().template used_elements<perspective_>() + rest().template used_elements<perspective_>();
380 }
381
383 static String name()
384 {
385 return String("PowerRowMatrix<") + SubMatrixType::name() + "," + stringify(blocks_) + ">";
386 }
387
388 template <Perspective perspective_ = Perspective::native>
389 Index size() const
390 {
391 return rows(perspective_) * columns(perspective_);
392 }
393
401 {
402 first().format(value);
403 rest().format(value);
404 }
405
409 void clear()
410 {
411 first().clear();
412 rest().clear();
413 }
414
427 void apply(VectorTypeL& r, const VectorTypeR& x) const
428 {
429 first().apply(r, x.first());
430 rest().apply(r, x.rest(), r, DataType(1));
431 }
432
434 {
435 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
436 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
437
438 DenseVector<DataType, IndexType> x_first(x, first().columns(), 0);
439 DenseVector<DataType, IndexType> x_rest(x, rest().columns(), first().columns());
440
441 first().apply(r, x_first);
442 rest().apply(r, x_rest, r, DataType(1));
443 }
444
457 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
458 {
459 first().apply_transposed(r.first(), x);
460 rest().apply_transposed(r.rest(), x);
461 }
462
464 {
465 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
466 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
467
468 DenseVector<DataType, IndexType> r_first(r, first().columns(), 0);
469 DenseVector<DataType, IndexType> r_rest(r, rest().columns(), first().columns());
470
471 first().apply_transposed(r_first, x);
472 rest().apply_transposed(r_rest, x);
473 }
474
491 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
492 {
493 first().apply(r, x.first(), y, alpha);
494 rest().apply(r, x.rest(), r, alpha);
495 }
496
498 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
499 {
500 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
501 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
502 XASSERTM(y.size() == this->rows(), "Vector size of y does not match!");
503
504 DenseVector<DataType, IndexType> x_first(x, first().columns(), 0);
505 DenseVector<DataType, IndexType> x_rest(x, rest().columns(), first().columns());
506
507 first().apply(r, x_first, y, alpha);
508 rest().apply(r, x_rest, r, alpha);
509 }
510
527 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
528 {
529 first().apply_transposed(r.first(), x, y.first(), alpha);
530 rest().apply_transposed(r.rest(), x, y.rest(), alpha);
531 }
532
534 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
535 {
536 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
537 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
538 XASSERTM(y.size() == this->columns(), "Vector size of y does not match!");
539
540 DenseVector<DataType, IndexType> r_first(r, first().columns(), 0);
541 DenseVector<DataType, IndexType> r_rest(r, rest().columns(), first().columns());
542
543 DenseVector<DataType, IndexType> y_first(y, first().columns(), 0);
544 DenseVector<DataType, IndexType> y_rest(y, rest().columns(), first().columns());
545
546 first().apply(r_first, x, y_first, alpha);
547 rest().apply(r_rest, x, y_rest, alpha);
548 }
549
557 {
558 DataType max_rel_diff = Math::max(this->first().max_rel_diff(x.first()), this->rest().max_rel_diff(x.rest()));
559 return max_rel_diff;
560 }
561
570 bool same_layout(const PowerRowMatrix& x) const
571 {
572 return (this->name() == x.name()) && (this->first().same_layout(x.first())) && (this->rest().same_layout(x.rest()));
573 }
574
577 {
578 return first().create_vector_l();
579 }
580
583 {
584 return VectorTypeR(first().create_vector_r(), rest().create_vector_r());
585 }
586
589 {
590 return this->first().get_length_of_line(row) + this->rest().get_length_of_line(row);
591 }
592
595 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
596 const Index col_start, const Index stride = 1) const
597 {
598 const Index length_of_base(this->first().get_length_of_line(row));
599
600 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
601 this->rest().set_line(row, pval_set + stride * length_of_base, pcol_set + stride * length_of_base, col_start + this->first().template columns<Perspective::pod>(), stride);
602 }
603
604 void set_line_reverse(const Index row, const DataType * const pval_set, const Index stride = 1)
605 {
606 const Index length_of_base(this->first().get_length_of_line(row));
607
608 this->first().set_line_reverse(row, pval_set, stride);
609 this->rest().set_line_reverse(row, pval_set + stride * length_of_base, stride);
610 }
611
612 Index row_degree(const Index row) const
613 {
614 return first().row_degree(row) + rest().row_degree(row);
615 }
616
617 template<typename IT2_>
618 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
619 {
620 const Index first_cols = first().template columns<Perspective::pod>();
621 const Index first_degree = first().get_row_col_indices(row, pcol_idx, col_offset);
622 return first_degree + rest().get_row_col_indices(row, pcol_idx + first_degree, col_offset + IT2_(first_cols));
623 }
624
625 template<typename DT2_>
626 Index get_row_values(const Index row, DT2_ * const pvals) const
627 {
628 const Index first_degree = first().get_row_values(row, pvals);
629 return first_degree + rest().get_row_values(row, pvals + first_degree);
630 }
631
632 template<typename DT2_>
633 Index set_row_values(const Index row, const DT2_ * const pvals)
634 {
635 const Index first_degree = first().set_row_values(row, pvals);
636 return first_degree + rest().set_row_values(row, pvals + first_degree);
637 }
638
640
642 std::uint64_t get_checkpoint_size(SerialConfig& config)
643 {
644 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
645 }
646
648 void restore_from_checkpoint_data(std::vector<char> & data)
649 {
650 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
651 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
652 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
653 std::vector<char> buffer_first(start, last_of_first);
654 _first.restore_from_checkpoint_data(buffer_first);
655
656 data.erase(std::begin(data), last_of_first);
658 }
659
661 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
662 {
663 std::size_t old_size = data.size();
664 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
665 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
666 char* csize = reinterpret_cast<char*>(&ireal_size);
667 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
668 {
669 data[old_size +i] = csize[i];
670 }
671
672 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
673 }
674
682 template <typename SubType2_>
684 {
685 this->first().convert(other.first());
686 this->rest().convert(other.rest());
687 }
688
689 template <typename SubType2_>
690 void convert_reverse(PowerRowMatrix<SubType2_, blocks_> & other) const
691 {
692 this->first().convert_reverse(other.first());
693 this->rest().convert_reverse(other.rest());
694 }
695 };
696
698 template<typename SubType_>
699 class PowerRowMatrix<SubType_, 1>
700 {
701 template<typename, int>
702 friend class PowerRowMatrix;
703
704 public:
705 typedef SubType_ SubMatrixType;
706 typedef typename SubMatrixType::DataType DataType;
707 typedef typename SubMatrixType::IndexType IndexType;
709 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
711 typedef typename SubMatrixType::VectorTypeL VectorTypeL;
713 typedef PowerVector<typename SubMatrixType::VectorTypeR, 1> VectorTypeR;
715 template <typename DT2_ = DataType, typename IT2_ = IndexType>
716 using ContainerType = PowerRowMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
717
718 static constexpr int num_row_blocks = 1;
719 static constexpr int num_col_blocks = 1;
720
721 protected:
723
725 explicit PowerRowMatrix(SubMatrixType&& the_first) :
726 _first(std::move(the_first))
727 {
728 }
729
730 public:
732 PowerRowMatrix()
733 {
734 }
735
737 explicit PowerRowMatrix(const SparseLayout<IndexType, layout_id>& layout) :
738 _first(layout)
739 {
740 }
741
743 PowerRowMatrix(PowerRowMatrix&& other) :
744 _first(std::move(other._first))
745 {
746 }
747
749 explicit PowerRowMatrix(FileMode mode, const String& filename)
750 {
751 read_from(mode, filename);
752 }
753
755 explicit PowerRowMatrix(FileMode mode, std::istream& file, const String& directory = "")
756 {
757 String line;
758 do {
759 if (file.eof())
760 XABORTM("Wrong Input-file");
761 std::getline(file, line);
762 line.trim_me();
763 } while (line.find("%%") == 0 || line == "");
764
765 SubMatrixType tmp_first(mode, directory + line);
766 _first = std::move(tmp_first);
767 }
768
769 void read_from(FileMode mode, const String& filename)
770 {
771 String directory;
772 auto found = filename.rfind("/");
773 if (found != std::string::npos)
774 {
775 directory = filename.substr(0, found + 1);
776 }
777
778 std::ifstream file(filename.c_str(), std::ifstream::in);
779 if (! file.is_open())
780 XABORTM("Unable to open Matrix file " + filename);
781
782 PowerRowMatrix other(mode, file, directory);
783
784 _first = std::move(other._first);
785
786 file.close();
787 }
788
790 PowerRowMatrix& operator=(PowerRowMatrix&& other)
791 {
792 if(this != &other)
793 {
794 _first = std::move(other._first);
795 }
796 return *this;
797 }
798
800 PowerRowMatrix(const PowerRowMatrix&) = delete;
802 PowerRowMatrix& operator=(const PowerRowMatrix&) = delete;
803
805 virtual ~PowerRowMatrix()
806 {
807 }
808
809 void write_out(FileMode mode, String filename) const
810 {
811 std::ofstream file(filename.c_str(), std::ofstream::out);
812 if (! file.is_open())
813 XABORTM("Unable to open Matrix file " + filename);
814
815 String suffix, directory;
816 auto found = filename.rfind(".");
817 if (found != std::string::npos)
818 {
819 suffix = filename.substr(found);
820 filename.erase(found);
821 }
822 found = filename.rfind("/");
823 if (found != std::string::npos)
824 {
825 directory = filename.substr(0, found + 1);
826 filename.erase(0, found + 1);
827 }
828
829 file << "%%MatrixMarket powerrowmatrix coordinate real general\n";
830 file << filename << "_pr" << 1 << suffix << "\n";
831
832 file.close();
833
834 this->write_out_submatrices(mode, directory, filename, suffix);
835 }
836
837 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
838 {
839 _first.write_out(mode, directory + prefix + "_pr" + stringify(length) + suffix);
840 }
841
842 PowerRowMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
843 {
844 return PowerRowMatrix(_first.clone(mode));
845 }
846
848 std::size_t bytes() const
849 {
850 return _first.bytes();
851 }
852
853
854 template<int i, int j>
856 {
857 static_assert(i == 0, "invalid sub-matrix index");
858 static_assert(j == 0, "invalid sub-matrix index");
859 return _first;
860 }
861
862 template<int i, int j>
863 const SubMatrixType& at() const
864 {
865 static_assert(i == 0, "invalid sub-matrix index");
866 static_assert(j == 0, "invalid sub-matrix index");
867 return _first;
868 }
869
870 SubMatrixType& get(int i, int j)
871 {
872 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
873 return _first;
874 }
875
876 const SubMatrixType& get(int i, int j) const
877 {
878 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
879 return _first;
880 }
881
882 SubMatrixType& first()
883 {
884 return _first;
885 }
886
887 const SubMatrixType& first() const
888 {
889 return _first;
890 }
891
892 int row_blocks() const
893 {
894 return 1;
895 }
896
897 int col_blocks() const
898 {
899 return 1;
900 }
901
902 template <Perspective perspective_ = Perspective::native>
903 Index rows() const
904 {
905 return first().template rows<perspective_>();
906 }
907
908 template <Perspective perspective_ = Perspective::native>
909 Index columns() const
910 {
911 return first().template columns<perspective_>();
912 }
913
914 template <Perspective perspective_ = Perspective::native>
915 Index used_elements() const
916 {
917 return first().template used_elements<perspective_>();
918 }
919
920 static String name()
921 {
922 return String("PowerRowMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
923 }
924
925 template <Perspective perspective_ = Perspective::native>
926 Index size() const
927 {
928 return rows(perspective_) * columns(perspective_);
929 }
930
931 void format(DataType value = DataType(0))
932 {
933 first().format(value);
934 }
935
936 void clear()
937 {
938 first().clear();
939 }
940
941 void apply(VectorTypeL& r, const VectorTypeR& x) const
942 {
943 first().apply(r, x.first());
944 }
945
946 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
947 {
948 first().apply(r, x);
949 }
950
951 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
952 {
953 first().apply(r, x.first(), y, alpha);
954 }
955
956 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
957 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
958 {
959 first().apply(r, x, y, alpha);
960 }
961
962 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
963 {
964 first().apply_transposed(r.first(), x);
965 }
966
967 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
968 {
969 first().apply_transposed(r, x);
970 }
971
972 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
973 {
974 first().apply_transposed(r.first(), x, y.first(), alpha);
975 }
976
977 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
978 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
979 {
980 first().apply_transposed(r, x, y, alpha);
981 }
982
989 DataType max_rel_diff(const PowerRowMatrix& x) const
990 {
991 return this->first().max_rel_diff(x.first());
992 }
993
1002 bool same_layout(const PowerRowMatrix& x) const
1003 {
1004 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1005 }
1006
1009 {
1010 return VectorTypeL(first().create_vector_l());
1011 }
1012
1015 {
1016 return VectorTypeR(first().create_vector_r());
1017 }
1018
1020 Index get_length_of_line(const Index row) const
1021 {
1022 return this->first().get_length_of_line(row);
1023 }
1024
1026 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
1027 const Index col_start, const Index stride = 1) const
1028 {
1029 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
1030 }
1031
1032 void set_line_reverse(const Index row, const DataType * const pval_set, const Index stride = 1)
1033 {
1034 this->first().set_line_reverse(row, pval_set, stride);
1035 }
1036
1037 Index row_degree(const Index row) const
1038 {
1039 return first().row_degree(row);
1040 }
1041
1042 template<typename IT2_>
1043 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1044 {
1045 return first().get_row_col_indices(row, pcol_idx, col_offset);
1046 }
1047
1048 template<typename DT2_>
1049 Index get_row_values(const Index row, DT2_ * const pvals) const
1050 {
1051 return first().get_row_values(row, pvals);
1052 }
1053
1054 template<typename DT2_>
1055 Index set_row_values(const Index row, const DT2_ * const pvals)
1056 {
1057 return first().set_row_values(row, pvals);
1058 }
1059
1061 std::uint64_t get_checkpoint_size(SerialConfig& config)
1062 {
1063 return _first.get_checkpoint_size(config);
1064 }
1065
1067 void restore_from_checkpoint_data(std::vector<char> & data)
1068 {
1069 _first.restore_from_checkpoint_data(data);
1070 }
1071
1073 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1074 {
1075 return _first.set_checkpoint_data(data, config);
1076 }
1077
1085 template <typename SubType2_>
1086 void convert(const PowerRowMatrix<SubType2_, 1> & other)
1087 {
1088 this->first().convert(other.first());
1089 }
1090
1091 template <typename SubType2_>
1092 void convert_reverse(PowerRowMatrix<SubType2_, 1> & other) const
1093 {
1094 this->first().convert_reverse(other.first());
1095 }
1096 };
1098 } // namespace LAFEM
1099} // 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
Index size() const
Returns the containers size.
Definition: container.hpp:1136
Dense data vector class template.
Power-Row-Matrix meta class template.
Index rows() const
Returns the total number of rows in this matrix.
void convert(const PowerRowMatrix< SubType2_, blocks_ > &other)
Conversion method.
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 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 used_elements() const
Returns the total number of non-zeros 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.
Index columns() const
Returns the total number of columns in this matrix.
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.
PowerRowMatrix(SubMatrixType &&the_first, RestClass &&the_rest)
base-class constructor; this one is protected for a reason
SubMatrixType::VectorTypeL VectorTypeL
Compatible L-vector type.
void format(DataType value=DataType(0))
Reset all elements of the container to a given value or zero if missing.
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
Index get_length_of_line(const Index row) const
Returns the number of NNZ-elements of the selected row.
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:47
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.