Matrix: Added (i, j) addressing to allow support for addressing blocks of the matrix

This change brings OpenFOAM into line with the standard matrix
addressing in other C++ libraries for better interoperability.
This commit is contained in:
Henry Weller
2016-03-20 19:44:29 +00:00
parent 767ffc3c7b
commit c13421b10a
29 changed files with 197 additions and 224 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -36,15 +36,15 @@ int main(int argc, char *argv[])
{ {
SquareMatrix<scalar> hmm(3); SquareMatrix<scalar> hmm(3);
hmm[0][0] = -3.0; hmm(0, 0) = -3.0;
hmm[0][1] = 10.0; hmm(0, 1) = 10.0;
hmm[0][2] = -4.0; hmm(0, 2) = -4.0;
hmm[1][0] = 2.0; hmm(1, 0) = 2.0;
hmm[1][1] = 3.0; hmm(1, 1) = 3.0;
hmm[1][2] = 10.0; hmm(1, 2) = 10.0;
hmm[2][0] = 2.0; hmm(2, 0) = 2.0;
hmm[2][1] = 6.0; hmm(2, 1) = 6.0;
hmm[2][2] = 1.0; hmm(2, 2) = 1.0;
//Info<< hmm << endl << hmm - 2.0*(-hmm) << endl; //Info<< hmm << endl << hmm - 2.0*(-hmm) << endl;
Info<< max(hmm) << endl; Info<< max(hmm) << endl;
@ -106,15 +106,15 @@ int main(int argc, char *argv[])
{ {
scalarSquareMatrix squareMatrix(3, 3, 0); scalarSquareMatrix squareMatrix(3, 3, 0);
squareMatrix[0][0] = 4; squareMatrix(0, 0) = 4;
squareMatrix[0][1] = 12; squareMatrix(0, 1) = 12;
squareMatrix[0][2] = -16; squareMatrix(0, 2) = -16;
squareMatrix[1][0] = 12; squareMatrix(1, 0) = 12;
squareMatrix[1][1] = 37; squareMatrix(1, 1) = 37;
squareMatrix[1][2] = -43; squareMatrix(1, 2) = -43;
squareMatrix[2][0] = -16; squareMatrix(2, 0) = -16;
squareMatrix[2][1] = -43; squareMatrix(2, 1) = -43;
squareMatrix[2][2] = 98; squareMatrix(2, 2) = 98;
const scalarSquareMatrix squareMatrixCopy = squareMatrix; const scalarSquareMatrix squareMatrixCopy = squareMatrix;
Info<< nl << "Square Matrix = " << squareMatrix << endl; Info<< nl << "Square Matrix = " << squareMatrix << endl;
@ -131,6 +131,22 @@ int main(int argc, char *argv[])
Info<< "det = " << detDecomposed(squareMatrix, sign) << endl; Info<< "det = " << detDecomposed(squareMatrix, sign) << endl;
} }
{
scalarSquareMatrix squareMatrix(3000, 3000, 1);
for(label i=0; i<squareMatrix.n(); i++)
{
squareMatrix(i, i) = 10;
}
scalarField rhs(squareMatrix.n(), 0);
rhs[0] = 1;
rhs[1] = 2;
rhs[2] = 3;
LUsolve(squareMatrix, rhs);
}
Info<< "\nEnd\n" << endl; Info<< "\nEnd\n" << endl;
return 0; return 0;

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -75,25 +75,25 @@ public:
dfdx[2] = (2.0/sqr(x))*y[2]; dfdx[2] = (2.0/sqr(x))*y[2];
dfdx[3] = (3.0/sqr(x))*y[3]; dfdx[3] = (3.0/sqr(x))*y[3];
dfdy[0][0] = 0.0; dfdy(0, 0) = 0.0;
dfdy[0][1] = -1.0; dfdy(0, 1) = -1.0;
dfdy[0][2] = 0.0; dfdy(0, 2) = 0.0;
dfdy[0][3] = 0.0; dfdy(0, 3) = 0.0;
dfdy[1][0] = 1.0; dfdy(1, 0) = 1.0;
dfdy[1][1] = -1.0/x; dfdy(1, 1) = -1.0/x;
dfdy[1][2] = 0.0; dfdy(1, 2) = 0.0;
dfdy[1][3] = 0.0; dfdy(1, 3) = 0.0;
dfdy[2][0] = 0.0; dfdy(2, 0) = 0.0;
dfdy[2][1] = 1.0; dfdy(2, 1) = 1.0;
dfdy[2][2] = -2.0/x; dfdy(2, 2) = -2.0/x;
dfdy[2][3] = 0.0; dfdy(2, 3) = 0.0;
dfdy[3][0] = 0.0; dfdy(3, 0) = 0.0;
dfdy[3][1] = 0.0; dfdy(3, 1) = 0.0;
dfdy[3][2] = 1.0; dfdy(3, 2) = 1.0;
dfdy[3][3] = -3.0/x; dfdy(3, 3) = -3.0/x;
} }
}; };

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -35,15 +35,15 @@ int main(int argc, char *argv[])
{ {
simpleMatrix<vector> hmm(3); simpleMatrix<vector> hmm(3);
hmm[0][0] = -3.0; hmm(0, 0) = -3.0;
hmm[0][1] = 10.0; hmm(0, 1) = 10.0;
hmm[0][2] = -4.0; hmm(0, 2) = -4.0;
hmm[1][0] = 2.0; hmm(1, 0) = 2.0;
hmm[1][1] = 3.0; hmm(1, 1) = 3.0;
hmm[1][2] = 10.0; hmm(1, 2) = 10.0;
hmm[2][0] = 2.0; hmm(2, 0) = 2.0;
hmm[2][1] = 6.0; hmm(2, 1) = 6.0;
hmm[2][2] = 1.0; hmm(2, 2) = 1.0;
hmm.source()[0] = vector(2.0, 1.0, 3.0); hmm.source()[0] = vector(2.0, 1.0, 3.0);
hmm.source()[1] = vector(1.0, 4.0, 3.0); hmm.source()[1] = vector(1.0, 4.0, 3.0);

View File

@ -312,11 +312,11 @@ triSurfacePointScalarField calcCurvature
scalar x = edgeVectors[i] & faceCoordSys[0]; scalar x = edgeVectors[i] & faceCoordSys[0];
scalar y = edgeVectors[i] & faceCoordSys[1]; scalar y = edgeVectors[i] & faceCoordSys[1];
T[0][0] += sqr(x); T(0, 0) += sqr(x);
T[1][0] += x*y; T(1, 0) += x*y;
T[1][1] += sqr(x) + sqr(y); T(1, 1) += sqr(x) + sqr(y);
T[2][1] += x*y; T(2, 1) += x*y;
T[2][2] += sqr(y); T(2, 2) += sqr(y);
scalar dndx = normalDifferences[i] & faceCoordSys[0]; scalar dndx = normalDifferences[i] & faceCoordSys[0];
scalar dndy = normalDifferences[i] & faceCoordSys[1]; scalar dndy = normalDifferences[i] & faceCoordSys[1];

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -67,10 +67,10 @@ Foam::scalar Foam::EulerSI::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/dx; a_(i, i) += 1.0/dx;
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -81,10 +81,10 @@ Foam::scalar Foam::Rosenbrock12::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/(gamma*dx); a_(i, i) += 1.0/(gamma*dx);
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -94,10 +94,10 @@ Foam::scalar Foam::Rosenbrock23::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/(gamma*dx); a_(i, i) += 1.0/(gamma*dx);
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -139,10 +139,10 @@ Foam::scalar Foam::Rosenbrock34::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/(gamma*dx); a_(i, i) += 1.0/(gamma*dx);
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -46,9 +46,9 @@ void Foam::SIBS::SIMPR
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a[i][j] = -h*dfdy[i][j]; a(i, j) = -h*dfdy(i, j);
} }
++a[i][i]; ++a(i, i);
} }
labelList pivotIndices(n_); labelList pivotIndices(n_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -51,7 +51,7 @@ void Foam::SIBS::polyExtrapolate
{ {
for (label j=0; j<n; j++) for (label j=0; j<n; j++)
{ {
d[j][0] = yest[j]; d(j, 0) = yest[j];
} }
} }
else else

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -85,10 +85,10 @@ Foam::scalar Foam::rodas23::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/(gamma*dx); a_(i, i) += 1.0/(gamma*dx);
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -108,10 +108,10 @@ Foam::scalar Foam::rodas34::solve
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/(gamma*dx); a_(i, i) += 1.0/(gamma*dx);
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -92,7 +92,7 @@ Foam::seulex::seulex(const ODESystem& ode, const dictionary& dict)
for (int l=0; l<k; l++) for (int l=0; l<k; l++)
{ {
scalar ratio = scalar(nSeq_[k])/nSeq_[l]; scalar ratio = scalar(nSeq_[k])/nSeq_[l];
coeff_[k][l] = 1.0/(ratio - 1.0); coeff_(k, l) = 1.0/(ratio - 1.0);
} }
} }
} }
@ -117,10 +117,10 @@ bool Foam::seulex::seul
{ {
for (label j=0; j<n_; j++) for (label j=0; j<n_; j++)
{ {
a_[i][j] = -dfdy_[i][j]; a_(i, j) = -dfdy_(i, j);
} }
a_[i][i] += 1.0/dx; a_(i, i) += 1.0/dx;
} }
LUDecompose(a_, pivotIndices_); LUDecompose(a_, pivotIndices_);
@ -192,13 +192,13 @@ void Foam::seulex::extrapolate
for (label i=0; i<n_; i++) for (label i=0; i<n_; i++)
{ {
table[j-1][i] = table[j-1][i] =
table[j][i] + coeff_[k][j]*(table[j][i] - table[j-1][i]); table(j, i) + coeff_(k, j)*(table(j, i) - table[j-1][i]);
} }
} }
for (int i=0; i<n_; i++) for (int i=0; i<n_; i++)
{ {
y[i] = table[0][i] + coeff_[k][0]*(table[0][i] - y[i]); y[i] = table(0, i) + coeff_(k, 0)*(table(0, i) - y[i]);
} }
} }
@ -288,7 +288,7 @@ void Foam::seulex::solve
forAll(scale_, i) forAll(scale_, i)
{ {
scale_[i] = absTol_[i] + relTol_[i]*mag(y0_[i]); scale_[i] = absTol_[i] + relTol_[i]*mag(y0_[i]);
err += sqr((y[i] - table_[0][i])/scale_[i]); err += sqr((y[i] - table_(0, i))/scale_[i]);
} }
err = sqrt(err/n_); err = sqrt(err/n_);
if (err > 1.0/SMALL || (k > 1 && err >= errOld)) if (err > 1.0/SMALL || (k > 1 && err >= errOld))

View File

@ -42,7 +42,7 @@ Foam::DiagonalMatrix<Type>::DiagonalMatrix(const Matrix<Form, Type>& a)
{ {
forAll(*this, i) forAll(*this, i)
{ {
this->operator[](i) = a[i][i]; this->operator[](i) = a(i, i);
} }
} }

View File

@ -156,7 +156,7 @@ Form Foam::Matrix<Form, Type>::T() const
{ {
for (label j=0; j<n(); j++) for (label j=0; j<n(); j++)
{ {
At[j][i] = A[i][j]; At(j, i) = A(i, j);
} }
} }
@ -238,7 +238,7 @@ const Type& Foam::max(const Matrix<Form, Type>& a)
<< abort(FatalError); << abort(FatalError);
// Return in error to keep compiler happy // Return in error to keep compiler happy
return a[0][0]; return a(0, 0);
} }
} }
@ -270,7 +270,7 @@ const Type& Foam::min(const Matrix<Form, Type>& a)
<< abort(FatalError); << abort(FatalError);
// Return in error to keep compiler happy // Return in error to keep compiler happy
return a[0][0]; return a(0, 0);
} }
} }
@ -411,7 +411,7 @@ Form Foam::operator*(const Matrix<Form, Type>& a, const Matrix<Form, Type>& b)
{ {
for (label l = 0; l < b.m(); l++) for (label l = 0; l < b.m(); l++)
{ {
ab[i][j] += a[i][l]*b[l][j]; ab(i, j) += a(i, l)*b(l, j);
} }
} }
} }

View File

@ -136,7 +136,7 @@ inline const Type& Foam::Matrix<Form, Type>::operator()
) const ) const
{ {
checki(i); checki(i);
checki(j); checkj(j);
return v_[i*nCols_ + j]; return v_[i*nCols_ + j];
} }
@ -149,7 +149,7 @@ inline Type& Foam::Matrix<Form, Type>::operator()
) )
{ {
checki(i); checki(i);
checki(j); checkj(j);
return v_[i*nCols_ + j]; return v_[i*nCols_ + j];
} }

View File

@ -39,7 +39,7 @@ Foam::scalar Foam::detDecomposed
for (label i = 0; i < matrix.m(); ++i) for (label i = 0; i < matrix.m(); ++i)
{ {
diagProduct *= matrix[i][i]; diagProduct *= matrix(i, i);
} }
return sign*diagProduct; return sign*diagProduct;

View File

@ -37,7 +37,7 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
for (label i = 0; i < matrix.m(); ++i) for (label i = 0; i < matrix.m(); ++i)
{ {
inv[i][i] = 1.0/matrix[i][i]; inv(i, i) = 1.0/matrix(i, i);
for (label j = 0; j < i; ++j) for (label j = 0; j < i; ++j)
{ {
@ -45,10 +45,10 @@ Foam::SymmetricSquareMatrix<Type> Foam::invDecomposed
for (label k = j; k < i; k++) for (label k = j; k < i; k++)
{ {
sum -= matrix[i][k]*inv[k][j]; sum -= matrix(i, k)*inv(k, j);
} }
inv[i][j] = sum/matrix[i][i]; inv(i, j) = sum/matrix(i, i);
} }
} }
@ -77,7 +77,7 @@ Foam::scalar Foam::detDecomposed(const SymmetricSquareMatrix<Type>& matrix)
for (label i = 0; i < matrix.m(); ++i) for (label i = 0; i < matrix.m(); ++i)
{ {
diagProduct *= matrix[i][i]; diagProduct *= matrix(i, i);
} }
return sqr(diagProduct); return sqr(diagProduct);

View File

@ -76,13 +76,6 @@ public:
//- Clone //- Clone
inline autoPtr<SymmetricSquareMatrix<Type>> clone() const; inline autoPtr<SymmetricSquareMatrix<Type>> clone() const;
//- Return subscript-checked row of Matrix.
inline Type& operator()(const label r, const label c);
//- Return subscript-checked row of constant Matrix.
inline const Type& operator()(const label r, const label c) const;
}; };

View File

@ -94,40 +94,4 @@ Foam::SymmetricSquareMatrix<Type>::clone() const
} }
template<class Type>
inline Type& Foam::SymmetricSquareMatrix<Type>::operator()
(
const label r,
const label c
)
{
if (r > c)
{
return this->operator[](r)[c];
}
else
{
return this->operator[](c)[r];
}
}
template<class Type>
inline const Type& Foam::SymmetricSquareMatrix<Type>::operator()
(
const label r,
const label c
) const
{
if (r > c)
{
return this->operator[](r)[c];
}
else
{
return this->operator[](c)[r];
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -60,40 +60,40 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
{ {
for (label k = i; k < Um; k++) for (label k = i; k < Um; k++)
{ {
scale += mag(U_[k][i]); scale += mag(U_(k, i));
} }
if (scale != 0) if (scale != 0)
{ {
for (label k = i; k < Um; k++) for (label k = i; k < Um; k++)
{ {
U_[k][i] /= scale; U_(k, i) /= scale;
s += U_[k][i]*U_[k][i]; s += U_(k, i)*U_(k, i);
} }
scalar f = U_[i][i]; scalar f = U_(i, i);
g = -sign(Foam::sqrt(s), f); g = -sign(Foam::sqrt(s), f);
scalar h = f*g - s; scalar h = f*g - s;
U_[i][i] = f - g; U_(i, i) = f - g;
for (label j = l-1; j < Un; j++) for (label j = l-1; j < Un; j++)
{ {
s = 0; s = 0;
for (label k = i; k < Um; k++) for (label k = i; k < Um; k++)
{ {
s += U_[k][i]*U_[k][j]; s += U_(k, i)*U_(k, j);
} }
f = s/h; f = s/h;
for (label k = i; k < A.m(); k++) for (label k = i; k < A.m(); k++)
{ {
U_[k][j] += f*U_[k][i]; U_(k, j) += f*U_(k, i);
} }
} }
for (label k = i; k < Um; k++) for (label k = i; k < Um; k++)
{ {
U_[k][i] *= scale; U_(k, i) *= scale;
} }
} }
} }
@ -106,15 +106,15 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
{ {
for (label k = l-1; k < Un; k++) for (label k = l-1; k < Un; k++)
{ {
scale += mag(U_[i][k]); scale += mag(U_(i, k));
} }
if (scale != 0) if (scale != 0)
{ {
for (label k=l-1; k < Un; k++) for (label k=l-1; k < Un; k++)
{ {
U_[i][k] /= scale; U_(i, k) /= scale;
s += U_[i][k]*U_[i][k]; s += U_(i, k)*U_(i, k);
} }
scalar f = U_[i][l-1]; scalar f = U_[i][l-1];
@ -124,7 +124,7 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
for (label k = l-1; k < Un; k++) for (label k = l-1; k < Un; k++)
{ {
rv1[k] = U_[i][k]/h; rv1[k] = U_(i, k)/h;
} }
for (label j = l-1; j < Um; j++) for (label j = l-1; j < Um; j++)
@ -132,17 +132,17 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
s = 0; s = 0;
for (label k = l-1; k < Un; k++) for (label k = l-1; k < Un; k++)
{ {
s += U_[j][k]*U_[i][k]; s += U_(j, k)*U_(i, k);
} }
for (label k = l-1; k < Un; k++) for (label k = l-1; k < Un; k++)
{ {
U_[j][k] += s*rv1[k]; U_(j, k) += s*rv1[k];
} }
} }
for (label k = l-1; k < Un; k++) for (label k = l-1; k < Un; k++)
{ {
U_[i][k] *= scale; U_(i, k) *= scale;
} }
} }
} }
@ -158,7 +158,7 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
{ {
for (label j = l; j < Un; j++) for (label j = l; j < Un; j++)
{ {
V_[j][i] = (U_[i][j]/U_[i][l])/g; V_(j, i) = (U_(i, j)/U_(i, l))/g;
} }
for (label j=l; j < Un; j++) for (label j=l; j < Un; j++)
@ -166,23 +166,23 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
s = 0; s = 0;
for (label k = l; k < Un; k++) for (label k = l; k < Un; k++)
{ {
s += U_[i][k]*V_[k][j]; s += U_(i, k)*V_(k, j);
} }
for (label k = l; k < Un; k++) for (label k = l; k < Un; k++)
{ {
V_[k][j] += s*V_[k][i]; V_(k, j) += s*V_(k, i);
} }
} }
} }
for (label j = l; j < Un;j++) for (label j = l; j < Un;j++)
{ {
V_[i][j] = V_[j][i] = 0.0; V_(i, j) = V_(j, i) = 0.0;
} }
} }
V_[i][i] = 1; V_(i, i) = 1;
g = rv1[i]; g = rv1[i];
l = i; l = i;
} }
@ -194,7 +194,7 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
for (label j = l; j < Un; j++) for (label j = l; j < Un; j++)
{ {
U_[i][j] = 0.0; U_(i, j) = 0.0;
} }
if (g != 0) if (g != 0)
@ -206,31 +206,31 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
s = 0; s = 0;
for (label k = l; k < Um; k++) for (label k = l; k < Um; k++)
{ {
s += U_[k][i]*U_[k][j]; s += U_(k, i)*U_(k, j);
} }
scalar f = (s/U_[i][i])*g; scalar f = (s/U_(i, i))*g;
for (label k = i; k < Um; k++) for (label k = i; k < Um; k++)
{ {
U_[k][j] += f*U_[k][i]; U_(k, j) += f*U_(k, i);
} }
} }
for (label j = i; j < Um; j++) for (label j = i; j < Um; j++)
{ {
U_[j][i] *= g; U_(j, i) *= g;
} }
} }
else else
{ {
for (label j = i; j < Um; j++) for (label j = i; j < Um; j++)
{ {
U_[j][i] = 0.0; U_(j, i) = 0.0;
} }
} }
++U_[i][i]; ++U_(i, i);
} }
for (label k = Un-1; k >= 0; k--) for (label k = Un-1; k >= 0; k--)
@ -272,9 +272,9 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
for (label j = 0; j < Um; j++) for (label j = 0; j < Um; j++)
{ {
scalar y = U_[j][mn]; scalar y = U_[j][mn];
scalar z = U_[j][i]; scalar z = U_(j, i);
U_[j][mn] = y*c + z*s; U_[j][mn] = y*c + z*s;
U_[j][i] = z*c - y*s; U_(j, i) = z*c - y*s;
} }
} }
} }
@ -287,7 +287,7 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
{ {
S_[k] = -z; S_[k] = -z;
for (label j = 0; j < Un; j++) V_[j][k] = -V_[j][k]; for (label j = 0; j < Un; j++) V_(j, k) = -V_(j, k);
} }
break; break;
} }
@ -383,7 +383,7 @@ Foam::SVD::SVD(const scalarRectangularMatrix& A, const scalar minCondition)
{ {
for (label j = 0; j < A.n(); j++) for (label j = 0; j < A.n(); j++)
{ {
diff = mag(A[i][j] - SVDA[i][j]); diff = mag(A(i, j) - SVDA(i, j));
if (diff > maxDiff) maxDiff = diff; if (diff > maxDiff) maxDiff = diff;
} }
} }

View File

@ -84,7 +84,7 @@ void Foam::LUDecompose
scalar sum = matrixi[j]; scalar sum = matrixi[j];
for (label k=0; k<i; k++) for (label k=0; k<i; k++)
{ {
sum -= matrixi[k]*matrix[k][j]; sum -= matrixi[k]*matrix(k, j);
} }
matrixi[j] = sum; matrixi[j] = sum;
} }
@ -99,7 +99,7 @@ void Foam::LUDecompose
for (label k=0; k<j; k++) for (label k=0; k<j; k++)
{ {
sum -= matrixi[k]*matrix[k][j]; sum -= matrixi[k]*matrix(k, j);
} }
matrixi[j] = sum; matrixi[j] = sum;
@ -138,7 +138,7 @@ void Foam::LUDecompose
for (label i=j+1; i<m; i++) for (label i=j+1; i<m; i++)
{ {
matrix[i][j] *= rDiag; matrix(i, j) *= rDiag;
} }
} }
} }
@ -155,7 +155,7 @@ void Foam::LUDecompose(scalarSymmetricSquareMatrix& matrix)
{ {
for (label k = j + 1; k < size; k++) for (label k = j + 1; k < size; k++)
{ {
matrix[j][k] = 0.0; matrix(j, k) = 0.0;
} }
} }
@ -169,18 +169,18 @@ void Foam::LUDecompose(scalarSymmetricSquareMatrix& matrix)
for (label i = 0; i < k; i++) for (label i = 0; i < k; i++)
{ {
s += matrix[i][k]*matrix[i][j]; s += matrix(i, k)*matrix(i, j);
} }
s = (matrix[j][k] - s)/matrix[k][k]; s = (matrix(j, k) - s)/matrix(k, k);
matrix[k][j] = s; matrix(k, j) = s;
matrix[j][k] = s; matrix(j, k) = s;
d += sqr(s); d += sqr(s);
} }
d = matrix[j][j] - d; d = matrix(j, j) - d;
if (d < 0.0) if (d < 0.0)
{ {
@ -190,7 +190,7 @@ void Foam::LUDecompose(scalarSymmetricSquareMatrix& matrix)
<< abort(FatalError); << abort(FatalError);
} }
matrix[j][j] = sqrt(d); matrix(j, j) = sqrt(d);
} }
} }
@ -232,9 +232,9 @@ void Foam::multiply
scalar ab = 0; scalar ab = 0;
for (label j = 0; j < A.n(); j++) for (label j = 0; j < A.n(); j++)
{ {
ab += A[i][j]*B[j][l]; ab += A(i, j)*B(j, l);
} }
ans[i][g] += C[l][g] * ab; ans(i, g) += C(l, g) * ab;
} }
} }
} }
@ -273,7 +273,7 @@ void Foam::multiply
{ {
for (label l = 0; l < C.m(); l++) for (label l = 0; l < C.m(); l++)
{ {
ans[i][g] += C[l][g] * A[i][l]*B[l]; ans(i, g) += C(l, g) * A(i, l)*B[l];
} }
} }
} }

View File

@ -47,7 +47,7 @@ void Foam::solve
// Swap entries around to find a good pivot // Swap entries around to find a good pivot
for (label j=i+1; j<m; j++) for (label j=i+1; j<m; j++)
{ {
if (mag(tmpMatrix[j][i]) > largestCoeff) if (mag(tmpMatrix(j, i)) > largestCoeff)
{ {
iMax = j; iMax = j;
largestCoeff = mag(tmpMatrix[iMax][i]); largestCoeff = mag(tmpMatrix[iMax][i]);
@ -58,13 +58,13 @@ void Foam::solve
{ {
for (label k=i; k<m; k++) for (label k=i; k<m; k++)
{ {
Swap(tmpMatrix[i][k], tmpMatrix[iMax][k]); Swap(tmpMatrix(i, k), tmpMatrix[iMax][k]);
} }
Swap(sourceSol[i], sourceSol[iMax]); Swap(sourceSol[i], sourceSol[iMax]);
} }
// Check that the system of equations isn't singular // Check that the system of equations isn't singular
if (mag(tmpMatrix[i][i]) < 1e-20) if (mag(tmpMatrix(i, i)) < 1e-20)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Singular Matrix" << "Singular Matrix"
@ -74,12 +74,12 @@ void Foam::solve
// Reduce to upper triangular form // Reduce to upper triangular form
for (label j=i+1; j<m; j++) for (label j=i+1; j<m; j++)
{ {
sourceSol[j] -= sourceSol[i]*(tmpMatrix[j][i]/tmpMatrix[i][i]); sourceSol[j] -= sourceSol[i]*(tmpMatrix(j, i)/tmpMatrix(i, i));
for (label k=m-1; k>=i; k--) for (label k=m-1; k>=i; k--)
{ {
tmpMatrix[j][k] -= tmpMatrix(j, k) -=
tmpMatrix[i][k]*tmpMatrix[j][i]/tmpMatrix[i][i]; tmpMatrix(i, k)*tmpMatrix(j, i)/tmpMatrix(i, i);
} }
} }
} }
@ -91,10 +91,10 @@ void Foam::solve
for (label k=j+1; k<m; k++) for (label k=j+1; k<m; k++)
{ {
ntempvec += tmpMatrix[j][k]*sourceSol[k]; ntempvec += tmpMatrix(j, k)*sourceSol[k];
} }
sourceSol[j] = (sourceSol[j] - ntempvec)/tmpMatrix[j][j]; sourceSol[j] = (sourceSol[j] - ntempvec)/tmpMatrix(j, j);
} }
} }
@ -257,7 +257,7 @@ void Foam::multiply
{ {
for (label l = 0; l < B.m(); l++) for (label l = 0; l < B.m(); l++)
{ {
ans[i][j] += A[i][l]*B[l][j]; ans(i, j) += A(i, l)*B(l, j);
} }
} }
} }

View File

@ -122,8 +122,8 @@ void Foam::CentredFitSnGradData<Polynomial>::calcFit
// Additional weighting for constant and linear terms // Additional weighting for constant and linear terms
for (label i = 0; i < B.m(); i++) for (label i = 0; i < B.m(); i++)
{ {
B[i][0] *= wts[0]; B(i, 0) *= wts[0];
B[i][1] *= wts[0]; B(i, 1) *= wts[0];
} }
// Set the fit // Set the fit
@ -137,14 +137,14 @@ void Foam::CentredFitSnGradData<Polynomial>::calcFit
for (label i=0; i<stencilSize; i++) for (label i=0; i<stencilSize; i++)
{ {
coeffsi[i] = wts[1]*wts[i]*svd.VSinvUt()[1][i]/scale; coeffsi[i] = wts[1]*wts[i]*svd.VSinvUt()(1, i)/scale;
} }
goodFit = goodFit =
( (
mag(wts[0]*wts[0]*svd.VSinvUt()[0][0] - wLin) mag(wts[0]*wts[0]*svd.VSinvUt()(0, 0) - wLin)
< this->linearLimitFactor()*wLin) < this->linearLimitFactor()*wLin)
&& (mag(wts[0]*wts[1]*svd.VSinvUt()[0][1] - (1 - wLin) && (mag(wts[0]*wts[1]*svd.VSinvUt()(0, 1) - (1 - wLin)
) < this->linearLimitFactor()*(1 - wLin)) ) < this->linearLimitFactor()*(1 - wLin))
&& coeffsi[0] < 0 && coeffsi[1] > 0 && coeffsi[0] < 0 && coeffsi[1] > 0
&& mag(coeffsi[0] + deltaCoeff) < 0.5*deltaCoeff && mag(coeffsi[0] + deltaCoeff) < 0.5*deltaCoeff
@ -163,10 +163,10 @@ void Foam::CentredFitSnGradData<Polynomial>::calcFit
<< " deltaCoeff " << deltaCoeff << nl << " deltaCoeff " << deltaCoeff << nl
<< " sing vals " << svd.S() << nl << " sing vals " << svd.S() << nl
<< "Components of goodFit:\n" << "Components of goodFit:\n"
<< " wts[0]*wts[0]*svd.VSinvUt()[0][0] = " << " wts[0]*wts[0]*svd.VSinvUt()(0, 0) = "
<< wts[0]*wts[0]*svd.VSinvUt()[0][0] << nl << wts[0]*wts[0]*svd.VSinvUt()(0, 0) << nl
<< " wts[0]*wts[1]*svd.VSinvUt()[0][1] = " << " wts[0]*wts[1]*svd.VSinvUt()(0, 1) = "
<< wts[0]*wts[1]*svd.VSinvUt()[0][1] << wts[0]*wts[1]*svd.VSinvUt()(0, 1)
<< " dim = " << this->dim() << endl; << " dim = " << this->dim() << endl;
wts[0] *= 10; wts[0] *= 10;
@ -174,14 +174,14 @@ void Foam::CentredFitSnGradData<Polynomial>::calcFit
for (label j = 0; j < B.n(); j++) for (label j = 0; j < B.n(); j++)
{ {
B[0][j] *= 10; B(0, j) *= 10;
B[1][j] *= 10; B(1, j) *= 10;
} }
for (label i = 0; i < B.m(); i++) for (label i = 0; i < B.m(); i++)
{ {
B[i][0] *= 10; B(i, 0) *= 10;
B[i][1] *= 10; B(i, 1) *= 10;
} }
} }
} }

View File

@ -196,8 +196,8 @@ void Foam::FitData<FitDataType, ExtendedStencil, Polynomial>::calcFit
// Additional weighting for constant and linear terms // Additional weighting for constant and linear terms
for (label i = 0; i < B.m(); i++) for (label i = 0; i < B.m(); i++)
{ {
B[i][0] *= wts[0]; B(i, 0) *= wts[0];
B[i][1] *= wts[0]; B(i, 1) *= wts[0];
} }
// Set the fit // Set the fit
@ -214,7 +214,7 @@ void Foam::FitData<FitDataType, ExtendedStencil, Polynomial>::calcFit
for (label i=0; i<stencilSize; i++) for (label i=0; i<stencilSize; i++)
{ {
coeffsi[i] = wts[0]*wts[i]*svd.VSinvUt()[0][i]; coeffsi[i] = wts[0]*wts[i]*svd.VSinvUt()(0, i);
if (mag(coeffsi[i]) > maxCoeff) if (mag(coeffsi[i]) > maxCoeff)
{ {
maxCoeff = mag(coeffsi[i]); maxCoeff = mag(coeffsi[i]);
@ -269,14 +269,14 @@ void Foam::FitData<FitDataType, ExtendedStencil, Polynomial>::calcFit
for (label j = 0; j < B.n(); j++) for (label j = 0; j < B.n(); j++)
{ {
B[0][j] *= 10; B(0, j) *= 10;
B[1][j] *= 10; B(1, j) *= 10;
} }
for (label i = 0; i < B.m(); i++) for (label i = 0; i < B.m(); i++)
{ {
B[i][0] *= 10; B(i, 0) *= 10;
B[i][1] *= 10; B(i, 1) *= 10;
} }
} }
} }

View File

@ -341,7 +341,7 @@ void Foam::chemistryModel<CompType, ThermoType>::jacobian
{ {
for (label j=0; j<nEqns(); j++) for (label j=0; j<nEqns(); j++)
{ {
dfdc[i][j] = 0.0; dfdc(i, j) = 0.0;
} }
} }

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -151,7 +151,7 @@ void Foam::EulerImplicit<ChemistryModel>::solve
scalar d = 0; scalar d = 0;
for (label j=0; j<nSpecie; j++) for (label j=0; j<nSpecie; j++)
{ {
d -= RR[i][j]*c[j]; d -= RR(i, j)*c[j];
} }
if (d < -SMALL) if (d < -SMALL)
@ -172,7 +172,7 @@ void Foam::EulerImplicit<ChemistryModel>::solve
// Add the diagonal and source contributions from the time-derivative // Add the diagonal and source contributions from the time-derivative
for (label i=0; i<nSpecie; i++) for (label i=0; i<nSpecie; i++)
{ {
RR[i][i] += 1.0/deltaT; RR(i, i) += 1.0/deltaT;
RR.source()[i] = c[i]/deltaT; RR.source()[i] = c[i]/deltaT;
} }

View File

@ -209,12 +209,12 @@ void Foam::radiation::viewFactor::initialise()
scalar sumF = 0.0; scalar sumF = 0.0;
for (label j=0; j<totalNCoarseFaces_; j++) for (label j=0; j<totalNCoarseFaces_; j++)
{ {
sumF += Fmatrix_()[i][j]; sumF += Fmatrix_()(i, j);
} }
scalar delta = sumF - 1.0; scalar delta = sumF - 1.0;
for (label j=0; j<totalNCoarseFaces_; j++) for (label j=0; j<totalNCoarseFaces_; j++)
{ {
Fmatrix_()[i][j] *= (1.0 - delta/(sumF + 0.001)); Fmatrix_()(i, j) *= (1.0 - delta/(sumF + 0.001));
} }
} }
} }
@ -541,13 +541,13 @@ void Foam::radiation::viewFactor::calculate()
if (i==j) if (i==j)
{ {
C[i][j] = invEj - (invEj - 1.0)*Fmatrix_()[i][j]; C(i, j) = invEj - (invEj - 1.0)*Fmatrix_()(i, j);
q[i] += (Fmatrix_()[i][j] - 1.0)*sigmaT4 - QrExt[j]; q[i] += (Fmatrix_()(i, j) - 1.0)*sigmaT4 - QrExt[j];
} }
else else
{ {
C[i][j] = (1.0 - invEj)*Fmatrix_()[i][j]; C(i, j) = (1.0 - invEj)*Fmatrix_()(i, j);
q[i] += Fmatrix_()[i][j]*sigmaT4; q[i] += Fmatrix_()(i, j)*sigmaT4;
} }
} }
@ -570,11 +570,11 @@ void Foam::radiation::viewFactor::calculate()
scalar invEj = 1.0/E[j]; scalar invEj = 1.0/E[j];
if (i==j) if (i==j)
{ {
CLU_()[i][j] = invEj-(invEj-1.0)*Fmatrix_()[i][j]; CLU_()(i, j) = invEj-(invEj-1.0)*Fmatrix_()(i, j);
} }
else else
{ {
CLU_()[i][j] = (1.0 - invEj)*Fmatrix_()[i][j]; CLU_()(i, j) = (1.0 - invEj)*Fmatrix_()(i, j);
} }
} }
} }
@ -598,11 +598,11 @@ void Foam::radiation::viewFactor::calculate()
if (i==j) if (i==j)
{ {
q[i] += (Fmatrix_()[i][j] - 1.0)*sigmaT4 - QrExt[j]; q[i] += (Fmatrix_()(i, j) - 1.0)*sigmaT4 - QrExt[j];
} }
else else
{ {
q[i] += Fmatrix_()[i][j]*sigmaT4; q[i] += Fmatrix_()(i, j)*sigmaT4;
} }
} }
} }

View File

@ -363,7 +363,7 @@ jacobian
{ {
for (label j=0; j<nEqns(); j++) for (label j=0; j<nEqns(); j++)
{ {
dfdc[i][j] = 0.0; dfdc(i, j) = 0.0;
} }
} }