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

Contents of /trunk/models/johnpye/fprops/test/sat1.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2679 - (show annotations) (download) (as text)
Mon Jan 28 03:41:23 2013 UTC (9 years, 5 months ago) by jpye
File MIME type: text/x-csrc
File size: 3075 byte(s)
fix test sat1 for n_eicosane above TP.
1 #include "../fluids.h"
2 #include "../fprops.h"
3 #include "../solve_Tx.h"
4 #include "../sat.h"
5 #include <assert.h>
6 #include <math.h>
7 #include "../fluids/fluids_list.h"
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;
30 FpropsError err = FPROPS_NO_ERROR;
31 FluidState S;
32
33 double T0, rho, rhof, rhog, psat1, psat2;
34
35 #define TEST_SAT(T1) \
36 T0 = T1; \
37 fprops_solve_Tx(T0,0,&rho,P,&err); \
38 assert(!err); \
39 S = fprops_set_Trho(T0,rho,P,&err); \
40 assert(!err); \
41 rhof = S.rho; \
42 psat1 = fprops_p(S,&err); \
43 assert(!err); \
44 fprops_solve_Tx(T0,1,&rho,P,&err); \
45 S = fprops_set_Trho(T0,rho,P,&err); \
46 assert(!err); \
47 assert(!err); \
48 psat2 = fprops_p(S,&err); \
49 assert(!err); \
50 rhog = S.rho; \
51 assert(fabs(psat1 - psat2) < 1e-3); \
52 MSG("At T = %f K (%f C), psat = %f, rhof = %f, rhog = %f ('%s')",T0,T0-273.15,psat1,rhof,rhog,P->name);
53
54 // following tests came form sat.c failures, mostly at close to critical point temp?
55 P = fprops_fluid("trans_difluorodiazine","pengrob","RPP"); assert(P);
56 TEST_SAT(259.958622);
57
58 P = fprops_fluid("silicon_tetrafluoride","pengrob","RPP"); assert(P);
59 TEST_SAT(258.859249);
60 TEST_SAT(258.894422);
61 TEST_SAT(258.929605);
62 TEST_SAT(258.964798);
63
64 P = fprops_fluid("boron_trifluoride","pengrob","RPP"); assert(P);
65 TEST_SAT(260.753648);
66
67 P = fprops_fluid("ozone","pengrob","RPP"); assert(P);
68 TEST_SAT(260.955380);
69 TEST_SAT(261.003569);
70 TEST_SAT(261.051776);
71
72 const char *fluids[] = {"water","toluene","ethanol","isohexane","n_eicosane", NULL};
73 // const char *fluids[] = {"toluene",NULL};
74 const char **fi = fluids;
75 while(*fi){
76 MSG("TESTING %s",*fi);
77 P = fprops_fluid(*fi,"pengrob",NULL);
78 assert(P);
79 err = FPROPS_NO_ERROR;
80
81 double psat,rhof,rhog;
82 fprops_triple_point(&psat, &rhof, &rhog, P, &err);
83 assert(!err);
84 ++fi;
85 }
86
87 P = fprops_fluid("water","helmholtz",NULL);
88 assert(P);
89 err = FPROPS_NO_ERROR;
90
91 // low-density saturation cases (I think)
92 TEST_SAT(273.15+4.1);
93 TEST_SAT(273.15+3.9);
94 TEST_SAT(273.15+4);
95 TEST_SAT(275.212471);
96 TEST_SAT(275.212471);
97 TEST_SAT(2.732910e+02);
98 TEST_SAT(2.731868e+02);
99 TEST_SAT(2.844904e+02);
100
101 psat1 = 709.144373;
102 fprops_sat_p(psat1,&T0,&rhof,&rhog,P,&err);
103 assert(!err);
104
105 P = fprops_fluid("isohexane","helmholtz",NULL);
106 assert(P);
107 err = FPROPS_NO_ERROR;
108
109 // low-density saturation cases (I think)
110 TEST_SAT(P->data->T_t);
111
112 /*MSG("At p = %f Pa, got T = %f K (%f C), rhof = %f, rhog = %f", psat1, T0, T0-273.15, rhof, rhog)*/;
113
114 fprintf(stderr,"\n");
115 color_on(stderr,ASC_FG_BRIGHTGREEN);
116 fprintf(stderr,"SUCCESS (%s)",__FILE__);
117 color_off(stderr);
118 fprintf(stderr,"\n");
119 return 0;
120 }
121

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