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-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
35 template<class Form, class Type>
36 template<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 
70 template<class Form, class Type>
71 template<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 
108 template<class Form, class Type>
109 Foam::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 
121 template<class Form, class Type>
122 Foam::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 
135 
136 template<class Form, class Type>
137 Foam::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 
151 template<class Form, class Type>
153 :
154  mRows_(mat.mRows_),
155  nCols_(mat.nCols_),
156  v_(nullptr)
157 {
158  if (mat.cdata())
159  {
160  doAlloc();
161 
162  std::copy(mat.cbegin(), mat.cend(), v_);
163  }
164 }
165 
166 
167 template<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 
180 template<class Form, class Type>
181 template<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 
197 template<class Form, class Type>
198 template<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 
219 template<class Form, class Type>
220 template<class MatrixType>
222 (
223  const MatrixBlock<MatrixType>& Mb
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 
243 template<class Form, class Type>
245 {
246  if (v_)
247  {
248  delete[] v_;
249  }
250 }
251 
252 
253 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
254 
255 template<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 
269 template<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 
289 template<class Form, class Type>
291 {
292  if (this == &mat)
293  {
294  return; // Self-swap is a no-op
295  }
296 
297  Foam::Swap(mRows_, mat.mRows_);
298  Foam::Swap(nCols_, mat.nCols_);
299  Foam::Swap(v_, mat.v_);
300 }
301 
302 
303 template<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 
323 template<class Form, class Type>
324 void 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  }
343 
344  transfer(newMatrix);
345 }
346 
347 
348 template<class Form, class Type>
349 void Foam::Matrix<Form, Type>::round(const scalar tol)
350 {
351  for (Type& val : *this)
352  {
353  if (mag(val) < tol)
354  {
355  val = Zero;
356  }
357  }
358 }
359 
360 
361 template<class Form, class Type>
363 {
364  Form At(labelPair{n(), m()});
365 
366  for (label i = 0; i < m(); ++i)
367  {
368  for (label j = 0; j < n(); ++j)
369  {
370  At(j, i) = Detail::conj((*this)(i, j));
371  }
372  }
373 
374  return At;
375 }
376 
377 
378 template<class Form, class Type>
380 {
381  const label len = Foam::min(mRows_, nCols_);
382 
383  List<Type> result(len);
384 
385  for (label i=0; i < len; ++i)
386  {
387  result[i] = (*this)(i, i);
388  }
389 
390  return result;
391 }
392 
393 
394 template<class Form, class Type>
396 {
397  const label len = Foam::min(mRows_, nCols_);
398 
399  #ifdef FULLDEBUG
400  if (list.size() != len)
401  {
403  << "List size (" << list.size()
404  << ") incompatible with Matrix diagonal" << abort(FatalError);
405  }
406  #endif
407 
408  for (label i=0; i < len; ++i)
409  {
410  (*this)(i, i) = list[i];
411  }
412 }
413 
414 
415 template<class Form, class Type>
417 {
418  const label len = Foam::min(mRows_, nCols_);
419 
420  Type val = Zero;
421 
422  for (label i=0; i < len; ++i)
423  {
424  val += (*this)(i, i);
425  }
426 
427  return val;
428 }
429 
430 
431 template<class Form, class Type>
433 (
434  const label colIndex,
435  const bool noSqrt
436 ) const
437 {
438  scalar result = Zero;
439 
440  for (label i=0; i < mRows_; ++i)
441  {
442  result += magSqr((*this)(i, colIndex));
443  }
444 
445  return noSqrt ? result : Foam::sqrt(result);
446 }
447 
448 
449 template<class Form, class Type>
450 Foam::scalar Foam::Matrix<Form, Type>::norm(const bool noSqrt) const
451 {
452  scalar result = Zero;
453 
454  for (const Type& val : *this)
455  {
456  result += magSqr(val);
457  }
458 
459  return noSqrt ? result : Foam::sqrt(result);
460 }
461 
462 
463 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
464 
465 template<class Form, class Type>
467 {
468  if (this == &mat)
469  {
470  return; // Self-assignment is a no-op
471  }
472 
473  if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
474  {
475  clear();
476  mRows_ = mat.mRows_;
477  nCols_ = mat.nCols_;
478  doAlloc();
479  }
480 
481  if (v_)
482  {
483  std::copy(mat.cbegin(), mat.cend(), v_);
484  }
485 }
486 
487 
488 template<class Form, class Type>
490 {
491  if (this != &mat)
492  {
493  // Self-assignment is a no-op
494  this->transfer(mat);
495  }
496 }
497 
498 
499 template<class Form, class Type>
500 template<class MatrixType>
502 (
504 )
505 {
506  for (label i = 0; i < mRows_; ++i)
507  {
508  for (label j = 0; j < nCols_; ++j)
509  {
510  (*this)(i, j) = Mb(i, j);
511  }
512  }
513 }
514 
515 
516 template<class Form, class Type>
517 template<class MatrixType>
519 (
520  const MatrixBlock<MatrixType>& Mb
521 )
522 {
523  for (label i = 0; i < mRows_; ++i)
524  {
525  for (label j = 0; j < nCols_; ++j)
526  {
527  (*this)(i, j) = Mb(i, j);
528  }
529  }
530 }
531 
532 
533 template<class Form, class Type>
535 {
536  std::fill(begin(), end(), val);
537 }
538 
539 
540 template<class Form, class Type>
542 {
543  std::fill(begin(), end(), Zero);
544 }
545 
546 
547 template<class Form, class Type>
549 {
550  #ifdef FULLDEBUG
551  if (this == &other)
552  {
554  << "Attempted addition to self"
555  << abort(FatalError);
556  }
557 
558  if (m() != other.m() || n() != other.n())
559  {
561  << "Attempt to add matrices with different sizes: ("
562  << m() << ", " << n() << ") != ("
563  << other.m() << ", " << other.n() << ')' << nl
564  << abort(FatalError);
565  }
566  #endif
567 
568  auto iter2 = other.cbegin();
569  for (Type& val : *this)
570  {
571  val += *iter2;
572  ++iter2;
573  }
574 }
575 
576 
577 template<class Form, class Type>
579 {
580  #ifdef FULLDEBUG
581  if (this == &other)
582  {
584  << "Attempted subtraction from self"
585  << abort(FatalError);
586  }
587 
588  if (m() != other.m() || n() != other.n())
589  {
591  << "Attempt to subtract matrices with different sizes: ("
592  << m() << ", " << n() << ") != ("
593  << other.m() << ", " << other.n() << ')' << nl
594  << abort(FatalError);
595  }
596  #endif
597 
598  auto iter2 = other.cbegin();
599  for (Type& val : *this)
600  {
601  val -= *iter2;
602  ++iter2;
603  }
604 }
605 
606 
607 template<class Form, class Type>
609 {
610  for (Type& val : *this)
611  {
612  val += s;
613  }
614 }
615 
616 
617 template<class Form, class Type>
619 {
620  for (Type& val : *this)
621  {
622  val -= s;
623  }
624 }
625 
626 
627 template<class Form, class Type>
629 {
630  for (Type& val : *this)
631  {
632  val *= s;
633  }
634 }
635 
636 
637 template<class Form, class Type>
639 {
640  for (Type& val : *this)
641  {
642  val /= s;
643  }
644 }
645 
646 
647 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
648 
649 namespace Foam
650 {
651 
652 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
653 
654 //- Find max value in Matrix
655 template<class Form, class Type>
656 const Type& max(const Matrix<Form, Type>& mat)
657 {
658  if (mat.empty())
659  {
661  << "Matrix is empty" << abort(FatalError);
662  }
663 
664  return *(std::max_element(mat.cbegin(), mat.cend()));
665 }
666 
667 
668 //- Find min value in Matrix
669 template<class Form, class Type>
670 const Type& min(const Matrix<Form, Type>& mat)
671 {
672  if (mat.empty())
673  {
675  << "Matrix is empty" << abort(FatalError);
676  }
677 
678  return *(std::min_element(mat.cbegin(), mat.cend()));
679 }
680 
681 
682 //- Find the min/max values of Matrix
683 template<class Form, class Type>
685 {
686  MinMax<Type> result;
687 
688  for (const Type& val : mat)
689  {
690  result += val;
691  }
692 
693  return result;
694 }
695 
696 
697 
698 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
699 
700 //- Matrix negation
701 template<class Form, class Type>
703 {
704  Form result(mat.sizes());
705 
707  (
708  mat.cbegin(),
709  mat.cend(),
710  result.begin(),
711  std::negate<Type>()
712  );
713 
714  return result;
715 }
716 
717 
718 //- Matrix addition. Returns Matrix of the same form as the first parameter.
719 template<class Form1, class Form2, class Type>
720 Form1 operator+
721 (
722  const Matrix<Form1, Type>& A,
723  const Matrix<Form2, Type>& B
724 )
725 {
726  #ifdef FULLDEBUG
727  if (A.m() != B.m() || A.n() != B.n())
728  {
730  << "Attempt to add matrices with different sizes: ("
731  << A.m() << ", " << A.n() << ") != ("
732  << B.m() << ", " << B.n() << ')' << nl
733  << abort(FatalError);
734  }
735  #endif
736 
737  Form1 result(A.sizes());
738 
740  (
741  A.cbegin(),
742  A.cend(),
743  B.cbegin(),
744  result.begin(),
745  std::plus<Type>()
746  );
747 
748  return result;
749 }
750 
751 
752 //- Matrix subtraction. Returns Matrix of the same form as the first parameter.
753 template<class Form1, class Form2, class Type>
754 Form1 operator-
755 (
756  const Matrix<Form1, Type>& A,
757  const Matrix<Form2, Type>& B
758 )
759 {
760  #ifdef FULLDEBUG
761  if (A.m() != B.m() || A.n() != B.n())
762  {
764  << "Attempt to subtract matrices with different sizes: ("
765  << A.m() << ", " << A.n() << ") != ("
766  << B.m() << ", " << B.n() << ')' << nl
767  << abort(FatalError);
768  }
769  #endif
770 
771  Form1 result(A.sizes());
772 
774  (
775  A.cbegin(),
776  A.cend(),
777  B.cbegin(),
778  result.begin(),
779  std::minus<Type>()
780  );
781 
782  return result;
783 }
784 
785 
786 //- Scalar multiplication of Matrix
787 template<class Form, class Type>
788 Form operator*(const Type& s, const Matrix<Form, Type>& mat)
789 {
790  Form result(mat.sizes());
791 
793  (
794  mat.cbegin(),
795  mat.cend(),
796  result.begin(),
797  [&](const Type& val) { return s * val; }
798  );
799 
800  return result;
801 }
802 
803 
804 //- Scalar multiplication of Matrix
805 template<class Form, class Type>
806 Form operator*(const Matrix<Form, Type>& mat, const Type& s)
807 {
808  return s*mat;
809 }
810 
811 
812 //- Scalar addition of Matrix
813 template<class Form, class Type>
814 Form operator+(const Type& s, const Matrix<Form, Type>& mat)
815 {
816  Form result(mat.sizes());
817 
819  (
820  mat.cbegin(),
821  mat.cend(),
822  result.begin(),
823  [&](const Type& val) { return s + val; }
824  );
825 
826  return result;
827 }
828 
829 
830 //- Scalar addition of Matrix
831 template<class Form, class Type>
832 Form operator+(const Matrix<Form, Type>& mat, const Type& s)
833 {
834  return s + mat;
835 }
836 
837 
838 //- Scalar subtraction of Matrix
839 template<class Form, class Type>
840 Form operator-(const Type& s, const Matrix<Form, Type>& mat)
841 {
842  Form result(mat.sizes());
843 
845  (
846  mat.cbegin(),
847  mat.end(),
848  result.begin(),
849  [&](const Type& val) { return s - val; }
850  );
851 
852  return result;
853 }
854 
855 
856 //- Scalar subtraction of Matrix
857 template<class Form, class Type>
858 Form operator-(const Matrix<Form, Type>& mat, const Type& s)
859 {
860  Form result(mat.sizes());
861 
863  (
864  mat.cbegin(),
865  mat.end(),
866  result.begin(),
867  [&](const Type& val) { return val - s; }
868  );
869 
870  return result;
871 }
872 
873 
874 //- Scalar division of Matrix
875 template<class Form, class Type>
876 Form operator/(const Matrix<Form, Type>& mat, const Type& s)
877 {
878  Form result(mat.sizes());
879 
881  (
882  mat.cbegin(),
883  mat.end(),
884  result.begin(),
885  [&](const Type& val) { return val / s; }
886  );
887 
888  return result;
889 }
890 
891 
892 //- Matrix-Matrix multiplication using ikj-algorithm
893 template<class Form1, class Form2, class Type>
895 operator*
896 (
897  const Matrix<Form1, Type>& A,
898  const Matrix<Form2, Type>& B
899 )
900 {
901  #ifdef FULLDEBUG
902  if (A.n() != B.m())
903  {
905  << "Attempt to multiply incompatible matrices:" << nl
906  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
907  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
908  << "The columns of A must equal rows of B"
909  << abort(FatalError);
910  }
911  #endif
912 
914  (
915  A.m(),
916  B.n(),
917  Zero
918  );
919 
920  for (label i = 0; i < AB.m(); ++i)
921  {
922  for (label k = 0; k < B.m(); ++k)
923  {
924  for (label j = 0; j < AB.n(); ++j)
925  {
926  AB(i, j) += A(i, k)*B(k, j);
927  }
928  }
929  }
930 
931  return AB;
932 }
933 
934 
935 //- Implicit inner product of Matrix-Matrix, equivalent to A.T()*B
936 template<class Form1, class Form2, class Type>
938 operator&
939 (
940  const Matrix<Form1, Type>& AT,
941  const Matrix<Form2, Type>& B
942 )
943 {
944  #ifdef FULLDEBUG
945  if (AT.m() != B.m())
946  {
948  << "Attempt to multiply incompatible matrices:" << nl
949  << "Matrix A : (" << AT.m() << ", " << AT.n() << ')' << nl
950  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
951  << "The rows of A must equal rows of B"
952  << abort(FatalError);
953  }
954  #endif
955 
957  (
958  AT.n(),
959  B.n(),
960  Zero
961  );
962 
963  for (label i = 0; i < AB.m(); ++i)
964  {
965  for (label k = 0; k < B.m(); ++k)
966  {
967  for (label j = 0; j < AB.n(); ++j)
968  {
969  AB(i, j) += Detail::conj(AT(k, i))*B(k, j);
970  }
971  }
972  }
973 
974  return AB;
975 }
976 
977 
978 //- Implicit outer product of Matrix-Matrix, equivalent to A*B.T()
979 template<class Form1, class Form2, class Type>
981 operator^
982 (
983  const Matrix<Form1, Type>& A,
984  const Matrix<Form2, Type>& BT
985 )
986 {
987  #ifdef FULLDEBUG
988  if (A.n() != BT.n())
989  {
991  << "Attempt to multiply incompatible matrices:" << nl
992  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
993  << "Matrix B : (" << BT.m() << ", " << BT.n() << ')' << nl
994  << "The columns of A must equal columns of B"
995  << abort(FatalError);
996  }
997  #endif
998 
1000  (
1001  A.m(),
1002  BT.m(),
1003  Zero
1004  );
1005 
1006  for (label i = 0; i < AB.m(); ++i)
1007  {
1008  for (label k = 0; k < BT.n(); ++k)
1009  {
1010  for (label j = 0; j < AB.n(); ++j)
1011  {
1012  AB(i, j) += A(i, k)*Detail::conj(BT(j, k));
1013  }
1014  }
1015  }
1016 
1017  return AB;
1018 }
1019 
1020 
1021 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1022 
1023 } // End namespace Foam
1024 
1025 // * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * * * //
1026 
1027 #include "MatrixIO.C"
1028 
1029 // ************************************************************************* //
Foam::MatrixBlock::n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:111
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
s
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))
Definition: gmvOutputSpray.H:25
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Matrix::n
label n() const noexcept
The number of columns.
Definition: MatrixI.H:102
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Matrix.H
Foam::operator-
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Foam::Matrix::~Matrix
~Matrix()
Destructor.
Definition: Matrix.C:244
B
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
A
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
Foam::Matrix::sizes
labelPair sizes() const
Return row/column sizes.
Definition: MatrixI.H:116
Foam::Matrix::operator-=
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
Definition: Matrix.C:578
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:519
Foam::Swap
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
Definition: DynamicListI.H:913
Foam::Matrix::release
List< Type > release()
Definition: Matrix.C:270
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:53
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
Foam::Matrix::transfer
void transfer(Matrix< Form, Type > &mat)
Definition: Matrix.C:304
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Matrix::round
void round(const scalar tol=SMALL)
Round elements with magnitude smaller than tol (SMALL) to zero.
Definition: Matrix.C:349
Foam::Matrix::cend
const_iterator cend() const
Return const_iterator to end traversing a constant Matrix.
Definition: MatrixI.H:537
Foam::Matrix::resize
void resize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
Definition: Matrix.C:324
Foam::MatrixBlock
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:66
Foam::Matrix::columnNorm
scalar columnNorm(const label colIndex, const bool noSqrt=false) const
Return L2-Norm of chosen column.
Definition: Matrix.C:433
Foam::Matrix::empty
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
Definition: MatrixI.H:123
Foam::Matrix::operator*=
void operator*=(const Type &s)
Matrix scalar multiplication.
Definition: Matrix.C:628
Foam::Matrix::clear
void clear()
Clear Matrix, i.e. set sizes to zero.
Definition: Matrix.C:256
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::FatalError
error FatalError
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ConstMatrixBlock::n
label n() const
Return the number of columns in the block.
Definition: MatrixBlockI.H:97
Foam::Matrix::operator/=
void operator/=(const Type &s)
Matrix scalar division.
Definition: Matrix.C:638
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::Matrix::swap
void swap(Matrix< Form, Type > &mat)
Swap contents.
Definition: Matrix.C:290
Foam::Matrix::operator=
void operator=(const Matrix< Form, Type > &mat)
Copy assignment. Takes linear time.
Definition: Matrix.C:466
Foam::MatrixBlock::m
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:104
Foam::Matrix::operator+=
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
Definition: Matrix.C:548
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:68
Foam::Matrix::T
Form T() const
Return (conjugate) transpose of Matrix.
Definition: Matrix.C:362
Foam::Matrix::end
iterator end()
Return an iterator to end traversing a Matrix.
Definition: MatrixI.H:521
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::Matrix::trace
Type trace() const
Return the trace.
Definition: Matrix.C:416
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
clear
patchWriters clear()
Foam::Matrix::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:95
Foam::min
const Type & min(const Matrix< Form, Type > &mat)
Find min value in Matrix.
Definition: Matrix.C:670
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::Pair< label >
Foam::Detail::conj
std::enable_if< !std::is_same< complex, T >::value, const T & >::type conj(const T &val)
Definition: complex.H:339
Foam::List< Type >
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::Matrix::norm
scalar norm(const bool noSqrt=false) const
Return Frobenius norm of Matrix.
Definition: Matrix.C:450
Foam::typeOfInnerProduct
Definition: products.H:51
Foam::operator+
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::Matrix::cbegin
const_iterator cbegin() const
Return const_iterator to begin traversing a constant Matrix.
Definition: MatrixI.H:529
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::Matrix::cdata
const Type * cdata() const noexcept
Definition: MatrixI.H:201
Foam::UList< Type >
k
label k
Boltzmann constant.
Definition: LISASMDCalcMethod2.H:41
Foam::ConstMatrixBlock::m
label m() const
Return the number of rows in the block.
Definition: MatrixBlockI.H:90
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::ConstMatrixBlock
Definition: Matrix.H:65
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::UList::size
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
Definition: UListI.H:360
Foam::minMax
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:61
Foam::Matrix::Matrix
Matrix()
Construct null.
Definition: MatrixI.H:48
Foam::MinMax
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: HashSet.H:76
MatrixIO.C
Foam::Matrix::diag
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
Definition: Matrix.C:379
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62