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

Cartesian to polar using FunkySetFields >>> Division by zero

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

Reply
 
LinkBack Thread Tools Display Modes
Old   September 29, 2014, 04:22
Default Cartesian to polar using FunkySetFields >>> Division by zero
  #1
New Member
 
Philipp Gruschka
Join Date: Jun 2014
Posts: 5
Rep Power: 3
pagru is on a distinguished road
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
pagru is offline   Reply With Quote

Old   September 29, 2014, 17:43
Default
  #2
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by pagru View Post
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
gschaider is offline   Reply With Quote

Old   October 1, 2014, 05:21
Default
  #3
New Member
 
Philipp Gruschka
Join Date: Jun 2014
Posts: 5
Rep Power: 3
pagru is on a distinguished road
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!!!
pagru is offline   Reply With Quote

Old   October 1, 2014, 18:30
Default
  #4
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 3,912
Rep Power: 40
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by pagru View Post
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 View Post
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
gschaider is offline   Reply With Quote

Reply

Tags
funkysetfields, swak4foam

Thread Tools
Display Modes

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



All times are GMT -4. The time now is 04:52.