Dynamic Mesh: Beginner CFD Training Package — Ep 08
Reciprocating Motion: CG-Motion Macro
- Lesson
- 08
- Run Time
- 18m 20s
- Published
- Aug 13, 2026
- Category
- Dynamic Mesh
- Course Progress
- 0%
CG-Motion Macro, UDF, Reciprocating Motion — ANSYS Fluent CFD Simulation
Description
This project simulates a cubic object undergoing reciprocating motion within a fluid domain using the CG-MOTION macro and the dynamic mesh capabilities of ANSYS Fluent. Where earlier dynamic-mesh cases prescribe motion through built-in options, this project shows how to define the motion yourself through a User-Defined Function (UDF) — the programmable, fully flexible way to drive a moving boundary. It demonstrates the power of UDFs for capturing complex object movements and their effect on the surrounding fluid. Within the Dynamic Mesh: Beginner CFD Training Package, this project introduces UDF-driven motion, giving you direct control over how a body moves rather than relying on a preset motion option.
Methodology
The work brings together three main components: 3D geometry modeling in Design Modeler, an unstructured mesh of 143,423 cells generated in ANSYS Meshing, and a CFD simulation in ANSYS Fluent driven by a custom UDF that prescribes the object's motion. The methodology relies on the Dynamic Mesh model to simulate the movement of a rigid body within the fluid domain: as the object reciprocates, the dynamic mesh deforms to accommodate its motion — the essential mechanism that allows a moving boundary to be represented. The moving object is defined as a rigid body, and its translational motion is imposed through a custom implementation of the DEFINE_CG_MOTION macro. The module guides you through the full UDF process — writing a custom velocity function for the reciprocating motion, implementing it within the DEFINE_CG_MOTION macro, compiling and loading the UDF into ANSYS Fluent, and configuring the Dynamic Mesh model to use this custom motion function.
Analysis
Once the simulation has run, you analyze how effectively the custom UDF captures the prescribed motion — examining time-dependent snapshots of the geometry, the path traced by the moving object, and the variation of its velocity and position over time. From these results you can confirm the UDF drives the motion correctly and see how the reciprocating body affects the surrounding fluid. Custom motion modeling of this kind brings greater flexibility in simulating a wide range of motion patterns, improved accuracy in fluid-structure interaction, and the ability to represent complex mechanical systems in CFD — with applications from piston engines to industrial mixing. By the end of this project, you'll be able to write and compile a DEFINE_CG_MOTION UDF, drive a rigid body's reciprocating motion through custom code, configure the Dynamic Mesh model to use it, and interpret the resulting motion and flow — a foundation for advanced work such as coupled FSI and multi-body motion.