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/)
-   -   Segmentation violation error...why??? (https://www.cfd-online.com/Forums/fluent-udf/92221-segmentation-violation-error-why.html)

be89 September 6, 2011 16:01

Segmentation violation error...why???
 
I wrote this UDF for the simulation of water vapor condensation as a mass transfer in a multiphase problem.
I compiled the UDF in Fluent, but when I try to run the calculation I receive a "segmentation violation error". I think that the error comes from the line "w_sat=.....", but I don't know how to correct it.
The UDF is this:
#include "udf.h"
#include "prop.h" /* for function: Saturation_Pressure() (of water) */

real H2O_Saturation_Pressure(real T)
{
real ratio, aTmTp;
aTmTp = .01 * (T - 338.15);
ratio = (647.286/T - 1.) *
(-7.419242 + aTmTp*(.29721 +
aTmTp*(-.1155286 +
aTmTp*(8.685635e-3 +
aTmTp*(1.094098e-3 +
aTmTp*(-4.39993e-3 +
aTmTp*(2.520658e-3 -
aTmTp*5.218684e-4)))))));
return (22.089e6 * exp(MIN(ratio,35.)));
}

DEFINE_MASS_TRANSFER(vap_condensation,c,t,from_pha se_index,from_species_index,to_phase_index,to_spec ies_index)
{
real m_lg;
real T_temp=C_T(c,t);
int i;
Material *m=THREAD_MATERIAL(t), *sp;
real x_h2o, x_sat, w_sat; /* w=mv/ma; x=mv/(ma+mv) */
real p=101325.;
if(MATERIAL_TYPE(m)==MATERIAL_MIXTURE)
{
mixture_species_loop(m,sp,i)
{
if (0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"h2o") || (0 == strcmp(MIXTURE_SPECIE_NAME(m,i),"H2O")))
{
x_h2o = C_YI(c,t,i);
}
}
}

w_sat=.622*H2O_Saturation_Pressure(T_temp)/(p-H2O_Saturation_Pressure(T_temp));

x_sat=w_sat/(1+w_sat);
m_lg = 0.;

if (x_h2o > x_sat)
{
m_lg=-(x_h2o-x_sat)*C_R(c,t);
}
return m_lg;
}


All times are GMT -4. The time now is 18:19.