CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   "if" command in CFX-13 is not really an "if" command!!!! (https://www.cfd-online.com/Forums/cfx/108167-if-command-cfx-13-not-really-if-command.html)

mohammad October 16, 2012 07:16

"if" command in CFX-13 is not really an "if" command!!!!
 
Dear All,
I am trying to make a conditional expression with "if" command in CFX-13.

Amazingly, the if command is not true...:eek:

for example, create this expression and see the results!!!

-if (a>5,10,loge(5-a))
if we see the results for any a>5 (e.g. "a=6") the results must be 10
However, the CFX-post tried to calculate the value of "loge(5-a)" which will be an mathematical error.
Seemningly, before applying the if command, the CFX-POST calculated the consequences .....

Any Idea or Alternative solution!!!???

Regards,

cdegroot October 16, 2012 09:45

This is answered in the CFX Reference Guide, section 13.2.2.

CEL supports the conditional if statement using the following syntax:
if( cond_expr, true_expr, false_expr )
where:
cond_expr: is the logical expression used as the conditional test
true_expr: is the mathematical expression used to determine the result if the conditional test is true.
false_expr : is the mathematical expression used to determine the result if the conditional test is false.

Note:**The expressions true_expr and false_expr are always evaluated independent of whether the evaluation of cond_expr is true or false. As a consequence, a conditional statement cannot be used to avoid division by zero as in if( x>0, 1/x, 1.0). In this case, when x=0.0, a division by zero will still occur because the expression 1/x is evaluated independent of whether x>0 is satisfied or not.

Luis Lei September 25, 2013 08:32

alternative here?
 
thank you very much for your infos, which is quite helpful to me. But, what can I do, if i do need the ,,real'' conditional statement? Is there a alternative maybe?

best wishes
Quote:

Originally Posted by cdegroot (Post 386889)
This is answered in the CFX Reference Guide, section 13.2.2.

CEL supports the conditional if statement using the following syntax:
if( cond_expr, true_expr, false_expr )
where:
cond_expr: is the logical expression used as the conditional test
true_expr: is the mathematical expression used to determine the result if the conditional test is true.
false_expr : is the mathematical expression used to determine the result if the conditional test is false.

Note:**The expressions true_expr and false_expr are always evaluated independent of whether the evaluation of cond_expr is true or false. As a consequence, a conditional statement cannot be used to avoid division by zero as in if( x>0, 1/x, 1.0). In this case, when x=0.0, a division by zero will still occur because the expression 1/x is evaluated independent of whether x>0 is satisfied or not.


ghorrocks September 25, 2013 18:39

If you are asking how to get around the caveat Chris mentions (that both true and false expression must evaluate or you get an error) - then the best way around this is to use a fortran user routine where you can use if/then/else statements. This is reasonably easy to do, use a user CEL expression linked to the fortran routine. See the documentation for details, it has examples of how to do it.

Luis Lei September 26, 2013 07:10

Quote:

Originally Posted by ghorrocks (Post 453602)
If you are asking how to get around the caveat Chris mentions (that both true and false expression must evaluate or you get an error) - then the best way around this is to use a fortran user routine where you can use if/then/else statements. This is reasonably easy to do, use a user CEL expression linked to the fortran routine. See the documentation for details, it has examples of how to do it.

Yep, thanks very much, i've found the documents needed and i'll do it. ;)


All times are GMT -4. The time now is 12:33.