CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for surface tension (https://www.cfd-online.com/Forums/fluent-udf/105857-udf-surface-tension.html)

smhosseini August 10, 2012 16:49

UDF for surface tension
 
Hi friends,
I want to determine surface tension. I wrote udf by using DEFINE_PROPERTY macro. I have an error and I know that this error is bcous of using this code:

Thread *liq = THREAD_SUB_THREAD(t,1);
x_water = C_YI(c,liq,1);
----------------------------------
liq is secondary phase and I have 4 species in liq phase.
is there anyone that knows how can I define mass fraction in secondary phase?

subha_meter August 22, 2012 22:07

The mass fraction (C_YI) macro is valid only when you use species transport model. Probably you are looking for volume fraction of secondary phase (C_VOF).

Quote:

Originally Posted by smhosseini (Post 376501)
Hi friends,
I want to determine surface tension. I wrote udf by using DEFINE_PROPERTY macro. I have an error and I know that this error is bcous of using this code:

Thread *liq = THREAD_SUB_THREAD(t,1);
x_water = C_YI(c,liq,1);
----------------------------------
liq is secondary phase and I have 4 species in liq phase.
is there anyone that knows how can I define mass fraction in secondary phase?


smhosseini August 23, 2012 05:07

Hi Subha,
Thanks for your reply. I have mass transfer and I'm using species transport model. ;)

subha_meter August 23, 2012 08:11

Hi,
I actually didn't notice that you are using species transport model. When you specify mass fractions (xi) of three species, the fourth one is automatically determined : 1 - sum(xi) (i= 0 to 2). What error message did you get? If you write the complete UDF here, it will be easy to debug it.

Regards,

Quote:

Originally Posted by smhosseini (Post 378286)
Hi Subha,
Thanks for your reply. I have mass transfer and I'm using species transport model. ;)


smhosseini August 23, 2012 13:10

dear subha,
thanks for your attention, i am really sorry for not being completely clear in explaining the problem :o.
my udf is:

#include "udf.h"
DEFINE_PROPERTY(surface_tension,c,t)
{
real x_water, sigma_water, sigma_MEA, sigma;
Thread *liq = THREAD_SUB_THREAD(t,1);
x_water = (1-C_YI(c,liq,3)) / (18.01 * ((1-C_YI(c,liq,3)) / 18.01 + C_YI(c,liq,3) / 61.08));
sigma_water = 76.0852 - 0.1609 * (C_T(c,t) - 273.15);
sigma_MEA = 53.082 - 0.1648 * (C_T(c,t) - 273.15);
sigma = (sigma_water - (sigma_water - sigma_MEA) * (1 + (0.63036 - (1.3e-5) * (C_T(c,t) - 273.15)) * x_water / (1 - ( 0.947 - 2e-5 * (C_T(c,t) - 273.15)) * x_water)) * (1 - x_water)) / 1000;
return sigma;
}
----------------------------------------------------------------------------------------------------
and my error is:
fluent received a fatal signal (segmentation violation).
I don't have error when i don't use C_YI.

subha_meter August 23, 2012 20:57

Hi sm,

It seems that your liquid phase contains water and MEA however you mentioned that there are 4 species in your liquid phase. What are the other two?

In your UDF you have accessed C_YI(c,liq,3) which is the mass fraction of 4th species. This will cause a "segment violation" problem if the appropriate component is not already defined in the species panel.

You already have the mass fraction of each component from C_YI(c,t,i) macro but if you would like to calculate the mole fraction of any component, you need to find out average molecular weight of the mixture. This can be done as follows,

#define N 4 /*maximum number of species*/

int i;
real mw[N],x[N],mol_frac[N],avg_mol_wt;
MATERIAL *mix,sp;
Thread *liq = THREAD_SUB_THREAD(t,1);
mix = THREAD_MATERIAL(liq);

mixture_species_loop(mix,sp,i)
{
mw[i] = MATERIAL_PROP(sp,PROP_mwi);
x[i] = C_YI(cell,liq,i);
avg_mol_wt + =mw[i]*x[i];
}

for(i=0;i<N;i++)
{
mol_frac[i] = C_YI(c,liq,i)/avg_mol_wt;
}

Hope it helps,

Quote:

Originally Posted by smhosseini (Post 378394)
dear subha,
thanks for your attention, i am really sorry for not being completely clear in explaining the problem :o.
my udf is:

#include "udf.h"
DEFINE_PROPERTY(surface_tension,c,t)
{
real x_water, sigma_water, sigma_MEA, sigma;
Thread *liq = THREAD_SUB_THREAD(t,1);
x_water = (1-C_YI(c,liq,3)) / (18.01 * ((1-C_YI(c,liq,3)) / 18.01 + C_YI(c,liq,3) / 61.08));
sigma_water = 76.0852 - 0.1609 * (C_T(c,t) - 273.15);
sigma_MEA = 53.082 - 0.1648 * (C_T(c,t) - 273.15);
sigma = (sigma_water - (sigma_water - sigma_MEA) * (1 + (0.63036 - (1.3e-5) * (C_T(c,t) - 273.15)) * x_water / (1 - ( 0.947 - 2e-5 * (C_T(c,t) - 273.15)) * x_water)) * (1 - x_water)) / 1000;
return sigma;
}
----------------------------------------------------------------------------------------------------
and my error is:
fluent received a fatal signal (segmentation violation).
I don't have error when i don't use C_YI.


smhosseini August 24, 2012 08:47

Dear subha,
I have five species in liq phase. But three other species are in low concentration and I disregard them against water and MEA.
you can compute mole fraction exactly from this formula:

xi = (wi / Mi) / (wi / Mi + wj / Mj + . . . )

w and M is mass fraction and molecular weight respectively.

Lab_001 January 26, 2022 05:06

Hi,
I am working on a project about welding. I use FLUENT vof to simulate the melting pool . During the calculation, I found that the surface tension define in my udf code have some problems. Here is my code:
-------------------------------------------------------------------
DEFINE_PROPERTY(surf_tension,c,t)
{
real surf;
int curr,i,j;
real temp1=C_T(c,t);
if(temp1>=1700)
surf=1.0-0.0003*(temp1-1700);
else if(temp1>=2980)
surf=0.41;
else
surf=1.0;
return surf;
}
-------------------------------------------------------------------
My surface tension seems like effect all the areas when temp1>=1700 and causes a whole area shape changing to my model. I think it should only effect the cell temp1>=1700. Is there anyone know what happen to that?

AlexanderZ February 2, 2022 19:14

code seems to be correct

huffymane June 18, 2022 01:14

Hey there anyone it may help. I know this reply is late, but this post helped me on my journey and I would like to answer.

I have the same objective as this post states, to write a UDF that controls the surface tension coefficient by analyzing the mixture species fraction.

The following code seems to be the answer:


DEFINE_PROPERTY(Custom_Surface_Tension, c, t)
{
Domain *mix;
mix = Get_Domain(1);

Thread *mix_thread = Lookup_Thread(mix, 2);
Thread *sec_phase = THREAD_SUB_THREAD(mix_thread,1);

real sigma, xm;

xm = C_YI(c,sec_phase,1);
sigma = 0.043*xm*xm - 0.1081*xm + 0.0702;


return sigma;
}


The key part being the first 4 lines of code:
Lines 1-2. grab the mixture domain pointer (domain ID=1 for mixture domain) & assign variable *mix.
Line 3. Find the relevant thread (domain ID=1 for mixture, Zone ID=2 for fluid), assign the lookup to a variable *mix_thread (this is a mixture level thread)

Line 4. Assign a phase level pointer (*sec_phase) to secondary phase thread



*sec_phase now has the required data to proceed with mass fraction function C_YI


All times are GMT -4. The time now is 20:42.