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

CEL expression for Signum function in CFX

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2018, 04:34
Exclamation CEL expression for Signum function in CFX
  #1
Member
 
Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Tingyun YIN is on a distinguished road
Hi, everyone.

I want to define Signum function in CFX, which is used to export -1, 0 or 1. For example, sgn(C) is equal to 1 when C>0; sgn(C) is equal to 0 when C=0; sgn(C) is equal to -1 when C<0.

Thanks in advance, Any comments and suggestions are appreciated.
Tingyun YIN is offline   Reply With Quote

Old   March 28, 2018, 04:48
Default
  #2
Senior Member
 
M
Join Date: Dec 2017
Posts: 419
Rep Power: 9
AtoHM is on a distinguished road
Depending on what values your are looking at, the if-Statement might be sufficient for this case. https://www.sharcnet.ca/Software/Ans...statement.html
Lets assume you look at a pressure field and do this kind of stuff, giving some threshold value, I doubt there would be a point in the field where the value will be exactly as the one you defined. Lets say you use 1 Pa. Double precision will give you maybe 1.0000008 Pa and 0.99999998 Pa as closest values, resulting in -1 or 1 eventually?
AtoHM is offline   Reply With Quote

Old   March 28, 2018, 05:02
Default
  #3
Member
 
Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Tingyun YIN is on a distinguished road
Quote:
Originally Posted by AtoHM View Post
Depending on what values your are looking at, the if-Statement might be sufficient for this case. https://www.sharcnet.ca/Software/Ans...statement.html
Lets assume you look at a pressure field and do this kind of stuff, giving some threshold value, I doubt there would be a point in the field where the value will be exactly as the one you defined. Lets say you use 1 Pa. Double precision will give you maybe 1.0000008 Pa and 0.99999998 Pa as closest values, resulting in -1 or 1 eventually?
Thanks for your reply.
Exactly, this function is used to distinguish positive or negative or zero in CFX. I am modifying the cavitation model. Flow field pressure is over than saturated vapor pressure, then evaporation occurs. Flow field pressure is lower than saturated vapor pressure, then condensation occurs. Otherwise, returns to 0, no changes.
Attached Images
File Type: png QQ20180328-095751@2x.png (25.6 KB, 20 views)
Tingyun YIN is offline   Reply With Quote

Old   March 28, 2018, 05:16
Default
  #4
Senior Member
 
M
Join Date: Dec 2017
Posts: 419
Rep Power: 9
AtoHM is on a distinguished road
What I was trying to say is, that I dont think it is possible using the simple if-Statement in the link to distinguish into -1,0,1. However, I doubt there is an actual need for having "0", because the solutions are numerical and the chance that it hits exactly the value you set are very small. So I think you can go with if C<0 use -1 and if C=>0 use 1 which allows to use this kind of if-Statement.

if( cond_expr, true_expr, false_expr )

if( Pressure < Threshold, -1, 1 )
AtoHM is offline   Reply With Quote

Old   March 28, 2018, 05:29
Thumbs up
  #5
Member
 
Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Tingyun YIN is on a distinguished road
Quote:
Originally Posted by AtoHM View Post
What I was trying to say is, that I dont think it is possible using the simple if-Statement in the link to distinguish into -1,0,1. However, I doubt there is an actual need for having "0", because the solutions are numerical and the chance that it hits exactly the value you set are very small. So I think you can go with if C<0 use -1 and if C=>0 use 1 which allows to use this kind of if-Statement.

if( cond_expr, true_expr, false_expr )

if( Pressure < Threshold, -1, 1 )
Yes, you are right. 0 is unable to be avoided, which is a problem. IF statement seems possible, but it still exits defect.
Tingyun YIN is offline   Reply With Quote

Old   March 28, 2018, 10:52
Default
  #6
Senior Member
 
Join Date: Jun 2009
Posts: 1,485
Rep Power: 27
Opaque will become famous soon enough
Besides the IF statement alternative discussed, there is also the "step" function.

step(C) = 1 if C>0
step(C) = -1 if C<0
step(0) = 0.5

The argument C must be dimensionless.

Be careful when working with floating points numbers, it is not a good practice to compare to 0. Perhaps, you want to return 0 whenever C is within some tolerance (machine/precision dependent) around 0.

In addition, this type of function generates considerable numerical instabilities because of their abrupt/sudden changes around 0. It is sometimes better to create a smooth "blending" function to transition from one regime/range to another.

Hope the above helps
Opaque is offline   Reply With Quote

Old   March 28, 2018, 11:01
Default
  #7
Member
 
Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Tingyun YIN is on a distinguished road
Quote:
Originally Posted by Opaque View Post
Besides the IF statement alternative discussed, there is also the "step" function.

step(C) = 1 if C>0
step(C) = -1 if C<0
step(0) = 0.5

The argument C must be dimensionless.

Be careful when working with floating points numbers, it is not a good practice to compare to 0. Perhaps, you want to return 0 whenever C is within some tolerance (machine/precision dependent) around 0.

In addition, this type of function generates considerable numerical instabilities because of their abrupt/sudden changes around 0. It is sometimes better to create a smooth "blending" function to transition from one regime/range to another.

Hope the above helps
Thanks for your suggestions. For current situation, STEP looks better.
Tingyun YIN is offline   Reply With Quote

Reply

Tags
cel, cfx, signum

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04
whats the cause of error? immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 08:15
CEL expression for normalizing temperature in CFX pre shahpar73 CFX 1 May 25, 2017 08:22
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 12 December 12, 2011 05:16
Passing Values in Multiple points by 1 CEL Function Araz CFX 0 May 5, 2011 17:06


All times are GMT -4. The time now is 07:17.