CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

floating point exception with exp and pow

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Flopi

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 7, 2020, 12:28
Default floating point exception with exp and pow
  #1
New Member
 
Join Date: Mar 2019
Posts: 7
Rep Power: 7
Flopi is on a distinguished road
Dear Forum,

I'm facing a surprising error in my code. When I use Foam::exp and Foam:: pow (potentially with other functions but I haven't tried more), I have the following error message (for pow):


#0 Foam::error:: printStack(Foam::Ostream&) at ??:?
#1 Foam::sigFpe::sigHandler(int) at ??:?
#2 ? in "/lib64/libc.so.6"
#3 ? in "/lib64/libm.so.6"
#4 pow in "/lib64/libm.so.6"
#5 Foam:: pow(Foam::Field<double>&, Foam::UList<double> const&, double const&) at ??:?
#6 Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam:: pow<Foam::fvPatchField, Foam::volMesh>(Foam::tmp<Foam::GeometricField<doub le, Foam::fvPatchField, Foam::volMesh> > const&, Foam::dimensioned<double> const&) at ??:?
#7 ? at ??:?
#8 __libc_start_main in "/lib64/libc.so.6"
#9 ? at ??:?


When using Foam::exp, I figured that the issue could come from taking the exponential of large numbers, and clipping the values to smaller numbers (i.e. <=10) was working. But this looks like a particularly inelegant solution. Moreover, it worked with earlier versions of Openfoam (I am now on openfoam 7).



Any idea as to why this is happening and how to work around it ?
Thanks
Flopi is offline   Reply With Quote

Old   November 12, 2020, 03:51
Default
  #2
New Member
 
Join Date: Mar 2019
Posts: 7
Rep Power: 7
Flopi is on a distinguished road
I am still facing the issue, and I was wondering if it is because Openfoam cannot handle large numbers.

Does any of you have an idea of what is the maximum value openfoam can handle ?
Flopi is offline   Reply With Quote

Old   November 12, 2020, 23:15
Default
  #3
Senior Member
 
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9
Marpole is on a distinguished road
I tested with exp(1000.0) without any issue. Can you post your code (only relevent portion) with values used for exp or pow?
__________________
Charles L.
Marpole is offline   Reply With Quote

Old   November 13, 2020, 03:58
Default
  #4
New Member
 
Join Date: Mar 2019
Posts: 7
Rep Power: 7
Flopi is on a distinguished road
Hi Charles,

Thanks for the answer. Actually, the field in my exponential goes up to 1500.0 which is indeed too high for OpenFOAM (returns Inf).
So I'm not sure what I can do apart from clipping values.



For the pow, it was my mistake, I was dividing by zero...
Marpole likes this.
Flopi is offline   Reply With Quote

Old   November 13, 2020, 13:57
Default
  #5
Senior Member
 
Charles
Join Date: Aug 2016
Location: Vancouver, Canada
Posts: 148
Rep Power: 9
Marpole is on a distinguished road
Yes, you are right.

For single precision, i.e. float, a number has a maximum of exponent of about 38. This will give the maximum input to function exp: 38*ln(10) = 87.

For double precision, i.e. double, a number has a maximum of exponent of about 308. This will give the maximum input to function exp: 308*ln(10) = 709

With input of 1000.0, it should give inf. I didn't check my result but just waited to see if there is any error message shown up .
__________________
Charles L.
Marpole is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 00:24.