/[ascend]/trunk/models/johnpye/fprops/test_ph.c
ViewVC logotype

Contents of /trunk/models/johnpye/fprops/test_ph.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2481 - (show annotations) (download) (as text)
Thu Jun 23 13:42:16 2011 UTC (11 years ago) by jpye
File MIME type: text/x-csrc
File size: 1732 byte(s)
Small demo of solve_ph functionality in C.
1 /*
2 ASCEND modelling environment
3 Copyright (C) 2004-2011 John Pye
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 *//** @file Small demonstration of the 'solve_ph' routines for FPROPS.
19
20 To build this file, run
21
22 gcc -o test_ph test_ph.c solve_ph.c helmholtz.c ideal.c fluids.c derivs.c sat.c fluids/*.c -lm
23 */
24 #include "solve_ph.h"
25 #include "fluids.h"
26 #include "helmholtz.h"
27 #include <stdio.h>
28
29 int main(void){
30 double p = 1e5;
31 double h = 3500e3;
32 const char *fluid = "water";
33
34 const HelmholtzData *D = fprops_fluid(fluid);
35
36 printf("Solving for (p = %f bar, h = %f kJ/kg) for fluid '%s'\n",p/1e5,h/1e3,fluid);
37
38 int reg = fprops_region_ph(p,h, D);
39
40 printf("Region = %d\n",reg);
41
42 double T = 0,rho = 0;
43 int res = fprops_solve_ph(p,h,&T, &rho, 0, D);
44
45 if(res)printf("ERROR %d! (check solve_ph.c for meaning)\n",res);
46 else printf("Success, solved state.\n");
47
48 printf("Result: T = %f K, rho = %f kg/m3\n",T,rho);
49
50 double p1, h1;
51 p1 = helmholtz_p(T,rho, D);
52 h1 = helmholtz_h(T,rho, D);
53 printf("Double check: p = %f bar\n",p1/1e5);
54 printf("Double check: h = %f kJ/kg\n",h1/1e3);
55
56 return 0;
57 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22