/[ascend]/branches/sid/models/johnpye/fprops/sat.c
ViewVC logotype

Diff of /branches/sid/models/johnpye/fprops/sat.c

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

revision 2661 by jpye, Thu Jan 17 00:15:12 2013 UTC revision 2662 by jpye, Fri Jan 18 00:34:51 2013 UTC
# Line 237  void fprops_triple_point(double *p_t_out Line 237  void fprops_triple_point(double *p_t_out
237          ERRMSG("Note: data for '%s' does not include a valid triple point temperature.",d->name);          ERRMSG("Note: data for '%s' does not include a valid triple point temperature.",d->name);
238      }      }
239    
   
240      MSG("Calculating saturation for '%s' (T_c = %f, p_c = %f) at T = %f",d->name, d->data->T_c, d->data->p_c, d->data->T_t);      MSG("Calculating saturation for '%s' (T_c = %f, p_c = %f) at T = %f",d->name, d->data->T_c, d->data->p_c, d->data->T_t);
241      fprops_sat_T(d->data->T_t, &p_t, &rhof_t, &rhog_t,d,err);      fprops_sat_T(d->data->T_t, &p_t, &rhof_t, &rhog_t,d,err);
242      if(*err)return;      if(*err)return;
# Line 252  typedef struct{ Line 251  typedef struct{
251      const PureFluid *P;      const PureFluid *P;
252      double p;      double p;
253      FpropsError *err;      FpropsError *err;
254        double Terr;
255  } SatPResidData;  } SatPResidData;
256    
257  static ZeroInSubjectFunction sat_p_resid;  static ZeroInSubjectFunction sat_p_resid;
# Line 259  static double sat_p_resid(double T, void Line 259  static double sat_p_resid(double T, void
259  #define D ((SatPResidData *)user_data)  #define D ((SatPResidData *)user_data)
260      double p, rhof, rhog;      double p, rhof, rhog;
261      fprops_sat_T(T, &p, &rhof, &rhog, D->P, D->err);      fprops_sat_T(T, &p, &rhof, &rhog, D->P, D->err);
262        if(*(D->err))D->Terr = T;
263      MSG("T = %f --> p = %f, rhof = %f, rhog = %f, RESID %f", T, p, rhof, rhog, (p - D->p));      MSG("T = %f --> p = %f, rhof = %f, rhog = %f, RESID %f", T, p, rhof, rhog, (p - D->p));
264      //if(*(D->err))MSG("Error: %s",fprops_error(*(D->err)));      //if(*(D->err))MSG("Error: %s",fprops_error(*(D->err)));
265      //if(*(D->err))return -1;      //if(*(D->err))return -1;
# Line 276  static double sat_p_resid(double T, void Line 277  static double sat_p_resid(double T, void
277      solver...      solver...
278  */    */  
279  void fprops_sat_p(double p, double *T_sat, double *rho_f, double *rho_g, const PureFluid *P, FpropsError *err){  void fprops_sat_p(double p, double *T_sat, double *rho_f, double *rho_g, const PureFluid *P, FpropsError *err){
     MSG("HELLO");  
280      if(*err){      if(*err){
281          MSG("ERROR FLAG ALREADY SET");          MSG("ERROR FLAG ALREADY SET");
282      }      }
# Line 287  void fprops_sat_p(double p, double *T_sa Line 287  void fprops_sat_p(double p, double *T_sa
287          *rho_g = P->data->rho_c;          *rho_g = P->data->rho_c;
288          return;          return;
289      }      }
290      SatPResidData D = {P, p, err};      /* FIXME what about checking triple point pressure? */
291        
292    
293        SatPResidData D = {P, p, err, 0};
294      MSG("Solving saturation conditions at p = %f", p);      MSG("Solving saturation conditions at p = %f", p);
295      double p1, T, resid;      double p1, T, resid;
296      int errn;      int errn;
# Line 295  void fprops_sat_p(double p, double *T_sa Line 298  void fprops_sat_p(double p, double *T_sa
298      if(Tt == 0)Tt = 0.2* P->data->T_c;      if(Tt == 0)Tt = 0.2* P->data->T_c;
299      errn = zeroin_solve(&sat_p_resid, &D, Tt, P->data->T_c, 1e-5, &T, &resid);      errn = zeroin_solve(&sat_p_resid, &D, Tt, P->data->T_c, 1e-5, &T, &resid);
300      if(*err){      if(*err){
301          ERRMSG("Error during zeroin_solve: %s", fprops_error(*err));          MSG("FPROPS error within zeroin_solve iteration ('%s', p = %f, p_c = %f): %s"
302          return;              , P->name, p, P->data->p_c, fprops_error(*err)
303            );
304      }      }
305      if(errn){      if(errn){
306          ERRMSG("Failed to solve saturation at p = %f.",p);          ERRMSG("Failed to solve saturation at p = %f.",p);
307          *err = FPROPS_SAT_CVGC_ERROR;          *err = FPROPS_SAT_CVGC_ERROR;
308          return;          return;
309        }else{
310            if(*err){
311                ERRMSG("Ignoring error inside zeroin_solve iteration at T = %f",D.Terr);
312            }
313            *err = FPROPS_NO_ERROR;
314      }      }
315      fprops_sat_T(T, &p1, rho_f, rho_g, P, err);      fprops_sat_T(T, &p1, rho_f, rho_g, P, err);
316      if(!*err)*T_sat = T;      if(!*err)*T_sat = T;

Legend:
Removed from v.2661  
changed lines
  Added in v.2662

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