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

Mass transfer UDF

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 5, 2017, 07:44
Default Mass transfer UDF
  #1
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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 Tc = C_T(cell, thread);
real Pc = C_P(cell, thread);
real Tsat = 195;
real Psat = psat;
Thread *liq = THREAD_SUB_THREAD(thread, from_index);
Thread *gas = THREAD_SUB_THREAD(thread, to_index);

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 is offline   Reply With Quote

Old   March 6, 2017, 10:28
Default
  #2
Boh
Member
 
Join Date: Sep 2016
Posts: 35
Rep Power: 6
Boh is on a distinguished road
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
Boh is offline   Reply With Quote

Old   March 6, 2017, 10:42
Default
  #3
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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?

Thanks for your time.

Steven.
Stevie_1200 is offline   Reply With Quote

Old   March 6, 2017, 11:04
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,817
Rep Power: 23
pakk will become famous soon enough
I think the following should work (perhaps after fixing some typos that I made, I did not test the code):

Code:
real my_psat(cell_t c,Thread *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_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 Tc = C_T(cell, thread);
real Pc = C_P(cell, thread);
real Tsat = 195;
real Psat = my_psat(cell,thread);
Thread *liq = THREAD_SUB_THREAD(thread, from_index);
Thread *gas = THREAD_SUB_THREAD(thread, to_index);

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 likes this.
pakk is offline   Reply With Quote

Old   March 6, 2017, 11:13
Default
  #5
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
Hi Pakk,

Thanks for your help, I will try that out.

Steven
Stevie_1200 is offline   Reply With Quote

Old   March 6, 2017, 15:15
Default
  #6
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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 my_psat(cell_t c, Thread *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_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 Tc = C_T(cell, thread);
real Pc = C_P(cell, thread);
real Psat = my_psat(cell, thread);
real Tsat = 195;
Thread *liq = THREAD_SUB_THREAD(thread, from_index);
Thread *gas = THREAD_SUB_THREAD(thread, to_index);

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.
Stevie_1200 is offline   Reply With Quote

Old   March 7, 2017, 07:14
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,817
Rep Power: 23
pakk will become famous soon enough
Try to initialize without the UDF.
pakk is offline   Reply With Quote

Old   March 7, 2017, 08:07
Default
  #8
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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 is offline   Reply With Quote

Old   March 7, 2017, 15:15
Default
  #9
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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?
Stevie_1200 is offline   Reply With Quote

Old   March 8, 2017, 05:23
Default
  #10
Boh
Member
 
Join Date: Sep 2016
Posts: 35
Rep Power: 6
Boh is on a distinguished road
Sorry I misunderstood your question....anyway I found this 2 UDF that I think will help you:

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)
Boh is offline   Reply With Quote

Old   March 8, 2017, 05:27
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,817
Rep Power: 23
pakk will become famous soon enough
At the location where you are asking Fluent to calculate psat, is the temperature defined there? (Are you solving the energy equation?)
pakk is offline   Reply With Quote

Old   March 8, 2017, 08:02
Default
  #12
Member
 
Stevie_1200's Avatar
 
Steven Taggart
Join Date: Jan 2014
Location: Hull, UK
Posts: 51
Rep Power: 9
Stevie_1200 is on a distinguished road
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
Stevie_1200 is offline   Reply With Quote

Old   March 8, 2017, 08:09
Default
  #13
Senior Member
 
Join Date: Nov 2013
Posts: 1,817
Rep Power: 23
pakk will become famous soon enough
Oh, then I think it is very possible that I made a mistake with pointer grammar.

Maybe the proper grammar is:
Code:
real my_psat(cell_t c, Thread *t)
{
...
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...
pakk is offline   Reply With Quote

Reply

Tags
mass transfer, saturation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
using define mass transfer udf for cavitation Komon Fluent UDF and Scheme Programming 14 June 21, 2016 02:50
udf source code for modelling mass transfer during film boiling vinita123 Fluent UDF and Scheme Programming 0 December 22, 2015 08:43
transient mass transfer in multiphase flow Tensian Fluent UDF and Scheme Programming 0 November 16, 2015 10:39
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
I need UDF help. S.Whitney FLUENT 0 October 15, 2007 11:29


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