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/)
-   -   property UDF compiles but runs with error (https://www.cfd-online.com/Forums/fluent-udf/201137-property-udf-compiles-but-runs-error.html)

Sam_1913 April 23, 2018 10:18

property UDF compiles but runs with error
 
1 Attachment(s)
hi guys,

i used a couple of UDFs to define viscosity, thermal conductivity, heat capacity and density of water as function of temperature...compilation wasnt a problem with visual studio express 15 (Fluent 17.2) yet after running the simulation, getting the error '' temperature limited to 1 on 12000 cells on zone 7 in domain 1'' for example...

when these functions are implemented directly in Fluent material database as piecewise polynomial, no such messages appear in TUI..

these are relatively simply polynomial fucntion UDFs...can anyone please point out what should i change regarding the setup :confused:...thanks in advance

Sam_1913 April 23, 2018 10:21

these are the udfs....


#include "udf.h"

DEFINE_SPECIFIC_HEAT(sfc_heat, T, Tref, h, yi)
{
real cp;

if (T > 700.)
{
cp = 14000;
*h = cp * (T - Tref);
}

else if (T > 678.2)
{
cp = (-12066.64 + 35. * T - 0.0253 * pow(T,2.)) * 1000;
*h = (-12066.64 * (T - Tref) + 17.5 * (T * T - Tref * Tref) - 0.00843 * (pow(T,3.) - pow(Tref,3.))) * 1000;
}

else if (T > 614.8)
{
cp = (-10342.5 + 49.32 * T - 0.0784 * pow(T,2.) + 4.16e-5 * pow(T,3.)) * 1000;
*h = (-10342.5 * (T - Tref) + 24.66 * (T * T - Tref * Tref) - 0.02613 * (pow(T,3.) - pow(Tref,3.)) + 1.04e-5 * (pow(T,4.) - pow(Tref,4.))) * 1000;
}

else if (T > 273.)
{
cp = (-0.5112 + 0.0371 * T - 9.935e-5 * pow(T,2.) + 9.0e-8 * pow(T,3.)) * 1000;
*h = (-0.5112 * (T - Tref) + 0.0189 * (T * T - Tref * Tref) - 3.312e-5 * (pow(T,3.) - pow(Tref,3.)) + 2.25e-8 * (pow(T,4.) - pow(Tref,4.))) * 1000;
}

else
{
cp = 4000;
*h = cp * (T - Tref);
}

return cp;
}


DEFINE_PROPERTY(therm_cond,c,t)
{
real ktc;
real T = C_T(c,t);

if (T > 700.)
ktc = 240.1e-3;

else if (T > 601.1)
ktc = (59597. - 282. * T + 0.45 * pow(T,2.) - 2.43e-4 * pow(T,3.)) * 1.e-3;

else if (T > 273.)
ktc = (-617.55 + 7.37 * T - 0.0123 * pow(T,2.) + 5.7e-6 * pow(T,3.)) * 1.e-3;

else
ktc = 560.1e-3;

return ktc;
}

DEFINE_PROPERTY(density,c,t)
{
real rho;
real T = C_T(c,t);

if (T > 700.)
rho = 270.;

else if (T > 585.9)
rho = 62651. - 303.4 * T + 0.5 * pow(T,2.) - 2.75e-4 * pow(T,3.);

else if (T > 273.)
rho = 967.6 + 0.61 * T - 0.0014 * pow(T,2.) - 5.82e-7 * pow(T,3.);

else
rho = 1020.;

return rho;
}

DEFINE_PROPERTY(viscosity,c,t)
{
real mu;
real T = C_T(c,t);


if (T > 700.)
mu = 37.1e-6;

else if (T > 355.6)
mu = (3436.2 - 16.8 * T + 0.029 * pow(T,2.) - 1.65e-5 * pow(T,3.)) * 1.e-6;

else if (T > 273.)
mu = (122974. - 1074.9 * T + 3.16 * pow(T,2.) - 0.003 * pow(T,3.)) * 1.e-6;

else
mu = 1750.1e-6;

return mu;
}

obscureed April 23, 2018 11:08

Hi Sam_1913,

One important issue is that you have not integrated the piecewise polynomial in order to reach h -- for each temperature interval, you have integrated that interval's polynomial. To get from Tref to 690K, for example, you should not integrate "cp = (-12066.64 + ...) * 1000;" all the way -- first you integrate "cp = (-0.5112 +...) * 1000;" from Tref to 614.8, etc. Since your polynomials go to absurd values outside their chosen ranges (because that's what polynomials always do), I would expect that this is quite a big problem. Maybe try it in a spreadsheet. You can rely on Tref being 298.15K unless you change it, and I would not advise changing it.

While you're trying a spreadsheet, see whether you are happy with the discontinuities in Cp (and maybe others) across your intervals. When I tried your polynomials, I got a jump from 5.66e3 to 1.30e4 at T=614.8K, for example. I might have made a mistake, or these might be intentional, but big jumps won't help stability. This is a much smaller problem than integrating h. Possibly you have created beautifully matching polynomials, but you are quoting the coefficients with low precision -- this is a common mistake.

Good luck!
Ed

Sam_1913 April 24, 2018 09:52

Quote:

Originally Posted by obscureed (Post 689958)
Hi Sam_1913,

One important issue is that you have not integrated the piecewise polynomial in order to reach h -- for each temperature interval, you have integrated that interval's polynomial. To get from Tref to 690K, for example, you should not integrate "cp = (-12066.64 + ...) * 1000;" all the way -- first you integrate "cp = (-0.5112 +...) * 1000;" from Tref to 614.8, etc. Since your polynomials go to absurd values outside their chosen ranges (because that's what polynomials always do), I would expect that this is quite a big problem. Maybe try it in a spreadsheet. You can rely on Tref being 298.15K unless you change it, and I would not advise changing it.

While you're trying a spreadsheet, see whether you are happy with the discontinuities in Cp (and maybe others) across your intervals. When I tried your polynomials, I got a jump from 5.66e3 to 1.30e4 at T=614.8K, for example. I might have made a mistake, or these might be intentional, but big jumps won't help stability. This is a much smaller problem than integrating h. Possibly you have created beautifully matching polynomials, but you are quoting the coefficients with low precision -- this is a common mistake.

Good luck!
Ed

Hi Ed, thanks a lot for your input...i tried integrating the cp as you said and the problem is now seemed to be solved and you were also absolutely right about me quoting the coefficients with low precision..

Thanks once again :)

Regards
Sam


All times are GMT -4. The time now is 01:17.