CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Enthalpy Calculation with UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 10, 2022, 06:15
Default Enthalpy Calculation with UDF
  #1
New Member
 
ANTALYA
Join Date: Sep 2017
Posts: 20
Rep Power: 8
erginbayrak is on a distinguished road
Hi, I have formed a UDF file in order to calculate the specific heat and enthalpy for a supercritical C02 flow, which are functions of temperature. Although compiling and running the following file is successful, I am taking some floating point exception errors after some iteration period. I would like to be grateful if you could share your recommendation about my code. Regards,



#include "udf.h"

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

if (300. >= T)
{
cp = 2.256999118844760E-02 * pow(T, 4.) - 2.606618818487370E+01 * pow(T, 3.) + 1.129129898467780E+04 * pow(T, 2.) - 2.174235523392760E+06 * T + 1.570278261279480E+08;
}
if (300. > T >= 306.)
{
cp = 1.147018354719330E+01 * pow(T, 4.) - 1.385519872072390E+04 * pow(T, 3.) + 6.276090044658930E+06 * pow(T, 2.) - 1.263530241490370E+09 * T + 9.539285116131690E+10;
}
if (306. > T >= 307.8)
{
cp = -1.611612838918710E+04 * pow(T, 4.) + 1.978085636985280E+07 * pow(T, 3.) - 9.104578256081260E+09 * pow(T, 2.) + 1.862478067464320E+12 * T - 1.428738938943020E+14;
}
if (307.8 > T >= 310.)
{
cp = -1.576135476848110E+03 * pow(T, 4.) + 1.945866130859760E+06 * pow(T, 3.) - 9.008641337104630E+08 * pow(T, 2.) + 1.853611584329810E+11 * T - 1.430227164258690E+13;
}
if (310. > T >= 320.)
{
cp = 1.770529718817220E+00 * pow(T, 4.) - 2.242833202341920E+03 * pow(T, 3.) + 1.065432793165650E+06 * pow(T, 2.) - 2.249454519629040E+08 * T + 1.781003821884030E+10;
}
if (320. > T)
{
cp = 2.086961941877520E-03 * pow(T, 4.) - 2.851496372954040E+00 * pow(T, 3.) + 1.461548345109060E+03 * pow(T, 2.) - 3.330816449664890E+05 * T + 2.848088978782360E+07;
}
return cp;
}

#include<stdio.h>
float findValueAt(float T)
{
if (300. >= T)

return 2.256999118844760E-02 * pow(T, 4.) - 2.606618818487370E+01 * pow(T, 3.) + 1.129129898467780E+04 * pow(T, 2.) - 2.174235523392760E+06 * T + 1.570278261279480E+08;

if (300. > T >= 306.)

return 1.147018354719330E+01 * pow(T, 4.) - 1.385519872072390E+04 * pow(T, 3.) + 6.276090044658930E+06 * pow(T, 2.) - 1.263530241490370E+09 * T + 9.539285116131690E+10;


if (306. > T >= 307.8)

return -1.611612838918710E+04 * pow(T, 4.) + 1.978085636985280E+07 * pow(T, 3.) - 9.104578256081260E+09 * pow(T, 2.) + 1.862478067464320E+12 * T - 1.428738938943020E+14;

if (307.8 > T >= 310.)

return -1.576135476848110E+03 * pow(T, 4.) + 1.945866130859760E+06 * pow(T, 3.) - 9.008641337104630E+08 * pow(T, 2.) + 1.853611584329810E+11 * T - 1.430227164258690E+13;


if (310. > T >= 320.)

return 1.770529718817220E+00 * pow(T, 4.) - 2.242833202341920E+03 * pow(T, 3.) + 1.065432793165650E+06 * pow(T, 2.) - 2.249454519629040E+08 * T + 1.781003821884030E+10;


if (320. > T)

return 2.086961941877520E-03 * pow(T, 4.) - 2.851496372954040E+00 * pow(T, 3.) + 1.461548345109060E+03 * pow(T, 2.) - 3.330816449664890E+05 * T + 2.848088978782360E+07;
}

int main()
{
int n;
float i,Tref,T,*h=0,k;

k = (T-Tref)/n;
n=1000;
*h = findValueAt(Tref) + findValueAt(T);
for(i=Tref+k;i<T;i=i+k)
*h = *h + 2 * findValueAt(i);
*h = (*h * k)/2;
}
erginbayrak is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
i have a problem with my udf when I give it Run Calculation secorreaz Fluent UDF and Scheme Programming 1 April 3, 2022 22:57
UDF For inlet Velo BC, trouble in soln calculation Siddharth17 Fluent UDF and Scheme Programming 2 March 24, 2022 08:08
Enthalpy Calculation for every media Component MNMK CFX 0 May 3, 2021 03:58
Define_Source UDF for Enthalpy of Dilution jreiter164 Fluent UDF and Scheme Programming 4 March 18, 2015 20:10
my UDF can not calculation? happyrabbit FLUENT 0 October 21, 2010 08:59


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