CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Problem with DEFINE_SOURCE

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 11, 2008, 07:59
Default Problem with DEFINE_SOURCE
  #1
Jacques
Guest
 
Posts: n/a
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
  Reply With Quote

Old   December 11, 2008, 11:09
Default Re: Problem with DEFINE_SOURCE
  #2
mange
Guest
 
Posts: n/a
If you post your UDF source code i may be able to give you some advice
  Reply With Quote

Old   December 12, 2008, 11:06
Default Re: Problem with DEFINE_SOURCE
  #3
Jacques
Guest
 
Posts: n/a
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;

}
  Reply With Quote

Old   December 15, 2008, 10:25
Default Re: Problem with DEFINE_SOURCE
  #4
mange
Guest
 
Posts: n/a
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.
  Reply With Quote

Old   December 16, 2008, 10:44
Default Re: Problem with DEFINE_SOURCE
  #5
Jacques
Guest
 
Posts: n/a
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;

}
  Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in using DEFINE_SOURCE for continuity zbpeng FLUENT 0 July 25, 2008 05:19
Problem on Parallel DEFINE_SOURCE Li FLUENT 0 May 9, 2008 00:13
Kind attn:problem in DEFINE_SOURCE in my UDF Phanindra FLUENT 1 February 23, 2007 10:03
DEFINE_SOURCE PK FLUENT 0 December 6, 2006 11:36
Ask about DEFINE_SOURCE. mazao FLUENT 1 November 15, 2005 07:20


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