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

Problem with the precision of scalar values

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 25, 2015, 12:11
Default Problem with the precision of scalar values
  #1
Member
 
fouad abi
Join Date: Nov 2015
Location: Geneva, Switzerland
Posts: 42
Rep Power: 10
faab is on a distinguished road
Send a message via Skype™ to faab
Dear everyone,

I am working with a modified version of the ChtMultiRegion Solver, and the DP (double precision) is the one I set for the compiler. I am working on a 64-bit unit. My problem is that when the solver computes a very large number - say -1.45 to the power 21, to take an actual example - and stacks it in the allocated memory by passing this value to an existing variable, it is converted to 0. So of course, when I later use this variable in a division I get a segmentation fault. I do not understand how this process works, and because I use the DP, I do not see how to fix the issue. Could anyone give me a hand with this matter please ?

PS. In case it helps: I just ran a test where I state a=-1.45e+21, and "print" the value which is returned correctly by the solver. But when I do not use the "e" exponent and enter the full value (with 19 zeros) I get 0 in return. So I guess the issue/limitation comes from the number of digits, any ideas ?? Thanks !
faab is offline   Reply With Quote

Old   November 26, 2015, 11:18
Default
  #2
Member
 
fouad abi
Join Date: Nov 2015
Location: Geneva, Switzerland
Posts: 42
Rep Power: 10
faab is on a distinguished road
Send a message via Skype™ to faab
After some time I was able to isolate the problem and it seems that the issue is caused by negative values computed in the power function Foam:ow(). I computed the following statement separately:
Foam:ow((-27e1), scalar(1)/scalar(3))
The same statement with +27 instead of -27 returns the correct answer (3). But with the negative value as an argument I get the following error message:
Foam::error:rintStack(Foam::Ostream&)
#1 Foam::sigFpe::sigHandler(int)
#2
at sigaction.c
#3
at interp.c
#4
#5 __libc_start_main
#6

Am I doing something wrong here ? Thank you for your help !
faab is offline   Reply With Quote

Old   November 26, 2015, 11:27
Default
  #3
Senior Member
 
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 17
wouter is on a distinguished road
Hello Faab,
here is your answer: http://www.cplusplus.com/reference/cmath/pow/
google is your friend.
hope this helps
wouter
wouter is offline   Reply With Quote

Old   November 26, 2015, 11:39
Default
  #4
Member
 
fouad abi
Join Date: Nov 2015
Location: Geneva, Switzerland
Posts: 42
Rep Power: 10
faab is on a distinguished road
Send a message via Skype™ to faab
Hi Wouter,

Thank you for your help. Your link only tells me that what I am doing is wrong, which I knew already. As I said I figured that using a negative base generates a domain error. My goal is to solve this, to find a work around.
Cheers, thanks again for your time.

Last edited by faab; November 26, 2015 at 11:44. Reason: -
faab is offline   Reply With Quote

Old   November 26, 2015, 17:55
Default
  #5
Senior Member
 
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 17
wouter is on a distinguished road
hello Faab,
Maybe the use or binairy instead of ascii in controldict. Or you need to change write precision to 23 or something.

hope this helps
Wouter
wouter is offline   Reply With Quote

Old   November 27, 2015, 04:44
Default
  #6
Member
 
fouad abi
Join Date: Nov 2015
Location: Geneva, Switzerland
Posts: 42
Rep Power: 10
faab is on a distinguished road
Send a message via Skype™ to faab
Hi Wouter,

Thank you for the tips. It did not solve the issue but I found out that the base is never supposed to be negative, so I must adapt the code to implement new sets of equations when the temperature gets to a limit where the base gets negative. In the end the problem is still unsolved but I don't need to work on this now, however if anyone has a solution as to how to compute negative bases using the Foam:ow() function, I am very keen to hear it !
Thanks again.
faab 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Negative values in scalar transport jnally OpenFOAM Running, Solving & CFD 5 August 23, 2018 15:32
sonicFoam Wedge, Max. Iterations Exceeded, hConstThermo, v199ah OpenFOAM Running, Solving & CFD 4 March 15, 2016 09:39
Non-Uniform Scalar Values Shabirmean OpenFOAM Running, Solving & CFD 0 August 27, 2014 13:12
[swak4Foam] Problem: Defining a linear scalar BC with groovyBC holp OpenFOAM Community Contributions 3 July 19, 2012 20:19
NEAGTIVE SCALAR VALUES Mario Siemens 1 November 18, 2002 02:01


All times are GMT -4. The time now is 05:06.