/[ascend]/branches/sid/models/johnpye/fprops/test/test_ttse.c
ViewVC logotype

Annotation of /branches/sid/models/johnpye/fprops/test/test_ttse.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2984 - (hide annotations) (download) (as text)
Sun Jun 28 00:58:42 2015 UTC (4 years ago) by sid
File MIME type: text/x-csrc
File size: 4423 byte(s)
test added


1 sid 2984
2    
3     #include "../fluids.h"
4     #include "../fprops.h"
5     #include "../solve_ph.h"
6     #include "../refstate.h"
7     #include "../sat.h"
8     #include "../visc.h"
9    
10     #include <assert.h>
11     #include <math.h>
12    
13     #include "../color.h"
14    
15     #define MSG(FMT, ...) \
16     color_on(stderr,ASC_FG_BRIGHTRED);\
17     fprintf(stderr,"%s:%d: ",__FILE__,__LINE__);\
18     color_on(stderr,ASC_FG_BRIGHTBLUE);\
19     fprintf(stderr,"%s: ",__func__);\
20     color_off(stderr);\
21     fprintf(stderr,FMT "\n",##__VA_ARGS__)
22    
23     #define ERRMSG(STR,...) \
24     color_on(stderr,ASC_FG_BRIGHTRED);\
25     fprintf(stderr,"ERROR:");\
26     color_off(stderr);\
27     fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)
28    
29     #define TOL_T 1e-8
30     #define TOL_RHO 1e-3
31    
32    
33    
34     int main(void){
35     const PureFluid *P;
36     FpropsError err;
37     FluidState S;
38     /*
39     #define FNAME(F) #F
40     #define COMMA ,
41     const char *helmfluids[] = { FLUIDS(FNAME,COMMA) COMMA RPPFLUIDS(FNAME,COMMA) };
42    
43     // int ii;
44     //for(ii=0; ii< sizeof(helmfluids)/sizeof(char *) ; ii++)
45     // printf("%s \n",helmfluids[ii]);
46     printf("SIZE %d\n",sizeof(helmfluids)/sizeof(char *));
47     #undef FNAME
48     const char *corrtypes[] = {"pengrob","helmholtz"}; // takes enum corrtypes_enum as index
49     const char *corrinitial[] = {"P","H"};
50     enum corrtypes_enum {CORRTYPE_PENGROB,CORRTYPE_HELMHOLTZ,CORRTYPE_N};
51     #define FHELM(F) CORRTYPE_HELMHOLTZ //not stringified with #
52     #define FPR(F) CORRTYPE_PENGROB
53     const enum corrtypes_enum corrfluids[] = {FLUIDS(FHELM,COMMA) COMMA RPPFLUIDS(FPR,COMMA) };
54     #undef FHELM
55     #undef FPR
56     #define FRPP(F) "RPP"
57     #define FUN(F) NULL
58     const char *srcfluids[] = {FLUIDS(FUN,COMMA) COMMA RPPFLUIDS(FRPP,COMMA) };
59     // int ii;
60     // for(ii=0; ii< sizeof(srcfluids)/sizeof(char *) ; ii++)
61     // printf("%s \n",srcfluids[ii]);
62     #undef FUN
63     #undef FRPP
64     #undef COMMA
65    
66     char nloggederrors = 0;
67     #define MAXNLOGGEDERRORS 25
68     #define MAXERRORLOG (MAXNLOGGEDERRORS*80)
69     char errorlog[MAXERRORLOG] = "";
70    
71     #define ERRLOG(FMT,...) \
72     if(nloggederrors < MAXNLOGGEDERRORS){\
73     int l = strlen(errorlog);\
74     char *s = errorlog + l;\
75     snprintf(s,MAXERRORLOG-l,FMT "\n",##__VA_ARGS__);\
76     }\
77     nloggederrors++;
78     */
79     const char *helmfluids[] = { "acetone"};
80     const int n = sizeof(helmfluids)/sizeof(char *);
81     int i,j;
82    
83     printf("%d %s\n",n,helmfluids[0]);
84    
85     P = fprops_fluid(helmfluids[0],"helmholtz",NULL);
86    
87    
88     /*
89     int nerrfluids = 0;
90     const char *errfluids[n];
91     MSG("Testing convergence of saturation curves for all helmholtz fluids...");
92     for(i=0; i<n; ++i){
93     int nerr = 0;
94     P = fprops_fluid(helmfluids[i],corrtypes[corrfluids[i]],srcfluids[i]);
95     if(!P){
96     MSG("Error initialising fluid '%s' type '%s'",helmfluids[i],corrtypes[corrfluids[i]]);
97     nerr = 1;
98     color_on(stdout,ASC_FG_BRIGHTRED);
99     fprintf(stdout,"%s",corrinitial[corrfluids[i]]);
100     color_off(stdout);
101     }else{
102     double Tt = P->data->T_t;
103     double Tc = P->data->T_c;
104     if(Tt == 0){
105     color_on(stdout,ASC_FG_YELLOW);
106     fprintf(stdout,"%s",corrinitial[corrfluids[i]]);
107     color_off(stdout);
108     Tt = 273.15 - 20;
109     if(Tt > Tc){
110     Tt = 0.4 * Tc;
111     }
112     }else{
113     color_on(stdout,ASC_FG_BRIGHTGREEN);
114     fprintf(stdout,"%s",corrinitial[corrfluids[i]]);// prints bright green H or P in output for helmholtz fluid
115     color_off(stdout);
116     }
117     double nT = 500;
118     double rT = 1/Tt;
119     double drT = (1/Tc - 1/Tt) / nT;
120     for(j=0; j<nT; ++j){
121     double T = 1/rT;
122     double psat,rhof,rhog;
123     err = FPROPS_NO_ERROR;
124     fprops_sat_T(T, &psat, &rhof, &rhog, P, &err);
125     if(err){
126     nerr++;
127     color_on(stdout,ASC_FG_BRIGHTRED);//print error
128     fprintf(stdout,"C");//print error
129     color_off(stdout);
130     ERRLOG("sat_T(%f) for '%s', omega=%f",T,P->name,P->data->omega);//log the error
131     }else{
132     fprintf(stdout,".");//just a dot for success
133     }
134     rT += drT;
135     }
136     }
137     fprintf(stdout,":%s\n",helmfluids[i]); // after test name of the fluid
138     if(nerr)errfluids[nerrfluids++] = helmfluids[i];
139     fprops_fluid_destroy(P); P = NULL;
140     }
141    
142     if(nerrfluids){
143     MSG("There were %d fluids with saturation curve errors:",nerrfluids);
144     for(i=0; i<nerrfluids; ++i){
145     fprintf(stderr," %s",errfluids[i]);
146     }
147     }
148     if(nloggederrors){
149     fprintf(stderr,"\n");
150     MSG("First %d of the %d errors logged:",MAXNLOGGEDERRORS,nloggederrors);
151     fprintf(stderr,"%s",errorlog);
152     }
153    
154     if(nerrfluids)return nerrfluids;
155    
156     fprintf(stderr,"\n");
157     color_on(stderr,ASC_FG_BRIGHTGREEN);
158     fprintf(stderr,"SUCCESS (%s)",__FILE__);
159     color_off(stderr);
160     fprintf(stderr,"\n");
161     return 0;
162    
163     */
164     }
165    
166    
167    
168    
169    
170    
171    
172    
173    
174    

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