|
[Sponsors] |
March 28, 2018, 04:34 |
CEL expression for Signum function in CFX
|
#1 |
Member
Tingyun YIN
Join Date: Apr 2017
Posts: 31
Rep Power: 9 |
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: 699
Rep Power: 12 |
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: 9 |
Quote:
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. |
||
March 28, 2018, 05:16 |
|
#4 |
Senior Member
M
Join Date: Dec 2017
Posts: 699
Rep Power: 12 |
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: 9 |
Quote:
|
||
March 28, 2018, 10:52 |
|
#6 |
Senior Member
Join Date: Jun 2009
Posts: 1,869
Rep Power: 33 |
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: 9 |
Quote:
|
||
Tags |
cel, cfx, signum |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] mesh airfoil NACA0012 | anand_30 | OpenFOAM Meshing & Mesh Conversion | 13 | March 7, 2022 18:22 |
[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 |
Passing Values in Multiple points by 1 CEL Function | Araz | CFX | 0 | May 5, 2011 17:06 |