CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF Access violation (http://www.cfd-online.com/Forums/fluent/87289-udf-access-violation.html)

therandomestname April 15, 2011 17:31

UDF Access violation
 
Hello all:

This is my first time using UDFs. I wrote a UDF for a volumetric reaction rate. It compiles, but gives me an access violation every time I try to run the simulation with it hooked in. It is pretty basic, the only tricky thing about it is that the rate formula uses the mole fraction, X, rather than the mass fraction. Does an access violation mean that there is a problem with the way the UDF is written or could it be a computer problem?

Here is the code:

#include"udf.h"
DEFINE_VR_RATE(co_combust,c,t,r,mw,yi,rr,rr_t)
{
real mw_mix = 0;
real yx = 0;
real mwx = 0;
real xfuel = 0;
real xo2 = 0;
real mole_con_fuel = 0;
real mole_con_o2 = 0;
int i = 0;
real *rate = 0;
for (i = 0; i < r->n_reactants; i++)
{
yx = yi[r->reactant[i]];
mwx = mw[r->reactant[i]];
mw_mix = mw_mix + yx * mwx;
}
xfuel = yi[r->reactant[0]]*mw_mix / mw[r->reactant[0]];
xo2 = yi[r->reactant[1]]*mw_mix / mw[r->reactant[1]];
mole_con_fuel = xfuel * C_P(c,t) / (UNIVERSAL_GAS_CONSTANT * C_T((c,t));
mole_con_o2 = xo2 * C_P(c,t) / (UNIVERSAL_GAS_CONSTANT * C_T(c,t));
*rate = -59.8 * pow(C_P(c,t), 0.3) * C_T(c,t) * mw[r->reactant[0]] * pow(xfuel, 0.5) * xo2 * exp( -12200 / C_T(c,t));
}


All times are GMT -4. The time now is 02:05.