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; } }