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

Annotation of /trunk/models/johnpye/fprops/test/ph.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2680 - (hide annotations) (download) (as text)
Mon Jan 28 06:30:25 2013 UTC (9 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 2693 byte(s)
Working on problem with solve_ph. Could be that one of the deriv routines is wrong in the saturation region?
1 jpye 2662
2     #include "../fluids.h"
3     #include "../fprops.h"
4     #include "../solve_ph.h"
5 jpye 2664 #include "../refstate.h"
6    
7 jpye 2662 #include <assert.h>
8     #include <math.h>
9    
10     #include "../color.h"
11    
12     #define MSG(FMT, ...) \
13     color_on(stderr,ASC_FG_BRIGHTRED);\
14     fprintf(stderr,"%s:%d: ",__FILE__,__LINE__);\
15     color_on(stderr,ASC_FG_BRIGHTBLUE);\
16     fprintf(stderr,"%s: ",__func__);\
17     color_off(stderr);\
18     fprintf(stderr,FMT "\n",##__VA_ARGS__)
19    
20     #define ERRMSG(STR,...) \
21     color_on(stderr,ASC_FG_BRIGHTRED);\
22     fprintf(stderr,"ERROR:");\
23     color_off(stderr);\
24     fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)
25    
26 jpye 2664 #define TOL_T 1e-8
27 jpye 2662 #define TOL_RHO 1e-3
28    
29    
30     int main(void){
31 jpye 2664 const PureFluid *P;
32 jpye 2680 FpropsError err = FPROPS_NO_ERROR;
33 jpye 2662 FluidState S;
34     double T0, rho0, p, h, T, rho;
35    
36     #define TEST_PH(T1,RHO1) \
37 jpye 2664 err = FPROPS_NO_ERROR;\
38     /*MSG("TEST_PH(T1=%f, RHO1=%f)",T1,RHO1);*/ \
39 jpye 2662 T0 = T1; \
40     rho0 = RHO1; \
41 jpye 2664 /*MSG("setting T,rho");*/\
42 jpye 2662 S = fprops_set_Trho(T0,rho0,P,&err); \
43     assert(!err); \
44 jpye 2664 /*MSG("calc p");*/\
45 jpye 2662 p = fprops_p(S,&err); \
46     assert(!err); \
47 jpye 2664 /*MSG("calc h");*/\
48 jpye 2662 h = fprops_h(S,&err); \
49     assert(!err); \
50 jpye 2664 /*MSG("solving ph");*/\
51 jpye 2662 fprops_solve_ph(p,h,&T,&rho,0,P,&err); \
52     assert(!err); \
53 jpye 2664 MSG("T err: %f",(T-T0));\
54     MSG("rho err: %f",(rho-rho0));\
55 jpye 2662 assert(fabs(T - T0) < TOL_T); \
56     assert(fabs(rho - rho0) < TOL_RHO);
57    
58 jpye 2680 P = fprops_fluid("isohexane","pengrob","J. Chem. Eng. Data, 51");
59     assert(P);
60 jpye 2668
61 jpye 2680 TEST_PH(128.4465, 1.);
62     TEST_PH(1.284465e+02, 1/1.693087e-03);
63     TEST_PH(1.284465e+02, 1/2.232836e-03);
64     TEST_PH(1.284465e+02, 1/2.944654e-03);
65     TEST_PH(1.284465e+02, 1/3.883396e-03);
66     TEST_PH(1.284465e+02, 1/5.121405e-03);
67    
68 jpye 2668 P = fprops_fluid("isohexane","helmholtz","J. Chem. Eng. Data, 51");
69     assert(P);
70 jpye 2680
71     TEST_PH(119.6, 807.530551164909);
72 jpye 2668
73 jpye 2664 P = fprops_fluid("water","helmholtz",NULL);
74     assert(P);
75    
76     TEST_PH(314.4054538268115, 999.7897902747587);
77    
78 jpye 2662 TEST_PH(4.278618181818e+02, 3.591421624513e-03);
79     TEST_PH(3.453541818182e+02, 6.899880592960e-03);
80     TEST_PH(7.166385454545e+02, 6.899880592960e-03);
81     TEST_PH(7.372654545455e+02, 4.092431601778e-03);
82    
83     TEST_PH(304.10372142680086, 999.7863801065582);
84     TEST_PH(283.4886584572104, 999.7900620473787);
85     TEST_PH(293.8028752316878, 999.7858245521049);
86    
87 jpye 2664 P = fprops_fluid("water","pengrob","IAPWS");
88     ReferenceState R = {FPROPS_REF_TPF};
89     fprops_set_reference_state(P,&R);
90     MSG("Testing '%s' (type '%d', source '%s')", P->name, P->type, P->source);
91     assert(P);
92     err = FPROPS_NO_ERROR;
93 jpye 2662
94 jpye 2664 TEST_PH(2.731600000000e+02, 8.618514819566e+02);
95     MSG("p = %f",p);
96     MSG("h = %f",h);
97    
98 jpye 2680 /* all done? report success */
99 jpye 2662 fprintf(stderr,"\n");
100     color_on(stderr,ASC_FG_BRIGHTGREEN);
101     fprintf(stderr,"SUCCESS (%s)",__FILE__);
102     color_off(stderr);
103     fprintf(stderr,"\n");
104     return 0;
105     }
106    

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