VectorSpace, Vector: Added findMin, findMax and perpendicular functions

The functions findMin and findMax return the index of the minimum or
maximum component, consistently with the functions in ListOps.H. The
perpendicular function returns an arbitrary vector perpendicular to the
supplied vector, with the same magnitude.
This commit is contained in:
Will Bainbridge
2018-05-31 14:23:15 +01:00
parent 2b07f4377a
commit b989b81d16
2 changed files with 36 additions and 1 deletions

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-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -160,6 +160,17 @@ inline Vector<Cmpt> operator^(const Vector<Cmpt>& v1, const Vector<Cmpt>& v2)
} }
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class Cmpt>
inline Vector<Cmpt> perpendicular(const Vector<Cmpt>& v)
{
Vector<Cmpt> u(Zero);
u[findMin(cmptMag(v))] = 1;
return u ^ v;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -620,6 +620,30 @@ inline typename innerProduct<Form1, Form2>::type dot
} }
template<class Form, class Cmpt, direction Ncmpts>
inline direction findMax(const VectorSpace<Form, Cmpt, Ncmpts>& vs)
{
direction index = 0;
for (direction i=1; i<Ncmpts; ++i)
{
index = vs[index] > vs[i] ? index : i;
}
return index;
}
template<class Form, class Cmpt, direction Ncmpts>
inline direction findMin(const VectorSpace<Form, Cmpt, Ncmpts>& vs)
{
direction index = 0;
for (direction i=1; i<Ncmpts; ++i)
{
index = vs[index] < vs[i] ? index : i;
}
return index;
}
// * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * //
template<class Form, class Cmpt, direction Ncmpts> template<class Form, class Cmpt, direction Ncmpts>