Skip to content

A small typo and possible issue in deformableParticles2D::area() #3

@YUXUANCHENG

Description

@YUXUANCHENG

First of all, there is a typo here:

cout << " ** uxi = " << uxi << ", uyi = " << uyi << "; uxim1 = " << uyim1 << ", uyim1 = " << uyim1 << endl;

I guess it meant to print "uxim1 = " << uxim1" instead of "uxim1 = " << uyim1".

Then,

thetai = acos(ci);

It is dangerous to call acos on a value exactly equals +/-1.0, because rounding errors can cause the computed value to be outside this range.

Such as:
ERROR: vertex area calculated is a nan, vi = 14, thetai = nan.
** uxi = 0.979597, uyi = -0.200974; uxim1 = 0.200974, uyim1 = 0.200974
** segmentCosine(vi) = -1
** Ending.
Even thought segmentCosine(vi) is exactly -1.0, acos returns nan.

A possible fix:
double Safe_Acos (double x)
{
if (x < -1.0) x = -1.0 ;
else if (x > 1.0) x = 1.0 ;
return acos (x) ;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions