
[Sponsors] 
December 18, 2011, 07:51 
using define mass transfer udf for cavitation

#1 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
Hi!
For the last couple of days, I've beed trying to figure out how to use DEFINE_MASS_TRANSFER in order to put into fluent a cavitation model, which is a bit different than those already integrated. I know there is DEFINE_CAV_RATE macro available to put into fluent your own source and sink terms for cavitation models, but let's leave that besides for now. The problem I'm facing is: I've written a definemasstransfer udf for ZwartGerberBelamri cavitation model and compiled it into fluent successfully. the idea is to find out if my udf gives the same results as zwartgerberbelamri model already available in fluent. The udf is written as follows: DEFINE_MASS_TRANSFER(zgb_model, c, mixture_thread, from_phase_index, from_species_index, to_phase_index, to_species_index) { real R; real p0, abs_p, dp, dp0, source; Thread *liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index); Thread *vap = THREAD_SUB_THREAD(mixture_thread, to_phase_index); p0 = RP_Get_Real("operatingpressure"); abs_p = C_P(c,mixture_thread)+p0; dp = p_vapabs_p; dp0 = ABS(dp); source = sqrt(2/3*dp0/C_R(c,liq)); if (dp > 0) R = Fe*3*alfa_n*(1C_VOF(c,vap))/Rb*C_R(c,vap)*source; else R = Fc*3*C_VOF(c,vap)*C_R(c,vap)/Rb*source; return (R); } some of the constants as alfa_n are of course predefined at the beggining of udf with #define alfa_n ... . The thing is that when I run the simulation, I get no mass transfer. However, the pressure in water doesn't drop below 0 Pa absolute pressure as it otherwise does in my problem(single phase simulation gives me pressures down to 5 bar ). So there is something happening with this udf, I just cannot figure out what exactly. Besides, if I put some constant value for R, I get mass transfer. Therefore I would really appreciate if someone would give a look at the UDF and tell me what I've done wrong. thanks in advance! 

December 19, 2011, 05:57 

#2 
Member
Join Date: Nov 2011
Location: Czech Republic
Posts: 95
Rep Power: 5 
If you want to know what is going on in your UDF it is worth trying write some values computed by your UDF to a textfile. You just have to create a file handle (by using fopen method called in DEFINE_INIT macro or some similar) and then write values that you are interested in (e.g. fprintf(handle, "%e,%e\n", dp, R);.


December 19, 2011, 11:23 

#3 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
hi!
I tried printf, to print results for R to console. But it didn't work, nothing appeared in console. I tried this at two computers, results are always the sameno mass transfer and nothing written in the console. But I'll try your suggestion. p.s.: @Sixkillers, I tried your suggestion, and as I expected, there was no file created or anything written into the file if I myself created a .txt file before. I think there must be something wrong with the compiler or with the thread pointers, and the reason is as follows: I tried to change the UDF, given in my first post, in order to find out which part od the equation for R is problematic. The constants work ok, I got mass transfer and therefore vapor. The values for mass transfer were correct, corresponding to the values of constants (Fe,3,alfa_n and Rb). Then I added source. And got the same result as if I used full equations for R. 0 mass transfer. source itself is: source = sqrt(2/3*dp0/C_R(c,liq)); It contains C_R(c,t) and p0>operating pressure. So my question is: is it possible that I used wrong thread pointers, or is compiler the reason? I use win7, 64bit, ansys 12.1 and for compiled udf's I use visual studio 2010 with sdk command prompt from .net framework 2.0 as is suggested in FAQ on this portal. Last edited by Komon; December 19, 2011 at 19:40. 

December 20, 2011, 07:07 

#4 
Member
Join Date: Nov 2011
Location: Czech Republic
Posts: 95
Rep Power: 5 
This is really weird, here is your source code slightly modified for debug purpose. An output file is called DEBUG_REPORT and it should be created after UDF is loaded into Fluent. Operating pressure should be written into it as the simulation proceeds. Also I included some NULL checks. Definitely give it a try.
Code:
static FILE* handle = NULL; DEFINE_EXECUTE_ON_LOADING(init, libname) { handle = fopen("DEBUG_REPORT", "w"); if(handle == NULL) { Message("Unable to create DEBUG_REPORT\n"); abort(); } } DEFINE_MASS_TRANSFER(zgb_model, c, mixture_thread, from_phase_index, from_species_index, to_phase_index, to_species_index) { real R; real p0, abs_p, dp, dp0, source; Thread *liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index); Thread *vap = THREAD_SUB_THREAD(mixture_thread, to_phase_index); if(liq == NULL) { Message("The liquid thread is NULL\n"); abort(); } if(vap == NULL) { Message("The vapour thread is NULL\n"); abort(); } p0 = RP_Get_Real("operatingpressure"); fprintf(handle, "%e\n", p0); /*ADDED*/ abs_p = C_P(c,mixture_thread)+p0; dp = p_vapabs_p; dp0 = ABS(dp); source = sqrt(2/3*dp0/C_R(c,liq)); if (dp > 0) R = Fe*3*alfa_n*(1C_VOF(c,vap))/Rb*C_R(c,vap)*source; else R = Fc*3*C_VOF(c,vap)*C_R(c,vap)/Rb*source; return (R); } 

December 20, 2011, 12:30 

#5 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
@Sixkillers
thanky you very much for your help! I was finally able to see which values are read into Fluent and where the problem is. I found out that all values read from macros like C_P and so on, even operating pressure, are OK. The problem was in equation for source variable. This was always 0, until I wrote it as follows: source = sqrt(2*dp0/(3*rho_liq)); /*rho_liq is C_R(c,liq)*/ then i got mass transfer from liquid to vapor and UDF finally started to give me some results.....which are still weird, but it is a progress I don't know the exact reason why this helped me to get results different from 0 for source.......it isn't that I wrote rho_liq instead of C_R, because only when I reordered the parts of equation I got results different from 0. I'm guessing it also isn't the numerical error because of using division and multiplying in a certain order.....it's just a complete unknown to me. anyway, thanks a lot for your help, I hope I'll be able to return the favour someday 

December 27, 2013, 16:15 

#6  
New Member
Join Date: Aug 2013
Posts: 3
Rep Power: 4 
Quote:
the 2nd version works where you do mixed type calculations of integer and double (result will be of type double). 

December 27, 2013, 16:47 

#7 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
hi,
yes, it's an old thread and since then I figured out about the trick with integers and doubles it gave me quite some headache, especially as I was really at the beggining of writing the UDFs. but thanks for the 2nd part of your reply, I did never check what happens if you multiply integer and double, I just rather used doubles everywhere. p.s.: happy holidays! 

December 18, 2014, 10:10 

#8  
New Member
Join Date: Jul 2012
Posts: 25
Rep Power: 5 
are the results by "Define_mass_transfer" the same with the results by the zawart cavitation model"?
i also use the "define_mass_transfer" to define the cavitation? but the results are divergence. Quote:


December 22, 2014, 13:50 

#9 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
Hi!
The define_mass_transfer did not work. What did work was define_cavitation_rate or an udf like thatwhich is specially meant for modelling cavitation source terms. 

December 22, 2014, 21:34 

#10 
New Member
Join Date: Jul 2012
Posts: 25
Rep Power: 5 

December 23, 2014, 02:00 

#11 
Member
Join Date: Sep 2011
Posts: 32
Rep Power: 6 
calculation diverged and therefore the results were useless...


Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Robin B.C.  Yu  FLUENT  3  May 27, 2012 04:19 
UDF for Species Mass Fraction Gradient *IN SPECIFIC ZONE *  e.g. along axis of sym.  ksiegs2  Fluent UDF and Scheme Programming  0  February 27, 2011 13:55 
Mass Transfer UDF using Fluent VOF  Anirudh_Deodhar  Fluent UDF and Scheme Programming  2  February 14, 2011 16:07 
About phase change heat and mass transfer  Michael  FLUENT  2  February 13, 2011 02:49 
mass flow in is not equal to mass flow out  saii  CFX  2  September 18, 2009 08:07 