Go to the documentation of this file.
35 template<
class Form,
class Type>
36 template<
class ListType>
45 if (mat.
n() !=
x.size())
48 <<
"Attempt to multiply incompatible Matrix and Vector:" <<
nl
49 <<
"Matrix : (" << mat.
m() <<
", " << mat.
n() <<
')' <<
nl
50 <<
"Matrix columns != Vector size (" <<
x.size() <<
')' <<
nl
56 auto& result = tresult.ref();
58 for (label i = 0; i < mat.
m(); ++i)
60 for (label j = 0; j < mat.
n(); ++j)
62 result[i] += mat(i, j)*
x[j];
70 template<
class Form,
class Type>
71 template<
class ListType>
80 if (mat.
m() !=
x.size())
83 <<
"Attempt to multiply incompatible Matrix and Vector:" <<
nl
84 <<
"Matrix : (" << mat.
m() <<
", " << mat.
n() <<
')' <<
nl
85 <<
"Matrix rows != Vector size (" <<
x.size() <<
')' <<
nl
91 auto& result = tresult.ref();
93 for (label i = 0; i < mat.
m(); ++i)
95 const Type& val =
x[i];
96 for (label j = 0; j < mat.
n(); ++j)
98 result[j] += val*mat(i, j);
108 template<
class Form,
class Type>
121 template<
class Form,
class Type>
136 template<
class Form,
class Type>
151 template<
class Form,
class Type>
167 template<
class Form,
class Type>
180 template<
class Form,
class Type>
181 template<
class Form2>
197 template<
class Form,
class Type>
198 template<
class MatrixType>
209 for (label i = 0; i < mRows_; ++i)
211 for (label j = 0; j < nCols_; ++j)
213 (*this)(i, j) = Mb(i,j);
219 template<
class Form,
class Type>
220 template<
class MatrixType>
231 for (label i = 0; i < mRows_; ++i)
233 for (label j = 0; j < nCols_; ++j)
235 (*this)(i, j) = Mb(i, j);
243 template<
class Form,
class Type>
255 template<
class Form,
class Type>
269 template<
class Form,
class Type>
274 const label len = size();
289 template<
class Form,
class Type>
303 template<
class Form,
class Type>
323 template<
class Form,
class Type>
326 if (m == mRows_ &&
n == nCols_)
333 const label mrow =
min(m, mRows_);
334 const label ncol =
min(
n, nCols_);
336 for (label i = 0; i < mrow; ++i)
338 for (label j = 0; j < ncol; ++j)
340 newMatrix(i, j) = (*this)(i, j);
348 template<
class Form,
class Type>
351 for (Type& val : *
this)
361 template<
class Form,
class Type>
366 for (label i = 0; i < m(); ++i)
368 for (label j = 0; j <
n(); ++j)
378 template<
class Form,
class Type>
381 const label len =
Foam::min(mRows_, nCols_);
385 for (label i=0; i < len; ++i)
387 result[i] = (*this)(i, i);
394 template<
class Form,
class Type>
397 const label len =
Foam::min(mRows_, nCols_);
400 if (list.
size() != len)
403 <<
"List size (" << list.
size()
408 for (label i=0; i < len; ++i)
410 (*this)(i, i) = list[i];
415 template<
class Form,
class Type>
418 const label len =
Foam::min(mRows_, nCols_);
422 for (label i=0; i < len; ++i)
424 val += (*this)(i, i);
431 template<
class Form,
class Type>
434 const label colIndex,
438 scalar result =
Zero;
440 for (label i=0; i < mRows_; ++i)
442 result +=
magSqr((*
this)(i, colIndex));
449 template<
class Form,
class Type>
452 scalar result =
Zero;
454 for (
const Type& val : *
this)
465 template<
class Form,
class Type>
473 if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
488 template<
class Form,
class Type>
499 template<
class Form,
class Type>
500 template<
class MatrixType>
506 for (label i = 0; i < mRows_; ++i)
508 for (label j = 0; j < nCols_; ++j)
510 (*this)(i, j) = Mb(i, j);
516 template<
class Form,
class Type>
517 template<
class MatrixType>
523 for (label i = 0; i < mRows_; ++i)
525 for (label j = 0; j < nCols_; ++j)
527 (*this)(i, j) = Mb(i, j);
533 template<
class Form,
class Type>
540 template<
class Form,
class Type>
547 template<
class Form,
class Type>
554 <<
"Attempted addition to self"
558 if (m() != other.
m() ||
n() != other.
n())
561 <<
"Attempt to add matrices with different sizes: ("
562 << m() <<
", " <<
n() <<
") != ("
563 << other.
m() <<
", " << other.
n() <<
')' <<
nl
568 auto iter2 = other.
cbegin();
569 for (Type& val : *
this)
577 template<
class Form,
class Type>
584 <<
"Attempted subtraction from self"
588 if (m() != other.
m() ||
n() != other.
n())
591 <<
"Attempt to subtract matrices with different sizes: ("
592 << m() <<
", " <<
n() <<
") != ("
593 << other.
m() <<
", " << other.
n() <<
')' <<
nl
598 auto iter2 = other.
cbegin();
599 for (Type& val : *
this)
607 template<
class Form,
class Type>
610 for (Type& val : *
this)
617 template<
class Form,
class Type>
620 for (Type& val : *
this)
627 template<
class Form,
class Type>
630 for (Type& val : *
this)
637 template<
class Form,
class Type>
640 for (Type& val : *
this)
655 template<
class Form,
class Type>
664 return *(std::max_element(mat.
cbegin(), mat.
cend()));
669 template<
class Form,
class Type>
678 return *(std::min_element(mat.
cbegin(), mat.
cend()));
683 template<
class Form,
class Type>
688 for (
const Type& val : mat)
701 template<
class Form,
class Type>
704 Form result(mat.
sizes());
719 template<
class Form1,
class Form2,
class Type>
727 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
730 <<
"Attempt to add matrices with different sizes: ("
731 <<
A.m() <<
", " <<
A.n() <<
") != ("
732 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
737 Form1 result(
A.sizes());
753 template<
class Form1,
class Form2,
class Type>
761 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
764 <<
"Attempt to subtract matrices with different sizes: ("
765 <<
A.m() <<
", " <<
A.n() <<
") != ("
766 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
771 Form1 result(
A.sizes());
787 template<
class Form,
class Type>
790 Form result(mat.
sizes());
797 [&](
const Type& val) {
return s * val; }
805 template<
class Form,
class Type>
813 template<
class Form,
class Type>
816 Form result(mat.
sizes());
823 [&](
const Type& val) {
return s + val; }
831 template<
class Form,
class Type>
839 template<
class Form,
class Type>
842 Form result(mat.
sizes());
849 [&](
const Type& val) {
return s - val; }
857 template<
class Form,
class Type>
860 Form result(mat.
sizes());
867 [&](
const Type& val) {
return val -
s; }
875 template<
class Form,
class Type>
878 Form result(mat.
sizes());
885 [&](
const Type& val) {
return val /
s; }
893 template<
class Form1,
class Form2,
class Type>
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"
920 for (label i = 0; i < AB.m(); ++i)
922 for (label
k = 0;
k <
B.m(); ++
k)
924 for (label j = 0; j < AB.n(); ++j)
926 AB(i, j) +=
A(i,
k)*
B(
k, j);
936 template<
class Form1,
class Form2,
class Type>
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"
963 for (label i = 0; i < AB.m(); ++i)
965 for (label
k = 0;
k <
B.m(); ++
k)
967 for (label j = 0; j < AB.n(); ++j)
979 template<
class Form1,
class Form2,
class Type>
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"
1006 for (label i = 0; i < AB.m(); ++i)
1008 for (label
k = 0;
k < BT.n(); ++
k)
1010 for (label j = 0; j < AB.n(); ++j)
label n() const
Return the number of columns in the block.
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
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))
A class for managing temporary objects.
label n() const noexcept
The number of columns.
static constexpr const zero Zero
Global zero (0)
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
labelPair sizes() const
Return row/column sizes.
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
void Swap(DynamicList< T, SizeMin1 > &a, DynamicList< T, SizeMin2 > &b)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
void transfer(Matrix< Form, Type > &mat)
void round(const scalar tol=SMALL)
Round elements with magnitude smaller than tol (SMALL) to zero.
const_iterator cend() const
Return const_iterator to end traversing a constant Matrix.
void resize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
A templated block of an (m x n) matrix of type <MatrixType>.
scalar columnNorm(const label colIndex, const bool noSqrt=false) const
Return L2-Norm of chosen column.
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
void operator*=(const Type &s)
Matrix scalar multiplication.
void clear()
Clear Matrix, i.e. set sizes to zero.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
label n() const
Return the number of columns in the block.
void operator/=(const Type &s)
Matrix scalar division.
errorManip< error > abort(error &err)
void swap(Matrix< Form, Type > &mat)
Swap contents.
void operator=(const Matrix< Form, Type > &mat)
Copy assignment. Takes linear time.
label m() const
Return the number of rows in the block.
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Form T() const
Return (conjugate) transpose of Matrix.
iterator end()
Return an iterator to end traversing a Matrix.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Type trace() const
Return the trace.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label m() const noexcept
The number of rows.
const Type & min(const Matrix< Form, Type > &mat)
Find min value in Matrix.
std::enable_if< !std::is_same< complex, T >::value, const T & >::type conj(const T &val)
dimensionedScalar sqrt(const dimensionedScalar &ds)
scalar norm(const bool noSqrt=false) const
Return Frobenius norm of Matrix.
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
const_iterator cbegin() const
Return const_iterator to begin traversing a constant Matrix.
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
const Type * cdata() const noexcept
label k
Boltzmann constant.
label m() const
Return the number of rows in the block.
void size(const label n) noexcept
Override size to be inconsistent with allocated storage.
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
A min/max value pair with additional methods. In addition to conveniently storing values,...
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...