Matrix.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "Matrix.H"
30#include <functional>
31#include <algorithm>
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35template<class Form, class Type>
36template<class ListType>
38(
39 const ListType& x
40) const
41{
42 const Matrix<Form, Type>& mat = *this;
43
44 #ifdef FULLDEBUG
45 if (mat.n() != x.size())
46 {
48 << "Attempt to multiply incompatible Matrix and Vector:" << nl
49 << "Matrix : (" << mat.m() << ", " << mat.n() << ')' << nl
50 << "Matrix columns != Vector size (" << x.size() << ')' << nl
51 << abort(FatalError);
52 }
53 #endif
54
55 auto tresult = tmp<Field<Type>>::New(mat.m(), Zero);
56 auto& result = tresult.ref();
57
58 for (label i = 0; i < mat.m(); ++i)
59 {
60 for (label j = 0; j < mat.n(); ++j)
61 {
62 result[i] += mat(i, j)*x[j];
63 }
64 }
65
66 return tresult;
67}
68
69
70template<class Form, class Type>
71template<class ListType>
73(
74 const ListType& x
75) const
76{
77 const Matrix<Form, Type>& mat = *this;
78
79 #ifdef FULLDEBUG
80 if (mat.m() != x.size())
81 {
83 << "Attempt to multiply incompatible Matrix and Vector:" << nl
84 << "Matrix : (" << mat.m() << ", " << mat.n() << ')' << nl
85 << "Matrix rows != Vector size (" << x.size() << ')' << nl
86 << abort(FatalError);
87 }
88 #endif
89
90 auto tresult = tmp<Field<Type>>::New(mat.n(), Zero);
91 auto& result = tresult.ref();
92
93 for (label i = 0; i < mat.m(); ++i)
94 {
95 const Type& val = x[i];
96 for (label j = 0; j < mat.n(); ++j)
97 {
98 result[j] += val*mat(i, j);
99 }
100 }
101
102 return tresult;
103}
104
105
106// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107
108template<class Form, class Type>
109Foam::Matrix<Form, Type>::Matrix(const label m, const label n)
110:
111 mRows_(m),
112 nCols_(n),
113 v_(nullptr)
114{
115 checkSize();
116
117 doAlloc();
118}
119
120
121template<class Form, class Type>
122Foam::Matrix<Form, Type>::Matrix(const label m, const label n, const Foam::zero)
123:
124 mRows_(m),
125 nCols_(n),
126 v_(nullptr)
127{
128 checkSize();
129
130 doAlloc();
131
132 std::fill(begin(), end(), Zero);
133}
134
136template<class Form, class Type>
137Foam::Matrix<Form, Type>::Matrix(const label m, const label n, const Type& val)
138:
139 mRows_(m),
140 nCols_(n),
141 v_(nullptr)
142{
143 checkSize();
144
145 doAlloc();
146
147 std::fill(begin(), end(), val);
148}
149
150
151template<class Form, class Type>
153:
154 mRows_(mat.mRows_),
155 nCols_(mat.nCols_),
156 v_(nullptr)
158 if (mat.cdata())
159 {
160 doAlloc();
161
162 std::copy(mat.cbegin(), mat.cend(), v_);
163 }
165
166
167template<class Form, class Type>
169:
170 mRows_(mat.mRows_),
171 nCols_(mat.nCols_),
172 v_(mat.v_)
173{
174 mat.mRows_ = 0;
175 mat.nCols_ = 0;
176 mat.v_ = nullptr;
177}
178
179
180template<class Form, class Type>
181template<class Form2>
183:
184 mRows_(mat.m()),
185 nCols_(mat.n()),
186 v_(nullptr)
187{
188 if (mat.cdata())
189 {
190 doAlloc();
191
192 std::copy(mat.cbegin(), mat.cend(), v_);
193 }
194}
195
196
197template<class Form, class Type>
198template<class MatrixType>
200(
202)
203:
204 mRows_(Mb.m()),
205 nCols_(Mb.n())
206{
207 doAlloc();
208
209 for (label i = 0; i < mRows_; ++i)
210 {
211 for (label j = 0; j < nCols_; ++j)
212 {
213 (*this)(i, j) = Mb(i,j);
214 }
215 }
216}
217
218
219template<class Form, class Type>
220template<class MatrixType>
222(
224)
225:
226 mRows_(Mb.m()),
227 nCols_(Mb.n())
228{
229 doAlloc();
230
231 for (label i = 0; i < mRows_; ++i)
232 {
233 for (label j = 0; j < nCols_; ++j)
234 {
235 (*this)(i, j) = Mb(i, j);
236 }
237 }
238}
239
240
241// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
242
243template<class Form, class Type>
245{
246 if (v_)
247 {
248 delete[] v_;
249 }
250}
251
252
253// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
254
255template<class Form, class Type>
257{
258 if (v_)
259 {
260 delete[] v_;
261 v_ = nullptr;
262 }
263
264 mRows_ = 0;
265 nCols_ = 0;
266}
267
268
269template<class Form, class Type>
271{
272 List<Type> list;
273
274 const label len = size();
275
276 if (v_ && len)
277 {
278 UList<Type> storage(v_, len);
279 list.swap(storage);
280
281 v_ = nullptr;
282 }
283 clear();
284
285 return list;
286}
287
288
289template<class Form, class Type>
291{
292 if (this == &mat)
293 {
294 return; // Self-swap is a no-op
295 }
296
297 std::swap(mRows_, mat.mRows_);
298 std::swap(nCols_, mat.nCols_);
299 std::swap(v_, mat.v_);
300}
301
302
303template<class Form, class Type>
305{
306 if (this == &mat)
307 {
308 return; // Self-assignment is a no-op
309 }
310
311 clear();
312
313 mRows_ = mat.mRows_;
314 nCols_ = mat.nCols_;
315 v_ = mat.v_;
316
317 mat.mRows_ = 0;
318 mat.nCols_ = 0;
319 mat.v_ = nullptr;
320}
321
322
323template<class Form, class Type>
324void Foam::Matrix<Form, Type>::resize(const label m, const label n)
325{
326 if (m == mRows_ && n == nCols_)
327 {
328 return;
329 }
330
331 Matrix<Form, Type> newMatrix(m, n, Zero);
332
333 const label mrow = min(m, mRows_);
334 const label ncol = min(n, nCols_);
335
336 for (label i = 0; i < mrow; ++i)
337 {
338 for (label j = 0; j < ncol; ++j)
339 {
340 newMatrix(i, j) = (*this)(i, j);
341 }
342 }
344 transfer(newMatrix);
345}
346
348template<class Form, class Type>
349void Foam::Matrix<Form, Type>::resize_nocopy(const label mrow, const label ncol)
351 if (mrow == mRows_ && ncol == nCols_)
352 {
353 return;
355
356 const label oldLen = (mRows_ * nCols_);
358 const label newLen = (mrow * ncol);
359
360 if (oldLen == newLen)
361 {
362 // Shallow resize is enough
363 mRows_ = mrow;
364 nCols_ = ncol;
365 }
366 else
367 {
368 this->clear();
370 mRows_ = mrow;
371 nCols_ = ncol;
372
373 this->doAlloc();
374 }
376
377
378template<class Form, class Type>
380{
381 for (Type& val : *this)
382 {
383 if (mag(val) < tol)
384 {
385 val = Zero;
386 }
387 }
388}
389
390
391template<class Form, class Type>
393{
394 Form At(labelPair{n(), m()});
395
396 for (label i = 0; i < m(); ++i)
397 {
398 for (label j = 0; j < n(); ++j)
399 {
400 At(j, i) = Detail::conj((*this)(i, j));
402 }
403
404 return At;
405}
406
408template<class Form, class Type>
410{
411 Form At(labelPair{n(), m()});
412
413 for (label i = 0; i < m(); ++i)
414 {
415 for (label j = 0; j < n(); ++j)
416 {
417 At(j, i) = (*this)(i, j);
418 }
419 }
420
421 return At;
422}
423
424
425template<class Form, class Type>
427{
428 const label len = Foam::min(mRows_, nCols_);
429
430 List<Type> result(len);
431
432 for (label i=0; i < len; ++i)
433 {
434 result[i] = (*this)(i, i);
435 }
436
437 return result;
438}
439
441template<class Form, class Type>
443{
444 const label len = Foam::min(mRows_, nCols_);
445
446 #ifdef FULLDEBUG
447 if (list.size() != len)
450 << "List size (" << list.size()
451 << ") incompatible with Matrix diagonal" << abort(FatalError);
452 }
453 #endif
455 for (label i=0; i < len; ++i)
456 {
457 (*this)(i, i) = list[i];
458 }
459}
461
462template<class Form, class Type>
464{
465 const label len = Foam::min(mRows_, nCols_);
467 Type val = Zero;
468
469 for (label i=0; i < len; ++i)
470 {
471 val += (*this)(i, i);
473
474 return val;
475}
476
477
478template<class Form, class Type>
480(
481 const label colIndex,
482 const bool noSqrt
483) const
484{
485 scalar result = Zero;
486
487 for (label i=0; i < mRows_; ++i)
488 {
489 result += magSqr((*this)(i, colIndex));
490 }
491
492 return noSqrt ? result : Foam::sqrt(result);
493}
494
495
496template<class Form, class Type>
497Foam::scalar Foam::Matrix<Form, Type>::norm(const bool noSqrt) const
498{
499 scalar result = Zero;
500
501 for (const Type& val : *this)
502 {
503 result += magSqr(val);
504 }
505
506 return noSqrt ? result : Foam::sqrt(result);
507}
508
509
510template<class Form, class Type>
512{
514 {
516 << "Invalid for non-contiguous data types"
517 << abort(FatalError);
518 }
519 return this->size_bytes();
520}
521
522
523// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
524
525template<class Form, class Type>
527{
528 if (this == &mat)
529 {
530 return; // Self-assignment is a no-op
531 }
532
533 if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
534 {
535 clear();
536 mRows_ = mat.mRows_;
537 nCols_ = mat.nCols_;
538 doAlloc();
539 }
540
541 if (v_)
542 {
543 std::copy(mat.cbegin(), mat.cend(), v_);
544 }
545}
546
547
548template<class Form, class Type>
550{
551 if (this != &mat)
552 {
553 // Self-assignment is a no-op
554 this->transfer(mat);
555 }
556}
557
558
559template<class Form, class Type>
560template<class MatrixType>
562(
564)
565{
566 for (label i = 0; i < mRows_; ++i)
567 {
568 for (label j = 0; j < nCols_; ++j)
569 {
570 (*this)(i, j) = Mb(i, j);
571 }
572 }
573}
574
575
576template<class Form, class Type>
577template<class MatrixType>
579(
581)
582{
583 for (label i = 0; i < mRows_; ++i)
584 {
585 for (label j = 0; j < nCols_; ++j)
586 {
587 (*this)(i, j) = Mb(i, j);
588 }
589 }
590}
591
592
593template<class Form, class Type>
595{
596 std::fill(begin(), end(), val);
597}
598
599
600template<class Form, class Type>
602{
603 std::fill(begin(), end(), Zero);
604}
605
606
607template<class Form, class Type>
609{
610 #ifdef FULLDEBUG
611 if (this == &other)
612 {
614 << "Attempted addition to self"
615 << abort(FatalError);
616 }
617
618 if (m() != other.m() || n() != other.n())
619 {
621 << "Attempt to add matrices with different sizes: ("
622 << m() << ", " << n() << ") != ("
623 << other.m() << ", " << other.n() << ')' << nl
624 << abort(FatalError);
625 }
626 #endif
627
628 auto iter2 = other.cbegin();
629 for (Type& val : *this)
630 {
631 val += *iter2;
632 ++iter2;
633 }
634}
635
636
637template<class Form, class Type>
639{
640 #ifdef FULLDEBUG
641 if (this == &other)
642 {
644 << "Attempted subtraction from self"
645 << abort(FatalError);
646 }
647
648 if (m() != other.m() || n() != other.n())
649 {
651 << "Attempt to subtract matrices with different sizes: ("
652 << m() << ", " << n() << ") != ("
653 << other.m() << ", " << other.n() << ')' << nl
654 << abort(FatalError);
655 }
656 #endif
657
658 auto iter2 = other.cbegin();
659 for (Type& val : *this)
660 {
661 val -= *iter2;
662 ++iter2;
663 }
664}
665
666
667template<class Form, class Type>
669{
670 for (Type& val : *this)
671 {
672 val += s;
673 }
674}
675
676
677template<class Form, class Type>
679{
680 for (Type& val : *this)
681 {
682 val -= s;
683 }
684}
685
686
687template<class Form, class Type>
689{
690 for (Type& val : *this)
691 {
692 val *= s;
693 }
694}
695
696
697template<class Form, class Type>
699{
700 for (Type& val : *this)
701 {
702 val /= s;
703 }
704}
705
706
707// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
708
709namespace Foam
710{
711
712// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
713
714//- Find max value in Matrix
715template<class Form, class Type>
716const Type& max(const Matrix<Form, Type>& mat)
717{
718 if (mat.empty())
719 {
721 << "Matrix is empty" << abort(FatalError);
722 }
723
724 return *(std::max_element(mat.cbegin(), mat.cend()));
725}
726
727
728//- Find min value in Matrix
729template<class Form, class Type>
730const Type& min(const Matrix<Form, Type>& mat)
731{
732 if (mat.empty())
733 {
735 << "Matrix is empty" << abort(FatalError);
736 }
737
738 return *(std::min_element(mat.cbegin(), mat.cend()));
739}
740
741
742//- Find the min/max values of Matrix
743template<class Form, class Type>
745{
746 MinMax<Type> result;
747
748 for (const Type& val : mat)
749 {
750 result += val;
751 }
752
753 return result;
754}
755
756
757
758// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
759
760//- Matrix negation
761template<class Form, class Type>
763{
764 Form result(mat.sizes());
765
766 std::transform
767 (
768 mat.cbegin(),
769 mat.cend(),
770 result.begin(),
771 std::negate<Type>()
772 );
773
774 return result;
775}
776
777
778//- Matrix addition. Returns Matrix of the same form as the first parameter.
779template<class Form1, class Form2, class Type>
780Form1 operator+
781(
782 const Matrix<Form1, Type>& A,
784)
785{
786 #ifdef FULLDEBUG
787 if (A.m() != B.m() || A.n() != B.n())
788 {
790 << "Attempt to add matrices with different sizes: ("
791 << A.m() << ", " << A.n() << ") != ("
792 << B.m() << ", " << B.n() << ')' << nl
793 << abort(FatalError);
794 }
795 #endif
796
797 Form1 result(A.sizes());
798
799 std::transform
800 (
801 A.cbegin(),
802 A.cend(),
803 B.cbegin(),
804 result.begin(),
805 std::plus<Type>()
806 );
807
808 return result;
809}
810
811
812//- Matrix subtraction. Returns Matrix of the same form as the first parameter.
813template<class Form1, class Form2, class Type>
814Form1 operator-
815(
816 const Matrix<Form1, Type>& A,
818)
819{
820 #ifdef FULLDEBUG
821 if (A.m() != B.m() || A.n() != B.n())
822 {
824 << "Attempt to subtract matrices with different sizes: ("
825 << A.m() << ", " << A.n() << ") != ("
826 << B.m() << ", " << B.n() << ')' << nl
827 << abort(FatalError);
828 }
829 #endif
830
831 Form1 result(A.sizes());
832
833 std::transform
834 (
835 A.cbegin(),
836 A.cend(),
837 B.cbegin(),
838 result.begin(),
839 std::minus<Type>()
840 );
841
842 return result;
843}
844
845
846//- Scalar multiplication of Matrix
847template<class Form, class Type>
848Form operator*(const Type& s, const Matrix<Form, Type>& mat)
849{
850 Form result(mat.sizes());
851
852 std::transform
853 (
854 mat.cbegin(),
855 mat.cend(),
856 result.begin(),
857 [&](const Type& val) { return s * val; }
858 );
859
860 return result;
861}
862
863
864//- Scalar multiplication of Matrix
865template<class Form, class Type>
866Form operator*(const Matrix<Form, Type>& mat, const Type& s)
867{
868 return s*mat;
869}
870
871
872//- Scalar addition of Matrix
873template<class Form, class Type>
874Form operator+(const Type& s, const Matrix<Form, Type>& mat)
875{
876 Form result(mat.sizes());
877
878 std::transform
879 (
880 mat.cbegin(),
881 mat.cend(),
882 result.begin(),
883 [&](const Type& val) { return s + val; }
884 );
885
886 return result;
887}
888
889
890//- Scalar addition of Matrix
891template<class Form, class Type>
892Form operator+(const Matrix<Form, Type>& mat, const Type& s)
893{
894 return s + mat;
895}
896
897
898//- Scalar subtraction of Matrix
899template<class Form, class Type>
900Form operator-(const Type& s, const Matrix<Form, Type>& mat)
901{
902 Form result(mat.sizes());
903
904 std::transform
905 (
906 mat.cbegin(),
907 mat.end(),
908 result.begin(),
909 [&](const Type& val) { return s - val; }
910 );
911
912 return result;
913}
914
915
916//- Scalar subtraction of Matrix
917template<class Form, class Type>
918Form operator-(const Matrix<Form, Type>& mat, const Type& s)
919{
920 Form result(mat.sizes());
921
922 std::transform
923 (
924 mat.cbegin(),
925 mat.end(),
926 result.begin(),
927 [&](const Type& val) { return val - s; }
928 );
929
930 return result;
931}
932
933
934//- Scalar division of Matrix
935template<class Form, class Type>
936Form operator/(const Matrix<Form, Type>& mat, const Type& s)
937{
938 Form result(mat.sizes());
939
940 std::transform
941 (
942 mat.cbegin(),
943 mat.end(),
944 result.begin(),
945 [&](const Type& val) { return val / s; }
946 );
947
948 return result;
949}
950
951
952//- Matrix-Matrix multiplication using ikj-algorithm
953template<class Form1, class Form2, class Type>
955operator*
956(
957 const Matrix<Form1, Type>& A,
959)
960{
961 #ifdef FULLDEBUG
962 if (A.n() != B.m())
963 {
965 << "Attempt to multiply incompatible matrices:" << nl
966 << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
967 << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
968 << "The columns of A must equal rows of B"
969 << abort(FatalError);
970 }
971 #endif
972
974 (
975 A.m(),
976 B.n(),
977 Zero
978 );
979
980 for (label i = 0; i < AB.m(); ++i)
981 {
982 for (label k = 0; k < B.m(); ++k)
983 {
984 for (label j = 0; j < AB.n(); ++j)
985 {
986 AB(i, j) += A(i, k)*B(k, j);
987 }
988 }
989 }
990
991 return AB;
992}
993
994
995//- Implicit inner product of Matrix-Matrix, equivalent to A.T()*B
996template<class Form1, class Form2, class Type>
998operator&
999(
1000 const Matrix<Form1, Type>& AT,
1001 const Matrix<Form2, Type>& B
1002)
1003{
1004 #ifdef FULLDEBUG
1005 if (AT.m() != B.m())
1006 {
1008 << "Attempt to multiply incompatible matrices:" << nl
1009 << "Matrix A : (" << AT.m() << ", " << AT.n() << ')' << nl
1010 << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
1011 << "The rows of A must equal rows of B"
1012 << abort(FatalError);
1013 }
1014 #endif
1015
1017 (
1018 AT.n(),
1019 B.n(),
1020 Zero
1021 );
1022
1023 for (label k = 0; k < B.m(); ++k)
1024 {
1025 for (label i = 0; i < AB.m(); ++i)
1026 {
1027 for (label j = 0; j < AB.n(); ++j)
1028 {
1029 AB(i, j) += Detail::conj(AT(k, i))*B(k, j);
1030 }
1031 }
1032 }
1033
1034 return AB;
1035}
1036
1037
1038//- Implicit outer product of Matrix-Matrix, equivalent to A*B.T()
1039template<class Form1, class Form2, class Type>
1041operator^
1042(
1043 const Matrix<Form1, Type>& A,
1044 const Matrix<Form2, Type>& BT
1045)
1046{
1047 #ifdef FULLDEBUG
1048 if (A.n() != BT.n())
1049 {
1051 << "Attempt to multiply incompatible matrices:" << nl
1052 << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
1053 << "Matrix B : (" << BT.m() << ", " << BT.n() << ')' << nl
1054 << "The columns of A must equal columns of B"
1055 << abort(FatalError);
1056 }
1057 #endif
1058
1060 (
1061 A.m(),
1062 BT.m(),
1063 Zero
1064 );
1065
1066 for (label i = 0; i < AB.m(); ++i)
1067 {
1068 for (label j = 0; j < AB.n(); ++j)
1069 {
1070 for (label k = 0; k < BT.n(); ++k)
1071 {
1072 AB(i, j) += A(i, k)*Detail::conj(BT(j, k));
1073 }
1074 }
1075 }
1076
1077 return AB;
1078}
1079
1080
1081// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1082
1083} // End namespace Foam
1084
1085// ************************************************************************* //
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
label k
label n
virtual bool resize()
Resize the ODE solver.
Definition: Euler.C:53
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: MatrixBlock.H:132
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: Matrix.H:81
label n() const noexcept
The number of columns.
Definition: MatrixI.H:103
const Type * cdata() const noexcept
Definition: MatrixI.H:202
~Matrix()
Destructor.
Definition: Matrix.C:244
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
Definition: MatrixI.H:551
List< Type > release()
Definition: Matrix.C:270
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
Definition: MatrixI.H:124
void round(const scalar tol=SMALL)
Round elements with magnitude smaller than tol (SMALL) to zero.
Definition: Matrix.C:379
Form transpose() const
Return non-conjugate transpose of Matrix.
Definition: Matrix.C:409
labelPair sizes() const
Return row/column sizes.
Definition: MatrixI.H:117
void operator*=(const Type &s)
Matrix scalar multiplication.
Definition: Matrix.C:688
void checkSize() const
Check that dimensions are positive, non-zero.
Definition: MatrixI.H:167
Type trace() const
Return the trace.
Definition: Matrix.C:463
iterator begin() noexcept
Return an iterator to begin traversing a Matrix.
Definition: MatrixI.H:535
Form T() const
Return conjugate transpose of Matrix.
Definition: Matrix.C:392
void resize_nocopy(const label mrow, const label ncol)
Change Matrix dimensions without preserving existing content.
Definition: Matrix.C:349
iterator end() noexcept
Return an iterator to end traversing a Matrix.
Definition: MatrixI.H:543
std::streamsize byteSize() const
Definition: Matrix.C:511
void swap(Matrix< Form, Type > &mat)
Swap contents.
Definition: Matrix.C:290
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
Definition: Matrix.C:608
Matrix() noexcept
Default construct (empty matrix)
Definition: MatrixI.H:49
void clear()
Clear Matrix, i.e. set sizes to zero.
Definition: Matrix.C:256
void operator=(const Matrix< Form, Type > &mat)
Copy assignment. Takes linear time.
Definition: Matrix.C:526
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
Definition: Matrix.C:426
scalar columnNorm(const label colIndex, const bool noSqrt=false) const
Return L2-Norm of chosen column.
Definition: Matrix.C:480
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
Definition: Matrix.C:638
void operator/=(const Type &s)
Matrix scalar division.
Definition: Matrix.C:698
const_iterator cend() const noexcept
Return const_iterator to end traversing a constant Matrix.
Definition: MatrixI.H:559
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: MinMax.H:128
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void swap(UList< T > &list)
Swap content with another UList of the same type in constant time.
Definition: UListI.H:434
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Normalises an input field with a chosen norm, and outputs a new normalised field.
Definition: norm.H:245
A class for managing temporary objects.
Definition: tmp.H:65
type
Volume classification types.
Definition: volumeType.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
patchWriters clear()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
std::enable_if<!std::is_same< complex, T >::value, constT & >::type conj(const T &val)
Definition: complex.H:343
Namespace for OpenFOAM.
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:61
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:78