CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

using define mass transfer udf for cavitation

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Komon

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 18, 2011, 06:51
Default using define mass transfer udf for cavitation
  #1
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
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;
Thread *liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index);
Thread *vap = THREAD_SUB_THREAD(mixture_thread, to_phase_index);

p0 = RP_Get_Real("operating-pressure");
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);
}

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!
Komon is offline   Reply With Quote

Old   December 19, 2011, 04:57
Default
  #2
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
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);.
Sixkillers is offline   Reply With Quote

Old   December 19, 2011, 10:23
Default
  #3
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
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.

Last edited by Komon; December 19, 2011 at 18:40.
Komon is offline   Reply With Quote

Old   December 20, 2011, 06:07
Default
  #4
Member
 
Join Date: Nov 2011
Location: Czech Republic
Posts: 97
Rep Power: 14
Sixkillers is on a distinguished road
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);
}
Sixkillers is offline   Reply With Quote

Old   December 20, 2011, 11:30
Default
  #5
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
@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
Komon is offline   Reply With Quote

Old   December 27, 2013, 15:15
Default
  #6
New Member
 
Join Date: Aug 2013
Posts: 3
Rep Power: 12
acshina37 is on a distinguished road
Quote:
Originally Posted by Komon View Post
@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).
acshina37 is offline   Reply With Quote

Old   December 27, 2013, 15:47
Default
  #7
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
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!
Komon is offline   Reply With Quote

Old   December 18, 2014, 09:10
Default
  #8
New Member
 
Join Date: Jul 2012
Posts: 25
Rep Power: 13
yuanmengyuan1989 is on a distinguished road
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:
Originally Posted by Komon View Post
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;
Thread *liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index);
Thread *vap = THREAD_SUB_THREAD(mixture_thread, to_phase_index);

p0 = RP_Get_Real("operating-pressure");
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);
}

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!
yuanmengyuan1989 is offline   Reply With Quote

Old   December 22, 2014, 12:50
Default
  #9
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
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.
ndabir likes this.
Komon is offline   Reply With Quote

Old   December 22, 2014, 20:34
Default
  #10
New Member
 
Join Date: Jul 2012
Posts: 25
Rep Power: 13
yuanmengyuan1989 is on a distinguished road
hi
does the "did not work" mean the caculation divergenced or the results useless?


Quote:
Originally Posted by Komon View Post
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 is offline   Reply With Quote

Old   December 23, 2014, 01:00
Default
  #11
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
calculation diverged and therefore the results were useless...
Komon is offline   Reply With Quote

Old   March 10, 2016, 10:38
Default
  #12
New Member
 
khaled oualha
Join Date: Feb 2016
Posts: 2
Rep Power: 0
khaled.oualha is on a distinguished road
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
khaled.oualha is offline   Reply With Quote

Old   March 10, 2016, 10:48
Default
  #13
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
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...
Komon is offline   Reply With Quote

Old   June 20, 2016, 17:48
Default
  #14
New Member
 
SHUJAN
Join Date: Jun 2016
Posts: 17
Rep Power: 9
MDSHUJAN is on a distinguished road
Quote:
Originally Posted by Komon View Post
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;
Thread *liq = THREAD_SUB_THREAD(mixture_thread, from_phase_index);
Thread *vap = THREAD_SUB_THREAD(mixture_thread, to_phase_index);

p0 = RP_Get_Real("operating-pressure");
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);
}

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!

Hi. I am using DEFINE_MASS_TRANSFER for modelling evaporation-condensation. I can compile my udf successfully, but it is not available in phase interaction tab to hook. Can you tell me how you hook your udf?
MDSHUJAN is offline   Reply With Quote

Old   June 21, 2016, 02:50
Default
  #15
Member
 
Join Date: Sep 2011
Posts: 43
Rep Power: 14
Komon is on a distinguished road
hi,

huh, it's been a long time since I used this, I'm afraid I don't know it from the top of my head anymore. But I don't think I had some issues with chosing it, I think it was quite straightforward in fluent, as for any define_mass_transfer udf.

regards
Komon is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 05:21
Mass Transfer UDF using Fluent VOF Anirudh_Deodhar Fluent UDF and Scheme Programming 3 November 18, 2015 09:29
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 12:55
About phase change heat and mass transfer Michael FLUENT 2 February 13, 2011 01:49


All times are GMT -4. The time now is 16:21.