||January 30, 2016 14:00
This thread is pretty old but since I found it through google I think others will, too.
I'm a Fluent / UDF beginner myself, but the following works for me. I verified results with manually using gravity in Fluent GUI. It works perfectly in my vof 2phase case. My UDF has a little bit different purpose but it's easy to adjust. Interpret UDF like always, go to cell zone conditions, select "Source Terms" and add it as x/y/z momentum however you like.
real flow_time = RP_Get_Real("flow-time");
if (flow_time < 0.1)
gravity = 0.;
gravity = 9.81;
/* gravity*cr(ct) is gravity*density = N/m³ = specific weight = F(g) on a unit of volume of a fluid */
source = gravity*C_R(c,t);
In my case it simply activates gravity in +x direction after 0.1s flow time. If you need varying gravity just use a function for gravity instead of a constant. For example remove if / else and use flow_time in sine function for gravity.