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
352 template <Perspective perspective_ = Perspective::native>
353 Index rows() const
354 {
355 return first().template rows<perspective_>() + rest().template rows<perspective_>();
356 }
357
364 template <Perspective perspective_ = Perspective::native>
366 {
367 return 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("PowerColMatrix<") + 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.first(), x);
430 rest().apply(r.rest(), x);
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> r_first(r, first().rows(), 0);
439 DenseVector<DataType, IndexType> r_rest(r, rest().rows(), first().rows());
440
441 first().apply(r_first, x);
442 rest().apply(r_rest, x);
443 }
444
457 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
458 {
459 first().apply_transposed(r, x.first());
460 rest().apply_transposed(r, x.rest(), r, DataType(1));
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> x_first(x, first().rows(), 0);
469 DenseVector<DataType, IndexType> x_rest(x, rest().rows(), first().rows());
470
471 first().apply_transposed(r, x_first);
472 rest().apply_transposed(r, x_rest, r, DataType(1));
473 }
474
491 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
492 {
493 first().apply(r.first(), x, y.first(), alpha);
494 rest().apply(r.rest(), x, y.rest(), 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> r_first(r, first().rows(), 0);
505 DenseVector<DataType, IndexType> r_rest(r, rest().rows(), first().rows());
506
507 DenseVector<DataType, IndexType> y_first(y, first().rows(), 0);
508 DenseVector<DataType, IndexType> y_rest(y, rest().rows(), first().rows());
509
510 first().apply(r_first, x, y_first, alpha);
511 rest().apply(r_rest, x, y_rest, alpha);
512 }
513
530 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
531 {
532 first().apply_transposed(r, x.first(), y, alpha);
533 rest().apply_transposed(r, x.rest(), r, alpha);
534 }
535
537 const DenseVector<DataType , IndexType>& y, DataType alpha = DataType(1)) const
538 {
539 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
540 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
541 XASSERTM(y.size() == this->columns(), "Vector size of y does not match!");
542
543 DenseVector<DataType, IndexType> x_first(x, first().rows(), 0);
544 DenseVector<DataType, IndexType> x_rest(x, rest().rows(), first().rows());
545
546 first().apply_transposed(r, x_first, y, alpha);
547 rest().apply_transposed(r, x_rest, r, 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 PowerColMatrix& 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 VectorTypeL(first().create_vector_l(), rest().create_vector_l());
579 }
580
583 {
584 return first().create_vector_r();
585 }
586
589 {
590 const Index brows(this->first().template rows<Perspective::pod>());
591
592 if (row < brows)
593 {
594 return this->first().get_length_of_line(row);
595 }
596 else
597 {
598 return this->rest().get_length_of_line(row - brows);
599 }
600 }
601
604 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
605 const Index col_start, const Index stride = 1) const
606 {
607 const Index brows(this->first().template rows<Perspective::pod>());
608
609 if (row < brows)
610 {
611 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
612 }
613 else
614 {
615 this->rest().set_line(row - brows, pval_set, pcol_set, col_start, stride);
616 }
617 }
618
619 void set_line_reverse(const Index row, const DataType * const pval_set, const Index stride = 1)
620 {
621 const Index brows(this->first().template rows<Perspective::pod>());
622
623 if (row < brows)
624 {
625 this->first().set_line_reverse(row, pval_set, stride);
626 }
627 else
628 {
629 this->rest().set_line_reverse(row - brows, pval_set, stride);
630 }
631 }
632
633 Index row_degree(const Index row) const
634 {
635 const Index first_rows = first().template rows<Perspective::pod>();
636 if(row < first_rows)
637 return first().row_degree(row);
638 else
639 return rest().row_degree(row - first_rows);
640 }
641
642 template<typename IT2_>
643 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
644 {
645 const Index first_rows = first().template rows<Perspective::pod>();
646 if(row < first_rows)
647 return first().get_row_col_indices(row, pcol_idx, col_offset);
648 else
649 return rest().get_row_col_indices(row - first_rows, pcol_idx, col_offset);
650 }
651
652 template<typename DT2_>
653 Index get_row_values(const Index row, DT2_ * const pvals) const
654 {
655 const Index first_rows = first().template rows<Perspective::pod>();
656 if(row < first_rows)
657 return first().get_row_values(row, pvals);
658 else
659 return rest().get_row_values(row - first_rows, pvals);
660 }
661
662 template<typename DT2_>
663 Index set_row_values(const Index row, const DT2_ * const pvals)
664 {
665 const Index first_rows = first().template rows<Perspective::pod>();
666 if(row < first_rows)
667 return first().set_row_values(row, pvals);
668 else
669 return rest().set_row_values(row - first_rows, pvals);
670 }
671
673
675 std::uint64_t get_checkpoint_size(SerialConfig& config)
676 {
677 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
678 }
679
681 void restore_from_checkpoint_data(std::vector<char> & data)
682 {
683 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
684 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
685 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
686 std::vector<char> buffer_first(start, last_of_first);
687 _first.restore_from_checkpoint_data(buffer_first);
688
689 data.erase(std::begin(data), last_of_first);
691 }
692
694 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
695 {
696 std::size_t old_size = data.size();
697 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
698 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
699 char* csize = reinterpret_cast<char*>(&ireal_size);
700 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
701 {
702 data[old_size + i] = csize[i];
703 }
704
705 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
706 }
707
715 template <typename SubType2_>
717 {
718 this->first().convert(other.first());
719 this->rest().convert(other.rest());
720 }
721
722 template <typename SubType2_>
723 void convert_reverse(PowerColMatrix<SubType2_, blocks_> & other) const
724 {
725 this->first().convert_reverse(other.first());
726 this->rest().convert_reverse(other.rest());
727 }
728 };
729
731 template<typename SubType_>
732 class PowerColMatrix<SubType_, 1>
733 {
734 template<typename, int>
735 friend class PowerColMatrix;
736
737 public:
738 typedef SubType_ SubMatrixType;
739 typedef typename SubMatrixType::DataType DataType;
740 typedef typename SubMatrixType::IndexType IndexType;
742 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
744 typedef PowerVector<typename SubMatrixType::VectorTypeL, 1> VectorTypeL;
746 typedef typename SubMatrixType::VectorTypeR VectorTypeR;
748 template <typename DT2_ = DataType, typename IT2_ = IndexType>
749 using ContainerType = PowerColMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
750
751 static constexpr int num_row_blocks = 1;
752 static constexpr int num_col_blocks = 1;
753
754 protected:
756
758 explicit PowerColMatrix(SubMatrixType&& the_first) :
759 _first(std::move(the_first))
760 {
761 }
762
763 public:
765 PowerColMatrix()
766 {
767 }
768
770 explicit PowerColMatrix(const SparseLayout<IndexType, layout_id>& layout) :
771 _first(layout)
772 {
773 }
774
776 PowerColMatrix(PowerColMatrix&& other) :
777 _first(std::move(other._first))
778 {
779 }
780
782 explicit PowerColMatrix(FileMode mode, String filename)
783 {
784 read_from(mode, filename);
785 }
786
788 explicit PowerColMatrix(FileMode mode, std::istream& file, String directory = "")
789 {
790 String line;
791 do {
792 if (file.eof())
793 XABORTM("Wrong Input-file");
794 std::getline(file, line);
795 line.trim_me();
796 } while (line.find("%%") == 0 || line == "");
797
798 SubMatrixType tmp_first(mode, directory + line);
799 _first = std::move(tmp_first);
800 }
801
802 void read_from(FileMode mode, String filename)
803 {
804 String directory;
805 auto found = filename.rfind("/");
806 if (found != std::string::npos)
807 {
808 directory = filename.substr(0, found + 1);
809 }
810
811 std::ifstream file(filename.c_str(), std::ifstream::in);
812 if (! file.is_open())
813 XABORTM("Unable to open Matrix file " + filename);
814
815 PowerColMatrix other(mode, file, directory);
816
817 _first = std::move(other._first);
818
819 file.close();
820 }
821
823 PowerColMatrix& operator=(PowerColMatrix&& other)
824 {
825 if(this != &other)
826 {
827 _first = std::move(other._first);
828 }
829 return *this;
830 }
831
833 PowerColMatrix(const PowerColMatrix&) = delete;
835 PowerColMatrix& operator=(const PowerColMatrix&) = delete;
836
838 virtual ~PowerColMatrix()
839 {
840 }
841
842 void write_out(FileMode mode, String filename) const
843 {
844 std::ofstream file(filename.c_str(), std::ofstream::out);
845 if (! file.is_open())
846 XABORTM("Unable to open Matrix file " + filename);
847
848 String suffix, directory;
849 auto found = filename.rfind(".");
850 if (found != std::string::npos)
851 {
852 suffix = filename.substr(found);
853 filename.erase(found);
854 }
855 found = filename.rfind("/");
856 if (found != std::string::npos)
857 {
858 directory = filename.substr(0, found + 1);
859 filename.erase(0, found + 1);
860 }
861
862 file << "%%MatrixMarket powercolmatrix coordinate real general\n";
863 file << filename << "_pc" << 1 << suffix << "\n";
864
865 file.close();
866
867 this->write_out_submatrices(mode, directory, filename, suffix);
868 }
869
870 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
871 {
872 _first.write_out(mode, directory + prefix + "_pc" + stringify(length) + suffix);
873 }
874
875 PowerColMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
876 {
877 return PowerColMatrix(_first.clone(mode));
878 }
879
881 std::size_t bytes() const
882 {
883 return _first.bytes();
884 }
885
886 template<int i, int j>
888 {
889 static_assert(i == 0, "invalid sub-matrix index");
890 static_assert(j == 0, "invalid sub-matrix index");
891 return _first;
892 }
893
894 template<int i, int j>
895 const SubMatrixType& at() const
896 {
897 static_assert(i == 0, "invalid sub-matrix index");
898 static_assert(j == 0, "invalid sub-matrix index");
899 return _first;
900 }
901
902 SubMatrixType& get(int i, int j)
903 {
904 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
905 return _first;
906 }
907
908 const SubMatrixType& get(int i, int j) const
909 {
910 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
911 return _first;
912 }
913
914 SubMatrixType& first()
915 {
916 return _first;
917 }
918
919 const SubMatrixType& first() const
920 {
921 return _first;
922 }
923
924 int row_blocks() const
925 {
926 return 1;
927 }
928
929 int col_blocks() const
930 {
931 return 1;
932 }
933
934 template <Perspective perspective_ = Perspective::native>
935 Index rows() const
936 {
937 return first().template rows<perspective_>();
938 }
939
940 template <Perspective perspective_ = Perspective::native>
941 Index columns() const
942 {
943 return first().template columns<perspective_>();
944 }
945
946 template <Perspective perspective_ = Perspective::native>
947 Index used_elements() const
948 {
949 return first().template used_elements<perspective_>();
950 }
951
952 static String name()
953 {
954 return String("PowerColMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
955 }
956
957 template <Perspective perspective_ = Perspective::native>
958 Index size() const
959 {
960 return rows<perspective_>() * columns<perspective_>();
961 }
962
963 void format(DataType value = DataType(0))
964 {
965 first().format(value);
966 }
967
968 void clear()
969 {
970 first().clear();
971 }
972
973 void apply(VectorTypeL& r, const VectorTypeR& x) const
974 {
975 first().apply(r.first(), x);
976 }
977
978 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
979 {
980 first().apply(r, x);
981 }
982
983 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
984 {
985 first().apply(r.first(), x, y.first(), alpha);
986 }
987
988 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
989 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
990 {
991 first().apply(r, x, y, alpha);
992 }
993
994 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
995 {
996 first().apply_transposed(r, x.first());
997 }
998
999 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
1000 {
1001 first().apply_transposed(r, x);
1002 }
1003
1004 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
1005 {
1006 first().apply_transposed(r, x.first(), y, alpha);
1007 }
1008
1009 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
1010 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
1011 {
1012 first().apply_transposed(r, x, y, alpha);
1013 }
1014
1021 DataType max_rel_diff(const PowerColMatrix& x) const
1022 {
1023 return this->first().max_rel_diff(x.first());
1024 }
1025
1028 {
1029 return VectorTypeL(first().create_vector_l());
1030 }
1031
1034 {
1035 return VectorTypeR(first().create_vector_r());
1036 }
1037
1039 Index get_length_of_line(const Index row) const
1040 {
1041 return this->first().get_length_of_line(row);
1042 }
1043
1045 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
1046 const Index col_start, const Index stride = 1) const
1047 {
1048 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
1049 }
1050
1051 void set_line_reverse(const Index row, const DataType * const pval_set, const Index stride = 1)
1052 {
1053 this->first().set_line_reverse(row, pval_set, stride);
1054 }
1055
1056 Index row_degree(const Index row) const
1057 {
1058 return first().row_degree(row);
1059 }
1060
1061 template<typename IT2_>
1062 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1063 {
1064 return first().get_row_col_indices(row, pcol_idx, col_offset);
1065 }
1066
1067 template<typename DT2_>
1068 Index get_row_values(const Index row, DT2_ * const pvals) const
1069 {
1070 return first().get_row_values(row, pvals);
1071 }
1072
1073 template<typename DT2_>
1074 Index set_row_values(const Index row, const DT2_ * const pvals)
1075 {
1076 return first().set_row_values(row, pvals);
1077 }
1078
1080 std::uint64_t get_checkpoint_size(SerialConfig& config)
1081 {
1082 return _first.get_checkpoint_size(config);
1083 }
1084
1086 void restore_from_checkpoint_data(std::vector<char> & data)
1087 {
1088 _first.restore_from_checkpoint_data(data);
1089 }
1090
1092 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1093 {
1094 return _first.set_checkpoint_data(data, config);
1095 }
1096
1104 template <typename SubType2_>
1105 void convert(const PowerColMatrix<SubType2_, 1> & other)
1106 {
1107 this->first().convert(other.first());
1108 }
1109
1110 template <typename SubType2_>
1111 void convert_reverse(PowerColMatrix<SubType2_, 1> & other) const
1112 {
1113 this->first().convert_reverse(other.first());
1114 }
1115
1124 bool same_layout(const PowerColMatrix& x) const
1125 {
1126 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1127 }
1128 };
1130 } // namespace LAFEM
1131} // 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-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 rows() const
Returns the total number of rows in this matrix.
PowerColMatrix(PowerColMatrix &&other)
move ctor
PowerColMatrix(FileMode mode, const String &filename)
Constructor.
SubType_ SubMatrixType
sub-matrix type
virtual ~PowerColMatrix()
virtual destructor
void convert(const PowerColMatrix< SubType2_, blocks_ > &other)
Conversion method.
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.
void format(DataType value=DataType(0))
Reset all elements of the container to a given value or zero if missing.
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.
Index used_elements() const
Returns the total number of non-zeros in this matrix.
Index columns() const
Returns the total number of columns in this matrix.
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.
Index get_length_of_line(const Index row) const
Returns the number of NNZ-elements of the selected row.
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.
SubMatrixType & at()
Returns a sub-matrix block.
PowerColMatrix< SubType_, blocks_-1 > RestClass
rest-class typedef
static constexpr SparseLayoutId layout_id
sub-matrix layout type
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.