/[ascend]/trunk/base/generic/packages/kvalues.c
ViewVC logotype

Diff of /trunk/base/generic/packages/kvalues.c

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

revision 533 by ben.allan, Mon Apr 17 03:18:06 2006 UTC revision 534 by johnpye, Tue Apr 25 13:25:04 2006 UTC
# Line 1  Line 1 
1  /*********************************************************************\  /*  ASCEND modelling environment
2                          External Distillation Routines.      Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Abbott.
3              by Kirk Abbott      Copyright (C) 2006 Carnegie Mellon University
4              Created: July 4, 1994  
5              Version: $Revision: 1.5 $      This program is free software; you can redistribute it and/or modify
6              Date last modified: $Date: 1997/07/18 12:20:07 $      it under the terms of the GNU General Public License as published by
7  This file is part of the Ascend Language Interpreter.      the Free Software Foundation; either version 2, or (at your option)
8        any later version.
9  Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Abbott.  
10        This program is distributed in the hope that it will be useful,
11  The Ascend Language Interpreter is free software; you can redistribute      but WITHOUT ANY WARRANTY; without even the implied warranty of
12  it and/or modify it under the terms of the GNU General Public License as      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  published by the Free Software Foundation; either version 2 of the      GNU General Public License for more details.
14  License, or (at your option) any later version.  
15        You should have received a copy of the GNU General Public License
16  The Ascend Language Interpreter is distributed in hope that it will be      along with this program; if not, write to the Free Software
17  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of      Foundation, Inc., 59 Temple Place - Suite 330,
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      Boston, MA 02111-1307, USA.
19  General Public License for more details.  *//**
20        @file
21  You should have received a copy of the GNU General Public License along with      External distillation routines
22  the program; if not, write to the Free Software Foundation, Inc., 675  *//*
23  Mass Ave, Cambridge, MA 02139 USA.  Check the file named COPYING.      by Kirk Abbott
24  \*********************************************************************/      Created: July 4, 1994
25        Version: $Revision: 1.5 $
26        Date last modified: $Date: 1997/07/18 12:20:07 $
27    */
28    
29  #include <utilities/ascConfig.h>  #include <utilities/ascConfig.h>
30  #include <compiler/compiler.h>  #include <compiler/compiler.h>
31  #include <compiler/packages.h>  #include <compiler/packages.h>
# Line 101  static int LookupData(struct Vpdata *vp) Line 105  static int LookupData(struct Vpdata *vp)
105    
106    
107  /*  /*
108   * The 2nd. arguement is the array of mole fractions.      The 2nd. argument is the array of mole fractions.
109   * the length of this list is then the number of components.      the length of this list is then the number of components.
110   */  */
111  static int GetNumberOfComponents(struct gl_list_t *arglist)  static int GetNumberOfComponents(struct gl_list_t *arglist)
112  {  {
113    int ncomps;    int ncomps;
# Line 118  static int GetNumberOfComponents(struct Line 122  static int GetNumberOfComponents(struct
122    }    }
123  }  }
124    
125  /*  /**
126   *********************************************************************      The following code takes a data instance and tries to decode it
127   * The following code takes a data instance and tries to decode it      to determine the names of the components used in the model. It will
128   * to determine the names of the components used in the model. It will      then create an array of these names and attach it to the problem.
129   * then create an array of these names and attach it to the problem.      The data is expected to be an instance of a model of the form:
130   * The data is expected to be an instance of a model of the form:  
131   *        MODEL kvalues_data;
132   *   MODEL kvalues_data;           ncomps IS_A integer;
133   *      ncomps IS_A integer;           ncomps := 3;
134   *  ncomps := 3;           components[1..ncomps] IS_A symbol;
135   *      components[1..ncomps] IS_A symbol;  
136   *           components[1] := 'a';
137   *      components[1] := 'a';           components[2] := 'b';
138   *      components[2] := 'b';           components[3] := 'c';
139   *      components[3] := 'c';        END kvalues_data;
140   *   END kvalues_data;  
141   *  */
142   *********************************************************************  static int GetComponentData(
143   *          struct Instance *data,
144   */          struct KVALUES_problem *problem
145  static int GetComponentData(struct Instance *data,  ){
                 struct KVALUES_problem *problem)  
 {  
146    struct InstanceName name;    struct InstanceName name;
147    struct Instance *child;    struct Instance *child;
148    unsigned long pos,c;    unsigned long pos,c;
# Line 188  static int GetComponentData(struct Insta Line 190  static int GetComponentData(struct Insta
190  static int CheckArgsOK(struct Slv_Interp *slv_interp,  static int CheckArgsOK(struct Slv_Interp *slv_interp,
191                 struct Instance *data,                 struct Instance *data,
192                 struct gl_list_t *arglist,                 struct gl_list_t *arglist,
193                 struct KVALUES_problem *problem)                 struct KVALUES_problem *problem
194  {  ){
195    unsigned long len,ninputs,noutputs;    unsigned long len,ninputs,noutputs;
196    int n_components;    int n_components;
197    int result;    int result;
# Line 225  static int CheckArgsOK(struct Slv_Interp Line 227  static int CheckArgsOK(struct Slv_Interp
227  }  }
228    
229    
230  /*  /**
231   *********************************************************************      This function is one of the registered functions. It operates in
232   * This function is one of the registered functions. It operates in      one of two modes, first_call or last_call. In the former it
233   * one of two modes, first_call or last_call. In the former it      creates a KVALUES_problem and calls a number of routines to check
234   * creates a KVALUES_problem and calls a number of routines to check      the arguements (data and arglist) and to cache the information
235   * the arguements (data and arglist) and to cache the information      processed away in the KVALUES_problem structure. We then attach
236   * processed away in the KVALUES_problem structure. We then attach      to the hook. *However*, the very first time this function is
237   * to the hook. *However*, the very first time this function is      called for any given external node, the slv_interp is guaranteed
238   * called for any given external node, the slv_interp is guaranteed      to be in a clean state. Hence if we find that slv_interp->user_data
239   * to be in a clean state. Hence if we find that slv_interp->user_data      is non-NULL, it means that this function has been called before,
240   * is non-NULL, it means that this function has been called before,      regardless of the first_call/last_call flags, and information was
241   * regardless of the first_call/last_call flags, and information was      stored there by us. So as not to leak, we either need to deallocate
242   * stored there by us. So as not to leak, we either need to deallocate      any storage or just update the information there.
243   * any storage or just update the information there.  
244   *      In last_call mode, the memory associated with the problem needs to
245   * In last_call mode, the memory associated with the problem needs to      released; this includes:
246   * released; this includes:      the array of compononent string pointers (we dont own the strings).
247   * the array of compononent string pointers (we dont own the strings).      the array of doubles.
248   * the array of doubles.      the problem structure itself.
249   * the problem structure itself.  */
  *  
  *********************************************************************  
  */  
250  int kvalues_preslv(struct Slv_Interp *slv_interp,  int kvalues_preslv(struct Slv_Interp *slv_interp,
251             struct Instance *data,             struct Instance *data,
252             struct gl_list_t *arglist)             struct gl_list_t *arglist
253  {  
254    ){
255    struct KVALUES_problem *problem;    struct KVALUES_problem *problem;
256    int workspace;    int workspace;
257    /*struct Instance *arg;    /*struct Instance *arg;
# Line 288  int kvalues_preslv(struct Slv_Interp *sl Line 288  int kvalues_preslv(struct Slv_Interp *sl
288    
289    
290  /*  /*
291   *********************************************************************      This function provides support to kvalues_fex which is one of the
292   * This function provides support to kvalues_fex which is one of the      registered functions. The input variables are T,x[1..ncomps],P.
293   * registered functions. The input variables are T,x[1..ncomps],P.      The output variables are y[1..n]. We also load up the x vector
294   * The output variables are y[1..n]. We also load up the x vector      (our copy) with satP[1..ncomps] as proof of concept that we can
295   * (our copy) with satP[1..ncomps] as proof of concept that we can      do (re)initialization.
296   * do (re)initialization.  */
  *********************************************************************  
  */  
297    
298  /*  /*
299   * The name field will be field in vp before the call.      The name field will be field in vp before the call.
300   * The rest of the data will be filled the structure      The rest of the data will be filled the structure
301   * provided that there are no errors.      provided that there are no errors.
302   */  */
303  static int GetCoefficients(struct Vpdata *vp)  static int GetCoefficients(struct Vpdata *vp){
 {  
304    if (LookupData(vp)==0)    if (LookupData(vp)==0)
305      return 0;      return 0;
306   else    else
307      return 1; /* error in name lookup */      return 1; /* error in name lookup */
308  }  }
309    
# Line 314  static int GetCoefficients(struct Vpdata Line 311  static int GetCoefficients(struct Vpdata
311  static int DoCalculation(struct Slv_Interp *slv_interp,  static int DoCalculation(struct Slv_Interp *slv_interp,
312               int ninputs, int noutputs,               int ninputs, int noutputs,
313               double *inputs,               double *inputs,
314               double *outputs)               double *outputs
315  {  ){
316    struct KVALUES_problem *problem;    struct KVALUES_problem *problem;
317    int c, offset;    int c, offset;
318    int ncomps;    int ncomps;
# Line 390  static int DoCalculation(struct Slv_Inte Line 387  static int DoCalculation(struct Slv_Inte
387  int kvalues_fex(struct Slv_Interp *slv_interp,  int kvalues_fex(struct Slv_Interp *slv_interp,
388          int ninputs, int noutputs,          int ninputs, int noutputs,
389          double *inputs, double *outputs,          double *inputs, double *outputs,
390          double *jacobian)          double *jacobian
391  {  ){
392    int nok;    int nok;
393    nok = DoCalculation(slv_interp, ninputs, noutputs, inputs, outputs);    nok = DoCalculation(slv_interp, ninputs, noutputs, inputs, outputs);
394    if (nok)    if (nok)
# Line 400  int kvalues_fex(struct Slv_Interp *slv_i Line 397  int kvalues_fex(struct Slv_Interp *slv_i
397      return 0;      return 0;
398  }  }
399    
400    /**
401  int KValues_Init (void)      Registration function
402  {  */
403    int kvalues_register(void){
404    int result;    int result;
405    
406    char kvalues_help[] = "This function does a bubble point calculation\    char kvalues_help[] = "This function does a bubble point calculation\

Legend:
Removed from v.533  
changed lines
  Added in v.534

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