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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2111 - (show annotations) (download) (as text)
Tue Dec 8 03:05:36 2009 UTC (10 years, 7 months ago) by jpye
File MIME type: text/x-chdr
File size: 1836 byte(s)
CO2 correlation looks to be working now.
Work on support for SUNDIALS on Windows.
1 #ifndef HELMHOLTZ_TEST_H
2 #define HELMHOLTZ_TEST_H
3
4 #include "helmholtz.h"
5
6 /* Macros and type declarations for running simple test cases */
7
8 typedef struct{double T,p,rho,u,h,s,cv,cp,cp0,a;} TestData;
9
10 /*, {Temperature, Pressure, Density, Int. Energy, Enthalpy, Entropy, Cp, Cp0, Helmholtz}
11
12 /**
13 Run tests for p, u, h, s, a against values from a user-provided TestData array
14 Tolerances are specified in the cdoe, in test.c.
15
16 @param temp_unit Set to 'C' for celsius or 'K' for Kelvin.
17
18 @return 1 if any failures occurred.
19 */
20 int helm_run_test_cases(const HelmholtzData *d, unsigned ntd, const TestData *td, int temp_unit);
21
22 /**
23 Check 'u' values and output discrepancy for plotting.
24 */
25 int helm_check_u(const HelmholtzData *d, unsigned ntd, const TestData *td);
26
27 /**
28 Check dp/dT values (rho constant) by comparison with finite
29 difference estimates (check that helmholtz_p is working first!)
30 */
31 int helm_check_p_T(const HelmholtzData *d, unsigned ntd, const TestData *td);
32
33 #define TEST_VERBOSE
34
35 #ifdef TEST_VERBOSE
36 # define TEST_SUCCESS(FN,PARAM1,PARAM2,PARAM3,VAL) \
37 fprintf(stderr," OK, %s(%f,%f,%s) = %8.2e with %.6f%% err.\n"\
38 ,FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\
39 )
40 #else
41 # define TEST_SUCCESS
42 #endif
43
44 /* a simple macro to actually do the testing */
45 #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
46 double cval; cval = FN(PARAM1,PARAM2,PARAM3);\
47 double err; err = cval - (double)(VAL);\
48 double relerrpc = (cval-(VAL))/(VAL)*100;\
49 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
50 if(fabs(err)>fabs(TOL)){\
51 fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %.5e,"\
52 " should be %.5e, error is %.10e (%.2f%%)!\n"\
53 , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\
54 ,relerrpc\
55 );\
56 exit(1);\
57 }else{\
58 TEST_SUCCESS(#FN,PARAM1,PARAM2,PARAM3,VAL);\
59 }\
60 }
61
62 #endif

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