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/)
-   -   UDF for evaporation (https://www.cfd-online.com/Forums/fluent-udf/125353-udf-evaporation.html)

pranab_jha October 23, 2013 20:05

UDF for evaporation
 
Hello,

I am trying to model evaporation from a droplet. So I have to apply my evaporation model at the interface. I have a 2D axisymmetric case set up. But I am not able to get my UDF to work. Could someone take a look and let me know please. Comments are added for convenience.

SUmmary of the code:
-I have used the DEFINE_MASS_TRANSFER macro and defined all variables and initialized them.

-I calculated saturation pressure using a polynomial function of cell temperature.

-Then the mass fraction of each species is used to compute the molar fraction of required species.

-Then I compute the interfacial area density from the volume fraction gradient.

-Then using that, I compute the mass transferred by evaporation.

Thanks for any help!!!

Temporary solver memory has been turned on from the solve-set-expert menu in Fluent.

/************************************************** *********
UDF to apply mass transfer rate from liquid to gas phase at the interface
************************************************** **********/
#include "udf.h"
#include "sg_mphase.h"
#include "materials.h"

#define MW_W 18.0
#define MW_A 29.0
#define R 8.314
#define pi 3.14159
#define a_c 0.04 /*accommodation coefficient*/

DEFINE_MASS_TRANSFER(mass_transfer1, c, mixture_thread, from_phase_index, from_species_index, to_phase_index, to_species_index)
{
/************ Declare variables *********/
float m_lg, T_cell, P_cell, P_sat;
float NV_VEC(G);
float X_W, Y_W, Y_A;
float cur_ts;
Thread *w_liq, *gas_mix, *w_gas;
face_t f;
Domain *mix_domain, *pdomain;
int i, pdomain_index;
float area[ND_ND], A, ad, theta, cotan, len;

/******** Define variables *********/
mix_domain = Get_Domain(1);
/* pdomain = DOMAIN_SUB_DOMAIN(mixture_domain,1); */ /* For gas domain */
pdomain_index = 0;
pdomain = DOMAIN_SUB_DOMAIN(mix_domain,pdomain_index);

w_liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index);
gas_mix = THREAD_SUB_THREAD(mixture_thread, to_phase_index);
w_gas = THREAD_SUB_THREAD(mixture_thread, to_species_index);

T_cell = C_T(c,mixture_thread); /*cell mixture temperature*/
P_cell = C_P(c,mixture_thread); /*cell mixture pressure*/
m_lg = 0.;
cur_ts = CURRENT_TIMESTEP; /* real time step size (in seconds)*/

/* compute saturation pressure for water vapor using polynomial fit */
P_sat = 0.000001*pow(T_cell,5) - 0.001*pow(T_cell,4) + 0.681*pow(T_cell,3) - 203.9*pow(T_cell,2) + 39482*T_cell + 4000000;

/* calculate molar fraction X_W from mass fraction Y_W */
Y_W = C_YI(c,gas_mix,0); /* index for water vap = 0, air = 1*/
Y_A = C_YI(c,gas_mix,1);
X_W = (Y_W*29)/((29*Y_W) + (18*Y_A));

/**** Compute the interfacial area density ****/
NV_V(G,=,C_VOF_G(c,w_liq)); /* vof gradient vector assignment*/

theta = atan(G[0]/G[1]); /* compute angle of VOF gradient vector, n1/n2 because of how geometry is set up in Fluent */
cotan = cos(theta) / sin(theta); /* compute cotangent of angle*/

A = C_VOLUME(c,mixture_thread)/(2*pi); /* in 2D- axis area computed from volume */

len = sqrt((2*C_VOF(c,w_liq)*A/cotan) + (2*C_VOF(c,w_liq)*A*cotan)); /* compute length of interface in a cell */

ad = len/A; /* calculate interfacial area density*/
/***** Computed the area density ad = length of interface / area of cell ***/

if (C_VOF(c, w_liq) != 0.0 && C_VOF(c, w_liq) != 1.0)
{
Message("AD = %f, theta = %f\n",ad, theta);

/* Compute m_lg only if P_sat > (Pcell*XW) */
if (P_sat - (P_cell*X_W) > 0.0)
{
m_lg = cur_ts * ad *(2*a_c/(2-a_c)) * sqrt(MW_W/(2*pi*R)) * ((P_sat - (P_cell*X_W)) / sqrt(T_cell));
}
else
{ m_lg = 0.0;}
}
else
{ m_lg = 0.0;}

return (m_lg); /* return value of mass transfer rate */

}

pranab_jha October 25, 2013 11:32

Just a quick update. The problem has not yet been solved. But if I remove the line
NV_V(G,=,C_VOF_G(c,w_liq)); and related dependents, the code works fine.

Although, I have used the option of keeping the solver temporary memory, C_VOF_G is giving me the issue, which is strange. Still working on it. If someone has any suggestions, please do post.

Thanks.

MichaelVS December 2, 2013 08:56

Dear pranab_jha,

Could you please specify the solution if you find one?
I am facing exactly the same problem with C_VOF_G.

Omarspace February 20, 2015 08:02

Hi , I am sorry but did no body of you find a solution for that ?
I checked the sg_mphase.h and i found the line
#define C_VOF_G(c,t) C_STORAGE_R_NV(c,t,SV_VOF_G)
and working with expert mood without freeing my memory i think VOF data should be saved .. Actually it is sent to my udf with zero value all of times despite it has value when i plot it in Fluent Solver .. did anyone find solution for this ?

rampal January 7, 2016 08:44

phase change problem inside heat pipe
 
Dear friends, I'm doing my project work on heat pipe simulation in fluent software. I have written udf for mass and energy source for phase change inside heat pipe. But condensation is not happening in evaporator section. If anyone have done this type of problem, please help me.

Thanks

My udf is paste below:


#include "udf.h"
#include "sg_mphase.h"
#include "mem.h"
#include "metric.h"
#include "flow.h"
#include "sg.h"
#define T_SAT 373.15
#define LAT_HT 2455.1345e3


DEFINE_SOURCE(vap_src,cell,pri_th,dS,eqn) /*vapour source udf*/
{
real m_dot_v;
Thread *mix_th, *sec_th;
mix_th = THREAD_SUPER_THREAD(pri_th);
sec_th = THREAD_SUB_THREAD(mix_th,1);
m_dot_v=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_v = 0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = 0.0;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_v = -0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
}
return m_dot_v;
}



DEFINE_SOURCE(liq_src,cell,sec_th,dS,eqn) /*liquid source udf*/
{
real m_dot_l;
Thread *mix_th, *pri_th;
mix_th = THREAD_SUPER_THREAD(sec_th);
pri_th = THREAD_SUB_THREAD(mix_th,0);
m_dot_l=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_l = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_R(cell,sec_th)*(C_T(cell,sec_th)-T_SAT)/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_l = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] =0.0;
}
return m_dot_l;
}



DEFINE_SOURCE(enrg_src,cell,mix_th,dS,eqn) /*energy source udf*/
{
real enrg_dot;
Thread *pri_th, *sec_th;
pri_th = THREAD_SUB_THREAD(mix_th,0);
sec_th = THREAD_SUB_THREAD(mix_th,1);
enrg_dot = 0.0;
if (C_T(cell,sec_th)>T_SAT)
{
enrg_dot = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT*(C_ T(cell,sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
enrg_dot = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*LAT_HT*(T_ SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,pri_th)*C_R(cell, pri_th)*LAT_HT/T_SAT;
}
return enrg_dot;
}

Abdelhamid Kassem October 18, 2016 13:37

Help in simulation of heat pipe (fluent).
 
Quote:

Originally Posted by rampal (Post 579935)
Dear friends, I'm doing my project work on heat pipe simulation in fluent software. I have written udf for mass and energy source for phase change inside heat pipe. But condensation is not happening in evaporator section. If anyone have done this type of problem, please help me.

Thanks

My udf is paste below:


#include "udf.h"
#include "sg_mphase.h"
#include "mem.h"
#include "metric.h"
#include "flow.h"
#include "sg.h"
#define T_SAT 373.15
#define LAT_HT 2455.1345e3


DEFINE_SOURCE(vap_src,cell,pri_th,dS,eqn) /*vapour source udf*/
{
real m_dot_v;
Thread *mix_th, *sec_th;
mix_th = THREAD_SUPER_THREAD(pri_th);
sec_th = THREAD_SUB_THREAD(mix_th,1);
m_dot_v=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_v = 0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = 0.0;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_v = -0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
}
return m_dot_v;
}



DEFINE_SOURCE(liq_src,cell,sec_th,dS,eqn) /*liquid source udf*/
{
real m_dot_l;
Thread *mix_th, *pri_th;
mix_th = THREAD_SUPER_THREAD(sec_th);
pri_th = THREAD_SUB_THREAD(mix_th,0);
m_dot_l=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_l = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_R(cell,sec_th)*(C_T(cell,sec_th)-T_SAT)/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_l = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] =0.0;
}
return m_dot_l;
}



DEFINE_SOURCE(enrg_src,cell,mix_th,dS,eqn) /*energy source udf*/
{
real enrg_dot;
Thread *pri_th, *sec_th;
pri_th = THREAD_SUB_THREAD(mix_th,0);
sec_th = THREAD_SUB_THREAD(mix_th,1);
enrg_dot = 0.0;
if (C_T(cell,sec_th)>T_SAT)
{
enrg_dot = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT*(C_ T(cell,sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
enrg_dot = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*LAT_HT*(T_ SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,pri_th)*C_R(cell, pri_th)*LAT_HT/T_SAT;
}
return enrg_dot;
}

----------------------------------------------------------------------------------
Anyone succeed to simulate the heat pipe evaporator and condenser?
I'm doing my bachelor project on it and i will appreciate any help in this case because, i'm beginner with fluent however, i know the equations of energy and momentum which need to be written in the UDF but i failed to simulate it.
My email : Abdelhamidkassem93@gmail.com
If anyone have udf or tutorials to help me in this case.

eaxhm1 April 21, 2017 07:29

[QUOTE=pranab_jha;458640]Hello,

I am trying to model evaporation from a droplet. So I have to apply my evaporation model at the interface. I have a 2D axisymmetric case set up. But I am not able to get my UDF to work. Could someone take a look and let me know please. Comments are added for convenience.

SUmmary of the code:
-I have used the DEFINE_MASS_TRANSFER macro and defined all variables and initialized them.



Hello Branab,
I have a case similar to this case, please, did you manage to run this UDF, if so, please could you send me the correct version of it, I really appreciate.


Hayder

vidyadhar November 29, 2018 01:05

storing gradients of VOF in UDMI in VOF method?
 
Quote:

Originally Posted by pranab_jha (Post 459015)
Just a quick update. The problem has not yet been solved. But if I remove the line
NV_V(G,=,C_VOF_G(c,w_liq)); and related dependents, the code works fine.

Although, I have used the option of keeping the solver temporary memory, C_VOF_G is giving me the issue, which is strange. Still working on it. If someone has any suggestions, please do post.

Thanks.


Hello Pranab,
I am working to model evaporation of a liquid into its vapor using VOF.
In the UDF that I am writing for this, I want to write an expression for calculating the gradient of volume fraction which represents the interfacial area density.
But, I am unable to store the values of gradients of volume fraction i.e., C_VOF_G.
I am getting zero value for C_UDMI and source, If I use the code lines:
if (C_VOF(cell,cell_thread)!=0.0 && C_VOF(cell,cell_thread)!=1.0)
{
source=3.2*(C_T(cell,cell_thread)-T_SAT)*(C_VOF_G(cell,cell_thread)[0]);
C_UDMI(cell,cell_thread,0) = source;
printf("source= %g\n",source);
}

If you have succeeded in storing the values of C_VOF_G and using them to estimate interfacial area density, I request you to help me how to do it.


Thanks in advance!
Vidyadhar

violin000 January 15, 2019 06:09

Quote:

Originally Posted by rampal (Post 579935)
Dear friends, I'm doing my project work on heat pipe simulation in fluent software. I have written udf for mass and energy source for phase change inside heat pipe. But condensation is not happening in evaporator section. If anyone have done this type of problem, please help me.

Thanks

My udf is paste below:


#include "udf.h"
#include "sg_mphase.h"
#include "mem.h"
#include "metric.h"
#include "flow.h"
#include "sg.h"
#define T_SAT 373.15
#define LAT_HT 2455.1345e3


DEFINE_SOURCE(vap_src,cell,pri_th,dS,eqn) /*vapour source udf*/
{
real m_dot_v;
Thread *mix_th, *sec_th;
mix_th = THREAD_SUPER_THREAD(pri_th);
sec_th = THREAD_SUB_THREAD(mix_th,1);
m_dot_v=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_v = 0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = 0.0;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_v = -0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
}
return m_dot_v;
}



DEFINE_SOURCE(liq_src,cell,sec_th,dS,eqn) /*liquid source udf*/
{
real m_dot_l;
Thread *mix_th, *pri_th;
mix_th = THREAD_SUPER_THREAD(sec_th);
pri_th = THREAD_SUB_THREAD(mix_th,0);
m_dot_l=0.0;
if (C_T(cell,sec_th)>T_SAT)
{
m_dot_l = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*(C_T(cell, sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_R(cell,sec_th)*(C_T(cell,sec_th)-T_SAT)/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
m_dot_l = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*(T_SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] =0.0;
}
return m_dot_l;
}



DEFINE_SOURCE(enrg_src,cell,mix_th,dS,eqn) /*energy source udf*/
{
real enrg_dot;
Thread *pri_th, *sec_th;
pri_th = THREAD_SUB_THREAD(mix_th,0);
sec_th = THREAD_SUB_THREAD(mix_th,1);
enrg_dot = 0.0;
if (C_T(cell,sec_th)>T_SAT)
{
enrg_dot = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT*(C_ T(cell,sec_th)-T_SAT)/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,sec_th)*C_R(cell,sec_th)*LAT_HT/T_SAT;
}
if (C_T(cell,pri_th)<T_SAT)
{
enrg_dot = 0.1*C_VOF(cell,pri_th)*C_R(cell,pri_th)*LAT_HT*(T_ SAT-C_T(cell,pri_th))/T_SAT;
dS[eqn] = -0.1*C_VOF(cell,pri_th)*C_R(cell, pri_th)*LAT_HT/T_SAT;
}
return enrg_dot;
}

Hello, I also use this UDF, but I have not evaporated. Is this your problem solved?

Quote:

Originally Posted by Abdelhamid Kassem (Post 621978)
----------------------------------------------------------------------------------
Anyone succeed to simulate the heat pipe evaporator and condenser?
I'm doing my bachelor project on it and i will appreciate any help in this case because, i'm beginner with fluent however, i know the equations of energy and momentum which need to be written in the UDF but i failed to simulate it.
My email : Abdelhamidkassem93@gmail.com
If anyone have udf or tutorials to help me in this case.

Hello, I also use this UDF, but I have not evaporated. Is this your problem solved? Could you tell me how to change it?

RestlessBreeze September 3, 2021 23:47

Quote:

Originally Posted by pranab_jha (Post 458640)
Hello,

I am trying to model evaporation from a droplet. So I have to apply my evaporation model at the interface. I have a 2D axisymmetric case set up. But I am not able to get my UDF to work. Could someone take a look and let me know please. Comments are added for convenience.

SUmmary of the code:
-I have used the DEFINE_MASS_TRANSFER macro and defined all variables and initialized them.

-I calculated saturation pressure using a polynomial function of cell temperature.

-Then the mass fraction of each species is used to compute the molar fraction of required species.

-Then I compute the interfacial area density from the volume fraction gradient.

-Then using that, I compute the mass transferred by evaporation.

Thanks for any help!!!

Temporary solver memory has been turned on from the solve-set-expert menu in Fluent.

/************************************************** *********
UDF to apply mass transfer rate from liquid to gas phase at the interface
************************************************** **********/
#include "udf.h"
#include "sg_mphase.h"
#include "materials.h"

#define MW_W 18.0
#define MW_A 29.0
#define R 8.314
#define pi 3.14159
#define a_c 0.04 /*accommodation coefficient*/

DEFINE_MASS_TRANSFER(mass_transfer1, c, mixture_thread, from_phase_index, from_species_index, to_phase_index, to_species_index)
{
/************ Declare variables *********/
float m_lg, T_cell, P_cell, P_sat;
float NV_VEC(G);
float X_W, Y_W, Y_A;
float cur_ts;
Thread *w_liq, *gas_mix, *w_gas;
face_t f;
Domain *mix_domain, *pdomain;
int i, pdomain_index;
float area[ND_ND], A, ad, theta, cotan, len;

/******** Define variables *********/
mix_domain = Get_Domain(1);
/* pdomain = DOMAIN_SUB_DOMAIN(mixture_domain,1); */ /* For gas domain */
pdomain_index = 0;
pdomain = DOMAIN_SUB_DOMAIN(mix_domain,pdomain_index);

w_liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index);
gas_mix = THREAD_SUB_THREAD(mixture_thread, to_phase_index);
w_gas = THREAD_SUB_THREAD(mixture_thread, to_species_index);

T_cell = C_T(c,mixture_thread); /*cell mixture temperature*/
P_cell = C_P(c,mixture_thread); /*cell mixture pressure*/
m_lg = 0.;
cur_ts = CURRENT_TIMESTEP; /* real time step size (in seconds)*/

/* compute saturation pressure for water vapor using polynomial fit */
P_sat = 0.000001*pow(T_cell,5) - 0.001*pow(T_cell,4) + 0.681*pow(T_cell,3) - 203.9*pow(T_cell,2) + 39482*T_cell + 4000000;

/* calculate molar fraction X_W from mass fraction Y_W */
Y_W = C_YI(c,gas_mix,0); /* index for water vap = 0, air = 1*/
Y_A = C_YI(c,gas_mix,1);
X_W = (Y_W*29)/((29*Y_W) + (18*Y_A));

/**** Compute the interfacial area density ****/
NV_V(G,=,C_VOF_G(c,w_liq)); /* vof gradient vector assignment*/

theta = atan(G[0]/G[1]); /* compute angle of VOF gradient vector, n1/n2 because of how geometry is set up in Fluent */
cotan = cos(theta) / sin(theta); /* compute cotangent of angle*/

A = C_VOLUME(c,mixture_thread)/(2*pi); /* in 2D- axis area computed from volume */

len = sqrt((2*C_VOF(c,w_liq)*A/cotan) + (2*C_VOF(c,w_liq)*A*cotan)); /* compute length of interface in a cell */

ad = len/A; /* calculate interfacial area density*/
/***** Computed the area density ad = length of interface / area of cell ***/

if (C_VOF(c, w_liq) != 0.0 && C_VOF(c, w_liq) != 1.0)
{
Message("AD = %f, theta = %f\n",ad, theta);

/* Compute m_lg only if P_sat > (Pcell*XW) */
if (P_sat - (P_cell*X_W) > 0.0)
{
m_lg = cur_ts * ad *(2*a_c/(2-a_c)) * sqrt(MW_W/(2*pi*R)) * ((P_sat - (P_cell*X_W)) / sqrt(T_cell));
}
else
{ m_lg = 0.0;}
}
else
{ m_lg = 0.0;}

return (m_lg); /* return value of mass transfer rate */

}

Hello, I am doing 3D droplet evaporation. I would like to ask if this UDF can be used for 3D evaporation model. thank you very much

Guvennergiz September 4, 2021 04:30

Why do you need an UDF to simulate evaporation in Fluent? I didnt perform this kind of sim. in Fluent before, but I am using Cradle right now and no need to any external function to perform that analysis.


All times are GMT -4. The time now is 08:27.