Parametrizing Ansys Fluent with python in linux

Question:

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.

Asked By: coyote

||

Answers:

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 !

Answered By: coyote

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

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 components are parameter_2 and parameter_3 because I didn’t choose sensible names. 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 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.

Answered By: Ed Smith
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.