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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2992 - (show annotations) (download) (as text)
Tue Jun 30 06:24:29 2015 UTC (7 years, 7 months ago) by sid
File MIME type: text/x-csrc
File size: 2665 byte(s)


1
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 #include "../ttse.h"
10
11 #include <assert.h>
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <time.h>
16
17 #include "../color.h"
18
19 #define MSG(FMT, ...) \
20 color_on(stderr,ASC_FG_BRIGHTRED);\
21 fprintf(stderr,"%s:%d: ",__FILE__,__LINE__);\
22 color_on(stderr,ASC_FG_BRIGHTBLUE);\
23 fprintf(stderr,"%s: ",__func__);\
24 color_off(stderr);\
25 fprintf(stderr,FMT "\n",##__VA_ARGS__)
26
27 #define ERRMSG(STR,...) \
28 color_on(stderr,ASC_FG_BRIGHTRED);\
29 fprintf(stderr,"ERROR:");\
30 color_off(stderr);\
31 fprintf(stderr," %s:%d:" STR "\n", __func__, __LINE__ ,##__VA_ARGS__)
32
33 #define TOL_T 1e-8
34 #define TOL_RHO 1e-3
35
36
37
38 int main(void){
39 PureFluid *P;
40 FpropsError err;
41 const char *helmfluids[] = { "water"};
42 //const int n = sizeof(helmfluids)/sizeof(char *);
43 int i;
44
45
46 MSG("Which Fluid? --> %s",helmfluids[0]);
47
48 P = (PureFluid *)fprops_fluid(helmfluids[0],"helmholtz",NULL);
49
50 MSG("Comparing Helmholtz vs TTSE");
51
52
53 double rho = 1350;
54
55
56
57 #define NPOINTS 500
58 double temp_s = 280;
59 double temp_f = 350;
60 int nT = NPOINTS;
61 double dT = (temp_f-temp_s)/nT;
62
63
64
65 double pressH[NPOINTS],entH[NPOINTS],enthalpyH[NPOINTS];
66 double pressT[NPOINTS],entT[NPOINTS],enthalpyT[NPOINTS];
67
68
69 clock_t start = clock();
70 for(i=0; i<nT; ++i){
71 err = FPROPS_NO_ERROR;
72
73 double T = temp_s + i*dT;
74
75 pressH[i] = P->p_fn(T, rho, P->data,&err) ;
76 entH[i] = P->s_fn(T, rho, P->data,&err) ;
77 enthalpyH[i] = P->h_fn(T, rho, P->data,&err) ;
78 }
79
80 clock_t end = clock();
81 double msecH = (double)(end - start) / (CLOCKS_PER_SEC/1000);
82
83 start = clock();
84 for(i=0; i<nT; ++i){
85 err = FPROPS_NO_ERROR;
86
87 double T = temp_s + i*dT;
88
89 pressT[i] = evaluate_ttse_p(P,T, rho) ;
90 entT[i] = evaluate_ttse_s(P,T, rho) ;
91 enthalpyT[i] = evaluate_ttse_h(P,T, rho) ;
92 }
93
94 end = clock();
95 double msecT = (double)(end - start) / (CLOCKS_PER_SEC/1000);
96
97
98 MSG("Percentage Errors");
99 MSG("Temp Pressure Entropy Enthalpy");
100
101
102
103 for(i=0; i<nT; ++i){
104 double T = temp_s + i*dT;
105 double pererrp = 100*((pressT[i]-pressH[i])/pressH[i]);
106 double pererrs = 100*((entT[i]-entH[i])/entH[i]);
107 double pererrh = 100*((enthalpyT[i]-enthalpyH[i])/enthalpyH[i]);
108
109 MSG("%f %f %f %f",T, pererrp,pererrs,pererrh );
110 }
111
112 MSG("Helmholtz did %d calculations in %e seconds", nT*3,msecH/1000);
113 MSG("TTSE did %d calculations in %e seconds", nT*3,msecT/1000);
114
115 return 1;
116 }
117
118
119
120
121
122
123
124
125
126

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