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

Annotation of /trunk/models/johnpye/fprops/fluids.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2788 - (hide annotations) (download) (as text)
Wed Jun 25 06:39:09 2014 UTC (10 years ago) by jpye
File MIME type: text/x-csrc
File size: 2454 byte(s)
kludgy fix to restore test solver_qrslv to non-crashing state (thcond missing data workaround in FPROPS)
1 jpye 2299 #include "fluids.h"
2     #include "fluids/fluids_list.h"
3 jpye 2654 #include "fprops.h"
4 jpye 2711 #include "helmholtz.h"
5     #include "pengrob.h"
6 jpye 2299
7     #include <string.h>
8 jpye 2654 #include <stdio.h>
9 jpye 2681 #include <assert.h>
10 jpye 2299
11 jpye 2788 //#define FLUIDS_DEBUG
12 jpye 2654 #ifdef FLUIDS_DEBUG
13     # include "color.h"
14 jpye 2788 # define MSG FPROPS_MSG
15     # define ERRMSG FPROPS_ERRMSG
16 jpye 2654 #else
17     # define MSG(ARGS...) ((void)0)
18 jpye 2671 # define ERRMSG(ARGS...) ((void)0)
19     #endif
20    
21 jpye 2654 /* declare the external EosData objects */
22 jpye 2299 #define X
23 jpye 2654 #define F(NAME) extern const EosData eos_##NAME;
24 jpye 2299 FLUIDS(F,X)
25 jpye 2654 #undef F
26     #define F(NAME) extern const EosData eos_rpp_##NAME;
27     RPPFLUIDS(F,X)
28     #undef F
29 jpye 2299 #undef X
30    
31 jpye 2654 /* create a list of all the fluids from fluids/fluids_list.h */
32 jpye 2299 #define X ,
33 jpye 2654 #define F(NAME) &eos_##NAME
34     const EosData *fluids[] ={ FLUIDS(F,X)
35     #undef F
36     #define F(NAME) &eos_rpp_##NAME
37     , RPPFLUIDS(F,X)
38     };
39 jpye 2299 #undef X
40     #undef F
41    
42     /* count them */
43     #define X +
44     #define F(NAME) 1
45 jpye 2654 static int nfluids = 0 + FLUIDS(F,X) + RPPFLUIDS(F,X);
46 jpye 2299 #undef F
47     #undef X
48    
49 jpye 2662 const PureFluid *fprops_fluid(const char *name, const char *corrtype, const char *source){
50 jpye 2299 int i;
51 jpye 2662 MSG("Looking for fluid '%s' of type '%s', with source text '%s'",name,corrtype,source);
52 jpye 2299 for(i = 0; i < nfluids; ++i){
53     if(0==strcmp(name, fluids[i]->name)){
54 jpye 2662 MSG("Got '%s' (type %d, source '%s')",name,fluids[i]->type,fluids[i]->source);
55     if(source){
56     if(fluids[i]->source && NULL != strstr(fluids[i]->source, source)){
57     MSG("Source '%s' OK",source);
58     }else{
59     MSG("Source '%s' not matched",source);
60     continue;
61     }
62     }
63 jpye 2654 if(fprops_corr_avail(fluids[i],corrtype)){
64 jpye 2662 MSG("Match! %d",i);
65 jpye 2654 return fprops_prepare(fluids[i],corrtype);
66     }else{
67     MSG("No match");
68     }
69 jpye 2299 }
70     }
71 jpye 2671 ERRMSG("No fluid found matching name '%s', type '%s' and source '%s'",name,corrtype,source);
72 jpye 2299 return NULL;
73     }
74 jpye 2301
75    
76     int fprops_num_fluids(){
77     return nfluids;
78     }
79    
80 jpye 2654 const PureFluid *fprops_get_fluid(int i){
81 jpye 2301 if(i >= 0 && i < nfluids){
82 jpye 2654 PureFluid *P = fprops_prepare(fluids[i],NULL);
83     MSG("Fluid '%s' with T_t = %f",P->name,P->data->T_t);
84     return P;
85 jpye 2301 }
86     return NULL;
87     }
88    
89 jpye 2711 void fprops_fluid_destroy(PureFluid *P){
90 jpye 2681 MSG("Freeing data for lfuid '%s'",P->name);
91     switch(P->type){
92     case FPROPS_HELMHOLTZ:
93     helmholtz_destroy(P);
94     break;
95     case FPROPS_PENGROB:
96     pengrob_destroy(P);
97     break;
98     case FPROPS_CUBIC:
99     assert(FPROPS_CUBIC != P->type);
100     break;
101     case FPROPS_IDEAL:
102     case FPROPS_REDKW:
103     case FPROPS_SOAVE:
104     case FPROPS_MBWR:
105     ERRMSG("Not implemented: fluid '%s' of type %d to be destroyed",P->name,P->type);
106     break;
107     }
108     }
109 jpye 2301

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