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

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

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

revision 1985 by jpye, Tue Feb 3 01:15:17 2009 UTC revision 1986 by jpye, Tue Feb 3 05:19:15 2009 UTC
# Line 115  const HelmholtzData helmholtz_data_water Line 115  const HelmholtzData helmholtz_data_water
115      , 3 /* gaussian terms */      , 3 /* gaussian terms */
116      , (const HelmholtzGausTerm[]){      , (const HelmholtzGausTerm[]){
117          /* n, t, d, alpha, beta, gamma, epsilon */          /* n, t, d, alpha, beta, gamma, epsilon */
118          {-0.31306260323435E2, 0, 3, 20, 150, 1.21, 1}          {-0.31306260323435e2, 0, 3, 20, 150, 1.21, 1}
119          ,{0.31546140237781E2, 1, 3, 20, 150, 1.21, 1}          ,{0.31546140237781e2, 1, 3, 20, 150, 1.21, 1}
120          ,{-0.25213154341695E4,4, 3, 20, 250, 1.25, 1}          ,{-0.25213154341695e4,4, 3, 20, 250, 1.25, 1}
121      }      }
122      , 2 /* critical terms */      , 2 /* critical terms */
123      , (const HelmholtzCritTerm[]){      , (const HelmholtzCritTerm[]){
# Line 127  const HelmholtzData helmholtz_data_water Line 127  const HelmholtzData helmholtz_data_water
127      }      }
128  };  };
129    
130    #ifdef TEST
131  /*  /*
132      Test suite. These tests attempt to validate the current code using      Test suite. These tests attempt to validate the current code using
133      a few sample figures output by REFPROP 7.0.      a few sample figures output by REFPROP 7.0.
# Line 136  const HelmholtzData helmholtz_data_water Line 136  const HelmholtzData helmholtz_data_water
136    
137      ./test.py water      ./test.py water
138  */  */
 #ifdef TEST  
139    
140  /*  /*
141      some code from freesteam, http://freesteam.sf.net/, which has been thoroughly      some code from freesteam, http://freesteam.sf.net/, which has been thoroughly
# Line 181  double phi0(const double delta, const do Line 180  double phi0(const double delta, const do
180      return sum;      return sum;
181  }  }
182    
183    typedef struct{double T, rho, p, cv, w, s;} TestDataIAPWS95;
184    const TestDataIAPWS95 td[]; const unsigned ntd;
185    
186  int main(void){  int main(void){
187      double rho, T;      double rho, T;
188      const HelmholtzData *d;      const HelmholtzData *d;
189    
190      d = &helmholtz_data_water;      d = &helmholtz_data_water;
191      double maxerr = 0;      double maxerr = 0;
192        unsigned i;
193    
194  /* a simple macro to actually do the testing */  /* a simple macro to actually do the testing */
195  #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\  #define ASSERT_TOL(FN,PARAM1,PARAM2,PARAM3,VAL,TOL) {\
# Line 200  int main(void){ Line 203  int main(void){
203                  , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\                  , __LINE__, #FN,PARAM1,PARAM2,#PARAM3, cval, VAL,cval-(VAL)\
204                  ,relerrpc\                  ,relerrpc\
205              );\              );\
206              exit(1);\              /*exit(1);*/\
207          }else{\          }else{\
208              fprintf(stderr,"    OK, %s(%f,%f,%s) = %8.2e with %.8f%% err.\n"\              fprintf(stderr,"    OK, %s(%f,%f,%s) = %8.2e with %.8f%% err.\n"\
209                  ,#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\                  ,#FN,PARAM1,PARAM2,#PARAM3,VAL,relerrpc\
# Line 220  int main(void){ Line 223  int main(void){
223          }          }
224      }      }
225    
226      fprintf(stderr,"IAPWS95 TABLE 6 TESTS\n");      /* LOW-LEVEL TEST DATA PROVIDED IN IAPWS95 */
227    
228        fprintf(stderr,"\nIAPWS95 TABLE 6 TESTS\n");
229      T = 500.; /* K */      T = 500.; /* K */
230      rho = 838.025; /* kg/m³ */      rho = 838.025; /* kg/m³ */
231      double tau = d->T_star / T;      double tau = d->T_star / T;
232      double delta = rho / d->rho_star;      double delta = rho / d->rho_star;
233    
234      ASSERT_TOL(helm_ideal, tau, delta, d->ideal, 0.204797733E1, 1e-6);      ASSERT_TOL(helm_ideal, tau, delta, d->ideal, 0.204797733E1, 1e-8);
235      ASSERT_TOL(helm_ideal_tau, tau, delta, d->ideal, 0.904611106E1, 1e-6);      ASSERT_TOL(helm_ideal_tau, tau, delta, d->ideal, 0.904611106E1, 1e-8);
236      ASSERT_TOL(HELM_IDEAL_DELTAU, tau, delta, d->ideal, 0., 1e-6);      ASSERT_TOL(HELM_IDEAL_DELTAU, tau, delta, d->ideal, 0., 1e-8);
237            
238      double phitt = helm_ideal_tautau(tau, d->ideal);      double phitt = helm_ideal_tautau(tau, d->ideal);
239      double val = (-0.193249185E1);      double val = (-0.193249185E1);
240      double err = phitt - val;      double err = phitt - val;
241      if(fabs(err) > 1e-6){      if(fabs(err) > 1e-8){
242          fprintf(stderr,"ERROR in helm_ideal_tautau near line %d\n",__LINE__);          fprintf(stderr,"ERROR in helm_ideal_tautau near line %d\n",__LINE__);
243          exit(1);          exit(1);
244      }else{      }else{
# Line 251  int main(void){ Line 256  int main(void){
256      ASSERT_TOL(helm_resid_tautau, tau, delta, d, -0.223440737E1, 1e-8);      ASSERT_TOL(helm_resid_tautau, tau, delta, d, -0.223440737E1, 1e-8);
257      ASSERT_TOL(helm_resid_deltau, tau, delta, d, -0.112176915e1, 1e-8);      ASSERT_TOL(helm_resid_deltau, tau, delta, d, -0.112176915e1, 1e-8);
258    
259        fprintf(stderr,"\nADDITIONAL LOW-LEVEL TESTS NEAR CRITICAL POINT\n");
260        
261        T = 647.; /* K */
262        rho = 358.; /* kg/m³ */
263        tau = d->T_star / T;
264        delta = rho / d->rho_star;
265    
266        /* this test value calculated from pressure using REFPROP 8 */
267        ASSERT_TOL(helmholtz_a, T, rho, d, -8.286875181e5, 1e-4);
268        ASSERT_TOL(helm_resid_del, tau, delta, d, -7.14012024e-1, 1e-8);
269    
270        fprintf(stderr,"\nIAPWS95 SINGLE-PHASE TESTS\n");
271        for(i=0; i<ntd; ++i){
272            double T = td[i].T;
273            double rho = td[i].rho;
274            double p = td[i].p * 1e6; /* Pa */
275            double cv = td[i].cv / 1e3; /* J/kgK */
276            double w = td[i].w; /* m/s */
277            double s = td[i].s * 1e3; /* J/kgK */
278            //fprintf(stderr,"T = %f, rho = %f, p = %f\n",T,rho,p);
279            ASSERT_TOL(helmholtz_s, T, rho, d, s, s*1e-8);
280            ASSERT_TOL(helmholtz_p, T, rho, d, p, p*1e-8);
281        }
282    
283      fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);      fprintf(stderr,"Tests completed OK (maximum error = %0.2f%%)\n",maxerr);
284      exit(0);      exit(0);
285  }  }
286    
287    /* HIGHER-LEVEL TEST-DATA PROVIDED IN IAPWS95 */
288    
289    const TestDataIAPWS95 td[] = {
290        {300, 0.9965560e3, 0.992418352e-1, 0.413018112e1, 0.150151914e4, 0.393062643}
291        ,{300, 0.1005308e4, 0.200022515e2,  0.406798347e1, 0.153492501e4, 0.387405401}
292        ,{300, 0.1188202e4, 0.700004704e3,  0.346135580e1, 0.244357992e4, 0.132609616}
293        ,{500, 0.4350000,   0.999679423e-1, 0.150817541e1, 0.548314253e3, 0.794488271e1}
294        ,{500, 0.4532000e1, 0.999938125,    0.166991025e1, 0.535739001e3, 0.682502725e1}
295        ,{500, 0.8380250e3, 0.100003858e2,  0.322106219e1, 0.127128441e4, 0.256690919e1}
296        ,{500, 0.1084564e4, 0.700000405e3,  0.307437693e1, 0.241200877e4, 0.203237509e1}
297        ,{647, 0.3580000e3, 0.220384756e2,  0.618315728e1, 0.252145078e3, 0.432092307e1}
298        ,{900, 0.2410000,   0.100062559,    0.175890657e1, 0.724027147e3, 0.916653194e1}
299        ,{900, 0.5261500e2, 0.200000690e2,  0.193510526e1, 0.698445674e3, 0.659070225e1}
300        ,{900, 0.8707690e3, 0.700000006e3,  0.266422350e1, 0.201933608e4, 0.417223802e1}
301    };
302    
303    const unsigned ntd = sizeof(td)/sizeof(TestDataIAPWS95);
304    
305  #endif  #endif
306    

Legend:
Removed from v.1985  
changed lines
  Added in v.1986

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