]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMUSimulator/include/FMIL/ThirdParty/FMI1/fmiModelFunctions.h
Renamed org.simantics.fmil to org.simantics.fmil.core to prevent having bundles and...
[simantics/fmil.git] / org.simantics.fmil.core / native / FMUSimulator / include / FMIL / ThirdParty / FMI1 / fmiModelFunctions.h
1 #ifndef fmiModelFunctions_h\r
2 #define fmiModelFunctions_h\r
3 \r
4 /* This header file must be utilized when compiling a model.\r
5    It defines all functions of the Model Execution Interface.\r
6    In order to have unique function names even if several models\r
7    are compiled together (e.g. for embedded systems), every "real" function name\r
8    is constructed by prepending the function name by\r
9    "MODEL_IDENTIFIER" + "_" where "MODEL_IDENTIFIER" is the short name\r
10    of the model used as the name of the zip-file where the model is stored.\r
11    Therefore, the typical usage is:\r
12 \r
13       #define MODEL_IDENTIFIER MyModel\r
14       #include "fmiModelFunctions.h"\r
15 \r
16    As a result, a function that is defined as "fmiGetDerivatives" in this header file,\r
17    is actually getting the name "MyModel_fmiGetDerivatives".\r
18 \r
19    Revisions:\r
20    - Jan. 20, 2010: stateValueReferencesChanged added to struct fmiEventInfo (ticket #27)\r
21                     (by M. Otter, DLR)\r
22                     Added WIN32 pragma to define the struct layout (ticket #34)\r
23                     (by J. Mauss, QTronic)\r
24    - Jan.  4, 2010: Removed argument intermediateResults from fmiInitialize\r
25                     Renamed macro fmiGetModelFunctionsVersion to fmiGetVersion\r
26                     Renamed macro fmiModelFunctionsVersion to fmiVersion\r
27                     Replaced fmiModel by fmiComponent in decl of fmiInstantiateModel\r
28                     (by J. Mauss, QTronic)\r
29    - Dec. 17, 2009: Changed extension "me" to "fmi" (by Martin Otter, DLR).\r
30    - Dez. 14, 2009: Added eventInfo to meInitialize and added\r
31                     meGetNominalContinuousStates (by Martin Otter, DLR)\r
32    - Sept. 9, 2009: Added DllExport (according to Peter Nilsson's suggestion)\r
33                     (by A. Junghanns, QTronic)\r
34    - Sept. 9, 2009: Changes according to FMI-meeting on July 21:\r
35                     meInquireModelTypesVersion     -> meGetModelTypesPlatform\r
36                     meInquireModelFunctionsVersion -> meGetModelFunctionsVersion\r
37                     meSetStates                    -> meSetContinuousStates\r
38                     meGetStates                    -> meGetContinuousStates\r
39                     removal of meInitializeModelClass\r
40                     removal of meGetTime\r
41                     change of arguments of meInstantiateModel\r
42                     change of arguments of meCompletedIntegratorStep\r
43                     (by Martin Otter, DLR):\r
44    - July 19, 2009: Added "me" as prefix to file names (by Martin Otter, DLR).\r
45    - March 2, 2009: Changed function definitions according to the last design\r
46                     meeting with additional improvements (by Martin Otter, DLR).\r
47    - Dec. 3 , 2008: First version by Martin Otter (DLR) and Hans Olsson (Dynasim).\r
48 \r
49 \r
50    Copyright © 2008-2009, MODELISAR consortium. All rights reserved.\r
51    This file is licensed by the copyright holders under the BSD License\r
52    (http://www.opensource.org/licenses/bsd-license.html):\r
53 \r
54    ----------------------------------------------------------------------------\r
55    Redistribution and use in source and binary forms, with or without\r
56    modification, are permitted provided that the following conditions are met:\r
57 \r
58    - Redistributions of source code must retain the above copyright notice,\r
59      this list of conditions and the following disclaimer.\r
60    - Redistributions in binary form must reproduce the above copyright notice,\r
61      this list of conditions and the following disclaimer in the documentation\r
62      and/or other materials provided with the distribution.\r
63    - Neither the name of the copyright holders nor the names of its\r
64      contributors may be used to endorse or promote products derived\r
65      from this software without specific prior written permission.\r
66 \r
67    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
68    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED\r
69    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
70    PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR\r
71    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
72    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
73    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
74    OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
75    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
76    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r
77    ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
78    ----------------------------------------------------------------------------\r
79 \r
80    with the extension:\r
81 \r
82    You may distribute or publicly perform any modification only under the\r
83    terms of this license.\r
84 */\r
85 \r
86 #include "fmiModelTypes.h"\r
87 #include <stdlib.h>\r
88 \r
89 /* Export fmi functions on Windows */\r
90 #ifdef _MSC_VER\r
91 #define DllExport __declspec( dllexport )\r
92 #else\r
93 #define DllExport\r
94 #endif\r
95 \r
96 /* Macros to construct the real function name\r
97    (prepend function name by MODEL_IDENTIFIER + "_") */\r
98 \r
99 #define fmiPaste(a,b)     a ## b\r
100 #define fmiPasteB(a,b)    fmiPaste(a,b)\r
101 #define fmiFullName(name) fmiPasteB(MODEL_IDENTIFIER, name)\r
102 \r
103 #define fmiGetModelTypesPlatform      fmiFullName(_fmiGetModelTypesPlatform)\r
104 #define fmiGetVersion                 fmiFullName(_fmiGetVersion)\r
105 #define fmiInstantiateModel           fmiFullName(_fmiInstantiateModel)\r
106 #define fmiFreeModelInstance          fmiFullName(_fmiFreeModelInstance)\r
107 #define fmiSetDebugLogging            fmiFullName(_fmiSetDebugLogging)\r
108 #define fmiSetTime                    fmiFullName(_fmiSetTime)\r
109 #define fmiSetContinuousStates        fmiFullName(_fmiSetContinuousStates)\r
110 #define fmiCompletedIntegratorStep    fmiFullName(_fmiCompletedIntegratorStep)\r
111 #define fmiSetReal                    fmiFullName(_fmiSetReal)\r
112 #define fmiSetInteger                 fmiFullName(_fmiSetInteger)\r
113 #define fmiSetBoolean                 fmiFullName(_fmiSetBoolean)\r
114 #define fmiSetString                  fmiFullName(_fmiSetString)\r
115 #define fmiInitialize                 fmiFullName(_fmiInitialize)\r
116 #define fmiGetDerivatives             fmiFullName(_fmiGetDerivatives)\r
117 #define fmiGetEventIndicators         fmiFullName(_fmiGetEventIndicators)\r
118 #define fmiGetReal                    fmiFullName(_fmiGetReal)\r
119 #define fmiGetInteger                 fmiFullName(_fmiGetInteger)\r
120 #define fmiGetBoolean                 fmiFullName(_fmiGetBoolean)\r
121 #define fmiGetString                  fmiFullName(_fmiGetString)\r
122 #define fmiEventUpdate                fmiFullName(_fmiEventUpdate)\r
123 #define fmiGetContinuousStates        fmiFullName(_fmiGetContinuousStates)\r
124 #define fmiGetNominalContinuousStates fmiFullName(_fmiGetNominalContinuousStates)\r
125 #define fmiGetStateValueReferences    fmiFullName(_fmiGetStateValueReferences)\r
126 #define fmiTerminate                  fmiFullName(_fmiTerminate)\r
127 \r
128 \r
129 /* Version number */\r
130 #define fmiVersion "1.0"\r
131 \r
132 /* Inquire version numbers of header files */\r
133    DllExport const char* fmiGetModelTypesPlatform();\r
134    DllExport const char* fmiGetVersion();\r
135 \r
136 /* make sure all compiler use the same alignment policies for structures */\r
137 #ifdef WIN32\r
138 #pragma pack(push,8)\r
139 #endif\r
140 \r
141 /* Type definitions */\r
142    typedef enum  {fmiOK,\r
143                   fmiWarning,\r
144                   fmiDiscard,\r
145                   fmiError,\r
146                   fmiFatal} fmiStatus;\r
147 \r
148    typedef void  (*fmiCallbackLogger)        (fmiComponent c, fmiString instanceName, fmiStatus status,\r
149                                               fmiString category, fmiString message, ...);\r
150    typedef void* (*fmiCallbackAllocateMemory)(size_t nobj, size_t size);\r
151    typedef void  (*fmiCallbackFreeMemory)    (void* obj);\r
152 \r
153    typedef struct {\r
154      fmiCallbackLogger         logger;\r
155      fmiCallbackAllocateMemory allocateMemory;\r
156      fmiCallbackFreeMemory     freeMemory;\r
157    } fmiCallbackFunctions;\r
158 \r
159    typedef struct {\r
160       fmiBoolean iterationConverged;\r
161       fmiBoolean stateValueReferencesChanged;\r
162       fmiBoolean stateValuesChanged;\r
163       fmiBoolean terminateSimulation;\r
164       fmiBoolean upcomingTimeEvent;\r
165       fmiReal    nextEventTime;\r
166    } fmiEventInfo;\r
167 \r
168 /* reset alignment policy to the one set before reading this file */\r
169 #ifdef WIN32\r
170 #pragma pack(pop)\r
171 #endif\r
172 \r
173 /* Creation and destruction of model instances and setting debug status */\r
174    DllExport fmiComponent fmiInstantiateModel (fmiString            instanceName,\r
175                                                fmiString            GUID,\r
176                                                fmiCallbackFunctions functions,\r
177                                                fmiBoolean           loggingOn);\r
178    DllExport void      fmiFreeModelInstance(fmiComponent c);\r
179    DllExport fmiStatus fmiSetDebugLogging  (fmiComponent c, fmiBoolean loggingOn);\r
180 \r
181 \r
182 /* Providing independent variables and re-initialization of caching */\r
183    DllExport fmiStatus fmiSetTime                (fmiComponent c, fmiReal time);\r
184    DllExport fmiStatus fmiSetContinuousStates    (fmiComponent c, const fmiReal x[], size_t nx);\r
185    DllExport fmiStatus fmiCompletedIntegratorStep(fmiComponent c, fmiBoolean* callEventUpdate);\r
186    DllExport fmiStatus fmiSetReal                (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiReal    value[]);\r
187    DllExport fmiStatus fmiSetInteger             (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiInteger value[]);\r
188    DllExport fmiStatus fmiSetBoolean             (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiBoolean value[]);\r
189    DllExport fmiStatus fmiSetString              (fmiComponent c, const fmiValueReference vr[], size_t nvr, const fmiString  value[]);\r
190 \r
191 \r
192 /* Evaluation of the model equations */\r
193    DllExport fmiStatus fmiInitialize(fmiComponent c, fmiBoolean toleranceControlled,\r
194                                      fmiReal relativeTolerance, fmiEventInfo* eventInfo);\r
195 \r
196    DllExport fmiStatus fmiGetDerivatives    (fmiComponent c, fmiReal derivatives[]    , size_t nx);\r
197    DllExport fmiStatus fmiGetEventIndicators(fmiComponent c, fmiReal eventIndicators[], size_t ni);\r
198 \r
199    DllExport fmiStatus fmiGetReal   (fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiReal    value[]);\r
200    DllExport fmiStatus fmiGetInteger(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiInteger value[]);\r
201    DllExport fmiStatus fmiGetBoolean(fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiBoolean value[]);\r
202    DllExport fmiStatus fmiGetString (fmiComponent c, const fmiValueReference vr[], size_t nvr, fmiString  value[]);\r
203 \r
204    DllExport fmiStatus fmiEventUpdate               (fmiComponent c, fmiBoolean intermediateResults, fmiEventInfo* eventInfo);\r
205    DllExport fmiStatus fmiGetContinuousStates       (fmiComponent c, fmiReal states[], size_t nx);\r
206    DllExport fmiStatus fmiGetNominalContinuousStates(fmiComponent c, fmiReal x_nominal[], size_t nx);\r
207    DllExport fmiStatus fmiGetStateValueReferences   (fmiComponent c, fmiValueReference vrx[], size_t nx);\r
208    DllExport fmiStatus fmiTerminate                 (fmiComponent c);\r
209 \r
210 #endif // fmiModelFunctions_h\r