在 Scheme (Fluent) 中 (do ...) 内运行代码的执行方式与循环外不同 [英] Running code inside (do ...) in Scheme (Fluent) executes differently than outside the loop

查看:66
本文介绍了在 Scheme (Fluent) 中 (do ...) 内运行代码的执行方式与循环外不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的上一个问题的续集:

我正在使用 ANSYS Fluent 程序进行 CFD 模拟.这个程序允许使用所谓的日志文件对模拟设置进行一些部分自动化,我才知道这个日志文件是用 Scheme 编写的.不幸的是,我什至从未听说过 Scheme,我只知道它是一种 Lisp 方言(我也对此一无所知).

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

我正在尝试通过使用循环自动为我的模拟设置一堆参数来自动化一些无聊的任务.如果我从 Fluent 的命令界面(模注释)运行此命令:

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 (modulo comments):

; Select item in list
(cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" '( 4))
; (Also?) select item in list
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*List2(Zone)")
; Open dialog window for the selected item
(cx-gui-do cx-activate-item "Boundary Conditions*Table1*Table3*Table4*ButtonBox1*PushButton1(Edit)")
; Set the "volume fraction" parameter to 1
(cx-gui-do cx-set-expression-entry "Velocity Inlet*Frame3*Frame6(Multiphase)*Table1*Table16*ExpressionEntry1(Volume Fraction)" '("1" . 0))
; CLick OK button to close window
(cx-gui-do cx-activate-item "Velocity Inlet*PanelButtons*PushButton1(OK)")

它按预期执行:它从下拉列表中选择一个项目,为该项目打开一个对话窗口,将参数的值从 0 更改为 1,然后关闭该窗口.如果我将上面的内容包装在一个循环中以循环遍历列表中的项目,并将 '( 4) 替换为 (list z):

it does as expected: It selects an item from a drop down list, opens a dialog window for that item, changes the value of a parameter from 0 to 1, and then closes that window. If I wrap the above in a loop to cycle through the items in the list, and replace the '( 4) by (list z):

(do ((z 4 (+ 1 z)))
    ((> z 27))
  (cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" (list z))
  (cx-gui-do cx-activate-item "Boundary Conditions*Table1*List2(Zone)")
  (cx-gui-do cx-activate-item "Boundary Conditions*Table1*Table3*Table4*ButtonBox1*PushButton1(Edit)")
  (cx-gui-do cx-set-expression-entry "Velocity Inlet*Frame3*Frame6(Multiphase)*Table1*Table16*ExpressionEntry1(Volume Fraction)" '("1" . 0))
  (cx-gui-do cx-activate-item "Velocity Inlet*PanelButtons*PushButton1(OK)"))

程序从列表中选择项目并打开对话框窗口(所以我认为前三行 cx-gui-do 没问题),但它没有设置的值体积分数"设置为 1 也不会关闭窗口.此外,在循环结束时,一个 #f 被打印到命令窗口,我想是 Scheme 告诉我出了什么问题,但我不知道是什么.

the program selects the item from the list and opens the dialog window (so I suppose the first three cx-gui-do lines are okay), but it doesn't set the value of "Volume Fraction" to 1 neither does it close the window. Also, at the end of the loop, an #f is printed to the command window, which I suppose is Scheme telling me something went wrong, but I can't figure out what.

为什么当我将代码放入循环中时代码的行为会发生变化,即使使用循环变量的部分(显然)正在工作?最后打印的#f是什么?

Why does the behaviour of the code change when I put it inside the loop, even though the part that uses the loop variable is (apparently) working? And what is the #f printed at the end?

推荐答案

我正在做一个类似的项目,这些奇怪的问题也发生在我身上.唯一的区别是,我使用的是普通的 TUI 命令,而不是这些 CFX 命令.

I am working on a similar project and these strange issues happened to me as well. The only difference is, I am using plain TUI commands not these CFX commands.

Ansys Fluent 没有关于 Scheme 的明确标准,因此通常很难找到可靠的文档或解释问题.一位 Ansys 工程师告诉我,他们使用MIT Scheme 3 和 4 的混合物".

Ansys Fluent does not have a clear standard regarding Scheme, so it is often a bit difficult to find reliable documentation or explain issues. I was told by an Ansys Engineer that they use "a mixture of MIT Scheme 3 and 4".

我不得不给你一些建议,这对我有帮助.

I have to suggestion for you which helped me from time to time.

首先尝试将您的命令包装在 (begin .....) 语句中.

First of all try to wrap your commands in a (begin .....) statement.

(do ((z 4 (+ 1 z)))
    ((> z 27))
     (begin
      (cx-gui-do cx-set-list-selections "Boundary Conditions*Table1*List2(Zone)" (list z))
      (cx-gui-do cx-activate-item "Boundary Conditions*Table1*List2(Zone)")
      (cx-gui-do cx-activate-item "Boundary Conditions*Table1*Table3*Table4*ButtonBox1*PushButton1(Edit)")
      (cx-gui-do cx-set-expression-entry "Velocity Inlet*Frame3*Frame6(Multiphase)*Table1*Table16*ExpressionEntry1(Volume Fraction)" '("1" . 0))
      (cx-gui-do cx-activate-item "Velocity Inlet*PanelButtons*PushButton1(OK)")
     )
)

这经常为我解决这些问题.

This often solved these kind of problems for me.

其次,再次自行执行这些命令,并特别注意您在菜单中的最终位置.您可能会卡在某种子菜单"中,您必须先退出才能做其他事情.我希望你能从下面的例子中明白我的意思,它可以在没有退出"的情况下工作

And secondly execute these commands on its own again and pay special attention to where you end up in the menu. You might get stuck in some kind of "submenu" which you have to quit before you do something else. I hope you get my point from the following example, which would work without the "quit"

/display objects 创建网格汽车表面-列表 (car) 退出

/display objects create mesh car surfaces-list (car) quit

这篇关于在 Scheme (Fluent) 中 (do ...) 内运行代码的执行方式与循环外不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆