ENH: Code refactoring

This commit is contained in:
andy
2013-11-05 11:13:04 +00:00
parent 9a8e128e8d
commit adc056ca07

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-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -26,13 +26,12 @@ License
#include "tensor.H" #include "tensor.H"
#include "mathematicalConstants.H" #include "mathematicalConstants.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // using namespace Foam::constant::mathematical;
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
template<> template<>
const char* const tensor::typeName = "tensor"; const char* const tensor::typeName = "tensor";
@ -83,12 +82,12 @@ const tensor tensor::I
0, 1, 0, 0, 1, 0,
0, 0, 1 0, 0, 1
); );
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Return eigenvalues in ascending order of absolute values Foam::vector Foam::eigenValues(const tensor& t)
vector eigenValues(const tensor& t)
{ {
scalar i = 0; scalar i = 0;
scalar ii = 0; scalar ii = 0;
@ -120,7 +119,7 @@ vector eigenValues(const tensor& t)
+ t.xy()*t.yx()*t.zz() + t.xx()*t.yz()*t.zy(); + t.xy()*t.yx()*t.zz() + t.xx()*t.yz()*t.zy();
// If there is a zero root // If there is a zero root
if (mag(c) < 1.0e-100) if (mag(c) < ROOTVSMALL)
{ {
scalar disc = sqr(a) - 4*b; scalar disc = sqr(a) - 4*b;
@ -157,14 +156,8 @@ vector eigenValues(const tensor& t)
scalar aBy3 = a/3; scalar aBy3 = a/3;
i = m2SqrtQ*cos(theta/3) - aBy3; i = m2SqrtQ*cos(theta/3) - aBy3;
ii = ii = m2SqrtQ*cos((theta + twoPi)/3) - aBy3;
m2SqrtQ iii = m2SqrtQ*cos((theta - twoPi)/3) - aBy3;
*cos((theta + constant::mathematical::twoPi)/3)
- aBy3;
iii =
m2SqrtQ
*cos((theta - constant::mathematical::twoPi)/3)
- aBy3;
} }
else else
{ {
@ -210,7 +203,7 @@ vector eigenValues(const tensor& t)
} }
vector eigenVector(const tensor& t, const scalar lambda) Foam::vector Foam::eigenVector(const tensor& t, const scalar lambda)
{ {
if (mag(lambda) < SMALL) if (mag(lambda) < SMALL)
{ {
@ -273,7 +266,7 @@ vector eigenVector(const tensor& t, const scalar lambda)
} }
tensor eigenVectors(const tensor& t) Foam::tensor Foam::eigenVectors(const tensor& t)
{ {
vector evals(eigenValues(t)); vector evals(eigenValues(t));
@ -289,7 +282,7 @@ tensor eigenVectors(const tensor& t)
// Return eigenvalues in ascending order of absolute values // Return eigenvalues in ascending order of absolute values
vector eigenValues(const symmTensor& t) Foam::vector Foam::eigenValues(const symmTensor& t)
{ {
scalar i = 0; scalar i = 0;
scalar ii = 0; scalar ii = 0;
@ -321,7 +314,7 @@ vector eigenValues(const symmTensor& t)
+ t.xy()*t.xy()*t.zz() + t.xx()*t.yz()*t.yz(); + t.xy()*t.xy()*t.zz() + t.xx()*t.yz()*t.yz();
// If there is a zero root // If there is a zero root
if (mag(c) < 1.0e-100) if (mag(c) < ROOTVSMALL)
{ {
scalar disc = sqr(a) - 4*b; scalar disc = sqr(a) - 4*b;
@ -358,14 +351,8 @@ vector eigenValues(const symmTensor& t)
scalar aBy3 = a/3; scalar aBy3 = a/3;
i = m2SqrtQ*cos(theta/3) - aBy3; i = m2SqrtQ*cos(theta/3) - aBy3;
ii = ii = m2SqrtQ*cos((theta + twoPi)/3) - aBy3;
m2SqrtQ iii = m2SqrtQ*cos((theta - twoPi)/3) - aBy3;
*cos((theta + constant::mathematical::twoPi)/3)
- aBy3;
iii =
m2SqrtQ
*cos((theta - constant::mathematical::twoPi)/3)
- aBy3;
} }
else else
{ {
@ -411,7 +398,7 @@ vector eigenValues(const symmTensor& t)
} }
vector eigenVector(const symmTensor& t, const scalar lambda) Foam::vector Foam::eigenVector(const symmTensor& t, const scalar lambda)
{ {
if (mag(lambda) < SMALL) if (mag(lambda) < SMALL)
{ {
@ -474,7 +461,7 @@ vector eigenVector(const symmTensor& t, const scalar lambda)
} }
tensor eigenVectors(const symmTensor& t) Foam::tensor Foam::eigenVectors(const symmTensor& t)
{ {
vector evals(eigenValues(t)); vector evals(eigenValues(t));
@ -489,8 +476,4 @@ tensor eigenVectors(const symmTensor& t)
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* // // ************************************************************************* //