2 // define class name and unique id
\r
3 #define MODEL_IDENTIFIER FMUCallBeforeInitializationTestModel
\r
4 #define MODEL_GUID "{f4c1919a-ebce-4a1a-baca-8e57e23985cf}"
\r
6 // include fmu header files, typedefs and macros
\r
10 #include "openmodelica.h"
\r
11 #include "openmodelica_func.h"
\r
12 #include "simulation_data.h"
\r
13 #include "omc_error.h"
\r
14 #include "fmiModelTypes.h"
\r
15 #include "fmiModelFunctions.h"
\r
16 #include "FMUCallBeforeInitializationTestModel_functions.h"
\r
17 #include "initialization.h"
\r
19 #include "fmu_model_interface.h"
\r
25 void setStartValues(ModelInstance *comp);
\r
26 void setDefaultStartValues(ModelInstance *comp);
\r
27 void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo);
\r
28 fmiReal getReal(ModelInstance* comp, const fmiValueReference vr);
\r
29 fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value);
\r
30 fmiInteger getInteger(ModelInstance* comp, const fmiValueReference vr);
\r
31 fmiStatus setInteger(ModelInstance* comp, const fmiValueReference vr, const fmiInteger value);
\r
32 fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr);
\r
33 fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value);
\r
34 fmiString getString(ModelInstance* comp, const fmiValueReference vr);
\r
35 fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value);
\r
37 // define model size
\r
38 #define NUMBER_OF_STATES 3
\r
39 #define NUMBER_OF_EVENT_INDICATORS 0
\r
40 #define NUMBER_OF_REALS 11
\r
41 #define NUMBER_OF_INTEGERS 1
\r
42 #define NUMBER_OF_STRINGS 0
\r
43 #define NUMBER_OF_BOOLEANS 1
\r
44 #define NUMBER_OF_EXTERNALFUNCTIONS 0
\r
46 // define variable data for model
\r
47 #define $PstockBoolean_ 0
\r
48 #define $PstockInteger_ 1
\r
49 #define $PstockReal_ 2
\r
50 #define $P$DER$PstockBoolean_ 3
\r
51 #define $P$DER$PstockInteger_ 4
\r
52 #define $P$DER$PstockReal_ 5
\r
53 #define $PvalveBoolean_ 6
\r
54 #define $PvalveInteger_ 7
\r
55 #define $PvalveReal_ 8
\r
62 // define initial state vector as vector of value references
\r
63 #define STATES { $PstockBoolean_, $PstockInteger_, $PstockReal_ }
\r
64 #define STATESDERIVATIVES { $P$DER$PstockBoolean_, $P$DER$PstockInteger_, $P$DER$PstockReal_ }
\r
67 // implementation of the Model Exchange functions
\r
68 #include "fmu_model_interface.c"
\r
70 // Set values for all variables that define a start value
\r
71 void setDefaultStartValues(ModelInstance *comp) {
\r
73 comp->fmuData->modelData.realVarsData[0].attribute.start = 0.0;
\r
74 comp->fmuData->modelData.realVarsData[1].attribute.start = 0.0;
\r
75 comp->fmuData->modelData.realVarsData[2].attribute.start = 0.0;
\r
76 comp->fmuData->modelData.realParameterData[0].attribute.start = 1.0;
\r
77 comp->fmuData->modelData.realParameterData[1].attribute.start = 0.0;
\r
78 comp->fmuData->modelData.integerParameterData[0].attribute.start = 1;
\r
79 comp->fmuData->modelData.booleanParameterData[0].attribute.start = 1;
\r
81 // Set values for all variables that define a start value
\r
82 void setStartValues(ModelInstance *comp) {
\r
84 comp->fmuData->modelData.realVarsData[0].attribute.start = comp->fmuData->localData[0]->realVars[0];
\r
85 comp->fmuData->modelData.realVarsData[1].attribute.start = comp->fmuData->localData[0]->realVars[1];
\r
86 comp->fmuData->modelData.realVarsData[2].attribute.start = comp->fmuData->localData[0]->realVars[2];
\r
87 comp->fmuData->modelData.realVarsData[3].attribute.start = comp->fmuData->localData[0]->realVars[3];
\r
88 comp->fmuData->modelData.realVarsData[4].attribute.start = comp->fmuData->localData[0]->realVars[4];
\r
89 comp->fmuData->modelData.realVarsData[5].attribute.start = comp->fmuData->localData[0]->realVars[5];
\r
90 comp->fmuData->modelData.realVarsData[6].attribute.start = comp->fmuData->localData[0]->realVars[6];
\r
91 comp->fmuData->modelData.realVarsData[7].attribute.start = comp->fmuData->localData[0]->realVars[7];
\r
92 comp->fmuData->modelData.realVarsData[8].attribute.start = comp->fmuData->localData[0]->realVars[8];
\r
93 comp->fmuData->modelData.realParameterData[0].attribute.start = comp->fmuData->simulationInfo.realParameter[0];
\r
94 comp->fmuData->modelData.realParameterData[1].attribute.start = comp->fmuData->simulationInfo.realParameter[1];
\r
95 comp->fmuData->modelData.integerParameterData[0].attribute.start = comp->fmuData->simulationInfo.integerParameter[0];
\r
96 comp->fmuData->modelData.booleanParameterData[0].attribute.start = comp->fmuData->simulationInfo.booleanParameter[0];
\r
98 // Used to set the next time event, if any.
\r
99 void eventUpdate(ModelInstance* comp, fmiEventInfo* eventInfo) {
\r
102 fmiReal getReal(ModelInstance* comp, const fmiValueReference vr) {
\r
104 case $PstockBoolean_ : return comp->fmuData->localData[0]->realVars[0]; break;
\r
105 case $PstockInteger_ : return comp->fmuData->localData[0]->realVars[1]; break;
\r
106 case $PstockReal_ : return comp->fmuData->localData[0]->realVars[2]; break;
\r
107 case $P$DER$PstockBoolean_ : return comp->fmuData->localData[0]->realVars[3]; break;
\r
108 case $P$DER$PstockInteger_ : return comp->fmuData->localData[0]->realVars[4]; break;
\r
109 case $P$DER$PstockReal_ : return comp->fmuData->localData[0]->realVars[5]; break;
\r
110 case $PvalveBoolean_ : return comp->fmuData->localData[0]->realVars[6]; break;
\r
111 case $PvalveInteger_ : return comp->fmuData->localData[0]->realVars[7]; break;
\r
112 case $PvalveReal_ : return comp->fmuData->localData[0]->realVars[8]; break;
\r
113 case $Pr_ : return comp->fmuData->simulationInfo.realParameter[0]; break;
\r
114 case time_ : return comp->fmuData->simulationInfo.realParameter[1]; break;
\r
120 fmiStatus setReal(ModelInstance* comp, const fmiValueReference vr, const fmiReal value) {
\r
122 case $PstockBoolean_ : comp->fmuData->localData[0]->realVars[0]=value; break;
\r
123 case $PstockInteger_ : comp->fmuData->localData[0]->realVars[1]=value; break;
\r
124 case $PstockReal_ : comp->fmuData->localData[0]->realVars[2]=value; break;
\r
125 case $P$DER$PstockBoolean_ : comp->fmuData->localData[0]->realVars[3]=value; break;
\r
126 case $P$DER$PstockInteger_ : comp->fmuData->localData[0]->realVars[4]=value; break;
\r
127 case $P$DER$PstockReal_ : comp->fmuData->localData[0]->realVars[5]=value; break;
\r
128 case $PvalveBoolean_ : comp->fmuData->localData[0]->realVars[6]=value; break;
\r
129 case $PvalveInteger_ : comp->fmuData->localData[0]->realVars[7]=value; break;
\r
130 case $PvalveReal_ : comp->fmuData->localData[0]->realVars[8]=value; break;
\r
131 case $Pr_ : comp->fmuData->simulationInfo.realParameter[0]=value; break;
\r
132 case time_ : comp->fmuData->simulationInfo.realParameter[1]=value; break;
\r
139 fmiInteger getInteger(ModelInstance* comp, const fmiValueReference vr) {
\r
141 case $Pi_ : return comp->fmuData->simulationInfo.integerParameter[0]; break;
\r
146 fmiStatus setInteger(ModelInstance* comp, const fmiValueReference vr, const fmiInteger value) {
\r
148 case $Pi_ : comp->fmuData->simulationInfo.integerParameter[0]=value; break;
\r
154 fmiBoolean getBoolean(ModelInstance* comp, const fmiValueReference vr) {
\r
156 case $Pb_ : return comp->fmuData->simulationInfo.booleanParameter[0]; break;
\r
162 fmiStatus setBoolean(ModelInstance* comp, const fmiValueReference vr, const fmiBoolean value) {
\r
164 case $Pb_ : comp->fmuData->simulationInfo.booleanParameter[0]=value; break;
\r
171 fmiString getString(ModelInstance* comp, const fmiValueReference vr) {
\r
178 fmiStatus setExternalFunction(ModelInstance* c, const fmiValueReference vr, const void* value){
\r