FLUENT V6 - User-Defined Function (UDF) to report spanwise forces acting on an aircraft wing


FLUENT can report the total force that is acting on the wing. But sometimes, it is required to know the spanwise report of forces acting on that wing. This can be achieved by using the UDF included below.
Details on usage of the UDF are given in the UDF itself. Following are the steps required to use the UDF
- Make the appropriate changes in the UDF (Axis direction, Force direction, no. of strips and id of the wall zone)
- Compile the UDF using Define->User-Defined->Functions->Compiled...
- Read in the case file
- Increase no. of User-Defined Memory to 1 using Define->User-Defined->Memory...
- Initialize the solution so that UDM is initialized
- Read in the data file
- Execute the demand function "force" using Define->User-Define->Execute On Demand...
- Plot contours of UDM-0 and check if the strips are marked correctly
- Fluent will report the spanwise distribution on the Fluent terminal
- A file called spanwise-force-report.txt will also be created


The UDF follows
/*******************************************************/
/* Written by Rahul Kumar */
/* rpk@fluent.co.in */
/* */
/* Used to obtain a spanwise force report on wings */
/*******************************************************/

#include "udf.h"

/* Spanwise direction */
#define AXIS_X 0
#define AXIS_Y 1
#define AXIS_Z 0

/* The direction along which the force is to be reported */
#define F_X 1
#define F_Y 0
#define F_Z 0

/* Number of strips into which the wing is to be divided */
/* Increasing this number increases the resolution of reporting */
/* It is however limited by the number of cells present along the spanwise direction */
/* Recommended value: */
/* For unstructured cells: no of cells along spanwise dir. divided by 3 */
/* For structured cells: no. of cells along spanwise dir. divided by 3 */
#define N_STRIPS 20

/* ID of the wing boundary zone */
/* You can get this from the Boundary Conditions Panel */
#define TID 15


/* Make sure you increase no. of User Defined Memory to 1 */
/* The UDM stores the strip number for each cell */
/* You can see contour plots of cell values of UDM-1 to check */
/* if the strips are marked correctly */

DEFINE_ON_DEMAND(force)
{
Domain *d=Get_Domain(1);
int i;
real A[ND_ND];
real axis[3], force_dir[3];
face_t f;
Thread *t=Lookup_Thread(d,TID);
cell_t c;
Thread *tc;
real x[ND_ND];
real NV_VEC(presforce),NV_VEC(viscforce);
real NV_VEC(dforce_pres),NV_VEC(dforce_visc);
real pforce[N_STRIPS],vforce[N_STRIPS];
real press=0.0;
real pressure=0.0;
real visc=0.0;
real min_dist=1000000000;
real max_dist=-1000000000;
real dist=0;
real strip_length;
FILE *fp;

NV_S(A,=,0.0);
NV_S(dforce_pres,=,0.0);
NV_S(dforce_visc,=,0.0);
NV_S(presforce,=,0.0);
NV_S(viscforce,=,0.0);

axis[0]=AXIS_X;
axis[1]=AXIS_Y;
axis[2]=AXIS_Z;

force_dir[0]=F_X;
force_dir[1]=F_Y;
force_dir[2]=F_Z;

fp=fopen("spanwise-force-report.txt", "w+");

begin_f_loop(f, t)
{
F_CENTROID(x, f, t);
dist=NV_DOT(x, axis);
if(dist<min_dist) min_dist=dist;
if(dist>max_dist) max_dist=dist;
}
end_f_loop(f, t)

strip_length=(max_dist-min_dist)/N_STRIPS;

Message("Marking strips...");
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
c=F_C0(f, t);
tc=THREAD_T0(t);
dist=NV_DOT(x, axis);
C_UDMI(c,tc,0)=(int)((dist-min_dist)/strip_length);
}
end_f_loop(f,t)

Message("Donen");

for(i=0;i<N_STRIPS;i++) {
pforce[i]=0;
vforce[i]=0;
}

begin_f_loop(f,t)
{
F_AREA(A,f,t);
c=F_C0(f, t);
tc=THREAD_T0(t);
pforce[(int)C_UDMI(c, tc, 0)]+=F_P(f, t) * NV_DOT(A, force_dir);
vforce[(int)C_UDMI(c, tc, 0)]+=(-1*(NV_DOT(F_STORAGE_R_N3V(f,t,SV_WALL_SHEAR), force_dir)));
}
end_f_loop(f,t)

Message("nnPressure forcet Viscous force");
for(i=0;i<N_STRIPS;i++)
{
press+=pforce[i];
visc+=vforce[i];
Message("n %g t %g",pforce[i],vforce[i]);
fprintf(fp, "%d t %f t %f n", i, pforce[i], vforce[i]);
}
Message("n---------- -----------");
Message("n %gt%g",press,visc);
fclose(fp);
}





Show Form
No comments yet. Be the first to add a comment!