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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2662 by jpye, Fri Jan 18 00:34:51 2013 UTC revision 2664 by jpye, Fri Jan 18 06:02:15 2013 UTC
# Line 2  Line 2 
2  #include "../fluids.h"  #include "../fluids.h"
3  #include "../fprops.h"  #include "../fprops.h"
4  #include "../solve_ph.h"  #include "../solve_ph.h"
5    #include "../refstate.h"
6    
7  #include <assert.h>  #include <assert.h>
8  #include <math.h>  #include <math.h>
9    
# Line 21  Line 23 
23      color_off(stderr);\      color_off(stderr);\
24      fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)      fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)
25    
26  #define TOL_T 1e-3  #define TOL_T 1e-8
27  #define TOL_RHO 1e-3  #define TOL_RHO 1e-3
28    
29    
30  int main(void){  int main(void){
31      const PureFluid *P = fprops_fluid("water","helmholtz",NULL);      const PureFluid *P;
32      assert(P);      FpropsError err;
     FpropsError err = FPROPS_NO_ERROR;  
33      FluidState S;      FluidState S;
   
34      double T0, rho0, p, h, T, rho;      double T0, rho0, p, h, T, rho;
35    
36  #define TEST_PH(T1,RHO1) \  #define TEST_PH(T1,RHO1) \
37      MSG("TEST_PH(T1=%f, RHO1=%f)",T1,RHO1); \      err = FPROPS_NO_ERROR;\
38        /*MSG("TEST_PH(T1=%f, RHO1=%f)",T1,RHO1);*/ \
39      T0 = T1; \      T0 = T1; \
40      rho0 = RHO1; \      rho0 = RHO1; \
41        /*MSG("setting T,rho");*/\
42      S = fprops_set_Trho(T0,rho0,P,&err); \      S = fprops_set_Trho(T0,rho0,P,&err); \
43      assert(!err); \      assert(!err); \
44        /*MSG("calc p");*/\
45      p = fprops_p(S,&err); \      p = fprops_p(S,&err); \
46      assert(!err); \      assert(!err); \
47        /*MSG("calc h");*/\
48      h = fprops_h(S,&err); \      h = fprops_h(S,&err); \
49      assert(!err); \      assert(!err); \
50        /*MSG("solving ph");*/\
51      fprops_solve_ph(p,h,&T,&rho,0,P,&err); \      fprops_solve_ph(p,h,&T,&rho,0,P,&err); \
52      assert(!err); \      assert(!err); \
53        MSG("T err: %f",(T-T0));\
54        MSG("rho err: %f",(rho-rho0));\
55      assert(fabs(T - T0) < TOL_T); \      assert(fabs(T - T0) < TOL_T); \
56      assert(fabs(rho - rho0) < TOL_RHO);      assert(fabs(rho - rho0) < TOL_RHO);
57    
58      // low-density saturation cases (I think)      P = fprops_fluid("water","helmholtz",NULL);
59        assert(P);
60        err = FPROPS_NO_ERROR;
61    
62        TEST_PH(314.4054538268115, 999.7897902747587);
63    
64      TEST_PH(4.278618181818e+02, 3.591421624513e-03);      TEST_PH(4.278618181818e+02, 3.591421624513e-03);
65      TEST_PH(3.453541818182e+02, 6.899880592960e-03);      TEST_PH(3.453541818182e+02, 6.899880592960e-03);
66      TEST_PH(7.166385454545e+02, 6.899880592960e-03);      TEST_PH(7.166385454545e+02, 6.899880592960e-03);
67      TEST_PH(7.372654545455e+02, 4.092431601778e-03);      TEST_PH(7.372654545455e+02, 4.092431601778e-03);
68    
     TEST_PH(314.4054538268115, 999.7897902747587);  
   
69      TEST_PH(304.10372142680086, 999.7863801065582);      TEST_PH(304.10372142680086, 999.7863801065582);
   
70      TEST_PH(283.4886584572104, 999.7900620473787);      TEST_PH(283.4886584572104, 999.7900620473787);
   
71      TEST_PH(293.8028752316878, 999.7858245521049);      TEST_PH(293.8028752316878, 999.7858245521049);
72    
73        P = fprops_fluid("water","pengrob","IAPWS");
74        ReferenceState R = {FPROPS_REF_TPF};
75        fprops_set_reference_state(P,&R);
76        MSG("Testing '%s' (type '%d', source '%s')", P->name, P->type, P->source);
77        assert(P);
78        err = FPROPS_NO_ERROR;
79    
80        TEST_PH(2.731600000000e+02, 8.618514819566e+02);
81        MSG("p = %f",p);
82        MSG("h = %f",h);
83    
84      fprintf(stderr,"\n");      fprintf(stderr,"\n");
85      color_on(stderr,ASC_FG_BRIGHTGREEN);      color_on(stderr,ASC_FG_BRIGHTGREEN);

Legend:
Removed from v.2662  
changed lines
  Added in v.2664

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