You are on page 1of 7

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

/* vprofile.c */
/* UDF for specifying steady-state velocity profile boundary condition */
/***********************************************************************/
#include "udf.h"

DEFINE_PROFILE(inlet_x_velocity, thread, position)


{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;

begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f, thread, position) = 20. - y*y/(.0745*.0745)*20.;
}
end_f_loop(f, thread)
}

/**********************************************************************/
/* unsteady.c */
/* UDF for specifying a transient velocity profile boundary condition */
/**********************************************************************/

#include "udf.h"

DEFINE_PROFILE(unsteady_velocity, thread, position)


{
face_t f;

begin_f_loop(f, thread)
{
real t = RP_Get_Real("flow-time");
F_PROFILE(f, thread, position) = 20. + 5.0*sin(10.*t);
}
end_f_loop(f, thread)
}

/******************************************************************/
/* UDF that adds momentum source term and derivative to duct flow */
/******************************************************************/

#include "udf.h"

#define CON 20.0

DEFINE_SOURCE(cell_x_source, cell, thread, dS, eqn)


{
real source;

if (C_T(cell,thread) <= 288.)


{
/* source term */
source = -CON*C_U(cell,thread);
/* derivative of source term w.r.t. x-velocity. */
dS[eqn] = -CON;
}
else
source = dS[eqn] = 0.;

return source;
}

/*********************************************************************/
/* UDF for specifying a temperature-dependent viscosity property */
/*********************************************************************/

#include "udf.h"

DEFINE_PROPERTY(cell_viscosity, cell, thread)


{
real mu_lam;
real temp = C_T(cell, thread);

if (temp > 288.)


mu_lam = 5.5e-3;
else if (temp > 286.)
mu_lam = 143.2135 - 0.49725 * temp;
else
mu_lam = 1.;

return mu_lam;
}

/**************************************************************/
/* rate.c */
/* UDF for specifying a reaction rate in a porous medium */
/**************************************************************/

#include "udf.h"

#define K1 2.0e-2
#define K2 5.

DEFINE_VR_RATE(user_rate, c, t, r, mole_weight, species_mf, rate, rr_t)


{
real s1 = species_mf[0];
real mw1 = mole_weight[0];

if (FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous)


*rate = K1*s1/pow((1.+K2*s1),2.0)/mw1;
else
*rate = 0.;
}

/***********************************************************************/
/* UDF for computing the magnitude of the gradient of T^4 */
/***********************************************************************/
#include "udf.h"

/* Define which user-defined scalars to use. */


enum
{
T4,
MAG_GRAD_T4,
N_REQUIRED_UDS
};

DEFINE_ADJUST(adjust_fcn, domain)
{
Thread *t;
cell_t c;
face_t f;

/* Make sure there are enough user-defined scalars. */


if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined scalars allocated");

/* Fill first UDS with temperature raised to fourth power. */


thread_loop_c (t,domain)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))
{
begin_c_loop (c,t)
{
real T = C_T(c,t);
C_UDSI(c,t,T4) = pow(T,4.);
}
end_c_loop (c,t)
}
}

thread_loop_f (t,domain)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))
{
begin_f_loop (f,t)
{
real T = 0.;
if (NULL != THREAD_STORAGE(t,SV_T))
T = F_T(f,t);
else if (NULL != THREAD_STORAGE(t->t0,SV_T))
T = C_T(F_C0(f,t),t->t0);
F_UDSI(f,t,T4) = pow(T,4.);
}
end_f_loop (f,t)
}
}

/* Fill second UDS with magnitude of gradient. */


thread_loop_c (t,domain)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&
NULL != T_STORAGE_R_NV(t,SV_UDSI_G(T4)))
{
begin_c_loop (c,t)
{
C_UDSI(c,t,MAG_GRAD_T4) = NV_MAG(C_UDSI_G(c,t,T4));
}
end_c_loop (c,t)
}
}

thread_loop_f (t,domain)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&
NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(T4)))
{
begin_f_loop (f,t)
{
F_UDSI(f,t,MAG_GRAD_T4)=C_UDSI(F_C0(f,t),t->t0,MAG_GRAD_T4);
}
end_f_loop (f,t)
}
}
}

/**************************************************************/
/* Implementation of the P1 model using user-defined scalars */
/**************************************************************/

#include "udf.h"

/* Define which user-defined scalars to use. */


enum
{
P1,
N_REQUIRED_UDS
};

static real abs_coeff = 1.0; /* absorption coefficient */


static real scat_coeff = 0.0; /* scattering coefficient */
static real las_coeff = 0.0; /* linear-anisotropic */
/* scattering coefficient */
static real epsilon_w = 1.0; /* wall emissivity */

DEFINE_ADJUST(p1_adjust, domain)
{
/* Make sure there are enough user defined-scalars. */
if (n_uds < N_REQUIRED_UDS)
Internal_Error("not enough user-defined scalars allocated");
}

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


{
dS[eqn] = -16.*abs_coeff*SIGMA_SBC*pow(C_T(c,t),3.);
return -abs_coeff*(4.*SIGMA_SBC*pow(C_T(c,t),4.) - C_UDSI(c,t,P1));
}
DEFINE_SOURCE(p1_source, c, t, dS, eqn)
{
dS[eqn] = -abs_coeff;
return abs_coeff*(4.*SIGMA_SBC*pow(C_T(c,t),4.) - C_UDSI(c,t,P1));
}

DEFINE_DIFFUSIVITY(p1_diffusivity, c, t, i)
{
return 1./(3.*abs_coeff + (3. - las_coeff)*scat_coeff);
}

DEFINE_PROFILE(p1_bc, thread, position)

{
face_t f;
real A[ND_ND],At;
real dG[ND_ND],dr0[ND_ND],es[ND_ND],ds,A_by_es;
real aterm,alpha0,beta0,gamma0,Gsource,Ibw;
real Ew = epsilon_w/(2.*(2. - epsilon_w));
Thread *t0=thread->t0;

/* Do nothing if areas aren't computed yet or not next to fluid. */


if (!Data_Valid_P() || !FLUID_THREAD_P(t0)) return;

begin_f_loop (f,thread)
{
cell_t c0 = F_C0(f,thread);

BOUNDARY_FACE_GEOMETRY(f,thread,A,ds,es,A_by_es,dr0);
At = NV_MAG(A);

if (NULLP(T_STORAGE_R_NV(t0,SV_UDSI_G(P1))))
Gsource = 0.; /* if gradient not stored yet */
else
BOUNDARY_SECONDARY_GRADIENT_SOURCE(Gsource,SV_UDSI_G(P1),
dG,es,A_by_es,1.);

gamma0 = C_UDSI_DIFF(c0,t0,P1);
alpha0 = A_by_es/ds;
beta0 = Gsource/alpha0;
aterm = alpha0*gamma0/At;

Ibw = SIGMA_SBC*pow(WALL_TEMP_OUTER(f,thread),4.)/M_PI;

/* Specify the radiative heat flux. */


F_PROFILE(f,thread,position) =
aterm*Ew/(Ew + aterm)*(4.*M_PI*Ibw - C_UDSI(c0,t0,P1) + beta0);
}
end_f_loop (f,thread)
}

DEFINE_HEAT_FLUX(heat_flux, f, t, c0, t0, cid, cir)


{
real Ew = epsilon_w/(2.*(2. - epsilon_w));

cid[0] = Ew * F_UDSI(f,t,P1);
cid[3] = 4.0 * Ew * SIGMA_SBC;

#define DEFINE_ADJUST(name, domain) \


void name(Domain *domain)
#define DEFINE_INIT(name, domain) \
void name(Domain *domain)
#define DEFINE_ON_DEMAND(name) \
void name(void)
#define DEFINE_RW_FILE(name, fp) \
void name(FILE *fp)

#define DEFINE_CG_MOTION(name, dt, vel, omega, time, dtime) \


void name(void *dt, real vel[], real omega[], real time, real dtime)
#define DEFINE_DIFFUSIVITY(name, c, t, i)
real name(cell_t c, Thread *t, int i)
#define DEFINE_GEOM(name, d, dt, position) \
void name(Domain *d, void *dt, real *position)
#define DEFINE_GRID_MOTION(name, d, dt, time, dtime) \
void name(Domain *d, void *dt, real time, real dtime)
#define DEFINE_HEAT_FLUX(name, f, t, c0, t0, cid, cir) \
void name(face_t f, Thread *t, cell_t c0, \
Thread *t0, real cid[], real cir[])
#define DEFINE_NOX_RATE(name, c, t, NOx) \
void name(cell_t c, Thread *t, NOx_Parameter *NOx)
#define DEFINE_PROFILE(name, t, i) \
void name(Thread *t, int i)
#define DEFINE_PROPERTY(name, c, t) \
real name(cell_t c, Thread *t)

#define DEFINE_SCAT_PHASE_FUNC(name, c, f) \
real name(real c, real *f)
#define DEFINE_SOURCE(name, c, t, dS, i) \
real name(cell_t c, Thread *t, real dS[], int i)
#define DEFINE_SR_RATE(name, f, t, r, mw, yi, rr) \
void name(face_t c, Thread *t, \
Reaction *r, real *mw, real *yi, real *rr)
#define DEFINE_TURB_PREMIX_SOURCE(name, c, t, turbulent_flame_speed, source) \
void name(cell_t c, Thread *t, real *turbulent_flame_speed, real *source)
#define DEFINE_TURBULENT_VISCOSITY(name, c, t) real name(cell_t c, Thread *t)
#define DEFINE_UDS_FLUX(name, f, t, i) \
real name(face_t f, Thread *t, int i)
#define DEFINE_UDS_UNSTEADY(name, c, t, i, apu, su) \
void name(cell_t c, Thread *t, int i, real *apu, real *su)
#define DEFINE_VR_RATE(name, c, t, r, mw, yi, rr, rr_t) \
void name(cell_t c, Thread *t, \
Reaction *r, real *mw, real *yi, \
real *rr, real *rr_t)

#define DEFINE_CAVITATION_RATE(name, c, t, p, rhoV, rhoL, vofV, p_v, n_b, m_dot) \


void name(cell_t c, Thread *t, real *p, real *rhoV, real *rhoL, real *vofV, \
real *p_v, real *n_b, real *m_dot)
#define DEFINE_DRIFT_DIAM(name, c, t) \
real name(cell_t c, Thread *t)
#define DEFINE_EXCHANGE_PROPERTY(name, c, mixture_thread, \
second_column_phase_index, first_column_phase_index) \
real name(cell_t c, Thread *mixture_thread, int second_column_phase_index,\
int first_column_phase_index)
#define DEFINE_VECTOR_EXCHANGE_PROPERTY(name, c, mixture_thread, \
second_column_phase_index, first_column_phase_index, vector_result) \
void name(cell_t c, Thread *mixture_thread, int second_column_phase_index,\
int first_column_phase_index, real *vector_result)

#define DEFINE_DPM_BODY_FORCE(name, p, i) \
real name(Tracked_Particle *p, int i)
#define DEFINE_DPM_DRAG(name, Re) \
real name(real Re)
#define DEFINE_DPM_SOURCE(name, c, t, S, strength, p) \
void name(cell_t c, Thread *t, dpms_t *S, \
real strength, Tracked_Particle *p)
#define DEFINE_DPM_PROPERTY(name, c, t, p) \
real name(cell_t c, Thread *t, Tracked_Particle *p)
#define DEFINE_DPM_OUTPUT(name, header, fp, p, t, plane) \
void name(int header, FILE *fp, \
Tracked_Particle *p, Thread *t, Plane *plane)
#define DEFINE_DPM_EROSION(name, p, t, f, normal, alpha, Vmag, mdot) \
void name(Tracked_Particle *p, Thread *t, \
face_t f, real normal[], real alpha, \
real Vmag, real mdot)
#define DEFINE_DPM_SCALAR_UPDATE(name, c, t, initialize, p) \
void name(cell_t c, Thread *t, int initialize, \
Tracked_Particle *p)

#define DEFINE_DPM_LAW(name, p, ci)


void name(Tracked_Particle *p, int ci)
#define DEFINE_DPM_SWITCH(name, p, ci) \
void name(Tracked_Particle *p, int ci)
#define DEFINE_DPM_INJECTION_INIT(name, I) \
void name(Injection *I)

You might also like