# Error in If-else statement

 Register Blogs Members List Search Today's Posts Mark Forums Read

 December 8, 2016, 08:59 Error in If-else statement #1 New Member   fluidflowsteel Join Date: Jun 2016 Posts: 21 Rep Power: 6 Hi all, i have the following problem VolscalarField X VolscalarField Y VolscalarField theta theta = atan(Y/X) We know that for theta = pi/2 or (3*pi)/2 etc. tangent values are undefined. Based on the X and Y coordinates of a point, I need to find out the angle theta in radians in OpenFOAM 3.0 I have written the following code which compiled without any errors forAll(X, cellI) { forAll(Y, cellI) { forAll(Theta, cellI) { if (X[cellI] == scalar(0.0)) { if (Y[cellI] > scalar(0.0)) { Theta = (Foam::constant::mathematical:i*0.5); } else { Theta = -(Foam::constant::mathematical:i*0.5); } } else if (X[cellI] > scalar(0.0)) { if (Y[cellI] > scalar(0.0)) { Theta = atan(Y/X); } else { Theta = (Foam::constant::mathematical:i*2) + atan(Y/X); } } else { Theta = (Foam::constant::mathematical:i) + atan(Y/X); } } } } It has compiled without any errors while running it is giving the following error. Seems to be related to something kind of 0/0 ? Can anyone help me ? Calculating scalar transport Courant Number mean: 0 max: 0 Time = 1e-12 #0 Foam::error:rintStack(Foam::Ostream&) at ??:? #1 Foam::sigFpe::sigHandler(int) at ??:? #2 ? in "/lib/x86_64-linux-gnu/libc.so.6" #3 Foam::divide(Foam::Field&, Foam::UList const&, Foam::UList const&) at ??:? #4 Foam::tmp > Foam:perator/(Foam::GeometricField const&, Foam::GeometricField const&) at ??:? #5 ? at ??:? #6 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #7 ? at ??:? Thanks in advance With regards

 December 9, 2016, 07:23 #2 Senior Member   khedar Join Date: Oct 2016 Posts: 112 Rep Power: 6 I would add a bunch of "Info" statements to pinpoint where "something/0" is occuring and then try to correct/modify it.

 December 9, 2016, 07:46 #3 New Member   fluidflowsteel Join Date: Jun 2016 Posts: 21 Rep Power: 6 Thanks for your input. Just found the function Foam::atan2(x,y) to calculate the angle theta (which can lie in any of the four quadrants) directly instead of if-else statements (the way i wrote the code in the thread). but in my case x and y are the volume scalar field. will it be like Theta = atan2f(x,y) ?