diff --git a/src/OpenFOAM/primitives/triad/triad.C b/src/OpenFOAM/primitives/triad/triad.C index 604696b0ec..b190014b6e 100644 --- a/src/OpenFOAM/primitives/triad/triad.C +++ b/src/OpenFOAM/primitives/triad/triad.C @@ -32,8 +32,6 @@ License namespace Foam { -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - template<> const char* const triad::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); +} + // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/triad/triad.H b/src/OpenFOAM/primitives/triad/triad.H index 3915faff50..fbf91fc0e2 100644 --- a/src/OpenFOAM/primitives/triad/triad.H +++ b/src/OpenFOAM/primitives/triad/triad.H @@ -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() {return true;}