CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   using define mass transfer udf for cavitation (https://www.cfd-online.com/Forums/fluent-udf/95441-using-define-mass-transfer-udf-cavitation.html)

 Komon December 18, 2011 07:51

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 define-mass-transfer udf for Zwart-Gerber-Belamri cavitation model and compiled it into fluent successfully. the idea is to find out if my udf gives the same results as zwart-gerber-belamri 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;

p0 = RP_Get_Real("operating-pressure");
dp = p_vap-abs_p;
dp0 = ABS(dp);
source = sqrt(2/3*dp0/C_R(c,liq));

if (dp > 0)
R = Fe*3*alfa_n*(1-C_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.

 Sixkillers December 19, 2011 05:57

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

 Komon December 19, 2011 11:23

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 same-no 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.

 Sixkillers December 20, 2011 07:07

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("operating-pressure");         fprintf(handle, "%e\n", p0); /*ADDED*/                 abs_p = C_P(c,mixture_thread)+p0;         dp = p_vap-abs_p;         dp0 = ABS(dp);         source = sqrt(2/3*dp0/C_R(c,liq));         if (dp > 0)         R = Fe*3*alfa_n*(1-C_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); }```

 Komon December 20, 2011 12:30

@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:)

 acshina37 December 27, 2013 16:15

Quote:
 Originally Posted by Komon (Post 336493) @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:)
I know this is an old thread. I just wanna say that you got 0 mass transfer in the 1st version was due to the truncation of the 2 integers in C (compute 2/3 gives 0, not 0.6666). Instead, use 2.0/3.0.
the 2nd version works where you do mixed type calculations of integer and double (result will be of type double).

 Komon December 27, 2013 16:47

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!

 yuanmengyuan1989 December 18, 2014 10:10

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:

 Komon December 22, 2014 13:50

Hi!

The define_mass_transfer did not work. What did work was define_cavitation_rate or an udf like that-which is specially meant for modelling cavitation source terms.

 yuanmengyuan1989 December 22, 2014 21:34

hi
does the "did not work" mean the caculation divergenced or the results useless?

Quote:
 Originally Posted by Komon (Post 524967) Hi! The define_mass_transfer did not work. What did work was define_cavitation_rate or an udf like that-which is specially meant for modelling cavitation source terms.

 Komon December 23, 2014 02:00

calculation diverged and therefore the results were useless...

 khaled.oualha March 10, 2016 11:38

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
e-mail: khaled87walha@gmail.com

 Komon March 10, 2016 11:48

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

 MDSHUJAN June 20, 2016 17:48

Quote: