/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "MatrixBlock.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template inline Foam::Matrix::Matrix() : mRows_(0), nCols_(0), v_(nullptr) {} template inline Foam::autoPtr> Foam::Matrix:: clone() const { return autoPtr>(new Matrix(*this)); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template inline const Foam::Matrix& Foam::Matrix::null() { return NullObjectRef>(); } template inline Foam::label Foam::Matrix::m() const { return mRows_; } template inline Foam::label Foam::Matrix::n() const { return nCols_; } template inline Foam::label Foam::Matrix::size() const { return mRows_*nCols_; } template inline void Foam::Matrix::checki(const label i) const { #ifdef FULLDEBUG if (!mRows_ || !nCols_) { FatalErrorInFunction << "Attempt to access element from empty matrix" << abort(FatalError); } else if (i<0 || i>=mRows_) { FatalErrorInFunction << "Index " << i << " out of range 0 ... " << mRows_-1 << abort(FatalError); } #endif } template inline void Foam::Matrix::checkj(const label j) const { #ifdef FULLDEBUG if (!mRows_ || !nCols_) { FatalErrorInFunction << "Attempt to access element from empty matrix" << abort(FatalError); } else if (j<0 || j>=nCols_) { FatalErrorInFunction << "index " << j << " out of range 0 ... " << nCols_-1 << abort(FatalError); } #endif } template inline const Type* Foam::Matrix::v() const { return v_; } template inline Type* Foam::Matrix::v() { return v_; } template inline Foam::ConstMatrixBlock> Foam::Matrix::block ( const label m, const label n, const label mStart, const label nStart ) const { return ConstMatrixBlock ( *this, m, n, mStart, nStart ); } template template inline Foam::ConstMatrixBlock> Foam::Matrix::block ( const label mStart, const label nStart ) const { return ConstMatrixBlock ( *this, VectorSpace::mRows, VectorSpace::nCols, mStart, nStart ); } template inline Foam::ConstMatrixBlock> Foam::Matrix::col ( const label m, const label mStart ) const { return ConstMatrixBlock ( *this, m, 1, mStart, 0 ); } template inline Foam::ConstMatrixBlock> Foam::Matrix::col ( const label m, const label mStart, const label nStart ) const { return ConstMatrixBlock ( *this, m, 1, mStart, nStart ); } template inline Foam::MatrixBlock> Foam::Matrix::block ( const label m, const label n, const label mStart, const label nStart ) { return MatrixBlock ( *this, m, n, mStart, nStart ); } template template inline Foam::MatrixBlock> Foam::Matrix::block(const label mStart, const label nStart) { return MatrixBlock ( *this, VectorSpace::mRows, VectorSpace::nCols, mStart, nStart ); } template inline Foam::MatrixBlock> Foam::Matrix::col(const label m, const label mStart) { return MatrixBlock ( *this, m, 1, mStart, 0 ); } template inline Foam::MatrixBlock> Foam::Matrix::col ( const label m, const label mStart, const label nStart ) { return MatrixBlock ( *this, m, 1, mStart, nStart ); } template void Foam::Matrix::shallowResize(const label m, const label n) { mRows_ = m; nCols_ = n; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template inline const Type& Foam::Matrix::operator() ( const label i, const label j ) const { checki(i); checkj(j); return v_[i*nCols_ + j]; } template inline Type& Foam::Matrix::operator() ( const label i, const label j ) { checki(i); checkj(j); return v_[i*nCols_ + j]; } template inline const Type* Foam::Matrix::operator[](const label i) const { checki(i); return v_ + i*nCols_; } template inline Type* Foam::Matrix::operator[](const label i) { checki(i); return v_ + i*nCols_; } // ************************************************************************* //