fluent_udf
- 格式:doc
- 大小:67.50 KB
- 文档页数:10
/***********************************************************************/
/* 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)