Commit 55253a89 authored by laurence's avatar laurence
Browse files

ENH: Update Test-Matrix.C to check solutions for symmetric square matrices

parent 7db513e3
......@@ -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-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,6 +25,7 @@ License
#include "scalarMatrices.H"
#include "vector.H"
#include "IFstream.H"
using namespace Foam;
......@@ -55,9 +56,9 @@ int main(int argc, char *argv[])
Info<< hmm << endl;
//SquareMatrix<scalar> hmm3(Sin);
SquareMatrix<scalar> hmm3(Sin);
//Info<< hmm3 << endl;
Info<< hmm3 << endl;
SquareMatrix<scalar> hmm4;
......@@ -71,14 +72,47 @@ int main(int argc, char *argv[])
Info<< hmm5 << endl;
{
scalarSymmetricSquareMatrix symmMatrix(3, 3, 0);
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;
Info<< nl << "Square Matrix = " << squareMatrix << endl;
symmMatrix(0, 0) = 4;
symmMatrix(1, 0) = 12;
symmMatrix(1, 1) = 37;
symmMatrix(2, 0) = -16;
symmMatrix(2, 1) = -43;
symmMatrix(2, 2) = 98;
scalarDiagonalMatrix rhs(3, 0);
rhs[0] = 1;
rhs[1] = 2;
rhs[2] = 3;
LUsolve(squareMatrix, rhs);
Info<< "Decomposition = " << squareMatrix << endl;
Info<< "Solution = " << rhs << endl;
}
{
scalarSymmetricSquareMatrix symmMatrix(4, 4, 0);
symmMatrix(0, 0) = 3.44854;
symmMatrix(1, 0) = -2.70766;
symmMatrix(1, 1) = 5.49922;
symmMatrix(2, 0) = -0.96245;
symmMatrix(2, 1) = 2.40948;
symmMatrix(2, 2) = 1.56918;
symmMatrix(3, 0) = 1.95912;
symmMatrix(3, 1) = -3.46118;
symmMatrix(3, 2) = -1.01410;
symmMatrix(3, 3) = 3.24753;
Info<< "Symmetric Square Matrix = " << symmMatrix << endl;
......@@ -91,10 +125,11 @@ int main(int argc, char *argv[])
Info<< "Inverse = " << invDecomposed(symmMatrix2) << endl;
Info<< "Determinant = " << detDecomposed(symmMatrix2) << endl;
scalarDiagonalMatrix rhs(3, 0);
scalarDiagonalMatrix rhs(4, 0);
rhs[0] = 1;
rhs[1] = 2;
rhs[2] = 3;
rhs[3] = 4;
LUsolve(symmMatrix, rhs);
......@@ -103,28 +138,20 @@ 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;
IFstream str("datafile");
scalarSymmetricSquareMatrix symmMatrix(str);
Info<< "Symmetric Square Matrix = " << symmMatrix << endl;
Info<< nl << "Square Matrix = " << squareMatrix << endl;
Info<< "Inverse = " << inv(symmMatrix) << endl;
Info<< "Determinant (ans = 0.24130) = " << det(symmMatrix) << endl;
scalarDiagonalMatrix rhs(3, 0);
scalarDiagonalMatrix rhs(4, 0);
rhs[0] = 1;
rhs[1] = 2;
rhs[2] = 3;
rhs[3] = 4;
LUsolve(squareMatrix, rhs);
Info<< "Decomposition = " << squareMatrix << endl;
LUsolve(symmMatrix, rhs);
Info<< "Solution = " << rhs << endl;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment