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

Contents of /branches/sid/models/johnpye/fprops/fluids.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3060 - (show annotations) (download) (as text)
Wed Aug 12 16:12:37 2015 UTC (3 years, 9 months ago) by sid
File MIME type: text/x-csrc
File size: 2467 byte(s)
update

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

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