Skip to content
Snippets Groups Projects
Commit b2981631 authored by laurence's avatar laurence
Browse files

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

difference between two triads
parent 91511116
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
// ************************************************************************* //
......@@ -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;}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment