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

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

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

revision 1824 by jpye, Wed Aug 20 11:05:05 2008 UTC revision 1825 by jpye, Thu Aug 21 05:03:19 2008 UTC
# Line 51  Line 51 
51    FORWARD DECLARATIONS    FORWARD DECLARATIONS
52  */  */
53    
54  ExtBBoxInitFunc helmholtz_p_prepare;  ExtBBoxInitFunc helmholtz_prepare;
55  ExtBBoxFunc helmholtz_p_calc;  ExtBBoxFunc helmholtz_p_calc;
56    ExtBBoxFunc helmholtz_u_calc;
57    ExtBBoxFunc helmholtz_h_calc;
58    
59  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
60    GLOBALS    GLOBALS
# Line 102  const HelmholtzData helmholtz_data_ammon Line 104  const HelmholtzData helmholtz_data_ammon
104      }      }
105  };  };
106    
107    static const char *helmholtz_p_help = "Calculate pressure from temperature and density, using Helmholtz fundamental correlation";
108    static const char *helmholtz_u_help = "Calculate specific internal energy from temperature and density, using Helmholtz fundamental correlation";
109    static const char *helmholtz_h_help = "Calculate specific enthalpy from temperature and density, using Helmholtz fundamental correlation";
110    
111  /*------------------------------------------------------------------------------  /*------------------------------------------------------------------------------
112    REGISTRATION FUNCTION    REGISTRATION FUNCTION
113  */  */
# Line 113  const HelmholtzData helmholtz_data_ammon Line 119  const HelmholtzData helmholtz_data_ammon
119  */  */
120  extern  extern
121  ASC_EXPORT int helmholtz_register(){  ASC_EXPORT int helmholtz_register(){
     const char *helmholtz_help = "Modified Benedict-Webb-Rubin correlation for thermodynamic properties";  
122      int result = 0;      int result = 0;
123    
124      ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising HELMHOLTZ...\n");      ERROR_REPORTER_HERE(ASC_PROG_NOTE,"Initialising HELMHOLTZ...\n");
125    
126      result += CreateUserFunctionBlackBox("helmholtz_p"  #define CALCFN(NAME,INPUTS,OUTPUTS) \
127          , helmholtz_p_prepare      result += CreateUserFunctionBlackBox(#NAME \
128          , helmholtz_p_calc /* value */          , helmholtz_prepare \
129          , (ExtBBoxFunc*)NULL /* derivatives not provided yet*/          , NAME##_calc /* value */ \
130          , (ExtBBoxFunc*)NULL /* hessian not provided yet */          , (ExtBBoxFunc*)NULL /* derivatives not provided yet*/ \
131          , (ExtBBoxFinalFunc*)NULL /* finalisation not implemented */          , (ExtBBoxFunc*)NULL /* hessian not provided yet */ \
132          , 2,1 /* inputs, outputs */          , (ExtBBoxFinalFunc*)NULL /* finalisation not implemented */ \
133          , helmholtz_help          , INPUTS,OUTPUTS /* inputs, outputs */ \
134          , 0.0          , NAME##_help /* help text */ \
135      ); /* returns 0 on success */          , 0.0 \
136        ) /* returns 0 on success */
137    
138        CALCFN(helmholtz_p,2,1);
139        CALCFN(helmholtz_u,2,1);
140        CALCFN(helmholtz_h,2,1);
141    
142    #undef CALCFN
143    
144      if(result){      if(result){
145          ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);          ERROR_REPORTER_HERE(ASC_PROG_NOTE,"CreateUserFunction result = %d\n",result);
# Line 135  ASC_EXPORT int helmholtz_register(){ Line 147  ASC_EXPORT int helmholtz_register(){
147      return result;      return result;
148  }  }
149    
150  /*------------------------------------------------------------------------------  /**
151    WRAPPING FOR 'helmholtz_p'...     'helmholtz_prepare' just gets the data member and checks that it's
152        valid, and stores it in the blackbox data field.
153  */  */
154    int helmholtz_prepare(struct BBoxInterp *bbox,
 int helmholtz_p_prepare(struct BBoxInterp *bbox,  
155         struct Instance *data,         struct Instance *data,
156         struct gl_list_t *arglist         struct gl_list_t *arglist
157  ){  ){
# Line 171  int helmholtz_p_prepare(struct BBoxInter Line 183  int helmholtz_p_prepare(struct BBoxInter
183          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Component must be 'ammonia' at this stage (only one component supported)");          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Component must be 'ammonia' at this stage (only one component supported)");
184      }      }
185    
186      ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING HELMHOLTZ_P...\n");      ERROR_REPORTER_HERE(ASC_PROG_NOTE,"PREPARING HELMHOLTZ...\n");
187    
188      bbox->user_data = (void*)&helmholtz_data_ammonia;      bbox->user_data = (void*)&helmholtz_data_ammonia;
189    
190      return 0;      return 0;
191  }  }
192    
193    /*------------------------------------------------------------------------------
194      EVALULATION ROUTINES
195    */
196    
197    #define CALCPREPARE \
198        /* a few checks about the input requirements */ \
199        if(ninputs != 2)return -1; \
200        if(noutputs != 1)return -2; \
201        if(inputs==NULL)return -3; \
202        if(outputs==NULL)return -4; \
203        if(bbox==NULL)return -5; \
204        \
205        /* the 'user_data' in the black box object will contain the */\
206        /* coefficients required for this fluid; cast it to the required form: */\
207        HelmholtzData *helmholtz_data = (HelmholtzData *)bbox->user_data
208    
209  /**  /**
210      Evaluation function. This one does the actual calling to the      Evaluation function for 'helmholtz_p'.
     'helmholtz_p' routine.  
211      @param jacobian ignored      @param jacobian ignored
212      @return 0 on success      @return 0 on success
213  */  */
# Line 189  int helmholtz_p_calc(struct BBoxInterp * Line 216  int helmholtz_p_calc(struct BBoxInterp *
216          double *inputs, double *outputs,          double *inputs, double *outputs,
217          double *jacobian          double *jacobian
218  ){  ){
219      /* a few checks about the input requirements */      CALCPREPARE;
     if(ninputs != 2)return -1;  
     if(noutputs != 1)return -2;  
     if(inputs==NULL)return -3;  
     if(outputs==NULL)return -4;  
     if(bbox==NULL)return -5;  
   
     /* the 'user_data' in the black box object will contain the coefficients  
     required for this fluid; cast it to the required form: */  
     HelmholtzData *helmholtz_data = (HelmholtzData *)bbox->user_data;  
220    
221      /* first input is temperature, second is molar density */      /* first input is temperature, second is molar density */
222      outputs[0] = helmholtz_p(inputs[0], inputs[1], helmholtz_data);      outputs[0] = helmholtz_p(inputs[0], inputs[1], helmholtz_data);
223    
224      /* no need to worry about error states etc. */      /* no need to worry about error states etc. */
225        return 0;
226    }
227    
228    
229    /**
230        Evaluation function for 'helmholtz_u'
231        @param jacobian ignored
232        @return 0 on success
233    */
234    int helmholtz_u_calc(struct BBoxInterp *bbox,
235            int ninputs, int noutputs,
236            double *inputs, double *outputs,
237            double *jacobian
238    ){
239        CALCPREPARE;
240    
241        /* first input is temperature, second is molar density */
242        outputs[0] = helmholtz_u(inputs[0], inputs[1], helmholtz_data);
243    
244        /* no need to worry about error states etc. */
245        return 0;
246    }
247    
248    
249    /**
250        Evaluation function for 'helmholtz_h'
251        @param jacobian ignored
252        @return 0 on success
253    */
254    int helmholtz_h_calc(struct BBoxInterp *bbox,
255            int ninputs, int noutputs,
256            double *inputs, double *outputs,
257            double *jacobian
258    ){
259        CALCPREPARE;
260    
261        /* first input is temperature, second is molar density */
262        outputs[0] = helmholtz_h(inputs[0], inputs[1], helmholtz_data);
263    
264        /* no need to worry about error states etc. */
265      return 0;      return 0;
266  }  }
267    
268    
269    
270    

Legend:
Removed from v.1824  
changed lines
  Added in v.1825

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