34template<
class Form,
class Type>
35template<
class ListType>
44 if (mat.
n() !=
x.size())
47 <<
"Attempt to multiply incompatible Matrix and Vector:" <<
nl
48 <<
"Matrix : (" << mat.
m() <<
", " << mat.
n() <<
')' <<
nl
49 <<
"Matrix columns != Vector size (" <<
x.size() <<
')' <<
nl
55 auto& result = tresult.ref();
57 for (label i = 0; i < mat.
m(); ++i)
59 for (label j = 0; j < mat.
n(); ++j)
61 result[i] += mat(i, j)*
x[j];
69template<
class Form,
class Type>
70template<
class ListType>
79 if (mat.
m() !=
x.size())
82 <<
"Attempt to multiply incompatible Matrix and Vector:" <<
nl
83 <<
"Matrix : (" << mat.
m() <<
", " << mat.
n() <<
')' <<
nl
84 <<
"Matrix rows != Vector size (" <<
x.size() <<
')' <<
nl
89 auto tresult = tmp<Field<Type>>::New(mat.
n(),
Foam::zero{});
90 auto& result = tresult.ref();
92 for (label i = 0; i < mat.
m(); ++i)
94 const Type& val =
x[i];
95 for (label j = 0; j < mat.
n(); ++j)
97 result[j] += val*mat(i, j);
107template<
class Form,
class Type>
120template<
class Form,
class Type>
135template<
class Form,
class Type>
150template<
class Form,
class Type>
161 std::copy(mat.cbegin(), mat.cend(), v_);
166template<
class Form,
class Type>
179template<
class Form,
class Type>
191 std::copy(mat.cbegin(), mat.cend(), v_);
196template<
class Form,
class Type>
197template<
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);
219template<
class Form,
class Type>
220template<
class MatrixType>
232 for (label i = 0; i < mRows_; ++i)
234 for (label j = 0; j < nCols_; ++j)
236 (*this)(i, j) = Mb(i, j);
244template<
class Form,
class Type>
254template<
class Form,
class Type>
266template<
class Form,
class Type>
271 const label len = size();
286template<
class Form,
class Type>
294 std::swap(mRows_, mat.mRows_);
295 std::swap(nCols_, mat.nCols_);
296 std::swap(v_, mat.v_);
300template<
class Form,
class Type>
320template<
class Form,
class Type>
323 if (m == mRows_ &&
n == nCols_)
333 for (label i = 0; i < mrow; ++i)
335 for (label j = 0; j < ncol; ++j)
337 newMatrix(i, j) = (*this)(i, j);
345template<
class Form,
class Type>
348 if (mrow == mRows_ && ncol == nCols_)
353 const label oldLen = (mRows_ * nCols_);
355 const label newLen = (mrow * ncol);
357 if (oldLen == newLen)
375template<
class Form,
class Type>
378 for (Type& val : *
this)
388template<
class Form,
class Type>
393 for (label i = 0; i < m(); ++i)
395 for (label j = 0; j <
n(); ++j)
405template<
class Form,
class Type>
410 for (label i = 0; i < m(); ++i)
412 for (label j = 0; j <
n(); ++j)
414 At(j, i) = (*this)(i, j);
422template<
class Form,
class Type>
425 const label len =
Foam::min(mRows_, nCols_);
427 List<Type> result(len);
429 for (label i=0; i < len; ++i)
431 result[i] = (*this)(i, i);
438template<
class Form,
class Type>
441 const label len =
Foam::min(mRows_, nCols_);
444 if (list.size() != len)
447 <<
"List size (" << list.size()
452 for (label i=0; i < len; ++i)
454 (*this)(i, i) = list[i];
459template<
class Form,
class Type>
462 const label len =
Foam::min(mRows_, nCols_);
466 for (label i=0; i < len; ++i)
468 val += (*this)(i, i);
475template<
class Form,
class Type>
478 const label colIndex,
484 for (label i=0; i < mRows_; ++i)
486 result +=
magSqr((*
this)(i, colIndex));
493template<
class Form,
class Type>
498 for (
const Type& val : *
this)
507template<
class Form,
class Type>
513 <<
"Invalid for non-contiguous data types"
522template<
class Form,
class Type>
530 if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
545template<
class Form,
class Type>
556template<
class Form,
class Type>
557template<
class MatrixType>
560 const ConstMatrixBlock<MatrixType>& Mb
563 for (label i = 0; i < mRows_; ++i)
565 for (label j = 0; j < nCols_; ++j)
567 (*this)(i, j) = Mb(i, j);
573template<
class Form,
class Type>
574template<
class MatrixType>
580 for (label i = 0; i < mRows_; ++i)
582 for (label j = 0; j < nCols_; ++j)
584 (*this)(i, j) = Mb(i, j);
590template<
class Form,
class Type>
597template<
class Form,
class Type>
604template<
class Form,
class Type>
611 <<
"Attempted addition to self"
615 if (m() != other.
m() ||
n() != other.
n())
618 <<
"Attempt to add matrices with different sizes: ("
619 << m() <<
", " <<
n() <<
") != ("
620 << other.
m() <<
", " << other.
n() <<
')' <<
nl
625 auto iter2 = other.
cbegin();
626 for (Type& val : *
this)
634template<
class Form,
class Type>
641 <<
"Attempted subtraction from self"
645 if (m() != other.
m() ||
n() != other.
n())
648 <<
"Attempt to subtract matrices with different sizes: ("
649 << m() <<
", " <<
n() <<
") != ("
650 << other.
m() <<
", " << other.
n() <<
')' <<
nl
655 auto iter2 = other.
cbegin();
656 for (Type& val : *
this)
664template<
class Form,
class Type>
667 for (Type& val : *
this)
674template<
class Form,
class Type>
677 for (Type& val : *
this)
684template<
class Form,
class Type>
687 for (Type& val : *
this)
694template<
class Form,
class Type>
697 for (Type& val : *
this)
712template<
class Form,
class Type>
721 return *(std::max_element(mat.
cbegin(), mat.
cend()));
726template<
class Form,
class Type>
735 return *(std::min_element(mat.
cbegin(), mat.
cend()));
740template<
class Form,
class Type>
745 for (
const Type& val : mat)
758template<
class Form,
class Type>
759Form
operator-(
const Matrix<Form, Type>& mat)
761 Form result(mat.sizes());
776template<
class Form1,
class Form2,
class Type>
779 const Matrix<Form1, Type>&
A,
784 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
787 <<
"Attempt to add matrices with different sizes: ("
788 <<
A.m() <<
", " <<
A.n() <<
") != ("
789 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
794 Form1 result(
A.sizes());
810template<
class Form1,
class Form2,
class Type>
813 const Matrix<Form1, Type>&
A,
814 const Matrix<Form2, Type>&
B
818 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
821 <<
"Attempt to subtract matrices with different sizes: ("
822 <<
A.m() <<
", " <<
A.n() <<
") != ("
823 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
828 Form1 result(
A.sizes());
844template<
class Form,
class Type>
845Form
operator*(
const Type&
s,
const Matrix<Form, Type>& mat)
847 Form result(mat.sizes());
854 [&](
const Type& val) { return s * val; }
862template<
class Form,
class Type>
863Form
operator*(
const Matrix<Form, Type>& mat,
const Type&
s)
870template<
class Form,
class Type>
873 Form result(mat.sizes());
880 [&](
const Type& val) { return s + val; }
888template<
class Form,
class Type>
889Form
operator+(
const Matrix<Form, Type>& mat,
const Type&
s)
896template<
class Form,
class Type>
899 Form result(mat.sizes());
906 [&](
const Type& val) { return s - val; }
914template<
class Form,
class Type>
917 Form result(mat.
sizes());
924 [&](
const Type& val) { return val - s; }
932template<
class Form,
class Type>
935 Form result(mat.
sizes());
942 [&](
const Type& val) { return val / s; }
950template<
class Form1,
class Form2,
class Type>
951typename typeOfInnerProduct<Type, Form1, Form2>::type
962 <<
"Attempt to multiply incompatible matrices:" <<
nl
963 <<
"Matrix A : (" <<
A.m() <<
", " <<
A.n() <<
')' <<
nl
964 <<
"Matrix B : (" <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
965 <<
"The columns of A must equal rows of B"
977 for (label i = 0; i < AB.m(); ++i)
979 for (label
k = 0;
k <
B.m(); ++
k)
981 for (label j = 0; j < AB.n(); ++j)
983 AB(i, j) +=
A(i,
k)*
B(
k, j);
993template<
class Form1,
class Form2,
class Type>
1002 if (AT.m() !=
B.m())
1005 <<
"Attempt to multiply incompatible matrices:" <<
nl
1006 <<
"Matrix A : (" << AT.m() <<
", " << AT.n() <<
')' <<
nl
1007 <<
"Matrix B : (" <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
1008 <<
"The rows of A must equal rows of B"
1020 for (label
k = 0;
k <
B.m(); ++
k)
1022 for (label i = 0; i < AB.m(); ++i)
1024 for (label j = 0; j < AB.n(); ++j)
1036template<
class Form1,
class Form2,
class Type>
1045 if (
A.n() != BT.n())
1048 <<
"Attempt to multiply incompatible matrices:" <<
nl
1049 <<
"Matrix A : (" <<
A.m() <<
", " <<
A.n() <<
')' <<
nl
1050 <<
"Matrix B : (" << BT.m() <<
", " << BT.n() <<
')' <<
nl
1051 <<
"The columns of A must equal columns of B"
1063 for (label i = 0; i < AB.m(); ++i)
1065 for (label j = 0; j < AB.n(); ++j)
1067 for (label
k = 0;
k < BT.n(); ++
k)
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A templated block of an (m x n) matrix of type <MatrixType>.
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
constexpr Matrix() noexcept
const Type * cdata() const noexcept
Return const pointer to the first data element, which can also be used to address into Matrix content...
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
List< Type > release()
Release storage management of Matrix contents by transferring management to a List.
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero).
void round(const scalar tol=SMALL)
Round elements with magnitude smaller than tol (SMALL) to zero.
label m() const noexcept
The number of rows.
void transfer(Matrix< Form, Type > &mat)
Transfer the contents of the argument Matrix into this Matrix and annul the argument Matrix.
labelPair sizes() const noexcept
Return row/column sizes.
Form transpose() const
Return non-conjugate transpose of Matrix.
void operator*=(const Type &s)
Matrix scalar multiplication.
void checkSize() const
Check that dimensions are positive, non-zero.
Type trace() const
Return the trace.
iterator begin() noexcept
Return an iterator to begin traversing a Matrix.
label size() const noexcept
The number of elements in Matrix (m*n).
Form T() const
Return conjugate transpose of Matrix.
void resize_nocopy(const label mrow, const label ncol)
Change Matrix dimensions without preserving existing content.
label n() const noexcept
The number of columns.
iterator end() noexcept
Return an iterator to end traversing a Matrix.
std::streamsize byteSize() const
Number of contiguous bytes for the Matrix data, runtime FatalError if type is not contiguous.
void swap(Matrix< Form, Type > &mat)
Swap contents.
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
void clear()
Clear Matrix, i.e. set sizes to zero.
void operator=(const Matrix< Form, Type > &mat)
Copy assignment. Takes linear time.
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
scalar columnNorm(const label colIndex, const bool noSqrt=false) const
Return L2-Norm of chosen column.
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the Matrix data, no runtime check that the type is actually contiguous...
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
scalar norm(const bool noSqrt=false) const
Return Frobenius norm of Matrix.
void operator/=(const Type &s)
Matrix scalar division.
void resize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
const_iterator cend() const noexcept
Return const_iterator to end traversing a constant Matrix.
A min/max value pair with additional methods. In addition to conveniently storing values,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
iterator begin() noexcept
Return an iterator to begin traversing the UList.
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
void size(const label n)
Older name for setAddressableSize.
A class for managing temporary objects.
Abstract template class to provide the form resulting from the inner-product of two forms.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
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))
std::enable_if_t<!std::is_same_v< complex, T >, const T & > conj(const T &val)
The 'conjugate' of non-complex returns itself (pass-through) it does not return a complex!
void deallocate(T *ptr)
Deallocate from memory pool, or normal.
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
Pair< label > labelPair
A pair of labels.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
constexpr bool is_contiguous_v
The is_contiguous value of Type (after stripping of qualifiers).
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a).