# Species mass transfer UDF

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

 May 29, 2020, 12:16 Species mass transfer UDF #1 Member   Anshuman Sinha Join Date: Oct 2018 Posts: 70 Rep Power: 6 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'?

 May 29, 2020, 12:22 Species' Indices #2 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 29, 2020, 13:04
#3
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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"

from_species_index, to_index, to_species_index)

{

real m_lg;

real T_SAT = 373.15;

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

 May 29, 2020, 13:09 Udf #4 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 29, 2020, 14:49
#5
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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"

from_species_index, to_index, to_species_index)

{

real m_lg;

real T_SAT = 373.15;

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

 May 29, 2020, 15:43 Bugs #6 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 29, 2020, 16:36
#7
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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;

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

}```

 May 29, 2020, 16:41 #8 Member   Anshuman Sinha Join Date: Oct 2018 Posts: 70 Rep Power: 6 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

 May 29, 2020, 17:10 TUI Commands #9 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

 May 30, 2020, 08:32 Compilation #11 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 30, 2020, 12:43
#12
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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:

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:

1 file(s) copied.

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"...

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

 May 30, 2020, 13:34 Compling #13 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 30, 2020, 16:40
#14
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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.

 May 30, 2020, 16:53 Compilation #15 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

 May 30, 2020, 17:17 #16 Member   Anshuman Sinha Join Date: Oct 2018 Posts: 70 Rep Power: 6 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); }```

May 30, 2020, 17:21
#17
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by Anshs 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?

 May 30, 2020, 17:38 Interface #18 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

May 30, 2020, 20:19
#19
Member

Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 6
Quote:
 Originally Posted by vinerm 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;

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

}```

 May 31, 2020, 06:52 Not Working #20 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,946 Blog Entries: 1 Rep Power: 34 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.

 Tags fluent, mass transfer, species tranport, udf