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 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>
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>
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>
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 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
648 
649 template<class Form, class Type>
650 const Type& Foam::max(const Matrix<Form, Type>& mat)
651 {
652  if (mat.empty())
653  {
655  << "Matrix is empty" << abort(FatalError);
656  }
657 
658  return *(std::max_element(mat.cbegin(), mat.cend()));
659 }
660 
661 
662 template<class Form, class Type>
663 const Type& Foam::min(const Matrix<Form, Type>& mat)
664 {
665  if (mat.empty())
666  {
668  << "Matrix is empty" << abort(FatalError);
669  }
670 
671  return *(std::min_element(mat.cbegin(), mat.cend()));
672 }
673 
674 
675 template<class Form, class Type>
676 Foam::MinMax<Type> Foam::minMax(const Matrix<Form, Type>& mat)
677 {
678  MinMax<Type> result;
679 
680  for (const Type& val : mat)
681  {
682  result += val;
683  }
684 
685  return result;
686 }
687 
688 
689 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
690 
691 template<class Form, class Type>
693 {
694  Form result(mat.sizes());
695 
697  (
698  mat.cbegin(),
699  mat.cend(),
700  result.begin(),
701  std::negate<Type>()
702  );
703 
704  return result;
705 }
706 
707 
708 template<class Form1, class Form2, class Type>
709 Form1 Foam::operator+
710 (
711  const Matrix<Form1, Type>& A,
712  const Matrix<Form2, Type>& B
713 )
714 {
715  #ifdef FULLDEBUG
716  if (A.m() != B.m() || A.n() != B.n())
717  {
719  << "Attempt to add matrices with different sizes: ("
720  << A.m() << ", " << A.n() << ") != ("
721  << B.m() << ", " << B.n() << ')' << nl
722  << abort(FatalError);
723  }
724  #endif
725 
726  Form1 result(A.sizes());
727 
729  (
730  A.cbegin(),
731  A.cend(),
732  B.cbegin(),
733  result.begin(),
734  std::plus<Type>()
735  );
736 
737  return result;
738 }
739 
740 
741 template<class Form1, class Form2, class Type>
742 Form1 Foam::operator-
743 (
744  const Matrix<Form1, Type>& A,
745  const Matrix<Form2, Type>& B
746 )
747 {
748  #ifdef FULLDEBUG
749  if (A.m() != B.m() || A.n() != B.n())
750  {
752  << "Attempt to subtract matrices with different sizes: ("
753  << A.m() << ", " << A.n() << ") != ("
754  << B.m() << ", " << B.n() << ')' << nl
755  << abort(FatalError);
756  }
757  #endif
758 
759  Form1 result(A.sizes());
760 
762  (
763  A.cbegin(),
764  A.cend(),
765  B.cbegin(),
766  result.begin(),
767  std::minus<Type>()
768  );
769 
770  return result;
771 }
772 
773 
774 template<class Form, class Type>
775 Form Foam::operator*(const Type& s, const Matrix<Form, Type>& mat)
776 {
777  Form result(mat.sizes());
778 
780  (
781  mat.cbegin(),
782  mat.cend(),
783  result.begin(),
784  [&](const Type& val) { return s * val; }
785  );
786 
787  return result;
788 }
789 
790 
791 template<class Form, class Type>
792 Form Foam::operator+(const Type& s, const Matrix<Form, Type>& mat)
793 {
794  Form result(mat.sizes());
795 
797  (
798  mat.cbegin(),
799  mat.cend(),
800  result.begin(),
801  [&](const Type& val) { return s + val; }
802  );
803 
804  return result;
805 }
806 
807 
808 template<class Form, class Type>
809 Form Foam::operator-(const Type& s, const Matrix<Form, Type>& mat)
810 {
811  Form result(mat.sizes());
812 
814  (
815  mat.cbegin(),
816  mat.end(),
817  result.begin(),
818  [&](const Type& val) { return s - val; }
819  );
820 
821  return result;
822 }
823 
824 
825 template<class Form, class Type>
826 Form Foam::operator*(const Matrix<Form, Type>& mat, const Type& s)
827 {
828  return s*mat;
829 }
830 
831 
832 template<class Form, class Type>
833 Form Foam::operator+(const Matrix<Form, Type>& mat, const Type& s)
834 {
835  return s + mat;
836 }
837 
838 
839 template<class Form, class Type>
840 Form Foam::operator-(const Matrix<Form, Type>& mat, const Type& s)
841 {
842  Form result(mat.sizes());
843 
845  (
846  mat.cbegin(),
847  mat.end(),
848  result.begin(),
849  [&](const Type& val) { return val - s; }
850  );
851 
852  return result;
853 }
854 
855 
856 template<class Form, class Type>
857 Form Foam::operator/(const Matrix<Form, Type>& mat, const Type& s)
858 {
859  Form result(mat.sizes());
860 
862  (
863  mat.cbegin(),
864  mat.end(),
865  result.begin(),
866  [&](const Type& val) { return val / s; }
867  );
868 
869  return result;
870 }
871 
872 
873 template<class Form1, class Form2, class Type>
875 Foam::operator*
876 (
877  const Matrix<Form1, Type>& A,
878  const Matrix<Form2, Type>& B
879 )
880 {
881  #ifdef FULLDEBUG
882  if (A.n() != B.m())
883  {
885  << "Attempt to multiply incompatible matrices:" << nl
886  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
887  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
888  << "The columns of A must equal rows of B"
889  << abort(FatalError);
890  }
891  #endif
892 
894  (
895  A.m(),
896  B.n(),
897  Zero
898  );
899 
900  for (label i = 0; i < AB.m(); ++i)
901  {
902  for (label k = 0; k < B.m(); ++k)
903  {
904  for (label j = 0; j < AB.n(); ++j)
905  {
906  AB(i, j) += A(i, k)*B(k, j);
907  }
908  }
909  }
910 
911  return AB;
912 }
913 
914 
915 template<class Form1, class Form2, class Type>
917 Foam::operator&
918 (
919  const Matrix<Form1, Type>& AT,
920  const Matrix<Form2, Type>& B
921 )
922 {
923  #ifdef FULLDEBUG
924  if (AT.m() != B.m())
925  {
927  << "Attempt to multiply incompatible matrices:" << nl
928  << "Matrix A : (" << AT.m() << ", " << AT.n() << ')' << nl
929  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
930  << "The rows of A must equal rows of B"
931  << abort(FatalError);
932  }
933  #endif
934 
936  (
937  AT.n(),
938  B.n(),
939  Zero
940  );
941 
942  for (label i = 0; i < AB.m(); ++i)
943  {
944  for (label k = 0; k < B.m(); ++k)
945  {
946  for (label j = 0; j < AB.n(); ++j)
947  {
948  AB(i, j) += Detail::conj(AT(k, i))*B(k, j);
949  }
950  }
951  }
952 
953  return AB;
954 }
955 
956 
957 template<class Form1, class Form2, class Type>
959 Foam::operator^
960 (
961  const Matrix<Form1, Type>& A,
962  const Matrix<Form2, Type>& BT
963 )
964 {
965  #ifdef FULLDEBUG
966  if (A.n() != BT.n())
967  {
969  << "Attempt to multiply incompatible matrices:" << nl
970  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
971  << "Matrix B : (" << BT.m() << ", " << BT.n() << ')' << nl
972  << "The columns of A must equal columns of B"
973  << abort(FatalError);
974  }
975  #endif
976 
978  (
979  A.m(),
980  BT.m(),
981  Zero
982  );
983 
984  for (label i = 0; i < AB.m(); ++i)
985  {
986  for (label k = 0; k < BT.n(); ++k)
987  {
988  for (label j = 0; j < AB.n(); ++j)
989  {
990  AB(i, j) += A(i, k)*Detail::conj(BT(j, k));
991  }
992  }
993  }
994 
995  return AB;
996 }
997 
998 
999 // * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
1000 
1001 #include "MatrixIO.C"
1002 
1003 // ************************************************************************* //
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
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:91
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:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Matrix.H
Foam::Matrix::n
ConstMatrixBlock< mType > const label n
Definition: Matrix.H:525
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:909
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:48
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 to zero elements with magnitude smaller than tol (SMALL)
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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:115
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:137
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:355
clear
patchWriters clear()
Foam::Matrix::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:95
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::Pair
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:54
Foam::Detail::conj
std::enable_if< !std::is_same< complex, T >::value, const T & >::type conj(const T &val)
Definition: complex.H:328
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), which can be used to avoid manipulating objects that ar...
Definition: zero.H:61