UDF: Beginner CFD Training Package — Ep 08
Cylinder Piston Motion
- Lesson
- 08
- Run Time
- 26m 20s
- Published
- Aug 19, 2026
- Category
- UDF
- Course Progress
- 0%
Cylinder Piston Motion (UDF-Driven Dynamic Mesh) — ANSYS Fluent CFD Simulation
Description
This project simulates the motion of a four-stroke engine's cylinder-piston system in ANSYS Fluent, built around a User-Defined Function (UDF) that drives the piston's dynamic mesh motion. Inside an internal combustion engine, the piston moves through four stages — intake, compression, power, and exhaust — while the valves open and close in sequence, and here that reciprocating motion is defined through a compiled UDF rather than a preset option. The simulation captures the complete cycle: the piston descending as the intake valve opens, the flow compressing as the piston ascends, the piston reaching top dead center at the power stroke, and the exhaust valve opening as the piston descends again. Within the User-Defined Functions (UDF): Beginner CFD Training Package, this project combines a UDF with dynamic mesh, showing how custom code drives a moving boundary in a real engine problem.
Methodology
The geometry is created in Design Modeler and meshed in ANSYS Meshing, establishing the computational domain of the cylinder-piston assembly and its valve regions. The piston's reciprocating motion is defined through a compiled UDF applied via the In-Cylinder dynamic mesh option, with the key parameters — crank radius, connecting-rod length, and piston stroke cutoff — specified to govern the piston's kinematic behavior. The UDF implements the full-piston motion function, driving the boundary movement of the piston surface throughout the four strokes. Building on this, rigid body motion is applied to the piston surface and valves, with profiles describing the time-varying valve lift, while deforming and stationary mesh zones are configured to accommodate the moving boundaries without degrading mesh quality. The dynamic mesh model works in conjunction with the UDF-defined reciprocating motion, and the case is solved with a transient approach and solver settings chosen to maintain stability as the mesh deforms and moves through each stroke.
Analysis
Pressure and velocity contours are analyzed throughout the piston cycle, and animations of the mesh deformation and resulting flow behavior are generated to verify the correct operation of the UDF-driven cylinder-piston system across all four strokes. From these results you can follow how the flow is drawn in, compressed, and expelled through the cycle, and confirm the UDF drives the piston and valve motion correctly. By the end of this project, you'll be able to write and compile a UDF that drives piston motion through the In-Cylinder dynamic mesh option, define crank parameters and valve-lift profiles, configure deforming and rigid-body mesh zones, and interpret the pressure and velocity fields of a UDF-driven four-stroke engine cycle.