- **Fluent UDF and Scheme Programming**
(*http://www.cfd-online.com/Forums/fluent-udf/*)

- - **UDF in Fluent
**
(*http://www.cfd-online.com/Forums/fluent-udf/49277-udf-fluent.html*)

UDF in Fluent
Hi everyone,
I am trying to simulate an elastically mounted circular cylinder in cross-flow within Fluent using a UDF to control its motion harmonically. The setup is exactly the same as the stationary cylinder in Tutorial 6: Flow Past a Circular Cylinder. With the addition of a UDF to this situation, I am hoping to simulate resonance from vortex-shedding and therefore, be able to control the motion of the cylinder using a SDOF solution. I have used the code for defining center of gravity and just added the SDOF solution equations to this code. At the moment the code seems to be running ok, however, it is not communicating with Fluent. Using the message command in the code, the force, displacement and velocity of the cylinder are completely different to the values that Fluent provides when reporting. However, the cylinder still seems to be moving, but not corresponding to the displacement from the UDF. If anyone can help, this would be greatly appreciated! I can supply more information if anyone asks, as at the moment, I am not sure what else to say. Please find a copy of the code below. Thanks. /************************************************** ********** * 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; } |

Re: UDF in Fluent
I know that the UDF apears lengthy, but the eleven or so variables towards the end of the code are just defining a step function for the SDOF system. The displacement, velocity and force are then updated to allow the calculations to be done in the next time step, using the previous time step variables. As I mentioned, this process seems to be working just fine, however, the returned values displayed throughout the message commands in the UDF are completely different to the corresponding values found in Fluent through the REPORT > FORCES or SURFACE INTEGRALS. Therefore, the motion of the cylinder is not harmonic and only in one direction, which causes the solution to diverge and present a negative volume error. Also, the CL history plot shows a constant zero for the first few iterations, then suddenly drops steeply to a large value of -10e6. Definitely unrealistic! I have tried changing the values of mass, spring stiffness (of the cylinder) and damping, as well as the time step size, but the same thing tends to happen.
I know there is most likely a syntax error somewhere. As I am not too familiar with C++ or Fluent commands, I cannot see what needs fixing in the code. If anyone has tried a similar problem of controlling a cylinder in cross-flow and mounted between springs (elastic motion), your help would be great! If anyone knows what syntax error is causing the UDF to be misinterpreted by Fluent, I will appreciate the input. Thanks. |

Quote:
please let me know what you have problem |

Hello everyone,
I am currently undertaking a similar project for my BEng Thesis at University. Has anyone come up with a solution to Andrews problem? Alternatively, does anyone have a working UDF for an elastically mounted cylinder, with one or two degrees of freedom. Many thanks, Peter |

Hi peatmac,Quote:
I also have some problem wake galloping of two tandem cylinders. if you work with me, please send me email (colopolo70@gmail.com) |

Quote:
Did anyone find the correct UDF for force oscillation cylinder... I am still looking for that... Kindly help if anyone can,,, My email ID is n_bkhan@yahoo.com Thanks in advance Regards Niaz |

All times are GMT -4. The time now is 09:06. |