CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Species Mole and Mass Fraction Macro (http://www.cfd-online.com/Forums/fluent/113122-species-mole-mass-fraction-macro.html)

combustion February 12, 2013 19:09

Species Mole and Mass Fraction Macro
 
Hi,

Fluent 14 has a macro for looking up mole and mass fractions of species for non-premixed combustion cases:

Pdf_XY(cell c, thread *t, x, y)

I am trying to write a source term for a UDS to duplicate the Brookes and Moss two equation soot model that is already built into fluent. I will later modify my source terms to make a new 2-eqn model.

My problem is that when I don't know how the species are indexed in fluent. Is the indexing based on the flamelet library or based on the pdf-mixture species list?

I have attached my code for one of the source terms.

Thanks for your help.

#include "udf.h"
#include "pdf_props.h"
#include "pdf_table.h"
#include "mem.h"
#include "materials.h"

/*********Constant Declarations*************************************/
#define c_alph 54.0 /* Units: 1/s */
#define N_avog 6.022045e+26 /* 1/kmol */
#define c_bet 1.0 /* no units */
#define rho_soot 1800.0 /* kg/m3 */
#define T_alph 21000.0 /* activation temperature of soot inception in K */
#define N_norm 1.0e+15 /* Moss-Brookes model: normalizing parameter */
#define l 1.0 /* l indicates the particle nucleation sensitivity to Pressure: defined as 1.0 for now */
#define PI 3.14159265358979324 /* Pi as a constant...alternatively pi=4.0*atan(1.0) */
#define SpNo 20 /* The number of species in the mechanism file: should be adjusted according to the mechanism */
#define Species 22 /* This is the index for the species of interest (C2H2 in this case) */
/*********End Constant Declarations*********************************/

DEFINE_SOURCE(n_sourceterm, c, ct, dS, eqn)
{
/*********Variable Declarations*************************************/
double dNdT, dp, X_C2H2, T, P, rho_cell, M, N, Ysoot, bNuc, R;
double x[SpNo], y[SpNo]; /* x is the array for species mole fractions and y is the array for mass fractions */
int id_c2h2;
/*********End Variable Declarations*********************************/

/*********Variable Assignments**************************************/
Material *mat = THREAD_MATERIAL(ct);
id_c2h2 = mixture_specie_index(mat, "c2h2");
Pdf_XY(c, ct, x, y); /* Calling the species mole and mass fractions for this cell */
X_C2H2 = x[id_c2h2]; /* arbitrarily defined for now */
T = C_T(c, ct); /* Temperature at the cell */
if (c == 400)
Message("Temp is %g\n, species %", T);
P = C_P(c, ct); /* Cell Presdsure */
if (c == 400)
Message("Press is %g\n, ", P);
rho_cell = C_R(c, ct); /* Cell average Density */
R = UNIVERSAL_GAS_CONSTANT; /* Universal gas constant is called with the built-in Fluent Macro */

Ysoot = C_UDSI(c, ct, 0); /* Calling soot mass fraction from m_sourceterm scalar */
if (c == 400)
Message("Ysoot is %g\n, ", Ysoot);

bNuc = C_UDSI(c, ct, 1); /* Calling soot number density from n_sourceterm scalar */
if (c == 400)
Message("bNuc is %g\n, ", bNuc);
/**********End Variable Assignments*********************************/

/**********Start Calculations************************************** */
M = rho_cell * Ysoot;
N = bNuc * rho_cell * N_norm;
dp = pow(((6.0 * M)/(PI * N * rho_soot)), (1.0/3.0));
dNdT = c_alph * N_avog * pow(((X_C2H2 * P)/(R * T)), l) * exp(-1.0 * T_alph / T) - c_bet * pow(((24.0 * R * T) / ( rho_soot * N_avog)), 0.5) * sqrt(dp) * pow(N, 2);
if (c == 400)
Message("dNdT is %g\n, ", dNdT);
/**********End of Calculations**************************************/

return (dNdT / N_norm);

}

pghoseju May 4, 2013 01:35

Edit the constants of moss brooks soot model
 
I desperately want to edit the constants of moss brooks soot model. But till now I did not get any idea. Is it possible to do such by any way? If possible please tell me.

combustion May 6, 2013 17:17

Hi Prakash,
The answer is No and Yes.
No: you cannot modify the constants in the Fluent solver. There is no option to go that route.

Yes: you can write a UDF for a two-eqn model and manipulate the coefficients as you see fit.

pghoseju May 8, 2013 05:05

UDF Soot
 
Thank you sir for your kind response.

Yes I want to create duplicate source term equations. In my result I am having c2h2. Any way I want to know how can I call temperature, pressure and specially mass fraction of C2H2 (Xprec, Xsgs) by udf. Also I want to know how can I call cell density for calculation of M and N.

Can you plz help me?

pghoseju May 23, 2013 02:26

udf soot
 
Sir Kaveh,
The same problem I am too facing. I am also using steady flamelet model. I got C2H2 in flamelet mixture. I also want to know what is the value of 'i' (index) so that I can use C_YI (c,t,i). I have number of species under pdf mixture and below it again number of species under flamelet mixture. So how can I count for species index? Should I start for pdf mixture or what???

plz help me

combustion May 23, 2013 12:29

Hi Prakash,

Who is "Sir" Kaveh? :)
I found out that you can find the species index by putting the following segment in your code:

/***************************************/
Material *mat = THREAD_MATERIAL(ct); /* This segment determines the species index number */
id_c2h2 = mixture_specie_index(mat, "c2h2");
/**************************************/

The example above is for acetylene. You can find any species index in the same manner. So, id_c2h2 is the variable that contains the species index for c2h2 which is an integer.

I hope this was useful.

pghoseju May 24, 2013 03:02

udf ssot
 
Thank you for your kind response.

pghoseju May 28, 2013 05:49

Sir,
When I am interpreting it, it shows the following error.

Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "mixture_specie_index" not found (pc=87).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "Pdf_XY" not found (pc=101).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "CX_Message" not found (pc=150).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "CX_Message" not found (pc=186).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "CX_Message" not found (pc=246).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "CX_Message" not found (pc=282).
Error: C:/Users/AMITAD~1/AppData/Local/Temp/udf soot 1_2.c.1.c: line 63: function "CX_Message" not found (pc=405).

combustion May 28, 2013 14:15

Have you included the proper libraries?

#include "materials.h"
#include "pdf_table.h"

pghoseju May 29, 2013 05:50

udf soot
 
Sir,
I included following libraries.

#include "udf.h"
#include "pdf_props.h"
#include "pdf_table.h"
#include "mem.h"
#include "materials.h"

combustion May 29, 2013 11:12

can you post your code here?

pghoseju June 8, 2013 04:29

udf soot
 
Sorry sir for late response. I was out of my city for few days. Actually I am using the UDF written by you on this forum. Again I was doing a great mistake that, I was interpreting the UDF in ANSYS 13.0 but now previous error is not there because now I am using Ansys 14.0.

But some new error came.
cpp -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/multiport/src" -I. -
UDFCONFIG_H="<C:/Users/WINDOW~1/AppData/Local/Temp/udfconfig-node0.h>" "C:/Users/WINDOW~1/AppData/Local/Temp/udf soot 1_2.c.0.c"
Error: C:\\PROGRA~1\\ANSYS Inc\\v140\\fluent\\fluent14.0.0/src/pdf_table.h: line 141: ran off top of typedef queue (300).

cpp -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/cortex/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/client/src" -I"C:\PROGRA~1\ANSYS Inc\v140\fluent\fluent14.0.0/multiport/src" -I. -
UDFCONFIG_H="<C:/Users/WINDOW~1/AppData/Local/Temp/udfconfig-node1.h>" "C:/Users/WINDOW~1/AppData/Local/Temp/udf soot 1_2.c.1.c"
Error: C:\\PROGRA~1\\ANSYS Inc\\v140\\fluent\\fluent14.0.0/src/pdf_table.h: line 141: ran off top of typedef queue (300).

pghoseju June 8, 2013 04:54

udf soot
 
The red marks I cannot get anythging from udf HELP
I found in udf help it is written like Bold letter I have written. Sir plz can you help me regarding this metter

#include "udf.h"
#include "pdf_props.h"
#include "pdf_table.h"
#include "mem.h"
#include "materials.h"

/*********Constant Declarations*************************************/
#define c_alph 54.0 /* Units: 1/s */
#define N_avog 6.022045e+26 /* 1/kmol */
#define c_bet 1.0 /* no units */
#define rho_soot 1800.0 /* kg/m3 */
#define T_alph 21000.0 /* activation temperature of soot inception in K */
#define N_norm 1.0e+15 /* Moss-Brookes model: normalizing parameter */
#define l 1.0 /* l indicates the particle nucleation sensitivity to Pressure: defined as 1.0 for now */
#define PI 3.14159265358979324 /* Pi as a constant...alternatively pi=4.0*atan(1.0) */
#define SpNo 20 /* The number of species in the mechanism file: should be adjusted according to the mechanism */
#define Species 22 /* This is the index for the species of interest (C2H2 in this case) */
/*********End Constant Declarations*********************************/

DEFINE_SOURCE(n_sourceterm, c, ct, dS, eqn)
{
/*********Variable Declarations*************************************/
double dNdT, dp, X_C2H2, T, P, rho_cell, M, N, Ysoot, bNuc, R;
double x[SpNo], y[SpNo]; /* x is the array for species mole fractions and y is the array for mass fractions */
int id_c2h2; ic2h2
/*********End Variable Declarations*********************************/

/*********Variable Assignments**************************************/
Material *mat = THREAD_MATERIAL(ct); Material *m = THREAD_MATERIAL(t);
id_c2h2 = mixture_specie_index(mat, "c2h2"); ic2h2 = mixture_specie_index(m, "c2h2");
Pdf_XY(c, ct, x, y); Pdf_XY(c, t, x, y);/* Calling the species mole and mass fractions for this cell */
X_C2H2 = x[id_c2h2]; X_C2H2 = xi[ic2h2]; /* arbitrarily defined for now */
T = C_T(c, ct); T = C_T(c, t)/* Temperature at the cell */
if (c == 400)
Message("Temp is %g\n, species %", T);
P = C_P(c, ct); P = C_P(c, t)/* Cell Presdsure */
if (c == 400)
Message("Press is %g\n, ", P);
rho_cell = C_R(c, ct); rho_cell = C_R(c, t);/* Cell average Density */
R = UNIVERSAL_GAS_CONSTANT; /* Universal gas constant is called with the built-in Fluent Macro */

Ysoot = C_UDSI(c, ct, 0); Ysoot = C_UDSI(c, t, 0);/* Calling soot mass fraction from m_sourceterm scalar */
if (c == 400)
Message("Ysoot is %g\n, ", Ysoot);

bNuc = C_UDSI(c, ct, 1); bNuc = C_UDSI(c, t, 1);/* Calling soot number density from n_sourceterm scalar */
if (c == 400)
Message("bNuc is %g\n, ", bNuc);
/**********End Variable Assignments*********************************/

/**********Start Calculations************************************** */
M = rho_cell * Ysoot;
N = bNuc * rho_cell * N_norm;
dp = pow(((6.0 * M)/(PI * N * rho_soot)), (1.0/3.0));
dNdT = c_alph * N_avog * pow(((X_C2H2 * P)/(R * T)), l) * exp(-1.0 * T_alph / T) - c_bet * pow(((24.0 * R * T) / ( rho_soot * N_avog)), 0.5) * sqrt(dp) * pow(N, 2);
if (c == 400)
Message("dNdT is %g\n, ", dNdT);
/**********End of Calculations**************************************/

return (dNdT / N_norm);

}

pghoseju June 18, 2013 10:15

udf soot
 
Sir I am posting my full udf, which is not running.
Plz help me.




#include "udf.h"
#include "pdf_props.h"
#include "pdf_table.h"
#include "mem.h"
#include "materials.h"

/*********Constant Declarations*************************************/
#define c_alph 54.0 /* Units: 1/s */
#define N_avog 6.022045e+26 /* 1/kmol */
#define c_bet 1.0 /* no units */
#define rho_soot 1800.0 /* kg/m3 */
#define T_alph 21000.0 /* activation temperature of soot inception in K */
#define N_norm 1.0e+15 /* Moss-Brookes model: normalizing parameter */
#define l 1.0 /* l indicates the particle nucleation sensitivity to Pressure: defined as 1.0 for now */
#define PI 3.14159265358979324 /* Pi as a constant...alternatively pi=4.0*atan(1.0) */
#define SpNo 20 /* The number of species in the mechanism file: should be adjusted according to the mechanism */
#define Species 22 /* This is the index for the species of interest (C2H2 in this case) */

#define Mp 144.0 /* mass of an incipent soot particle. here taken for C12 */
#define c_gama 11700.0 /* surface growth rate scaling factor */
#define T_gama 12100.0 /* activation temperature of surface growth rate */
#define m 1.0
#define n 1.0
#define c_oxid 0.015
#define c_omega 105.8125
#define eta_coll 0.04
/*********End Constant Declarations*********************************/

DEFINE_SOURCE(n_sourceterm, c, ct, dS, eqn)
{
/*********Variable Declarations*************************************/
double dNdT, dp, X_C2H2, X_OH, T, P, rho_cell, M, N, Ysoot, bNuc, R;
double x[SpNo], y[SpNo]; /* x is the array for species mole fractions and y is the array for mass fractions */
int id_c2h2;
int id_oh
/*********End Variable Declarations*********************************/

/*********Variable Assignments**************************************/
Material *mat = THREAD_MATERIAL(ct);
id_c2h2 = mixture_specie_index(mat, "c2h2");
id_oh = mixture_species_index(mat, "oh");
Pdf_XY(c, ct, x, y); /* Calling the species mole and mass fractions for this cell */
X_C2H2 = x[id_c2h2]; /* arbitrarily defined for now */
X_OH = x[id_oh];

T = C_T(c, ct); /* Temperature at the cell */
if (c == 400)
Message("Temp is %g\n, species %", T);

P = C_P(c, ct); /* Cell Presdsure */
if (c == 400)
Message("Press is %g\n, ", P);

rho_cell = C_R(c, ct); /* Cell average Density */

R = UNIVERSAL_GAS_CONSTANT; /* Universal gas constant is called with the built-in Fluent Macro */

Ysoot = C_UDSI(c, ct, 0); /* Calling soot mass fraction from m_sourceterm scalar */
if (c == 400)
Message("Ysoot is %g\n, ", Ysoot);

bNuc = C_UDSI(c, ct, 1); /* Calling soot number density from n_sourceterm scalar */
if (c == 400)
Message("bNuc is %g\n, ", bNuc);
/**********End Variable Assignments*********************************/

/**********Start Calculations************************************** */
M = rho_cell * Ysoot;
N = bNuc * rho_cell * N_norm;

dp = pow(((6.0 * M)/(PI * N * rho_soot)), (1.0/3.0));

dNdT = c_alph * N_avog * pow(((X_C2H2 * P)/(R * T)), l) * exp(-1.0 * T_alph / T) - c_bet * pow(((24.0 * R * T) / ( rho_soot * N_avog)), 0.5) * sqrt(dp) * pow(N, 2);
if (c == 400)

dMdT = Mp * C_alph * pow(((X_C2H2 * P)/(R * T)), l) * exp(-1.0 * T_alph / T) + c_gama * pow(((X_C2H2 * P)/(R * T)), m) * (exp(-1.0 * T_gama / T) * (pow((pi * N), 1.0/3.0)) * (pow((6 * M)/rho_soot), 2.0/3.0)) - c_oxid * c_omega * eta_coll

* ((X_OH * P) / (R * T)) * sqrt(T) * pow((pi * N), 1.0/3.0) * pow((6*M/rho_soot), 2.0/3.0)

Message("dNdT is %g\n, ", dNdT);
/**********End of Calculations**************************************/

return (dNdT / N_norm);
return (dMdT);

}

pghoseju June 24, 2013 06:47

soot model
 
Dear kaveh.
I am giving my uds source code for soot mass fraction. Another code for nuclei is also there but I am not giving that, because both are similar.
But still error is showing. can you plz help me.

#include "udf.h"
#include "pdf_props.h"
#include "pdf_table.h"
#include "mem.h"
#include "materials.h"
#include "sg_udms.h"

/*********Constant Declarations*************************************/

#define Mp 144.0 /* mass of an incipent soot particle. here taken for C12 */
#define c_alph 54.0 /* Units: 1/s */
#define T_alph 21000.0 /* activation temperature of soot inception in K */
#define c_gama 11700.0 /* surface growth rate scaling factor */
#define T_gama 12100.0 /* activation temperature of surface growth rate */
#define c_oxid 0.015 /* oxidation rate scaling parameter */
#define c_omega 105.8125 /* oxidation model constant */
#define eta_coll 0.04 /* collisional efficiency parameter */
#define rho_soot 1800.0 /* kg/m3 */
#define l 1.0 /* indicates the particle nucleation sensitivity to Pressure */
#define m 1.0 /* indicates the particle surface growth sensitivity to Pressure */
#define n 1.0 /* indicates the particle surface growth sensitivity to soot mass concentration */
#define PI 3.14159265358979324 /* Pi as a constant...alternatively pi=4.0*atan(1.0) */


/*********End Constant Declarations*********************************/

DEFINE_SOURCE(m_sourceterm, c, t, dS, eqn)
{
/*********Variable Declarations*************************************/
double dMdT, X_C2H2, X_OH, T, P, rho_cell, M, N, Ysoot, bNuc, R;

int ic2h2;
int ioh;
/*********End Variable Declarations*********************************/

/*********Variable Assignments**************************************/
Material *m = THREAD_MATERIAL(t);
ic2h2 = mixture_specie_index(m, "c2h2");
ioh = mixture_species_index(m, "oh");

Pdf_XY(c, t, x, y); /* Calling the species mole and mass fractions for this cell */
X_C2H2 = xi[ic2h2];
X_OH = xi[ioh];

T = C_T(c, t); /* Temperature at the cell */
if (c == 400)
Message("Temp is %g\n, species %", T);

P = C_P(c, t); /* Cell Pressure */
if (c == 400)
Message("Press is %g\n, ", P);

rho_cell = C_R(c, t); /* Cell average Density */

R = UNIVERSAL_GAS_CONSTANT; /* Universal gas constant is called with the built-in Fluent Macro */

Ysoot = C_UDSI(c, t, 0); /* Calling soot mass fraction from m_sourceterm scalar */
if (c == 400)
Message("Ysoot is %g\n, ", Ysoot);

bNuc = C_UDSI(c, t, 1); /* Calling soot number density from n_sourceterm scalar */
if (c == 400)
Message("bNuc is %g\n, ", bNuc);
/**********End Variable Assignments*********************************/

/**********Start Calculations************************************** */
M = rho_cell * Ysoot;
N = bNuc * rho_cell * N_norm;

dMdT = Mp * C_alph * pow(((X_C2H2 * P)/(R * T)), l) * exp(-1.0 * T_alph / T) + c_gama * pow(((X_C2H2 * P)/(R * T)), m) * (exp(-1.0 * T_gama / T) * (pow((pi * N), 1.0/3.0)) * (pow((6 * M)/rho_soot), 2.0/3.0)) - c_oxid * c_omega * eta_coll * ((X_OH * P) / (R * T)) * sqrt(T) * pow((pi * N), 1.0/3.0) * pow((6*M/rho_soot), 2.0/3.0)

Message("dMdT is %g\n, ", dMdT);
/**********End of Calculations**************************************/

return (dMdT);

}

doni October 29, 2013 04:57

hi pghoseju
i cant undrestand what is UDSI , im new in udf , i have to define udf for UDSI? can u help me?


All times are GMT -4. The time now is 06:55.