CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF help (https://www.cfd-online.com/Forums/fluent-udf/88752-udf-help.html)

zhaolinchen May 25, 2011 04:53

UDF Done
 
I am simulating a wing using fluent and want to output all the aerodynamic forces into a txt or dat file, does anyone know which udf command shoud i use. I know command "message " only shows the forces on the windows, so anyone knows please give me a hand, many thanks

zhaolinchen May 26, 2011 12:56

Ok i made this script to integrate the forces however it only works as a interpreted UDF and not a compiled UDF. Any ideas?

/************************************************** ******************
************************************************** *******************/
#include "udf.h"
#define airfoil_tid 15 /* Zone ID of airfoil */
#define domain_zone 1
float P_i;
float A_i;
float U_i;
float V_i;
float W_i;
float Fpx;
float Fpy;
float A[3];
Domain *domain;
face_t f; /* airfoil surface*/
Thread *t;/* wing thread*/
DEFINE_ADJUST(forces,domain)
{
domain = Get_Domain(domain_zone);
t = Lookup_Thread(domain, airfoil_tid);
Fpx=0;
Fpy=0;
begin_f_loop(f,t)
{

F_AREA(A,f,t);
P_i = F_P(f,t);
Fpx += P_i*A[0];
Fpy += P_i*A[1];
}
end_f_loop(f,t)


printf("forces are: %f\n,%f\n", Fpx,Fpy);
}

dmoroian May 31, 2011 05:27

The normal way is to include <stdio.h> when you want to use printf. However, try to use Message, instead of printf, it takes exactly the same arguments.
You have to be aware, though, that your udf will not work correctly in parallel (due to the face summation).

zhaolinchen May 31, 2011 07:52

Quote:

Originally Posted by dmoroian (Post 309904)
The normal way is to include <stdio.h> when you want to use printf. However, try to use Message, instead of printf, it takes exactly the same arguments.
You have to be aware, though, that your udf will not work correctly in parallel (due to the face summation).

thanks dmoroian, do you have any ideals about the commands for parallel? many thanks

dmoroian May 31, 2011 08:09

short example
 
Code:

#include "udf.h"
#include "prf.h"
#define airfoil_tid  15    /* Zone ID of airfoil */
#define domain_zone  1
float P_i;
float A_i;
float U_i;
float V_i;
float W_i;
float Fpx;
float Fpy;
float A[3];
Domain *domain;
face_t f; /* airfoil surface*/
Thread *t;/* wing thread*/
DEFINE_ADJUST(forces,domain)
{
#if !RP_HOST
  domain = Get_Domain(domain_zone); 
  if(NULL == (t = Lookup_Thread(domain, airfoil_tid)))
      Error("Something is wrong with the thread:0x%x\n",t);
  Fpx=0;
  Fpy=0;               
  begin_f_loop(f,t)
  {
     
      F_AREA(A,f,t);
      P_i = F_P(f,t);
      Fpx += P_i*A[0];
      Fpy += P_i*A[1];
  }     
  end_f_loop(f,t)

  Fpx = PRF_GRSUM1(Fpx);
  Fpy = PRF_GRSUM1(Fpy);
 
  Message0("forces are: %f\n,%f\n", Fpx,Fpy);
}


zhaolinchen June 2, 2011 08:46

1 Attachment(s)
Hi dmoroian, thanks for the help, I was trying to get the shear stress along the airfoil, however, got some problems when i check the values: code shows below:
/************************************************** ******************
UDF for integrating pressure forces and displaying it in the
console
************************************************** *******************/
#include "udf.h"
#include "metric.h"
#include "mem.h"
#define airfoil_tid 13 /* Zone ID of airfoil */
#define domain_zone 1
float DUDX,DUDX1;
float pressure;
float DPDX1;
int counter;
int nface;
int a;
int b;
int zone_ID;
Domain *domain;
face_t f; /* airfoil surface*/
cell_t c;
cell_t c0;
Thread *t;
Thread *t0;
Thread *t1;

DEFINE_ADJUST(forces,domain)
{

//if (!Data_Valid_P()) return;
domain = Get_Domain(domain_zone);
t = Lookup_Thread(domain, airfoil_tid);
//zone_ID = THREAD_ID(t); /*out put the airfoil thread number*/
//Message("zone_ID: %d\n",zone_ID);
//counter = 0;
//if(b = BOUNDARY_FACE_THREAD_P(t));
//{Message("boundary: %d\n", b);
//}
begin_f_loop(f,t)
{


t0 = F_C0_THREAD(f,t);
c0 = F_C0(f,t);
nface = C_NFACES(c0,t0);
DUDX = C_DUDX(c0,t0);/* seems problems come from here, which not match to the fluent post-process values, see the values at the bottom*/
pressure = C_P(c0,t0);/*also the pressure force is not right as well*/
a = FLUID_THREAD_P(t0); /* check whether t0 is a thread in the domain*/

Message("DUDX: %e,%d,%d,%e\n",DUDX,nface,a,pressure);


}
end_f_loop(f,t)

begin_c_loop(c,t)
{
//if (BOUNDARY_FACE_THREAD_P(t))
// {
DPDX1 = C_P_G(c,t)[0];
//t1 = C_FACE_THREAD(c,t,0);
// c = C_FACE(c,t,0);

//Message("DPDX = %e\n", DPDX1);
// }
}
end_c_loop(c,t)

}
********************************************
values from the codes:
this colume is pressure force at wall
DUDX: 3.746866e+000,4,1,-1.851858e+001
DUDX: -1.253381e+000,4,1,-2.228758e+001
DUDX: -4.220629e+000,4,1,-1.864905e+001
DUDX: -2.343874e+000,4,1,1.658862e+001
DUDX: -9.178568e+001,4,1,1.796235e+001
DUDX: -2.398940e+000,4,1,1.648010e+001
DUDX: -5.881291e+000,4,1,-2.434795e+001
DUDX: -5.239357e+000,4,1,-2.471040e+001
DUDX: -5.963025e+000,4,1,-2.434571e+001
DUDX: 4.096624e+000,4,1,-1.958149e+001
DUDX: -1.208462e+000,4,1,-2.364586e+001
DUDX: -4.264113e+000,4,1,-1.990714e+001

***********************************************
forces from the fluent write file, from plots of du/dx--x and pressure--x
pressure du/dx
-20.3986 1.24743
-20.4641 -2.73684
-21.4992 -5.42141
-24.5353 -5.63565
-24.534 -5.66827
-22.1281 -5.43965
-21.7746 -2.73628
-21.6116 1.44466
-1.54782 0.625361
17.2248 -47.0923
17.2791 -47.0647
-0.960895 0.08465

****************************************
below is the case file:
Attachment 7892

dmoroian June 3, 2011 01:59

I'm sorry, but I don't really understand your problem. It seems different than the first one above.

niravtm007 August 31, 2011 00:57

Hii friendss.. i have worked out with 2d udf for parabolic velocity inlet.
please help me how this code will change with 3d. i wanna know how will be the equation considering 3rd dimmension.
as in 2d we have V(x)=Vmax- y^2/(disatnce from centre in y direction )^2 * Vmax.
please help me.
also give suggestion how to work out on sinusoidal inlet udf.
thanks in advance


All times are GMT -4. The time now is 04:08.