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

[swak4Foam] Cartesian to polar using FunkySetFields >>> Division by zero

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread 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: 11
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: 4,225
Rep Power: 51
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: 11
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: 4,225
Rep Power: 51
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


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
[swak4Foam] how to use funkySetFields function in muliregion case bryant_k OpenFOAM Community Contributions 15 October 15, 2021 02:50
On body-fitted cartesian mesh generation sbaffini Main CFD Forum 0 October 21, 2016 10:32
polar and cartesian coordinates. Afaraj FLUENT 0 November 21, 2015 11:07
Shear stress distribution from cartesian to polar coordinates Dawood Al-Mosuli FLUENT 0 January 6, 2015 18:11
Difficulty In Setting Boundary Conditions Moinul Haque CFX 4 November 25, 2014 17:30


All times are GMT -4. The time now is 08:59.