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

Species mass transfer UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 29, 2020, 12:16
Default Species mass transfer UDF
  #1
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
I am modeling a species mass transfer model, in which I want to transfer a species from one phase to another phase. I am trying to express this process with the last term of the equation given below. [ m_dot(p_j,q_i) = mass transfer of 'species j from p phase' to 'species i of q phase' ]

Screenshot 2020-05-23 at 10.31.53 AM.jpg

I have tried modeling it with the help of the fluent's UDF tutorial example. Please have a look at this.


Code:
#include "udf.h"

 

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,

from_species_index, to_index, to_species_index)

{

   real m_lg;

   real T_SAT = 373.15;

   Thread *gas = THREAD_SUB_THREAD(thread, from_index);      // gas phase

   Thread *liq = THREAD_SUB_THREAD(thread, to_index);          // liquid phase

 

   m_lg = 0.;           // initialisation 


   if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))

     {

       m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*

         fabs(T_SAT-C_T(cell,gas))/T_SAT;

          from_species_index = 0. (let's say the first species)
          to_species_index = 2. (let's say the third species)

        m_lg = 0.1* C_VOF(cell,gas) * C_R(cell,gas) * C_YI(c , gas , 0)  ;

//here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in the mixture denoted by phase 'gas'.

      }

   return (m_lg);

Is the above UDF correct?

But how will the UDF know whether to transfer the species to 'to_species_index = 2'?
Anshs is offline   Reply With Quote

Old   May 29, 2020, 12:22
Default Species' Indices
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
The from and to indices for species as well as phases is not set in the UDF, rather in the Interaction panel where the UDF is hooked. You have to select phases as well as species. Fluent will take those values and transfer the mass. Remove the lines from the code that specify the indices for species.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 29, 2020, 13:04
Default
  #3
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
The from and to indices for species as well as phases is not set in the UDF, rather in the Interaction panel where the UDF is hooked. You have to select phases as well as species. Fluent will take those values and transfer the mass. Remove the lines from the code that specify the indices for species.
Is this correct? Can you summarise for me what will it do (according to you) .

I have written it to model a condensation phenomenon. When Temp < 373.15K, then the 1st species from gas phase ( denoted by species index 0) gets transferred to 1st species of the liquid phase.

But how will it identify the 1st species of 'to phase' (liquid phase).


Code:
#include "udf.h"

 

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,

from_species_index, to_index, to_species_index)

{

   real m_lg;

   real T_SAT = 373.15;

   Thread *gas = THREAD_SUB_THREAD(thread, from_index);      // gas phase

   Thread *liq = THREAD_SUB_THREAD(thread, to_index);          // liquid phase

 

   m_lg = 0.;           // initialisation 


   if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))

     {

       m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*

         fabs(T_SAT-C_T(cell,gas))/T_SAT;

        m_lg = 0.1* C_VOF(cell,gas) * C_R(cell,gas) * C_YI(c , gas , 0)  ;

//here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in the mixture denoted by phase 'gas'.

      }

   return (m_lg);
Thanks
Anshs is offline   Reply With Quote

Old   May 29, 2020, 13:09
Default Udf
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
The UDF needs to be hooked. And then you will know which species is referred to as from and which one is to. I think you have not yet tried to hook it.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 29, 2020, 14:49
Default
  #5
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
The UDF needs to be hooked. And then you will know which species is referred to as from and which one is to. I think you have not yet tried to hook it.
Yeah, I got your point. In the mass transfer tab of phase interaction, we will need to put on these specific details.

One more thing, if I want to further modify the transfer rate as given in the picture below.

Screenshot 2020-05-29 at 11.13.16 PM.jpg

Code:
#include "udf.h"

 

DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index,

from_species_index, to_index, to_species_index)

{

   real m_lg;

   real T_SAT = 373.15;

   Thread *gas = THREAD_SUB_THREAD(thread, from_index);      // gas phase

   Thread *liq = THREAD_SUB_THREAD(thread, to_index);          // liquid phase

 

   m_lg = 0.;           // initialisation 


   if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))

     {

       m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*

         fabs(T_SAT-C_T(cell,gas))/T_SAT;

       
         D = DEFINE_DIFFUSIVITY*(*name,*c,*t,*I)

         X_co2_eq= 0.1;

         X_co2 = C_VOF(cell,gas) * C_R(cell,gas) * C_YI(c , gas , 0)*


         k = 0.4*sqrt(D)*(C_D(c,t)/ C_MU_T(c,t)).^0.25



         //a = interfacial area/volume 

 , I have the separate UDF for this

         m_lg = k*a* ( X_co2_eq - X_co2);

         //here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in 
         the mixture denoted by phase 'gas'.

      }

   return (m_lg);
Is this correct? Thanks
Anshs is offline   Reply With Quote

Old   May 29, 2020, 15:43
Default Bugs
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
There are many syntactical bugs in the code. C language does not use caret for power, rather pow function. Secondly, DEFINE_DIFFUSIVITY is not required and nor is it intended to be used in this manner. You can access diffusivity directly using C_DIFF_L.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 29, 2020, 16:36
Default
  #7
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
There are many syntactical bugs in the code. C language does not use caret for power, rather pow function. Secondly, DEFINE_DIFFUSIVITY is not required and nor is it intended to be used in this manner. You can access diffusivity directly using C_DIFF_L.
Okay I got your point, I'll check the syntax.



Now I have a problem while loading the UDF, the previous udf it's code is:


Error: No user-defined functions have been loaded.

Error Object: #f

Error: Set_Property: null user-defined-function name

Error: Set_Property: null user-defined-function name

Error Object: #f


Code:
#include "udf.h"



DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)

{

real m_lg;

real T_SAT = 373.15;

Thread *gas = THREAD_SUB_THREAD(thread, from_index); // gas phase

Thread *liq = THREAD_SUB_THREAD(thread, to_index); // liquid phase



m_lg = 0.; // initialisation


if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))

{

m_lg = 0.1*C_VOF(cell,gas)*C_R(cell,gas)*

fabs(T_SAT-C_T(cell,gas))/T_SAT;

m_lg = 0.1* C_VOF(cell,gas) * C_R(cell,gas) * C_YI(cell , gas , 0) ;

//here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in the mixture denoted by phase 'gas'.

}

return (m_lg);

}
Anshs is offline   Reply With Quote

Old   May 29, 2020, 16:41
Default
  #8
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Referring to some other forum thread I also tried these TUI codes but nothing happened:

solve/set/expert

Linearized Mass Transfer UDF? [no] no

use alternate formulation for wall temperatures? [no]

Save cell residuals for post-processing? [no]

Keep temporary solver memory from being freed? [no]

Allow selection of all applicable discretization schemes? [no]


Error: Set_Property: null user-defined-function name

Error: Set_Property: null user-defined-function name

Error Object: #f
Anshs is offline   Reply With Quote

Old   May 29, 2020, 17:10
Default TUI Commands
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
You don't need TUI commands. Those are required only if you want to access gradients or if you wish to use linearized mass transfer. First of all, just try to return a constant value. And do not use capital letters or standard names for variable names; those could conflict with Fluent define names.

The error implies that the library has not been compiled. Check for errors during compilation. Furthermore, you have two equations for m_lg. Only the value calculated from the last one will be used.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 29, 2020, 17:22
Default
  #10
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
I tried to put a constant value for m_lg = 0.01, added the source file, clicked build, then clicked load. Also, the UDF file is in the same drive as the fluent file

Message:


Invalid switch - "new_ladle".

Copied D:\mass_trans.c to D:

ew_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\src

udf_names.c and user_nt.udf files in 2ddp are upto date.

(system "copy "C:\PROGRA~1\ANSYSI~1\v180\fluent"\fluent18.0.0\sr c\udf\makefile_nt.udf "D:

ew_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\win64\2ddp\makefile" ")

1 file(s) copied.

(chdir "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf")(chdir "win64\2ddp")

Done.



Opening library "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf"...

Library "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\win64\2ddp\libudf.dll" opened

liq_gas_source

Done.



Error: No user-defined functions have been loaded.

Error Object: #f



Error: Set_Property: null user-defined-function name



Error: Set_Property: null user-defined-function name

Error Object: #f
Anshs is offline   Reply With Quote

Old   May 30, 2020, 08:32
Default Compilation
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It is quite possible that you have two or more UDF libraries and there is problem with one of these. If there is only one library, then the compilation is not done properly. Delete the existing library and then compile it. Check for warnings or errors during compilation. Once compiled, go to the library and check for the existence of .dll file.

Furthermore, compilation cannot be done from inside WB until and unless all the paths are set properly, which is a rarity with Windows and Visual Studio. So, I'd recommend you to compile the library using stand-alone Fluent and then load it within Fluent started from WB.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 30, 2020, 12:43
Default
  #12
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It is quite possible that you have two or more UDF libraries and there is problem with one of these. If there is only one library, then the compilation is not done properly. Delete the existing library and then compile it. Check for warnings or errors during compilation. Once compiled, go to the library and check for the existence of .dll file.

Furthermore, compilation cannot be done from inside WB until and unless all the paths are set properly, which is a rarity with Windows and Visual Studio. So, I'd recommend you to compile the library using stand-alone Fluent and then load it within Fluent started from WB.
After I click build, this message shows in the console:

Code:
Copied D:

ew_ladle\mass_trans.c to D:

ew_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\src

udf_names.c and user_nt.udf files in 2ddp are upto date.

(system "copy "C:\PROGRA~1\ANSYSI~1\v180\fluent"\fluent18.0.0\src\udf\makefile_nt.udf "D:

ew_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\win64\2ddp\makefile" ")

1 file(s) copied.

(chdir "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf")(chdir "win64\2ddp")

Done.
After pressing 'load' this message comes in the console:

Code:
Opening library "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf"...

Library "D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\D:\new_ladle\ladle_x_files\dp0\FFF-5\Fluent\libudf\win64\2ddp\libudf.dll" opened

liq_gas_source

Done.
After I check in the UDF mechanism for 'edit'


Code:
Error: No user-defined functions have been loaded.

Error Object: #f



DPM Iteration ....



DPM Iteration ....



DPM Iteration ....



Error: Set_Property: null user-defined-function name



Error: Set_Property: null user-defined-function name

Error Object: #f
I'm not able to follow, what to do. Thanks
Anshs is offline   Reply With Quote

Old   May 30, 2020, 13:34
Default Compling
  #13
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
It is not compiling the UDF. Do it in stand-alone Fluent, i.e., outside WB.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 30, 2020, 16:40
Default
  #14
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
It is not compiling the UDF. Do it in stand-alone Fluent, i.e., outside WB.
How to do that? I have made the file on the workbench.

EDIT: It worked, I ran that after exporting a case file and opening it on a fluent launcher.
Anshs is offline   Reply With Quote

Old   May 30, 2020, 16:53
Default Compilation
  #15
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Visual Studio has a command prompt. You need to open that command prompt using right-click > Run As Administrator. Then, start Fluent from within that command prompt using command fluent. Before starting Fluent, change to the directory where case files and C source file for your UDF is located.

Once Fluent starts, compile the library. You don't need to load a case file. Look for warnings or error messages during compilation. If everything goes alright, then, go back to Fluent within WB, go to User-Defined > Manage, provide the name of the library that you compiled, and click on Load.
Anshs likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 30, 2020, 17:17
Default
  #16
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
I have checked for the above cases, I want some help with a problem in this code. I want to run this code such that, the mass transfer only occurs at the phase interface, given that I have initialized the problem with both the phases present in the system and separated by a phase boundary interface. mass to not through phase 1 ( gas phase ) but only at the boundary on phases 1 and 2.

How may I proceed to change my UDF?

Thanks for all the above help.


Code:
#include "udf.h"



DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)

{

real m_lg;

real T_SAT = 373.15;

Thread *gas = THREAD_SUB_THREAD(thread, from_index); // gas phase

Thread *liq = THREAD_SUB_THREAD(thread, to_index); // liquid phase



m_lg = 0.; // initialisation


if ((m_lg == 0. ) && (C_T(cell, gas) <= T_SAT))

{


fabs(T_SAT-C_T(cell,gas))/T_SAT;

m_lg = 0.1* C_VOF(cell,gas) * C_R(cell,gas) * C_YI(cell , gas , 0) ;

//here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in the mixture denoted by phase 'gas'.

}

return (m_lg);

}
Anshs is offline   Reply With Quote

Old   May 30, 2020, 17:21
Default
  #17
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by Anshs View Post
I have checked for the above cases, I want some help with a problem in this code. I want to run this code such that, the mass transfer only occurs at the phase interface, given that I have initialized the problem with both the phases present in the system and separated by a phase boundary interface. mass to not through phase 1 ( gas phase ) but only at the boundary on phases 1 and 2.

How may I proceed to change my UDF?
I think an if (equality) condition to select the phase interface, like cells with (volume fraction =! 0 or 1), if it's correct. then how and where may I express it in the UDF?
Anshs is offline   Reply With Quote

Old   May 30, 2020, 17:38
Default Interface
  #18
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
You can use conditional statement to check for volume fraction to be between, say, 0.3 and 0.7 for any phase and set value of mass transfer to be 0 otherwise. However, a more sophisticated and accurate approach is to use gradient of volume fraction instead of volume fraction itself. But if you keep volume fraction between 0.3 and 0.7, it should work.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 30, 2020, 20:19
Default
  #19
Member
 
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8
Anshs is on a distinguished road
Quote:
Originally Posted by vinerm View Post
You can use conditional statement to check for volume fraction to be between, say, 0.3 and 0.7 for any phase and set value of mass transfer to be 0 otherwise. However, a more sophisticated and accurate approach is to use gradient of volume fraction instead of volume fraction itself. But if you keep volume fraction between 0.3 and 0.7, it should work.
This is not working, is this correct as per what you said?
Thanks

Code:
#include "udf.h"



DEFINE_MASS_TRANSFER(liq_gas_source, cell, thread, from_index, from_species_index, to_index, to_species_index)

{

real m_lg;

real T_SAT = 373.15;

Thread *gas = THREAD_SUB_THREAD(thread, from_index); // gas phase

Thread *liq = THREAD_SUB_THREAD(thread, to_index); // liquid phase



m_lg = 0.; // initialisation


if ( (C_VOF(cell,gas) >0.3) && (C_VOF(cell,gas) <0.7))

{


m_lg = 0.1* C_VOF(cell,gas) * C_R(cell,gas) * C_YI(cell , gas , 0) ;

//here C_YI(c, gas, 0 ), denotes species mass fraction of 1st species in the mixture denoted by phase 'gas'.

}

return (m_lg);

}
Anshs is offline   Reply With Quote

Old   May 31, 2020, 06:52
Default Not Working
  #20
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
What do you mean by not working? Is it not compiling, or giving run-time error, or giving wrong values?

Fluent does not accept // for comments. So, either use /* */ or remove comments altogether.
Anshs likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply

Tags
fluent, mass transfer, species tranport, udf


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
Accessing phase interaction mass transfer rate in UDF ahmadimo Fluent UDF and Scheme Programming 1 October 7, 2021 00:08
species transport, mass transfer rate mattK FLUENT 4 September 16, 2021 15:22
Coupled Heat and Mass Transfer Mecroob OpenFOAM Running, Solving & CFD 1 July 12, 2020 20:24
UDF Source Terms: Both Species and Mass? Baum Fluent UDF and Scheme Programming 5 April 17, 2020 10:11
Species Mass Transfer Abu-Khawlah FLUENT 0 December 9, 2005 11:35


All times are GMT -4. The time now is 13:51.