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/)
-   -   UDF-Specific heat as a function of Temperature (https://www.cfd-online.com/Forums/fluent-udf/117139-udf-specific-heat-function-temperature.html)

ahvz May 2, 2013 21:35

UDF-Specific heat as a function of Temperature
 
1 Attachment(s)
Hi,

I am trying to write a UDF for the Specific heat (Cp) as a function of Temperature.
I used "curve fitting" technique to obtain the formula.

my First question, am I not sure if I put the below formula correctly (the original one is attached) ?

Cp=4.3568+27.57838*exp(-0.5*((K-19.08514)/2.00369)^2)

Second question, why the code is not interrupting ("float" error)? please guide me if through the code is right or not.

As its for a transient analysis so, I expected to call the temperature from current temperature.


#include "udf.h"
DEFINE_SPECIFIC_HEAT(my_user_cp,c,K,thread, position)
{
real cp; /*specific heat as a function of temperature*/
real K; /* Temperature*/


face_t f;
begin_f_loop(f,thread)
{
F_CENTROID(K,f,thread);
Cp = CURRENT_TEMPERATURE;

Cp=4.3568+27.57838*exp(-0.5*((K-19.08514)/2.00369)^2)

F_PROFILE(C, K, position) =Cp;
}
end_f_loop(C,K)
}


regards,

blackmask May 2, 2013 22:28

As far as I can recall, the binary operator "^" in C means BIT-AND and it expects both operand to be integer, so you should replace
(...)^2
to
pow( (...), 2.0 )
when you need to calculate the power of a float number.

Correct me if I am wrong

ahvz May 3, 2013 05:27

Thank you for reply,

Actually, I recived this error for the formula :

pow: too few arguments supplied (argument 2)

which its :

cp=4.3568+27.57838*exp(-0.5*(pow((T-19.08514)/2.00369),2.0)

blackmask May 3, 2013 06:07

Your ")" does not match "("

cp=4.3568+27.57838*exp(-0.5*( pow( (T-19.08514)/2.00369,2.0) ) );

ahvz May 3, 2013 06:13

thank you! the formula's error now solved.

but still have error "invalid type for binary expression: int + pointer to float" it belongs to the line after formula I guess.


#include "udf.h"
DEFINE_SPECIFIC_HEAT(my_user_cp,c,T,thread, position)
{
real cp; /*specific heat as a function of temperature*/
real T; /* Temperature*/


face_t f;
begin_f_loop(f,thread)
{


cp=4.3568+27.57838*exp(-0.5*( pow( (T-19.08514)/2.00369,2.0) ) );


F_CENTROID(T,f,thread);
y = CURRENT_TEMPERATURE;
F_PROFILE(f, thread, position) =cp;
}
end_f_loop(C,T)
}


regards,

blackmask May 3, 2013 07:23

Try this one, adapted from the fluent udf manual.

#include "udf.h"
DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi)
{
real cp=4.3568+27.57838*exp(-0.5*( pow( (T-19.08514)/2.00369,2.0) ) );
*h = cp*(T-Tref);
return cp;
}

ahvz May 3, 2013 07:32

thank you very much,

It was hooked to the Fluent.

As I have two UDF file, Is it possible to hook two UDF for analysis at same time ?

it seems impossible as I tryied to do!

what I should to do ?


regards,

blackmask May 3, 2013 07:50

I think at least you can concatenate the two files into a single file.

ahvz May 3, 2013 09:25

I did and its work very well. I just paste the second code at the end of first code. let see the results...

many thanks,

ahvz May 4, 2013 08:14

would you please tell me how to change inital temperature value in Fluent ? and in C program code as UDF file ?

as I can see the initial temperature (at step 0) for the model, its 26 C by default by Fluent. how can I change it ? where is the option menu in Fluent ? or in this such a case that in transient analysis I must define at UDF file which its already interrupted to the Fluent ?

Note: when I am using hybrid initialization!
regards,

blackmask May 4, 2013 08:47

You can use DEFINE_INIT to specify the initial values.

ahvz May 4, 2013 09:11

Done!

it works very well, thank you very much,

best regards,

ghost82 October 19, 2014 09:48

Quote:

Originally Posted by blackmask (Post 424938)
Try this one, adapted from the fluent udf manual.

#include "udf.h"
DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi)
{
real cp=4.3568+27.57838*exp(-0.5*( pow( (T-19.08514)/2.00369,2.0) ) );
*h = cp*(T-Tref);
return cp;
}

It's an old post, but take care that the equation for enthalpy is wrong, since it's valid for constant cp(f(T)).
Correct equation is integral of cp.

thanhho May 28, 2015 18:53

Quote:

Originally Posted by ghost82 (Post 515039)
It's an old post, but take care that the equation for enthalpy is wrong, since it's valid for constant cp(f(T)).
Correct equation is integral of cp.

In which case, how would one write the integral of cp to correctly represent the enthalpy in UDF?

rampal February 26, 2016 05:14

udf for specific heat (cp) of water
 
Dear friends, I have to write udf for specific heat of water as function of temperature. I have written according to DEFINE_PROPERTY macro, but it is not working. Specific heat of water as a function of temperature (in deg Celsius) is as follows:
cp = 4.2174356 - 0.0056181625*temp + 0.0012992528*pow(temp,1.5) - 0.00011535353*pow(temp,2.0) + 4.14964*pow(10.0,-6.0)*pow(temp,2.5)

I have seen in UDF manual DEFINE_SPECIFIC_HEAT, but don't understand how can I write for above defined function. Please help me.

Thanks in advance:)


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