|
[Sponsors] |
|
November 25, 2015, 12:11 |
Problem with the precision of scalar values
|
#1 |
Member
|
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 ! |
|
November 26, 2015, 11:18 |
|
#2 |
Member
|
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 ! |
|
November 26, 2015, 11:27 |
|
#3 |
Senior Member
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 17 |
Hello Faab,
here is your answer: http://www.cplusplus.com/reference/cmath/pow/ google is your friend. hope this helps wouter |
|
November 26, 2015, 11:39 |
|
#4 |
Member
|
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: - |
|
November 26, 2015, 17:55 |
|
#5 |
Senior Member
Wouter van der Meer
Join Date: May 2009
Location: Elahuizen, Netherlands
Posts: 203
Rep Power: 17 |
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 |
|
November 27, 2015, 04:44 |
|
#6 |
Member
|
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. |
|
|
|
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 |