From e18ac8ff506e95b5f04ca7ce24b31165645b10c8 Mon Sep 17 00:00:00 2001 From: Henry Weller <http://cfd.direct> Date: Sun, 6 Mar 2016 19:04:53 +0000 Subject: [PATCH] Matrix: Improved readability of the code --- src/OpenFOAM/matrices/Matrix/Matrix.C | 56 ++++++++++++------------- src/OpenFOAM/matrices/Matrix/Matrix.H | 2 +- src/OpenFOAM/matrices/Matrix/MatrixI.H | 22 +++++----- src/OpenFOAM/matrices/Matrix/MatrixIO.C | 14 +++---- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.C b/src/OpenFOAM/matrices/Matrix/Matrix.C index 3937f9cb1ed..d06cef41e62 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.C +++ b/src/OpenFOAM/matrices/Matrix/Matrix.C @@ -30,14 +30,14 @@ License template<class Form, class Type> void Foam::Matrix<Form, Type>::allocate() { - if (n_ && m_) + if (nRows_ && nCols_) { - v_ = new Type*[n_]; - v_[0] = new Type[n_*m_]; + v_ = new Type*[nRows_]; + v_[0] = new Type[nRows_*nCols_]; - for (label i=1; i<n_; i++) + for (label i=1; i<nRows_; i++) { - v_[i] = v_[i-1] + m_; + v_[i] = v_[i-1] + nCols_; } } } @@ -61,14 +61,14 @@ Foam::Matrix<Form, Type>::~Matrix() template<class Form, class Type> Foam::Matrix<Form, Type>::Matrix(const label n, const label m) : - n_(n), - m_(m), + nRows_(n), + nCols_(m), v_(NULL) { - if (n_ < 0 || m_ < 0) + if (nRows_ < 0 || nCols_ < 0) { FatalErrorInFunction - << "bad n, m " << n_ << ", " << m_ + << "bad n, m " << nRows_ << ", " << nCols_ << abort(FatalError); } @@ -79,14 +79,14 @@ Foam::Matrix<Form, Type>::Matrix(const label n, const label m) template<class Form, class Type> Foam::Matrix<Form, Type>::Matrix(const label n, const label m, const Type& a) : - n_(n), - m_(m), + nRows_(n), + nCols_(m), v_(NULL) { - if (n_ < 0 || m_ < 0) + if (nRows_ < 0 || nCols_ < 0) { FatalErrorInFunction - << "bad n, m " << n_ << ", " << m_ + << "bad n, m " << nRows_ << ", " << nCols_ << abort(FatalError); } @@ -96,7 +96,7 @@ Foam::Matrix<Form, Type>::Matrix(const label n, const label m, const Type& a) { Type* v = v_[0]; - label nm = n_*m_; + label nm = nRows_*nCols_; for (label i=0; i<nm; i++) { @@ -109,8 +109,8 @@ Foam::Matrix<Form, Type>::Matrix(const label n, const label m, const Type& a) template<class Form, class Type> Foam::Matrix<Form, Type>::Matrix(const Matrix<Form, Type>& a) : - n_(a.n_), - m_(a.m_), + nRows_(a.nRows_), + nCols_(a.nCols_), v_(NULL) { if (a.v_) @@ -119,7 +119,7 @@ Foam::Matrix<Form, Type>::Matrix(const Matrix<Form, Type>& a) Type* v = v_[0]; const Type* av = a.v_[0]; - label nm = n_*m_; + label nm = nRows_*nCols_; for (label i=0; i<nm; i++) { v[i] = av[i]; @@ -136,8 +136,8 @@ void Foam::Matrix<Form, Type>::clear() delete[] (v_[0]); delete[] v_; } - n_ = 0; - m_ = 0; + nRows_ = 0; + nCols_ = 0; v_ = NULL; } @@ -147,11 +147,11 @@ void Foam::Matrix<Form, Type>::transfer(Matrix<Form, Type>& a) { clear(); - n_ = a.n_; - a.n_ = 0; + nRows_ = a.nRows_; + a.nRows_ = 0; - m_ = a.m_; - a.m_ = 0; + nCols_ = a.nCols_; + a.nCols_ = 0; v_ = a.v_; a.v_ = NULL; @@ -185,7 +185,7 @@ void Foam::Matrix<Form, Type>::operator=(const Type& t) { Type* v = v_[0]; - label nm = n_*m_; + label nm = nRows_*nCols_; for (label i=0; i<nm; i++) { v[i] = t; @@ -204,11 +204,11 @@ void Foam::Matrix<Form, Type>::operator=(const Matrix<Form, Type>& a) << abort(FatalError); } - if (n_ != a.n_ || m_ != a.m_) + if (nRows_ != a.nRows_ || nCols_ != a.nCols_) { clear(); - n_ = a.n_; - m_ = a.m_; + nRows_ = a.nRows_; + nCols_ = a.nCols_; allocate(); } @@ -217,7 +217,7 @@ void Foam::Matrix<Form, Type>::operator=(const Matrix<Form, Type>& a) Type* v = v_[0]; const Type* av = a.v_[0]; - label nm = n_*m_; + label nm = nRows_*nCols_; for (label i=0; i<nm; i++) { v[i] = av[i]; diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H index 8455ac997f6..87652bdd6b0 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.H +++ b/src/OpenFOAM/matrices/Matrix/Matrix.H @@ -76,7 +76,7 @@ class Matrix // Private data //- Number of rows and columns in Matrix. - label n_, m_; + label nRows_, nCols_; //- Row pointers Type** __restrict__ v_; diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H index 613285c707d..5286b98f421 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixI.H +++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H @@ -28,8 +28,8 @@ License template<class Form, class Type> inline Foam::Matrix<Form, Type>::Matrix() : - n_(0), - m_(0), + nRows_(0), + nCols_(0), v_(NULL) {} @@ -55,37 +55,37 @@ inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null() template<class Form, class Type> inline Foam::label Foam::Matrix<Form, Type>::n() const { - return n_; + return nRows_; } template<class Form, class Type> inline Foam::label Foam::Matrix<Form, Type>::m() const { - return m_; + return nCols_; } template<class Form, class Type> inline Foam::label Foam::Matrix<Form, Type>::size() const { - return n_*m_; + return nRows_*nCols_; } template<class Form, class Type> inline void Foam::Matrix<Form, Type>::checki(const label i) const { - if (!n_) + if (!nRows_) { FatalErrorInFunction << "attempt to access element from zero sized row" << abort(FatalError); } - else if (i<0 || i>=n_) + else if (i<0 || i>=nRows_) { FatalErrorInFunction - << "index " << i << " out of range 0 ... " << n_-1 + << "index " << i << " out of range 0 ... " << nRows_-1 << abort(FatalError); } } @@ -94,16 +94,16 @@ inline void Foam::Matrix<Form, Type>::checki(const label i) const template<class Form, class Type> inline void Foam::Matrix<Form, Type>::checkj(const label j) const { - if (!m_) + if (!nCols_) { FatalErrorInFunction << "attempt to access element from zero sized column" << abort(FatalError); } - else if (j<0 || j>=m_) + else if (j<0 || j>=nCols_) { FatalErrorInFunction - << "index " << j << " out of range 0 ... " << m_-1 + << "index " << j << " out of range 0 ... " << nCols_-1 << abort(FatalError); } } diff --git a/src/OpenFOAM/matrices/Matrix/MatrixIO.C b/src/OpenFOAM/matrices/Matrix/MatrixIO.C index 8c52bdebc5d..60df6849371 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixIO.C +++ b/src/OpenFOAM/matrices/Matrix/MatrixIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,8 +34,8 @@ License template<class Form, class Type> Foam::Matrix<Form, Type>::Matrix(Istream& is) : - n_(0), - m_(0), + nRows_(0), + nCols_(0), v_(NULL) { operator>>(is, *this); @@ -59,10 +59,10 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Form, Type>& M) if (firstToken.isLabel()) { - M.n_ = firstToken.labelToken(); - M.m_ = readLabel(is); + M.nRows_ = firstToken.labelToken(); + M.nCols_ = readLabel(is); - label nm = M.n_*M.m_; + label nm = M.nRows_*M.nCols_; // Read list contents depending on data format if (is.format() == IOstream::ASCII || !contiguous<Type>()) @@ -151,7 +151,7 @@ Foam::Istream& Foam::operator>>(Istream& is, Matrix<Form, Type>& M) template<class Form, class Type> Foam::Ostream& Foam::operator<<(Ostream& os, const Matrix<Form, Type>& M) { - label nm = M.n_*M.m_; + label nm = M.nRows_*M.nCols_; os << M.n() << token::SPACE << M.m(); -- GitLab