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

Using C_VOF to compute saturation temperature

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By pakk
  • 1 Post By annan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 26, 2019, 23:30
Default Using C_VOF to compute saturation temperature
  #1
New Member
 
Alexandre Coulombe
Join Date: Feb 2019
Posts: 7
Rep Power: 7
alex2293 is on a distinguished road
Hello everyone,

I want to simulate humid air condensing on a cold surface. I'm using the VOF multiphase model with Lee condensation-evaporation model.

I'm trying to write my first UDF to define the saturation temperature of humid air in the Lee model based on the C_VOF of water vapor, the water vapor density, the C_VOF of air, the air density and the temperature.

I tried to follow this thread: UDF for volume fraction

#include "udf.h"
#define rho_water_vapor 0.59;
#define rho_air 1.2;
#define mix_pressure 101325;
DEFINE_PROPERTY(saturation_temperature,c,t)
{
real sat_temp;
real partial_vapor_pressure;
cell_t cell;
Thread **pt;
Thread *cell_threads;
Domain *mixture_domain;
{
mp_thread_loop_c(t, mixture_domain, pt)
{
begin_c_loop(cell,pt)
{
real temp = C_T(cell,pt[0]);
real VOF_air = C_VOF(cell,pt[2]);
real VOF_water_vapor = C_VOF(cell,pt[2])
w = (VOF_water_vapor*rho_water_vapor)/(VOF_air*rho_air);
sat_temp = w*0.008-0.14;
}
end_c_loop(cell,pt)
}
return sat_temp;
}
}

I'm getting parse error on line 21. I think that the domain 1 is the mixture level, 1 is the air phase and 2 is the water vapor phase. However I'm not sure how to use mp_thread_loop_c and C_VOF.

Do you have any tips for me?

Alex
alex2293 is offline   Reply With Quote

Old   February 27, 2019, 01:51
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
read your console output next time
your code
Code:
real VOF_water_vapor = C_VOF(cell,pt[2])
should be
Code:
real VOF_water_vapor = C_VOF(cell,pt[2]);
best regards
AlexanderZ is offline   Reply With Quote

Old   February 27, 2019, 02:23
Default
  #3
New Member
 
Alexandre Coulombe
Join Date: Feb 2019
Posts: 7
Rep Power: 7
alex2293 is on a distinguished road
Thank you Alexander, however I'm still getting the same errors.
alex2293 is offline   Reply With Quote

Old   February 27, 2019, 04:09
Default
  #4
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 10
annan is on a distinguished road
Dear Alex2293,

First of all, I would recommand defining the mixture domain as :
Domain *mixture_domain = Get_Domain(1);

Is your air volume fraction equal to your water vapor volume fraction ? because you are assigning them the same value

real VOF_air = C_VOF(cell,pt[2]);
real VOF_water_vapor = C_VOF(cell,pt[2]);

How many phases do you have ? which one is the primary phase and which ones are the secondary phases ? This would enable me help you to use the right index to define the right volume fraction.

Regards,
Annan
annan is offline   Reply With Quote

Old   February 27, 2019, 05:15
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
The problem is in the first few lines:


Code:
#define rho_water_vapor 0.59;
#define rho_air 1.2;
#define mix_pressure 101325;

You should not put the semicolon at the end. These lines are not for the c-compiler, but for the pre-processor. The lines should be:



Code:
#define rho_water_vapor 0.59
#define rho_air 1.2
#define mix_pressure 101325
annan and mattshifantastic like this.
pakk is offline   Reply With Quote

Old   February 27, 2019, 08:09
Default
  #6
New Member
 
Alexandre Coulombe
Join Date: Feb 2019
Posts: 7
Rep Power: 7
alex2293 is on a distinguished road
Thanks to both of you. The UDF code now looks like this:

#include "udf.h"
#define rho_air 1.2
#define rho_wv 0.59
#define mix_pressure 101325
DEFINE_PROPERTY(saturation_temperature,c,thread)
{
real temp = C_T(c,thread);
real sat_temp;
real w;
Domain *mix_domain = Get_Domain(1);
Thread *mix_thread;
Thread **pt;
cell_t cell;
mp_thread_loop_c(mix_thread, mix_domain, pt)
{
begin_c_loop(cell,pt)
{
real VOF_wv = C_VOF(c,pt[3])*rho_wv;
real VOF_air = C_VOF(c,pt[2])*rho_air;
w = VOF_wv / VOF_air;
sat_temp = w * 101325 * 0.008;
end_c_loop(cell,pt)
}
}
return sat_temp;
}

I can add it as an interpreted UDF without errors but Fluent crashes when I initialize. I was also able to hook it to the lee model in the phase interaction dialog.

I have 3 phases. The air is the main phase, the water vapor is the second phase and the liquid water is the third phase.

Should I use this UDF as a compiled one? I can only start Fluent in serial mode, if I use the parallel mode it crashes right after reading the udf file.

Alex
alex2293 is offline   Reply With Quote

Old   February 27, 2019, 13:08
Default
  #7
New Member
 
Alexandre Coulombe
Join Date: Feb 2019
Posts: 7
Rep Power: 7
alex2293 is on a distinguished road
Annan, I have 3 phases. The principal phase is air, the second is water vapor and the third is liquid water.

I'm simulating a simple case where I have a closed volume of air at 20°C 50%RH which is around 0.01VOF of water vapor. The bottom surface of the enclosure is at 0°C. The humid air should cool down below the dew point and form a water film on the cold surface.

I removed the semicolons at the end and assigned the correct pt[] values. I don't have parse errors anymore. It can be interpreted and run in serial mode only.

However I think that instead of using the Lee model and a UDF to define the saturation temperature I should use a source term to define the mass transfer rate.

The present UDF returns a saturation temperature, but how does it tell Fluent that there is a different saturation temperature for each cell?

Thanks again for your help, it's really appreciated.
alex2293 is offline   Reply With Quote

Old   February 28, 2019, 04:03
Default
  #8
Member
 
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 10
annan is on a distinguished road
Dear Alexandre,
First of all, I still see a small error in your UDF, there are two lines which need to be switched like this :

sat_temp = w * 101325 * 0.008;
}
end_c_loop(cell,pt)


Also, I don't think it is appropriate to use a cell loop inside a DEFINE_PROPERTY Macro, this is how I would write the UDF :

#include "udf.h"
#define rho_air 1.2
#define rho_wv 0.59
#define mix_pressure 101325
DEFINE_PROPERTY(saturation_temperature,c,thread)
{
real temp = C_T(c,thread);
real sat_temp;
real w;

Thread *t_air = THREAD_SUB_THREAD(thread,0);
Thread *t_wv = THREAD_SUB_THREAD(thread,1);
Thread *t_wl = THREAD_SUB_THREAD(thread,2);

real VOF_wv = C_VOF(c,t_wv)*rho_wv;
real VOF_air = C_VOF(c,t_air)*rho_air;
w = VOF_wv / VOF_air;

sat_temp = w * 101325 * 0.008;

return sat_temp;
}

As for how fluent understands that there is a different saturation temperature in each cell :
- the DEFINE_PROPERTY macro is executed in a cell of the domain => DEFINE_PROPERTY(saturation_temperature,c,thread)
- it calculates the property sat_temp each time as it is executed in a cell
- it returns the value sat_temp in that cell
Now, as the volume fraction, temperature and other properties change from one cell to another, fluent will assign a different saturation temperature for each cell.

Hope this will help, good luck.
Regards,
Annan
mattshifantastic likes this.
annan is offline   Reply With Quote

Old   February 28, 2019, 04:20
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Since we are focussing on details:
  • You define mix_pressure, but don't use it. You still use the number 101325.
  • You use 0.008 in your code. It is good practice to avoid such magic numbers, and use names. I don't know what this number represents, so I call it "magic constant" below.
  • You calculate the temperature ("temp"), but you never use it.
  • If C_VOF of air can become 0, you run into problems where you divide by zero. Even though you might know that physically this will never happen, it might happen numerically in an intermediate solution. It might even become a negative number. It is unlikely, but not impossible, to give problems in a calculation. To avoid this, tell the program what to do if the VOF of air is non-positive. In my example below, I return a saturation temperature of 1000 K.





Code:
#include "udf.h"
#define rho_air 1.2
#define rho_wv 0.59
#define mix_pressure 101325
#define magic_constant 0.008

 DEFINE_PROPERTY(saturation_temperature,c,thread)
{
 Thread *t_air = THREAD_SUB_THREAD(thread,0);
 Thread *t_wv = THREAD_SUB_THREAD(thread,1);
 real VOF_wv = C_VOF(c,t_wv)*rho_wv;    
 real VOF_air = C_VOF(c,t_air)*rho_air;

 if (VOF_air>0) {
  w = VOF_wv / VOF_air;
  return w * mix_pressure * magic_constant);
 } else {
  return 1000;
 }
}
pakk is offline   Reply With Quote

Old   March 4, 2019, 08:29
Default
  #10
New Member
 
Alexandre Coulombe
Join Date: Feb 2019
Posts: 7
Rep Power: 7
alex2293 is on a distinguished road
Thanks again to both of you, now my UDF is running without errors and the mass conservation is ok.

The mass of water vapor in the air at the beginning equals the mass of water after a few iterations.

However, the water doesn't form a film a the bottom of the domain (rectangular domain without flow, cold bottom surface). It stays suspended with a very small density gradient.

I activated gravity and sharp in the interface modeling.

It forms a film when I choose the interfacial anti-diffusion option. However, it then diverge I get the message Error: Divergence detected in AMG solver: Pressure correction.

Do anyone have an idea?
Thanks again
alex2293 is offline   Reply With Quote

Old   December 12, 2021, 03:44
Default
  #11
New Member
 
Babak
Join Date: Oct 2021
Posts: 12
Rep Power: 5
CMIUCBS is on a distinguished road
Hello Alexandre.

By any chance do you have the final form of your code which is working without error? is it possible for you to share it with me?
That would be a big help.
CMIUCBS is offline   Reply With Quote

Reply


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
Ansys CFX problem: unexpected very high temperatures in premix laminar combustion faizan_habib7 CFX 4 February 1, 2016 18:00
Plotting Saturation Temperature Jannssen CFX 4 January 27, 2016 17:04
unexpected constant Temperature on a clip surface Sungki OpenFOAM Running, Solving & CFD 0 August 4, 2015 05:50
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 07:27
Bulk temperature Tf is obtained from total or static temperature? NPU_conanxie FLUENT 0 March 30, 2011 06:56


All times are GMT -4. The time now is 21:00.