Designing customization in CFD can be tricky, especially when you want a user-friendly interface to control parameters. Using a custom GUI in Fluent combined with Scheme and UDFs provides an elegant solution for engineers and researchers.
Fluid flow in mixed tanks, such as bioreactors, is encountered across a wide range of industrial applications. These systems are fundamental to processes in the biochemical, pharmaceutical, food, and chemical industries, where effective mixing is required to ensure uniform distribution of species, heat, and momentum. The resulting flow fields are typically complex, involving strong turbulence, multiphase interactions, and non-Newtonian behavior, all of which significantly influence process performance, product quality, and scale-up.
In multiphase or bioreactor simulations, there may be instances when inlet flow may need to vary in time — for example, sinusoidal pulsing or square-wave injection — to mimic realistic operating conditions or to optimize mixing. In CFD, this can be achieved in Fluent using expressions or UDFs. However, both of these approaches require a bit of learning. If we are to deploy a model to be tested by multiple users at different levels of experience, it may be advantageous to provide a simple pathway for modifying the model without the need or risk of modifying expressions or code.
Hard-coding parameters in a UDF makes it inflexible. In UDF, changing injection type or amplitude requires recompilation. Non-technical users may struggle to modify UDFs safely without a clear knowledge of how the code works in its entirety. These bottlenecks can result in slower iteration, error-prone workflows, and limited parametric studies.
A potential solution is to create easy graphical user interfaces (GUIs) that allow for a more convenient user experience. Fluent allows for the creation of custom-built GUIs for easy control of models. To build such tools, Fluent requires the use of schemes. These are the important features to build GUIs in Fluent:
1. Scheme RP variables
Define parameters like amplitude, period, mean velocity, and injection type.
These variables can be numbers (real or integer) or boolean flags. They are readily accessible to UDFs and TUI.
| ;RP Variable Declarations (make-new-rpvar 'user/amplitude 0.5 'real) (make-new-rpvar 'user/period 0.5 'real) (make-new-rpvar 'user/type 0 'int) (make-new-rpvar 'user/u_mean 2.0 'real) (make-new-rpvar 'user/radiobutton1 #f 'boolean) (make-new-rpvar 'user/radiobutton2 #f 'boolean) |
2. Custom GUI
Expose Scheme variables to users in Fluent’s GUI.
Users can set amplitude, period, and switch between injection types without editing code. The definition of each field in the GUI must be written in a .scm file. The following snippets show where the RP variables are defined in the GUI and how their values are entered.
| ;Update-CB Function, Invoked When Dialog Box Is Opened ((define (update-cb . args) (cx-set-toggle-button user/radiobutton1 (rpgetvar 'user/radiobutton1)) (cx-set-toggle-button user/radiobutton2 (rpgetvar 'user/radiobutton2)) (cx-set-integer-entry user/amplitude (rpgetvar 'user/amplitude)) (cx-set-integer-entry user/period (rpgetvar 'user/period)) (cx-set-integer-entry user/u_mean (rpgetvar 'user/u_mean)) |
(set! user/buttonbox2 (cx-create-button-box user/box1 "Pulse Injection Type:" 'radio-mode #t 'row 1)) (set! user/radiobutton1 (cx-create-toggle-button user/buttonbox2 "Sinusoidal")) (set! user/radiobutton2 (cx-create-toggle-button user/buttonbox2 "Square-Wave")) (set! user/u_mean (cx-create-real-entry user/box2 "Average Velocity [m/s]" 'row 1)) (set! user/period (cx-create-real-entry user/box2 "Period [s]" 'row 2)) (set! user/amplitude (cx-create-real-entry user/box2 "Amplitude" 'row 3)) |
3. UDF that reads Scheme variables
A single UDF updates inlet velocity at each time step based on the values of the RP variables defined by the user.
Supports both sinusoidal and square-wave inlet profiles, as described in the equations below
Note that the example shown here is for a relatively simple application. In problems that require heavy UDF usage to model complex physical problems, the use of schemes to create GUIs can be even more relevant for easier tuning and control. In this example, once the scheme file has been loaded into Fluent, a new menu option appears ("Set Pulse Injection"). By clicking on it, the user can open a dialog box, which will contain data inputs to define the pulse injection profile (average velocity, period and amplitude), and the type of injection (sinusoidal or square-wave). Other options can also be created and coded for in the schemes and UDF.
Note that the UDF must be able to read all of the variables declared and used by the scheme, and be compiled successfully for this approach to work. Additionally, the velocity of the inlet must be set to udf profile with the hooked UDF.
While some of these efforts could be carried out using expressions instead, the combination of UDF + Schemes makes it easy to switch between different injection types and settings with a few mouse clicks. This is especially important when deploying complex models that require the use of multiple UDFs and variables, but where not all the users are necessarily familiar with coding syntax for UDFs. It also makes it easy to modify parameters used by the UDF without the need to modify the code and re-compile.
The resulting mass flow for a sinusoidal and square injections can be visualized on the animation below. Note that the code ensures that the inlet velocity can never be negative, which would occur if amplitude is greater than 1. This guarantees that the minimum mass flow rate that can be achieved is always 0 kg/s.
The scheme file and UDF used for this simulation can be downloaded here.
Ozen Engineering Inc. leverages its extensive consulting expertise in CFD, FEA, optics, photonics, and electromagnetic simulations to achieve exceptional results across various engineering projects, addressing complex challenges.
We offer support, mentoring, and consulting services to enhance the performance and reliability. Trust our proven track record to accelerate projects, optimize performance, and deliver high-quality, cost-effective results. For more information, please visit https://ozeninc.com.
If you want to learn more about our consulting services, please visit: https://www.ozeninc.com/consulting/
CFD: https://www.ozeninc.com/consulting/cfd-consulting/
FEA: https://www.ozeninc.com/consulting/fea-consulting/
Optics: https://www.ozeninc.com/consulting/optics-photonics/
Photonics: https://www.ozeninc.com/consulting/optics-photonics/
Electromagnetic Simulations: https://www.ozeninc.com/consulting/electromagnetic-consulting/
Thermal Analysis & Electronics Cooling: https://www.ozeninc.com/consulting/thermal-engineering-electronics-cooling/
Fractional Volume Method for Stirred Mixing Time Evaluation with CFD
Creating a Reduced Order Model for Vortex Prediction in Stirred Tank
An overview about Mixing Processes using ANSYS CFD and Rocky-DEM
The Role of CFD on Bioreactor Scale Up Process
How to Predict Performance of Bioreactors and Mixing Tanks
Getting Started with Ansys FreeFlow: Modeling a Stirred Tank