CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

UDF in Fluent

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By Andrew
  • 1 Post By colopolo

Reply
 
LinkBack Thread Tools Display Modes
Old   September 16, 2008, 21:46
Default UDF in Fluent
  #1
Andrew
Guest
 
Posts: n/a
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;

}

smm6889 likes this.
  Reply With Quote

Old   September 17, 2008, 21:37
Default Re: UDF in Fluent
  #2
Andrew
Guest
 
Posts: n/a
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.

  Reply With Quote

Old   October 11, 2011, 03:40
Default
  #3
Member
 
^^
Join Date: Aug 2011
Posts: 70
Rep Power: 5
colopolo is on a distinguished road
Quote:
Originally Posted by Andrew
;153470
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.
DID you fix your problem?
please let me know what you have problem
colopolo is offline   Reply With Quote

Old   February 21, 2012, 12:44
Default
  #4
New Member
 
Peter
Join Date: Jan 2012
Posts: 29
Rep Power: 5
peatmac is on a distinguished road
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
peatmac is offline   Reply With Quote

Old   March 16, 2012, 04:35
Default Hi peatmac,
  #5
Member
 
^^
Join Date: Aug 2011
Posts: 70
Rep Power: 5
colopolo is on a distinguished road
Quote:
Originally Posted by peatmac View Post
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
Did you success work for solving one or two degrees of freedom of cylinder?

I also have some problem wake galloping of two tandem cylinders. if you work with me, please send me email (colopolo70@gmail.com)
smm6889 likes this.
colopolo is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fluent in Linux vs. Fluent in Windows Melih FLUENT 6 November 16, 2014 10:39
Fluent/Unix vs. Fluent/Windows sjjaber FLUENT 10 January 5, 2005 17:58
Running FLUENT 6.0 sims. on FLUENT 6.1 ozgur FLUENT 2 April 2, 2004 13:23


All times are GMT -4. The time now is 12:25.