Scheme Language in Fluent.ppt
PERA Global, ShanghailA dialect of LISP, a very old programming language.lIts grammar is very simple and its commands have a general form like: (Command Name, argument1,argument2.).lThe Scheme Command in FLUENT:1) Run simulation processes automatically(Journal file) 2) Extend the Interface of Fluent. 1.Arithmetic Functions+ - * / , entspricht UPN, mehr als 2 Argumente mglich: (+ 2 4 5) 11 (/ 6 3) 2 (/ 2) ; similar to (/ 1 2) 0.5 (abs x), (sqrt x), (expt x y) = x y, (exp x) = e x, (log x) = ln x, (sin x), (cos x), (atan x), (atan x y) = arctan(x/y), Integer(!)-Functions: (remainder 45 6) 3 (modulo 5 2) 1 (truncate x), (round x), (ceiling x), (floor x), . (max x y .), (min x y .) (apply max (1 5 8 3 4) ; find the maximum in a list 8 2.Global and Local VariablesGlobal variable defintion: (define x 3) (+ x 1) 4 No difference in variable types(integer,real,string).Changing variable values is not possible in functions, which only local varialbes are valid:(set! x 1) to change variable values (display x) or (write x) to output variable values Integer (2), Float (2.5), Boolean (#t fr true, #f false) Strings (this is a text string) and Symbols: symbol, for example.: (define x this-is-a-symbol) Global variables and self-defined functions are valid until the end of Fluent. Lokale Scheme-Variablen Local varable definition:(let (var1 value1) (var2 value2) .) ;variables are valid only in this scope)3.“Format“ command (format #f format var1 and var like printf in C, . var1 var2 . ) l Tilde () is used instead of %: a general format (Strings without ) d Integer 04d always 4 digits with enough 0 before (5 wird zu 0005) f floating number4.2f 1.2 -1.20 s String with (format #f string: s ! text) becomes string: text ! There are a few of ways to call scheme in FLUENT.1. Input the command in the text interface There are a few of ways to call scheme in FLUENT.The scheme command can be also input in menu “Solve/Execute-Commands”, which will be executed by each iteration or time step. There are a few of ways to call scheme in FLUENT.Call in FLUENT menu using “File/Read/Scheme” to read a .scm file.If the scheme file is saved as .fluent and in the same directory as the case file, then it can be automatically loaded when the case file is read.FLUENT commands can be called in Scheme in two ways: Command in text interface(ti-menu-load-string “display/contour temperature 30 100”)It will return “#t” if success, “#f” if failureThis is the normal and fast way to use fluent commands GUI command(not a common way)These commands are used in journal file, for example:(cx-gui-do cx-activate-item “Velocity Vectors*PanelButtons*PushButton1(OK)”) Call UDF in Scheme:(%udf-on-demand udf-eod-name) How to use Scheme funtions in UDF is moment not known. C funtion CX_Interpret_String(scheme-command-string), which is declared in Fluent.Inc/fluentX.Y/cort, can interprete scheme-command-string, but can not access the environmental variables. RP variables (used in text interface commands)For example, the following command gets the simulation time (rpgetvar flow-time) 0.1Then comes the command to set the simulation time: (rpsetvar flow-time 0)All RP variables are defined in case file. CX variables (only used in GUI commands)The following examples are about the settings of the color map: (cxgetvar cmap-list)0.1 (cxsetvar def-cmap “rgb”) (rp-var-define name default-and-init-value type #f) For example: (rp-var-define udf/var1 0 real #f) The way to get the info about the variable: (rp-var-object udf/var1) (udf/var1 0 real #f 0) (rp-var-object udf/var2)#f real RP_Get_Real(char *s) long RP_Get_Integer(char *s) char *RP_Get_String(char *s) boolean RP_Get_Boolean(char *s) void RP_Set_Real(char *s, real v) void RP_Set_Integer(char *s, real v) void RP_Set_Boolean(char * s, boolean v) void RP_Set_String(char *s, char *v) void RP_Set_Symbol(char *s, char *v)for example:var1=RP_Get_Real(“udf/var1”)RP_Set_Real(“udf/var1”,3.2) PaintSim is written in Scheme to run simulation processes automatically and conveniently in a flow-line way. It can also be used for post-processing of simulation results.u Display the content of the main window after being enableduDisplay the buttons in the bottom of the main windowuStart Gui uStart to define the window layoutuDefine the button events uCreate the frames and other componentsuShow the panel after all components are defined:uAdd one menu item to Fluent (rpsetvar paintsim/target_id 2) (%rpgetvar paintsim/target_id) (rpsetvar paintsim/nrtrack 30) (%rpgetvar paintsim/nrtrack) (rpsetvar paintsim/fthick_name fthick_test.txt) (%rpgetvar paintsim/fthick_name) Radius_Needle=RP_Get_Real(lacksim/radius_needle); Roughness_Needle=RP_Get_Real(lacksim/roughness_needle); PaintSim must be loaded first. Once it is loaded, all the variables have their own default values. However, if the case-data files are saved after these variables are modified, the modified values will also be saved in case-data files. Then, next time when the case-data files are re-loaded, these variables will have the values saved in case-data files, but not the default values. In batch-file mode, the FLUENT GUI can not be used. This is already considered in the code of PaintSim. At this time, the menu will not be loaded, but all the variables can be changed by the command input into the text-command interface of FLUENT. In batch file, the scheme file can be loaded with the similar form like “load paintsim.scm”. Actually, you can also use the scheme command directly in batch files. For example, “(rpsetvar paintsim/target_id)” It is used to set the ID number of the target wall.