33 template<
class Form,
class Type>
36 const label len = size();
48 template<
class Form,
class Type>
57 template<
class Form,
class Type>
60 Matrix<Form, Type>(dims.first(), dims.second())
64 template<
class Form,
class Type>
71 template<
class Form,
class Type>
74 Matrix<Form, Type>(dims.first(), dims.second(), val)
78 template<
class Form,
class Type>
88 template<
class Form,
class Type>
91 return NullObjectRef<Matrix<Form, Type>>();
95 template<
class Form,
class Type>
98 return mRows_ * nCols_;
102 template<
class Form,
class Type>
109 template<
class Form,
class Type>
112 return !mRows_ || !nCols_;
116 template<
class Form,
class Type>
119 if (!mRows_ || !nCols_)
122 <<
"Attempt to access element from empty matrix" 125 if (i < 0 || mRows_ <= i)
128 <<
"Index " << i <<
" out of range 0 ... " << mRows_-1
134 template<
class Form,
class Type>
137 if (!mRows_ || !nCols_)
140 <<
"Attempt to access element from empty matrix" 143 if (j < 0 || nCols_ <= j)
146 <<
"index " << j <<
" out of range 0 ... " << nCols_-1
152 template<
class Form,
class Type>
155 if (mRows_ < 0 || nCols_ < 0)
158 <<
"Incorrect size (" << mRows_ <<
", " << nCols_ <<
')' <<
nl 165 template<
class Form,
class Type>
168 const label len = size();
176 for (label idx = 1; idx < len; ++idx)
178 if (v_[0] != v_[idx])
188 template<
class Form,
class Type>
195 template<
class Form,
class Type>
202 template<
class Form,
class Type>
205 return reinterpret_cast<const char*
>(v_);
209 template<
class Form,
class Type>
212 return reinterpret_cast<char*
>(v_);
216 template<
class Form,
class Type>
219 return mRows_*nCols_*
sizeof(Type);
223 template<
class Form,
class Type>
229 return (v_ + irow*nCols_);
233 template<
class Form,
class Type>
239 return (v_ + irow*nCols_);
243 template<
class Form,
class Type>
247 if (idx < 0 || this->size() <= idx)
250 <<
"index " << idx <<
" out of range 0 ... " << this->size()
258 template<
class Form,
class Type>
262 if (idx < 0 || this->size() <= idx)
265 <<
"index " << idx <<
" out of range 0 ... " << this->size()
273 template<
class Form,
class Type>
277 const label colIndex,
278 const label rowIndex,
284 len = mRows_ - rowIndex;
287 return ConstMatrixBlock<mType>
298 template<
class Form,
class Type>
302 const label rowIndex,
303 const label colIndex,
309 len = nCols_ - colIndex;
312 return ConstMatrixBlock<mType>
323 template<
class Form,
class Type>
327 const label rowIndex,
328 const label colIndex,
333 if (szRows < 0) szRows = mRows_ - rowIndex;
334 if (szCols < 0) szCols = nCols_ - colIndex;
347 template<
class Form,
class Type>
348 template<
class VectorSpace>
352 const label rowIndex,
367 template<
class Form,
class Type>
371 const label colIndex,
372 const label rowIndex,
378 len = mRows_ - rowIndex;
381 return MatrixBlock<mType>
392 template<
class Form,
class Type>
396 const label rowIndex,
397 const label colIndex,
403 len = nCols_ - colIndex;
406 return MatrixBlock<mType>
417 template<
class Form,
class Type>
421 const label rowIndex,
422 const label colIndex,
427 if (szRows < 0) szRows = mRows_ - rowIndex;
428 if (szCols < 0) szCols = nCols_ - colIndex;
441 template<
class Form,
class Type>
442 template<
class VectorSpace>
446 const label rowIndex,
461 template<
class Form,
class Type>
468 template<
class Form,
class Type>
476 template<
class Form,
class Type>
482 return this->AmulImpl(
x);
486 template<
class Form,
class Type>
493 return this->AmulImpl(
x);
497 template<
class Form,
class Type>
503 return this->TmulImpl(
x);
507 template<
class Form,
class Type>
514 return this->TmulImpl(
x);
520 template<
class Form,
class Type>
528 template<
class Form,
class Type>
532 return v_ + (mRows_ * nCols_);
536 template<
class Form,
class Type>
544 template<
class Form,
class Type>
548 return v_ + (mRows_ * nCols_);
552 template<
class Form,
class Type>
560 template<
class Form,
class Type>
564 return v_ + (mRows_ * nCols_);
570 template<
class Form,
class Type>
581 return v_[irow*nCols_ + jcol];
585 template<
class Form,
class Type>
596 return v_[irow*nCols_ + jcol];
600 template<
class Form,
class Type>
606 return v_ + irow*nCols_;
610 template<
class Form,
class Type>
616 return v_ + irow*nCols_;
628 template<
class Form,
class Type>
640 template<
class Form,
class Type,
class Addr>
652 template<
class Form,
class Type>
664 template<
class Form,
class Type,
class Addr>
665 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.
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().
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...
static const Matrix< Form, Type > & null()
Return a null Matrix.
label size() const
The number of elements in Matrix (m*n)
const Type & at(const label idx) const
Linear addressing const element access.
Type * iterator
Random access iterator for traversing a Matrix.
labelPair sizes() const
Return row/column sizes.
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.
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)
Matrix() noexcept
Default construct (empty matrix)
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.