
[Sponsors] 
June 9, 2010, 00:54 
UserDefined Scalar (UDS) Source code

#1 
New Member
Gloria
Join Date: Feb 2010
Posts: 16
Rep Power: 8 
Hi, Everybody,
I am using UDF in the source term of UDS. The equation is U*A*CEcell*Scalar/ V, where U is the velocity; A is the face area that normal to U; CEcell is function of U, but here it is treated as constant for test the code; V is the control volume of the cell. I wrote a code (the simplified code is followed in the end) but there is error as followed. Experts, please give me some advice about the problem, I am really working on this problem for a long time. I post the problem before, but nobody answer me. I just try again, hope someone can help me . Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: () DEFINE_SOURCE(uds_source0,c,t,dS,eqn) { real source; real x[ND_ND], z, Ucell,V, CEcell; real NV_VEC(vel),NV_VEC(Af),flow_rate_1; int i; face_t f; Ucell=C_U(c,t); V=C_VOLUME(c,t); z=x[1]; /************************************************** *************************************/ C_CENTROID(x,f,t); CEcell=0.01; /************************************************** *************************************/ F_AREA(Af,f,t); NV_D(vel,=,F_U(f,t),F_V(f,t)); flow_rate_1=NV_DOT(vel,Af); source = C_UDSI(c,t,0)*CEcell*flow_rate_1/V; dS[eqn] = CEcell*flow_rate_1/V; return source; } 

June 9, 2010, 03:02 

#2 
New Member
Join Date: Jun 2009
Posts: 11
Rep Power: 9 
Did you activate de UDS in the fluent menu? This is a tipical error when some pointer is doing his work anomaly.


June 9, 2010, 07:38 

#3 
New Member
Gloria
Join Date: Feb 2010
Posts: 16
Rep Power: 8 
Thank you, jpcfd, for the reply.
What I did is that simulate the air flow first to get the velocity, then introduce 8 UDSs, change the diffusivity under material; flux under UDS; then initial value from the inlet; and source term under porous zone under boundary conditions. Then uncheck the equations of flow and turbulence under solution control to continue iteration. Can this active the UDS you asked? It works before I use this code, but this code is reasonable. 

June 10, 2010, 03:09 

#4 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 9 
Hi Gloria,
there are several errors in your code. First of all you have to realize that DEFINE_SOURCE loops over cells and not faces. Thus, F_AREA() does not know for which face f (and which facethread t) it should compute the area. This definitely causes an access violation. c_face_loop may be the macro that helps you as it loops over all faces of a given cell. Having a closer look at the udfuser guide will help too. cheers 

June 12, 2010, 01:04 

#5 
New Member
Gloria
Join Date: Feb 2010
Posts: 16
Rep Power: 8 
Hi, Coglione,
Thank you for the suggestion. I wrote a code using c_face_loop(c,t,i), but it doesn't work and has the same error.Could you please help me to check where the problems are? Really appreciated! /*****************************CEcell abtained in above program*************************************/ c_face_loop(c,t,i) { cell_t c0,c1=1; Thread *t0,*t1=NULL; c0=F_C0(f,t); t0=F_C0_THREAD(f,t); F_AREA(Af,f,t); if (BOUNDARY_FACE_THREAD_P(t)) { NV_D(vel, =,F_U(f,t),F_V(f,t),F_W(f,t)); flow_rate_1=NV_DOT(vel,Af); source = C_UDSI(c,t,0)*CEcell*flow_rate_1/V; dS[eqn] = CEcell*flow_rate_1/V; } else { NV_D(vel,=,C_U(c0,t0),C_V(c0,t0),C_W(c0,t0)); flow_rate_1=NV_DOT(vel,Af); source = C_UDSI(c,t,0)*CEcell*flow_rate_1/V; dS[eqn] = CEcell*flow_rate_1/V; } } return source; } 

June 14, 2010, 03:41 

#6 
Senior Member
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 9 
Hello again,
your code is still missing the part where you retrieve the faceid (f) and facethread (ft) for which you want to get some information. Use within your c_face_loop f = C_FACE(c,t,i); tf = C_FACE_THREAD(c,t,i); and with that F_AREA(Af,f,tf), F_U(f,tf) ... should work properly. cheers 

October 15, 2014, 12:12 

#7 
New Member
Aravind
Join Date: Oct 2014
Posts: 3
Rep Power: 4 
#include "udf.h"
#include"sg.h" enum { E, N_REQUIRED_UDS }; DEFINE_ADJUST(e_adjust,domain) { if (n_uds < N_REQUIRED_UDS) Internal_Error("not enough userdefined scalars allocated"); } /*DEFINE_SOURCE(energy_source_up,c,t,dS,eqn) { dS[eqn]= 49574.9 *pow((C_R(c,t)*C_U(c,t))/C_MU_L(c,t), 0.42 ); return 49574.9 *pow((C_R(c,t)*C_U(c,t))/C_MU_L(c,t), 0.42 )*( 400 C_UDSI(c,t,E)); } DEFINE_SOURCE(energy_source_down,c,t,dS,eqn) { dS[eqn]= 12.45 *pow((C_R(c,t)*C_U(c,t))/C_MU_L(c,t), 0.96 ); return 12.45 *pow((C_R(c,t)*C_U(c,t))/C_MU_L(c,t), 0.96 )*( 400 C_UDSI(c,t,E)); }*/ DEFINE_DIFFUSIVITY(e_diffusivity,c,t,i) { real X[ND_ND],xp; C_CENTROID(X,c,t); xp = X[0]; if(xp <= 0.035) { return 0.2 +( 1.772 *pow( 10.0 , 10 )*pow(C_UDSI(c,t,E), 3 )); } else { return 0.1 +( 1.77 *pow( 10.0 , 9 )*pow(C_UDSI(c,t,E), 3 )); } } DEFINE_PROFILE(e_profile,t,i) { face_t f; begin_f_loop (f,t) { F_PROFILE(f,t,i)= 2.367*pow(10.0 ,7 )*(pow(F_UDSI(f,t,i), 4 ) pow( 300.0 , 4 )); } end_f_loop (f,t) } When i tried for initializing ,it is showing the below mentioned error. Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: #f Plz help me sir 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Understanding komega SST model source code  tmhonka  OpenFOAM Programming & Development  1  September 8, 2009 07:33 
OpenFOAM on MinGW crosscompiler hosted on Linux  allenzhao  OpenFOAM Installation  127  January 30, 2009 20:08 
DxFoam reader update  hjasak  OpenFOAM PostProcessing  69  April 24, 2008 01:24 
user defined scalar  saghir  FLUENT  1  December 4, 2006 06:25 
Please help me run UDF code for source  Suga  FLUENT  1  February 3, 2006 04:40 