CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   User-Defined Scalar (UDS) Source code (https://www.cfd-online.com/Forums/fluent/76943-user-defined-scalar-uds-source-code.html)

 lig June 9, 2010 00:54

User-Defined Scalar (UDS) Source code

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:
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
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;
}

 jpcfd June 9, 2010 03:02

Did you activate de UDS in the fluent menu? This is a tipical error when some pointer is doing his work anomaly.

 lig June 9, 2010 07:38

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.

 coglione June 10, 2010 03:09

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 face-thread 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 udf-user guide will help too.

cheers

 lig June 12, 2010 01:04

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;
c0=F_C0(f,t);
F_AREA(Af,f,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;
}

 coglione June 14, 2010 03:41

Hello again,

your code is still missing the part where you retrieve the face-id (f) and face-thread (ft) for which you want to get some information.
f = C_FACE(c,t,i);

and with that
F_AREA(Af,f,tf), F_U(f,tf) ... should work properly.

cheers

 aravindbpillai October 15, 2014 12:12

#include "udf.h"
#include"sg.h"
enum
{
E,
N_REQUIRED_UDS
};
{
if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined 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 :(

 All times are GMT -4. The time now is 00:22.