
[Sponsors] 
March 29, 2015, 07:23 
Force on moving body

#1 
New Member
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 11 
Hi,
I want to calculate the resulting force on a body moving in a fluid with predefined speed, but I am new to the work with UDF's. As far as I understood with the SDOF Macro the Motion resulting out of a Force can be simulated, but the Macro is of void type, so there is no output. The CG_MOTION Macro however defines a Motion, so this is more what I want. Is there a possibility to generate a output(for example by using the DEFINE_OUTPUT_PARAMETER Macro) of the total force acting in the body, like the Force the SDOF Macro uses to calculate the Motion? The force resulting out of the pressure(integration over the faces) and the fictious force (F=m*(dv/dt)) are no problem to calculate, but how can the "dynamic" force, resultant of the friction of the fluid on the body be calculated in UDF, like SDOF (at least I think) does? Is it maybe possible to export the force from the SDOF makro? Thank you very much in advance for any sugestion! 

March 31, 2015, 13:34 
Motion UDF

#2 
New Member
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 11 
The UDF part for the motion should look like this:
Code:
#include "udf.h" #include <math.h> DEFINE_CG_MOTION(bewegung,dt,velocity,omega,time,dtime) { double hub = 0.002; //[m] double freq = 500; //[1/s] NV_S(vel, =, 0.0); NV_S(omega, =, 0.0); double arg = 2*M_PI*time*freq // 0:x; 1:y; 2:z; vel[0] = (M_PI*hub*freq)*sin(arg); } 

March 31, 2015, 18:02 

#3 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 
Which force components do you wish to include: pressure, wall shear? Have a read of this thread because they have code for calculating the force as a sum of pressure and wall shear.


April 1, 2015, 12:15 

#4 
New Member
Joe Chorn
Join Date: Mar 2015
Posts: 4
Rep Power: 11 
Thank you very much, did not find this thread before...
So the UDF schould look like this, right? Code:
#include "udf.h" #include <math.h> #define HUB 0.004; /* [m], double amplitude */ #define FREQ 500.0; /* [1/s], frequency, 2ms switching time */ #define MASS 1.0; /* [kg] needs to be updated!!! */ /* predefined motion */ DEFINE_CG_MOTION(bewegung,dt,cg_velocity,cg_omega,time,dtime) { double arg; if (!Data_Valid_P()) return; /*end in invalid data?*/ /* initialization */ NV_S(cg_velocity, = , 0.0); /* set vel to 0, so only velocity in one direction is allowed(will be set below) */ NV_S(cg_omega, =, 0.0); /* no angular velocity needed */ arg = 2 * M_PI * time * freq; /* argument of sin */ vel[0] = (M_PI * hub * freq) * cos(arg); /* total velocity in x direction, first devirative of position */ } DEFINE_OUTPUT_PARAMETER(force) /*problem: returns int!*/ { Thread *t; /* pointer to thread */ face_t f; real forces*; /* 0:newtonforce(F=m*a); 1:pressure force(F=p*A); 2:shear force; */ real acc; /* acceleration */ real arg; /* argument of sin */ t = DT_THREAD(dt); /* get the thread pointer for which this motion is defined */ NV_S(forces, = , 0.0); /*if (!Data_Valid_P()) return ;*/ /*end if invalid data? */ arg = 2 * M_PI * time * freq; /* argument of sin */ acc = 1 * pow(M_PI, 2) * pow(FREQ, 2) * HUB * sin(arg); /* second derivative of position */ forces[0] = MASS * acc; begin_f_loop(f, t) { F_AREA(A, f, t); /* "Projected area" Vector */ forces[1] += F_P(f, t) * A[0]; /* pressure force at current face added; only pressure normal to x! */ forces[2] += F_STORAGE_R_N3V(f, t, SV_WALL_SHEAR)[0]; /* shear force at current face added; only force in xdirection */ } end_f_loop(f, t) real f_tot = forces[0] + forces[1] + forces[2]; return (int *)f_tot; } is there any way to get a double output? Thanks in advance! 

April 1, 2015, 18:38 

#5 
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 
If DEFINE_OUTPUT_PARAMETER doesn't suit your requirements, you could either print the force to the screen with Message() or save to a text file.
When are you calling this force summation, you may need to parallelise this code if running Fluent in parallel. 

April 2, 2015, 11:25 

#6 
Senior Member
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 14 
First, I see a couple minor syntax issues:
C is case sensitive. I see both 'hub' and 'freq' in several places, which need to be 'HUB' and 'FREQ'. Check your variable declarations. C requires all variable declarations at the top, before any nondeclaration code. 'f_tot' is being declared where it appears at the end, not at the top. (i.e. you should have 'real f_tot;' at the top and 'f_tot = forces...;' near the end. I'm really not sure what's going on with the return type. It looks like that code, as written, doesn't return an int, but a pointer to an int. If you remove the '(int *)' and instead just have 'return f_tot;' it should return a real (which is a float when running fluent in single precision and a double when running in double precision). I'm not exactly sure how the vector operations play with arrays, since your 'forces' array isn't exactly the kind of vector you'd usually use for 'NV_*' operations. Instead of 'real forces*;' and later 'NV_S(forces, =, 0.0);' it might be more robust to just have 'real forces[3]={0};' 

Tags 
cg_motion, force, motion simulation, sdof, udf 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
BC for measuring force on blunt body  letthe  OpenFOAM PreProcessing  4  December 9, 2013 18:20 
Problems with SUPG body force term  FEM question  Main CFD Forum  0  January 21, 2006 17:51 
UDF for lift force on a bluff body  sawa  FLUENT  2  April 11, 2005 03:06 
how to add body force in a duct  jane  FLUENT  0  March 27, 2004 23:13 
Body force  Jacob  FLUENT  0  August 4, 2003 16:38 