# Cartesian to polar using FunkySetFields >>> Division by zero

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

 September 29, 2014, 04:22 Cartesian to polar using FunkySetFields >>> Division by zero #1 New Member   Philipp Gruschka Join Date: Jun 2014 Posts: 5 Rep Power: 4 Hello everybody! First of all, I'm pretty new to OpenFOAM! Currently I'm trying to transform cartesian coordinates to cylindrical coordinates by using funkySetFields. My problem is that the calculation of the circumferential coordinate (phi) requires the calculation of arctan(y/x). For the areas where phi is calculated by arctan(y/x), the case x=0 is clearly excluded, which I also wanted to implement by 1.) using an exclusion in the expression line, e.g. expression "pos().x > 0 ? arctan(y/x) : (elseif-cond.)" 2.) using the condition option, e.g. expression "arctan(y/x)" condition "pos().x > 0" Both results in division by zero exceptions, like the expression is applied to the field before the condition is evaluated. Also I'm not quite sure whether funkySetFields understands arcus-functions. Hope somebody can help me! Thanks in advance, Philipp

September 29, 2014, 17:43
#2
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,997
Rep Power: 42
Quote:
 Originally Posted by pagru Hello everybody! First of all, I'm pretty new to OpenFOAM! Currently I'm trying to transform cartesian coordinates to cylindrical coordinates by using funkySetFields. My problem is that the calculation of the circumferential coordinate (phi) requires the calculation of arctan(y/x). For the areas where phi is calculated by arctan(y/x), the case x=0 is clearly excluded, which I also wanted to implement by 1.) using an exclusion in the expression line, e.g. expression "pos().x > 0 ? arctan(y/x) : (elseif-cond.)" 2.) using the condition option, e.g. expression "arctan(y/x)" condition "pos().x > 0" Both results in division by zero exceptions, like the expression is applied to the field before the condition is evaluated. Also I'm not quite sure whether funkySetFields understands arcus-functions. Hope somebody can help me! Thanks in advance, Philipp
Problem is that with d=a?b:c swak first calculates a, b & c for all values and only then selects the values from b and c that will compose d (with condition it is similar). If expression b produces a division by zero (although the value will not be used later) the evaluation will fail

The workaround would be to make sure that the division by 0 never happens. Like this for instance: "pos().x>0 ? arctan(y/(pos().x>0 ? x : 1e-10)): (other expression)" or "pos().x>0 ? arctan(y/max(x,1e-10)) : othr-expr"
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 October 1, 2014, 05:21 #3 New Member   Philipp Gruschka Join Date: Jun 2014 Posts: 5 Rep Power: 4 That works fine, thank you! Two other quesions: 1.) Is there a way to create a pseudo-unsteady calculation of the field with funkySetFields? Starting from a simple 0/ folder, I'd like to use time and/or deltaT in my dictionary, so that I can compute three or four further timesteps without really calculating it with OpenFOAM. Therefore funkySetFields should be able to automatically create new time folders. 2.) How can I declarate and use variables and constants in FSF? I read something about #include and allowFunctionObjects, but since I'm not really familiar with the OpenFOAM structures I don't really know how to do it... Again, thank you very much in advance!!!

October 1, 2014, 18:30
#4
Assistant Moderator

Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,997
Rep Power: 42
Quote:
 Originally Posted by pagru That works fine, thank you! Two other quesions: 1.) Is there a way to create a pseudo-unsteady calculation of the field with funkySetFields? Starting from a simple 0/ folder, I'd like to use time and/or deltaT in my dictionary, so that I can compute three or four further timesteps without really calculating it with OpenFOAM. Therefore funkySetFields should be able to automatically create new time folders.
Something like replayTransientBC but for fields?

FSF only works if time-folders are there. So at least you'd have to create the folders for FSF (OF) to recognize them. Then you can insert a field as usual

What you CAN do to emulate that behaviour is use replayTransientBC: add expressionField-functionObjects that create the fields you want in system/controlDict and apply the utility

Quote:
 Originally Posted by pagru 2.) How can I declarate and use variables and constants in FSF? I read something about #include and allowFunctionObjects, but since I'm not really familiar with the OpenFOAM structures I don't really know how to do it...
Variables are only possible in FSF if used in dictionary mode (if the expression is specified in a dictionary and not in the command line).
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request

 Tags funkysetfields, swak4foam

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

All times are GMT -4. The time now is 02:28.