Problem with the precision of scalar values
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 ! |
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::pow(). I computed the following statement separately:
Foam::pow((-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::printStack(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 ! |
Hello Faab,
here is your answer: http://www.cplusplus.com/reference/cmath/pow/ google is your friend. hope this helps wouter |
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. |
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 |
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::pow() function, I am very keen to hear it ! Thanks again. |
All times are GMT -4. The time now is 04:10. |