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

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