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

If statement in Fluent TUI command!

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

Like Tree5Likes
  • 3 Post By LuckyTran
  • 2 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 26, 2018, 14:09
Default If statement in Fluent TUI command!
  #1
Member
 
Join Date: Dec 2017
Posts: 34
Rep Power: 9
malekan.cfd is on a distinguished road
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?
malekan.cfd is offline   Reply With Quote

Old   February 28, 2018, 07:21
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
The Scheme if syntax is:
Code:
(if test true-action false-action)
For example:
Code:
(if (> (rpgetvar 'flow-time) 0.355)
  (late-action)
  (early-action))
You are missing a closing parenthesis in your if, and the quote-mark needs to be moved to the right. If you need more than one command in either branch, you must surround them in a begin:
Code:
(begin (action1) (action2))
obscureed is offline   Reply With Quote

Old   February 28, 2018, 10:40
Default What about if-else condition!
  #3
Member
 
Join Date: Dec 2017
Posts: 34
Rep Power: 9
malekan.cfd is on a distinguished road
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.
malekan.cfd is offline   Reply With Quote

Old   February 28, 2018, 17:54
Default
  #4
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,760
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
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)
So to modify the example above, an if else-if else-if else type statement would look like:
Code:
(if 
(> (rpgetvar 'flow-time) 0.355) (action1)
(> (rpgetvar 'flow-time) 0.255) (action2)
(> (rpgetvar 'flow-time) 0.155) (action3)
(action4)
)
LuckyTran is offline   Reply With Quote

Old   March 2, 2018, 10:42
Default
  #5
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
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))))
Fluent accepts another construction instead of if:
Code:
(cond (test1 body1)
      (test2 body2)
      ;;; etc
      (else body))
and here each body can be multiple function calls, with no need for (begin ...).

Ed
obscureed is offline   Reply With Quote

Old   March 2, 2018, 14:40
Default It means ...
  #6
Member
 
Join Date: Dec 2017
Posts: 34
Rep Power: 9
malekan.cfd is on a distinguished road
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?
malekan.cfd is offline   Reply With Quote

Old   March 2, 2018, 15:51
Default
  #7
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,760
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
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))))
Note that I wrote only one "if" and my example, which does not look anything like this.

This is the same as I wrote but with "if" replaced by "cond"
Code:
(cond (test1 body1)
      (test2 body2)
      ;;; etc
      (else body))
roi247, malekan.cfd and Master312 like this.
LuckyTran is offline   Reply With Quote

Old   March 5, 2018, 12:24
Default
  #8
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Quote:
Originally Posted by malekan.cfd View Post
Ed, what you have explanied means that each (test# body#) can represent an if (test#) plus its action (body#), right?
Hi Malekan,

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))
  )
If 'flow-time is 0.3550001, for example, then we call (action1) only.

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
malekan.cfd and lytemar like this.
obscureed is offline   Reply With Quote

Old   March 7, 2018, 10:30
Default Thanks again!
  #9
Member
 
Join Date: Dec 2017
Posts: 34
Rep Power: 9
malekan.cfd is on a distinguished road
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
malekan.cfd is offline   Reply With Quote

Old   November 16, 2018, 08:57
Default
  #10
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
Quote:
Originally Posted by obscureed View Post
The Scheme if syntax is:
Code:
(if test true-action false-action)
For example:
Code:
(if (> (rpgetvar 'flow-time) 0.355)
  (late-action)
  (early-action))
You are missing a closing parenthesis in your if, and the quote-mark needs to be moved to the right. If you need more than one command in either branch, you must surround them in a begin:
Code:
(begin (action1) (action2))
hello dear

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?
Saman95 is offline   Reply With Quote

Old   November 20, 2018, 00:21
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
use %rpgetvar macro
for your case
Code:
(%rpgetvar 'variable)
best regards
AlexanderZ is offline   Reply With Quote

Reply

Tags
fluent, tui commands

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
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


All times are GMT -4. The time now is 13:27.