ANSYS Fluent Customization and Automation
Imagine you are working as a CFD Analyst/ Design Engineer in a leading automotive industry performing year round optimization studies on various aerodynamic aspects of car design. Definitely your job profile would be exciting and challenging but at the same time most of your tasks involve repetitive CFD procedures like same simulation strategy for various design changes. For such an CFD engineer automation and customization would be a great savior.
Since ANSYS Fluent is the most widely used CFD tool globally let us focus into various aspects of customization and automation in ANSYS Fluent. There are different ways in which ANSYS Fluent can be automated.
Some of the regularly used approaches are:
- Automation through journal file
- Automation through Scheme programming
- Automation through UDF (user defined functions)
What is a Journal file ?
A journal file is a text file that contains a set of commands, which when read in ANSYS Fluent would process those commands sequentially. There are 2 ways to create a journal file.
1. Recording journal file from GUI(Graphical User Interface): File > Write > Start Journal
While setting up a case file we can record all commands we gave with GUI or TUI, and we can playback recorded file later on to give same setup. Simplest example is if we create 2 mesh for one geometry (one is fine mesh and another coarser) then we can record journal file while setting up the first case and then we can use this recorded journal file for the second case setup.
2. Writing journal file with TUI (Text User Interface) commands:
In ANSYS Fluent, the menus and commands which are available from GUI are also accessible from TUI, we can write a TUI command in console or else we can write all commands to be executed in a text file and save it with extension .jou and read it as a journal file.
File > Read >Journal
Beginners would find it easy to automate ANSYS Fluent by recording journal file from GUI and writing journal file using TUI commands as these are easiest way compared to other possible automation methods.
Scheme programming:
Scheme is a high level language and a dialect of programming language Lisp. Dialect of programming language is variation or extension of language that does not change its intrinsic nature. Scheme supports operations on structured data such as strings, lists, and vectors, as well as operations on more traditional data such as numbers and characters. While Scheme is often identified with symbolic applications, its rich set of data types and flexible control structures make it a truly versatile language.
Scheme programming can be very effectively used for automation of ANSYS Fluent. We can use it for post processing purpose, to automate whole process of simulation and report creation, as well as it can handle file read/write operations. A recorded journal file follows the syntax of scheme, as it is based on scheme programming itself.
UDF (User defined functions):
A UDF is a program written in ‘C’ language which can be used for implementing additional functions into ANSYS Fluent software during its use. It is basically used to enhance standard features of solver. Using UDF we can give boundary conditions varying with time, execute commands on demand, execute commands at the end of iteration or time step, adjust computed values on once per iteration basis and many more. Simplest example of automation using UDF is changing time step size depending on real flow time or some other property.
Various applications of programming in ANSYS Fluent
Let us discuss the extent of automation that can be done using the above mentioned streams of automation. Using automation a CFD engineer can do the case setup, perform the simulation, collect results, generate reports, analyze the data, carry out modifications in design, change setup, and run simulation again.
In short, a complete optimization study can be automated in Fluent, certainly customizing ANSYS Fluent as per the requirement.
Examples of Automations:
Automating process of taking images in transient simulations. For this we have 2 options, one is to take images after required number of time steps and secondly, save data files at required time intervals and after simulation open these data files to take pictures.
It is very useful to automate whole process of simulation and make it parametric for design of experiments (DOE). For this we need to make a parametric code so that we can change parameters as per our need. This will definitely save a lot of time.
ANSYS Fluent GUI menus or TUI menus can be customized using Scheme programming. ANSYS Fluent allows two-way communication between solver variables and users generated script. This can be effectively used for customizing ANSYS Fluent.
Following video will show you an example of ANSYS Fluent customization based on the above point. We have created one menu button named as ‘LearnCAx’ and in the drop down menu there is a sub menu named as ‘LearnCAx Website’ that on clicking opens LearnCAx website. This video also demonstrates an example of adding a button “Reset-Time” with which we can reset time in a transient simulation.
{modal index.php/en/?option=com_content&view=article&id=100}{/modal}
{modal index.php/en/?option=com_content&view=article&id=100}{/modal}
|
Demonstration on the use of “do loop” in ANSYS Fluent using Scheme programming
Test Case: Post processing of CFD simulation in ANSYS Fluent using Scheme programming (do loop)
Objective:
a) To create 150 iso-surfaces
b) To save 150 images of velocity contours
Scenario:
In this test case we will be using Scheme programming for post processing of CFD simulation. We have done a simulation of flow around buildings, and we need to create an animation of velocity distribution as we climb higher right from the ground. In order to achieve this, we will be taking something around 150 images of velocity contours at different heights and then merging them into a video file. So for this we require 150 iso-surfaces to be created and then to plot velocity contours on them for taking pictures.
Regular way vs smarter way:
Suppose, we do all these manually then it is a very tedious job to do and it’s very time consuming also. This would involve creation of iso-surface using iso-surface dialog box repeatedly. Similarly for displaying contours and saving pictures repetitive use of respective dialog boxes will be required.
But if we write a Scheme file using do loop to create surfaces, display contours and take pictures then it becomes a work of just few minutes.
Following line shows a code written in Scheme for creating 150 planes. For this we have used do loop which is actually similar to for loop of other programming languages.
(Do ((x 1 (+ x 1))) ((> x 150))
(Ti-menu-load-string (format #f "surface/iso-surface z-coordinate z-plane-~a () () ~a" x x))
)
Following Do loop is for displaying contours which are created in last do loop, and take pictures.
Do ((x 1 (+ x 1))) ((> x 150))
(Ti-menu-load-string (format #f "display/set/contours surface z-plane-~a ()" x))
(Ti-menu-load-string (format #f "display/contour/velocity-magnitude 0 5.0"))
(Ti-menu-load-string (format #f "display/save-picture/cont-plane-%4n.jpg"))
)
Following video explains the above written script.
{modal index.php/en/?option=com_content&view=article&id=102}{/modal}
{modal index.php/en/?option=com_content&view=article&id=102}{/modal}
|
Keep visiting this series as more will be coming soon !!!
Blog Co-Author:
Subhransu Majhi
Member of Technical Staff,
LearnCAx
Inspire | Educate | Mentor
Website: LearnCAx.com | Email: subhransu@cctech.co.in
1) Scheme Programming by Mirko Javurek (German Document) : http://willem.engen.nl/uni/fluent/documents/external/scheme-programmierung.pdf
2) Translation of above German Document made by Tiago Macarios : http://hpc.hud.ac.uk/w/images/2/2b/Fluent_Scheme_Programming_Reference.pdf
3) ANSYS Fluent User Manual
The Author
{module [319]}
The Author
{module [312]}