CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Mass transfer UDF (https://www.cfd-online.com/Forums/fluent-udf/184548-mass-transfer-udf.html)

 Stevie_1200 March 5, 2017 07:44

Mass transfer UDF

Hello,

I am trying to construct a mass transfer UDF for use in Fluent and I am having mixed results. I have a function at the start to calculate the saturation pressure, the value of this should then be used in the mass transfer calculation, however I am uncertain how to call the saturation pressure into the mass transfer function. Could anyone give any pointers on the best way to do this?

I have included the code below, highlighted is my (poor!) attempt at calling the value of the saturation pressure into the mass transfer calculation.

Thanks!

#include "udf.h"

DEFINE_PROPERTY(psat,c,t)
{ real a[3] = {6.81228, 1301.679, -3.494};
real b[3] = {7.5322, 835.06, 268.223};
real Psat;
real T = C_T(c,t);

if (T <= 200)
Psat = pow(10, a[0]-(a[1]/(T + a[2])));
else
Psat = pow(10, b[0]-(b[1]/(T + b[2])));

return Psat;
}

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,from_species_index, to_index, to_species_index)
{
real m_lg;
real Tsat = 195;
real Psat = psat;

Tc = MAX(Tc, 273.15);

m_lg = 0.;

if (Pc <= Psat)
{
m_lg = 0.1*C_VOF(cell,liq)*C_R(cell,liq)*fabs(Tc-Tsat)/Tsat;
}
if ((m_lg == 0. ) && (Pc > Psat))
{
m_lg = -0.1*C_VOF(cell,gas)*C_R(cell,gas)*fabs(Tsat-Tc)/Tsat;
}
return (m_lg);
}

 Boh March 6, 2017 10:28

you can define the psat before the define property function...just write real Psat after the #include "udf.h" line. You don't need to redefine it in the define property function...just assign the value to it

 Stevie_1200 March 6, 2017 10:42

Hi Boh,

I am not sure I follow, I am using the define property function to calculate the Psat, how do I access this calculated Psat value in the define_mass_transfer function?

Steven.

 pakk March 6, 2017 11:04

I think the following should work (perhaps after fixing some typos that I made, I did not test the code):

Code:

real a[3] = {6.81228, 1301.679, -3.494};
real b[3] = {7.5322, 835.06, 268.223};
real Psat;
real T = C_T(c,t);

if (T <= 200)
Psat = pow(10, a[0]-(a[1]/(T + a[2])));
else
Psat = pow(10, b[0]-(b[1]/(T + b[2])));

return Psat;
}

DEFINE_PROPERTY(psat,c,t)
{
return(my_psat(c,t));
}

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,from_species_index, to_index, to_species_index)
{
real m_lg;
real Tsat = 195;

Tc = MAX(Tc, 273.15);

m_lg = 0.;

if (Pc <= Psat)
{
m_lg = 0.1*C_VOF(cell,liq)*C_R(cell,liq)*fabs(Tc-Tsat)/Tsat;
}
if ((m_lg == 0. ) && (Pc > Psat))
{
m_lg = -0.1*C_VOF(cell,gas)*C_R(cell,gas)*fabs(Tsat-Tc)/Tsat;
}
return (m_lg);
}

 Stevie_1200 March 6, 2017 11:13

Hi Pakk,

Thanks for your help, I will try that out.

Steven

 Stevie_1200 March 6, 2017 15:15

Hello,

I used the code included below and it compiles fine but I have been getting errors when I initialise the simulation. I have included the error message below. From having a look online it seems to be a variable trying to access some information that is not available but I cant seem to work it out.

#include "udf.h"

{
real a[3] = {6.81228, 1301.679, -3.494};
real b[3] = {7.5322, 835.06, 268.223};
real Psat;
real T = C_T(c,t);

if (T <= 200)
Psat = pow(10, a[0]-(a[1]/(T + a[2])));
else
Psat = pow(10, b[0]-(b[1]/(T + b[2])));
return Psat;
}

DEFINE_PROPERTY(Psat,c,t)
{
return (my_psat(c,t));
}

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,from_species_index, to_index, to_species_index)
{
real m_lg;
real Tsat = 195;

m_lg = 0.;

if (Pc <= Psat)
{
m_lg = 0.1*C_VOF(cell,liq)*C_R(cell,liq)*fabs(Tc-Tsat)/Tsat;
}
if ((m_lg == 0. ) && (Pc > Psat))
{
m_lg = -0.1*C_VOF(cell,gas)*C_R(cell,gas)*fabs(Tsat-Tc)/Tsat;
}
return (m_lg);
}

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

Node 0: Process 564: Received signal SIGSEGV.

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

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

Node 1: Process 4352: Received signal SIGSEGV.

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

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

Node 2: Process 6456: Received signal SIGSEGV.

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

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

Node 3: Process 8004: Received signal SIGSEGV.

================================================== ============================
MPI Application rank 0 exited before MPI_Finalize() with status 2
The fl process could not be started.

 pakk March 7, 2017 07:14

Try to initialize without the UDF.

 Stevie_1200 March 7, 2017 08:07

Hi Pakk,

I tried initializing without the UDF and it works fine but as soon as I turn on the UDF (either at the start or after some iterations) I get the same error.

Steven

 Stevie_1200 March 7, 2017 15:15

Hi Pakk,

Its the temperature macro in the first routine that seems to be causing the problem. If I assign a value to the temperature everything is fine but if I try and access the cell temperature through C_T(c,t) I run in to problems.

Am I accessing the cell temperature in the correct way?

 Boh March 8, 2017 05:23

http://users.ugent.be/~mvbelleg/case...sflux_source.c

http://users.ugent.be/~mvbelleg/case...D/Parameters.c

I think you're trying to do something similar (same approach suggested by Pakk)

 pakk March 8, 2017 05:27

At the location where you are asking Fluent to calculate psat, is the temperature defined there? (Are you solving the energy equation?)

 Stevie_1200 March 8, 2017 08:02

Thanks for them Boh, I will have a look through them tonight.

Pak, yes I have the energy equation on, I moved the psat routine to inside the mass flow rate routine and it seems to access the temperature fine. This may be a solution but I would like to work out why I cant do it as originally intended as I would like to keep both calculations separate.

Steven

 pakk March 8, 2017 08:09

Oh, then I think it is very possible that I made a mistake with pointer grammar.

Maybe the proper grammar is:
Code:

{
...
real T = C_T(c,*t);

Or you might have to add/remove * or & in other places.

I make more mistakes with this than I like to admit...

 All times are GMT -4. The time now is 23:03.