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 not running iteration (https://www.cfd-online.com/Forums/fluent-udf/161714-udf-not-running-iteration.html)

krushna October 27, 2015 02:04

udf not running iteration
 
Dear All,
I am working on hydrogen absorption based on metal hydride. In my case, hydrogen is injected into the reactor, then hydrogen will react with metal (porous material) to form metal hydride at that time heat is generated which is kept out by using heat exchanger.

I was runing UDF many times but it not work(iteration not starting)


Any one COuld help me?

Here is my UDF code:
#include"udf.h"

/* Input Boundary Conditions */
#define T_i 300.0 /* Inlet temp in K */
#define T_f 298.0 /* Coolant fluid temp in Kelvin [K] */
#define P_i 10e5 /* Inlet pressure in pascals */
#define h_o 1000 /* Heat transfer coeff in W/m^2-K */
#define x_i 0 /* Initial value of H/M for reaction to START */
#define x_f 1 /* Final value of H/M for reaction to STOP @ saturation */

/* Properties of Misc Metal */
#define rho_m 8400 /* Density in kg/m^3 */
#define C_pm 419 /* Sp heat in J/kg-K */
#define K_m 3.0728 /* Thermal conductivity in W/m-K */
#define por 0.5 /* Porosity */
#define rho_ss 8518 /* Density of MH @ saturation kg/m^3 */
#define rho_s 8400 /* Density of MH kg/m^3 */
#define E_a 21170 /* Activation energy in J/mol H2 */
#define per 1e-8 /* Permeability */
#define DELTA_S 107.2 /* Entropy of Formation J/mol H2-K */
#define DELTA_H 28000 /* Enthalpy of Formation J/mol H2 */

/* Properties of Hydrogen */
#define K_g 0.1272 /* Thermal Conductivity in W/m-K */
#define C_pg 14283 /* Sp heat in J/kg-K */
#define rho_g 0.0838 /* Density in kg/m^3 */
#define M_g 2.016 /* Molecular weight in kg/mol */

/* CONSTANTS */
#define R_u 8.314 /* Universal gas Constant J/mol-K */
#define k_a 75 /* Reaction Constant for absorption in (sec)^-1 */

/* Initialization of cell property of scalar i.e. 'initial value of x to solve UDS_SOURCE'*/
DEFINE_INIT(my_init_fuc,d)
{
cell_t c;
Thread*t;
thread_loop_c(t,d)
{
begin_c_loop_all(c,t)
{
C_UDSI(c,t,0)= 0;
}
end_c_loop_all(c,t)
}
}

/*UDF for solving Energy Equation HEAT SOURCE term */
DEFINE_SOURCE(heat_generation,c,t,ds,eqn)
{
real q_a;
real physical_dt;

physical_dt = RP_Get_Real("physical-time-step");
q_a= 1000*(rho_ss-rho_s)*(1-por)*(DELTA_H/M_g)*(C_UDSI(c,t,0)-C_UDSI_M1(c,t,0))/physical_dt;
ds[eqn]=0;
C_UDMI(c,t,0)=q_a; /* Memory allocation for storing 'heat generation' */
return q_a;

}
/* Continuity Equation SOURCE term */
/* Not required in CONDUCTION model */
DEFINE_SOURCE(continuity_source,c,t,ds,eqn)
{
real c_a;
real physical_dt;
physical_dt = RP_Get_Real("physical-time-step");

c_a= (rho_ss-rho_s)*(1-por)*(C_UDSI(c,t,0)-C_UDSI_M1(c,t,0))/physical_dt;
ds[eqn]=0;
//C_UDMI(c,t,1)=c_a; /* Memory allocation for storing 'mass of Hydrogen stored' */
return c_a;

}

/* UDS for solving Kinetic equation by using unsteady equation i.e. by using Unsteady eq solving dx/dt eqn */
DEFINE_UDS_UNSTEADY(uds_time,c,t,i,apu,su)
{
real physical_dt;
real vol;
real rho;
real phi_old;
physical_dt = RP_Get_Real("physical-time-step");
vol = C_VOLUME(c,t);
rho = 1; /* for varying density use rho = C_R_M1(c,t); */
*apu = -rho*vol/physical_dt;
phi_old = C_STORAGE_R(c,t,SV_UDSI_M1(0));
*su = rho*vol*phi_old/physical_dt;
}

/* Kinetic Equation(dx/dt eq) SOURCE term for this define User Define Scalar i.e. 'x' */
/* Convection & Diffusion part are zero */
DEFINE_SOURCE(uds_source,c,t,ds,eqn)
{
real tp;
real rate;
real P_eq;
real cond;
real x_now;

tp = C_T(c,t);
P_eq = pow(2.72,((DELTA_S/R_u)-(DELTA_H/(R_u*tp))))*pow(10,5);
cond = P_i/P_eq;

if(cond>1)
{
rate = k_a*pow(2.72,(-E_a/(R_u*tp)))*((P_i/P_eq)-1)*((C_UDSI_M1(c,t,0) - x_f)/(x_i - x_f));
ds[eqn] = k_a*pow(2.72,(-E_a/(R_u*tp)))*((P_i/P_eq)-1)*(1/(x_i - x_f));
}
else
{
rate = 0;
ds[eqn] = 0;
}

C_UDMI(c,t,2)=rate; /* Memory allocation for storing 'rate' */
return rate;

}

Regards,
krushna

`e` November 2, 2015 15:46

Which part of the iteration is not working, or does Fluent not even begin an iteration? Add a message in each macro to check if each macro is called. For example, add:

Code:

Message0("DEFINE_SOURCE macro is now starting...\n");

krushna November 2, 2015 23:26

thank you for your help
regards
krushna

krushna November 3, 2015 00:32

Dear 'e',
thank you for you solution, In my case, hydrogen is injected into the reactor, then hydrogen will react with metal (porous material) to form metal hydride at that time heat is generated which is kept out by using heat ex-changer. but coolant flow is started before hydrogen injection. so, i run steady cold flow simulation and then transient simulation with energy generation initialize by read .dat file of cold flow simulation.
problem is how to initialize the reactor side.
please give me solution.
thanking you,
regards,
krushna

`e` November 3, 2015 02:58

Does the usual initialisation procedure not work (uniform initial conditions)? You could also patch the values if they're non-uniform.

krushna November 3, 2015 03:37

ok thank you

ZKR February 25, 2017 16:50

hi, i'm working with the same case, i have trouble with creating UDF, please how to create it?


All times are GMT -4. The time now is 19:43.