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_)
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>
385 for (
label i=0; i < len; ++i)
387 result[i] = (*this)(i, i);
394 template<
class Form,
class Type>
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>
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)
649 template<
class Form,
class Type>
658 return *(std::max_element(mat.
cbegin(), mat.
cend()));
662 template<
class Form,
class Type>
671 return *(std::min_element(mat.
cbegin(), mat.
cend()));
675 template<
class Form,
class Type>
680 for (
const Type&
val : mat)
691 template<
class Form,
class Type>
694 Form result(mat.
sizes());
708 template<
class Form1,
class Form2,
class Type>
709 Form1 Foam::operator+
716 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
719 <<
"Attempt to add matrices with different sizes: ("
720 <<
A.m() <<
", " <<
A.n() <<
") != ("
721 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
726 Form1 result(
A.sizes());
741 template<
class Form1,
class Form2,
class Type>
742 Form1 Foam::operator-
749 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
752 <<
"Attempt to subtract matrices with different sizes: ("
753 <<
A.m() <<
", " <<
A.n() <<
") != ("
754 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
759 Form1 result(
A.sizes());
774 template<
class Form,
class Type>
777 Form result(mat.
sizes());
784 [&](
const Type&
val) {
return s *
val; }
791 template<
class Form,
class Type>
794 Form result(mat.
sizes());
801 [&](
const Type&
val) {
return s +
val; }
808 template<
class Form,
class Type>
811 Form result(mat.
sizes());
818 [&](
const Type&
val) {
return s -
val; }
825 template<
class Form,
class Type>
832 template<
class Form,
class Type>
839 template<
class Form,
class Type>
842 Form result(mat.
sizes());
849 [&](
const Type&
val) {
return val -
s; }
856 template<
class Form,
class Type>
859 Form result(mat.
sizes());
866 [&](
const Type&
val) {
return val /
s; }
873 template<
class Form1,
class Form2,
class Type>
877 const Matrix<Form1, Type>&
A,
878 const Matrix<Form2, Type>&
B
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"
900 for (
label i = 0; i < AB.m(); ++i)
904 for (
label j = 0; j < AB.n(); ++j)
906 AB(i, j) +=
A(i,
k)*
B(
k, j);
915 template<
class Form1,
class Form2,
class Type>
919 const Matrix<Form1, Type>& AT,
920 const Matrix<Form2, Type>&
B
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"
942 for (
label i = 0; i < AB.m(); ++i)
946 for (
label j = 0; j < AB.n(); ++j)
957 template<
class Form1,
class Form2,
class Type>
961 const Matrix<Form1, Type>&
A,
962 const Matrix<Form2, Type>& BT
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"
984 for (
label i = 0; i < AB.m(); ++i)
988 for (
label j = 0; j < AB.n(); ++j)
label ListType::const_reference val
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.
static constexpr const zero Zero
Global zero.
ConstMatrixBlock< mType > const label n
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 to zero elements with magnitude smaller than tol (SMALL)
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.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
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.
An ordered pair of two objects of type <T> with first() and second() elements.
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), which can be used to avoid manipulating objects that ar...