|
[Sponsors] |
February 26, 2018, 14:09 |
If statement in Fluent TUI command!
|
#1 |
Member
Join Date: Dec 2017
Posts: 34
Rep Power: 9 |
Dear All,
I need to write an if-statement to check the flow_time status, if it is between a specific times, the analysis must follow some commands. I know the if part: (if (> (rpgetvar' flow-time) 0.355) (desired task) But if-else is something unknown for me. I need add an "else if" condition as well. Does anyone has any experience to share? |
|
February 28, 2018, 07:21 |
|
#2 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
The Scheme if syntax is:
Code:
(if test true-action false-action) Code:
(if (> (rpgetvar 'flow-time) 0.355) (late-action) (early-action)) Code:
(begin (action1) (action2)) |
|
February 28, 2018, 10:40 |
What about if-else condition!
|
#3 |
Member
Join Date: Dec 2017
Posts: 34
Rep Power: 9 |
Thanks for your comment and useful information. But, what about if-else condition, something equivalent to this:
if (flow-time > 0.1 && flow-time< 0.5) do something else if flow-time >= 0.5 do something else Thanks. |
|
February 28, 2018, 17:54 |
|
#4 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
The example above already tells you how to do else, notice the false action and (early action) in the examples.
Note that logically else-if only occurs when the previous condition has failed: But to be more-precise, Scheme goes like Code:
(if test1-expression then1-expression test2-expression then2-expression else-expression) Code:
(if (> (rpgetvar 'flow-time) 0.355) (action1) (> (rpgetvar 'flow-time) 0.255) (action2) (> (rpgetvar 'flow-time) 0.155) (action3) (action4) ) |
|
March 2, 2018, 10:42 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hi LuckyTran,
The example you give might be valid Scheme (I'm not sure), but it is not accepted by Fluent. You are right, though, that a single if...else (as I provided) is enough to build up multiple tests, because the false-action can be another if. For example: Code:
(if (> a b1) (action1) (if (> a b2) (action2) (if (> a b3) (action3) (action_default)))) Code:
(cond (test1 body1) (test2 body2) ;;; etc (else body)) Ed |
|
March 2, 2018, 14:40 |
It means ...
|
#6 |
Member
Join Date: Dec 2017
Posts: 34
Rep Power: 9 |
Dear Ed and LuckyTran,
Thanks for your comments. I agree with Ed, I have tried what you suggested LuckyTran before and Fluent gave me an error. Ed, what you have explanied means that each (test# body#) can represent an if (test#) plus its action (body#), right? |
|
March 2, 2018, 15:51 |
|
#7 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66 |
I think you should both read what I have written again
This is not what I wrote. Code:
(if (> a b1) (action1) (if (> a b2) (action2) (if (> a b3) (action3) (action_default)))) This is the same as I wrote but with "if" replaced by "cond" Code:
(cond (test1 body1) (test2 body2) ;;; etc (else body)) |
|
March 5, 2018, 12:24 |
|
#8 | |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Quote:
You are basically correct, but (as you have probably worked out) it is different from a series of *separate* (if ...) statements, in that only one branch is ever selected. The branches are tested in the order stated (which sounds obvious, but the order of evaluation is not always guaranteed elsewhere in Scheme). Of course, another way to get only one branch selected is with a *nested* set of (if ...) statements, such as the one I mentioned earlier. We can take LuckyTran's example and rephrase it such that Fluent will accept it: Code:
(cond ((> (rpgetvar 'flow-time) 0.355) (action1)) ((> (rpgetvar 'flow-time) 0.255) (action2a) (action2b)) ((> (rpgetvar 'flow-time) 0.155) 0.333) (else (action4a) (action4b) (action4c)) ) By the way, I slightly regret focussing on a function call such as "(action1)" as the only branch that I mentioned -- a branch can alternatively be a literal value, as in 0.333 above, with no parentheses. (There would be no purpose to this in the example -- it only matters if the result of the (cond ...) function is then used in some way.) For a (cond ...) statement, there can be multiple actions in a body, and the (cond ...) function returns the value returned by the last action in the selected body. Ed |
||
March 7, 2018, 10:30 |
Thanks again!
|
#9 |
Member
Join Date: Dec 2017
Posts: 34
Rep Power: 9 |
Dear Ed and LuckyTran,
Thanks again for your comments. Last explanation by Ed made everything clear for me. The idea of having multiple actions in the same if-statement is very useful, thanks for sharing. Regards, Malekan |
|
November 16, 2018, 08:57 |
|
#10 | |
Member
Join Date: Nov 2017
Posts: 54
Rep Power: 9 |
Quote:
I want to write command that write case and data but I don't know how to write if statement (if (= (rpgetvar 'variable) 1) (write-case-data "Iteration-%t.cas") (display "not 100s, do nothing\n"))\n variable is changed in UDF and case & data are saved. is it true? |
||
November 20, 2018, 00:21 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
use %rpgetvar macro
for your case Code:
(%rpgetvar 'variable) |
|
Tags |
fluent, tui commands |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Command line reference ANSYS fluent | alaspina | FLUENT | 2 | July 27, 2017 12:48 |
fluent text command doesnt show all options! | m2montazari | FLUENT | 3 | March 13, 2017 00:56 |
Fluent Tui Command for transient | MachZero | FLUENT | 5 | January 17, 2017 14:57 |
Fluent batch command for unsteady | taekyu8 | FLUENT | 0 | January 7, 2013 16:18 |
Fluent from command line not in background please! | Chris Bailey | FLUENT | 5 | July 28, 2012 08:26 |