# CEL expression for Signum function in CFX

 User Name Remember Me Password
 Register Blogs Members List Search Today's Posts Mark Forums Read

 LinkBack Thread Tools Search this Thread Display Modes
 March 28, 2018, 04:34 CEL expression for Signum function in CFX #1 Member   Tingyun YIN Join Date: Apr 2017 Posts: 31 Rep Power: 6 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.

 March 28, 2018, 04:48 #2 Senior Member   M Join Date: Dec 2017 Posts: 419 Rep Power: 9 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?

March 28, 2018, 05:02
#3
Member

Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Quote:
 Originally Posted by AtoHM 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
 QQ20180328-095751@2x.png (25.6 KB, 20 views)

 March 28, 2018, 05:16 #4 Senior Member   M Join Date: Dec 2017 Posts: 419 Rep Power: 9 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 )

March 28, 2018, 05:29
#5
Member

Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Quote:
 Originally Posted by AtoHM 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.

 March 28, 2018, 10:52 #6 Senior Member   Join Date: Jun 2009 Posts: 1,485 Rep Power: 27 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

March 28, 2018, 11:01
#7
Member

Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 6
Quote:
 Originally Posted by Opaque 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.

 Tags cel, cfx, signum

 Thread Tools Search this Thread Search this Thread: Advanced Search 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 Off Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post [Other] refineWallLayer Error Yuby OpenFOAM Meshing & Mesh Conversion 2 November 11, 2021 12:04 immortality OpenFOAM Running, Solving & CFD 13 March 24, 2021 08:15 shahpar73 CFX 1 May 25, 2017 08:22 [Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 12 December 12, 2011 05:16 Araz CFX 0 May 5, 2011 17:06

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

 Contact Us - CFD Online - Privacy Statement - Top