CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Problems with Saturation Temperature UDF and mass transfer UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By SteffenBcfd
  • 1 Post By AlexanderZ
  • 1 Post By Selawe97

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 7, 2022, 07:42
Default Problems with Saturation Temperature UDF and mass transfer UDF
  #1
New Member
 
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 4
SteffenBcfd is on a distinguished road
Hello,


I have two ssues regarding scripting UDFs.



It's a multiphase simulation with two phases, one liquid and one gas. The domaine is only a simple 2d pipe with a pressure inlet and a pressure outlet.



The first one is that a UDF for calculationg the saturation temperature as a function of pressure (Antoine Equation) always gives the value zero when I plot the C_UDMI(c, t, 1) = Tsat.



Here is the used script (I added three UDFs in one file (1.Surface Tension, Saturation Temperatur and Mass transfer, complied without errors):



#include "udf.h"
/*Set Gas primary phase*/
/*Set Liquid secondary phase*/
/**C_UDMI(cell,thread,0)=sigma, C_UDMI(cell,thread,1)=Tsat, C_UDMI(cell,thread,2)=m_evap, C_UDMI(cell,thread,3)=m_cond**/
DEFINE_PROPERTY(sfc, c, t)
{
real sfc;
real Temp = C_T(c, t);
real k1 = 0.0008;
real k2 = -0.3475;
real k3 = 31.068;
sfc = (k1 * pow(Temp, 2) + k2 * Temp + k3)*0.001;
C_UDMI(c, t, 0) = sfc;
return sfc;
}
DEFINE_PROPERTY(Tsat, c, t)
{
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(c, t);
real Tsat;
real pstatic = C_P(c, t);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
Tsat = (B / (A - (double)log10((double)pvap))) - C;
C_UDMI(c, t, 1) = Tsat;
return Tsat;
}


The second issue is about a mass transfer UDF aka

Lee evaporation model (it's the code from the ANSYS Fluent UDF Manual, Release 15.0, page 150-151).




DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real m_lg;
real T_SAT = C_UDMI(cell, thread, 1);
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
/***Lee Mass Transfer***/
m_lg = 0.;
if (C_T(cell, liq) >= T_SAT)
{
m_lg = -revap*C_VOF(cell,liq)*C_R(cell,liq)*fabs(C_T(cell, liq)-T_SAT)/T_SAT; /*Evaporation*/
C_UDMI(cell, thread, 4) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))
{
m_lg = rcond*C_VOF(cell,gas)*C_R(cell,gas)*fabs(T_SAT-C_T(cell,gas))/T_SAT; /*Condensation*/
C_UDMI(cell, thread, 5) = m_lg;
}
return (m_lg);
}


If I use a simplified version and set constant values for mass transfer (-2 for evaporation and 1 for condensation) the udf is running.



DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real m_lg;
real T_SAT = 77;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
m_lg = 0.;
if (C_T(cell, liq) >= T_SAT)
{
m_lg = -2; /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))
{
m_lg = 1; /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}



The boundary conditions aren't a problem, because when I use the implemented mass transfer Lee model, the simulation is running just fine.


Something is wrong in the mass transfer script and cause always floating point exception. If I understand it rigth it means division by zero.



Maybe someone has a clue what is causing the errors.


Greetings

Steffen
Eddy_94 and bidax like this.
SteffenBcfd is offline   Reply With Quote

Old   December 8, 2022, 00:36
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
1
Code:
Tsat = (B / (A - (double)log10((double)pvap))) - C;
may be (double) is a problem here, remove it, run fluent in double precision mode
Code:
Tsat = (B / (A - log10(pvap))) - C;
2
Code:
m_lg = -revap*C_VOF(cell,liq)*C_R(cell,liq)*fabs(C_T(cell, liq)-T_SAT)/T_SAT; /*Evaporation*/
/T_SAT; -> means division on 0, as: real T_SAT = C_UDMI(cell, thread, 1);
you may define T_SAT as a constant to test the code
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 8, 2022, 09:51
Default
  #3
New Member
 
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 4
SteffenBcfd is on a distinguished road
Dear Alexander,


thanks for your advice.


I colud solve the first issue (Tsat always 0K) through merging the Antoine equation into the mass transfer UDF, but the second error is still present.
Even if a change Tsat in 77 K.


DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
/*Parameters of Lee evaporation and condensation Model*/
real m_lg;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
m_lg = 0.;
/*Parameters of Antoine Equation for calculation of saturation temperature as function of pressure*/
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
/*Saturation Temperature calculation*/
Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;
/*Mass transfer calculation*/
if (C_T(cell, liq) >= 77.);
{
m_lg = - revap * C_VOF(cell, liq)*C_R(cell, liq)*fabs(C_T(cell, liq) - 77.) / 77.; /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= 77.))
{
m_lg = rcond * C_VOF(cell, gas)*C_R(cell, gas)*fabs(77. - C_T(cell, gas)) / 77.; /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}


If I simplify the source terms:

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
/*Parameters of Lee evaporation and condensation Model*/
real m_lg;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
m_lg = 0.;
/*Parameters of Antoine Equation for calculation of saturation temperature as function of pressure*/
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
/*Saturation Temperature calculation*/
Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;
/*Mass transfer calculation*/
if (C_T(cell, liq) >= 77.);
{
m_lg = - 1; /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= 77.))
{
m_lg = 0.1; /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}

there is no floating point exception. The simulation runs like intended.
Something is still false in the source term, but no divison by zero is taking place.

m_lg =- revap * C_VOF(cell, liq)*C_R(cell, liq)*fabs(C_T(cell, liq) - 77.) / 77.


I don't get it.



best regards
Steffen
SteffenBcfd is offline   Reply With Quote

Old   December 9, 2022, 01:52
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
seems like the problem is here C_VOF(cell, liq)

Essentially you hate to use VOF model to access this macro

tricky part could be here as well:
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/

may be index are wrong try to_index for gas
SteffenBcfd likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 9, 2022, 07:22
Default
  #5
New Member
 
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 4
SteffenBcfd is on a distinguished road
Dear Alexander,

you are right. C_VOF(c,t) is only accessible in combination with the VoF model. Thanks a lot for your support, it helped a lot. Now it is working with constant saturation pressure, but the Function for saturation temperature is still making trouble if I use the calculated saturation temperature.



real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;

Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;


The saturation temperature is close to the inlet and outlet dropping to zero and this is causing overflow if I link the pressure-dependent saturation temperature with mass transfer (I calculated the Tsat=f(p) for the case of constant Tsat for mass transfer)
This is strange because the pressure is dropping from 1.7 bar to 0 bar (101325 reference Pressure).

I guess I have to limit the saturation temperature appropriately.

Is it possible to limit the calculated saturation temperature for the cells concerning the position in the x direction (the simulation domain is a simple pipe with 0.4 m length, the x-axis is starting at zero for the inlet and the end value of 0.4 m for the outlet)?

Greetings
Steffen
Attached Images
File Type: jpg Tsat.jpg (83.7 KB, 7 views)
File Type: jpg pressure.jpg (73.3 KB, 6 views)
SteffenBcfd is offline   Reply With Quote

Old   December 9, 2022, 08:28
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
its hard for me to suggest anything based on theory of phenomena

however, regarding the code, it's pretty simple define specific zones
for that you may use C_CENTROID macro, checking if coordinate is large or smaller particular value

you may check ansys fluent customization manual for examples of code
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 12, 2022, 14:58
Default
  #7
New Member
 
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 4
SteffenBcfd is on a distinguished road
Dear Alexander,


thanks for your helpful advice. I added cell loop to limit the Saturation temperature at the beginning and the end of the pipe:



#include "udf.h"
/*Set Gas primary phase*/
/*Set Liquid secondary phase*/
/**C_UDMI(cell,thread,0)=sigma, C_UDMI(cell,thread,1)=Tsat, C_UDMI(cell,thread,2)=m_evap, C_UDMI(cell,thread,3)=m_cond**/
DEFINE_PROPERTY(sfc, c, t)
{
real sfc;
real Temp = C_T(c, t);
real k1 = 0.0008;
real k2 = -0.3475;
real k3 = 31.068;
sfc = (k1 * pow(Temp, 2) + k2 * Temp + k3)*0.001;
C_UDMI(c, t, 0) = sfc;
return sfc;
}
DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
/*Parameter of saturation temperatur limiter*/
real xmin = 0.01;
real xmax = 0.39;
real xend = 0.4;
real Tsatmax = 122;
real Tsatmin = 104;
real x[ND_ND];
/*Parameters of Lee evaporation and condensation Model*/
real m_lg;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
m_lg = 0.;
/*Parameters of Antoine Equation for calculation of saturation temperature as function of pressure*/
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
/*Saturation Temperature calculation*/
/*Limiting the saturation pressure at the beginning and end of of the pipe*/
begin_c_loop(cell, thread)
{
C_CENTROID(x, cell, thread);
if (0. < x[0] && x[0] <= xmin)
{
Tsat = Tsatmax;
C_UDMI(cell, thread, 1) = Tsat;
}
if (xmin < x[0] && x[0] <= xmax)
{
Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;
}
if (xmax < x[0] && x[0] <= xend)
{
Tsat = Tsatmin;
C_UDMI(cell, thread, 1) = Tsat;
}
}
end_c_loop(cell, thread)
/*Mass transfer calculation*/
if (C_T(cell, liq) >= C_UDMI(cell, thread, 1));
{
m_lg = - revap * C_VOF(cell, liq)*C_R(cell, liq)*fabs(C_T(cell, liq) - C_UDMI(cell, thread, 1)) / C_UDMI(cell, thread, 1); /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= C_UDMI(cell, thread, 1)))
{
m_lg = rcond * C_VOF(cell, gas)*C_R(cell, gas)*fabs(C_UDMI(cell, thread, 1) - C_T(cell, gas)) / C_UDMI(cell, thread, 1); /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}


Unfortunately, it's not entitely working yet. I got still error messages.
The compilling works without any warning.



iter continuity x-velocity y-velocity energy k omega intermit retheta vf-liquid time/iter
Stabilizing pressure coupled to enhance linear solver robustness.
Stabilizing pressure coupled using GMRES to enhance linear solver robustness.


Experiencing convergence difficulties - temporarily relaxing and trying again...


Experiencing convergence difficulties - temporarily relaxing and trying again...


Experiencing convergence difficulties - temporarily relaxing and trying again...


Experiencing convergence difficulties - temporarily relaxing and trying again...
Stabilizing pressure coupled to enhance linear solver robustness.
Stabilizing pressure coupled using GMRES to enhance linear solver robustness.


Experiencing convergence difficulties - temporarily relaxing and trying again...


Divergence detected in AMG solver: pressure coupled Stabilizing vof-1 to enhance linear solver robustness.
Stabilizing vof-1 using GMRES to enhance linear solver robustness.


Divergence detected in AMG solver: vof-1
Divergence detected in AMG solver: pressure coupled
Divergence detected in AMG solver: vof-1
Error at host: floating point exception


===============Message from the Cortex Process================================


Compute processes interrupted. Processing can be resumed.


================================================== ============================


Error: floating point exception
Error Object: #f


I guess I made something wrong at the scripting



Greetings

Steffen
SteffenBcfd is offline   Reply With Quote

Old   December 13, 2022, 04:32
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
try following code
Code:
#include "udf.h"
/*Set Gas primary phase*/
/*Set Liquid secondary phase*/
/**C_UDMI(cell,thread,0)=sigma, C_UDMI(cell,thread,1)=Tsat, C_UDMI(cell,thread,2)=m_evap, C_UDMI(cell,thread,3)=m_cond**/
DEFINE_PROPERTY(sfc, c, t)
{
real sfc;
real Temp = C_T(c, t);
real k1 = 0.0008;
real k2 = -0.3475;
real k3 = 31.068;
sfc = (k1 * pow(Temp, 2) + k2 * Temp + k3)*0.001;
C_UDMI(c, t, 0) = sfc;
return sfc;
}
DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
/*Parameter of saturation temperatur limiter*/
real xmin = 0.01;
real xmax = 0.39;
real xend = 0.4;
real Tsatmax = 122;
real Tsatmin = 104;
real x[ND_ND];
/*Parameters of Lee evaporation and condensation Model*/
real m_lg = 0.;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
/*Parameters of Antoine Equation for calculation of saturation temperature as function of pressure*/
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
/*Saturation Temperature calculation*/
/*Limiting the saturation pressure at the beginning and end of of the pipe*/

C_CENTROID(x, cell, thread);
if (0. < x[0] && x[0] <= xmin)
{
Tsat = Tsatmax;
C_UDMI(cell, thread, 1) = Tsat;
}
else if (xmin < x[0] && x[0] <= xmax)
{
Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;
}
else if (xmax < x[0] && x[0] <= xend)
{
Tsat = Tsatmin;
C_UDMI(cell, thread, 1) = Tsat;
}

/*Mass transfer calculation*/
if (C_T(cell, liq) >= C_UDMI(cell, thread, 1));
{
m_lg = - revap * C_VOF(cell, liq)*C_R(cell, liq)*fabs(C_T(cell, liq) - C_UDMI(cell, thread, 1)) / C_UDMI(cell, thread, 1); /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= C_UDMI(cell, thread, 1)))
{
m_lg = rcond * C_VOF(cell, gas)*C_R(cell, gas)*fabs(C_UDMI(cell, thread, 1) - C_T(cell, gas)) / C_UDMI(cell, thread, 1); /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}
you don't need additional loop over cells, as DEFINE_MASS_TRANSFER macro is loop over cells itself

i'm not sure should thread or liq (as thread pointer) should be used, you may change it, if code above doesn't work
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   December 27, 2022, 19:30
Default
  #9
New Member
 
Mohammad
Join Date: Sep 2022
Posts: 12
Rep Power: 4
Selawe97 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
try following code
Code:
#include "udf.h"
/*Set Gas primary phase*/
/*Set Liquid secondary phase*/
/**C_UDMI(cell,thread,0)=sigma, C_UDMI(cell,thread,1)=Tsat, C_UDMI(cell,thread,2)=m_evap, C_UDMI(cell,thread,3)=m_cond**/
DEFINE_PROPERTY(sfc, c, t)
{
real sfc;
real Temp = C_T(c, t);
real k1 = 0.0008;
real k2 = -0.3475;
real k3 = 31.068;
sfc = (k1 * pow(Temp, 2) + k2 * Temp + k3)*0.001;
C_UDMI(c, t, 0) = sfc;
return sfc;
}
DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
/*Parameter of saturation temperatur limiter*/
real xmin = 0.01;
real xmax = 0.39;
real xend = 0.4;
real Tsatmax = 122;
real Tsatmin = 104;
real x[ND_ND];
/*Parameters of Lee evaporation and condensation Model*/
real m_lg = 0.;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
/*Parameters of Antoine Equation for calculation of saturation temperature as function of pressure*/
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(cell, thread);
real Tsat;
real pstatic = C_P(cell, thread);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
/*Saturation Temperature calculation*/
/*Limiting the saturation pressure at the beginning and end of of the pipe*/

C_CENTROID(x, cell, thread);
if (0. < x[0] && x[0] <= xmin)
{
Tsat = Tsatmax;
C_UDMI(cell, thread, 1) = Tsat;
}
else if (xmin < x[0] && x[0] <= xmax)
{
Tsat = (B / (A - log10(pvap))) - C;
C_UDMI(cell, thread, 1) = Tsat;
}
else if (xmax < x[0] && x[0] <= xend)
{
Tsat = Tsatmin;
C_UDMI(cell, thread, 1) = Tsat;
}

/*Mass transfer calculation*/
if (C_T(cell, liq) >= C_UDMI(cell, thread, 1));
{
m_lg = - revap * C_VOF(cell, liq)*C_R(cell, liq)*fabs(C_T(cell, liq) - C_UDMI(cell, thread, 1)) / C_UDMI(cell, thread, 1); /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= C_UDMI(cell, thread, 1)))
{
m_lg = rcond * C_VOF(cell, gas)*C_R(cell, gas)*fabs(C_UDMI(cell, thread, 1) - C_T(cell, gas)) / C_UDMI(cell, thread, 1); /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}
you don't need additional loop over cells, as DEFINE_MASS_TRANSFER macro is loop over cells itself

i'm not sure should thread or liq (as thread pointer) should be used, you may change it, if the code above doesn't work
Hello

I have a question regarding the previous code, do I need also to define a heat transfer code beside the mass transfer code to simulate (the evaporation and condensation process)?
Thanks,

Mohammad
bidax likes this.
Selawe97 is offline   Reply With Quote

Old   January 24, 2024, 03:55
Default hiiii!
  #10
New Member
 
Bidax
Join Date: Dec 2023
Posts: 10
Rep Power: 2
bidax is on a distinguished road
Quote:
Originally Posted by Selawe97 View Post
Hello

I have a question regarding the previous code, do I need also to define a heat transfer code beside the mass transfer code to simulate (the evaporation and condensation process)?
Thanks,

Mohammad
Hi! have you solve this problem?
I want to simulate a three-dimensional pipeline that contains only two phases, water and water vapor. Water flows in and evaporates within the pipeline. I've written a UDF to acquire the phase interface and have added mass and energy source terms. However, the results are not correct. I'm wondering if you have experience with similar simulations and if you have any suggestions? Can the mass_transfer macro be used to simulate the phase change?
bidax is offline   Reply With Quote

Old   January 24, 2024, 04:06
Default evaporation lee udf
  #11
New Member
 
Bidax
Join Date: Dec 2023
Posts: 10
Rep Power: 2
bidax is on a distinguished road
Quote:
Originally Posted by SteffenBcfd View Post
Hello,


I have two ssues regarding scripting UDFs.



It's a multiphase simulation with two phases, one liquid and one gas. The domaine is only a simple 2d pipe with a pressure inlet and a pressure outlet.



The first one is that a UDF for calculationg the saturation temperature as a function of pressure (Antoine Equation) always gives the value zero when I plot the C_UDMI(c, t, 1) = Tsat.



Here is the used script (I added three UDFs in one file (1.Surface Tension, Saturation Temperatur and Mass transfer, complied without errors):



#include "udf.h"
/*Set Gas primary phase*/
/*Set Liquid secondary phase*/
/**C_UDMI(cell,thread,0)=sigma, C_UDMI(cell,thread,1)=Tsat, C_UDMI(cell,thread,2)=m_evap, C_UDMI(cell,thread,3)=m_cond**/
DEFINE_PROPERTY(sfc, c, t)
{
real sfc;
real Temp = C_T(c, t);
real k1 = 0.0008;
real k2 = -0.3475;
real k3 = 31.068;
sfc = (k1 * pow(Temp, 2) + k2 * Temp + k3)*0.001;
C_UDMI(c, t, 0) = sfc;
return sfc;
}
DEFINE_PROPERTY(Tsat, c, t)
{
real A = 3.7362;
real B = 264.651;
real C = -6.788;
real Temp = C_T(c, t);
real Tsat;
real pstatic = C_P(c, t);
real poperation = RP_Get_Real("operating-pressure");
real pvap;
pvap = (pstatic + poperation)*10E-5;
Tsat = (B / (A - (double)log10((double)pvap))) - C;
C_UDMI(c, t, 1) = Tsat;
return Tsat;
}


The second issue is about a mass transfer UDF aka

Lee evaporation model (it's the code from the ANSYS Fluent UDF Manual, Release 15.0, page 150-151).




DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real m_lg;
real T_SAT = C_UDMI(cell, thread, 1);
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
/***Lee Mass Transfer***/
m_lg = 0.;
if (C_T(cell, liq) >= T_SAT)
{
m_lg = -revap*C_VOF(cell,liq)*C_R(cell,liq)*fabs(C_T(cell, liq)-T_SAT)/T_SAT; /*Evaporation*/
C_UDMI(cell, thread, 4) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))
{
m_lg = rcond*C_VOF(cell,gas)*C_R(cell,gas)*fabs(T_SAT-C_T(cell,gas))/T_SAT; /*Condensation*/
C_UDMI(cell, thread, 5) = m_lg;
}
return (m_lg);
}


If I use a simplified version and set constant values for mass transfer (-2 for evaporation and 1 for condensation) the udf is running.



DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real m_lg;
real T_SAT = 77;
real revap = 100.;
real rcond = 0.1;
Thread *gas = THREAD_SUB_THREAD(thread, from_index); /*Gas primary phase*/
Thread *liq = THREAD_SUB_THREAD(thread, to_index); /*Liquid secondary phase*/
m_lg = 0.;
if (C_T(cell, liq) >= T_SAT)
{
m_lg = -2; /*Evaporating*/
C_UDMI(cell, thread, 2) = m_lg;
}
if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))
{
m_lg = 1; /*Condensing*/
C_UDMI(cell, thread, 3) = m_lg;
}
return (m_lg);
}



The boundary conditions aren't a problem, because when I use the implemented mass transfer Lee model, the simulation is running just fine.


Something is wrong in the mass transfer script and cause always floating point exception. If I understand it rigth it means division by zero.



Maybe someone has a clue what is causing the errors.


Greetings

Steffen
Hi! have you solve this problem?
I want to simulate a three-dimensional pipeline that contains only two phases, water and water vapor. Water flows in and evaporates within the pipeline. I've written a UDF to acquire the phase interface and have added mass and energy source terms. However, the results are not correct. I'm wondering if you have experience with similar simulations and if you have any suggestions? Can the mass_transfer macro be used to simulate the phase change?
bidax is offline   Reply With Quote

Old   February 4, 2024, 08:39
Default
  #12
Member
 
Sebi
Join Date: Mar 2019
Posts: 49
Rep Power: 7
bloodflow is on a distinguished road
Quote:
Originally Posted by Selawe97 View Post
Hello

I have a question regarding the previous code, do I need also to define a heat transfer code beside the mass transfer code to simulate (the evaporation and condensation process)?
Thanks,

Mohammad
Yes - If you are implementing phase change UDF's you need at least two UDFS:

One is the mass transfer UDF (e.g., DEFINE_SOURCE) that returns that mass source in kg/m3/s of the new phase

The other must be the energy released or absorbed during the phase change. Since evaporation requires an energy input, it is usually a negative energy source (i.e., a decrease in temperature).

This can be added using a DEFINE_SOURCE UDF, where the energy change is m_dot*L_v, where L_V is the latent heat of vaporization.
bloodflow is offline   Reply With Quote

Old   February 4, 2024, 08:43
Default
  #13
Member
 
Sebi
Join Date: Mar 2019
Posts: 49
Rep Power: 7
bloodflow is on a distinguished road
Quote:
Originally Posted by bidax View Post
Hi! have you solve this problem?
I want to simulate a three-dimensional pipeline that contains only two phases, water and water vapor. Water flows in and evaporates within the pipeline. I've written a UDF to acquire the phase interface and have added mass and energy source terms. However, the results are not correct. I'm wondering if you have experience with similar simulations and if you have any suggestions? Can the mass_transfer macro be used to simulate the phase change?
Either post your code or provide more information. Neither water nor water vapor are phases. Liquid, solid and gas are the phases.

I don't know your application, but I highly doubt using only liquid water and water vapour would be correct, as it doesn't include oxygen, nitrogen or any other air species...
bloodflow is offline   Reply With Quote

Reply

Tags
define_mass_transfer, define_property, divergence amg solver, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF for mass transfer from DPM to continuous phase mpcaixeta Fluent UDF and Scheme Programming 1 September 19, 2024 14:06
Saturation temperature UDF for evaporation-condensation obiscolly50 Fluent UDF and Scheme Programming 1 June 20, 2021 11:08
Problems modelling nucleate boiling using mass transfer udf from tutorial aayushjain27 Fluent UDF and Scheme Programming 0 February 7, 2015 08:23
Problems regarding mass transfer UDF Yifan_G Fluent UDF and Scheme Programming 8 December 8, 2014 11:21
Mass transfer with varying saturation temperature Lukeimpervius Fluent UDF and Scheme Programming 0 April 27, 2014 14:19


All times are GMT -4. The time now is 22:17.