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-2021 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  std::swap(mRows_, mat.mRows_);
298  std::swap(nCols_, mat.nCols_);
299  std::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>::resize_nocopy(const label mrow, const label ncol)
350 {
351  if (mrow == mRows_ && ncol == nCols_)
352  {
353  return;
354  }
355 
356  const label oldLen = (mRows_ * nCols_);
357 
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();
369 
370  mRows_ = mrow;
371  nCols_ = ncol;
372 
373  this->doAlloc();
374  }
375 }
376 
377 
378 template<class Form, class Type>
379 void Foam::Matrix<Form, Type>::round(const scalar tol)
380 {
381  for (Type& val : *this)
382  {
383  if (mag(val) < tol)
384  {
385  val = Zero;
386  }
387  }
388 }
389 
390 
391 template<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));
401  }
402  }
403 
404  return At;
405 }
406 
407 
408 template<class Form, class Type>
410 {
411  const label len = Foam::min(mRows_, nCols_);
412 
413  List<Type> result(len);
414 
415  for (label i=0; i < len; ++i)
416  {
417  result[i] = (*this)(i, i);
418  }
419 
420  return result;
421 }
422 
423 
424 template<class Form, class Type>
426 {
427  const label len = Foam::min(mRows_, nCols_);
428 
429  #ifdef FULLDEBUG
430  if (list.size() != len)
431  {
433  << "List size (" << list.size()
434  << ") incompatible with Matrix diagonal" << abort(FatalError);
435  }
436  #endif
437 
438  for (label i=0; i < len; ++i)
439  {
440  (*this)(i, i) = list[i];
441  }
442 }
443 
444 
445 template<class Form, class Type>
447 {
448  const label len = Foam::min(mRows_, nCols_);
449 
450  Type val = Zero;
451 
452  for (label i=0; i < len; ++i)
453  {
454  val += (*this)(i, i);
455  }
456 
457  return val;
458 }
459 
460 
461 template<class Form, class Type>
463 (
464  const label colIndex,
465  const bool noSqrt
466 ) const
467 {
468  scalar result = Zero;
469 
470  for (label i=0; i < mRows_; ++i)
471  {
472  result += magSqr((*this)(i, colIndex));
473  }
474 
475  return noSqrt ? result : Foam::sqrt(result);
476 }
477 
478 
479 template<class Form, class Type>
480 Foam::scalar Foam::Matrix<Form, Type>::norm(const bool noSqrt) const
481 {
482  scalar result = Zero;
483 
484  for (const Type& val : *this)
485  {
486  result += magSqr(val);
487  }
488 
489  return noSqrt ? result : Foam::sqrt(result);
490 }
491 
492 
493 template<class Form, class Type>
494 std::streamsize Foam::Matrix<Form, Type>::byteSize() const
495 {
497  {
499  << "Invalid for non-contiguous data types"
500  << abort(FatalError);
501  }
502  return this->size_bytes();
503 }
504 
505 
506 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
507 
508 template<class Form, class Type>
510 {
511  if (this == &mat)
512  {
513  return; // Self-assignment is a no-op
514  }
515 
516  if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
517  {
518  clear();
519  mRows_ = mat.mRows_;
520  nCols_ = mat.nCols_;
521  doAlloc();
522  }
523 
524  if (v_)
525  {
526  std::copy(mat.cbegin(), mat.cend(), v_);
527  }
528 }
529 
530 
531 template<class Form, class Type>
533 {
534  if (this != &mat)
535  {
536  // Self-assignment is a no-op
537  this->transfer(mat);
538  }
539 }
540 
541 
542 template<class Form, class Type>
543 template<class MatrixType>
545 (
547 )
548 {
549  for (label i = 0; i < mRows_; ++i)
550  {
551  for (label j = 0; j < nCols_; ++j)
552  {
553  (*this)(i, j) = Mb(i, j);
554  }
555  }
556 }
557 
558 
559 template<class Form, class Type>
560 template<class MatrixType>
562 (
563  const MatrixBlock<MatrixType>& Mb
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 
576 template<class Form, class Type>
578 {
579  std::fill(begin(), end(), val);
580 }
581 
582 
583 template<class Form, class Type>
585 {
586  std::fill(begin(), end(), Zero);
587 }
588 
589 
590 template<class Form, class Type>
592 {
593  #ifdef FULLDEBUG
594  if (this == &other)
595  {
597  << "Attempted addition to self"
598  << abort(FatalError);
599  }
600 
601  if (m() != other.m() || n() != other.n())
602  {
604  << "Attempt to add matrices with different sizes: ("
605  << m() << ", " << n() << ") != ("
606  << other.m() << ", " << other.n() << ')' << nl
607  << abort(FatalError);
608  }
609  #endif
610 
611  auto iter2 = other.cbegin();
612  for (Type& val : *this)
613  {
614  val += *iter2;
615  ++iter2;
616  }
617 }
618 
619 
620 template<class Form, class Type>
622 {
623  #ifdef FULLDEBUG
624  if (this == &other)
625  {
627  << "Attempted subtraction from self"
628  << abort(FatalError);
629  }
630 
631  if (m() != other.m() || n() != other.n())
632  {
634  << "Attempt to subtract matrices with different sizes: ("
635  << m() << ", " << n() << ") != ("
636  << other.m() << ", " << other.n() << ')' << nl
637  << abort(FatalError);
638  }
639  #endif
640 
641  auto iter2 = other.cbegin();
642  for (Type& val : *this)
643  {
644  val -= *iter2;
645  ++iter2;
646  }
647 }
648 
649 
650 template<class Form, class Type>
652 {
653  for (Type& val : *this)
654  {
655  val += s;
656  }
657 }
658 
659 
660 template<class Form, class Type>
662 {
663  for (Type& val : *this)
664  {
665  val -= s;
666  }
667 }
668 
669 
670 template<class Form, class Type>
672 {
673  for (Type& val : *this)
674  {
675  val *= s;
676  }
677 }
678 
679 
680 template<class Form, class Type>
682 {
683  for (Type& val : *this)
684  {
685  val /= s;
686  }
687 }
688 
689 
690 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
691 
692 namespace Foam
693 {
694 
695 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
696 
697 //- Find max value in Matrix
698 template<class Form, class Type>
699 const Type& max(const Matrix<Form, Type>& mat)
700 {
701  if (mat.empty())
702  {
704  << "Matrix is empty" << abort(FatalError);
705  }
706 
707  return *(std::max_element(mat.cbegin(), mat.cend()));
708 }
709 
710 
711 //- Find min value in Matrix
712 template<class Form, class Type>
713 const Type& min(const Matrix<Form, Type>& mat)
714 {
715  if (mat.empty())
716  {
718  << "Matrix is empty" << abort(FatalError);
719  }
720 
721  return *(std::min_element(mat.cbegin(), mat.cend()));
722 }
723 
724 
725 //- Find the min/max values of Matrix
726 template<class Form, class Type>
728 {
729  MinMax<Type> result;
730 
731  for (const Type& val : mat)
732  {
733  result += val;
734  }
735 
736  return result;
737 }
738 
739 
740 
741 // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
742 
743 //- Matrix negation
744 template<class Form, class Type>
746 {
747  Form result(mat.sizes());
748 
750  (
751  mat.cbegin(),
752  mat.cend(),
753  result.begin(),
754  std::negate<Type>()
755  );
756 
757  return result;
758 }
759 
760 
761 //- Matrix addition. Returns Matrix of the same form as the first parameter.
762 template<class Form1, class Form2, class Type>
763 Form1 operator+
764 (
765  const Matrix<Form1, Type>& A,
766  const Matrix<Form2, Type>& B
767 )
768 {
769  #ifdef FULLDEBUG
770  if (A.m() != B.m() || A.n() != B.n())
771  {
773  << "Attempt to add matrices with different sizes: ("
774  << A.m() << ", " << A.n() << ") != ("
775  << B.m() << ", " << B.n() << ')' << nl
776  << abort(FatalError);
777  }
778  #endif
779 
780  Form1 result(A.sizes());
781 
783  (
784  A.cbegin(),
785  A.cend(),
786  B.cbegin(),
787  result.begin(),
788  std::plus<Type>()
789  );
790 
791  return result;
792 }
793 
794 
795 //- Matrix subtraction. Returns Matrix of the same form as the first parameter.
796 template<class Form1, class Form2, class Type>
797 Form1 operator-
798 (
799  const Matrix<Form1, Type>& A,
800  const Matrix<Form2, Type>& B
801 )
802 {
803  #ifdef FULLDEBUG
804  if (A.m() != B.m() || A.n() != B.n())
805  {
807  << "Attempt to subtract matrices with different sizes: ("
808  << A.m() << ", " << A.n() << ") != ("
809  << B.m() << ", " << B.n() << ')' << nl
810  << abort(FatalError);
811  }
812  #endif
813 
814  Form1 result(A.sizes());
815 
817  (
818  A.cbegin(),
819  A.cend(),
820  B.cbegin(),
821  result.begin(),
822  std::minus<Type>()
823  );
824 
825  return result;
826 }
827 
828 
829 //- Scalar multiplication of Matrix
830 template<class Form, class Type>
831 Form operator*(const Type& s, const Matrix<Form, Type>& mat)
832 {
833  Form result(mat.sizes());
834 
836  (
837  mat.cbegin(),
838  mat.cend(),
839  result.begin(),
840  [&](const Type& val) { return s * val; }
841  );
842 
843  return result;
844 }
845 
846 
847 //- Scalar multiplication of Matrix
848 template<class Form, class Type>
849 Form operator*(const Matrix<Form, Type>& mat, const Type& s)
850 {
851  return s*mat;
852 }
853 
854 
855 //- Scalar addition of Matrix
856 template<class Form, class Type>
857 Form operator+(const Type& s, const Matrix<Form, Type>& mat)
858 {
859  Form result(mat.sizes());
860 
862  (
863  mat.cbegin(),
864  mat.cend(),
865  result.begin(),
866  [&](const Type& val) { return s + val; }
867  );
868 
869  return result;
870 }
871 
872 
873 //- Scalar addition of Matrix
874 template<class Form, class Type>
875 Form operator+(const Matrix<Form, Type>& mat, const Type& s)
876 {
877  return s + mat;
878 }
879 
880 
881 //- Scalar subtraction of Matrix
882 template<class Form, class Type>
883 Form operator-(const Type& s, const Matrix<Form, Type>& mat)
884 {
885  Form result(mat.sizes());
886 
888  (
889  mat.cbegin(),
890  mat.end(),
891  result.begin(),
892  [&](const Type& val) { return s - val; }
893  );
894 
895  return result;
896 }
897 
898 
899 //- Scalar subtraction of Matrix
900 template<class Form, class Type>
901 Form operator-(const Matrix<Form, Type>& mat, const Type& s)
902 {
903  Form result(mat.sizes());
904 
906  (
907  mat.cbegin(),
908  mat.end(),
909  result.begin(),
910  [&](const Type& val) { return val - s; }
911  );
912 
913  return result;
914 }
915 
916 
917 //- Scalar division of Matrix
918 template<class Form, class Type>
919 Form operator/(const Matrix<Form, Type>& mat, const Type& s)
920 {
921  Form result(mat.sizes());
922 
924  (
925  mat.cbegin(),
926  mat.end(),
927  result.begin(),
928  [&](const Type& val) { return val / s; }
929  );
930 
931  return result;
932 }
933 
934 
935 //- Matrix-Matrix multiplication using ikj-algorithm
936 template<class Form1, class Form2, class Type>
938 operator*
939 (
940  const Matrix<Form1, Type>& A,
941  const Matrix<Form2, Type>& B
942 )
943 {
944  #ifdef FULLDEBUG
945  if (A.n() != B.m())
946  {
948  << "Attempt to multiply incompatible matrices:" << nl
949  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
950  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
951  << "The columns of A must equal rows of B"
952  << abort(FatalError);
953  }
954  #endif
955 
957  (
958  A.m(),
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) += A(i, k)*B(k, j);
970  }
971  }
972  }
973 
974  return AB;
975 }
976 
977 
978 //- Implicit inner product of Matrix-Matrix, equivalent to A.T()*B
979 template<class Form1, class Form2, class Type>
981 operator&
982 (
983  const Matrix<Form1, Type>& AT,
984  const Matrix<Form2, Type>& B
985 )
986 {
987  #ifdef FULLDEBUG
988  if (AT.m() != B.m())
989  {
991  << "Attempt to multiply incompatible matrices:" << nl
992  << "Matrix A : (" << AT.m() << ", " << AT.n() << ')' << nl
993  << "Matrix B : (" << B.m() << ", " << B.n() << ')' << nl
994  << "The rows of A must equal rows of B"
995  << abort(FatalError);
996  }
997  #endif
998 
1000  (
1001  AT.n(),
1002  B.n(),
1003  Zero
1004  );
1005 
1006  for (label i = 0; i < AB.m(); ++i)
1007  {
1008  for (label k = 0; k < B.m(); ++k)
1009  {
1010  for (label j = 0; j < AB.n(); ++j)
1011  {
1012  AB(i, j) += Detail::conj(AT(k, i))*B(k, j);
1013  }
1014  }
1015  }
1016 
1017  return AB;
1018 }
1019 
1020 
1021 //- Implicit outer product of Matrix-Matrix, equivalent to A*B.T()
1022 template<class Form1, class Form2, class Type>
1024 operator^
1026  const Matrix<Form1, Type>& A,
1027  const Matrix<Form2, Type>& BT
1028 )
1029 {
1030  #ifdef FULLDEBUG
1031  if (A.n() != BT.n())
1032  {
1034  << "Attempt to multiply incompatible matrices:" << nl
1035  << "Matrix A : (" << A.m() << ", " << A.n() << ')' << nl
1036  << "Matrix B : (" << BT.m() << ", " << BT.n() << ')' << nl
1037  << "The columns of A must equal columns of B"
1038  << abort(FatalError);
1039  }
1040  #endif
1041 
1043  (
1044  A.m(),
1045  BT.m(),
1046  Zero
1047  );
1048 
1049  for (label i = 0; i < AB.m(); ++i)
1050  {
1051  for (label k = 0; k < BT.n(); ++k)
1052  {
1053  for (label j = 0; j < AB.n(); ++j)
1054  {
1055  AB(i, j) += A(i, k)*Detail::conj(BT(j, k));
1056  }
1057  }
1058  }
1059 
1060  return AB;
1061 }
1062 
1063 
1064 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
1065 
1066 } // End namespace Foam
1067 
1068 // ************************************************************************* //
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:103
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::end
iterator end() noexcept
Return an iterator to end traversing a Matrix.
Definition: MatrixI.H:543
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:117
Foam::Matrix::operator-=
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
Definition: Matrix.C:621
Foam::transform
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
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:379
Foam::Matrix::resize
void resize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
Definition: Matrix.C:324
Foam::Matrix::byteSize
std::streamsize byteSize() const
Definition: Matrix.C:494
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:463
Foam::Matrix::empty
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
Definition: MatrixI.H:124
Foam::Matrix::cend
const_iterator cend() const noexcept
Return const_iterator to end traversing a constant Matrix.
Definition: MatrixI.H:559
Foam::Matrix::operator*=
void operator*=(const Type &s)
Matrix scalar multiplication.
Definition: Matrix.C:671
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::Matrix::resize_nocopy
void resize_nocopy(const label mrow, const label ncol)
Change Matrix dimensions without preserving existing content.
Definition: Matrix.C:349
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:681
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:509
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:591
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:392
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:446
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
clear
patchWriters clear()
Foam::Matrix::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
Foam::min
const Type & min(const Matrix< Form, Type > &mat)
Find min value in Matrix.
Definition: Matrix.C:713
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:480
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::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::Matrix::cdata
const Type * cdata() const noexcept
Definition: MatrixI.H:202
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::Matrix::Matrix
Matrix() noexcept
Default construct (empty matrix)
Definition: MatrixI.H:49
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Foam::minMax
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
Definition: hashSets.C:61
Foam::Matrix::cbegin
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
Definition: MatrixI.H:551
Foam::MinMax
A min/max value pair with additional methods. In addition to conveniently storing values,...
Definition: HashSet.H:76
Foam::Matrix::diag
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
Definition: Matrix.C:409
Foam::is_contiguous
A template class to specify that a data type can be considered as being contiguous in memory.
Definition: contiguous.H:75
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62