CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Problem with DEFINE_SOURCE (https://www.cfd-online.com/Forums/fluent/50030-problem-define_source.html)

Jacques December 11, 2008 06:59

Problem with DEFINE_SOURCE
 
Hi there, I try to specify my problem and hope someone can help me out!

I want to add a source term with DEFINE_SOURCE to only the closest(the first) cells around my geometry. How to add the source term only there isn't the problem. The problem is, that I want to calculate for each cell a different source-term. And I need to calculate it with the area normal vector of each cells boundary face.

I wrote a udf with the c_face_loop macro. But when I fprint the area normal vector it is in every cell the same vector.

Would be great if someone can help me or has an idea...

Thank you for any reply! Jacques

mange December 11, 2008 10:09

Re: Problem with DEFINE_SOURCE
 
If you post your UDF source code i may be able to give you some advice

Jacques December 12, 2008 10:06

Re: Problem with DEFINE_SOURCE
 
Hi and thanks for your reply!

I first wrote a DEFINE_ON_DEMAND UDF. This UDF works fine! Then I tried to implement it into the DEFINE_SOURCE udf. So I first post the DEFINE_ON_DEMAND source code and second the UDF I have problems with.

Would be great if you can help me! Jacques

/* ************************************************** */

#include "udf.h"

DEFINE_ON_DEMAND(beta)

{

Domain *d; real uvf, vvf; face_t f; real A[ND_ND], area, nv; cell_t c, c0; Thread *t,*t0, *c_thread, *t_fog; FILE *fp;

int Zone_ID=6; /* Zone ID of the wall on which beta has to be calculated */ /* It can be obtained from the boundary condition panel.*/

d=Get_Domain(1);

/* ************************************************** * */

/* Initialize the UDM value to zero in complete domain */

thread_loop_c(c_thread,d)

{

begin_c_loop(c, c_thread)

{

C_UDMI(c,c_thread,0)= 0;

}

end_c_loop(c, c_thread)

}

/* ************************************************** * */

/* Calculate DOT of fog-vel and n and store it in UDM */

t=Lookup_Thread(d,Zone_ID);

t_fog=THREAD_SUB_THREAD(t,1);

begin_f_loop(f, t_fog)

{

F_AREA(A,f,t_fog);

area = NV_MAG(A);

c0 = F_C0(f,t_fog);

t0 = THREAD_T0(t_fog);

uvf = C_U(c0,t0);

vvf = C_V(c0,t0);

printf("A0 = %f A1 = %f uvf = %f vvf = %f \n",A[0],A[1],uvf,vvf);

fp = fopen("data_beta.txt","a");

fprintf(fp,"A1 = %f A2 = %f uvf = %f vvf = %f nv = %f\n",A[0],A[1],uvf,vvf,nv);

fclose(fp);

C_UDMI(c0,t0,0)= (NVD_DOT(A,uvf,vvf,0));

}

end_f_loop(f, t_fog)

}

/* *********************************************** */

/* *********************************************** */

now the DEFINE_SOURCE UDF that doesn't work properly:

/* *********************************************** */

/* ************************************************** */

#include "udf.h" #include "sg.h"

DEFINE_SOURCE(neg_source_f_loop,c,t,dS,eqn)

{

Domain *d; real source = 0.0; real uvf, vvf, nv; real A[ND_ND]; face_t f; Thread *t0, *t_fog; FILE *fp;

int Zone_ID=6;

d=Get_Domain(1);

t0=Lookup_Thread(d,Zone_ID);

/*t_fog=THREAD_SUB_THREAD(t,1); <--had to delete it because it produced segmentation violation for some reason?? I think because the Source will be defined only for the second phase via Fluent GUI, its not necessary to implement it here?!*/

begin_f_loop(f,t0)

{

F_AREA(A,f,t0);

uvf = C_U(c,t);

vvf = C_V(c,t);

nv = NVD_DOT(A,uvf,vvf,0);

fp = fopen("data_f_loop.txt","a");

fprintf(fp,"A0 = %f A1 = %f uvf = %f vvf = %f nv = %f\n",A[0],A[1],uvf,vvf,nv);

fclose(fp);

source = -(NVD_DOT(A,uvf,vvf,0));

}

end_f_loop(f,t0)

return source;

}

mange December 15, 2008 09:25

Re: Problem with DEFINE_SOURCE
 
Hi,

Where do you hook your UDF? normally if you hook a UDF source function it will already be in a loop. So that if you hook it in a fluid domain, on the liquid level (if you have more than one phase) it should already be looping though all your cells.

Jacques December 16, 2008 09:44

Re: Problem with DEFINE_SOURCE
 
Hi,

I solved the problem. ;) here is the code (without the header):

c_face_loop(c,t,n)

{

f = C_FACE (c,t,n);

tf = C_FACE_THREAD (c,t,n);

if ( THREAD_TYPE(tf) == THREAD_F_WALL )

{

F_AREA(A,f,tf); uvf = C_U(c,t); vvf = C_V(c,t);

source = (NVD_DOT(A,uvf,vvf,0);

}

return source;

}


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