FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
power_diag_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
15namespace FEAT
16{
17 namespace LAFEM
18 {
33 template<
34 typename SubType_,
35 int blocks_>
37 {
38 // Note: the case = 1 is specialized below
39 static_assert(blocks_ > 1, "invalid block size");
40
41 // declare this class template as a friend for recursive inheritance
42 template<typename, int>
43 friend class PowerDiagMatrix;
44
46 typedef PowerDiagMatrix<SubType_, blocks_-1> RestClass;
47
48 public:
50 typedef SubType_ SubMatrixType;
52 typedef typename SubMatrixType::DataType DataType;
54 typedef typename SubMatrixType::IndexType IndexType;
56 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
62 template <typename DT2_ = DataType, typename IT2_ = IndexType>
64
66 template <typename DataType2_, typename IndexType2_>
68
70 static constexpr int num_row_blocks = blocks_;
72 static constexpr int num_col_blocks = blocks_;
73
74 protected:
79
81 explicit PowerDiagMatrix(SubMatrixType&& the_first, RestClass&& the_rest) :
82 _first(std::move(the_first)),
83 _rest(std::move(the_rest))
84 {
85 }
86
87 public:
90 {
91 }
92
95 _first(layout),
96 _rest(layout)
97 {
98 }
99
102 _first(std::move(other._first)),
103 _rest(std::move(other._rest))
104 {
105 }
106
115 explicit PowerDiagMatrix(FileMode mode, String filename)
116 {
117 read_from(mode, filename);
118 }
119
130 explicit PowerDiagMatrix(FileMode mode, std::istream& file, String directory = "")
131 {
132 String line;
133 do {
134 if (file.eof())
135 XABORTM("Wrong Input-file");
136 std::getline(file, line);
137 line.trim_me();
138 } while (line.find("%%") == 0 || line == "");
139
140 SubMatrixType tmp_first(mode, directory + line);
141 _first = std::move(tmp_first);
142
143 RestClass tmp_rest(mode, file, directory);
144 _rest = std::move(tmp_rest);
145 }
146
153 void read_from(FileMode mode, String filename)
154 {
155 String directory;
156 auto found = filename.rfind("/");
157 if (found != std::string::npos)
158 {
159 directory = filename.substr(0, found + 1);
160 }
161
162 std::ifstream file(filename.c_str(), std::ifstream::in);
163 if (! file.is_open())
164 XABORTM("Unable to open Matrix file " + filename);
165
166 String line;
167 std::getline(file, line);
168 if (line.find("%%MatrixMarket powerdiagmatrix coordinate real general") == String::npos)
169 XABORTM("Input-file is not a complatible file");
170
171 PowerDiagMatrix other(mode, file, directory);
172
173 _first = std::move(other._first);
174 _rest = std::move(other._rest);
175
176 file.close();
177 }
178
181 {
182 if(this != &other)
183 {
184 _first = std::move(other._first);
185 _rest = std::move(other._rest);
186 }
187 return *this;
188 }
189
194
197 {
198 }
199
206 void write_out(FileMode mode, String filename) const
207 {
208 std::ofstream file(filename.c_str(), std::ofstream::out);
209 if (! file.is_open())
210 XABORTM("Unable to open Matrix file " + filename);
211
212 String suffix, directory;
213 auto found = filename.rfind(".");
214 if (found != std::string::npos)
215 {
216 suffix = filename.substr(found);
217 filename.erase(found);
218 }
219 found = filename.rfind("/");
220 if (found != std::string::npos)
221 {
222 directory = filename.substr(0, found + 1);
223 filename.erase(0, found + 1);
224 }
225
226 file << "%%MatrixMarket powerdiagmatrix coordinate real general\n";
227 for (Index i(1); i <= blocks_; ++i)
228 {
229 file << filename << "_pd" << i << suffix << "\n";
230 }
231
232 file.close();
233
234 this->write_out_submatrices(mode, directory, filename, suffix);
235 }
236
245 void write_out_submatrices(FileMode mode, String directory, String prefix, String suffix, Index length = blocks_) const
246 {
247 _first.write_out(mode, directory + prefix + "_pd" + stringify(length + 1 - blocks_) + suffix);
248 _rest.write_out_submatrices(mode, directory, prefix, suffix, length);
249 }
250
255 {
256 return PowerDiagMatrix(_first.clone(mode), _rest.clone(mode));
257 }
258
267 void clone(const PowerDiagMatrix & other, CloneMode clone_mode = CloneMode::Weak)
268 {
269 (*this)=other.clone(clone_mode);
270 }
271
273 std::size_t bytes() const
274 {
275 return _first.bytes() + _rest.bytes();
276 }
277
282 {
283 return PowerDiagMatrix(_first.transpose(), _rest.transpose());
284 }
285
298 template<int i_, int j_>
300 {
301 static_assert(i_ == j_, "invalid sub-matrix index");
302 static_assert((0 <= i_) && (i_ < blocks_), "invalid sub-matrix index");
304 }
305
307 template<int i_, int j_>
308 const SubMatrixType& at() const
309 {
310 static_assert(i_ == j_, "invalid sub-matrix index");
311 static_assert((0 <= i_) && (i_ < blocks_), "invalid sub-matrix index");
313 }
314
324 SubMatrixType& get(int i, int j)
325 {
326 XASSERTM((i == j) && (0 <= i) && (i < blocks_), "invalid sub-matrix index");
327 return (i == 0) ? _first : _rest.get(i-1, j-1);
328 }
329
331 const SubMatrixType& get(int i, int j) const
332 {
333 XASSERTM((i == j) && (0 <= i) && (i < blocks_), "invalid sub-matrix index");
334 return (i == 0) ? _first : _rest.get(i-1, j-1);
335 }
336
338 std::uint64_t get_checkpoint_size(SerialConfig& config)
339 {
340 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
341 }
342
344 void restore_from_checkpoint_data(std::vector<char> & data)
345 {
346 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
347 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
348 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
349 std::vector<char> buffer_first(start, last_of_first);
350 _first.restore_from_checkpoint_data(buffer_first);
351
352 data.erase(std::begin(data), last_of_first);
354 }
355
357 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
358 {
359 std::size_t old_size = data.size();
360 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
361 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
362 char* csize = reinterpret_cast<char*>(&ireal_size);
363 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
364 {
365 data[old_size + i] = csize[i];
366 }
367
368 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
369 }
370
372 SubMatrixType& first()
373 {
374 return _first;
375 }
376
377 const SubMatrixType& first() const
378 {
379 return _first;
380 }
381
382 RestClass& rest()
383 {
384 return _rest;
385 }
386
387 const RestClass& rest() const
388 {
389 return _rest;
390 }
391
392 int row_blocks() const
393 {
394 return num_row_blocks;
395 }
396
397 int col_blocks() const
398 {
399 return num_col_blocks;
400 }
402
405 {
406 return first().num_rows() + rest().num_rows();
407 }
408
411 {
412 return first().num_cols() + rest().num_cols();
413 }
414
417 {
418 return first().num_nzes() + rest().num_nzes();
419 }
420
423 {
424 return first().num_rows_raw() + rest().num_rows_raw();
425 }
426
429 {
430 return first().num_cols_raw() + rest().num_cols_raw();
431 }
432
435 {
436 return first().num_nzes_raw() + rest().num_nzes_raw();
437 }
438
440 static String name()
441 {
442 return String("PowerDiagMatrix<") + SubMatrixType::name() + "," + stringify(blocks_) + ">";
443 }
444
451 void format()
452 {
453 first().format();
454 rest().format();
455 }
456
457 void format(DataType value)
458 {
459 first().format(value);
460 rest().format(value);
461 }
462
466 void clear()
467 {
468 first().clear();
469 rest().clear();
470 }
471
473 void extract_diag(VectorTypeL& diag) const
474 {
475 first().extract_diag(diag.first());
476 rest().extract_diag(diag.rest());
477 }
478
491 void apply(VectorTypeL& r, const VectorTypeR& x) const
492 {
493 first().apply(r.first(), x.first());
494 rest().apply(r.rest(), x.rest());
495 }
496
498 {
499 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
500 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
501
502 DenseVector<DataType, IndexType> r_first(r, first().num_rows(), 0);
503 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
504
505 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
506 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
507
508 first().apply(r_first, x_first);
509 rest().apply(r_rest, x_rest);
510 }
511
524 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
525 {
526 first().apply_transposed(r.first(), x.first());
527 rest().apply_transposed(r.rest(), x.rest());
528 }
529
531 {
532 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
533 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
534
535 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
536 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
537
538 DenseVector<DataType, IndexType> x_first(x, first().num_rows(), 0);
539 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
540
541 first().apply_transposed(r_first, x_first);
542 rest().apply_transposed(r_rest, x_rest);
543 }
544
561 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
562 {
563 first().apply(r.first(), x.first(), y.first(), alpha);
564 rest().apply(r.rest(), x.rest(), y.rest(), alpha);
565 }
566
568 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
569 {
570 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
571 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
572 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
573
574 DenseVector<DataType, IndexType> r_first(r, first().num_rows(), 0);
575 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
576
577 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
578 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
579
580 DenseVector<DataType, IndexType> y_first(y, first().num_rows(), 0);
581 DenseVector<DataType, IndexType> y_rest(y, rest().num_rows(), first().num_rows());
582
583 first().apply(r_first, x_first, y_first, alpha);
584 rest().apply(r_rest, x_rest, y_rest, alpha);
585 }
586
603 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
604 {
605 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
606 rest().apply_transposed(r.rest(), x.rest(), y.rest(), alpha);
607 }
608
610 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
611 {
612 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
613 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
614 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
615
616 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
617 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
618
619 DenseVector<DataType, IndexType> x_first(x, first().num_rows(), 0);
620 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
621
622 DenseVector<DataType, IndexType> y_first(y, first().num_cols(), 0);
623 DenseVector<DataType, IndexType> y_rest(y, rest().num_cols(), first().num_cols());
624
625 first().apply_transposed(r_first, x_first, y_first, alpha);
626 rest().apply_transposed(r_rest, x_rest, y_rest, alpha);
627 }
628
636 {
637 DataType max_rel_diff = Math::max(this->first().max_rel_diff(x.first()), this->rest().max_rel_diff(x.rest()));
638 return max_rel_diff;
639 }
640
649 bool same_layout(const PowerDiagMatrix& x) const
650 {
651 return (this->name() == x.name()) && (this->first().same_layout(x.first())) && (this->rest().same_layout(x.rest()));
652 }
653
656 {
657 return VectorTypeL(first().create_vector_l(), rest().create_vector_l());
658 }
659
662 {
663 return VectorTypeR(first().create_vector_r(), rest().create_vector_r());
664 }
665
666 void scale_rows(const PowerDiagMatrix& a, const VectorTypeL& w)
667 {
668 first().scale_rows(a.first(), w.first());
669 rest().scale_rows(a.rest(), w.rest());
670 }
671
672 void scale_cols(const PowerDiagMatrix& a, const VectorTypeR& w)
673 {
674 first().scale_cols(a.first(), w.first());
675 rest().scale_cols(a.rest(), w.rest());
676 }
677
679 Index row_degree(const Index row) const
680 {
681 const Index first_rows = first().num_rows_raw();
682 if(row < first_rows)
683 return first().row_degree(row);
684 else
685 return rest().row_degree(row - first_rows);
686 }
687
688 template<typename IT2_>
689 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
690 {
691 const Index first_rows = first().num_rows_raw();
692 const Index first_cols = first().num_cols_raw();
693 if(row < first_rows)
694 return first().get_row_col_indices(row, pcol_idx, col_offset);
695 else
696 return rest().get_row_col_indices(row - first_rows, pcol_idx, col_offset + IT2_(first_cols));
697 }
698
699 template<typename DT2_>
700 Index get_row_values(const Index row, DT2_ * const pvals) const
701 {
702 const Index first_rows = first().num_rows_raw();
703 if(row < first_rows)
704 return first().get_row_values(row, pvals);
705 else
706 return rest().get_row_values(row - first_rows, pvals);
707 }
708
709 template<typename DT2_>
710 Index set_row_values(const Index row, const DT2_ * const pvals)
711 {
712 const Index first_rows = first().num_rows_raw();
713 if(row < first_rows)
714 return first().set_row_values(row, pvals);
715 else
716 return rest().set_row_values(row - first_rows, pvals);
717 }
718
720
728 template <typename SubType2_>
730 {
731 this->first().convert(source.first());
732 this->rest().convert(source.rest());
733 }
734
735 template <typename SubType2_>
736 void copy(const PowerDiagMatrix<SubType2_, blocks_> & source)
737 {
738 this->first().copy(source.first());
739 this->rest().copy(source.rest());
740 }
741
742 template <typename SubType2_>
743 void copy_to(PowerDiagMatrix<SubType2_, blocks_> & target) const
744 {
745 this->first().copy_to(target.first());
746 this->rest().copy_to(target.rest());
747 }
748 };
749
751 template<typename SubType_>
752 class PowerDiagMatrix<SubType_, 1>
753 {
754 template<typename, int>
755 friend class PowerDiagMatrix;
756
757 public:
758 typedef SubType_ SubMatrixType;
759 typedef typename SubMatrixType::DataType DataType;
760 typedef typename SubMatrixType::IndexType IndexType;
762 static constexpr SparseLayoutId layout_id = SubMatrixType::layout_id;
764 typedef PowerVector<typename SubMatrixType::VectorTypeL, 1> VectorTypeL;
766 typedef PowerVector<typename SubMatrixType::VectorTypeR, 1> VectorTypeR;
768 template <typename DT2_ = DataType, typename IT2_ = IndexType>
769 using ContainerType = PowerDiagMatrix<typename SubType_::template ContainerType<DT2_, IT2_>, 1>;
770
772 template <typename DataType2_, typename IndexType2_>
773 using ContainerTypeByDI = ContainerType<DataType2_, IndexType2_>;
774
775 static constexpr int num_row_blocks = 1;
776 static constexpr int num_col_blocks = 1;
777
778 protected:
780
782 explicit PowerDiagMatrix(SubMatrixType&& the_first) :
783 _first(std::move(the_first))
784 {
785 }
786
787 public:
789 PowerDiagMatrix()
790 {
791 }
792
794 explicit PowerDiagMatrix(const SparseLayout<IndexType, layout_id>& layout) :
795 _first(layout)
796 {
797 }
798
800 PowerDiagMatrix(PowerDiagMatrix&& other) :
801 _first(std::move(other._first))
802 {
803 }
804
806 PowerDiagMatrix& operator=(PowerDiagMatrix&& other)
807 {
808 if(this != &other)
809 {
810 _first = std::move(other._first);
811 }
812 return *this;
813 }
814
816 explicit PowerDiagMatrix(FileMode mode, const String& filename)
817 {
818 read_from(mode, filename);
819 }
820
822 explicit PowerDiagMatrix(FileMode mode, std::istream& file, const String& directory = "")
823 {
824 String line;
825 do {
826 if (file.eof())
827 XABORTM("Wrong Input-file");
828 std::getline(file, line);
829 line.trim_me();
830 } while (line.find("%%") == 0 || line == "");
831
832 SubMatrixType tmp_first(mode, directory + line);
833 _first = std::move(tmp_first);
834 }
835
836 void read_from(FileMode mode, const String& filename)
837 {
838 String directory;
839 auto found = filename.rfind("/");
840 if (found != std::string::npos)
841 {
842 directory = filename.substr(0, found + 1);
843 }
844
845 std::ifstream file(filename.c_str(), std::ifstream::in);
846 if (! file.is_open())
847 XABORTM("Unable to open Matrix file " + filename);
848
849 PowerDiagMatrix other(mode, file, directory);
850
851 _first = std::move(other._first);
852
853 file.close();
854 }
855
857 PowerDiagMatrix(const PowerDiagMatrix&) = delete;
859 PowerDiagMatrix& operator=(const PowerDiagMatrix&) = delete;
860
862 virtual ~PowerDiagMatrix()
863 {
864 }
865
866 void write_out(FileMode mode, String filename) const
867 {
868 std::ofstream file(filename.c_str(), std::ofstream::out);
869 if (! file.is_open())
870 XABORTM("Unable to open Matrix file " + filename);
871
872 String suffix, directory;
873 auto found = filename.rfind(".");
874 if (found != std::string::npos)
875 {
876 suffix = filename.substr(found);
877 filename.erase(found);
878 }
879 found = filename.rfind("/");
880 if (found != std::string::npos)
881 {
882 directory = filename.substr(0, found + 1);
883 filename.erase(0, found + 1);
884 }
885
886 file << "%%MatrixMarket powerdiagmatrix coordinate real general\n";
887 file << filename << "_pd" << 1 << suffix << "\n";
888
889 file.close();
890
891 this->write_out_submatrices(mode, directory, filename, suffix);
892 }
893
894 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
895 {
896 _first.write_out(mode, directory + prefix + "_pd" + stringify(length) + suffix);
897 }
898
899 PowerDiagMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
900 {
901 return PowerDiagMatrix(_first.clone(mode));
902 }
903
904 void clone(const PowerDiagMatrix & other, CloneMode clone_mode = CloneMode::Weak)
905 {
906 (*this)=other.clone(clone_mode);
907 }
908
910 std::size_t bytes() const
911 {
912 return _first.bytes();
913 }
914
915 PowerDiagMatrix transpose() const
916 {
917 return PowerDiagMatrix(_first.transpose());
918 }
919
920 template<int i, int j>
922 {
923 static_assert(i == 0, "invalid sub-matrix index");
924 static_assert(j == 0, "invalid sub-matrix index");
925 return _first;
926 }
927
928 template<int i, int j>
929 const SubMatrixType& at() const
930 {
931 static_assert(i == 0, "invalid sub-matrix index");
932 static_assert(j == 0, "invalid sub-matrix index");
933 return _first;
934 }
935
936 SubMatrixType& get(int i, int j)
937 {
938 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
939 return _first;
940 }
941
942 const SubMatrixType& get(int i, int j) const
943 {
944 XASSERTM((i == 0) && (j == 0), "invalid sub-matrix index");
945 return _first;
946 }
947
949 std::uint64_t get_checkpoint_size(SerialConfig& config)
950 {
951 return _first.get_checkpoint_size(config);
952 }
953
955 void restore_from_checkpoint_data(std::vector<char> & data)
956 {
957 _first.restore_from_checkpoint_data(data);
958 }
959
961 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
962 {
963 return _first.set_checkpoint_data(data, config);
964 }
965
966 SubMatrixType& first()
967 {
968 return _first;
969 }
970
971 const SubMatrixType& first() const
972 {
973 return _first;
974 }
975
976 int row_blocks() const
977 {
978 return 1;
979 }
980
981 int col_blocks() const
982 {
983 return 1;
984 }
985
986 Index num_rows() const
987 {
988 return first().num_rows();
989 }
990
991 Index num_cols() const
992 {
993 return first().num_cols();
994 }
995
996 Index num_nzes() const
997 {
998 return first().num_nzes();
999 }
1000
1001 Index num_rows_raw() const
1002 {
1003 return first().num_rows_raw();
1004 }
1005
1006 Index num_cols_raw() const
1007 {
1008 return first().num_cols_raw();
1009 }
1010
1011 Index num_nzes_raw() const
1012 {
1013 return first().num_nzes_raw();
1014 }
1015
1016 static String name()
1017 {
1018 return String("PowerDiagMatrix<") + SubMatrixType::name() + "," + stringify(1) + ">";
1019 }
1020
1021 void format()
1022 {
1023 first().format();
1024 }
1025
1026 void format(DataType value)
1027 {
1028 first().format(value);
1029 }
1030
1031 void clear()
1032 {
1033 first().clear();
1034 }
1035
1036 void extract_diag(VectorTypeL& diag) const
1037 {
1038 first().extract_diag(diag.first());
1039 }
1040
1041 void apply(VectorTypeL& r, const VectorTypeR& x) const
1042 {
1043 first().apply(r.first(), x.first());
1044 }
1045
1046 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
1047 {
1048 first().apply(r, x);
1049 }
1050
1051 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
1052 {
1053 first().apply(r.first(), x.first(), y.first(), alpha);
1054 }
1055
1056 void apply(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
1057 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
1058 {
1059 first().apply(r, x, y, alpha);
1060 }
1061
1062 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
1063 {
1064 first().apply_transposed(r.first(), x.first());
1065 }
1066
1067 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x) const
1068 {
1069 first().apply_transposed(r, x);
1070 }
1071
1072 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
1073 {
1074 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
1075 }
1076
1077 void apply_transposed(DenseVector<DataType, IndexType>& r, const DenseVector<DataType, IndexType>& x,
1078 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
1079 {
1080 first().apply_transposed(r, x, y, alpha);
1081 }
1082
1089 DataType max_rel_diff(const PowerDiagMatrix& x) const
1090 {
1091 return first().max_rel_diff(x.first());
1092 }
1093
1096 {
1097 return VectorTypeL(first().create_vector_l());
1098 }
1099
1102 {
1103 return VectorTypeR(first().create_vector_r());
1104 }
1105
1106 void scale_rows(const PowerDiagMatrix& a, const VectorTypeL& w)
1107 {
1108 first().scale_rows(a.first(), w.first());
1109 }
1110
1111 void scale_cols(const PowerDiagMatrix& a, const VectorTypeR& w)
1112 {
1113 first().scale_cols(a.first(), w.first());
1114 }
1115
1116 Index row_degree(const Index row) const
1117 {
1118 return first().row_degree(row);
1119 }
1120
1121 template<typename IT2_>
1122 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1123 {
1124 return first().get_row_col_indices(row, pcol_idx, col_offset);
1125 }
1126
1127 template<typename DT2_>
1128 Index get_row_values(const Index row, DT2_ * const pvals) const
1129 {
1130 return first().get_row_values(row, pvals);
1131 }
1132
1133 template<typename DT2_>
1134 Index set_row_values(const Index row, const DT2_ * const pvals)
1135 {
1136 return first().set_row_values(row, pvals);
1137 }
1138
1147 template <typename SubType2_>
1148 void convert(const PowerDiagMatrix<SubType2_, 1> & source)
1149 {
1150 this->first().convert(source.first());
1151 }
1152
1153 template <typename SubType2_>
1154 void copy(const PowerDiagMatrix<SubType2_, 1> & source)
1155 {
1156 this->first().copy(source.first());
1157 }
1158
1159 template <typename SubType2_>
1160 void copy_to(PowerDiagMatrix<SubType2_, 1> & target) const
1161 {
1162 this->first().copy_to(target.first());
1163 }
1164
1173 bool same_layout(const PowerDiagMatrix& x) const
1174 {
1175 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1176 }
1177 };
1179 } // namespace LAFEM
1180} // 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-Diag-Matrix meta class template.
PowerDiagMatrix(SubMatrixType &&the_first, RestClass &&the_rest)
base-class constructor; this one is protected for a reason
PowerDiagMatrix(FileMode mode, std::istream &file, String directory="")
Constructor.
SubMatrixType & at()
Returns a sub-matrix block.
SubMatrixType & get(int i, int j)
Returns a sub-matrix block.
PowerDiagMatrix(PowerDiagMatrix &&other)
move ctor
ContainerType< DataType2_, IndexType2_ > ContainerTypeByDI
this typedef lets you create a matrix container with different Data and Index types
PowerVector< typename SubMatrixType::VectorTypeL, blocks_ > VectorTypeL
Compatible L-vector type.
PowerVector< typename SubMatrixType::VectorTypeR, blocks_ > VectorTypeR
Compatible R-vector type.
PowerDiagMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a deep copy of this matrix.
static constexpr SparseLayoutId layout_id
sub-matrix layout type
std::uint64_t set_checkpoint_data(std::vector< char > &data, SerialConfig &config)
Index num_nzes() const
Returns the total number of non-zeros in this matrix.
PowerDiagMatrix & operator=(PowerDiagMatrix &&other)
move-assign operator
const SubMatrixType & at() const
Returns a sub-matrix block.
void restore_from_checkpoint_data(std::vector< char > &data)
Extract object from checkpoint.
SubMatrixType::DataType DataType
sub-matrix data type
PowerDiagMatrix(const PowerDiagMatrix &)=delete
deleted copy-ctor
PowerDiagMatrix(FileMode mode, String filename)
Constructor.
bool same_layout(const PowerDiagMatrix &x) const
Checks if the structural layout of this matrix matches that of another matrix. This excludes comparis...
void convert(const PowerDiagMatrix< SubType2_, blocks_ > &source)
Conversion method.
Index num_cols_raw() const
Returns the total number of columns in this matrix.
PowerDiagMatrix transpose() const
Creates and returns the transpose of this matrix.
void write_out(FileMode mode, String filename) const
Write out matrix to file.
void clone(const PowerDiagMatrix &other, CloneMode clone_mode=CloneMode::Weak)
Clone operation.
Index num_rows_raw() const
Returns the total number of rows in this matrix.
static String name()
Returns a descriptive string for this container.
void read_from(FileMode mode, String filename)
Read in matrix from file.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Applies this matrix onto a vector.
void format()
Reset all elements of the container to a given value or zero if missing.
SubMatrixType::IndexType IndexType
sub-matrix index type
SubMatrixType _first
the first sub-matrix
std::size_t bytes() const
Returns the total amount of bytes allocated.
std::uint64_t get_checkpoint_size(SerialConfig &config)
Calculate size.
PowerDiagMatrix< SubType_, blocks_-1 > RestClass
rest-class typedef
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
PowerDiagMatrix< typename SubType_::template ContainerType< DT2_, IT2_ >, blocks_ > ContainerType
Our 'base' class type.
void write_out_submatrices(FileMode mode, String directory, String prefix, String suffix, Index length=blocks_) const
Write out submatrices to file.
PowerDiagMatrix(const SparseLayout< IndexType, layout_id > &layout)
sub-matrix layout ctor
static constexpr int num_col_blocks
number of column blocks (horizontal size)
void apply(VectorTypeL &r, const VectorTypeR &x, const VectorTypeL &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
SubType_ SubMatrixType
sub-matrix type
const SubMatrixType & get(int i, int j) const
Returns a sub-matrix block.
void apply_transposed(VectorTypeR &r, const VectorTypeL &x, const VectorTypeR &y, DataType alpha=DataType(1)) const
Applies this matrix onto a vector.
DataType max_rel_diff(const PowerDiagMatrix &x) const
Retrieve the maximum relative difference of this matrix and another one y.max_rel_diff(x) returns .
static constexpr int num_row_blocks
number of row blocks (vertical size)
Index num_nzes_raw() const
Returns the total number of non-zeros in this matrix.
void clear()
Free all allocated arrays.
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
virtual ~PowerDiagMatrix()
virtual destructor
Index num_cols() const
Returns the total number of columns in this matrix.
RestClass _rest
the remaining part
void apply_transposed(VectorTypeR &r, const VectorTypeL &x) const
Applies this matrix onto a vector.
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
PowerDiagMatrix & operator=(const PowerDiagMatrix &)=delete
deleted copy-assign operator
Index num_rows() const
Returns the total number of rows in this matrix.
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.