|
[Sponsors] |
May 29, 2020, 12:16 |
Species mass transfer UDF
|
#1 |
Member
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8 |
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
|
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: 8 |
Quote:
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); |
||
May 29, 2020, 13:09 |
Udf
|
#4 |
Senior Member
|
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: 8 |
Quote:
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); |
||
May 29, 2020, 15:43 |
Bugs
|
#6 |
Senior Member
|
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: 8 |
Quote:
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); } |
||
May 29, 2020, 16:41 |
|
#8 |
Member
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8 |
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
|
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 29, 2020, 17:22 |
|
#10 |
Member
Anshuman Sinha
Join Date: Oct 2018
Posts: 70
Rep Power: 8 |
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 |
|
May 30, 2020, 08:32 |
Compilation
|
#11 |
Senior Member
|
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: 8 |
Quote:
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. 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. 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 |
||
May 30, 2020, 13:34 |
Compling
|
#13 |
Senior Member
|
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: 8 |
||
May 30, 2020, 16:53 |
Compilation
|
#15 |
Senior Member
|
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.
__________________
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: 8 |
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: 8 |
Quote:
|
||
May 30, 2020, 17:38 |
Interface
|
#18 |
Senior Member
|
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: 8 |
Quote:
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); } |
||
May 31, 2020, 06:52 |
Not Working
|
#20 |
Senior Member
|
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.
__________________
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 |
|
|
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 |