From 7ea4631c84ca6240a99bbb092a3b86b98d057dea Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Fri, 22 Mar 2019 11:49:53 +0000 Subject: [PATCH] Stability fix: hinv inverse of truly singular tensors --- src/foam/primitives/Tensor/tensor/tensor.C | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/foam/primitives/Tensor/tensor/tensor.C b/src/foam/primitives/Tensor/tensor/tensor.C index 3f14b5d23..942da8d16 100644 --- a/src/foam/primitives/Tensor/tensor/tensor.C +++ b/src/foam/primitives/Tensor/tensor/tensor.C @@ -658,6 +658,12 @@ tensor hinv(const tensor& t) zeroInv += tensor(sqr(eigVecs.y())); } + if (det(t + zeroInv) < VSMALL) + { + // Determinant is still zero. Return zero inverse + return tensor::zero; + } + return inv(t + zeroInv) - zeroInv; } } @@ -705,6 +711,12 @@ symmTensor hinv(const symmTensor& t) zeroInv += sqr(eigVecs.y()); } + if (det(t + zeroInv) < VSMALL) + { + // Determinant is still zero. Return zero inverse + return symmTensor::zero; + } + return inv(t + zeroInv) - zeroInv; } }