/home/doxygen/libascend/compiler/extfunc.h

Go to the documentation of this file.
00001 /*
00002     ASCEND modelling environment
00003     Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly, Kirk Andre Abbott
00004     Copyright (C) 2006 Benjamin Allan
00005     Copyright (C) 2006 Carnegie Mellon University
00006 
00007     This program is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2, or (at your option)
00010     any later version.
00011 
00012     This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place - Suite 330,
00020     Boston, MA 02111-1307, USA.
00021 *//*
00045     by Kirk Andre Abbott and Ben Allan
00046     Created: July 4, 1994.
00047     Version: $Revision: 1.5 $
00048     Version control file: $RCSfile: extfunc.h,v $
00049     Date last modified: $Date: 1997/07/18 12:29:30 $
00050     Last modified by: $Author: mthomas $
00051 */
00052 
00053 #ifndef ASC_EXTFUNC_H
00054 #define ASC_EXTFUNC_H
00055 
00060 #include <utilities/ascConfig.h>
00061 #include "relation_util.h"
00062 
00063 /*------------------------------------------------------------------------------
00064     type definitions and forward decls
00065 */
00066 
00080 typedef int ExtEvalFunc(int *mode, int *m, int *n,
00081    double *x, double *u, double *f, double *g);
00082 
00089 enum ExternalFuncType {
00090   efunc_ERR = 0, 
00091   efunc_BlackBox = 10, 
00092   efunc_GlassBox = 20, 
00093   efunc_Method = 30 
00094 };
00095 
00096 struct GlassBoxExternalFunc {
00097   ExtEvalFunc *initial;
00098   ExtEvalFunc **value; 
00099   ExtEvalFunc **deriv; 
00100   ExtEvalFunc **deriv2; 
00101   ExtEvalFunc *final; 
00102 };
00103 
00104 
00106 enum Calc_status {
00107   calc_converged,
00108   calc_diverged,
00109   calc_fp_error,
00110   calc_incorrect_args,
00111   calc_error,
00112   calc_all_ok
00113 };
00114 
00120 enum Request_type {
00121   bb_none,        
00122   bb_first_call,  
00123   bb_last_call,   
00124   bb_check_args,  
00125   bb_recalculate, 
00126   bb_func_eval,   
00127   bb_deriv_eval,  
00128   bb_hess_eval,   
00129   bb_single_step  
00131 };
00132 
00142 struct BBoxInterp {
00144   enum Calc_status status;
00145 
00150   void *user_data;
00151 
00163   enum Request_type task;
00164   /* if someone still needs a nodestamp, we could go back to
00165      defining one, but it should really be inside user_data as
00166      ascend doesn't need it. */
00167 
00168 };
00169 
00170 typedef int ExtBBoxInitFunc(struct BBoxInterp *interp
00171         , struct Instance *data
00172         , struct gl_list_t *arglist
00173 );
00190 typedef void ExtBBoxFinalFunc(struct BBoxInterp *interp);
00222 typedef int ExtBBoxFunc(struct BBoxInterp *interp,
00223         int ninputs, int noutputs,
00224         double *inputs, double *outputs, double *jacobian);
00225 
00226 struct BlackBoxExternalFunc {
00227   ExtBBoxInitFunc *initial; 
00228   ExtBBoxFunc *value; 
00229   ExtBBoxFunc *deriv; 
00230   ExtBBoxFunc *deriv2; 
00231   ExtBBoxFinalFunc *final; 
00232   double inputTolerance; 
00234 };
00235 
00236 
00248 typedef int ExtMethodRun(struct Instance *context, struct gl_list_t *args, void *user_data);
00249 
00262 typedef int ExtMethodInit( struct Instance *context);
00263 
00276 typedef int ExtMethodDestroyFn( void *user_data);
00277 
00278 
00279 struct MethodExternalFunc {
00280   ExtMethodRun *run; 
00281   void *user_data; 
00284   ExtMethodDestroyFn *destroyfn;
00285 };
00286 
00287 struct ExternalFunc {
00288   enum ExternalFuncType etype;
00289   CONST char *name; 
00290   CONST char *help; 
00291   unsigned long n_inputs; 
00292   unsigned long n_outputs; 
00293   union {
00294     struct GlassBoxExternalFunc glass;
00295     struct BlackBoxExternalFunc black;
00296     struct MethodExternalFunc method;
00297   } u;
00298 };
00299 
00300 /*------------------------------------------------------------------------------
00301   REGISTRATION / LOOKUP FUNCTIONS
00302 */
00303 
00304 
00305 extern void InitExternalFuncLibrary(void);
00311 extern void DestroyExtFuncLibrary(void);
00318 extern int AddExternalFunc(struct ExternalFunc *efunc, int force);
00331 ASC_DLLSPEC struct ExternalFunc *LookupExtFunc(CONST char *funcname);
00338 extern struct ExternalFunc *RemoveExternalFunc(char *name);
00344 extern void DestroyExternalFunc(struct ExternalFunc *name);
00352 extern void PrintExtFuncLibrary(FILE *f);
00358 ASC_DLLSPEC char *WriteExtFuncLibraryString(void);
00368 ASC_DLLSPEC void TraverseExtFuncLibrary(void (*)(void *,void *),void *secondparam);
00369 
00370 
00372 ASC_DLLSPEC unsigned long NumberInputArgs(CONST struct ExternalFunc *efunc);
00373 
00375 ASC_DLLSPEC unsigned long NumberOutputArgs(CONST struct ExternalFunc *efunc);
00376 
00377 
00378 ASC_DLLSPEC CONST char*ExternalFuncName(CONST struct ExternalFunc *efunc);
00383 /*------------------------------------------------------------------------------
00384   EXTERNAL METHOD STUFF
00385 */
00386 
00387 ASC_DLLSPEC int CreateUserFunctionMethod(CONST char *name
00388         ,ExtMethodRun *run
00389         ,CONST long n_args
00390         ,CONST char *help
00391         ,void *user_data
00392         ,ExtMethodDestroyFn *destroyfn
00393 );
00433 extern ExtMethodRun *GetExtMethodRun(struct ExternalFunc *efunc);
00434 extern void *GetExtMethodUserData(struct ExternalFunc *efunc);
00435 
00436 /*------------------------------------------------------------------------------
00437   BLACK BOX STUFF
00438 */
00439 
00441 extern ExtBBoxInitFunc *GetInitFunc(struct ExternalFunc *efunc);
00443 extern ExtBBoxFunc *GetValueFunc(struct ExternalFunc *efunc);
00445 extern ExtBBoxFunc *GetDerivFunc(struct ExternalFunc *efunc);
00447 extern ExtBBoxFunc *GetDeriv2Func(struct ExternalFunc *efunc);
00449 extern ExtBBoxFinalFunc *GetFinalFunc(struct ExternalFunc *efunc);
00451 extern double GetValueFuncTolerance(struct ExternalFunc *efunc);
00452 
00453 
00454 ASC_DLLSPEC int CreateUserFunctionBlackBox(CONST char *name,
00455         ExtBBoxInitFunc *init,
00456         ExtBBoxFunc *value,
00457         ExtBBoxFunc *deriv,
00458         ExtBBoxFunc *deriv2,
00459         ExtBBoxFinalFunc *final,
00460         CONST unsigned long n_inputs,
00461         CONST unsigned long n_outputs,
00462         CONST char *help,
00463         double inputTolerance
00464 );
00509 ASC_DLLSPEC int DefaultExtBBoxInitFunc(struct BBoxInterp *interp
00510         , struct Instance *data
00511         , struct gl_list_t *arglist
00512 );
00521 ASC_DLLSPEC int ErrorExtBBoxValueFunc(struct BBoxInterp *interp
00522         , int ninputs, int noutputs
00523         , double *inputs, double *outputs
00524         , double *jacobian
00525 );
00532 ASC_DLLSPEC int DefaultExtBBoxFuncDerivFD(struct BBoxInterp *interp
00533         , int ninputs, int noutputs
00534         , double *inputs, double *outputs
00535         , double *jacobian
00536 );
00546 ASC_DLLSPEC int DefaultExtBBoxFuncDeriv2FD(struct BBoxInterp *interp
00547         , int ninputs, int noutputs
00548         , double *inputs, double *outputs
00549         , double *jacobian
00550 );
00561 ASC_DLLSPEC void DefaultExtBBoxFinalFunc(struct BBoxInterp *interp);
00570 /*-----------------------------------------------------------------------------
00571   GLASS BOX STUFF
00572 */
00573 
00574 ASC_DLLSPEC int CreateUserFunctionGlassBox(CONST char *name,
00575         ExtEvalFunc *init,
00576         ExtEvalFunc **value,
00577         ExtEvalFunc **deriv,
00578         ExtEvalFunc **deriv2,
00579         ExtEvalFunc *final,
00580         CONST unsigned long n_inputs, CONST unsigned long n_outputs,
00581         CONST char *help
00582 );
00606 extern ExtEvalFunc *GetGlassBoxInit(struct ExternalFunc *efunc);
00608 extern ExtEvalFunc **GetValueJumpTable(struct ExternalFunc *efunc);
00610 extern ExtEvalFunc **GetDerivJumpTable(struct ExternalFunc *efunc);
00612 extern ExtEvalFunc **GetDeriv2JumpTable(struct ExternalFunc *efunc);
00614 extern ExtEvalFunc *GetGlassBoxFinal(struct ExternalFunc *efunc);
00615 
00616 /* @} */
00617 
00618 #endif /* ASC_EXTFUNC_H */

Generated on Thu Jul 17 04:00:10 2008 for libascend by  doxygen 1.5.1