34 template<
class Form,
class Type>
35 template<
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];
69 template<
class Form,
class Type>
70 template<
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 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);
107 template<
class Form,
class Type>
120 template<
class Form,
class Type>
131 std::fill_n(begin(), size(),
Zero);
135 template<
class Form,
class Type>
146 std::fill_n(begin(), size(), val);
150 template<
class Form,
class Type>
166 template<
class Form,
class Type>
179 template<
class Form,
class Type>
180 template<
class Form2>
196 template<
class Form,
class Type>
197 template<
class MatrixType>
200 const ConstMatrixBlock<MatrixType>& Mb
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>
223 const MatrixBlock<MatrixType>& Mb
232 for (label i = 0; i < mRows_; ++i)
234 for (label j = 0; j < nCols_; ++j)
236 (*this)(i, j) = Mb(i, j);
244 template<
class Form,
class Type>
254 template<
class Form,
class Type>
266 template<
class Form,
class Type>
271 const label len = size();
286 template<
class Form,
class Type>
294 std::swap(mRows_, mat.mRows_);
295 std::swap(nCols_, mat.nCols_);
296 std::swap(v_, mat.v_);
300 template<
class Form,
class Type>
320 template<
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);
345 template<
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)
375 template<
class Form,
class Type>
378 for (Type& val : *
this)
388 template<
class Form,
class Type>
393 for (label i = 0; i < m(); ++i)
395 for (label j = 0; j <
n(); ++j)
405 template<
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);
422 template<
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);
438 template<
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];
459 template<
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);
475 template<
class Form,
class Type>
478 const label colIndex,
484 for (label i=0; i < mRows_; ++i)
486 result +=
magSqr((*
this)(i, colIndex));
493 template<
class Form,
class Type>
498 for (
const Type& val : *
this)
507 template<
class Form,
class Type>
510 if constexpr (!is_contiguous_v<Type>)
513 <<
"Invalid for non-contiguous data types" 516 return this->size_bytes();
522 template<
class Form,
class Type>
530 if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
545 template<
class Form,
class Type>
556 template<
class Form,
class Type>
557 template<
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);
573 template<
class Form,
class Type>
574 template<
class MatrixType>
577 const MatrixBlock<MatrixType>& Mb
580 for (label i = 0; i < mRows_; ++i)
582 for (label j = 0; j < nCols_; ++j)
584 (*this)(i, j) = Mb(i, j);
590 template<
class Form,
class Type>
593 std::fill_n(begin(), size(), val);
597 template<
class Form,
class Type>
600 std::fill_n(begin(), size(),
Zero);
604 template<
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)
634 template<
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)
664 template<
class Form,
class Type>
667 for (Type& val : *
this)
674 template<
class Form,
class Type>
677 for (Type& val : *
this)
684 template<
class Form,
class Type>
687 for (Type& val : *
this)
694 template<
class Form,
class Type>
697 for (Type& val : *
this)
712 template<
class Form,
class Type>
721 return *(std::max_element(mat.
cbegin(), mat.
cend()));
726 template<
class Form,
class Type>
735 return *(std::min_element(mat.
cbegin(), mat.
cend()));
740 template<
class Form,
class Type>
745 for (
const Type& val : mat)
758 template<
class Form,
class Type>
759 Form
operator-(
const Matrix<Form, Type>& mat)
761 Form result(mat.sizes());
776 template<
class Form1,
class Form2,
class Type>
779 const Matrix<Form1, Type>&
A,
780 const Matrix<Form2, Type>&
B 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());
810 template<
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());
844 template<
class Form,
class Type>
845 Form
operator*(
const Type&
s,
const Matrix<Form, Type>& mat)
847 Form result(mat.sizes());
854 [&](
const Type& val) {
return s * val; }
862 template<
class Form,
class Type>
863 Form
operator*(
const Matrix<Form, Type>& mat,
const Type&
s)
870 template<
class Form,
class Type>
871 Form
operator+(
const Type&
s,
const Matrix<Form, Type>& mat)
873 Form result(mat.sizes());
880 [&](
const Type& val) {
return s + val; }
888 template<
class Form,
class Type>
889 Form
operator+(
const Matrix<Form, Type>& mat,
const Type&
s)
896 template<
class Form,
class Type>
897 Form
operator-(
const Type&
s,
const Matrix<Form, Type>& mat)
899 Form result(mat.sizes());
906 [&](
const Type& val) {
return s - val; }
914 template<
class Form,
class Type>
917 Form result(mat.
sizes());
924 [&](
const Type& val) {
return val -
s; }
932 template<
class Form,
class Type>
935 Form result(mat.
sizes());
942 [&](
const Type& val) {
return val /
s; }
950 template<
class Form1,
class Form2,
class 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);
993 template<
class Form1,
class Form2,
class Type>
997 const Matrix<Form1, Type>& AT,
998 const Matrix<Form2, Type>&
B 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)
1036 template<
class Form1,
class Form2,
class Type>
1040 const Matrix<Form1, Type>&
A,
1041 const Matrix<Form2, Type>& BT
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)
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
Abstract template class to provide the form resulting from the inner-product of two forms...
void resize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
constexpr Matrix() noexcept
Default construct (empty matrix)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Form T() const
Return conjugate transpose of Matrix.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
constexpr char nl
The newline '\n' character (0x0a)
A min/max value pair with additional methods. In addition to conveniently storing values...
scalar columnNorm(const label colIndex, const bool noSqrt=false) const
Return L2-Norm of chosen column.
dimensionedScalar sqrt(const dimensionedScalar &ds)
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.
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
label k
Boltzmann constant.
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! ...
List< Type > release()
Release storage management of Matrix contents by transferring management to a List.
tmp< faMatrix< Type > > operator+(const faMatrix< Type > &, const faMatrix< Type > &)
void transfer(Matrix< Form, Type > &mat)
Transfer the contents of the argument Matrix into this Matrix and annul the argument Matrix...
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
MinMax< label > minMax(const labelHashSet &set)
Find the min/max values of labelHashSet.
label n() const noexcept
The number of columns.
labelPair sizes() const noexcept
Return row/column sizes.
tmp< faMatrix< Type > > operator*(const areaScalarField::Internal &, const faMatrix< Type > &)
Type trace() const
Return the trace.
void operator*=(const Type &s)
Matrix scalar multiplication.
List< Type > diag() const
Extract the diagonal elements. Method may change in the future.
iterator end() noexcept
Return an iterator to end traversing a Matrix.
scalar norm(const bool noSqrt=false) const
Return Frobenius norm of Matrix.
void clear()
Clear Matrix, i.e. set sizes to zero.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
const Type * cdata() const noexcept
Return const pointer to the first data element, which can also be used to address into Matrix content...
void swap(Matrix< Form, Type > &mat)
Swap contents.
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order: ...
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
Pair< label > labelPair
A pair of labels.
label m() const noexcept
The number of rows.
std::streamsize byteSize() const
Number of contiguous bytes for the Matrix data, runtime FatalError if type is not contiguous...
const_iterator cend() const noexcept
Return const_iterator to end traversing a constant Matrix.
Form transpose() const
Return non-conjugate transpose of Matrix.
void operator/=(const Type &s)
Matrix scalar division.
void round(const scalar tol=SMALL)
Round elements with magnitude smaller than tol (SMALL) to zero.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
void resize_nocopy(const label mrow, const label ncol)
Change Matrix dimensions without preserving existing content.
A class for managing temporary objects.
void operator=(const Matrix< Form, Type > &mat)
Copy assignment. Takes linear time.
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))
static const Foam::dimensionedScalar A("", Foam::dimPressure, 611.21)
static const Foam::dimensionedScalar B("", Foam::dimless, 18.678)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)