using define mass transfer udf for cavitation
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! 
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);.

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. 
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; 
@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:) 
Quote:
the 2nd version works where you do mixed type calculations of integer and double (result will be of type double). 
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! 
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:

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. 
hi
does the "did not work" mean the caculation divergenced or the results useless? Quote:

calculation diverged and therefore the results were useless...

Hello
I want to define the cavitation model from UDF in Fluent and I dont know how, can you help me please. if you have any tutorial or cavitation file to compile in Fluent because I have not made the programing. thanks a lot email: khaled87walha@gmail.com 
Did you check the UDF manual for fluent, more specifically define_cavitation_rate udf description? If I'm not mistaken it has good points on how to include your own udf into fluent.
From the top of my head, you need to use compiled udf functions (there are options to have interpreted and compiled udfs), and you also need to enable singhal cavitation model if you want to then use your own cavitation model via udf. This request about singhal model is a bit funny, since you need to know that fluent then operates with mass and not volume fractions for phases...I think this is also shown in the example for the mentioned udf in the manual... 
All times are GMT 4. The time now is 11:54. 