33 template<
class Form,
class Type>
36 const label len = size();
41 this->v_ = ListPolicy::allocate<Type>(len);
49 template<
class Form,
class Type>
58 template<
class Form,
class Type>
61 Matrix<Form, Type>(dims.first(), dims.second())
65 template<
class Form,
class Type>
72 template<
class Form,
class Type>
75 Matrix<Form, Type>(dims.first(), dims.second(), val)
79 template<
class Form,
class Type>
89 template<
class Form,
class Type>
92 return (mRows_ * nCols_);
96 template<
class Form,
class Type>
103 template<
class Form,
class Type>
106 return !mRows_ || !nCols_;
110 template<
class Form,
class Type>
113 if (!mRows_ || !nCols_)
116 <<
"Attempt to access element from empty matrix" 119 if (i < 0 || mRows_ <= i)
122 <<
"Index " << i <<
" out of range 0 ... " << mRows_-1
128 template<
class Form,
class Type>
131 if (!mRows_ || !nCols_)
134 <<
"Attempt to access element from empty matrix" 137 if (j < 0 || nCols_ <= j)
140 <<
"index " << j <<
" out of range 0 ... " << nCols_-1
146 template<
class Form,
class Type>
149 if (mRows_ < 0 || nCols_ < 0)
152 <<
"Incorrect size (" << mRows_ <<
", " << nCols_ <<
')' <<
nl 159 template<
class Form,
class Type>
171 template<
class Form,
class Type>
178 template<
class Form,
class Type>
185 template<
class Form,
class Type>
188 return reinterpret_cast<const char*
>(v_);
192 template<
class Form,
class Type>
195 return reinterpret_cast<char*
>(v_);
199 template<
class Form,
class Type>
202 return std::streamsize(mRows_*nCols_)*
sizeof(Type);
206 template<
class Form,
class Type>
212 return (v_ + irow*nCols_);
216 template<
class Form,
class Type>
222 return (v_ + irow*nCols_);
226 template<
class Form,
class Type>
230 if (idx < 0 || this->size() <= idx)
233 <<
"index " << idx <<
" out of range 0 ... " << this->size()
241 template<
class Form,
class Type>
245 if (idx < 0 || this->size() <= idx)
248 <<
"index " << idx <<
" out of range 0 ... " << this->size()
256 template<
class Form,
class Type>
260 const label colIndex,
261 const label rowIndex,
267 len = mRows_ - rowIndex;
270 return ConstMatrixBlock<mType>
281 template<
class Form,
class Type>
285 const label rowIndex,
286 const label colIndex,
292 len = nCols_ - colIndex;
295 return ConstMatrixBlock<mType>
306 template<
class Form,
class Type>
310 const label rowIndex,
311 const label colIndex,
316 if (szRows < 0) szRows = mRows_ - rowIndex;
317 if (szCols < 0) szCols = nCols_ - colIndex;
330 template<
class Form,
class Type>
331 template<
class VectorSpace>
335 const label rowIndex,
350 template<
class Form,
class Type>
354 const label colIndex,
355 const label rowIndex,
361 len = mRows_ - rowIndex;
364 return MatrixBlock<mType>
375 template<
class Form,
class Type>
379 const label rowIndex,
380 const label colIndex,
386 len = nCols_ - colIndex;
389 return MatrixBlock<mType>
400 template<
class Form,
class Type>
404 const label rowIndex,
405 const label colIndex,
410 if (szRows < 0) szRows = mRows_ - rowIndex;
411 if (szCols < 0) szCols = nCols_ - colIndex;
424 template<
class Form,
class Type>
425 template<
class VectorSpace>
429 const label rowIndex,
444 template<
class Form,
class Type>
451 template<
class Form,
class Type>
459 template<
class Form,
class Type>
465 return this->AmulImpl(
x);
469 template<
class Form,
class Type>
476 return this->AmulImpl(
x);
480 template<
class Form,
class Type>
486 return this->TmulImpl(
x);
490 template<
class Form,
class Type>
497 return this->TmulImpl(
x);
503 template<
class Form,
class Type>
511 template<
class Form,
class Type>
515 return v_ + (mRows_ * nCols_);
519 template<
class Form,
class Type>
527 template<
class Form,
class Type>
531 return v_ + (mRows_ * nCols_);
535 template<
class Form,
class Type>
543 template<
class Form,
class Type>
547 return v_ + (mRows_ * nCols_);
553 template<
class Form,
class Type>
564 return v_[irow*nCols_ + jcol];
568 template<
class Form,
class Type>
579 return v_[irow*nCols_ + jcol];
583 template<
class Form,
class Type>
589 return v_ + irow*nCols_;
593 template<
class Form,
class Type>
599 return v_ + irow*nCols_;
611 template<
class Form,
class Type>
623 template<
class Form,
class Type,
class Addr>
635 template<
class Form,
class Type>
647 template<
class Form,
class Type,
class Addr>
648 inline tmp<Field<Type>>
operator*
void shallowResize(const label m, const label n)
Resize Matrix without reallocating storage (unsafe)
ConstMatrixBlock< mType > subColumn(const label colIndex, const label rowIndex=0, label len=-1) const
Return const column or column's subset of Matrix.
ConstMatrixBlock< mType > subRow(const label rowIndex, const label colIndex=0, label len=-1) const
Return const row or const row's subset of Matrix.
autoPtr< mType > clone() const
Clone.
constexpr Matrix() noexcept
Default construct (empty matrix)
patchWriters resize(patchIds.size())
tmp< Field< Type > > Tmul(const UList< Type > &x) const
Left-multiply Matrix by a row vector (x * A)
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.
constexpr char nl
The newline '\n' character (0x0a)
tmp< Field< Type > > Amul(const UList< Type > &x) const
Right-multiply Matrix by a column vector (A * x)
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.
A templated block of an (m x n) matrix of type <MatrixType>.
void setSize(const label m, const label n)
Change Matrix dimensions, preserving the elements.
const Type * operator[](const label irow) const
Return const pointer to data in the specified row - rowData().
enum uniformity check_uniformity(InputIt first, InputIt last)
Algorithm to determine list/container uniformity.
iterator begin() noexcept
Return an iterator to begin traversing a Matrix.
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
bool empty() const noexcept
Return true if Matrix is empty (i.e., size() is zero)
ConstMatrixBlock< mType > subMatrix(const label rowIndex, const label colIndex, label szRows=-1, label szCols=-1) const
Return const sub-block of Matrix.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage, reinterpreted as byte data...
labelPair sizes() const noexcept
Return row/column sizes.
const Type & at(const label idx) const
Linear addressing const element access.
Type * iterator
Random access iterator for traversing a Matrix.
bool uniform() const
True if all entries have identical values, and Matrix is non-empty.
iterator end() noexcept
Return an iterator to end traversing a Matrix.
Container (non-empty) with identical values.
label size() const noexcept
The number of elements in Matrix (m*n)
errorManip< error > abort(error &err)
const Type * cdata() const noexcept
Return const pointer to the first data element, which can also be used to address into Matrix content...
void checki(const label irow) const
Check index i is within valid range [0, m)
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order: ...
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the Matrix data, no runtime check that the type is actually contiguous...
Pair< label > labelPair
A pair of labels.
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage, reinterpreted as byte data...
const Type * const_iterator
Random access iterator for traversing a Matrix.
const_iterator cend() const noexcept
Return const_iterator to end traversing a constant Matrix.
const Type * rowData(const label irow) const
Return const pointer to data in the specified row.
void checkj(const label jcol) const
Check index j is within valid range [0, n)
Type * data() noexcept
Return pointer to the first data element, which can also be used to address into Matrix contents...
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing a constant Matrix.
A class for managing temporary objects.
ConstMatrixBlock< mType > block(const label rowIndex, const label colIndex) const
Access Field as a ConstMatrixBlock.
void checkSize() const
Check that dimensions are positive, non-zero.