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

Error in If-else statement

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 8, 2016, 08:59
Default Error in If-else statement
  #1
New Member
 
fluidflowsteel
Join Date: Jun 2016
Posts: 21
Rep Power: 10
fluidflowsteel is on a distinguished road
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<double>&, Foam::UList<double> const&, Foam::UList<double> const&) at ??:?
#4 Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> > Foam:perator/<Foam::fvPatchField, Foam::volMesh>(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&, Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) at ??:?
#5 ? at ??:?
#6 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#7 ? at ??:?


Thanks in advance

With regards
fluidflowsteel is offline   Reply With Quote

Old   December 9, 2016, 07:23
Default
  #2
Senior Member
 
khedar
Join Date: Oct 2016
Posts: 111
Rep Power: 10
khedar is on a distinguished road
I would add a bunch of "Info" statements to pinpoint where "something/0" is occuring and then try to correct/modify it.
khedar is offline   Reply With Quote

Old   December 9, 2016, 07:46
Default
  #3
New Member
 
fluidflowsteel
Join Date: Jun 2016
Posts: 21
Rep Power: 10
fluidflowsteel is on a distinguished road
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) ?
fluidflowsteel 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
Help with if statement CHARLES OpenFOAM Programming & Development 17 August 22, 2021 04:14
compiling error to fortran statement DATA MASK_VELD/2#00000000000000001/ JackG Main CFD Forum 0 October 22, 2016 15:25
How to use if statement in openFoam solver? rapierrz OpenFOAM Programming & Development 7 August 4, 2015 06:19
Restricting area in if statement Blackhawks84 Fluent UDF and Scheme Programming 4 July 22, 2012 17:50
Weak statement for Galerkin Method rugabug Main CFD Forum 0 March 26, 2010 20:19


All times are GMT -4. The time now is 01:30.