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
334 {
335 return first().num_rows() + rest().num_rows();
336 }
337
340 {
341 return first().num_cols() + rest().num_cols();
342 }
343
346 {
347 return first().num_nzes() + rest().num_nzes();
348 }
349
352 {
353 return first().num_rows_raw() + rest().num_rows_raw();
354 }
355
358 {
359 return first().num_cols_raw() + rest().num_cols_raw();
360 }
361
364 {
365 return first().num_nzes_raw() + rest().num_nzes_raw();
366 }
367
369 static String name()
370 {
371 return String("TupleDiagMatrix<") + sub_name_list() + ">";
372 }
373
380 void format()
381 {
382 first().format();
383 rest().format();
384 }
385
386 void format(DataType value)
387 {
388 first().format(value);
389 rest().format(value);
390 }
391
395 void clear()
396 {
397 first().clear();
398 rest().clear();
399 }
400
402 void extract_diag(VectorTypeL& diag) const
403 {
404 first().extract_diag(diag.first());
405 rest().extract_diag(diag.rest());
406 }
407
420 void apply(VectorTypeL& r, const VectorTypeR& x) const
421 {
422 first().apply(r.first(), x.first());
423 rest().apply(r.rest(), x.rest());
424 }
425
427 {
428 XASSERTM(r.size() == this->num_rows(), "Vector size of r does not match!");
429 XASSERTM(x.size() == this->num_cols(), "Vector size of x does not match!");
430
431 DenseVector<DataType, IndexType> r_first(r, first().num_rows(), 0);
432 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
433
434 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
435 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
436
437 first().apply(r_first, x_first);
438 rest().apply(r_rest, x_rest);
439 }
440
453 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
454 {
455 first().apply_transposed(r.first(), x.first());
456 rest().apply_transposed(r.rest(), x.rest());
457 }
458
460 {
461 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
462 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
463
464 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
465 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
466
467 DenseVector<DataType, IndexType> x_first(x, first().num_rows(), 0);
468 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
469
470 first().apply_transposed(r_first, x_first);
471 rest().apply_transposed(r_rest, x_rest);
472 }
473
490 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
491 {
492 first().apply(r.first(), x.first(), y.first(), alpha);
493 rest().apply(r.rest(), x.rest(), y.rest(), alpha);
494 }
495
497 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
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 XASSERTM(y.size() == this->num_rows(), "Vector size of y does not match!");
502
503 DenseVector<DataType, IndexType> r_first(r, first().num_rows(), 0);
504 DenseVector<DataType, IndexType> r_rest(r, rest().num_rows(), first().num_rows());
505
506 DenseVector<DataType, IndexType> x_first(x, first().num_cols(), 0);
507 DenseVector<DataType, IndexType> x_rest(x, rest().num_cols(), first().num_cols());
508
509 DenseVector<DataType, IndexType> y_first(y, first().num_rows(), 0);
510 DenseVector<DataType, IndexType> y_rest(y, rest().num_rows(), first().num_rows());
511
512 first().apply(r_first, x_first, y_first, alpha);
513 rest().apply(r_rest, x_rest, y_rest, alpha);
514 }
515
532 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
533 {
534 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
535 rest().apply_transposed(r.rest(), x.rest(), y.rest(), alpha);
536 }
537
539 const DenseVector<DataType, IndexType>& y, DataType alpha = DataType(1)) const
540 {
541 XASSERTM(r.size() == this->num_cols(), "Vector size of r does not match!");
542 XASSERTM(x.size() == this->num_rows(), "Vector size of x does not match!");
543 XASSERTM(y.size() == this->num_cols(), "Vector size of y does not match!");
544
545 DenseVector<DataType, IndexType> r_first(r, first().num_cols(), 0);
546 DenseVector<DataType, IndexType> r_rest(r, rest().num_cols(), first().num_cols());
547
548 DenseVector<DataType, IndexType> x_first(x, first().num_rows(), 0);
549 DenseVector<DataType, IndexType> x_rest(x, rest().num_rows(), first().num_rows());
550
551 DenseVector<DataType, IndexType> y_first(y, first().num_cols(), 0);
552 DenseVector<DataType, IndexType> y_rest(y, rest().num_cols(), first().num_cols());
553
554 first().apply_transposed(r_first, x_first, y_first, alpha);
555 rest().apply_transposed(r_rest, x_rest, y_rest, alpha);
556 }
557
560 {
561 return VectorTypeL(first().create_vector_l(), rest().create_vector_l());
562 }
563
566 {
567 return VectorTypeR(first().create_vector_r(), rest().create_vector_r());
568 }
569
570 void scale_rows(const TupleDiagMatrix& a, const VectorTypeL& w)
571 {
572 first().scale_rows(a.first(), w.first());
573 rest().scale_rows(a.rest(), w.rest());
574 }
575
576 void scale_cols(const TupleDiagMatrix& a, const VectorTypeR& w)
577 {
578 first().scale_cols(a.first(), w.first());
579 rest().scale_cols(a.rest(), w.rest());
580 }
581
582 Index row_degree(const Index row) const
583 {
584 const Index first_rows = first().num_rows_raw();
585 if(row < first_rows)
586 return first().row_degree(row);
587 else
588 return rest().row_degree(row - first_rows);
589 }
590
591 template<typename IT2_>
592 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
593 {
594 const Index first_rows = first().num_rows_raw();
595 const Index first_cols = first().num_cols_raw();
596 if(row < first_rows)
597 return first().get_row_col_indices(row, pcol_idx, col_offset);
598 else
599 return rest().get_row_col_indices(row - first_rows, pcol_idx, col_offset + IT2_(first_cols));
600 }
601
602 template<typename DT2_>
603 Index get_row_values(const Index row, DT2_ * const pvals) const
604 {
605 const Index first_rows = first().num_rows_raw();
606 if(row < first_rows)
607 return first().get_row_values(row, pvals);
608 else
609 return rest().get_row_values(row - first_rows, pvals);
610 }
611
612 template<typename DT2_>
613 Index set_row_values(const Index row, const DT2_ * const pvals)
614 {
615 const Index first_rows = first().num_rows_raw();
616 if(row < first_rows)
617 return first().set_row_values(row, pvals);
618 else
619 return rest().set_row_values(row - first_rows, pvals);
620 }
621
623
625 std::uint64_t get_checkpoint_size(SerialConfig& config)
626 {
627 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
628 }
629
631 void restore_from_checkpoint_data(std::vector<char> & data)
632 {
633 std::uint64_t isize = *(std::uint64_t*) data.data(); //get size of checkpointed _first
634 std::vector<char>::iterator start = std::begin(data) + sizeof(std::uint64_t);
635 std::vector<char>::iterator last_of_first = std::begin(data) + sizeof(std::uint64_t) + (int) isize;
636 std::vector<char> buffer_first(start, last_of_first);
637 _first.restore_from_checkpoint_data(buffer_first);
638
639 data.erase(std::begin(data), last_of_first);
641 }
642
644 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
645 {
646 std::size_t old_size = data.size();
647 data.insert(std::end(data), sizeof(std::uint64_t), 0); //add placeholder
648 std::uint64_t ireal_size = _first.set_checkpoint_data(data, config); //add data of _first to the overall checkpoint and save its size
649 char* csize = reinterpret_cast<char*>(&ireal_size);
650 for(std::size_t i(0) ; i < sizeof(std::uint64_t) ; ++i) //overwrite the guessed datalength
651 {
652 data[old_size +i] = csize[i];
653 }
654
655 return sizeof(std::uint64_t) + ireal_size + _rest.set_checkpoint_data(data, config); //generate and add checkpoint data for the _rest
656 }
657
665 template <typename First2_, typename... Rest2_>
667 {
668 this->first().convert(source.first());
669 this->rest().convert(source.rest());
670 }
671
672 template <typename First2_, typename... Rest2_>
673 void copy(const TupleDiagMatrix<First2_, Rest2_...>& source)
674 {
675 this->first().copy(source.first());
676 this->rest().copy(source.rest());
677 }
678
679 template <typename First2_, typename... Rest2_>
680 void copy_to(TupleDiagMatrix<First2_, Rest2_...>& target) const
681 {
682 this->first().copy_to(target.first());
683 this->rest().copy_to(target.rest());
684 }
685
694 bool same_layout(const TupleDiagMatrix& x) const
695 {
696 return (this->name() == x.name()) && (this->first().same_layout(x.first())) && (this->rest().same_layout(x.rest()));
697 }
698 };
699
701 template<typename First_>
702 class TupleDiagMatrix<First_>
703 {
704 template<typename,typename...>
705 friend class TupleDiagMatrix;
706
707 public:
708 typedef typename First_::DataType DataType;
709 typedef typename First_::IndexType IndexType;
711 typedef TupleVector<typename First_::VectorTypeL> VectorTypeL;
713 typedef TupleVector<typename First_::VectorTypeR> VectorTypeR;
714
715 template <typename DT2_ = DataType, typename IT2_ = IndexType>
716 using ContainerType = TupleDiagMatrix<typename First_::template ContainerType<DT2_, IT2_> >;
717
718 static constexpr int num_row_blocks = 1;
719 static constexpr int num_col_blocks = 1;
720
721 protected:
722 First_ _first;
723
724 static String sub_name_list()
725 {
726 return First_::name();
727 }
728
729 public:
731 TupleDiagMatrix()
732 {
733 }
734
735 explicit TupleDiagMatrix(First_&& the_first) :
736 _first(std::forward<First_>(the_first))
737 {
738 }
739
741 TupleDiagMatrix(TupleDiagMatrix&& other) :
742 _first(std::forward<First_>(other._first))
743 {
744 }
745
747 explicit TupleDiagMatrix(FileMode mode, const String& filename)
748 {
749 read_from(mode, filename);
750 }
751
753 explicit TupleDiagMatrix(FileMode mode, std::istream& file, const String& directory = "")
754 {
755 String line;
756 do {
757 if (file.eof())
758 XABORTM("Wrong Input-file");
759 std::getline(file, line);
760 line.trim_me();
761 } while (line.find("%%") == 0 || line == "");
762
763 _first = First_(mode, directory + line);
764 }
765
766 void read_from(FileMode mode, const String& filename)
767 {
768 String directory;
769 auto found = filename.rfind("/");
770 if (found != std::string::npos)
771 {
772 directory = filename.substr(0, found + 1);
773 }
774
775 std::ifstream file(filename.c_str(), std::ifstream::in);
776 if (! file.is_open())
777 XABORTM("Unable to open Matrix file " + filename);
778
779 TupleDiagMatrix other(mode, file, directory);
780
781 _first = std::move(other._first);
782
783 file.close();
784 }
785
787 TupleDiagMatrix& operator=(TupleDiagMatrix&& other)
788 {
789 if(this != &other)
790 {
791 _first = std::forward<First_>(other._first);
792 }
793 return *this;
794 }
795
797 TupleDiagMatrix(const TupleDiagMatrix&) = delete;
799 TupleDiagMatrix& operator=(const TupleDiagMatrix&) = delete;
800
802 virtual ~TupleDiagMatrix()
803 {
804 }
805
806 void write_out(FileMode mode, String filename) const
807 {
808 std::ofstream file(filename.c_str(), std::ofstream::out);
809 if (! file.is_open())
810 XABORTM("Unable to open Matrix file " + filename);
811
812 String suffix, directory;
813 auto found = filename.rfind(".");
814 if (found != std::string::npos)
815 {
816 suffix = filename.substr(found);
817 filename.erase(found);
818 }
819 found = filename.rfind("/");
820 if (found != std::string::npos)
821 {
822 directory = filename.substr(0, found + 1);
823 filename.erase(0, found + 1);
824 }
825
826 file << "%%MatrixMarket tuplediagmatrix coordinate real general\n";
827 file << filename << "_td" << 1 << suffix << "\n";
828
829 file.close();
830
831 this->write_out_submatrices(mode, directory, filename, suffix);
832 }
833
834 void write_out_submatrices(FileMode mode, const String& directory, const String& prefix, const String& suffix, Index length = 1) const
835 {
836 _first.write_out(mode, directory + prefix + "_td" + stringify(length) + suffix);
837 }
838
839 TupleDiagMatrix clone(LAFEM::CloneMode mode = LAFEM::CloneMode::Weak) const
840 {
841 return TupleDiagMatrix(_first.clone(mode));
842 }
843
845 std::size_t bytes() const
846 {
847 return _first.bytes();
848 }
849
850 TupleDiagMatrix transpose() const
851 {
852 return TupleDiagMatrix(_first.transpose());
853 }
854
855 template<int i, int j>
856 typename TupleElement<i, First_>::Type& at()
857 {
858 static_assert(i == 0, "invalid sub-matrix index");
859 static_assert(j == 0, "invalid sub-matrix index");
860 return _first;
861 }
862
863 template<int i, int j>
864 const typename TupleElement<i, First_>::Type& at() const
865 {
866 static_assert(i == 0, "invalid sub-matrix index");
867 static_assert(j == 0, "invalid sub-matrix index");
868 return _first;
869 }
870
871 First_& first()
872 {
873 return _first;
874 }
875
876 const First_& first() const
877 {
878 return _first;
879 }
880
881 int row_blocks() const
882 {
883 return 1;
884 }
885
886 int col_blocks() const
887 {
888 return 1;
889 }
890
891 Index num_rows() const
892 {
893 return first().num_rows();
894 }
895
896 Index num_cols() const
897 {
898 return first().num_cols();
899 }
900
901 Index num_nzes() const
902 {
903 return first().num_nzes();
904 }
905
906 Index num_rows_raw() const
907 {
908 return first().num_rows_raw();
909 }
910
911 Index num_cols_raw() const
912 {
913 return first().num_cols_raw();
914 }
915
916 Index num_nzes_raw() const
917 {
918 return first().num_nzes_raw();
919 }
920
921 void format()
922 {
923 first().format();
924 }
925
926 void format(DataType value)
927 {
928 first().format(value);
929 }
930
931 void clear()
932 {
933 first().clear();
934 }
935
937 static String name()
938 {
939 return String("TupleDiagMatrix<") + sub_name_list() + ">";
940 }
941
942 void extract_diag(VectorTypeL& diag) const
943 {
944 first().extract_diag(diag.first());
945 }
946
947 void apply(VectorTypeL& r, const VectorTypeR& x) const
948 {
949 first().apply(r.first(), x.first());
950 }
951
952 void apply(VectorTypeL& r, const VectorTypeR& x, const VectorTypeL& y, DataType alpha = DataType(1)) const
953 {
954 first().apply(r.first(), x.first(), y.first(), alpha);
955 }
956
957 void apply_transposed(VectorTypeR& r, const VectorTypeL& x) const
958 {
959 first().apply_transposed(r.first(), x.first());
960 }
961
962 void apply_transposed(VectorTypeR& r, const VectorTypeL& x, const VectorTypeR& y, DataType alpha = DataType(1)) const
963 {
964 first().apply_transposed(r.first(), x.first(), y.first(), alpha);
965 }
966
969 {
970 return VectorTypeL(first().create_vector_l());
971 }
972
975 {
976 return VectorTypeR(first().create_vector_r());
977 }
978
979 void scale_rows(const TupleDiagMatrix& a, const VectorTypeL& w)
980 {
981 first().scale_rows(a.first(), w.first());
982 }
983
984 void scale_cols(const TupleDiagMatrix& a, const VectorTypeR& w)
985 {
986 first().scale_cols(a.first(), w.first());
987 }
988
989 Index row_degree(const Index row) const
990 {
991 return first().row_degree(row);
992 }
993
994 template<typename IT2_>
995 Index get_row_col_indices(const Index row, IT2_* const pcol_idx, const IT2_ col_offset) const
996 {
997 return first().get_row_col_indices(row, pcol_idx, col_offset);
998 }
999
1000 template<typename DT2_>
1001 Index get_row_values(const Index row, DT2_ * const pvals) const
1002 {
1003 return first().get_row_values(row, pvals);
1004 }
1005
1006 template<typename DT2_>
1007 Index set_row_values(const Index row, const DT2_ * const pvals)
1008 {
1009 return first().set_row_values(row, pvals);
1010 }
1011
1013 std::uint64_t get_checkpoint_size(SerialConfig& config)
1014 {
1015 return _first.get_checkpoint_size(config);
1016 }
1017
1019 void restore_from_checkpoint_data(std::vector<char> & data)
1020 {
1021 _first.restore_from_checkpoint_data(data);
1022 }
1023
1025 std::uint64_t set_checkpoint_data(std::vector<char>& data, SerialConfig& config)
1026 {
1027 return _first.set_checkpoint_data(data, config);
1028 }
1029
1037 template <typename First2_>
1038 void convert(const TupleDiagMatrix<First2_>& source)
1039 {
1040 this->first().convert(source.first());
1041 }
1042
1043 template <typename First2_>
1044 void copy(const TupleDiagMatrix<First2_>& source)
1045 {
1046 this->first().copy(source.first());
1047 }
1048
1049 template <typename First2_>
1050 void copy_to(TupleDiagMatrix<First2_>& target) const
1051 {
1052 this->first().copy_to(target.first());
1053 }
1054
1063 bool same_layout(const TupleDiagMatrix& x) const
1064 {
1065 return (this->name() == x.name()) && (this->first().same_layout(x.first()));
1066 }
1067 };
1069 } // namespace LAFEM
1070} // 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.
Config class for serialize parameter.
Definition: container.hpp:50
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
TupleDiagMatrix(const TupleDiagMatrix &)=delete
deleted copy-ctor
Index num_nzes_raw() const
Returns the total number of non-zeros in this matrix.
TupleDiagMatrix clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a deep copy of this matrix.
void format()
Reset all elements of the container to a given value or zero if missing.
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 num_nzes() const
Returns the total number of non-zeros in this matrix.
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 num_cols_raw() const
Returns the total number of columns in this matrix.
TupleElement< i_, First_, Rest_... >::Type & at()
Returns a sub-matrix block.
void clear()
Free all allocated arrays.
Index num_rows() const
Returns the total number of rows in this matrix.
void convert(const TupleDiagMatrix< First2_, Rest2_... > &source)
Conversion method.
Index num_cols() const
Returns the total number of columns in this matrix.
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 num_rows_raw() const
Returns the total number of rows 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.