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

Annotation of /trunk/models/johnpye/fprops/water.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1873 - (hide annotations) (download) (as text)
Thu Sep 18 02:34:54 2008 UTC (15 years, 10 months ago) by jpye
File MIME type: text/x-csrc
File size: 5064 byte(s)
Adding water to fluids set (for the purpose of debuggin using freesteam code).
1 jpye 1873 #include "water.h"
2    
3     #define WATER_R 461.51805 /* J/kg路K */
4     #define WATER_TSTAR 647.096 /* K */
5    
6     /**
7     Ideal gas data for Water/Steam, from IAPWS-95.
8     http://www.iapws.org/relguide/IAPWS95.pdf
9     */
10     const IdealData ideal_data_water = {
11     -8.32044648201 /* constant */
12     , 6.6832105268 /* linear */
13     , WATER_TSTAR /* Tstar */
14     , WATER_R /* cpstar J/kgK */
15     , 1 /* power terms */
16     , (const IdealPowTerm[]){
17     {3.00632, 1}
18     }
19     , 5 /* exponential terms */
20     , (const IdealExpTerm []){
21     {0.012436, 1.28728967}
22     ,{0.97315, 3.53734222}
23     ,{1.27950, 7.74073708}
24     ,{0.96956, 9.24437796}
25     ,{0.24873, 27.5075105}
26     }
27     };
28    
29    
30     /**
31     Residual (non-ideal) property data for Water/Steam, from IAPWS-95.
32     http://www.iapws.org/relguide/IAPWS95.pdf
33     */
34     const HelmholtzData helmholtz_data_water = {
35     /* R */ WATER_R /* J/kg/K */
36     , /* M */ 0.00000000000000 /* kg/kmol -- need to look up value cited by IAPWS */
37     , /* rho_star */322. /* kg/m鲁 */
38     , /* T_star */ WATER_TSTAR /* K */
39     , &ideal_data_water
40     , 51 /* np */
41     , (const HelmholtzPowTerm[]){
42     /* a_i, t_i, d_i, l_i */
43     {0.12533547935523E-1, -0.5, 1, 0}
44     ,{0.78957634722828E1, 0.875, 1, 0}
45     ,{-0.87803203303561E1, 1, 1, 0}
46     ,{0.31802509345418, 0.5, 2, 0}
47     ,{-0.26145533859358, 0.75, 2, 0}
48     ,{-0.78199751687981E-2, 0.375, 3, 0}
49     ,{0.88089493102134E-2, 1, 4, 0}
50     ,{-0.66856572307965, 4, 1, 1}
51     ,{0.20433810950965, 6, 1, 1}
52     ,{-0.66212605039687E-4, 12, 1, 1}
53     ,{-0.19232721156002, 1, 2, 1}
54     ,{-0.25709043003438, 5, 2, 1}
55     ,{0.16074868486251, 4, 3, 1}
56     ,{-0.40092828925807E-1, 2, 4, 1}
57     ,{0.39343422603254E-6, 13, 4, 1}
58     ,{-0.75941377088144E-5, 9, 5, 1}
59     ,{0.56250979351888E-3, 3, 7, 1}
60     ,{-0.15608652257135E-4, 4, 9, 1}
61     ,{0.11537996422951E-8, 11, 10, 1}
62     ,{0.36582165144204E-6, 4, 11, 1}
63     ,{-0.13251180074668E-11, 13, 13, 1}
64     ,{-0.62639586912454E-9, 1, 15, 1}
65     ,{-0.10793600908932, 7, 1, 2}
66     ,{0.17611491008752E-1, 1, 2, 2}
67     ,{0.22132295167546, 9, 2, 2}
68     ,{-0.40247669763528, 10, 2, 2}
69     ,{0.58083399985759, 10, 3, 2}
70     ,{0.49969146990806E-2, 3, 4, 2}
71     ,{-0.31358700712549E-1, 7, 4, 2}
72     ,{-0.74315929710341, 10, 4, 2}
73     ,{0.47807329915480, 10, 5, 2}
74     ,{0.20527940895948E-1, 6, 6, 2}
75     ,{-0.13636435110343, 10, 6, 2}
76     ,{0.14180634400617E-1, 10, 7, 2}
77     ,{0.83326504880713E-2, 1, 9, 2}
78     ,{-0.29052336009585E-1, 2, 9, 2}
79     ,{0.38615085574206E-1, 3, 9, 2}
80     ,{-0.20393486513704E-1, 4, 9, 2}
81     ,{-0.16554050063734E-2, 8, 9, 2}
82     ,{0.19955571979541E-2, 6, 10, 2}
83     ,{0.15870308324157E-3, 9, 10, 2}
84     ,{-0.16388568342530E-4, 8, 12, 2}
85     ,{0.43613615723811E-1, 16, 3, 3}
86     ,{0.34994005463765E-1, 22, 4, 3}
87     ,{-0.76788197844621E-1, 23, 4, 3}
88     ,{0.22446277332006E-1, 23, 5, 3}
89     ,{-0.62689710414685E-4, 10, 14, 4}
90     ,{-0.55711118565645E-9, 50, 3, 6}
91     ,{-0.19905718354408, 44, 6, 6}
92     ,{0.31777497330738, 46, 6, 6}
93     ,{-0.11841182425981, 50, 6, 6}
94     }
95     , 0, 0 /* no exponential terms */
96     };
97    
98    
99     /*
100     Test suite. These tests attempt to validate the current code using
101     a few sample figures output by REFPROP 7.0.
102    
103     To run the test, compile and run as follows:
104    
105     ./test.py water
106     */
107     #ifdef TEST
108    
109     /*
110     some code from freesteam, http://freesteam.sf.net/, which has been thoroughly
111     validated already.
112     */
113    
114     const double n0[] = {
115     0.0,
116     -8.32044648201, 6.6832105268, 3.00632, 0.012436,
117     0.97315, 1.27950, 0.96956, 0.24873
118     };
119    
120     const double gamma0[] = {
121     0.0, 0.0, 0.0, 0.0,
122     1.28728967,
123     3.53734222,
124     7.74073708,
125     9.24437796,
126     27.5075105
127     };
128    
129     enum Limits{
130     eGamma1 = 4,
131     eGamma2 = 9,
132     ePhir1 = 1,
133     ePhir2 = 8,
134     ePhir3 = 52,
135     ePhir4 = 55,
136     ePhir5 = 57
137     };
138    
139     #include <assert.h>
140     #include <stdlib.h>
141     #include <stdio.h>
142     #include <math.h>
143     #include "ideal_impl.h"
144    
145     double phi0(const double delta, const double tau){
146     int i;
147     double sum = 0;
148     for (i = eGamma1; i < eGamma2; i++)
149     {
150     sum += n0[i]*log(1-exp(-tau*gamma0[i]));
151     }
152     sum += log(delta) + n0[1] + n0[2]*tau + n0[3]*log(tau);
153     return sum;
154     }
155    
156     int main(void){
157     double rho, T;
158     const HelmholtzData *d;
159    
160     d = &helmholtz_data_water;
161     double maxerr = 0;
162    
163     /* a simple macro to actually do the testing */
164     #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
165     double cval; cval = FN(PARAM1,PARAM2,PARAM3);\
166     double err; err = cval - (double)(VAL);\
167     double relerrpc = (cval-(VAL))/(VAL)*100;\
168     if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
169     if(fabs(err)>fabs(TOL)){\
170     fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %0.8f,"\
171     " should be %f, error is %.10e (%.2f%%)!\n"\
172     , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\
173     ,relerrpc\
174     );\
175     exit(1);\
176     }else{\
177     fprintf(stderr," OK, %s(%f,%f,%s) = %8.2e with %.6f%% err.\n"\
178     ,#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\
179     );\
180     }\
181     }
182    
183    
184     fprintf(stderr,"phi0 TESTS\n");
185     for(T = 300; T <= 900; T+= 100){
186     for(rho = 900; rho >= 0.9; rho*=0.5){
187     double delta = rho / d->rho_star;
188     double tau = d->T_star / T;
189     double p0 = phi0(delta,tau);
190    
191     ASSERT_TOL(helm_ideal, tau, delta, d->ideal, p0, p0*1e-5);
192     }
193     }
194    
195     fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
196     exit(0);
197     }
198    
199     #endif
200    

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