ENH: triad: Add diff function that returns a scalar representing the

difference between two triads
This commit is contained in:
laurence
2013-01-25 15:16:11 +00:00
parent 9151111657
commit b298163146
2 changed files with 31 additions and 4 deletions

View File

@ -32,8 +32,6 @@ License
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<>
const char* const triad::Vector<vector>::typeName = "triad";
@ -50,6 +48,8 @@ const triad triad::min(vector::min, vector::min, vector::min);
const triad triad::unset(triad::max);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -353,6 +353,30 @@ void Foam::triad::operator=(const tensor& t)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
Foam::scalar Foam::diff(const triad& A, const triad& B)
{
triad tmpA = A.sortxyz();
triad tmpB = B.sortxyz();
scalar sumDifference = 0;
for (direction dir = 0; dir < 3; dir++)
{
if (!tmpA.set(dir) || !tmpB.set(dir))
{
continue;
}
scalar cosPhi =
(tmpA[dir] & tmpB[dir])/(mag(tmpA[dir])*mag(tmpA[dir]) + SMALL);
cosPhi = min(max(cosPhi, -1), 1);
sumDifference += mag(cosPhi - 1);
}
return (sumDifference/3);
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -154,6 +154,9 @@ public:
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
//- Return a quantity of the difference between two triads
scalar diff(const triad& A, const triad& B);
//- Data associated with quaternion type are contiguous
template<>
inline bool contiguous<triad>() {return true;}