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/)
-   -   Using C_VOF to compute saturation temperature (https://www.cfd-online.com/Forums/fluent-udf/215234-using-c_vof-compute-saturation-temperature.html)

alex2293 February 26, 2019 22:30

Using C_VOF to compute saturation temperature
 
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: https://www.cfd-online.com/Forums/fl...-fraction.html

#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

AlexanderZ February 27, 2019 00:51

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

alex2293 February 27, 2019 01:23

Thank you Alexander, however I'm still getting the same errors.

annan February 27, 2019 03:09

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

pakk February 27, 2019 04:15

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


alex2293 February 27, 2019 07:09

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 February 27, 2019 12:08

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.

annan February 28, 2019 03:03

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

pakk February 28, 2019 03:20

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;
 }
}


alex2293 March 4, 2019 07:29

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

CMIUCBS December 12, 2021 02:44

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.


All times are GMT -4. The time now is 14:37.