/[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 2285 - (show annotations) (download) (as text)
Sat Aug 14 13:47:07 2010 UTC (10 years, 1 month ago) by jpye
File MIME type: text/x-chdr
File size: 2817 byte(s)
Added routine to calculate ideal->m and ideal->c for desired reference state values.
Adjusted toluene reference state so that s=0, h=0 for liquid at the triple pt.
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 Calculate values of 'c' and 'm' for the IdealData, based on expected values of h, s at reference
25 state.
26 */
27 int helm_calc_offsets(double Tref, double rhoref, double href, double sref, const HelmholtzData *d);
28
29
30 /**
31 Check 'u' values and output discrepancy for plotting.
32 */
33 int helm_check_u(const HelmholtzData *d, unsigned ntd, const TestData *td);
34
35 /**
36 Check dp/dT values (rho constant) by comparison with finite
37 difference estimates (check that helmholtz_p is working first!)
38 */
39 int helm_check_p_T(const HelmholtzData *d, unsigned ntd, const TestData *td);
40
41
42 int helm_check_d2pdrho2_T(const HelmholtzData *d, unsigned ntd, const TestData *td);
43
44 /*
45 Check the value of critical pressure given in the species data.
46 */
47 int helm_check_p_c(const HelmholtzData *d);
48
49 #define TEST_VERBOSE
50
51 #ifdef TEST_VERBOSE
52 # define TEST_SUCCESS(FN,PARAM1,PARAM2,PARAM3,VAL) \
53 fprintf(stderr," OK, %s(%f,%f,%s) = %8.2e with %.6f%% err.\n"\
54 ,FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\
55 )
56 #else
57 # define TEST_SUCCESS
58 #endif
59
60 /* a simple macro to actually do the testing */
61 #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
62 double cval; cval = FN(PARAM1,PARAM2,PARAM3);\
63 double err; err = cval - (double)(VAL);\
64 double relerrpc = (cval-(VAL))/(VAL)*100;\
65 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
66 if(fabs(err)>fabs(TOL)){\
67 fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %.5e,"\
68 " should be %.5e, error is %.10e (%.2f%%)!\n"\
69 , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\
70 ,relerrpc\
71 );\
72 exit(1);\
73 }else{\
74 TEST_SUCCESS(#FN,PARAM1,PARAM2,PARAM3,VAL);\
75 }\
76 }
77
78 /* even simpler testing of an assertion */
79 #define ASSERT_TOL_VAL(CALC,REF,TOL) {\
80 double cval = (CALC);\
81 double rval = (REF);\
82 double relerrpc = (cval-rval)/100.;\
83 if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\
84 if(fabs(err)>fabs(TOL)){\
85 fprintf(stderr,"ERROR in line %d: value of '%s' = %.5e,"\
86 " should be %.5e, error is %.10e (%.2f%%)!\n"\
87 ,__LINE__,#CALC,cval,rval,cval-rval,relerrpc\
88 );\
89 exit(1);\
90 }else{\
91 fprintf(stderr," OK, %s = %8.2e with %0.6f%% err.\n"\
92 ,#CALC,rval,relerrpc\
93 );\
94 }\
95 }
96
97 #endif
98

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