FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
tuple_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/tuple_vector.hpp>
10#include <kernel/lafem/sparse_layout.hpp>
11#include <kernel/lafem/meta_element.hpp>
12
13
14#include <fstream>
15
16namespace FEAT
17{
18 namespace LAFEM
19 {
31 template<
32 typename First_,
33 typename... Rest_>
35 {
36 // declare this class template as a friend for recursive inheritance
37 template<typename, typename...>
38 friend class TupleDiagMatrix;
39
41 typedef TupleDiagMatrix<Rest_...> RestClass;
42
43 public:
45 typedef typename First_::DataType DataType;
47 typedef typename First_::IndexType IndexType;
48
50 typedef TupleVector<typename First_::VectorTypeL, typename Rest_::VectorTypeL...> VectorTypeL;
52 typedef TupleVector<typename First_::VectorTypeR, typename Rest_::VectorTypeR...> VectorTypeR;
53
55 template <typename DT2_ = DataType, typename IT2_ = IndexType>
57 typename First_::template ContainerType<DT2_, IT2_>,
58 typename Rest_::template ContainerType<DT2_, IT2_>...>;
59
61 template <typename DT2_, typename IT2_>
63 typename First_::template ContainerType<DT2_, IT2_>,
64 typename Rest_::template ContainerType<DT2_, IT2_>...>;
65
67 static constexpr int num_row_blocks = RestClass::num_row_blocks + 1;
69 static constexpr int num_col_blocks = RestClass::num_col_blocks + 1;
70
71 protected:
73 First_ _first;
76
78 explicit TupleDiagMatrix(First_&& the_first, RestClass&& the_rest) :
79 _first(std::forward<First_>(the_first)),
80 _rest(std::forward<RestClass>(the_rest))
81 {
82 }
83
86 {
87 return First_::name() + "," + RestClass::sub_name_list();
88 }
89
90 public:
93 {
94 }
95
97 explicit TupleDiagMatrix(First_&& the_first, Rest_&&... the_rest) :
98 _first(std::forward<First_>(the_first)),
99 _rest(std::forward<Rest_>(the_rest)...)
100 {
101 }
102
105 _first(std::forward<First_>(other._first)),
106 _rest(std::forward<RestClass>(other._rest))
107 {
108 }
109
118 explicit TupleDiagMatrix(FileMode mode, const String& filename)
119 {
120 read_from(mode, filename);
121 }
122
133 explicit TupleDiagMatrix(FileMode mode, std::istream& file, const String& directory = "")
134 {
135 String line;
136 do {
137 if (file.eof())
138 XABORTM("Wrong Input-file");
139 std::getline(file, line);
140 line.trim_me();
141 } while (line.find("%%") == 0 || line == "");
142
143 _first = First_(mode, directory + line);
144 _rest = RestClass(mode, file, directory);
145 }
146
153 void read_from(FileMode mode, const 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 tuplediagmatrix coordinate real general") == String::npos)
169 XABORTM("Input-file is not a complatible file");
170
171 TupleDiagMatrix 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::forward<First_>(other._first);
185 _rest = std::forward<RestClass>(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 tuplediagmatrix coordinate real general\n";
227 for (Index i(1); i <= num_row_blocks; ++i)
228 {
229 file << filename << "_td" << 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, const String& directory, const String& prefix, const String& suffix, Index length = num_row_blocks) const
246 {
247 _first.write_out(mode, directory + prefix + "_td" + stringify(length + 1 - num_row_blocks) + suffix);
248 _rest.write_out_submatrices(mode, directory, prefix, suffix, length);
249 }
250
255 {
256 return TupleDiagMatrix(_first.clone(mode), _rest.clone(mode));
257 }
258
260 std::size_t bytes() const
261 {
262 return _first.bytes() + _rest.bytes();
263 }
264
269 {
270 return TupleDiagMatrix(_first.transpose(), _rest.transpose());
271 }
272
285 template<int i_, int j_>
286 typename TupleElement<i_, First_, Rest_...>::Type& at()
287 {
288 static_assert(i_ == j_, "invalid sub-matrix index");
290 }
291
293 template<int i_, int j_>
294 const typename TupleElement<i_, First_, Rest_...>::Type& at() const
295 {
296 static_assert(i_ == j_, "invalid sub-matrix index");
298 }
299
301 First_& first()
302 {
303 return _first;
304 }
305
306 const First_& first() const
307 {
308 return _first;
309 }
310
311 RestClass& rest()
312 {
313 return _rest;
314 }
315
316 const RestClass& rest() const
317 {
318 return _rest;
319 }
320
321 int row_blocks() const
322 {
323 return num_row_blocks;
324 }
325
326 int col_blocks() const
327 {
328 return num_col_blocks;
329 }
331
333 Index rows() const
334 {
335 return first().rows() + rest().rows();
336 }
337
340 {
341 return first().columns() + rest().columns();
342 }
343
346 {
347 return first().used_elements() + rest().used_elements();
348 }
349
351 static String name()
352 {
353 return String("TupleDiagMatrix<") + sub_name_list() + ">";
354 }
355
356 Index size() const
357 {
358 return rows() * columns();
359 }
360
368 {
369 first().format(value);
370 rest().format(value);
371 }
372
376 void clear()
377 {
378 first().clear();
379 rest().clear();
380 }
381
383 void extract_diag(VectorTypeL& diag) const
384 {
385 first().extract_diag(diag.first());
386 rest().extract_diag(diag.rest());
387 }
388
401 void apply(VectorTypeL& r, const VectorTypeR& x) const
402 {
403 first().apply(r.first(), x.first());
404 rest().apply(r.rest(), x.rest());
405 }
406
408 {
409 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
410 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
411
412 DenseVector<DataType, IndexType> r_first(r, first().rows(), 0);
413 DenseVector<DataType, IndexType> r_rest(r, rest().rows(), first().rows());
414
415 DenseVector<DataType, IndexType> x_first(x, first().columns(), 0);
416 DenseVector<DataType, IndexType> x_rest(x, rest().columns(), first().columns());
417
418 first().apply(r_first, x_first);
419 rest().apply(r_rest, x_rest);
420 }
421
434 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
435 {
436 first().apply_transposed(r.first(), x.first());
437 rest().apply_transposed(r.rest(), x.rest());
438 }
439
441 {
442 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
443 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
444
445 DenseVector<DataType, IndexType> r_first(r, first().columns(), 0);
446 DenseVector<DataType, IndexType> r_rest(r, rest().columns(), first().columns());
447
448 DenseVector<DataType, IndexType> x_first(x, first().rows(), 0);
449 DenseVector<DataType, IndexType> x_rest(x, rest().rows(), first().rows());
450
451 first().apply_transposed(r_first, x_first);
452 rest().apply_transposed(r_rest, x_rest);
453 }
454
471 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
472 {
473 first().apply(r.first(), x.first(), y.first(), alpha);
474 rest().apply(r.rest(), x.rest(), y.rest(), alpha);
475 }
476
478 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
479 {
480 XASSERTM(r.size() == this->rows(), "Vector size of r does not match!");
481 XASSERTM(x.size() == this->columns(), "Vector size of x does not match!");
482 XASSERTM(y.size() == this->rows(), "Vector size of y does not match!");
483
484 DenseVector<DataType, IndexType> r_first(r, first().rows(), 0);
485 DenseVector<DataType, IndexType> r_rest(r, rest().rows(), first().rows());
486
487 DenseVector<DataType, IndexType> x_first(x, first().columns(), 0);
488 DenseVector<DataType, IndexType> x_rest(x, rest().columns(), first().columns());
489
490 DenseVector<DataType, IndexType> y_first(y, first().rows(), 0);
491 DenseVector<DataType, IndexType> y_rest(y, rest().rows(), first().rows());
492
493 first().apply(r_first, x_first, y_first, alpha);
494 rest().apply(r_rest, x_rest, y_rest, alpha);
495 }
496
513 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
514 {
515 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
516 rest().apply_transposed(r.rest(), x.rest(), y.rest(), alpha);
517 }
518
520 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
521 {
522 XASSERTM(r.size() == this->columns(), "Vector size of r does not match!");
523 XASSERTM(x.size() == this->rows(), "Vector size of x does not match!");
524 XASSERTM(y.size() == this->columns(), "Vector size of y does not match!");
525
526 DenseVector<DataType, IndexType> r_first(r, first().columns(), 0);
527 DenseVector<DataType, IndexType> r_rest(r, rest().columns(), first().columns());
528
529 DenseVector<DataType, IndexType> x_first(x, first().rows(), 0);
530 DenseVector<DataType, IndexType> x_rest(x, rest().rows(), first().rows());
531
532 DenseVector<DataType, IndexType> y_first(y, first().columns(), 0);
533 DenseVector<DataType, IndexType> y_rest(y, rest().columns(), first().columns());
534
535 first().apply_transposed(r_first, x_first, y_first, alpha);
536 rest().apply_transposed(r_rest, x_rest, y_rest, alpha);
537 }
538
541 {
542 return VectorTypeL(first().create_vector_l(), rest().create_vector_l());
543 }
544
547 {
548 return VectorTypeR(first().create_vector_r(), rest().create_vector_r());
549 }
550
551 void scale_rows(const TupleDiagMatrix& a, const VectorTypeL& w)
552 {
553 first().scale_rows(a.first(), w.first());
554 rest().scale_rows(a.rest(), w.rest());
555 }
556
557 void scale_cols(const TupleDiagMatrix& a, const VectorTypeR& w)
558 {
559 first().scale_cols(a.first(), w.first());
560 rest().scale_cols(a.rest(), w.rest());
561 }
562
565 {
566 const Index brows(this->first().rows());
567
568 if (row < brows)
569 {
570 return this->first().get_length_of_line(row);
571 }
572 else
573 {
574 return this->rest().get_length_of_line(row - brows);
575 }
576 }
577
580 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
581 const Index col_start, const Index stride = 1) const
582 {
583 const Index brows(this->first().rows());
584 const Index bcolumns(this->first().columns());
585
586 if (row < brows)
587 {
588 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
589 }
590 else
591 {
592 this->rest().set_line(row - brows, pval_set, pcol_set, col_start + bcolumns, stride);
593 }
594 }
595
596 void set_line_reverse(const Index row, DataType * const pval_set, const Index stride = 1)
597 {
598 const Index brows(this->first().rows());
599
600 if (row < brows)
601 {
602 this->first().set_line_reverse(row, pval_set, stride);
603 }
604 else
605 {
606 this->rest().set_line_reverse(row - brows, pval_set, stride);
607 }
608 }
610
612 std::uint64_t get_checkpoint_size(SerialConfig& config)
613 {
614 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
615 }
616
618 void restore_from_checkpoint_data(std::vector<char> & data)
619 {
620 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
621 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
622 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
623 std::vector<char> buffer_first(start, last_of_first);
624 _first.restore_from_checkpoint_data(buffer_first);
625
626 data.erase(std::begin(data), last_of_first);
628 }
629
631 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
632 {
633 std::size_t old_size = data.size();
634 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
635 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
636 char* csize = reinterpret_cast<char*>(&ireal_size);
637 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
638 {
639 data[old_size +i] = csize[i];
640 }
641
642 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
643 }
644
652 template <typename First2_, typename... Rest2_>
654 {
655 this->first().convert(other.first());
656 this->rest().convert(other.rest());
657 }
658
659 template <typename First2_, typename... Rest2_>
660 void convert_reverse(TupleDiagMatrix<First2_, Rest2_...>& other) const
661 {
662 this->first().convert_reverse(other.first());
663 this->rest().convert_reverse(other.rest());
664 }
665
674 bool same_layout(const TupleDiagMatrix& x) const
675 {
676 return (this->name() == x.name()) && (this->first().same_layout(x.first())) && (this->rest().same_layout(x.rest()));
677 }
678 };
679
681 template<typename First_>
682 class TupleDiagMatrix<First_>
683 {
684 template<typename,typename...>
685 friend class TupleDiagMatrix;
686
687 public:
688 typedef typename First_::DataType DataType;
689 typedef typename First_::IndexType IndexType;
691 typedef TupleVector<typename First_::VectorTypeL> VectorTypeL;
693 typedef TupleVector<typename First_::VectorTypeR> VectorTypeR;
694
695 template <typename DT2_ = DataType, typename IT2_ = IndexType>
696 using ContainerType = TupleDiagMatrix<typename First_::template ContainerType<DT2_, IT2_> >;
697
698 static constexpr int num_row_blocks = 1;
699 static constexpr int num_col_blocks = 1;
700
701 protected:
702 First_ _first;
703
704 static String sub_name_list()
705 {
706 return First_::name();
707 }
708
709 public:
711 TupleDiagMatrix()
712 {
713 }
714
715 explicit TupleDiagMatrix(First_&& the_first) :
716 _first(std::forward<First_>(the_first))
717 {
718 }
719
721 TupleDiagMatrix(TupleDiagMatrix&& other) :
722 _first(std::forward<First_>(other._first))
723 {
724 }
725
727 explicit TupleDiagMatrix(FileMode mode, const String& filename)
728 {
729 read_from(mode, filename);
730 }
731
733 explicit TupleDiagMatrix(FileMode mode, std::istream& file, const String& directory = "")
734 {
735 String line;
736 do {
737 if (file.eof())
738 XABORTM("Wrong Input-file");
739 std::getline(file, line);
740 line.trim_me();
741 } while (line.find("%%") == 0 || line == "");
742
743 _first = First_(mode, directory + line);
744 }
745
746 void read_from(FileMode mode, const String& filename)
747 {
748 String directory;
749 auto found = filename.rfind("/");
750 if (found != std::string::npos)
751 {
752 directory = filename.substr(0, found + 1);
753 }
754
755 std::ifstream file(filename.c_str(), std::ifstream::in);
756 if (! file.is_open())
757 XABORTM("Unable to open Matrix file " + filename);
758
759 TupleDiagMatrix other(mode, file, directory);
760
761 _first = std::move(other._first);
762
763 file.close();
764 }
765
767 TupleDiagMatrix& operator=(TupleDiagMatrix&& other)
768 {
769 if(this != &other)
770 {
771 _first = std::forward<First_>(other._first);
772 }
773 return *this;
774 }
775
777 TupleDiagMatrix(const TupleDiagMatrix&) = delete;
779 TupleDiagMatrix& operator=(const TupleDiagMatrix&) = delete;
780
782 virtual ~TupleDiagMatrix()
783 {
784 }
785
786 void write_out(FileMode mode, String filename) const
787 {
788 std::ofstream file(filename.c_str(), std::ofstream::out);
789 if (! file.is_open())
790 XABORTM("Unable to open Matrix file " + filename);
791
792 String suffix, directory;
793 auto found = filename.rfind(".");
794 if (found != std::string::npos)
795 {
796 suffix = filename.substr(found);
797 filename.erase(found);
798 }
799 found = filename.rfind("/");
800 if (found != std::string::npos)
801 {
802 directory = filename.substr(0, found + 1);
803 filename.erase(0, found + 1);
804 }
805
806 file << "%%MatrixMarket tuplediagmatrix coordinate real general\n";
807 file << filename << "_td" << 1 << suffix << "\n";
808
809 file.close();
810
811 this->write_out_submatrices(mode, directory, filename, suffix);
812 }
813
814 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
815 {
816 _first.write_out(mode, directory + prefix + "_td" + stringify(length) + suffix);
817 }
818
819 TupleDiagMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
820 {
821 return TupleDiagMatrix(_first.clone(mode));
822 }
823
825 std::size_t bytes() const
826 {
827 return _first.bytes();
828 }
829
830 TupleDiagMatrix transpose() const
831 {
832 return TupleDiagMatrix(_first.transpose());
833 }
834
835 template<int i, int j>
836 typename TupleElement<i, First_>::Type& at()
837 {
838 static_assert(i == 0, "invalid sub-matrix index");
839 static_assert(j == 0, "invalid sub-matrix index");
840 return _first;
841 }
842
843 template<int i, int j>
844 const typename TupleElement<i, First_>::Type& at() const
845 {
846 static_assert(i == 0, "invalid sub-matrix index");
847 static_assert(j == 0, "invalid sub-matrix index");
848 return _first;
849 }
850
851 First_& first()
852 {
853 return _first;
854 }
855
856 const First_& first() const
857 {
858 return _first;
859 }
860
861 int row_blocks() const
862 {
863 return 1;
864 }
865
866 int col_blocks() const
867 {
868 return 1;
869 }
870
871 Index rows() const
872 {
873 return first().rows();
874 }
875
876 Index columns() const
877 {
878 return first().columns();
879 }
880
881 Index used_elements() const
882 {
883 return first().used_elements();
884 }
885
886 void format(DataType value = DataType(0))
887 {
888 first().format(value);
889 }
890
891 void clear()
892 {
893 first().clear();
894 }
895
896 Index size() const
897 {
898 return rows() * columns();
899 }
900
902 static String name()
903 {
904 return String("TupleDiagMatrix<") + sub_name_list() + ">";
905 }
906
907 void extract_diag(VectorTypeL& diag) const
908 {
909 first().extract_diag(diag.first());
910 }
911
912 void apply(VectorTypeL& r, const VectorTypeR& x) const
913 {
914 first().apply(r.first(), x.first());
915 }
916
917 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
918 {
919 first().apply(r.first(), x.first(), y.first(), alpha);
920 }
921
922 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
923 {
924 first().apply_transposed(r.first(), x.first());
925 }
926
927 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
928 {
929 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
930 }
931
934 {
935 return VectorTypeL(first().create_vector_l());
936 }
937
940 {
941 return VectorTypeR(first().create_vector_r());
942 }
943
944 void scale_rows(const TupleDiagMatrix& a, const VectorTypeL& w)
945 {
946 first().scale_rows(a.first(), w.first());
947 }
948
949 void scale_cols(const TupleDiagMatrix& a, const VectorTypeR& w)
950 {
951 first().scale_cols(a.first(), w.first());
952 }
953
955 Index get_length_of_line(const Index row) const
956 {
957 return this->first().get_length_of_line(row);
958 }
959
961 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
962 const Index col_start, const Index stride = 1) const
963 {
964 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
965 }
966
967 void set_line_reverse(const Index row, DataType * const pval_set, const Index stride = 1) const
968 {
969 this->first().set_line_reverse(row, pval_set, stride);
970 }
971
973 std::uint64_t get_checkpoint_size(SerialConfig& config)
974 {
975 return _first.get_checkpoint_size(config);
976 }
977
979 void restore_from_checkpoint_data(std::vector<char> & data)
980 {
981 _first.restore_from_checkpoint_data(data);
982 }
983
985 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
986 {
987 return _first.set_checkpoint_data(data, config);
988 }
989
997 template <typename First2_>
998 void convert(const TupleDiagMatrix<First2_>& other)
999 {
1000 this->first().convert(other.first());
1001 }
1002
1003 template <typename First2_>
1004 void convert_reverse(TupleDiagMatrix<First2_>& other) const
1005 {
1006 this->first().convert_reverse(other.first());
1007 }
1008
1017 bool same_layout(const TupleDiagMatrix& x) const
1018 {
1019 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1020 }
1021 };
1023 } // namespace LAFEM
1024} // 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.
Config class for serialize parameter.
Definition: container.hpp:47
Tuple-Diag-Matrix meta class template.
void write_out(FileMode mode, String filename) const
Write out matrix to file.
TupleDiagMatrix< Rest_... > RestClass
rest-class typedef
TupleDiagMatrix(FileMode mode, std::istream &file, const String &directory="")
Constructor.
TupleDiagMatrix & operator=(TupleDiagMatrix &&other)
move-assign operator
void convert(const TupleDiagMatrix< First2_, Rest2_... > &other)
Conversion method.
TupleDiagMatrix(const TupleDiagMatrix &)=delete
deleted copy-ctor
TupleDiagMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a deep copy of this matrix.
TupleDiagMatrix(First_ &&the_first, RestClass &&the_rest)
base-class constructor; this one is protected for a reason
void restore_from_checkpoint_data(std::vector< char > &data)
Extract object from checkpoint.
Index columns() const
Returns the total number of columns in this matrix.
void format(DataType value=DataType(0))
Reset all elements of the container to a given value or zero if missing.
Index get_length_of_line(const Index row) const
Returns the number of NNZ-elements of the selected row.
TupleDiagMatrix< typename First_::template ContainerType< DT2_, IT2_ >, typename Rest_::template ContainerType< DT2_, IT2_ >... > ContainerType
Our 'base' class type.
TupleDiagMatrix & operator=(const TupleDiagMatrix &)=delete
deleted copy-assign operator
First_ _first
the first sub-matrix
std::uint64_t get_checkpoint_size(SerialConfig &config)
Calculate size.
VectorTypeR create_vector_r() const
Returns a new compatible R-Vector.
const TupleElement< i_, First_, Rest_... >::Type & at() 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.
void apply(VectorTypeL &r, const VectorTypeR &x) const
Applies this matrix onto a vector.
void read_from(FileMode mode, const String &filename)
Read in matrix from file.
std::uint64_t set_checkpoint_data(std::vector< char > &data, SerialConfig &config)
TupleDiagMatrix transpose() const
Creates and returns the transpose of this matrix.
First_::DataType DataType
sub-matrix data type
bool same_layout(const TupleDiagMatrix &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.
RestClass _rest
the remaining part
Index rows() const
Returns the total number of rows in this matrix.
TupleElement< i_, First_, Rest_... >::Type & at()
Returns a sub-matrix block.
void clear()
Free all allocated arrays.
TupleDiagMatrix(FileMode mode, const String &filename)
Constructor.
static String name()
Returns a descriptive string for this container.
void extract_diag(VectorTypeL &diag) const
extract main diagonal vector from matrix
virtual ~TupleDiagMatrix()
virtual destructor
std::size_t bytes() const
Returns the total amount of bytes allocated.
TupleVector< typename First_::VectorTypeL, typename Rest_::VectorTypeL... > VectorTypeL
Compatible L-vector type.
TupleVector< typename First_::VectorTypeR, typename Rest_::VectorTypeR... > VectorTypeR
Compatible R-vector type.
void write_out_submatrices(FileMode mode, const String &directory, const String &prefix, const String &suffix, Index length=num_row_blocks) const
Write out submatrices to file.
static String sub_name_list()
Returns a list of all sub-matrix type names.
void apply_transposed(VectorTypeR &r, const VectorTypeL &x) const
Applies this matrix onto a vector.
static constexpr int num_row_blocks
number of row blocks (vertical size)
TupleDiagMatrix(TupleDiagMatrix &&other)
move ctor
First_::IndexType IndexType
sub-matrix index type
static constexpr int num_col_blocks
number of column blocks (horizontal size)
Index used_elements() const
Returns the total number of non-zeros in this matrix.
TupleDiagMatrix(First_ &&the_first, Rest_ &&... the_rest)
Sub-Matrix emplacement constructor.
VectorTypeL create_vector_l() const
Returns a new compatible L-Vector.
Variadic TupleVector class template.
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
@ 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.
Tuple container element helper class template.