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

Diff of /trunk/models/johnpye/fprops/nitrogen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1885 by jpye, Thu Sep 18 13:33:46 2008 UTC revision 1886 by jpye, Fri Sep 19 07:22:54 2008 UTC
# Line 117  const HelmholtzData helmholtz_data_nitro Line 117  const HelmholtzData helmholtz_data_nitro
117  #ifdef TEST  #ifdef TEST
118    
119  #include "ideal_impl.h"  #include "ideal_impl.h"
 #include <assert.h>  
 #include <stdlib.h>  
 #include <stdio.h>  
 #include <math.h>  
120    
121  /* a simple macro to actually do the testing */  #include "test.h"
122  #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\  #include <math.h>
123          double cval; cval = FN(PARAM1,PARAM2,PARAM3);\  #include <stdio.h>
124          double err; err = cval - (double)(VAL);\  #include <assert.h>
         double relerrpc = (cval-(VAL))/(VAL)*100;\  
         if(fabs(relerrpc)>maxerr)maxerr=fabs(relerrpc);\  
         if(fabs(err)>fabs(TOL)){\  
             fprintf(stderr,"ERROR in line %d: value of '%s(%f,%f,%s)' = %f,"\  
                 " should be %f, error is %f (%.2f%%)!\n"\  
                 , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\  
                 ,relerrpc\  
             );\  
             exit(1);\  
         }else{\  
             fprintf(stderr,"    OK, %s(%f,%f,%s) = %8.2e with %.6f%% err.\n"\  
                 ,#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\  
             );\  
         }\  
     }  
   
 typedef struct{double T,p,rho,u,h,s,cv,cp,cp0,a;} TestData;  
 const TestData td[]; const unsigned ntd;  
125    
126  double phi0(double tau, double del){  double phi0(double tau, double del){
127      return log(del) - log(tau) - 12.76953 - 0.007841630*tau + 3.5*log(tau) - 1.934819e-4/tau - 1.247742e-5/(tau*tau) + 6.678326e-8/(tau*tau*tau) + 1.012941*log(1 - exp(-26.65788*tau));      return log(del) - log(tau) - 12.76953 - 0.007841630*tau + 3.5*log(tau) - 1.934819e-4/tau - 1.247742e-5/(tau*tau) + 6.678326e-8/(tau*tau*tau) + 1.012941*log(1 - exp(-26.65788*tau));
# Line 178  double phi0tau(double tau, double del){ Line 156  double phi0tau(double tau, double del){
156      return res;      return res;
157  }  }
158    
159    const TestData td[]; const unsigned ntd;
160    
161  int main(void){  int main(void){
162    
163      double rho, T, p, u, h, a, s, cp0;      double rho, T, p, u, h, a, s, cp0;
# Line 207  int main(void){ Line 187  int main(void){
187    
188      fprintf(stderr,"Running through %d test points...\n",n);      fprintf(stderr,"Running through %d test points...\n",n);
189    
   
 #define CP0_TEMP(T,RHO,DATA) helmholtz_cp0(T,DATA)  
     fprintf(stderr,"CP0 TESTS\n");  
     for(i=0; i<n;++i){  
         cp0 = td[i].cp0*1e3;  
         ASSERT_TOL(CP0_TEMP, td[i].T+273.15, td[i].rho, d, cp0, cp0*1e-6);  
     }  
 #undef CP0_TEMP  
   
   
190      fprintf(stderr,"CONSISTENCY TESTS (of test data): u, T, s, a...");      fprintf(stderr,"CONSISTENCY TESTS (of test data): u, T, s, a...");
191      for(i=0; i<n; ++i){      for(i=0; i<n; ++i){
192          u = td[i].u*1e3;          u = td[i].u*1e3;
# Line 241  int main(void){ Line 211  int main(void){
211      }      }
212      fprintf(stderr,"done\n");      fprintf(stderr,"done\n");
213    
 #if 1  
     fprintf(stderr,"CONSISTENCY TESTS (of calculated values): a=u+Ts, h=u+p/rho\n");  
     for(i=0; i<n; ++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         s = helmholtz_s(T,rho,d);  
         u = helmholtz_u(T,rho,d);  
         p = helmholtz_p(T,rho,d);  
         ASSERT_TOL(helmholtz_a, T, rho, d, u-T*s, (u-T*s)*1e-6);  
         ASSERT_TOL(helmholtz_h, T, rho, d, u+p/rho, (u+p/rho)*1e-6);  
     }  
     fprintf(stderr,"done\n");  
 #endif  
   
     fprintf(stderr,"PRESSURE TESTS\n");  
     for(i=0; i<n;++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         p = td[i].p*1e6;  
         ASSERT_TOL(helmholtz_p, T, rho, d, p, p*1e-6);  
     }  
   
214  #if 0  #if 0
215      /* can only use this check if c,m haven't been offset from original */      /* can only use this check if c,m haven't been offset from original */
216      fprintf(stderr,"CONSISTENCY TESTS (with handwritten phi0 expr)\n");      fprintf(stderr,"CONSISTENCY TESTS (with handwritten phi0 expr)\n");
# Line 284  int main(void){ Line 232  int main(void){
232      }      }
233  #endif  #endif
234    
235        /* check evaluation against the test dataset */
236      fprintf(stderr,"INTERNAL ENERGY TESTS\n");      return helm_run_test_cases(d, ntd, td);
     for(i=0; i<n;++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         u = td[i].u*1e3;  
         //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(u - helmholtz_u(T,rho,d)));  
         ASSERT_TOL(helmholtz_u, td[i].T+273.15, td[i].rho, d, u, u*1e-6);  
     }  
   
     fprintf(stderr,"ENTROPY TESTS\n");  
     double se = 0, sse = 0;  
     for(i=0; i<n;++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         s = td[i].s*1e3;  
         double err = s - helmholtz_s(T,rho,d);  
         se += err;  
         sse += err*err;  
         //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(s - helmholtz_s(T,rho,d)));  
         ASSERT_TOL(helmholtz_s, T, rho, d, s, 1e-6*s);  
     }  
     //fprintf(stderr,"average error = %.10e\n",se/n);  
     //fprintf(stderr,"sse - n se^2 = %.3e\n",sse - n*se*se);  
     //exit(1);  
   
     fprintf(stderr,"HELMHOLTZ ENERGY TESTS\n");  
     for(i=0; i<n;++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         a = td[i].a*1e3;  
         //fprintf(stderr,"%.20e\t%.20e\t%.20e\n",T,rho,(a - helmholtz_a(T,rho,d)));  
         ASSERT_TOL(helmholtz_a, T, rho, d, a, a*1e-6);  
     }  
     //exit(1);  
   
     fprintf(stderr,"ENTHALPY TESTS\n");  
     for(i=0; i<n;++i){  
         T = td[i].T+273.15;  
         rho = td[i].rho;  
         h = td[i].h*1e3;  
         //fprintf(stderr,"%.20e\n",(h - helmholtz_h(T,rho,d)) );  
         ASSERT_TOL(helmholtz_h, td[i].T+273.15, td[i].rho, d, h, 1E3);  
     }  
   
     fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);  
     exit(0);  
237  }  }
238    
239  const TestData td[] = {  const TestData td[] = {

Legend:
Removed from v.1885  
changed lines
  Added in v.1886

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