How to define a periodic piecewise function for inlet velocity in UDF
Dear all,
I would like to ask how to define a periodic piecewise function for inlet velocity in UDF.
the function can be like:
v=f(t), (n=0,1,2,...)
0.07n<=t<0.07n+0.02, v=1
0.07n+0.02<=t<0.07(n+1), v=0
thanks a lot!
Best Answer

Rob UKForum Coordinator
I've done this using a mix of IF statements, sin(t) and floor https://www.programiz.com/cppprogramming/libraryfunction/cmath/floor I'll leave you to work out the maths!
Answers
I've done this using a mix of IF statements, sin(t) and floor https://www.programiz.com/cppprogramming/libraryfunction/cmath/floor I'll leave you to work out the maths!
I have solved this problem already~
@lytsophy Excellent. Please post the solution for others to learn from.
Thanks a lot!
the code could be like:
#include "udf.h"
DEFINE_PROFILE(inlet_velocity,th,i)
{
face_t f;
begin_f_loop(f,th)
real t=(CURRENT_TIMEfloor(CURRENT_TIME/0.7)*0.7);
{
if(t<0.2)
F_PROFILE(f,th,i)=0.01;
else
F_PROFILE(f,th,i)=0;
}
end_f_loop(f,th);
}