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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1835 - (hide annotations) (download) (as text)
Mon Aug 25 08:18:23 2008 UTC (15 years, 11 months ago) by jpye
File MIME type: text/x-csrc
File size: 10178 byte(s)
Checked in generalised version of ideal gas component.
Working on adding the 'exponential' term for the Nitrogen correlation.
1 jpye 1833 #include "ammonia.h"
2    
3 jpye 1835
4     /**
5     Ideal gas data for Ammonia, from Tillner-Roth, Harms-Watzenberg and
6 jpye 1833 Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak', DKV-Tagungsbericht,
7     20:167-181, 1993. This is the ammmonia property correlation recommended
8 jpye 1835 by NIST in its program REFPROP 7.0.
9     */
10     const IdealData ideal_data_ammonia = {
11     -15.815020 /* const */
12     , 4.255726 /* linear */
13     , 3 /* power terms */
14     , (const IdealPowTerm[]){
15     {11.474340, 1./3 }
16     ,{-1.296211, -3./2.}
17     ,{0.5706757, -7./4.}
18     }
19     , 0, (const IdealExpTerm *)0 /* no exponential terms */
20     };
21    
22 jpye 1833
23 jpye 1835 /**
24     Residual (non-ideal) property data for Ammonia, from Tillner-Roth,
25     Harms-Watzenberg and Baehr, 'Eine neue Fundamentalgleichung f端r Ammoniak',
26     DKV-Tagungsbericht, 20:167-181, 1993. This is the ammmonia property correlation
27     recommended by NIST in its program REFPROP 7.0.
28     */
29 jpye 1833 const HelmholtzData helmholtz_data_ammonia = {
30     /* R */ 488.189 /* J/kg/K */
31     , /* M */ 17.03026 /* kg/kmol */
32     , /* rho_star */225. /* kg/m続 */
33     , /* T_star */ 405.40 /* K */
34 jpye 1835 , &ideal_data_ammonia
35     , 21 /* nr */
36 jpye 1833 , (const HelmholtzATDL[]){
37     /* a_i, t_i, d_i, l_i */
38     {0.4554431E-1, -0.5 , 2, 0}/* 1 */
39     ,{0.7238548E+0, 0.5 , 1, 0 }
40     ,{0.1229470E-1, 1 , 4, 0 }
41     ,{-0.1858814E+1, 1.5 , 1, 0 }
42     ,{0.2141882E-10, 3 , 15, 0 }/* 5 */
43     ,{-0.1430020E-1, 0 , 3, 1 }
44     ,{0.3441324E+0, 3 , 3, 1 }
45     ,{-0.2873571E+0, 4 , 1, 1 }
46     ,{0.2352589E-4, 4 , 8, 1 }
47     ,{-0.3497111E-1, 5 , 2, 1}/* 10 */
48     ,{0.2397852E-1, 3 , 1, 2}
49     ,{0.1831117E-2, 5 , 8, 2}
50     ,{-0.4085375E-1, 6 , 1, 2}
51     ,{0.2379275E+0, 8 , 2, 2}
52     ,{-0.3548972E-1, 8 , 3, 2}/* 15 */
53     ,{-0.1823729E+0, 10, 2, 2}
54     ,{0.2281556E-1, 10 , 4, 2}
55     ,{-0.6663444E-2, 5 , 3, 3}
56     ,{-0.8847486E-2, 7.5, 1, 3}
57     ,{0.2272635E-2 , 15 , 2, 3}/* 20 */
58     ,{-0.5588655E-3, 30, 4, 3}
59     }
60     };
61    
62    
63     /*
64     Test suite. These tests attempt to validate the current code using
65     a few sample figures output by REFPROP 7.0.
66    
67     To run the test, compile and run as follows:
68    
69     gcc helmholtz.c ammonia.c -DTEST -o ammonia -lm && ./ammonia
70    
71     These tests all currently pass with a maximum error of 2%. The error
72     seems to arise in the enthalpy data for low temperatures. Haven't been
73     able to determine where the problem comes from.
74     */
75     #ifdef TEST
76    
77     #include <assert.h>
78     #include <stdlib.h>
79     #include <stdio.h>
80     #include <math.h>
81    
82     /* a simple macro to actually do the testing */
83     #define ASSERT_TOL(EXPR,VAL,TOL) {\
84     double cval; cval = (EXPR);\
85     double err; err = cval - (double)(VAL);\
86     double relerrpc = (cval-(VAL))/(VAL)*100;\
87     if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
88     if(fabs(err)>TOL){\
89     fprintf(stderr,"ERROR in line %d: value of '%s' = %f, should be %f, error is %f (%.2f%%)!\n"\
90     , __LINE__, #EXPR, cval, VAL,cval-(VAL),relerrpc);\
91     exit(1);\
92     }else{\
93     fprintf(stderr," OK, %s = %8.2e with %.2f%% err.\n",#EXPR,VAL,relerrpc);\
94     /*fprintf(stderr," (err = %8.2e, tol = %8.2e, calc = %8.2e)\n",fabs(err),TOL,cval);*/\
95     }\
96     }
97    
98     int main(void){
99     double rho, T, p, h, u;
100     const HelmholtzData *d;
101    
102     d = &helmholtz_data_ammonia;
103     double maxerr = 0;
104    
105     fprintf(stderr,"PRESSURE TESTS\n");
106    
107     fprintf(stderr,"p(T,rho) = 0.1 MPa\n");
108     ASSERT_TOL(helmholtz_p(273.15 -70,724.74783,d), 0.1E6, 1E3);
109     ASSERT_TOL(helmholtz_p(273.15 -60,713.64815,d), 0.1E6, 1E3);
110     ASSERT_TOL(helmholtz_p(273.15 -50,702.11130,d), 0.1E6, 1E3);
111     ASSERT_TOL(helmholtz_p(273.15 -40,690.16351,d), 0.1E6, 1E3);
112     ASSERT_TOL(helmholtz_p(273.15 -33.588341,682.29489,d), 0.1E6,1E3);
113     ASSERT_TOL(helmholtz_p(273.15+ 0,0.76123983,d), 0.1E6, 1E3);
114     ASSERT_TOL(helmholtz_p(273.15+100,0.55135,d), 0.1E6, 1E3);
115     ASSERT_TOL(helmholtz_p(273.15+250,0.39203,d), 0.1E6, 1E3);
116     ASSERT_TOL(helmholtz_p(273.15+420,0.29562,d), 0.1E6, 1E3);
117    
118     fprintf(stderr,"p(T,rho) = 1 MPa\n");
119     ASSERT_TOL(helmholtz_p(273.15 -70,725.05815,d), 1E6, 1E3);
120     ASSERT_TOL(helmholtz_p(273.15+ 0,638.97275,d), 1E6, 1E3);
121     ASSERT_TOL(helmholtz_p(273.15+ 30,7.5736465,d), 1E6, 1E3);
122     ASSERT_TOL(helmholtz_p(273.15+150,4.9816537,d), 1E6, 1E3);
123     ASSERT_TOL(helmholtz_p(273.15+200,4.4115,d), 1E6, 1E3);
124     ASSERT_TOL(helmholtz_p(273.15+350,3.3082,d), 1E6, 1E3);
125     ASSERT_TOL(helmholtz_p(273.15+420,2.9670,d), 1E6, 1E3);
126    
127     fprintf(stderr,"p(T,rho) = 10 MPa\n");
128     ASSERT_TOL(helmholtz_p(273.15+-40.,694.67407,d), 10E6, 1E3);
129     ASSERT_TOL(helmholtz_p(273.15+-20.,670.54741,d), 10E6, 1E3);
130     ASSERT_TOL(helmholtz_p(273.15+50,573.07306,d), 10E6, 1E3);
131     ASSERT_TOL(helmholtz_p(273.15+110,441.76869,d), 10E6, 1E3);
132     ASSERT_TOL(helmholtz_p(273.15+150,74.732,d), 10E6, 1E3);
133     ASSERT_TOL(helmholtz_p(273.15+200,54.389,d), 10E6, 1E3);
134     ASSERT_TOL(helmholtz_p(273.15+350,35.072,d), 10E6, 1E3);
135     ASSERT_TOL(helmholtz_p(273.15+420,30.731,d), 10E6, 1E3);
136    
137     fprintf(stderr,"p(T,rho) = 20 MPa\n");
138     ASSERT_TOL(helmholtz_p(273.15+150,359.40683,d), 20E6, 1E4);
139     ASSERT_TOL(helmholtz_p(273.15+200,152.83430,d), 20E6, 1E4);
140     ASSERT_TOL(helmholtz_p(273.15+350,74.590236,d), 20E6, 1E4);
141     ASSERT_TOL(helmholtz_p(273.15+420,63.601873,d), 20E6, 1E4);
142    
143     //fprintf(stderr,"IDEAL HELMHOLTZ COMPONENT\n");
144     //ASSERT_TOL(helm_ideal(273.15, 0)
145    
146     fprintf(stderr,"ENTHALPY TESTS\n");
147    
148     /* this offset is required to attain agreement with values from REFPROP */
149     double Z = -1635.7e3 + 1492.411e3;
150    
151     fprintf(stderr,"h(T,rho) at p = 0.1 MPa\n");
152     ASSERT_TOL(helmholtz_h(273.15+-60, 713.65,d), Z+75.166e3, 0.2e3);
153     ASSERT_TOL(helmholtz_h(273.15+ 0,0.76124,d), Z+1635.7e3, 0.2e3);
154     ASSERT_TOL(helmholtz_h(273.15+ 50,0.63869,d), Z+1744.0e3, 0.2e3);
155     ASSERT_TOL(helmholtz_h(273.15+200,0.43370,d), Z+2087.0e3, 0.2e3);
156     ASSERT_TOL(helmholtz_h(273.15+300,0.35769,d), Z+2340.0e3, 1e3);
157     ASSERT_TOL(helmholtz_h(273.15+420,0.29562,d), Z+2674.3e3, 1e3);
158    
159     fprintf(stderr,"h(T,rho) at p = 1 MPa\n");
160     ASSERT_TOL(helmholtz_h(273.15+150,4.9817,d), Z+1949.1e3, 1e3);
161     ASSERT_TOL(helmholtz_h(273.15+200,4.4115,d), Z+2072.7e3, 1e3);
162     ASSERT_TOL(helmholtz_h(273.15+350,3.3082,d), Z+2468.2e3, 1e3);
163     ASSERT_TOL(helmholtz_h(273.15+420,2.9670,d), Z+2668.6e3, 1e3);
164    
165     fprintf(stderr,"h(T,rho) at p = 10 MPa\n");
166     ASSERT_TOL(helmholtz_h(273.15+-50,706.21,d), Z+127.39e3, 2e3);
167     ASSERT_TOL(helmholtz_h(273.15+-0,645.04,d), Z+349.53e3, 2e3);
168    
169     ASSERT_TOL(helmholtz_h(273.15+150,74.732,d), Z+1688.5e3, 1e3);
170     ASSERT_TOL(helmholtz_h(273.15+200,54.389,d), Z+1908.0e3, 1e3);
171     ASSERT_TOL(helmholtz_h(273.15+350,35.072,d), Z+2393.4e3, 1e3);
172     ASSERT_TOL(helmholtz_h(273.15+420,30.731,d), Z+2611.8e3, 1e3);
173    
174     fprintf(stderr,"h(T,rho) at p = 20 MPa\n");
175     /* note rather larger errors in the following few lines -- why? */
176     ASSERT_TOL(helmholtz_h(273.15 -70,731.41,d), Z+51.734e3, 0.5e3);
177     ASSERT_TOL(helmholtz_h(273.15 -60,721.00318,d), Z+93.871419e3, 0.5e3);
178     ASSERT_TOL(helmholtz_h(273.15 -50,710.19289,d), Z+136.54351e3, 1e3);
179     ASSERT_TOL(helmholtz_h(273.15 -40,699.02472,d), Z+179.72030e3, 0.5e3);
180     ASSERT_TOL(helmholtz_h(273.15+ 30,612.22,d), Z+493.28e3, 0.5e3);
181     ASSERT_TOL(helmholtz_h(273.15+150,359.40683,d), Z+1162.5e3, 0.5e3);
182     ASSERT_TOL(helmholtz_h(273.15+200,152.83430,d), Z+1662.9e3, 0.5e3);
183     ASSERT_TOL(helmholtz_h(273.15+250,106.31299,d), Z+1928.6499e3, 0.5e3);
184     ASSERT_TOL(helmholtz_h(273.15+300,86.516941,d), Z+2128.9031e3, 0.5e3);
185     ASSERT_TOL(helmholtz_h(273.15+330,78.784703,d), Z+2238.2416e3, 0.5e3);
186     ASSERT_TOL(helmholtz_h(273.15+350,74.590236,d), Z+2308.8516e3, 10e3);
187     ASSERT_TOL(helmholtz_h(273.15+420,63.601873,d), Z+2549.2872e3, 10e3);
188    
189     fprintf(stderr,"h(T,rho) at p = 100 MPa\n");
190     ASSERT_TOL(helmholtz_h(273.15+ 0,690.41,d), Z+422.69e3, 0.5e3);
191     ASSERT_TOL(helmholtz_h(273.15+100,591.07,d), Z+850.44e3, 0.1e3);
192     ASSERT_TOL(helmholtz_h(273.15+250,437.69,d), Z+1506.6e3, 1e3);
193     ASSERT_TOL(helmholtz_h(273.15+420,298.79,d), Z+2252.3e3, 1e3);
194    
195 jpye 1835
196    
197     fprintf(stderr,"ENTROPY TESTS\n");
198    
199     /* offset required to attain agreement with REFPROP */
200     double Y = -471.596704;
201    
202     fprintf(stderr,"s(T,rho) at p = 0.1 MPa\n");
203     ASSERT_TOL(helmholtz_s(273.15+-60, 713.65,d), Y+0.36737e3, 0.5);
204     ASSERT_TOL(helmholtz_s(273.15+ 0,0.76124,d), Y+6.8900e3, 0.5);
205     ASSERT_TOL(helmholtz_s(273.15+ 50,0.63869,d), Y+7.2544e3, 0.5);
206     ASSERT_TOL(helmholtz_s(273.15+200,0.43370,d), Y+8.1232e3, 0.5);
207     ASSERT_TOL(helmholtz_s(273.15+300,0.35769,d), Y+8.6084e3, 1);
208     ASSERT_TOL(helmholtz_s(273.15+420,0.29562,d), Y+9.1365e3, 1);
209    
210     fprintf(stderr,"s(T,rho) at p = 1 MPa\n");
211     ASSERT_TOL(helmholtz_s(273.15+-50,702.49,d), Y+0.56381e3, 0.5);
212     ASSERT_TOL(helmholtz_s(273.15+150,4.9817,d), Y+6.7008e3, 0.5);
213     ASSERT_TOL(helmholtz_s(273.15+200,4.4115,d), Y+6.9770e3, 0.5);
214     ASSERT_TOL(helmholtz_s(273.15+350,3.3082,d), Y+7.7012e3, 0.5);
215     ASSERT_TOL(helmholtz_s(273.15+420,2.9670,d), Y+8.0059e3, 0.5);
216    
217     fprintf(stderr,"s(T,rho) at p = 10 MPa\n");
218     ASSERT_TOL(helmholtz_s(273.15+-70,728.11,d), Y+0.14196e3, 1);
219     ASSERT_TOL(helmholtz_s(273.15+-50,706.21,d), Y+0.54289e3, 1);
220     ASSERT_TOL(helmholtz_s(273.15+-20,670.55,d), Y+1.0975e3, 1);
221     ASSERT_TOL(helmholtz_s(273.15+ 0,645.04,d), Y+1.4403e3, 1);
222     ASSERT_TOL(helmholtz_s(273.15+125.17,356.70,d), Y+3.5463e3, 1);
223    
224     ASSERT_TOL(helmholtz_s(273.15+125.17,121.58,d), Y+4.5150e3, 1);
225     ASSERT_TOL(helmholtz_s(273.15+200,54.389,d), Y+5.5906e3, 1);
226     ASSERT_TOL(helmholtz_s(273.15+350,35.072,d), Y+6.4850e3, 1);
227     ASSERT_TOL(helmholtz_s(273.15+420,30.731,d), Y+6.8171e3, 1);
228    
229     fprintf(stderr,"s(T,rho) at p = 20 MPa\n");
230     ASSERT_TOL(helmholtz_s(273.15+-50,710.19,d), Y+0.52061e3, 1);
231     ASSERT_TOL(helmholtz_s(273.15+ 30,612.22,d), Y+1.8844e3, 1);
232     ASSERT_TOL(helmholtz_s(273.15+150,359.41,d), Y+3.7164e3, 1);
233     ASSERT_TOL(helmholtz_s(273.15+200,152.83,d), Y+4.8376e3, 1);
234     ASSERT_TOL(helmholtz_s(273.15+350,74.590,d), Y+6.0407e3, 1);
235     ASSERT_TOL(helmholtz_s(273.15+420,63.602,d), Y+6.4066e3, 1);
236    
237     fprintf(stderr,"s(T,rho) at p = 100 MPa\n");
238     ASSERT_TOL(helmholtz_s(273.15+ 0,690.41,d), Y+1.2158e3, 1);
239     ASSERT_TOL(helmholtz_s(273.15+100,591.07,d), Y+2.5499e3, 1);
240     ASSERT_TOL(helmholtz_s(273.15+250,437.69,d), Y+4.0264e3, 1);
241     ASSERT_TOL(helmholtz_s(273.15+420,298.79,d), Y+5.2620e3, 1);
242    
243     /* successful entropy tests means that helm_ideal_tau, helm_real_tau, helm_ideal and helm_resid are all OK */
244    
245 jpye 1833 fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
246     exit(0);
247     }
248     #endif

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