/[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 1886 - (show annotations) (download) (as text)
Fri Sep 19 07:22:54 2008 UTC (15 years, 8 months ago) by jpye
File MIME type: text/x-csrc
File size: 2289 byte(s)
Adding separate file with basic test routine.
1 #include "test.h"
2
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math.h>
7
8 int helm_run_test_cases(const HelmholtzData *d, unsigned ntd, const TestData *td){
9
10 double rho, T, p, u, h, a, s, cp0;
11
12 double maxerr = 0;
13
14 unsigned i;
15 const unsigned n = ntd;
16
17 fprintf(stderr,"Running through %d test points...\n",n);
18
19 /* Checking CP0 values */
20
21 #define CP0_TEMP(T,RHO,DATA) helmholtz_cp0(T,DATA)
22 fprintf(stderr,"CP0 TESTS\n");
23 for(i=0; i<n;++i){
24 cp0 = td[i].cp0*1e3;
25 ASSERT_TOL(CP0_TEMP, td[i].T+273.15, td[i].rho, d, cp0, cp0*1e-6);
26 }
27 #undef CP0_TEMP
28
29 /* Checking pressure values (proves phir_delta) */
30
31 fprintf(stderr,"PRESSURE TESTS\n");
32 for(i=0; i<n;++i){
33 T = td[i].T+273.15;
34 rho = td[i].rho;
35 p = td[i].p*1e6;
36 ASSERT_TOL(helmholtz_p, T, rho, d, p, p*1e-6);
37 }
38
39 /* Checking internal energy values (proves phi0_tau, phir_tau) */
40
41 fprintf(stderr,"INTERNAL ENERGY TESTS\n");
42 for(i=0; i<n;++i){
43 T = td[i].T+273.15;
44 rho = td[i].rho;
45 u = td[i].u*1e3;
46 //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(u - helmholtz_u(T,rho,d)));
47 ASSERT_TOL(helmholtz_u, td[i].T+273.15, td[i].rho, d, u, u*1e-6);
48 }
49
50 /* Checking entropy values */
51
52 fprintf(stderr,"ENTROPY TESTS\n");
53 double se = 0, sse = 0;
54 for(i=0; i<n;++i){
55 T = td[i].T+273.15;
56 rho = td[i].rho;
57 s = td[i].s*1e3;
58 double err = s - helmholtz_s(T,rho,d);
59 se += err;
60 sse += err*err;
61 //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(s - helmholtz_s(T,rho,d)));
62 ASSERT_TOL(helmholtz_s, T, rho, d, s, 1e-6*s);
63 }
64 //fprintf(stderr,"average error = %.10e\n",se/n);
65 //fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);
66 //exit(1);
67
68 /* Checking helmholtz energy values */
69
70 fprintf(stderr,"HELMHOLTZ ENERGY TESTS\n");
71 for(i=0; i<n;++i){
72 T = td[i].T+273.15;
73 rho = td[i].rho;
74 a = td[i].a*1e3;
75 //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(a - helmholtz_a(T,rho,d)));
76 ASSERT_TOL(helmholtz_a, T, rho, d, a, a*1e-6);
77 }
78 //exit(1);
79
80 fprintf(stderr,"ENTHALPY TESTS\n");
81 for(i=0; i<n;++i){
82 T = td[i].T+273.15;
83 rho = td[i].rho;
84 h = td[i].h*1e3;
85 //fprintf(stderr,"%.20e\n",(h - helmholtz_h(T,rho,d)) );
86 ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, h, 1E3);
87 }
88
89 fprintf(stderr,"Tests completed OK (maximum error = %0.5f%%)\n",maxerr);
90 exit(0);
91 }
92

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