mirror of
https://github.com/OpenFOAM/OpenFOAM-6.git
synced 2025-12-08 06:57:46 +00:00
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:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
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
|
||||
|
||||
@ -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 * * * * * * * * * * * * * //
|
||||
|
||||
template<class Form, class Cmpt, direction Ncmpts>
|
||||
|
||||
Reference in New Issue
Block a user