1 /* modiface.h
2 
3    Written by Don Maszle
4    8 October 1991
5 
6    Copyright (c) 1991-2017 Free Software Foundation, Inc.
7 
8    This file is part of GNU MCSim.
9 
10    GNU MCSim is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License
12    as published by the Free Software Foundation; either version 3
13    of the License, or (at your option) any later version.
14 
15    GNU MCSim is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with GNU MCSim; if not, see <http://www.gnu.org/licenses/>
22 */
23 
24 #ifndef MODIFACE_DEFINED
25 
26 /* ----------------------------------------------------------------------------
27    Inclusions  */
28 
29 #include "hungtype.h"
30 #include "lexfn.h"
31 
32 
33 /* ----------------------------------------------------------------------------
34    Typedefs  */
35 
36 typedef HANDLE HVAR;    /* Handle to a model variable  */
37 typedef HVAR *PHVAR;    /* and a pointer to the handle */
38 
39 
40 /* ----------------------------------------------------------------------------
41    Globals/Externals  */
42 
43 extern char szModelDescFilename[];
44 extern char szModelSourceFilename[];
45 extern char szModelGenAndVersion[];
46 
47 
48 /* ----------------------------------------------------------------------------
49    Prototypes  */
50 
51 /* Model Initialization and calculation */
52 
53 /* void InitExpt (void); */
54 void InitModel (void);    /* Initialize model to nominal values */
55 void ScaleModel (PDOUBLE pdTime);   /* Scale the model as defined */
56 
57 void CalcDeriv (double rgModelVars[], double rgDerivs[], PDOUBLE pdTime);
58 void CalcJacob (PDOUBLE pdTime, double rgModelVars[], long column,
59                 double rgdJac[]);
60 void CalcOutputs (double rgModelVars[], double rgDerivs[], PDOUBLE pdTime);
61 
62 void CalcInputs (PDOUBLE pdTime);
63 
64 
65 /* For exchanging info with the model */
66 
67 void DumpSymbolTable (char *szFilename); /* For diagnostics */
68 
69 PDOUBLE GetModelVector (void);    /* Vector of model vars */
70 int     GetNModelVars (void);     /* Number of model vars */
71 int     GetNStates (void);        /* First n Model vars are states */
72 
73 /* All interactions with individual variables and parameters
74    of the model are managed through HANDLEs.  The variable name
75    is submitted and a handle to the variable, HVAR, is returned.
76    This handle can then be used to get the current value of the
77    variable, or to change the value.
78 
79    Note that inputs are defined by IFN function records and thus
80    have a separate assignment routine.  For inputs, GetVarValue()
81    returns the current value of the input, as defined in the last
82    calculation, and SetInput() takes a pointer to a defining IFN
83    record.  The record is copied into the model, and is assumed to
84    be valid--no verification of parameters is performed.
85 */
86 
87 HVAR   GetVarHandle (PSTR szName);/* Returns a handle to szName */
88 
89 double GetVarValue (HVAR hVar);   /* Returns current value of hVar */
90 char   *GetVarName (HVAR hVar);   /* Returns the variable name of hVar */
91 
92 BOOL IsInput (HVAR hVar);       /* Returns TRUE if hVar is an input */
93 BOOL IsState (HVAR hVar);       /* Returns TRUE if hVar is a state */
94 BOOL IsOutput (HVAR hVar);      /* Returns TRUE if hVar is an output */
95 BOOL IsModelVar (HVAR hVar);    /* Returns TRUE if hVar is a state or output */
96 BOOL IsParm (HVAR hVar);        /* Returns TRUE if hVar is a parm */
97 
98 /* Finds time of next input transition */
99 void UpdateInputs (PDOUBLE pdTime, PDOUBLE pdNextTransTime);
100 
101 BOOL SetInput (HVAR hVar,            /* Returns TRUE if assignment succeeds */
102                PIFN pInputFnRecord); /* Function description for hvar */
103 
104 BOOL SetVar (HVAR hVar,     /* Returns  TRUE if assignment succeeds */
105              double dVal);  /* Value to be assigned */
106 
107 int ModelIndex (HVAR hvar); /* Returns the index of a model variable */
108 
109 #define MODIFACE_DEFINED
110 #endif
111 
112 /* End */
113 
114 
115