3

I'm trying to do a parametric study in Ansys fluent through python. The idea is to calculate some parameters before feeding them to fluent as boundary conditions and initial conditions.

I have searched wide and far but could not come into any pertinent information... maybe i'm not looking with the good keywords.

Or is there an equivalent of ANSYS Parametric Design Language (APDL) for fluent ? I can only find information for mechanical.

Do anyone could guide me in the good direction or somewhere to go look for more information.

P.S. I could not find any information in CFD-online, ansys site or here in stack overflow.

coyote
  • 194
  • 13

2 Answers2

4

So after some long search around the global internet I found how to do it. There are two main forms of doing it :

  • Via Ansys Workbench
  • Directly into Ansys Fluent

Ansys Workbench


Directly with scripting, I did not used this method hence this is what I understood without trying or testing it. You can run the workbench in batch mode with the following bash command :

runwb2 -B -R "path/script.py"

Where -B stands for batch mode and -R excecutes the specified script.

An example and explanations can be found here : Scripted CFD simulations and postprocessing in Fluent and ParaVIEW

Ansys Fluent


TL;DR : Use Journals and python to modify journals, then run fluent through python.

First the simulation must be prepared with fluent GUI. You need to fix all non variable parameters as well defining monitors. You save all that information into a case file.

Once done that you must create a template with the commands to initialize the calculations. The easiest way is to search in the net and try everything in the TUI at fluent. Once everything has been validated, you create a template (The easiest way is to use jinja2)

Finally, a simple loop over the parameters to test with the following bash command with python can do magic:

# Running fluent
bashCommand = "fluent 3ddp -i "+ journal_output + " >& outputfile &"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

It works really well and once you get use to Fluent commands it is quite easy !

coyote
  • 194
  • 13
  • 1
    Only seen this today - not that I'd have had time to add anything useful. Just a note to say thank you for following up your query with reporting your research efforts. It may be something I'd use myself way down the line! – Amiga500 Aug 25 '21 at 13:45
  • I've been working even more, just need to find the time to update it a little bit more. Nevertheless, Ansys workbench is not easy to automate unless you only use Ansys workbench... – coyote Aug 25 '21 at 14:48
1

Another way is to create parameters in Fluent for whatever you want to vary. For example, I wanted to vary the boundary conditions for an aerofoil simulation to change the angle of attack, e.g.

enter image description here

where blue arrows need to be set to different components to give different angles of attack, something like:

enter image description here

First make sure your case runs and gives sensible results setting the boundaries as numbers. Then, the two components of velocity in the boundary conditions can be set to parameters from the downwards arrow on the right, choose New input Parameter for each and give sensible names,

enter image description here

Here my two velocity components are Ux and Uy. Then go to the parametric tab, click Add Design Point a few times and export to a csv file,

enter image description here

Then you can simply copy the range of points you want to run, overwriting values in the csv file and adding extra rows as needed.

enter image description here

Then reimport this into Fluent. To get a useful output, here I wanted the drag/lift coefficient, you want to create a report item in the Report Definitions under Solution

enter image description here

be sure to tick

enter image description here

so this appears on the Parametric study tab. Then provided the individual case ran, the Update All button should give the results of the parameter study. It's worth noting, in my case at least, reported drag and lift forces assume X=1 Y=0 and X=0 Y=1 respectively so may need some rotation base on the inflow angle...

Ed Smith
  • 12,716
  • 2
  • 43
  • 55