Porous Media: Intermediate CFD Training Package — Ep 01
Source Macro UDF: Momentum Source Term
- Lesson
- 01
- Run Time
- 18m 22s
- Published
- Sep 12, 2026
- Category
- Porous
- Course Progress
- 0%
Source Macro, UDF, Momentum Source Term CFD Simulation
Description
This project simulates water flow through a channel containing a porous medium using a custom User-Defined Function (UDF) in ANSYS Fluent, demonstrating how UDFs can accurately capture porous media effects without relying on the software's built-in porous zone options. The 3D geometry was designed in Design Modeler and meshed in ANSYS Meshing using a structured grid totaling 256,000 cells.
Methodology
This simulation modifies the momentum equation directly to represent the presence of a porous medium along the flow path, implementing a custom source term specifically within the z-direction momentum equation using the DEFINE_SOURCE macro. The source term itself is formulated as a function of both velocity and position, with its derivative also computed and supplied to the solver to maintain numerical stability throughout the solution process.
Building and applying this UDF involves writing the custom source term equation, implementing it through the DEFINE_SOURCE macro, compiling and loading the resulting UDF into ANSYS Fluent, and configuring the flow model to reference this custom source term function in place of a standard porous zone definition.
Conclusion
Results include 2D and 3D pressure contours, pressure gradient visualizations, and longitudinal pressure change plots along the channel. These results confirm that the custom source term successfully reproduces the expected pressure drop behavior characteristic of flow through a porous medium, validating this UDF-based approach as a flexible alternative to built-in porous modeling options.
This technique offers particular value where standard porous zone settings fall short of representing more specialized or custom porous media behavior — relevant to applications ranging from groundwater flow to industrial filtration — and provides a foundation for extending into more advanced scenarios, such as multiphase flow through heterogeneous porous media, coupled heat transfer and chemical reactions within porous flow, or dynamically adaptive source terms representing time-varying porous media behavior.