|
[Sponsors] |
January 21, 2017, 12:56 |
and atan2
|
#1 |
New Member
Join Date: Feb 2012
Posts: 5
Rep Power: 14 |
Hello all,
I'm trying to initialise a field depending on the polar angle and just noticed, there is no atan2 in swak4foam. The workaround would be to use atan with some conditions as shown here: https://en.wikipedia.org/wiki/Atan2 Atan is not going from -pi to pi. Does somebody have a solution to this problem already? Am I overseening a trivial solution? Regards, Luk |
|
January 22, 2017, 06:43 |
atan2 in funkySetFieldsDict
|
#2 |
New Member
Join Date: Feb 2012
Posts: 5
Rep Power: 14 |
I found a solution to the problem. I used a sequence of ifs written down as ternary operators. The math is taken from here:
https://de.mathworks.com/matlabcentr...from-0-to-2-pi This is the snippet to use in funkySetFieldsDict. Please note, I'm in the y-z-plane instead of the x-y-plane used in the explanation. I simply replaced x by z. Please check if the angle definition fits your coordinate system before use. Code:
myVariables ( // code for y-z-plane polar angle "theta=0;" //if x>0 // v=atan(y/x); //end "theta=(pos().z>0)?atan(pos().y/pos().z):theta;" //if y>=0 & x<0 // v=pi+atan(y/x); //end "theta=((pos().y>=0)&&(pos().z<0))?pi+atan(pos().y/pos().z):theta;" //if y<0 & x<0 // v=-pi+atan(y/x); //end "theta=((pos().y<0)&&(pos().z<0))?-pi+atan(pos().y/pos().z):theta;" //if y>0 & x==0 // v=pi/2; //end "theta=((pos().y>0)&&(pos().z==0))?pi/2:theta;" //if y<0 & x==0 // v=-pi/2; //end "theta=((pos().y<0)&&(pos().z==0))?-pi/2:theta;" //if v<0 // v=v+2*pi; //end // uncomment if you need the angle range to be 0:2pi instead of -pi:pi //"theta=(theta<0)?theta+2*pi:theta;" ); |
|
Tags |
atan2, swak4foam |
|
|