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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1901 - (hide annotations) (download) (as text)
Thu Sep 25 07:40:47 2008 UTC (15 years, 9 months ago) by jpye
File MIME type: text/x-csrc
File size: 3451 byte(s)
Completed hydrogen, passes tests for h,u,s,p,a to high accuracy.
1 jpye 1886 #include "test.h"
2    
3     #include <assert.h>
4     #include <stdlib.h>
5     #include <stdio.h>
6     #include <math.h>
7    
8 jpye 1891
9 jpye 1886 int helm_run_test_cases(const HelmholtzData *d, unsigned ntd, const TestData *td){
10    
11     double rho, T, p, u, h, a, s, cp0;
12    
13     double maxerr = 0;
14 jpye 1891 double se = 0, sse = 0;
15 jpye 1886
16     unsigned i;
17     const unsigned n = ntd;
18    
19     fprintf(stderr,"Running through %d test points...\n",n);
20    
21     /* Checking CP0 values */
22    
23     #define CP0_TEMP(T,RHO,DATA) helmholtz_cp0(T,DATA)
24     fprintf(stderr,"CP0 TESTS\n");
25     for(i=0; i<n;++i){
26     cp0 = td[i].cp0*1e3;
27     ASSERT_TOL(CP0_TEMP, td[i].T+273.15, td[i].rho, d, cp0, cp0*1e-6);
28     }
29     #undef CP0_TEMP
30    
31 jpye 1898 /* Checking pressure values (proves phir_delta) */
32     fprintf(stderr,"PRESSURE TESTS\n");
33     for(i=16; i<n;++i){
34     T = td[i].T+273.15;
35     rho = td[i].rho;
36     p = td[i].p*1e6;
37     ASSERT_TOL(helmholtz_p, T, rho, d, p, p*1e-3);
38     }
39    
40 jpye 1897 /* Checking internal energy values (proves phi0_tau, phir_tau) */
41    
42     fprintf(stderr,"INTERNAL ENERGY TESTS\n");
43     for(i=0; i<n;++i){
44     T = td[i].T+273.15;
45     rho = td[i].rho;
46     u = td[i].u*1e3;
47 jpye 1898 ASSERT_TOL(helmholtz_u, T, rho, d, u, 1e3*u);
48 jpye 1897 }
49    
50 jpye 1891 /* Checking entropy values */
51 jpye 1886
52 jpye 1891 fprintf(stderr,"ENTROPY TESTS\n");
53     se = 0, sse = 0;
54 jpye 1886 for(i=0; i<n;++i){
55     T = td[i].T+273.15;
56     rho = td[i].rho;
57 jpye 1891 s = td[i].s*1e3;
58     ASSERT_TOL(helmholtz_s, T, rho, d, s, 1e-6*s);
59 jpye 1886 }
60    
61 jpye 1891 /* checking enthalpy values */
62     fprintf(stderr,"ENTHALPY TESTS\n");
63     se = 0, sse = 0;
64     for(i=0; i<n;++i){
65     T = td[i].T+273.15;
66     rho = td[i].rho;
67     h = td[i].h*1e3;
68     #if 0
69     double err = h - helmholtz_h(T,rho,d);
70     se += err;
71     sse += err*err;
72     fprintf(stderr,"%.12e\t%.12e\t%.12e\t%.12e\n",T,rho,u,err);
73     #else
74     ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, h, 1E3);
75     #endif
76     }
77     #if 0
78     fprintf(stderr,"average error = %.10e\n",se/n);
79     fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
80     exit(1);
81     #endif
82 jpye 1886
83     /* Checking helmholtz energy values */
84    
85     fprintf(stderr,"HELMHOLTZ ENERGY TESTS\n");
86     for(i=0; i<n;++i){
87     T = td[i].T+273.15;
88     rho = td[i].rho;
89     a = td[i].a*1e3;
90     //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(a - helmholtz_a(T,rho,d)));
91     ASSERT_TOL(helmholtz_a, T, rho, d, a, a*1e-6);
92     }
93 jpye 1891
94     fprintf(stderr,"Tests completed OK (maximum error = %0.5f%%)\n",maxerr);
95     exit(0);
96     }
97 jpye 1886
98 jpye 1891 int helm_check_u(const HelmholtzData *d, unsigned ntd, const TestData *td){
99     unsigned i;
100 jpye 1901 double T,rho,u,err,se = 0,sse = 0;
101 jpye 1891 unsigned n = ntd;
102     double tol = 1e-1;
103    
104     fprintf(stderr,"INTERNAL ENERGY VALUES\n\n");
105     fprintf(stderr,"%-18s\t%-18s\t%-18s\t%-18s\t%-18s\n","T","rho","u","du","%err");
106 jpye 1886 for(i=0; i<n;++i){
107     T = td[i].T+273.15;
108     rho = td[i].rho;
109 jpye 1891 u = td[i].u*1e3;
110     err = u - helmholtz_u(T,rho,d);
111     se += err;
112     sse += err*err;
113     fprintf(stderr,"%.12e\t%.12e\t%.12e\t%.12e\t%.6f\n",T,rho,u,err,err/u*100.);
114 jpye 1901 }
115     fprintf(stderr,"average error = %.10e\n",se/n);
116     fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
117     }
118 jpye 1891
119 jpye 1901 int helm_check_s(const HelmholtzData *d, unsigned ntd, const TestData *td){
120     unsigned i;
121     double T,rho,s,err,se = 0,sse = 0;
122     unsigned n = ntd;
123     double tol = 1e-1;
124    
125     fprintf(stderr,"ENTROPY VALUES\n\n");
126     fprintf(stderr,"%-18s\t%-18s\t%-18s\t%-18s\t%-18s\n","T","rho","s","ds","%err");
127     for(i=0; i<n;++i){
128     T = td[i].T + 273.15;
129     rho = td[i].rho;
130     s = td[i].s*1e3;
131     err = s - helmholtz_s(T,rho,d);
132     se += err;
133     sse += err*err;
134     fprintf(stderr,"%.12e\t%.12e\t%.12e\t%.12e\t%.6f\n",T,rho,s,err,err/s*100.);
135 jpye 1886 }
136 jpye 1891 fprintf(stderr,"average error = %.10e\n",se/n);
137     fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
138 jpye 1886 }
139    

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