From b989b81d16cab40bf958bc10f03020ead2339a18 Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Thu, 31 May 2018 14:23:15 +0100 Subject: [PATCH] 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. --- src/OpenFOAM/primitives/Vector/VectorI.H | 13 +++++++++- .../primitives/VectorSpace/VectorSpaceI.H | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/OpenFOAM/primitives/Vector/VectorI.H b/src/OpenFOAM/primitives/Vector/VectorI.H index 518a398dc..7cde6e3b0 100644 --- a/src/OpenFOAM/primitives/Vector/VectorI.H +++ b/src/OpenFOAM/primitives/Vector/VectorI.H @@ -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 operator^(const Vector& v1, const Vector& v2) } +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +template +inline Vector perpendicular(const Vector& v) +{ + Vector u(Zero); + u[findMin(cmptMag(v))] = 1; + return u ^ v; +} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H index afd654cd3..fb30cb0ef 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H @@ -620,6 +620,30 @@ inline typename innerProduct::type dot } +template +inline direction findMax(const VectorSpace& vs) +{ + direction index = 0; + for (direction i=1; i vs[i] ? index : i; + } + return index; +} + + +template +inline direction findMin(const VectorSpace& vs) +{ + direction index = 0; + for (direction i=1; i