
[Sponsors] 
Problems with Saturation Temperature UDF and mass transfer UDF 

LinkBack  Thread Tools  Search this Thread  Display Modes 
December 7, 2022, 06:42 
Problems with Saturation Temperature UDF and mass transfer UDF

#1 
New Member
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 3 
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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; 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 150151). 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_SATC_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 

December 7, 2022, 23:36 

#2 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
1
Code:
Tsat = (B / (A  (double)log10((double)pvap)))  C; Code:
Tsat = (B / (A  log10(pvap)))  C; Code:
m_lg = revap*C_VOF(cell,liq)*C_R(cell,liq)*fabs(C_T(cell, liq)T_SAT)/T_SAT; /*Evaporation*/ you may define T_SAT as a constant to test the code
__________________
best regards ****************************** press LIKE if this message was helpful 

December 8, 2022, 08:51 

#3 
New Member
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 3 
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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; /*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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; /*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 

December 9, 2022, 00:52 

#4 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
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
__________________
best regards ****************************** press LIKE if this message was helpful 

December 9, 2022, 06:22 

#5 
New Member
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 3 
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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; 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 pressuredependent 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 xaxis is starting at zero for the inlet and the end value of 0.4 m for the outlet)? Greetings Steffen 

December 9, 2022, 07:28 

#6 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
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 

December 12, 2022, 13:58 

#7 
New Member
Steffen
Join Date: Jul 2022
Posts: 10
Rep Power: 3 
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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; /*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 xvelocity yvelocity energy k omega intermit retheta vfliquid 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 vof1 to enhance linear solver robustness. Stabilizing vof1 using GMRES to enhance linear solver robustness. Divergence detected in AMG solver: vof1 Divergence detected in AMG solver: pressure coupled Divergence detected in AMG solver: vof1 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 

December 13, 2022, 03:32 

#8 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 
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("operatingpressure"); real pvap; pvap = (pstatic + poperation)*10E5; /*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); } 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 

December 27, 2022, 18:30 

#9  
New Member
Mohammad
Join Date: Sep 2022
Posts: 12
Rep Power: 3 
Quote:
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 

January 24, 2024, 02:55 
hiiii!

#10  
New Member
Bidax
Join Date: Dec 2023
Posts: 10
Rep Power: 2 
Quote:
I want to simulate a threedimensional 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? 

January 24, 2024, 03:06 
evaporation lee udf

#11  
New Member
Bidax
Join Date: Dec 2023
Posts: 10
Rep Power: 2 
Quote:
I want to simulate a threedimensional 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? 

February 4, 2024, 07:39 

#12  
Member
Sebi
Join Date: Mar 2019
Posts: 49
Rep Power: 7 
Quote:
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. 

February 4, 2024, 07:43 

#13  
Member
Sebi
Join Date: Mar 2019
Posts: 49
Rep Power: 7 
Quote:
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... 

Tags 
define_mass_transfer, define_property, divergence amg solver, udf 
Thread Tools  Search this Thread 
Display Modes  


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