/[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 2662 - (hide annotations) (download) (as text)
Fri Jan 18 00:34:51 2013 UTC (9 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 1750 byte(s)
Added some C tests for sat and solve_ph routines.
Added parameter 'source' to fprops_fluid, to allow data with a particular source to be specified (optionally). This allows forced testing explicitly of the RPP data even when Helmholtz data is also available.
Tweaked some convergence parameters in sat.c and solve_ph.c to get convergence across broader range of parameters for more fluids (more testing required).
1 jpye 2662
2     #include "../fluids.h"
3     #include "../fprops.h"
4     #include "../solve_ph.h"
5     #include <assert.h>
6     #include <math.h>
7    
8     #include "../color.h"
9    
10     #define MSG(FMT, ...) \
11     color_on(stderr,ASC_FG_BRIGHTRED);\
12     fprintf(stderr,"%s:%d: ",__FILE__,__LINE__);\
13     color_on(stderr,ASC_FG_BRIGHTBLUE);\
14     fprintf(stderr,"%s: ",__func__);\
15     color_off(stderr);\
16     fprintf(stderr,FMT "\n",##__VA_ARGS__)
17    
18     #define ERRMSG(STR,...) \
19     color_on(stderr,ASC_FG_BRIGHTRED);\
20     fprintf(stderr,"ERROR:");\
21     color_off(stderr);\
22     fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)
23    
24     #define TOL_T 1e-3
25     #define TOL_RHO 1e-3
26    
27    
28     int main(void){
29     const PureFluid *P = fprops_fluid("water","helmholtz",NULL);
30     assert(P);
31     FpropsError err = FPROPS_NO_ERROR;
32     FluidState S;
33    
34     double T0, rho0, p, h, T, rho;
35    
36     #define TEST_PH(T1,RHO1) \
37     MSG("TEST_PH(T1=%f, RHO1=%f)",T1,RHO1); \
38     T0 = T1; \
39     rho0 = RHO1; \
40     S = fprops_set_Trho(T0,rho0,P,&err); \
41     assert(!err); \
42     p = fprops_p(S,&err); \
43     assert(!err); \
44     h = fprops_h(S,&err); \
45     assert(!err); \
46     fprops_solve_ph(p,h,&T,&rho,0,P,&err); \
47     assert(!err); \
48     assert(fabs(T - T0) < TOL_T); \
49     assert(fabs(rho - rho0) < TOL_RHO);
50    
51     // low-density saturation cases (I think)
52     TEST_PH(4.278618181818e+02, 3.591421624513e-03);
53     TEST_PH(3.453541818182e+02, 6.899880592960e-03);
54     TEST_PH(7.166385454545e+02, 6.899880592960e-03);
55     TEST_PH(7.372654545455e+02, 4.092431601778e-03);
56    
57     TEST_PH(314.4054538268115, 999.7897902747587);
58    
59     TEST_PH(304.10372142680086, 999.7863801065582);
60    
61     TEST_PH(283.4886584572104, 999.7900620473787);
62    
63     TEST_PH(293.8028752316878, 999.7858245521049);
64    
65    
66     fprintf(stderr,"\n");
67     color_on(stderr,ASC_FG_BRIGHTGREEN);
68     fprintf(stderr,"SUCCESS (%s)",__FILE__);
69     color_off(stderr);
70     fprintf(stderr,"\n");
71     return 0;
72     }
73    

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