UDF to automatically change timestep size

There might be a need to change timestep size based on number of iterations taken for a case to converge within each time-step. This could be accomplished through an UDF which is attached at the end of this notes. The UDF needs to be hooked in the iterate panel under "User-Defined Time-Step" which is
available after switching on Adaptive method.

UDF that changes the time step value for a time-dependent solution.This
UDF is linked in iterate panel after switching on adaptive time-stepping method.
Note that UDF is called at the beginning of every timestep.This implies,
if a time step size of 100 is given in Fluent panel,then 200 is taken as
initial timestep size. Presently, if the number of iterations
is less than 10, the timestep is doubled. If the number of iterations
is more than 20, the timestep is halved.
#include "udf.h"
static int last_total_niter = 0;

DEFINE_DELTAT(mydeltat, domain)
real time_step;
int iter = N_ITER - last_total_niter;
if (iter < 10)
time_step = CURRENT_TIMESTEP*2;
if (iter > 20)
time_step = CURRENT_TIMESTEP*0.5;

printf("TIME_STEP_SIZE= %f n",time_step);
last_total_niter = N_ITER;
return time_step;

Show Form
No comments yet. Be the first to add a comment!