1

I'm using the ANSYS Fluent program for CFD simulations. This program allows some partial automation of the simulation setup using a so-called Journal File, and I just came to know that this Journal File is written in Scheme. Unfortunately I never even heard of Scheme, I just know it's a Lisp dialect (which I also know nothing of).

I'm trying to automate some boring tasks by using a loop to automatically set a bunch of parameters to my simulation. If I run this command from Fluent's command interface:

(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" '( 4))

it does what's expected (it selects item 4 from a list). However, if I stick that into a loop:

(do ((z 4 (+ z 1))) ((> z 27))
  (cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" '( z))
)

nothing happens and the program prints a #f in the command window. Then, if I do:

(define z 4)
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" '( z))

nothing happens at all.

Why does replacing the number 4 by a variable doesn't work? And why does the loop returns a #f?

  • What this line ` ((> z 27))` should do? Did you meant something like `(when (> z 27) (cx-gui-do .....` - conditional execution? – rsm Nov 18 '19 at 01:45
  • @rsm I copied that line from some example in the internet. That line is supposed to be the stop condition of the loop (loop from z=4 and stop when z>27). If I add the `when`, as you suggested, the program raises the error `Error: eval: unbound variable Error Object: when` – The Drunken Whaler Nov 18 '19 at 01:49
  • Oh, sorry. I thought it's part of the `do` body because of the indentation ;) – rsm Nov 18 '19 at 01:52
  • @rsm No problem. Sorry if I unintentionally butchered the indentation ;-) – The Drunken Whaler Nov 18 '19 at 01:53
  • Please check my answer. If it solved your problem, please accept it, to mark your question as solved, and if you like it, please upvote. If your problem still exists, let me know. – rsm Nov 18 '19 at 02:23

1 Answers1

2

The problem here I think comes from '(z) part. This tick ' is called quote and is a short hand for (quote ...) call. It does not create a list, it's for returning something without evaluation. In your case if you pass (4) instead of '(4) you will get an error, because Scheme will try to evaluate it, and there is no function called 4. It's ok to use quote when you pass some static data (variable or list) as in your first example. But when you use '(z), this list will be passed to cx-gui-do as is, variable z will not be substituted here, it will stay as a symbol z.

It might sound a bit misterious, so to make this short - when you dynamically create a list, you have to use list function. This should work:

(do ((z 4 (+ 1 z)))
    ((> z 27))
  (cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" (list z)))

EDIT: #f you see when you use do loop is a return value. Every time you evaluate something in Schemes REPL / prompt / Command Interface, return value is printed (ie if you try (+ 1 20) you should get as 21 printed). For do loop you have to provide return expression. If not, it's unspecified what do loop will return (so in some implementations it might be #f meaning false, in other () aka NIL). Nothing wrong is happening there :)

rsm
  • 2,530
  • 4
  • 26
  • 33
  • 1
    Fluent doesn't seem to have the `+1` function, so I reverted to `+ 1`. Other than that the loop worked great! Thanks! (another thing is not working, but that's for another question.) Also, my user profile doesn't seem to have the `+1` function to vote for your answer just yet :( – The Drunken Whaler Nov 18 '19 at 02:25
  • If you can/want to take a look, I'd appreaciate: https://stackoverflow.com/q/58907521/12388640. Thanks again :-) – The Drunken Whaler Nov 18 '19 at 03:11
  • @TheDrunkenWhaler I updated my answer to explain `#f` you get. Unfortunatelly I don't know Fluent, and your second question looks like Fluent related issue. At least Scheme code looks ok there. – rsm Nov 18 '19 at 03:32
  • Thanks for the explanation about the `#f`; it makes sense now! I guess that it may be something related to the timing of the graphical interface or whatnot, and I wouldn't be surprised if it were a Fluent-only problem... This thing of using commands for clicking in graphical interface buttons seem really stupid to me... Thanks for your help anyway! (Just a small correction: Lucky you you don't know Fluent ;-) – The Drunken Whaler Nov 18 '19 at 03:39