mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Matrix: Improved readability of the code
This commit is contained in:
@ -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];
|
||||
|
||||
@ -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_;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user