Getting started with Fluent (6.3) batch files

If you have to do any serious amount of CFD work with Fluent you will probably do a lot of repetitious stuff, especially so in parametric studies with Fluent. E.g. if you have to simulate a flow and get the results for each of the turbulence models (that are available in Fluent) and find out which turbulence model gives better results. Doing this from Fluent GUI repeatedly would be really frustrating, not to mention, time consuming. One way to automate Fluent might be to use the journal files (to record and play back) but the journal files are too fragile. What I mean by that is, it breaks down too easily, like, when one of the models diverges. Then you have to figure out how to continue from there.

Fortunately, to solve these problems, Fluent has a really cool Command Line Interface (CLI). The CLI uses, and is written in a dialect of Lisp called Scheme. Not familiar with Scheme? Don’t sweat it. CLI is simple and inCLItive enough to grok quickly. You can run the CLI commands by opening Fluent and typing them at the command prompt or you can create a script/batch file containing all the CLI commands and run it for repetitive tasks. All right, enough talk, let’s see some examples.

Let’s start by reading a case file into fluent using CLI.

/file/read-case example.cas ‘reads the case file named example.cas

Want to read a case and the associated data file? No problem.

/file/read-case-data example.cas ‘reads example.cas and example.dat

While the above commands work perfectly fine, fluent has a really smart pattern matching in CLI. i.e you can abbreviate the CLI commands and Fluent will try to understand it based on pattern matching, which will be clear in a minute.

/file/rc example.cas
/file/rcd example.cas

Or, taking it further,
rc example.cas
rcd example.cas

To change the turbulence model to RSM
/define/models/viscous/reynolds-stress-model yes
Or, just,
/def/mod/vis/rsm y

Note that the yes (or y) is an argument for the /def/mod/vis/rsm command, to confirm the enabling of the RSM model. In CLI, each command might have zero, one or multiple command arguments. The arguments might need to be numbers or character strings or Boolean or a list of values. More on this later.

To enable enhanced wall treatment,
/define/models/viscous/near-wall-treatment/enhance-wall-treatment yes
Or, just,
/def/mod/vis/nwt/ewt y
All right, I’ll stop beating the abbreviation hammer now.
To run a 1000 iterations,
/solve/iterate 1000

As you can see from the above examples, the CLI command should be very inCLItive from the way you’d accomplish the same task through the menu bar in the GUI. And you don’t have to remember all these commands and their arguments. You can just explore it by firing up fluent GUI and pressing enter at the command prompt. The character ‘>’ is the command prompt in Fluent GUI. You can see how one could find the command to set the turbulence model in the figure below.


Now that you got your feet wet, let’s see a complete batch file that can be used to run a case file (init.cas in this example) with various turbulence models.
*************************batch.jou******************************
/file/rc init.cas
/solve/initialize/compute-defaults/velocity-inlet inlet
/solve/initialize/initialize-flow
/solve/iterate 5000
/plot/plot yes "Nu1-ske-ewt.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-ske-ewt.cas

/define/model/viscous/ke-rng y
/solve/iterate 5000
/plot/plot yes "Nu1-rngke-ewt.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-rngke-ewt.cas

/define/model/viscous/ke-realizable y
/solve/iterate 5000
/plot/plot yes "Nu1-realke-ewt.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-realke-ewt.cas

/define/model/viscous/kw-standard y
/define/model/viscous/kw-shear-correction y
/solve/iterate 5000
/plot/plot yes "Nu1-skw-sfc.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-skw-sfc.cas

/define/model/viscous/kw-sst y
/solve/iterate 5000
/plot/plot yes "Nu1-sst.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-sstkw.cas

/define/model/viscous/rsm y
/define/model/viscous/rsmlps y
/define/model/viscous/rsm-solve-tke y
/define/model/viscous/rsm-wall-echo y
/define/model/viscous/nwt/ewt y
/solve/iterate 5000
/plot/plot yes "Nu1-lpsRSM-ewt.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-lpsRSM-ewt.cas

/define/model/viscous/rsm-omega-based y
/solve/iterate 5000
/plot/plot yes "Nu1-lrso-sfc.xy" yes no no nusselt no no x-over-w bot_wall_1 bot_wall_2 ()
/file/wcd flatplate1-lrso-sfc.cas
exit

****************************batch.jou******************************
Once you have this file created, you can create a case file init.cas with everything other than turbulence model set. Then all you have to do is run

$ fluent 2d –g -i <batch.jou> output &
$

This will read the init.cas file set the turbulence model, run a few iterations and save the result. This will be repeated for various turbulence models as specified in the batch.jou file.This is only the tip of the iceberg. You can do some funky stuff with the scheme constructs like looping, etc. you can use shell scripting too to generate the fluent batch files. E.g in situations where you want to run all the case files in a specific directory, u can use shell scripting to loop through all the case files in the directory and generate the CLI code for running them in fluent. I’ll try to write another blog post on some advanced scenarios. Hope this helps.

1 comment:

Unknown said...

Hello, thanks for your blog on TUI's in Fluent, they're very helpful. Just wondered if you know more advanced commands for opening the particle tracking panel, releasing a particle from an injection but writing the data to file NOT displaying in GUI's. I can do it using the GUI but its not clear how to do it with TUI - some commands are just not there!

My email is mecarlg@yahoo.co.uk

Hope you have time to help, cheers,

Carlos.