Fixing rare precision error in Tsuji damping

This commit is contained in:
jtclemm
2024-02-23 13:29:18 -07:00
parent e51a65696d
commit fef2150bfb

View File

@ -130,6 +130,8 @@ void GranSubModDampingTsuji::init()
double GranSubModDampingTsuji::calculate_forces()
{
damp_prefactor = damp * sqrt(gm->meff * gm->Fnormal / gm->delta);
// in case argument < 0 due to precision issues
double sqrt1 = MAX(0, gm->meff * gm->Fnormal / gm->delta);
damp_prefactor = damp * sqrt(sqrt1);
return -damp_prefactor * gm->vnnr;
}