View Issue Details

IDProjectCategoryView StatusLast Update
0000618OpenFOAMBugpublic2012-08-07 13:53
Reporteruser232Assigned Tohenry  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Summary0000618: sign function gives incorrect sign of zero
Descriptionmathematically, the sign (also called sgn) function should give

+1 for values of S greater than zero
-1 for values of S less than zero
0 for values equal to zero

OpenFOAM sign gives
+1 for values of S greater than or equal to zero
-1 for values of S less than zero

Solutions:
1) correct the sign function for scalars and make sure all references to sign give expected result.
2) or create new function called signum (latin for sign) that will give the expected result
Steps To Reproduceusing sign(volScalarField)
Additional InformationA function to return the correct sign of scalar s, might have the structure

return (s > -SMALL)-(s < SMALL);

this might be faster than the branched version of

return s < 0 ? -1 : s > 0 ? 1 : 0;

**the reason for such a formulation of sign, could be for level-set methods, where you need to preserve the zero level-set. For classical level-set you solve dG/dt = sign(G)(1-mag(grad(G)) and if sign(G) returns a +1 for zero, then the solution process will alter the zero level-set and "lose" the interface.


Alternatively, a smoothed sign function could be defined with the pseudo-code

smoothsignum(s) = s / sqrt(pow(s,2)+pow(eps,2))

where transition is sharper for eps approaching 0.
TagsNo tags attached.

Activities

henry

2012-08-07 13:53

manager   ~0001565

OpenFOAM sign gives
+1 for values of S greater than or equal to zero
-1 for values of S less than zero

This is a deliberate choice and necessary many uses of sign in OpenFOAM. If you need an alternative definition for other purposes you will need to define your own version of the function.

Issue History

Date Modified Username Field Change
2012-08-07 13:12 user232 New Issue
2012-08-07 13:53 henry Note Added: 0001565
2012-08-07 13:53 henry Status new => resolved
2012-08-07 13:53 henry Resolution open => no change required
2012-08-07 13:53 henry Assigned To => henry