From 1a7654b0a6de6a2bc96350f65748625b92e8c603 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Thu, 17 Mar 2016 10:13:30 +0000 Subject: [PATCH] Bugfix: Round-off stabilisation in sqrt --- src/ODE/sixDOF/finiteRotation/finiteRotation.C | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ODE/sixDOF/finiteRotation/finiteRotation.C b/src/ODE/sixDOF/finiteRotation/finiteRotation.C index c03d0d037..c1f9a3900 100644 --- a/src/ODE/sixDOF/finiteRotation/finiteRotation.C +++ b/src/ODE/sixDOF/finiteRotation/finiteRotation.C @@ -82,7 +82,9 @@ Foam::vector Foam::finiteRotation::eulerAngles(const tensor& rotT) // Calculate roll angle rollAngle = atan2(rotT.yz(), rotT.zz()); - const scalar c2 = sqrt(rotT.xx() + rotT.xy()); + // Use mag to avoid negative value due to round-off + // HJ, 24/Feb/2016 + const scalar c2 = sqrt(Foam::max(0, rotT.xx() + rotT.xy())); // Calculate pitch angle pitchAngle = atan2(-rotT.xz(), c2); -- 2.11.4.GIT