From 5236b1c3d6a5408ade72e88acf18d66075ebf5f2 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Thu, 17 Mar 2016 11:22:31 +0000 Subject: [PATCH] Added cmptSign functions --- src/foam/primitives/Scalar/ScalarTemplate.H | 14 ++++++++++---- src/foam/primitives/VectorSpace/VectorSpaceI.H | 14 +++++++++++++- src/foam/primitives/ops/ops.H | 4 ++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/foam/primitives/Scalar/ScalarTemplate.H b/src/foam/primitives/Scalar/ScalarTemplate.H index 3adf20267..75f01b2be 100644 --- a/src/foam/primitives/Scalar/ScalarTemplate.H +++ b/src/foam/primitives/Scalar/ScalarTemplate.H @@ -235,6 +235,12 @@ inline Scalar cmptMag(const Scalar s) } +inline Scalar cmptSign(const Scalar s) +{ + return sign(s); +} + + // Standard C++ transcendental functions transFunc(sqrt) transFunc(cbrt) @@ -268,7 +274,7 @@ transFunc(y1) // Stabilisation around zero for division -inline Scalar stabilise(const Scalar s, const Scalar small) +inline Scalar stabilise(const Scalar& s, const Scalar& small) { if (s >= 0) { @@ -283,9 +289,9 @@ inline Scalar stabilise(const Scalar s, const Scalar small) inline Scalar cmptStabilise ( - const Scalar s, - const Scalar small, - const Scalar value + const Scalar& s, + const Scalar& small, + const Scalar& value ) { if (mag(s) < small) diff --git a/src/foam/primitives/VectorSpace/VectorSpaceI.H b/src/foam/primitives/VectorSpace/VectorSpaceI.H index 5ccbd0597..2b1e8fdd3 100644 --- a/src/foam/primitives/VectorSpace/VectorSpaceI.H +++ b/src/foam/primitives/VectorSpace/VectorSpaceI.H @@ -431,6 +431,18 @@ inline Form cmptMag } +template +inline Form cmptSign +( + const VectorSpace& vs +) +{ + Form v; + VectorSpaceOps::eqOp(v, vs, eqSignOp()); + return v; +} + + template inline Form cmptStabilise ( @@ -440,7 +452,7 @@ inline Form cmptStabilise ) { Form v = vs; - for (int i=0; i class eqMagOp { public: void operator()(T& x, const T& y) const { x = mag(y); } }; +template +class eqSignOp +{ public: void operator()(T& x, const T& y) const { x = sign(y); } }; + template class plusEqMagSqrOp2 { public: void operator()(T1& x, const T2& y) const { x += magSqr(y); } };