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/)
-   -   Verification of UDF - getting errors (https://www.cfd-online.com/Forums/fluent-udf/132722-verification-udf-getting-errors.html)

kkondaveeti April 5, 2014 03:25

Verification of UDF - getting errors
 
Hi,

I am a beginner in wirting UDF's, Currently I need to write UDF for vatiation of Specific heat based on pressure and temperature. In a nutshell, Cp will be calculated at P = 1atm and at P = 10atm. Now, a log interpolation is used to find the Cp value in the interim pressure points. Here is the UDF., while interpreting, I an getting errors like "function returning float returns double" "coeffCp1: argument 1 type mismatch (pointer to double instead of pointer to float)" Please help me
Thank you

/*Make sure the units of pressure is Atm, Cp in cal/g-k and temp in K*/
#include <stdio.h>
#include "udf.h"
/* Specific heat for 1 atmosphere */
void coeffCp1(double *Acp, double *Bcp, double *Ccp, double *Dcp, double *Ecp, double input_temp)
{
if (input_temp < 500)
{
(*Acp) = 0; (*Bcp) = 0; (*Ccp) = 0; (*Dcp) = 0; (*Ecp) = 0.24;
}
else if (input_temp >= 500 && input_temp < 1750)
{
(*Acp) = 0.164992; (*Bcp) = 0.156336e1; (*Ccp) = 0.552429e1; (*Dcp) = 0.879873e1; (*Ecp) = 0.412806e1;
}
else if (input_temp >= 1750 && input_temp < 3250)
{
(*Acp) = -0.830572e1; (*Bcp) = -0.483112e2; (*Ccp) = -0.101598e3; (*Dcp) = -0.897230e2; (*Ecp) = -0.280651e2;
}
else if (input_temp >= 3250 && input_temp < 4750)
{
(*Acp) = 0.848335e2; (*Bcp) = 0.361629e3; (*Ccp) = 0.561712e3; (*Dcp) = 0.376565e3; (*Ecp) = 0.915792e2;
}
else if (input_temp >= 4750 && input_temp < 7750)
{
(*Acp) = -0.945467e1; (*Bcp) = -0.640807e2; (*Ccp) = -0.893740e2; (*Dcp) = -0.403342e2; (*Ecp) = -0.458728e1;
}
else if (input_temp >= 7750 && input_temp < 11750)
{
(*Acp) = -0.153176e3; (*Bcp) = -0.476111e2; (*Ccp) = 0.217674e2; (*Dcp) = 0.314736e1; (*Ecp) = 0.922570e-1;
}
else if (input_temp >= 11750 && input_temp < 20500)
{
(*Acp) = 0.975058e2; (*Bcp) = -0.158721e3; (*Ccp) = 0.753693e2; (*Dcp) = -0.936668e1; (*Ecp) = 0.987515e0;
}
else
{
(*Acp) = -0.473648e2; (*Bcp) = 0.818135e2; (*Ccp) = 0.169726e2; (*Dcp) = -0.836769e2; (*Ecp) = 0.339060e2;
}

}



/* Specific heat for 10 atmosphere */
void coeffCp10(double *Acp, double *Bcp, double *Ccp, double *Dcp, double *Ecp, double input_temp)
{
if (input_temp < 500)
{
(*Acp) = 0; (*Bcp) = 0; (*Ccp) = 0; (*Dcp) = 0; (*Ecp) = 0.24;
}
else if (input_temp >= 500 && input_temp < 1750)
{
(*Acp) = 0.111751; (*Bcp) = 0.105018e1; (*Ccp) = 0.368846e1; (*Dcp) = 0.591074e1; (*Ecp) = 0.244269e1;
}
else if (input_temp >= 1750 && input_temp < 3250)
{
(*Acp) = 0.252675; (*Bcp) = 0.341131e1; (*Ccp) = 0.131529e2; (*Dcp) = 0.203259e2; (*Ecp) = 0.100197e2;
}
else if (input_temp >= 3250 && input_temp < 5750)
{
(*Acp) = 0.450386e2; (*Bcp) = 0.167261e3; (*Ccp) = 0.224426e3; (*Dcp) = 0.128924e3; (*Ecp) = 0.263694e2;
}
else if (input_temp >= 5750 && input_temp < 9250)
{
(*Acp) = 0.231376e2; (*Bcp) = -0.104484e1; (*Ccp) = -0.271807e2; (*Dcp) = -0.102436e2; (*Ecp) = -0.333185e-1;
}
else if (input_temp >= 9250 && input_temp < 13750)
{
(*Acp) = -0.799940e2; (*Bcp) = 0.170114e2; (*Ccp) = 0.187072e2; (*Dcp) = -0.350311e1; (*Ecp) = 0.184168e0;
}
else if (input_temp >= 13750 && input_temp < 22500)
{
(*Acp) = 0.491689e2; (*Bcp) = -0.116351e3; (*Ccp) = 0.889977e2; (*Dcp) = -0.242638e2; (*Ecp) = 0.263659e1;
}
else
{
(*Acp) = -0.253231e3; (*Bcp) = 0.955890e3; (*Ccp) = -0.132457e4; (*Dcp) = 0.798459e3; (*Ecp) = -0.175990e3;
}
}

double compute_cp(double input_temp, double input_pressure)
{
double Acp, Bcp, Ccp, Dcp, Ecp;
double Cp1, Cp10;
double P2 = 1.01325e7, P1=1.01325e5;
double Y = input_temp/1000.0;

coeffCp1(&Acp,&Bcp,&Ccp,&Dcp,&Ecp,input_temp);
Cp1 = exp(Acp*Y*Y*Y*Y + Bcp*Y*Y*Y + Ccp*Y*Y + Dcp*Y + Ecp);
coeffCp10(&Acp,&Bcp,&Ccp,&Dcp,&Ecp,input_temp);
Cp10 = exp(Acp*Y*Y*Y*Y + Bcp*Y*Y*Y + Ccp*Y*Y + Dcp*Y + Ecp);

if (input_pressure < 1 && input_pressure > 1.0e7)
{
printf("Invalid interpolation range for pressure in UDF \n");
}
/* Interpolation w. r. t Pressure for input pressure */

return exp((log(Cp10)-log(Cp1))/(log(P2)-log(P1))*(log(input_pressure)-log(P1))+log(Cp1));
}


DEFINE_PROPERTY(cell_specificheat, c, t)
{
double cp;
double input_temp = C_T(c, t);
double input_pressure = C_P(c, t)+op_pres;

if (input_temp > 288.15 && input_temp < 500.0 )
{
cp = 0.24;
}
else
{
cp = compute_cp(input_temp,input_pressure);
}

return cp;
}



upeksa April 10, 2014 10:02

You should not use the DEFINE_PROPERTY macro for the specific heat.
Use the DEFINE_SPECIFIC_HEAT macro instead.

Look it up in your UDF manual.

Cheers

kkondaveeti April 10, 2014 10:05

Hi,

I have checked by using DEFINE_SPECIFIC_HEAT as well, but getting the same error

Thank you

upeksa April 11, 2014 13:25

I have checked your UDF more carefully and I think that your problem is that you have done an incorrect use of pointers.

I am not an expert in the usage of pointers, but a pointer is not a number actually, is a memory direction: so when you have written (*Acp)=0 and so on, I think that you meant "The value of Acp is 0", but what you have programed with the "*" was "The value of Acp is going to be stored in the memory position called 0".

Check that.

Cheers


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