Vous êtes sur la page 1sur 2

/************************************************** ********** * 1-degree of freedom equation of motion (y-direction) * compiled UDF ************************************************** **********/ #include "udf.

h" static real v_prev = 0.0; /* initial velocity of cylinder */ static real x_prev = 0.0; /* initial displacement of cylinder */ static real force_prev = 0.0; /* initial force on cylinder */ DEFINE_CG_MOTION(cylinder,dt,vel,omega,time,dtime) { Thread *t; face_t f; real NV_VEC(A); real force, v, x, dv, m, k, c_absorb, z, wn, wd, beta, a, b, c, d, aa, bb, cc, dd, coeff1, coeff2, coeff3; /* reset velocities */ NV_S(vel, =, 0.0); NV_S(omega, =, 0.0); if (!Data_Valid_P()) return; /* get the thread pointer for which this motion is defined */ t = DT_THREAD(dt); m = 50000.0; /* mass of cylinder */ k = 1.0; /* spring stiffness of cylinder system */ c_absorb = 1.0; /* damping coefficient */ z = c_absorb/(2*sqrt(k*m)); /* damping parameter */ wn = sqrt(k/m); /* natural frequency of system */ wd = sqrt(1 - pow(z, 2))*wn; /* damped frequency of the system */ beta = z*wn; /* calculation constant */ /* compute pressure force on body by looping through all faces */ force = 0.0; Message ("time = %f, y_disp = %f, y_vel = %f, force = %f\n", time, x_prev, v_prev, force); begin_f_loop(f,t) { /* integral to find force */ F_AREA(A,f,t); force += F_P(f,t) * NV_MAG(A); } end_f_loop(f,t) /* compute change in velocity, i.e., dv = (F - c*v - k*x) * dt / mass velocity update using explicit Euler formula */ Message ("time = %f, y_disp = %f, y_vel = %f, force = %f\n", time, x_prev, v_prev, force); /* define the constant variables for displacement and velocity expressions */ coeff1 = 1/(k*wd*dtime); coeff2 = (pow(wd, 2) - pow(beta, 2))/pow(wn, 2); coeff3 = (2*wd*beta)/pow(wn, 2); a = coeff1*(exp(-beta*dtime)*(((coeff2 - (beta*dtime))*sin(wd*dtime)) - ((coeff3 + (wd*dtime))*cos(wd*dtime))) + coeff3);

b = coeff1*(exp(-beta*dtime)*((-coeff2*sin(wd*dtime)) + (coeff3*cos(wd*dtime))) + (wd*dtime) - coeff3); c = exp(-beta*dtime)*(cos(wd*dtime) + ((beta/wd)*sin(wd*dtime))); d = (1/wd)*exp(-beta*dtime)*sin(wd*dtime); aa = coeff1*(exp(-beta*dtime)*(((beta + (dtime*pow(wn, 2)))*sin(wd*dtime)) + (wd*cos(wd*dtime))) - wd); bb = coeff1*(-exp(-beta*dtime)*((beta*sin(wd*dtime)) + (wd*cos(wd*dtime))) + wd); cc = -(pow(wn, 2)/wd)*exp(-beta*dtime)*sin(wd*dtime); dd = exp(-beta*dtime)*(cos(wd*dtime) - ((beta/wd)*sin(wd*dtime))); x = a*force_prev + b*force + c*x_prev + d*v_prev; /* displacement of cylinder updated each time step */ v = aa*force_prev + bb*force + cc*x_prev + dd*v_prev; /* velocity of cylinder updated each time step */ dv = (dtime*(force - (c_absorb*v) - (k*x))) / m; /* change in velocity updated each time step */ x_prev = x; v_prev = v; force_prev = force; Message ("time = %f, y_disp = %f, y_vel = %f, force = %f\n", time, x_prev, v_prev, force_prev); /* set y-component of velocity */ vel[1] = dv; }

------------/************************************************************ * * 1-degree of freedom equation of motion (x-direction) * compiled UDF * ************************************************************/ static real v_prev = 0.0;

Vous aimerez peut-être aussi