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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2664 - (show annotations) (download) (as text)
Fri Jan 18 06:02:15 2013 UTC (10 years, 8 months ago) by jpye
File MIME type: text/x-csrc
File size: 2260 byte(s)
Trying to debug fprops_triple_point for Toluene with pengrob correlation. Something strange is happening with fratio.
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
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;
31 FluidState S;
32 double T0, rho, rhof, rhog, psat1, psat2;
33
34 #define TEST_SAT(T1) \
35 T0 = T1; \
36 fprops_solve_Tx(T0,0,&rho,P,&err); \
37 assert(!err); \
38 S = fprops_set_Trho(T0,rho,P,&err); \
39 assert(!err); \
40 rhof = S.rho; \
41 psat1 = fprops_p(S,&err); \
42 assert(!err); \
43 fprops_solve_Tx(T0,1,&rho,P,&err); \
44 S = fprops_set_Trho(T0,rho,P,&err); \
45 assert(!err); \
46 assert(!err); \
47 psat2 = fprops_p(S,&err); \
48 assert(!err); \
49 rhog = S.rho; \
50 assert(fabs(psat1 - psat2) < 1e-3); \
51 /*MSG("At T = %f K (%f C), psat = %f, rhof = %f, rhog = %f",T0,T0-273.15,psat1,rhof,rhog);*/
52
53 // const char *fluids[] = {"water","toluene","ethanol",NULL};
54 const char *fluids[] = {"water",NULL};
55 char **fi = fluids;
56 while(*fi){
57 MSG("TESTING %s",*fi);
58 P = fprops_fluid(*fi,"pengrob",NULL);
59 assert(P);
60 err = FPROPS_NO_ERROR;
61
62 double psat,rhof,rhog;
63 fprops_triple_point(&psat, &rhof, &rhog, P, &err);
64 assert(!err);
65 ++fi;
66 }
67
68 P = fprops_fluid("water","helmholtz",NULL);
69 assert(P);
70 err = FPROPS_NO_ERROR;
71
72 // low-density saturation cases (I think)
73 TEST_SAT(273.15+4.1);
74 TEST_SAT(273.15+3.9);
75 TEST_SAT(273.15+4);
76 TEST_SAT(275.212471);
77 TEST_SAT(275.212471);
78 TEST_SAT(2.732910e+02);
79 TEST_SAT(2.731868e+02);
80 TEST_SAT(2.844904e+02);
81
82 psat1 = 709.144373;
83 fprops_sat_p(psat1,&T0,&rhof,&rhog,P,&err);
84 assert(!err);
85
86 /*MSG("At p = %f Pa, got T = %f K (%f C), rhof = %f, rhog = %f", psat1, T0, T0-273.15, rhof, rhog)*/;
87
88 fprintf(stderr,"\n");
89 color_on(stderr,ASC_FG_BRIGHTGREEN);
90 fprintf(stderr,"SUCCESS (%s)",__FILE__);
91 color_off(stderr);
92 fprintf(stderr,"\n");
93 return 0;
94 }
95

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