Videos > Exploring Parametric Studies with PyFluent: Gas–Liquid Stirred Tank Simulation
Sep 19, 2025

Exploring Parametric Studies with PyFluent: Gas–Liquid Stirred Tank Simulation

Hello, today I would like to demonstrate the steps to set up an ANSYS Fluent simulation. For this example, I have already set up my Fluent base case simulation with much of the physics configured. Alternatively, you can perform this setup in PyFluent using Python scripts, but I will walk through the setup in Fluent itself.

Model Overview

This is a stirred tank reactor model. We don't have reactions; we only simulate the flow of water and air. We use the Eulerian model to represent the two phases:

  • Primary Phase: Water
  • Secondary Phase: Air, represented as one-millimeter bubbles

Phase Interaction

  • Forces enabled for drag coefficient and surface tension
  • Mass transfer between phases, allowing species to move from one phase to another (e.g., oxygen dissolving into water)
  • Mass transfer coefficient models for CO2 and phase exchange

Mixture Preparation

Before setting up mass transfer, prepare your mixtures:

  • Air Mix: Composed of oxygen, CO2, and nitrogen
  • Water Mix: Includes water liquid, CO2, and O2 in the liquid phase

Boundary Conditions

  • Water Inlet: Mass flow inlet from the top
  • Air Inlet: Velocity inlet from a vertical tube

The goal is to observe how the mixture of water and air affects overall mixing. We also use a moving reference frame for the impeller:

  • Region: Fluid MRF1
  • Speed: 20 radians per second
  • Rotation Axis: Z-axis

Simulation Setup with PyFluent

We will run the simulation for a number of iterations using a steady-state model. Key parameters include:

  • Rotational Velocity: Angular velocity of the impeller
  • Air Velocity: Defined for the phase air, initially set to 0.2

Python Script Overview

The script is adapted from the PyFluent example library for MixingTank. Key steps include:

  1. Import the MixingTank case file
  2. Define the number of iterations and key parameters as numpy arrays
  3. Assign parameters to the simulation (e.g., inlet gas velocity and angular velocity)
  4. Initialize the simulation and run calculations
  5. Save case and data files with parameter names
  6. Generate contour files for water velocity magnitude and O2 in the water phase

Post-Processing

Additional post-processing includes generating report definitions for:

  • Torque on impeller walls
  • Average strain rate
  • Average dissipation rates

These reports are volume averages, specifically looking at the water phases. The files are named according to the parameters being varied for easy identification.

Conclusion

This setup can be applied to any CFD application, making it easy to script actions for a simulation. It's particularly useful for parametric studies and complex studies involving different parameter levels. You can also use Python's visualization tools for further post-processing.

For more information, please contact us at Ozen Engineering, Inc..

[This was auto-generated. There may be mispellings.]

Exploring Parametric Studies with PyFluent: Gas–Liquid Stirred Tank Simulation Hello, today I would like to show steps on how to set up an ANSYS Fluent simulation. For this example, I already set up my Fluent base case simulation with a lot of the physics already set up.

You can also do that alternatively in PyFluent using Python codes, Python scripts, but I'm going to go through the setup in Fluent itself. So this is a stirred tank reactor model. We don't really have reactions; we only have a flow of water and gas as air.

And basically, we are using the Eulerian model to represent the two phases, and if you see here, basically we have the Eulerian model set up; we have two phases: water as my primary phase and air as my secondary phase, represented as one-millimeter bubbles.

For phase interaction, we have forces enabled for drag coefficient and surface tension, as well as we have mass transfer between the different phases. So species in water and air can basically go from one phase to another.

Oxygen, for example, can be dissolved into water, or if water has excess oxygen, some of it can go into air. The mass transfer coefficient is the same as the liquid phase to the gas phase. It's usually ordered that way, but it can go either way.

So likewise, we have the mass transfer coefficient models for CO2, phase exchange between the two phases. So before you actually are able to set up this mass transfer, you need to prepare your mixtures. So basically, we have an air mix that is composed of three species: oxygen, CO2, and nitrogen.

And for water, likewise, we need to have water liquid and CO2 and O2 in the liquid phase as well. And basically, these are the key setups for this model. Likewise, we have boundary conditions. So we have two inlets: one inlet is the water inlet that's coming from the top here.

This is the water input, and if I display the water inlet, it might be easier to visualize. Water is coming from the side from the top, and it basically drops. And air is coming from this tube that's going along, going vertically down using a velocity inlet, and water is using a mass flow inlet.

So basically, the idea is we want to see how the mixture of water with air affects the overall mixing, so how this setup works.

We also have, I should mention, the moving reference frame for the impeller, so we have a region around the impeller, which is called fluid MRF 1. And if I double-click here, you can see how it's set up.

So we have a speed of 20 radians for this case, but we are going to actually vary this parameter using our PyFluent script, and basically, the rotation axis direction is in the Z-axis, as well as we have motion for the walls of the shaft.

So, once we run the simulation, we are going to be able to see things like the O2 in the liquid phase, how it gets dissolved into the liquid, into the water phase. We can also look at things like CO2, for example. Here we have a pretty even distribution.

We can look at things like the velocity contours to look at the impact of the impeller. So we expect this to change if our rotational velocity changes as well.

So basically, what we're going to do in our PyFluent simulation is we're going to run the simulation for a number of iterations using a steady-state model.

I'm basically assuming a steady state, and once we do that, we are going to be able to plot some contours, some results to visualize the impact of different key parameters. So the one parameter I mentioned before is the rotational velocity, angular velocity of the impeller.

Another parameter is the air velocity, which I define for the phase air here, which is defined as 0.2, but I'm going to vary that value using the script as well. I should open that again to show the species.

So basically, we're assuming that we have air with 21% oxygen, a small portion of CO2, around 420 ppm. So basically, this is the setup that we have here. Once we set up the simulation, we can save it directly, save the case and the data file.

But here, what we care the most about is the case because we're going to run a fresh simulation; we're going to initialize for each case that we run. So here is the Python script, as you can see.

This is adapted from the PyFluent example library for MixingTank, and this is where I actually import my file, the MixingTank case file, which I read, and then basically, after I read, I define the number of iterations and I define my key parameters here as numpy arrays.

So basically, here, I modified this code slightly, but basically, we're running from 0.2, 0.4, 0.6, and 0. 8. So these are the four, basically four gas velocities, and we can run even more.

So the following is the first step of the simulation, which is to define the gas velocity and rotational velocity. This is where we assign the parameters to the simulation. We go into the Inlet one, which is for the velocity inlet that I showed before.

Define as AirInlet, so it has to match the name in your case file. Inlet for air, again, this is where we actually link the inlet velocity in the case file to the value that I have defined here.

So you can see inlet gas velocity is the value that you're getting from the loop, and that you're assigning to the boundary.

We also do the same thing for the MRF, so here we have to loop through the zones and identify the zones that have MRF defined in their name, and then from that, we can assign the angular velocity and radians per second to that fluid zone, to the moving reference frame zone.

Likewise, we do the same for the shaft. Any walls that have shaft in their names are selected, and we apply the angle of speed parameter to them.

So we then initialize our simulation using this script, and then we can run calculations using the same, basically I wrote this twice, but basically, we don't need to, but the idea is we run, we set up the run calculation, so this is not exactly where we run, we run it right here.

This is just a parameter called run calculation where we define some properties like the iteration count and so on. And then this is where we, before I actually run, I save a case in data that's been initialized already.

So this is where I save the case in data with the names of the parameters that I want. I generate the contour files for the water velocity magnitude and the O2 in the water phase. This is basically how to set up the image files from the contours.

Look that I put the names of the key variables that I'm varying in the names of the files, so that I can go back and easily identify what that file is for.

You could also do additional post-processing, so this could be all included in the same script, but basically, this is showing how to do post-processing to get some report definitions, some actual values.

So basically, I'm looking here at the torque on the impeller walls and also at the average strain rate and average dissipation rates. So basically, this is a single value for each iteration for the whole domain.

So basically, this is what it's doing, so we are creating a report definition here for example for the average dissipation rate. The report is a volume average, looking at the water phases specifically. So basically, here is where we get the report file itself.

We name the file according to the parameters that we are varying as well, so that it's easy to find them. And then it generates a report using the average dissipation rate. Similarly, you can look at the average strain rate as well as the torque.

So basically, these are just report definitions that you can use for further post-processing and to plot graphs and to look at the relationship of these key parameters on the performance of your stir tank. So this could be applied for any other type of application in CFD.

It makes it fairly easy to script your actions for a simulation. It's especially useful for parametric studies, for more complex studies involving different levels of parameters.

Here, for example, I did a full factorial model, but different design of experiment approaches can be implemented as well. You can also use Python's visualization tools to do further post-processing, which is very cool. Please contact us at https://ozeninc.com/contact for more information.