mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: triad: Add diff function that returns a scalar representing the
difference between two triads
This commit is contained in:
@ -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;}
|
||||
|
||||
Reference in New Issue
Block a user