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 0ea0848047
commit 67a51b1fdd
29 changed files with 197 additions and 224 deletions

View File

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

View File

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

View File

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