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/)
-   -   Why my udf for condensation is useless (https://www.cfd-online.com/Forums/fluent-udf/227950-why-my-udf-condensation-useless.html)

Su M Z June 15, 2020 07:20

Why my udf for condensation is useless
 
Hello Everyone,
I am trying to use the udf code to simulate in-tube condensation of the steam and air mixture.The VOF model and the species transport model were enabled in Fluent, and the udf code was compiled and loaded without error. A liquid phase mass source term, a gas phase mass source term, and an energy source term are defined. My idea is to judge whether it is a vapor-liquid interface firstly, if it is, then assign a value to the source term, if not, then continue to judge whether it is a wall surface. The thickness of the first layer of my adherent mesh is 0.03mm. Here's my code. There's no condensation after running the case. Anybody know why that is? Any comments would be appreciated.

#include "udf.h"
#include "sg.h"
#include "sg_mphase.h"
#include "flow.h"
#include "mem.h"
#define air_molecular 28.966
#define vapor_molecular 18.0152
#define lam 0.8
#define standard_temper 298.15
#define standard_pressure 101325
#define standard_diffusivity 2.56e-5
#define SYMMETRY 13

#define WALL_NUMBER1 12
#define prim_index 0
#define index_evap_primary 1
#define p_op 101325
int phase_domain_index;
real face_center[ND_ND], cell_center[ND_ND], a[ND_ND], b[ND_ND];
real p, diffusivity, Wvol;
real cell_vapor_pressure, wall_temper, wall_pressure;
real NV_VEC(A),j,i;
real area, area_density, mass_transfer_coeff, B1, area1;
real water_temper, water_satpressure;
real vapor_density,u,v;
int n;
Domain *domain1;
cell_t c;
Thread *t;
Thread *tp;
Thread *ts;
Thread *tf,*tb;
face_t fa;
face_t fb ;
real source;
double latent_heat(double Tsat)
{
double sum;
sum=2501.7-2.4114*(Tsat-273.15);
return sum;
}


DEFINE_SOURCE(vap_src,cell,first,dS,eqn)
{
Thread *mixer, *sec_th;
Thread *sym;
face_t f;
real m_dot_first;
real mass_dot;
mixer = THREAD_SUPER_THREAD(first);
sec_th = THREAD_SUB_THREAD(mixer,1);

if (C_VOF(cell, first) > 0&&C_VOF(cell, first) < 1)
{

mass_dot = -2.56e-4;
dS[eqn] =0;
}
else
{
mass_dot =0;
dS[eqn]=0;

c_face_loop(cell, mixer, n)
{
fa = C_FACE(cell, mixer, n);
tf = C_FACE_THREAD(cell, mixer, n);
F_CENTROID(face_center, fa, tf);
if (face_center[0] < 1e-5)
{
mass_dot = -2.56e-4;
dS[eqn] =0;


}
}
}
source = mass_dot;
return source;
}



DEFINE_SOURCE(liq_src, cell, sec_th, dS, eqn)
{
Thread *mixer, *first;
Thread *sym;
face_t f;
real mass_dot;
mixer = THREAD_SUPER_THREAD(sec_th);
first = THREAD_SUB_THREAD(mixer, 0);
if (C_VOF(cell, sec_th) > 0&&C_VOF(cell, sec_th) < 1)
{

mass_dot = 2.56e-4;
dS[eqn] =0;
}
else
{
mass_dot =0;
dS[eqn]=0;
c_face_loop(cell, mixer, n)
{
fa = C_FACE(cell, mixer, n);
tf = C_FACE_THREAD(cell, mixer, n);
F_CENTROID(face_center, fa, tf);
if (face_center[0]< 1e-5)
{
mass_dot = 2.56e-4;
dS[eqn] =0;



}
}
}
source = mass_dot;
return source;
}



DEFINE_SOURCE(enrg_src, cell, mixer, dS, eqn)
{
Thread *first, *sec_th;
Thread *sym;
face_t f ;
real m_dot, latentheat;
real mass_dot;
first = THREAD_SUB_THREAD(mixer, 0);
sec_th = THREAD_SUB_THREAD(mixer, 1);
/************************************************/

if (C_VOF(cell, sec_th) > 0&&C_VOF(cell, sec_th) < 1)
{
mass_dot = -2.56e-4;
dS[eqn] =0;

}
else
{
latentheat = latent_heat(C_T(cell, first));
mass_dot =0;
dS[eqn]=0;
c_face_loop(cell, mixer, n)
{
fa = C_FACE(cell, mixer, n);
tf = C_FACE_THREAD(cell, mixer, n);
F_CENTROID(face_center, fa, tf);
if (face_center[0] < 1e-5)
{
mass_dot = -2.56e-4;
dS[eqn] =0;



}
}
}

m_dot = -mass_dot;
return latentheat*m_dot;
}

vinerm June 15, 2020 07:35

The code
 
Your logic may be right but the code is very crude. First of all, C_VOF will always be less than 1, until the case diverges. So, you don't need to check for that. Secondly, the source UDF is executed over each cell and computers do not take 1 as 1; it could be 0.99999999999999. That means the code is being executed almost in each cell. And even in the energy source, the value of the source term is equal to mass.

What's the reason behind using a UDF and not using inbuilt model?

Su M Z June 15, 2020 08:13

First of all,thank you very much for your reply. In my set, the primary phase is the gas mixture, the secondary phase is liquid water. At the initial time there is no existence of the secondary phase. C_VOF is used to determine gas-liquid interface, at the initial moment, C_VOF values of all grid should be equal to 0, when the liquid filled with grid, C_VOF should be equal to 1, in both cases,the source terms are 0. The value of the energy source term is the mass times the latent heat, and I defined a function to find the latent heat. The above is my understanding,but I do not konw whether it is accurate. In addition to this,even the udf is crude,there should be a feedback,but there is no condensation in my case at all.As for the last question,I have read some relevant papers and found that many of them used udf, so I decided to try it.

vinerm June 15, 2020 09:10

Udf
 
If someone has used UDF, they might have had reasons for that, such as, older versions of Fluent.

If there is no liquid phase initially, then the code is supposed to add some liquid mass in the cells adjacent to the walls. But, since it is liquid, its volume would be extremely low, most likely below the cut-off value for the volume fraction. Default is 1e-6. Implying that nothing would happen and eventually, all the mass will be lost.

Su M Z June 15, 2020 21:06

Okay, I'll try. Thank you, buddy!


All times are GMT -4. The time now is 15:41.