35template<
class Form,
class Type>
36template<
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];
70template<
class Form,
class Type>
71template<
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);
108template<
class Form,
class Type>
121template<
class Form,
class Type>
136template<
class Form,
class Type>
147 std::fill(begin(), end(), val);
151template<
class Form,
class Type>
167template<
class Form,
class Type>
180template<
class Form,
class Type>
197template<
class Form,
class Type>
198template<
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>
231 for (label i = 0; i < mRows_; ++i)
233 for (label j = 0; j < nCols_; ++j)
235 (*this)(i, j) = Mb(i, j);
243template<
class Form,
class Type>
255template<
class Form,
class Type>
269template<
class Form,
class Type>
274 const label len = size();
289template<
class Form,
class Type>
297 std::swap(mRows_, mat.mRows_);
298 std::swap(nCols_, mat.nCols_);
299 std::swap(v_, mat.v_);
303template<
class Form,
class Type>
323template<
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);
348template<
class Form,
class Type>
351 if (mrow == mRows_ && ncol == nCols_)
356 const label oldLen = (mRows_ * nCols_);
358 const label newLen = (mrow * ncol);
360 if (oldLen == newLen)
378template<
class Form,
class Type>
381 for (Type& val : *
this)
391template<
class Form,
class Type>
396 for (label i = 0; i < m(); ++i)
398 for (label j = 0; j <
n(); ++j)
408template<
class Form,
class Type>
413 for (label i = 0; i < m(); ++i)
415 for (label j = 0; j <
n(); ++j)
417 At(j, i) = (*this)(i, j);
425template<
class Form,
class Type>
428 const label len =
Foam::min(mRows_, nCols_);
432 for (label i=0; i < len; ++i)
434 result[i] = (*this)(i, i);
441template<
class Form,
class Type>
447 if (list.
size() != len)
450 <<
"List size (" << list.
size()
455 for (label i=0; i < len; ++i)
457 (*this)(i, i) = list[i];
462template<
class Form,
class Type>
465 const label len =
Foam::min(mRows_, nCols_);
469 for (label i=0; i < len; ++i)
471 val += (*this)(i, i);
478template<
class Form,
class Type>
481 const label colIndex,
485 scalar result =
Zero;
487 for (label i=0; i < mRows_; ++i)
489 result +=
magSqr((*
this)(i, colIndex));
496template<
class Form,
class Type>
499 scalar result =
Zero;
501 for (
const Type& val : *
this)
510template<
class Form,
class Type>
516 <<
"Invalid for non-contiguous data types"
519 return this->size_bytes();
525template<
class Form,
class Type>
533 if (mRows_ != mat.mRows_ || nCols_ != mat.nCols_)
548template<
class Form,
class Type>
559template<
class Form,
class Type>
560template<
class MatrixType>
566 for (label i = 0; i < mRows_; ++i)
568 for (label j = 0; j < nCols_; ++j)
570 (*this)(i, j) = Mb(i, j);
576template<
class Form,
class Type>
577template<
class MatrixType>
583 for (label i = 0; i < mRows_; ++i)
585 for (label j = 0; j < nCols_; ++j)
587 (*this)(i, j) = Mb(i, j);
593template<
class Form,
class Type>
596 std::fill(begin(), end(), val);
600template<
class Form,
class Type>
603 std::fill(begin(), end(),
Zero);
607template<
class Form,
class Type>
614 <<
"Attempted addition to self"
618 if (m() != other.
m() ||
n() != other.
n())
621 <<
"Attempt to add matrices with different sizes: ("
622 << m() <<
", " <<
n() <<
") != ("
623 << other.
m() <<
", " << other.
n() <<
')' <<
nl
628 auto iter2 = other.
cbegin();
629 for (Type& val : *
this)
637template<
class Form,
class Type>
644 <<
"Attempted subtraction from self"
648 if (m() != other.
m() ||
n() != other.
n())
651 <<
"Attempt to subtract matrices with different sizes: ("
652 << m() <<
", " <<
n() <<
") != ("
653 << other.
m() <<
", " << other.
n() <<
')' <<
nl
658 auto iter2 = other.
cbegin();
659 for (Type& val : *
this)
667template<
class Form,
class Type>
670 for (Type& val : *
this)
677template<
class Form,
class Type>
680 for (Type& val : *
this)
687template<
class Form,
class Type>
690 for (Type& val : *
this)
697template<
class Form,
class Type>
700 for (Type& val : *
this)
715template<
class Form,
class Type>
724 return *(std::max_element(mat.
cbegin(), mat.
cend()));
729template<
class Form,
class Type>
738 return *(std::min_element(mat.
cbegin(), mat.
cend()));
743template<
class Form,
class Type>
748 for (
const Type& val : mat)
761template<
class Form,
class Type>
764 Form result(mat.
sizes());
779template<
class Form1,
class Form2,
class Type>
787 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
790 <<
"Attempt to add matrices with different sizes: ("
791 <<
A.m() <<
", " <<
A.n() <<
") != ("
792 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
797 Form1 result(
A.sizes());
813template<
class Form1,
class Form2,
class Type>
821 if (
A.m() !=
B.m() ||
A.n() !=
B.n())
824 <<
"Attempt to subtract matrices with different sizes: ("
825 <<
A.m() <<
", " <<
A.n() <<
") != ("
826 <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
831 Form1 result(
A.sizes());
847template<
class Form,
class Type>
850 Form result(mat.
sizes());
857 [&](
const Type& val) { return s * val; }
865template<
class Form,
class Type>
873template<
class Form,
class Type>
876 Form result(mat.
sizes());
883 [&](
const Type& val) { return s + val; }
891template<
class Form,
class Type>
899template<
class Form,
class Type>
902 Form result(mat.
sizes());
909 [&](
const Type& val) { return s - val; }
917template<
class Form,
class Type>
920 Form result(mat.
sizes());
927 [&](
const Type& val) { return val - s; }
935template<
class Form,
class Type>
938 Form result(mat.
sizes());
945 [&](
const Type& val) { return val / s; }
953template<
class Form1,
class Form2,
class Type>
965 <<
"Attempt to multiply incompatible matrices:" <<
nl
966 <<
"Matrix A : (" <<
A.m() <<
", " <<
A.n() <<
')' <<
nl
967 <<
"Matrix B : (" <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
968 <<
"The columns of A must equal rows of B"
980 for (label i = 0; i < AB.m(); ++i)
982 for (label
k = 0;
k <
B.m(); ++
k)
984 for (label j = 0; j < AB.n(); ++j)
986 AB(i, j) +=
A(i,
k)*
B(
k, j);
996template<
class Form1,
class Form2,
class Type>
1005 if (AT.
m() !=
B.m())
1008 <<
"Attempt to multiply incompatible matrices:" <<
nl
1009 <<
"Matrix A : (" << AT.
m() <<
", " << AT.
n() <<
')' <<
nl
1010 <<
"Matrix B : (" <<
B.m() <<
", " <<
B.n() <<
')' <<
nl
1011 <<
"The rows of A must equal rows of B"
1023 for (label
k = 0;
k <
B.m(); ++
k)
1025 for (label i = 0; i < AB.m(); ++i)
1027 for (label j = 0; j < AB.n(); ++j)
1039template<
class Form1,
class Form2,
class Type>
1048 if (
A.n() != BT.n())
1051 <<
"Attempt to multiply incompatible matrices:" <<
nl
1052 <<
"Matrix A : (" <<
A.m() <<
", " <<
A.n() <<
')' <<
nl
1053 <<
"Matrix B : (" << BT.m() <<
", " << BT.n() <<
')' <<
nl
1054 <<
"The columns of A must equal columns of B"
1066 for (label i = 0; i < AB.m(); ++i)
1068 for (label j = 0; j < AB.n(); ++j)
1070 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)
virtual bool resize()
Resize the ODE solver.
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:
label n() const noexcept
The number of columns.
const Type * cdata() const noexcept
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
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.
Form transpose() const
Return non-conjugate transpose of Matrix.
labelPair sizes() const
Return row/column sizes.
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.
Form T() const
Return conjugate transpose of Matrix.
void resize_nocopy(const label mrow, const label ncol)
Change Matrix dimensions without preserving existing content.
iterator end() noexcept
Return an iterator to end traversing a Matrix.
std::streamsize byteSize() const
void swap(Matrix< Form, Type > &mat)
Swap contents.
void operator+=(const Matrix< Form, Type > &other)
Matrix addition.
Matrix() noexcept
Default construct (empty matrix)
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.
label m() const noexcept
The number of rows.
void operator-=(const Matrix< Form, Type > &other)
Matrix subtraction.
void operator/=(const Type &s)
Matrix scalar division.
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...
void swap(UList< T > &list)
Swap content with another UList of the same type in constant time.
void size(const label n)
Older name for setAddressableSize.
Normalises an input field with a chosen norm, and outputs a new normalised field.
transferModelList & transfer()
Transfer.
A class for managing temporary objects.
type
Volume classification types.
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<!std::is_same< complex, T >::value, constT & >::type conj(const T &val)
tmp< faMatrix< Type > > operator-(const faMatrix< Type > &)
Unary negation.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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)
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
A template class to specify that a data type can be considered as being contiguous in memory.