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 }
609
610 Index row_degree(const Index row) const
611 {
612 const Index first_rows = first().template rows<Perspective::pod>();
613 if(row < first_rows)
614 return first().row_degree(row);
615 else
616 return rest().row_degree(row - first_rows);
617 }
618
619 template<typename IT2_>
620 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
621 {
622 const Index first_rows = first().template rows<Perspective::pod>();
623 const Index first_cols = first().template columns<Perspective::pod>();
624 if(row < first_rows)
625 return first().get_row_col_indices(row, pcol_idx, col_offset);
626 else
627 return rest().get_row_col_indices(row - first_rows, pcol_idx, col_offset + IT2_(first_cols));
628 }
629
630 template<typename DT2_>
631 Index get_row_values(const Index row, DT2_ * const pvals) const
632 {
633 const Index first_rows = first().template rows<Perspective::pod>();
634 if(row < first_rows)
635 return first().get_row_values(row, pvals);
636 else
637 return rest().get_row_values(row - first_rows, pvals);
638 }
639
640 template<typename DT2_>
641 Index set_row_values(const Index row, const DT2_ * const pvals)
642 {
643 const Index first_rows = first().template rows<Perspective::pod>();
644 if(row < first_rows)
645 return first().set_row_values(row, pvals);
646 else
647 return rest().set_row_values(row - first_rows, pvals);
648 }
649
651
653 std::uint64_t get_checkpoint_size(SerialConfig& config)
654 {
655 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
656 }
657
659 void restore_from_checkpoint_data(std::vector<char> & data)
660 {
661 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
662 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
663 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
664 std::vector<char> buffer_first(start, last_of_first);
665 _first.restore_from_checkpoint_data(buffer_first);
666
667 data.erase(std::begin(data), last_of_first);
669 }
670
672 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
673 {
674 std::size_t old_size = data.size();
675 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
676 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
677 char* csize = reinterpret_cast<char*>(&ireal_size);
678 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
679 {
680 data[old_size +i] = csize[i];
681 }
682
683 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
684 }
685
693 template <typename First2_, typename... Rest2_>
695 {
696 this->first().convert(other.first());
697 this->rest().convert(other.rest());
698 }
699
700 template <typename First2_, typename... Rest2_>
701 void convert_reverse(TupleDiagMatrix<First2_, Rest2_...>& other) const
702 {
703 this->first().convert_reverse(other.first());
704 this->rest().convert_reverse(other.rest());
705 }
706
715 bool same_layout(const TupleDiagMatrix& x) const
716 {
717 return (this->name() == x.name()) && (this->first().same_layout(x.first())) && (this->rest().same_layout(x.rest()));
718 }
719 };
720
722 template<typename First_>
723 class TupleDiagMatrix<First_>
724 {
725 template<typename,typename...>
726 friend class TupleDiagMatrix;
727
728 public:
729 typedef typename First_::DataType DataType;
730 typedef typename First_::IndexType IndexType;
732 typedef TupleVector<typename First_::VectorTypeL> VectorTypeL;
734 typedef TupleVector<typename First_::VectorTypeR> VectorTypeR;
735
736 template <typename DT2_ = DataType, typename IT2_ = IndexType>
737 using ContainerType = TupleDiagMatrix<typename First_::template ContainerType<DT2_, IT2_> >;
738
739 static constexpr int num_row_blocks = 1;
740 static constexpr int num_col_blocks = 1;
741
742 protected:
743 First_ _first;
744
745 static String sub_name_list()
746 {
747 return First_::name();
748 }
749
750 public:
752 TupleDiagMatrix()
753 {
754 }
755
756 explicit TupleDiagMatrix(First_&& the_first) :
757 _first(std::forward<First_>(the_first))
758 {
759 }
760
762 TupleDiagMatrix(TupleDiagMatrix&& other) :
763 _first(std::forward<First_>(other._first))
764 {
765 }
766
768 explicit TupleDiagMatrix(FileMode mode, const String& filename)
769 {
770 read_from(mode, filename);
771 }
772
774 explicit TupleDiagMatrix(FileMode mode, std::istream& file, const String& directory = "")
775 {
776 String line;
777 do {
778 if (file.eof())
779 XABORTM("Wrong Input-file");
780 std::getline(file, line);
781 line.trim_me();
782 } while (line.find("%%") == 0 || line == "");
783
784 _first = First_(mode, directory + line);
785 }
786
787 void read_from(FileMode mode, const String& filename)
788 {
789 String directory;
790 auto found = filename.rfind("/");
791 if (found != std::string::npos)
792 {
793 directory = filename.substr(0, found + 1);
794 }
795
796 std::ifstream file(filename.c_str(), std::ifstream::in);
797 if (! file.is_open())
798 XABORTM("Unable to open Matrix file " + filename);
799
800 TupleDiagMatrix other(mode, file, directory);
801
802 _first = std::move(other._first);
803
804 file.close();
805 }
806
808 TupleDiagMatrix& operator=(TupleDiagMatrix&& other)
809 {
810 if(this != &other)
811 {
812 _first = std::forward<First_>(other._first);
813 }
814 return *this;
815 }
816
818 TupleDiagMatrix(const TupleDiagMatrix&) = delete;
820 TupleDiagMatrix& operator=(const TupleDiagMatrix&) = delete;
821
823 virtual ~TupleDiagMatrix()
824 {
825 }
826
827 void write_out(FileMode mode, String filename) const
828 {
829 std::ofstream file(filename.c_str(), std::ofstream::out);
830 if (! file.is_open())
831 XABORTM("Unable to open Matrix file " + filename);
832
833 String suffix, directory;
834 auto found = filename.rfind(".");
835 if (found != std::string::npos)
836 {
837 suffix = filename.substr(found);
838 filename.erase(found);
839 }
840 found = filename.rfind("/");
841 if (found != std::string::npos)
842 {
843 directory = filename.substr(0, found + 1);
844 filename.erase(0, found + 1);
845 }
846
847 file << "%%MatrixMarket tuplediagmatrix coordinate real general\n";
848 file << filename << "_td" << 1 << suffix << "\n";
849
850 file.close();
851
852 this->write_out_submatrices(mode, directory, filename, suffix);
853 }
854
855 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
856 {
857 _first.write_out(mode, directory + prefix + "_td" + stringify(length) + suffix);
858 }
859
860 TupleDiagMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
861 {
862 return TupleDiagMatrix(_first.clone(mode));
863 }
864
866 std::size_t bytes() const
867 {
868 return _first.bytes();
869 }
870
871 TupleDiagMatrix transpose() const
872 {
873 return TupleDiagMatrix(_first.transpose());
874 }
875
876 template<int i, int j>
877 typename TupleElement<i, First_>::Type& at()
878 {
879 static_assert(i == 0, "invalid sub-matrix index");
880 static_assert(j == 0, "invalid sub-matrix index");
881 return _first;
882 }
883
884 template<int i, int j>
885 const typename TupleElement<i, First_>::Type& at() const
886 {
887 static_assert(i == 0, "invalid sub-matrix index");
888 static_assert(j == 0, "invalid sub-matrix index");
889 return _first;
890 }
891
892 First_& first()
893 {
894 return _first;
895 }
896
897 const First_& first() const
898 {
899 return _first;
900 }
901
902 int row_blocks() const
903 {
904 return 1;
905 }
906
907 int col_blocks() const
908 {
909 return 1;
910 }
911
912 Index rows() const
913 {
914 return first().rows();
915 }
916
917 Index columns() const
918 {
919 return first().columns();
920 }
921
922 Index used_elements() const
923 {
924 return first().used_elements();
925 }
926
927 void format(DataType value = DataType(0))
928 {
929 first().format(value);
930 }
931
932 void clear()
933 {
934 first().clear();
935 }
936
937 Index size() const
938 {
939 return rows() * columns();
940 }
941
943 static String name()
944 {
945 return String("TupleDiagMatrix<") + sub_name_list() + ">";
946 }
947
948 void extract_diag(VectorTypeL& diag) const
949 {
950 first().extract_diag(diag.first());
951 }
952
953 void apply(VectorTypeL& r, const VectorTypeR& x) const
954 {
955 first().apply(r.first(), x.first());
956 }
957
958 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
959 {
960 first().apply(r.first(), x.first(), y.first(), alpha);
961 }
962
963 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
964 {
965 first().apply_transposed(r.first(), x.first());
966 }
967
968 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
969 {
970 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
971 }
972
975 {
976 return VectorTypeL(first().create_vector_l());
977 }
978
981 {
982 return VectorTypeR(first().create_vector_r());
983 }
984
985 void scale_rows(const TupleDiagMatrix& a, const VectorTypeL& w)
986 {
987 first().scale_rows(a.first(), w.first());
988 }
989
990 void scale_cols(const TupleDiagMatrix& a, const VectorTypeR& w)
991 {
992 first().scale_cols(a.first(), w.first());
993 }
994
996 Index get_length_of_line(const Index row) const
997 {
998 return this->first().get_length_of_line(row);
999 }
1000
1002 void set_line(const Index row, DataType * const pval_set, IndexType * const pcol_set,
1003 const Index col_start, const Index stride = 1) const
1004 {
1005 this->first().set_line(row, pval_set, pcol_set, col_start, stride);
1006 }
1007
1008 void set_line_reverse(const Index row, DataType * const pval_set, const Index stride = 1) const
1009 {
1010 this->first().set_line_reverse(row, pval_set, stride);
1011 }
1012
1013 Index row_degree(const Index row) const
1014 {
1015 return first().row_degree(row);
1016 }
1017
1018 template<typename IT2_>
1019 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
1020 {
1021 return first().get_row_col_indices(row, pcol_idx, col_offset);
1022 }
1023
1024 template<typename DT2_>
1025 Index get_row_values(const Index row, DT2_ * const pvals) const
1026 {
1027 return first().get_row_values(row, pvals);
1028 }
1029
1030 template<typename DT2_>
1031 Index set_row_values(const Index row, const DT2_ * const pvals)
1032 {
1033 return first().set_row_values(row, pvals);
1034 }
1035
1037 std::uint64_t get_checkpoint_size(SerialConfig& config)
1038 {
1039 return _first.get_checkpoint_size(config);
1040 }
1041
1043 void restore_from_checkpoint_data(std::vector<char> & data)
1044 {
1045 _first.restore_from_checkpoint_data(data);
1046 }
1047
1049 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1050 {
1051 return _first.set_checkpoint_data(data, config);
1052 }
1053
1061 template <typename First2_>
1062 void convert(const TupleDiagMatrix<First2_>& other)
1063 {
1064 this->first().convert(other.first());
1065 }
1066
1067 template <typename First2_>
1068 void convert_reverse(TupleDiagMatrix<First2_>& other) const
1069 {
1070 this->first().convert_reverse(other.first());
1071 }
1072
1081 bool same_layout(const TupleDiagMatrix& x) const
1082 {
1083 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1084 }
1085 };
1087 } // namespace LAFEM
1088} // 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:47
String & trim_me(const String &charset)
Trims this string.
Definition: string.hpp:359
@ 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:993
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
Tuple container element helper class template.