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 }
633
635 std::uint64_t get_checkpoint_size(SerialConfig& config)
636 {
637 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
638 }
639
641 void restore_from_checkpoint_data(std::vector<char> & data)
642 {
643 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
644 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
645 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
646 std::vector<char> buffer_first(start, last_of_first);
647 _first.restore_from_checkpoint_data(buffer_first);
648
649 data.erase(std::begin(data), last_of_first);
651 }
652
654 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
655 {
656 std::size_t old_size = data.size();
657 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
658 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
659 char* csize = reinterpret_cast<char*>(&ireal_size);
660 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
661 {
662 data[old_size + i] = csize[i];
663 }
664
665 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
666 }
667
675 template <typename SubType2_>
677 {
678 this->first().convert(other.first());
679 this->rest().convert(other.rest());
680 }
681
682 template <typename SubType2_>
683 void convert_reverse(PowerColMatrix<SubType2_, blocks_> & other) const
684 {
685 this->first().convert_reverse(other.first());
686 this->rest().convert_reverse(other.rest());
687 }
688 };
689
691 template<typename SubType_>
692 class PowerColMatrix<SubType_, 1>
693 {
694 template<typename, int>
695 friend class PowerColMatrix;
696
697 public:
698 typedef SubType_ SubMatrixType;
699 typedef typename SubMatrixType::DataType DataType;
700 typedef typename SubMatrixType::IndexType IndexType;
702 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
704 typedef PowerVector<typename SubMatrixType::VectorTypeL, 1> VectorTypeL;
706 typedef typename SubMatrixType::VectorTypeR VectorTypeR;
708 template <typename DT2_ = DataType, typename IT2_ = IndexType>
709 using ContainerType = PowerColMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
710
711 static constexpr int num_row_blocks = 1;
712 static constexpr int num_col_blocks = 1;
713
714 protected:
716
718 explicit PowerColMatrix(SubMatrixType&& the_first) :
719 _first(std::move(the_first))
720 {
721 }
722
723 public:
725 PowerColMatrix()
726 {
727 }
728
730 explicit PowerColMatrix(const SparseLayout<IndexType, layout_id>& layout) :
731 _first(layout)
732 {
733 }
734
736 PowerColMatrix(PowerColMatrix&& other) :
737 _first(std::move(other._first))
738 {
739 }
740
742 explicit PowerColMatrix(FileMode mode, String filename)
743 {
744 read_from(mode, filename);
745 }
746
748 explicit PowerColMatrix(FileMode mode, std::istream& file, String directory = "")
749 {
750 String line;
751 do {
752 if (file.eof())
753 XABORTM("Wrong Input-file");
754 std::getline(file, line);
755 line.trim_me();
756 } while (line.find("%%") == 0 || line == "");
757
758 SubMatrixType tmp_first(mode, directory + line);
759 _first = std::move(tmp_first);
760 }
761
762 void read_from(FileMode mode, String filename)
763 {
764 String directory;
765 auto found = filename.rfind("/");
766 if (found != std::string::npos)
767 {
768 directory = filename.substr(0, found + 1);
769 }
770
771 std::ifstream file(filename.c_str(), std::ifstream::in);
772 if (! file.is_open())
773 XABORTM("Unable to open Matrix file " + filename);
774
775 PowerColMatrix other(mode, file, directory);
776
777 _first = std::move(other._first);
778
779 file.close();
780 }
781
783 PowerColMatrix& operator=(PowerColMatrix&& other)
784 {
785 if(this != &other)
786 {
787 _first = std::move(other._first);
788 }
789 return *this;
790 }
791
793 PowerColMatrix(const PowerColMatrix&) = delete;
795 PowerColMatrix& operator=(const PowerColMatrix&) = delete;
796
798 virtual ~PowerColMatrix()
799 {
800 }
801
802 void write_out(FileMode mode, String filename) const
803 {
804 std::ofstream file(filename.c_str(), std::ofstream::out);
805 if (! file.is_open())
806 XABORTM("Unable to open Matrix file " + filename);
807
808 String suffix, directory;
809 auto found = filename.rfind(".");
810 if (found != std::string::npos)
811 {
812 suffix = filename.substr(found);
813 filename.erase(found);
814 }
815 found = filename.rfind("/");
816 if (found != std::string::npos)
817 {
818 directory = filename.substr(0, found + 1);
819 filename.erase(0, found + 1);
820 }
821
822 file << "%%MatrixMarket powercolmatrix coordinate real general\n";
823 file << filename << "_pc" << 1 << suffix << "\n";
824
825 file.close();
826
827 this->write_out_submatrices(mode, directory, filename, suffix);
828 }
829
830 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
831 {
832 _first.write_out(mode, directory + prefix + "_pc" + stringify(length) + suffix);
833 }
834
835 PowerColMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
836 {
837 return PowerColMatrix(_first.clone(mode));
838 }
839
841 std::size_t bytes() const
842 {
843 return _first.bytes();
844 }
845
846 template<int i, int j>
848 {
849 static_assert(i == 0, "invalid sub-matrix index");
850 static_assert(j == 0, "invalid sub-matrix index");
851 return _first;
852 }
853
854 template<int i, int j>
855 const SubMatrixType& at() const
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 SubMatrixType& get(int i, int j)
863 {
864 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
865 return _first;
866 }
867
868 const SubMatrixType& get(int i, int j) const
869 {
870 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
871 return _first;
872 }
873
874 SubMatrixType& first()
875 {
876 return _first;
877 }
878
879 const SubMatrixType& first() const
880 {
881 return _first;
882 }
883
884 int row_blocks() const
885 {
886 return 1;
887 }
888
889 int col_blocks() const
890 {
891 return 1;
892 }
893
894 template <Perspective perspective_ = Perspective::native>
895 Index rows() const
896 {
897 return first().template rows<perspective_>();
898 }
899
900 template <Perspective perspective_ = Perspective::native>
901 Index columns() const
902 {
903 return first().template columns<perspective_>();
904 }
905
906 template <Perspective perspective_ = Perspective::native>
907 Index used_elements() const
908 {
909 return first().template used_elements<perspective_>();
910 }
911
912 static String name()
913 {
914 return String("PowerColMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
915 }
916
917 template <Perspective perspective_ = Perspective::native>
918 Index size() const
919 {
920 return rows<perspective_>() * columns<perspective_>();
921 }
922
923 void format(DataType value = DataType(0))
924 {
925 first().format(value);
926 }
927
928 void clear()
929 {
930 first().clear();
931 }
932
933 void apply(VectorTypeL& r, const VectorTypeR& x) const
934 {
935 first().apply(r.first(), x);
936 }
937
938 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
939 {
940 first().apply(r, x);
941 }
942
943 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
944 {
945 first().apply(r.first(), x, y.first(), alpha);
946 }
947
948 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
949 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
950 {
951 first().apply(r, x, y, alpha);
952 }
953
954 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
955 {
956 first().apply_transposed(r, x.first());
957 }
958
959 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
960 {
961 first().apply_transposed(r, x);
962 }
963
964 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
965 {
966 first().apply_transposed(r, x.first(), y, alpha);
967 }
968
969 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
970 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
971 {
972 first().apply_transposed(r, x, y, alpha);
973 }
974
981 DataType max_rel_diff(const PowerColMatrix& x) const
982 {
983 return this->first().max_rel_diff(x.first());
984 }
985
988 {
989 return VectorTypeL(first().create_vector_l());
990 }
991
994 {
995 return VectorTypeR(first().create_vector_r());
996 }
997
999 Index get_length_of_line(const Index row) const
1000 {
1001 return this->first().get_length_of_line(row);
1002 }
1003
1005 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
1006 const Index col_start, const Index stride = 1) const
1007 {
1008 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
1009 }
1010
1011 void set_line_reverse(const Index row, const DataType * const pval_set, const Index stride = 1)
1012 {
1013 this->first().set_line_reverse(row, pval_set, stride);
1014 }
1015
1017 std::uint64_t get_checkpoint_size(SerialConfig& config)
1018 {
1019 return _first.get_checkpoint_size(config);
1020 }
1021
1023 void restore_from_checkpoint_data(std::vector<char> & data)
1024 {
1025 _first.restore_from_checkpoint_data(data);
1026 }
1027
1029 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1030 {
1031 return _first.set_checkpoint_data(data, config);
1032 }
1033
1041 template <typename SubType2_>
1042 void convert(const PowerColMatrix<SubType2_, 1> & other)
1043 {
1044 this->first().convert(other.first());
1045 }
1046
1047 template <typename SubType2_>
1048 void convert_reverse(PowerColMatrix<SubType2_, 1> & other) const
1049 {
1050 this->first().convert_reverse(other.first());
1051 }
1052
1061 bool same_layout(const PowerColMatrix& x) const
1062 {
1063 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1064 }
1065 };
1067 } // namespace LAFEM
1068} // 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:46
String & trim_me(const String &charset)
Trims this string.
Definition: string.hpp:358
@ 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:944
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
Power container element helper class template.