CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   User Defined Property-Density (http://www.cfd-online.com/Forums/fluent-udf/90485-user-defined-property-density.html)

bmatsuo July 11, 2011 23:13

User Defined Property-Density
 
Hello,

I am trying to create a user defined density, which is temperature dependent. Basically, I have the values for the density at different temperatures and am using the UDF to interpolate the temperature in the cell to give the value for what the density should be. Below is the UDF that I have written. FLUENT will compile the UDF, but when I try to set the reference values or initialize the solution I get the following error:

Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: #f

Here is what I have for the UDF:

#include "udf.h"

int ctr; /*loop counter*/

double temp_data[201] = {280.00, 280.25, 280.50, 280.75, 281.00, 281.25,
281.50, 281.75, 282.00, 282.25, 282.50,282.75,
...(I'll omit the middle values), 330.00};
double dens_data[201] = {971.0105, 969.3090, 967.6075, 965.8965, 964.1615,
962.4265, 960.6770, 958.9135, 957.1450, 955.3620,
...(Omitting middle values), 197.7790};
DEFINE_PROPERTY(cell_density, cell, thread)
{
double rho; /* kg/m^3 */
double rho_1; /* kg/m^3 */
double rho_2; /* kg/m^3 */
double temp_1; /* Kelvin */
double temp_2; /* Kelvin */
double temp = C_T(cell, thread);
for (ctr=0; ctr < 210; ctr++)
{
if (temp >= temp_data[ctr] && temp <= temp_data[ctr+1])
{
temp_1 = temp_data[ctr];
temp_2 = temp_data[ctr+1];
rho_1 = dens_data[ctr];
rho_1 = dens_data[ctr+1];
rho = rho_1+(temp-temp_1)*(rho_2-rho_1)/(temp_2-temp_1);
}
else if (temp < temp_data[1])
{
rho = 971.011;
}
else if (temp > temp_data[210])
{
rho = 197.779;
}
else
break;
}
return rho;
}

Thank you in advance for your help!

bmatsuo July 11, 2011 23:17

Also, the flow is at a constant pressure throughout the whole system.


All times are GMT -4. The time now is 00:41.