alikuyuk
Subscriber
Also, here is the code:n/**********************************************************************nConcatenated UDFs for the Discrete Phase Model includingnan implementation of a condensation modelnan example for the use of DPM_SWITCHn***********************************************************************/n#include "udf.h"n#include "dpm.h"n#define UDM_RH 0 /* no. of UDM holding relative humidity */n#define N_REQ_UDM 1 /* 1 more than UDM_RH */n#define CONDENS 1.0e-4 /* a condensation rate constant */nint h2o_index=0; /* index of water vapor species in mixture material */nreal mw_h2o=18.; /* molecular weight of water */nreal H2O_Saturation_Pressure(real T)n{nreal ratio, aTmTp;nT = MAX(T, 273);nT = MIN(T, 647.286);naTmTp = .01 * (T - 338.15);nratio = (647.286 / T - 1.) *n(-7.419242 + aTmTp * (.29721 +naTmTp * (-.1155286 +naTmTp * (8.685635e-3 +naTmTp * (1.094098e-3 +naTmTp * (-4.39993e-3 +naTmTp * (2.520658e-3 -naTmTp * 5.218684e-4)))))));nreturn (22.089e6 * exp(MIN(ratio, 35.)));n}nreal myHumidity(cell_t c, Thread *t)n{nint i;nMaterial *m = THREAD_MATERIAL(t), *sp;nreal yi_h2o = 0; /* water mass fraction */nreal r_mix = 0.0; /* sum of [mass fraction / mol. weight] over all species */nreal humidity;nif ((MATERIAL_TYPE(m) == MATERIAL_MIXTURE) && (FLUID_THREAD_P(t)))n{nyi_h2o = C_YI(c, t, h2o_index); /* water vapor mass fraction */nmixture_species_loop(m, sp, i)n{nr_mix += C_YI(c,t,i) / MATERIAL_PROP(sp, PROP_mwi);n}nhumidity = op_pres * yi_h2o / (mw_h2o * r_mix) /nH2O_Saturation_Pressure(C_T(c,t));nreturn humidity;n}nelsenreturn 0.;n}nDEFINE_DPM_LAW(condenshumidlaw, p, coupled)n{nreal area;nreal mp_dot;n/* Get Cell and Thread from Particle Structure */ncell_t c = P_CELL(p);nThread *t = P_CELL_THREAD(p);narea = 4.0 * M_PI * (P_DIAM(p) * P_DIAM(p));n/* Note This law only used if Humidity > 1.0 so mp_dot always positive*/nmp_dot = CONDENS * sqrt(area) * (myHumidity(c, t) - 1.0);nif (mp_dot > 0.0)n{nP_MASS(p) += mp_dot * P_DT(p);nP_DIAM(p) = pow(6.0 * P_MASS(p) / (P_RHO(p) * M_PI), 1./3.);n}n/* Assume condensing particle is in thermal equilibrium with fluid in cell */nP_T(p) = C_T(c,t);n}nDEFINE_DPM_SOURCE(dpm_source, c, t, S, strength, p)n{nreal mp_dot;n/* mp_dot is the mass source to the continuous phasen* (Difference in mass between entry and exit from cell)n* multiplied by strength (Number of particles/s in stream)n*/nmp_dot = (P_MASS0(p) - P_MASS(p)) * strength;nif (P_CURRENT_LAW(p) == DPM_LAW_USER_1)n{n/* Sources relevant to the user law 1:n* add the source to the condensing speciesn* equation and adjust the energy source byn* adding the latent heat at reference temperaturen*/nS->species[h2o_index] += mp_dot;nS->energy -= mp_dot * P_INJECTION(p)->latent_heat_ref;n}n}nDEFINE_DPM_SWITCH(dpm_switch, p, coupled)n{ncell_t c = P_CELL(p);nThread *t = P_CELL_THREAD(p);nMaterial *m = P_MATERIAL(p);n/* If the relative humidity is higher than 1n* and the particle temperature below the boiling temperaturen* switch to condensation lawn*/nif ((C_UDMI(c,t,UDM_RH) > 1.0) && (P_T(p) < DPM_BOILING_TEMPERATURE(p, m)))nP_CURRENT_LAW(p) = DPM_LAW_USER_1;nelsenP_CURRENT_LAW(p) = DPM_LAW_INITIAL_INERT_HEATING;n}nDEFINE_ADJUST(adj_relhum, domain)n{ncell_t cell;nThread *thread;nif(sg_udm < N_REQ_UDM)nMessage("\Not enough user defined memory allocated. %d required.\",nN_REQ_UDM);nelsen{nreal humidity, min, max;nmin = 1e10;nmax = 0.0;nthread_loop_c(thread, domain)n{n/* Check if thread is a Fluid thread and has UDMs set up on it */nif (FLUID_THREAD_P(thread) &&ULLP(THREAD_STORAGE(thread, SV_UDM_I)))n{nMaterial *m = THREAD_MATERIAL(thread), *sp;nint i;n/* Set the species index and molecular weight of water */nif (MATERIAL_TYPE(m) == MATERIAL_MIXTURE)nmixture_species_loop (m,sp,i)n{nif (0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"h2o") ||n(0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"H2O")))n{nh2o_index = i;nmw_h2o = MATERIAL_PROP(sp,PROP_mwi);n}n}nbegin_c_loop(cell,thread)n{nhumidity = myHumidity(cell, thread);nmin = MIN(min, humidity);nmax = MAX(max, humidity);nC_UDMI(cell, thread, UDM_RH) = humidity;n}nend_c_loop(cell, thread)n}n}nMessage("\Relative Humidity set in udm-%d", UDM_RH);nMessage(" range:(%f,%f)\", min, max);n}/* end if for enough UDSs and UDMs */n}nDEFINE_ON_DEMAND(set_relhum)n{nadj_relhum(Get_Domain(1));