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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1898 - (show annotations) (download) (as text)
Thu Sep 25 07:01:05 2008 UTC (15 years, 9 months ago) by jpye
File MIME type: text/x-csrc
File size: 2999 byte(s)
Debugging hydrogen, checked helm_resid_del values against spread, seem OK...
1 #include "test.h"
2
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math.h>
7
8
9 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 double se = 0, sse = 0;
15
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 /* 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 #if 0
41 /* Checking internal energy values (proves phi0_tau, phir_tau) */
42
43 fprintf(stderr,"INTERNAL ENERGY TESTS\n");
44 for(i=0; i<n;++i){
45 T = td[i].T+273.15;
46 rho = td[i].rho;
47 u = td[i].u*1e3;
48 ASSERT_TOL(helmholtz_u, T, rho, d, u, 1e3*u);
49 }
50
51 /* Checking entropy values */
52
53 fprintf(stderr,"ENTROPY TESTS\n");
54 se = 0, sse = 0;
55 for(i=0; i<n;++i){
56 T = td[i].T+273.15;
57 rho = td[i].rho;
58 s = td[i].s*1e3;
59 ASSERT_TOL(helmholtz_s, T, rho, d, s, 1e-6*s);
60 }
61
62 /* checking enthalpy values */
63 fprintf(stderr,"ENTHALPY TESTS\n");
64 se = 0, sse = 0;
65 for(i=0; i<n;++i){
66 T = td[i].T+273.15;
67 rho = td[i].rho;
68 h = td[i].h*1e3;
69 #if 0
70 double err = h - helmholtz_h(T,rho,d);
71 se += err;
72 sse += err*err;
73 fprintf(stderr,"%.12e\t%.12e\t%.12e\t%.12e\n",T,rho,u,err);
74 #else
75 ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, h, 1E3);
76 #endif
77 }
78 #if 0
79 fprintf(stderr,"average error = %.10e\n",se/n);
80 fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
81 exit(1);
82 #endif
83
84 /* Checking helmholtz energy values */
85
86 fprintf(stderr,"HELMHOLTZ ENERGY TESTS\n");
87 for(i=0; i<n;++i){
88 T = td[i].T+273.15;
89 rho = td[i].rho;
90 a = td[i].a*1e3;
91 //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(a - helmholtz_a(T,rho,d)));
92 ASSERT_TOL(helmholtz_a, T, rho, d, a, a*1e-6);
93 }
94
95 #endif
96 fprintf(stderr,"Tests completed OK (maximum error = %0.5f%%)\n",maxerr);
97 exit(0);
98 }
99
100 int helm_check_u(const HelmholtzData *d, unsigned ntd, const TestData *td){
101 unsigned i;
102 double T,rho,u,err,se,sse;
103 unsigned n = ntd;
104 double tol = 1e-1;
105
106 fprintf(stderr,"INTERNAL ENERGY VALUES\n\n");
107 fprintf(stderr,"%-18s\t%-18s\t%-18s\t%-18s\t%-18s\n","T","rho","u","du","%err");
108 for(i=0; i<n;++i){
109 if(td[i].p < 1.0) continue;
110 if(td[i].p > 1.0) break;
111 T = td[i].T+273.15;
112 rho = td[i].rho;
113 u = td[i].u*1e3;
114 err = u - helmholtz_u(T,rho,d);
115 se += err;
116 sse += err*err;
117 fprintf(stderr,"%.12e\t%.12e\t%.12e\t%.12e\t%.6f\n",T,rho,u,err,err/u*100.);
118
119 if(fabs(err)>fabs(u*tol)){
120 fprintf(stderr,"ERROR, exceeded error tol %f%%\n",tol*100);
121 exit(1);
122 }
123 }
124 fprintf(stderr,"average error = %.10e\n",se/n);
125 fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
126 }
127

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