You can use DEFINE_DPM_SWITCH to modify
the criteria for switching between laws. The function can be used
to control the switching between the user-defined particle laws and
the default particle laws, or between different user-defined or default
particle laws.
DEFINE_DPM_SWITCH (name, tp, ci)
|
Argument Type |
Description |
|---|---|
|
|
UDF name. |
|
|
Pointer to
the |
|
|
Variable that indicates
if the continuous and discrete phases are coupled (equal to |
Function returns
void
There are three arguments to DEFINE_DPM_SWITCH: name, tp, and
ci. You supply name, the name of the UDF. tp and ci are variables that are passed by the ANSYS Fluent solver
to your UDF.
Important: Pointer tp can be used as an argument
to the macros defined in DPM Macros to
obtain information about particle properties (for example, injection
properties).
The following is an example of a compiled UDF that uses DEFINE_DPM_SWITCH to switch between DPM laws using a
criterion. The UDF switches to DPM_LAW_USER_1 which refers to condenshumidlaw since only
one user law has been defined. The switching criterion is the local
humidity which is computed in the domain using a DEFINE_ON_DEMAND function, which again calls the function myHumidity for every cell. In the case where the humidity is greater than , condensation is computed
by applying a simple mass transfer calculation. Otherwise, ANSYS Fluent’s
standard law for Inert Heating is applied. The UDF requires one UDML
and needs a species called
h2o to compute
the local humidity.
/**********************************************************************
Concatenated UDFs for the Discrete Phase Model including
an implementation of a condensation model
an example for the use of DPM_SWITCH
***********************************************************************/
#include "udf.h"
#include "dpm.h"
#define UDM_RH 0 /* no. of UDM holding relative humidity */
#define N_REQ_UDM 1 /* 1 more than UDM_RH */
#define CONDENS 1.0e-4 /* a condensation rate constant */
int h2o_index=0; /* index of water vapor species in mixture material */
real mw_h2o=18.; /* molecular weight of water */
real H2O_Saturation_Pressure(real T)
{
real ratio, aTmTp;
T = MAX(T, 273);
T = MIN(T, 647.286);
aTmTp = .01 * (T - 338.15);
ratio = (647.286 / T - 1.) *
(-7.419242 + aTmTp * (.29721 +
aTmTp * (-.1155286 +
aTmTp * (8.685635e-3 +
aTmTp * (1.094098e-3 +
aTmTp * (-4.39993e-3 +
aTmTp * (2.520658e-3 -
aTmTp * 5.218684e-4)))))));
return (22.089e6 * exp(MIN(ratio, 35.)));
}
real myHumidity(cell_t c, Thread *t)
{
int i;
Material *m = THREAD_MATERIAL(t), *sp;
real yi_h2o = 0; /* water mass fraction */
real r_mix = 0.0; /* sum of [mass fraction / mol. weight] over all species */
real humidity;
if ((MATERIAL_TYPE(m) == MATERIAL_MIXTURE) && (FLUID_THREAD_P(t)))
{
yi_h2o = C_YI(c, t, h2o_index); /* water vapor mass fraction */
mixture_species_loop(m, sp, i)
{
r_mix += C_YI(c,t,i) / MATERIAL_PROP(sp, PROP_mwi);
}
humidity = op_pres * yi_h2o / (mw_h2o * r_mix) /
H2O_Saturation_Pressure(C_T(c,t));
return humidity;
}
else
return 0.;
}
DEFINE_DPM_LAW(condenshumidlaw, tp, coupled)
{
real area;
real mp_dot;
/* Get Cell and Thread from Particle Structure */
cell_t c = TP_CELL(tp);
Thread *t = TP_CELL_THREAD(tp);
area = 4.0 * M_PI * (TP_DIAM(tp) * TP_DIAM(tp));
/* Note This law only used if Humidity > 1.0 so mp_dot always positive*/
mp_dot = CONDENS * sqrt(area) * (myHumidity(c, t) - 1.0);
if (mp_dot > 0.0)
{
TP_MASS(tp) += mp_dot * TP_DT(tp);
TP_DIAM(tp) = pow(6.0 * TP_MASS(tp) / (TP_RHO(tp) * M_PI), 1./3.);
}
/* Assume condensing particle is in thermal equilibrium with fluid in cell */
TP_T(tp) = C_T(c,t);
}
DEFINE_DPM_SOURCE(dpm_source, c, t, S, strength, tp)
{
real mp_dot;
/* mp_dot is the mass source to the continuous phase
* (Difference in mass between entry and exit from cell)
* multiplied by strength (Number of particles/s in stream)
*/
mp_dot = (TP_MASS0(tp) - TP_MASS(tp)) * strength;
if (TP_CURRENT_LAW(tp) == DPM_LAW_USER_1)
{
/* Sources relevant to the user law 1:
* add the source to the condensing species
* equation and adjust the energy source by
* adding the latent heat at reference temperature
*/
S->species[h2o_index] += mp_dot;
S->energy -= mp_dot * TP_INJECTION(tp)->latent_heat_ref;
}
}
DEFINE_DPM_SWITCH(dpm_switch, tp, coupled)
{
cell_t c = TP_CELL(tp);
Thread *t = TP_CELL_THREAD(tp);
Material *m = TP_MATERIAL(tp);
/* If the relative humidity is higher than 1
* and the particle temperature below the boiling temperature
* switch to condensation law
*/
if ((C_UDMI(c,t,UDM_RH) > 1.0) && (TP_T(tp) < DPM_BOILING_TEMPERATURE(tp, m)))
TP_CURRENT_LAW(tp) = DPM_LAW_USER_1;
else
TP_CURRENT_LAW(tp) = DPM_LAW_INITIAL_INERT_HEATING;
}
DEFINE_ADJUST(adj_relhum, domain)
{
cell_t cell;
Thread *thread;
if(sg_udm < N_REQ_UDM)
Message("\nNot enough user defined memory allocated. %d required.\n",
N_REQ_UDM);
else
{
real humidity, min, max;
min = 1e10;
max = 0.0;
thread_loop_c(thread, domain)
{
/* Check if thread is a Fluid thread and has UDMs set up on it */
if (FLUID_THREAD_P(thread) && NNULLP(THREAD_STORAGE(thread, SV_UDM_I)))
{
Material *m = THREAD_MATERIAL(thread), *sp;
int i;
/* Set the species index and molecular weight of water */
if (MATERIAL_TYPE(m) == MATERIAL_MIXTURE)
mixture_species_loop (m,sp,i)
{
if (0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"h2o") ||
(0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"H2O")))
{
h2o_index = i;
mw_h2o = MATERIAL_PROP(sp,PROP_mwi);
}
}
begin_c_loop(cell,thread)
{
humidity = myHumidity(cell, thread);
min = MIN(min, humidity);
max = MAX(max, humidity);
C_UDMI(cell, thread, UDM_RH) = humidity;
}
end_c_loop(cell, thread)
}
}
Message("\nRelative Humidity set in udm-%d", UDM_RH);
Message(" range:(%f,%f)\n", min, max);
}/* end if for enough UDSs and UDMs */
}
DEFINE_ON_DEMAND(set_relhum)
{
adj_relhum(Get_Domain(1));
}
After the UDF that you have defined using DEFINE_DPM_SWITCH is interpreted (Interpreting UDFs)
or compiled (Compiling UDFs), the name
of the argument that you supplied as the first DEFINE macro argument will become visible in the Custom Laws dialog box in ANSYS Fluent. See Hooking DEFINE_DPM_SWITCH UDFs for details on how to hook your DEFINE_DPM_SWITCH UDF to ANSYS Fluent.