1 /* Simulation code for FMUAllTypesOfVariablesTestModel generated by the OpenModelica Compiler 1.8.1+ (r11690). */
\r
3 #include "openmodelica.h"
\r
4 #include "openmodelica_func.h"
\r
5 #include "simulation_data.h"
\r
6 #include "simulation_runtime.h"
\r
7 #include "omc_error.h"
\r
12 #include "FMUAllTypesOfVariablesTestModel_functions.h"
\r
14 #include "_FMUAllTypesOfVariablesTestModel.h"
\r
15 #include "FMUAllTypesOfVariablesTestModel_functions.c"
\r
16 /* dummy VARINFO and FILEINFO */
\r
17 const FILE_INFO dummyFILE_INFO = {"",-1,-1,-1,-1,1};
\r
18 const VAR_INFO dummyVAR_INFO = {-1,"","",(FILE_INFO){"",-1,-1,-1,-1,1}};
\r
22 #ifdef _OMC_MEASURE_TIME
\r
23 int measure_time_flag = 1;
\r
25 int measure_time_flag = 0;
\r
28 void setupDataStruc(DATA *data)
\r
30 ASSERT(data,"Error while initialize Data");
\r
31 data->modelData.modelName = "FMUAllTypesOfVariablesTestModel";
\r
32 data->modelData.modelFilePrefix = "FMUAllTypesOfVariablesTestModel";
\r
33 data->modelData.modelDir = "";
\r
34 data->modelData.modelGUID = "{e473ffda-4cfa-4ca5-b49b-0c9abe90687b}";
\r
36 data->modelData.nStates = 3;
\r
37 data->modelData.nVariablesReal = 2*3+4;
\r
38 data->modelData.nVariablesInteger = 1;
\r
39 data->modelData.nVariablesBoolean = 1;
\r
40 data->modelData.nVariablesString = 0;
\r
41 data->modelData.nParametersReal = 2;
\r
42 data->modelData.nParametersInteger = 1;
\r
43 data->modelData.nParametersBoolean = 1;
\r
44 data->modelData.nParametersString = 0;
\r
45 data->modelData.nInputVars = 0;
\r
46 data->modelData.nOutputVars = 0;
\r
47 data->modelData.nJacobians = 4;
\r
48 data->modelData.nHelpVars = 0;
\r
50 data->modelData.nAliasReal = 0;
\r
51 data->modelData.nAliasInteger = 0;
\r
52 data->modelData.nAliasBoolean = 0;
\r
53 data->modelData.nAliasString = 0;
\r
55 data->modelData.nZeroCrossings = 0;
\r
56 data->modelData.nSamples = 0;
\r
57 data->modelData.nInitEquations = 0;
\r
58 data->modelData.nResiduals = 3;
\r
59 data->modelData.nExtObjs = 0;
\r
60 data->modelData.nFunctions = 0;
\r
61 data->modelData.nEquations = 18;
\r
63 data->modelData.nDelayExpressions = 0;
\r
67 void setupDataStruc2(DATA *data)
\r
69 const struct FUNCTION_INFO funcInfo[1] = {{-1,"",omc_dummyFileInfo}};
\r
70 memcpy(data->modelData.functionNames, &funcInfo, data->modelData.nFunctions*sizeof(FUNCTION_INFO));
\r
72 const VAR_INFO** equationInfo_cref1 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
73 equationInfo_cref1[0] = &$PvalveReal__varInfo;
\r
74 const VAR_INFO** equationInfo_cref3 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
75 equationInfo_cref3[0] = &$P$DER$PstockReal__varInfo;
\r
76 const VAR_INFO** equationInfo_cref5 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
77 equationInfo_cref5[0] = &$PvalveInteger__varInfo;
\r
78 const VAR_INFO** equationInfo_cref7 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
79 equationInfo_cref7[0] = &$P$DER$PstockInteger__varInfo;
\r
80 const VAR_INFO** equationInfo_cref9 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
81 equationInfo_cref9[0] = &$PvalveBoolean__varInfo;
\r
82 const VAR_INFO** equationInfo_cref11 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
83 equationInfo_cref11[0] = &$P$DER$PstockBoolean__varInfo;
\r
84 const VAR_INFO** equationInfo_cref13 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
85 equationInfo_cref13[0] = &$PcontinuousReal__varInfo;
\r
86 const VAR_INFO** equationInfo_cref15 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
87 equationInfo_cref15[0] = &$PdiscreteInteger__varInfo;
\r
88 const VAR_INFO** equationInfo_cref17 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
\r
89 equationInfo_cref17[0] = &$PdiscreteBoolean__varInfo;
\r
90 const struct EQUATION_INFO equationInfo[18] = {
\r
91 {1012,"SES_ALGORITHM 0", 0, NULL},
\r
92 {1013,"SES_SIMPLE_ASSIGN 1",1,equationInfo_cref1},
\r
93 {1014,"SES_ALGORITHM 2", 0, NULL},
\r
94 {1015,"SES_SIMPLE_ASSIGN 3",1,equationInfo_cref3},
\r
95 {1016,"SES_ALGORITHM 4", 0, NULL},
\r
96 {1017,"SES_SIMPLE_ASSIGN 5",1,equationInfo_cref5},
\r
97 {1018,"SES_ALGORITHM 6", 0, NULL},
\r
98 {1019,"SES_SIMPLE_ASSIGN 7",1,equationInfo_cref7},
\r
99 {1020,"SES_ALGORITHM 8", 0, NULL},
\r
100 {1021,"SES_SIMPLE_ASSIGN 9",1,equationInfo_cref9},
\r
101 {1022,"SES_ALGORITHM 10", 0, NULL},
\r
102 {1023,"SES_SIMPLE_ASSIGN 11",1,equationInfo_cref11},
\r
103 {1024,"SES_ALGORITHM 12", 0, NULL},
\r
104 {1025,"SES_SIMPLE_ASSIGN 13",1,equationInfo_cref13},
\r
105 {1026,"SES_ALGORITHM 14", 0, NULL},
\r
106 {1027,"SES_SIMPLE_ASSIGN 15",1,equationInfo_cref15},
\r
107 {1028,"SES_ALGORITHM 16", 0, NULL},
\r
108 {1029,"SES_SIMPLE_ASSIGN 17",1,equationInfo_cref17}
\r
110 const int n_omc_equationInfo_reverse_prof_index = 0;
\r
111 const int omc_equationInfo_reverse_prof_index[] = {
\r
114 memcpy(data->modelData.equationInfo, &equationInfo, data->modelData.nEquations*sizeof(EQUATION_INFO));
\r
116 data->modelData.nProfileBlocks = n_omc_equationInfo_reverse_prof_index;
\r
117 data->modelData.equationInfo_reverse_prof_index = (int*) malloc(data->modelData.nProfileBlocks*sizeof(int));
\r
118 memcpy(data->modelData.equationInfo_reverse_prof_index, omc_equationInfo_reverse_prof_index, data->modelData.nProfileBlocks*sizeof(int));
\r
121 /* Has to be performed after _init.xml file has been read */
\r
122 void callExternalObjectConstructors(DATA *data)
\r
125 mem_state = get_memory_state();
\r
126 /* data->simulationInfo.extObjs = NULL; */
\r
129 void callExternalObjectDestructors(DATA *data)
\r
131 if (data->simulationInfo.extObjs) {
\r
132 free(data->simulationInfo.extObjs);
\r
133 data->simulationInfo.extObjs = 0;
\r
138 int input_function(DATA *data)
\r
143 int output_function(DATA *data)
\r
148 /* Initializes the raw time events of the simulation using the now
\r
149 calcualted parameters. */
\r
150 void function_sampleInit(DATA *data)
\r
154 int function_updateSample(DATA *data)
\r
158 mem_state = get_memory_state();
\r
159 restore_memory_state(mem_state);
\r
164 int function_storeDelayed(DATA *data)
\r
168 mem_state = get_memory_state();
\r
169 restore_memory_state(mem_state);
\r
174 int updateBoundStartValues(DATA *data)
\r
178 DEBUG_INFO(LOG_INIT, "updating start-values:");
\r
183 int initial_residual(DATA *data, double $P$_lambda, double* initialResiduals)
\r
188 mem_state = get_memory_state();
\r
189 DEBUG_INFO(LOG_RES_INIT, "updating initial_residuals:");
\r
190 initialResiduals[i++] = ((1.0 - $P$_lambda) * ($PstockReal - $P$START$PstockReal));
\r
191 DEBUG_INFO_AL2(LOG_RES_INIT, " residual[%d] : (1.0 - $_lambda) * (stockReal - $_start(stockReal)) = %f", i, initialResiduals[i-1]);
\r
192 initialResiduals[i++] = ((1.0 - $P$_lambda) * ($PstockInteger - $P$START$PstockInteger));
\r
193 DEBUG_INFO_AL2(LOG_RES_INIT, " residual[%d] : (1.0 - $_lambda) * (stockInteger - $_start(stockInteger)) = %f", i, initialResiduals[i-1]);
\r
194 initialResiduals[i++] = ((1.0 - $P$_lambda) * ($PstockBoolean - $P$START$PstockBoolean));
\r
195 DEBUG_INFO_AL2(LOG_RES_INIT, " residual[%d] : (1.0 - $_lambda) * (stockBoolean - $_start(stockBoolean)) = %f", i, initialResiduals[i-1]);
\r
196 restore_memory_state(mem_state);
\r
201 int updateBoundParameters(DATA *data)
\r
205 mem_state = get_memory_state();
\r
206 restore_memory_state(mem_state);
\r
212 void eqFunction_0(DATA *data) {
\r
213 modelica_boolean tmp0;
\r
214 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:24:2-24:93]*/
\r
216 $PvalveBoolean = (((tmp0 || $Pb) || (!$Pb))?($Pb?1.0:-1.0):$P$PRE$PvalveBoolean);
\r
217 /*#endModelicaLine*/
\r
221 void eqFunction_1(DATA *data) {
\r
222 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:28:2-28:34]*/
\r
223 $P$DER$PstockBoolean = $PvalveBoolean;
\r
224 /*#endModelicaLine*/
\r
228 void eqFunction_2(DATA *data) {
\r
229 modelica_boolean tmp1;
\r
230 modelica_boolean tmp2;
\r
231 modelica_boolean tmp3;
\r
232 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:25:2-25:80]*/
\r
234 RELATIONTOZC(tmp2, (modelica_integer)$Pi, (modelica_integer) 0, -1,Less,<);
\r
235 RELATIONTOZC(tmp3, (modelica_integer)$Pi, (modelica_integer) 0, -1,GreaterEq,>=);
\r
236 $PvalveInteger = (((tmp1 || tmp2) || tmp3)?((modelica_real)(modelica_integer)$Pi):$P$PRE$PvalveInteger);
\r
237 /*#endModelicaLine*/
\r
241 void eqFunction_3(DATA *data) {
\r
242 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:29:2-29:34]*/
\r
243 $P$DER$PstockInteger = $PvalveInteger;
\r
244 /*#endModelicaLine*/
\r
248 void eqFunction_4(DATA *data) {
\r
249 modelica_boolean tmp4;
\r
250 modelica_boolean tmp5;
\r
251 modelica_boolean tmp6;
\r
252 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:26:2-26:74]*/
\r
254 RELATIONTOZC(tmp5, $Pr, 0.0, -1,Less,<);
\r
255 RELATIONTOZC(tmp6, $Pr, 0.0, -1,GreaterEq,>=);
\r
256 $PvalveReal = (((tmp4 || tmp5) || tmp6)?$Pr:$P$PRE$PvalveReal);
\r
257 /*#endModelicaLine*/
\r
261 void eqFunction_5(DATA *data) {
\r
262 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:30:2-30:28]*/
\r
263 $P$DER$PstockReal = $PvalveReal;
\r
264 /*#endModelicaLine*/
\r
267 static void functionODE_system0(DATA *data,int omc_thread_number)
\r
269 eqFunction_0(data);
\r
270 eqFunction_1(data);
\r
271 eqFunction_2(data);
\r
272 eqFunction_3(data);
\r
273 eqFunction_4(data);
\r
274 eqFunction_5(data);
\r
276 static void (*functionODE_systems[1])(DATA *, int) = {
\r
277 functionODE_system0
\r
280 void function_initMemoryState()
\r
282 push_memory_states(1);
\r
285 int functionODE(DATA *data)
\r
288 state mem_state; /* We need to have separate memory pools for separate systems... */
\r
289 mem_state = get_memory_state();
\r
290 for (id=0; id<1; id++) {
\r
291 th_id = omp_get_thread_num();
\r
292 functionODE_systems[id](data,th_id);
\r
294 restore_memory_state(mem_state);
\r
298 #include <simulation_inline_solver.h>
\r
299 const char *_omc_force_solver=_OMC_FORCE_SOLVER;
\r
300 const int inline_work_states_ndims=_OMC_SOLVER_WORK_STATES_NDIMS;
\r
301 int functionODE_inline(DATA* data, double stepSize)
\r
307 void eqFunction_6(DATA *data) {
\r
308 modelica_boolean tmp10;
\r
309 modelica_boolean tmp11;
\r
310 modelica_boolean tmp12;
\r
311 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:22:2-22:84]*/
\r
313 RELATIONTOZC(tmp11, $Pr, 0.0, -1,Less,<);
\r
314 RELATIONTOZC(tmp12, $Pr, 0.0, -1,GreaterEq,>=);
\r
315 $PcontinuousReal = (((tmp10 || tmp11) || tmp12)?$Pr:$P$PRE$PcontinuousReal);
\r
316 /*#endModelicaLine*/
\r
319 /* for continuous time variables */
\r
320 int functionAlgebraics(DATA *data)
\r
324 mem_state = get_memory_state();
\r
325 eqFunction_6(data);
\r
326 restore_memory_state(mem_state);
\r
332 void eqFunction_7(DATA *data) {
\r
333 modelica_boolean tmp13;
\r
334 modelica_boolean tmp14;
\r
335 modelica_boolean tmp15;
\r
336 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:26:2-26:74]*/
\r
338 SAVEZEROCROSS(tmp14, $Pr, 0.0, -1,Less,<);
\r
339 SAVEZEROCROSS(tmp15, $Pr, 0.0, -1,GreaterEq,>=);
\r
340 $PvalveReal = (((tmp13 || tmp14) || tmp15)?$Pr:$P$PRE$PvalveReal);
\r
341 /*#endModelicaLine*/
\r
345 void eqFunction_8(DATA *data) {
\r
346 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:30:2-30:28]*/
\r
347 $P$DER$PstockReal = $PvalveReal;
\r
348 /*#endModelicaLine*/
\r
352 void eqFunction_9(DATA *data) {
\r
353 modelica_boolean tmp16;
\r
354 modelica_boolean tmp17;
\r
355 modelica_boolean tmp18;
\r
356 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:25:2-25:80]*/
\r
358 SAVEZEROCROSS(tmp17, (modelica_integer)$Pi, (modelica_integer) 0, -1,Less,<);
\r
359 SAVEZEROCROSS(tmp18, (modelica_integer)$Pi, (modelica_integer) 0, -1,GreaterEq,>=);
\r
360 $PvalveInteger = (((tmp16 || tmp17) || tmp18)?((modelica_real)(modelica_integer)$Pi):$P$PRE$PvalveInteger);
\r
361 /*#endModelicaLine*/
\r
365 void eqFunction_10(DATA *data) {
\r
366 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:29:2-29:34]*/
\r
367 $P$DER$PstockInteger = $PvalveInteger;
\r
368 /*#endModelicaLine*/
\r
372 void eqFunction_11(DATA *data) {
\r
373 modelica_boolean tmp19;
\r
374 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:24:2-24:93]*/
\r
376 $PvalveBoolean = (((tmp19 || $Pb) || (!$Pb))?($Pb?1.0:-1.0):$P$PRE$PvalveBoolean);
\r
377 /*#endModelicaLine*/
\r
381 void eqFunction_12(DATA *data) {
\r
382 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:28:2-28:34]*/
\r
383 $P$DER$PstockBoolean = $PvalveBoolean;
\r
384 /*#endModelicaLine*/
\r
388 void eqFunction_13(DATA *data) {
\r
389 modelica_boolean tmp20;
\r
390 modelica_boolean tmp21;
\r
391 modelica_boolean tmp22;
\r
392 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:22:2-22:84]*/
\r
394 SAVEZEROCROSS(tmp21, $Pr, 0.0, -1,Less,<);
\r
395 SAVEZEROCROSS(tmp22, $Pr, 0.0, -1,GreaterEq,>=);
\r
396 $PcontinuousReal = (((tmp20 || tmp21) || tmp22)?$Pr:$P$PRE$PcontinuousReal);
\r
397 /*#endModelicaLine*/
\r
401 void eqFunction_14(DATA *data) {
\r
402 modelica_boolean tmp23;
\r
403 modelica_boolean tmp24;
\r
404 modelica_boolean tmp25;
\r
405 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:21:2-21:86]*/
\r
407 SAVEZEROCROSS(tmp24, (modelica_integer)$Pi, (modelica_integer) 0, -1,Less,<);
\r
408 SAVEZEROCROSS(tmp25, (modelica_integer)$Pi, (modelica_integer) 0, -1,GreaterEq,>=);
\r
409 $PdiscreteInteger = (((tmp23 || tmp24) || tmp25)?(modelica_integer)$Pi:$P$PRE$PdiscreteInteger);
\r
410 /*#endModelicaLine*/
\r
414 void eqFunction_15(DATA *data) {
\r
415 modelica_boolean tmp26;
\r
416 /*#modelicaLine [FMUAllTypesOfVariablesTest.mo:20:2-20:81]*/
\r
418 $PdiscreteBoolean = (((tmp26 || $Pb) || (!$Pb))?$Pb:$P$PRE$PdiscreteBoolean);
\r
419 /*#endModelicaLine*/
\r
422 int functionDAE(DATA *data, int *needToIterate)
\r
425 *needToIterate = 0;
\r
427 mem_state = get_memory_state();
\r
428 eqFunction_7(data);
\r
429 eqFunction_8(data);
\r
430 eqFunction_9(data);
\r
431 eqFunction_10(data);
\r
432 eqFunction_11(data);
\r
433 eqFunction_12(data);
\r
434 eqFunction_13(data);
\r
435 eqFunction_14(data);
\r
436 eqFunction_15(data);
\r
437 restore_memory_state(mem_state);
\r
442 int function_onlyZeroCrossings(DATA *data, double *gout,double *t)
\r
446 mem_state = get_memory_state();
\r
447 restore_memory_state(mem_state);
\r
452 int checkForDiscreteChanges(DATA *data)
\r
454 int needToIterate = 0;
\r
456 if ($PdiscreteBoolean != $P$PRE$PdiscreteBoolean) { DEBUG_INFO2(LOG_EVENTS,"Discrete Var discreteBoolean : %d to %d", $P$PRE$PdiscreteBoolean, $PdiscreteBoolean); needToIterate=1; }
\r
457 if ($PdiscreteInteger != $P$PRE$PdiscreteInteger) { DEBUG_INFO2(LOG_EVENTS,"Discrete Var discreteInteger : %ld to %ld", $P$PRE$PdiscreteInteger, $PdiscreteInteger); needToIterate=1; }
\r
459 return needToIterate;
\r
462 /* function to check assert after a step is done */
\r
463 int checkForAsserts(DATA *data)
\r
470 int initialAnalyticJacobianA(DATA* data){
\r
474 int initialAnalyticJacobianB(DATA* data){
\r
478 int initialAnalyticJacobianC(DATA* data){
\r
482 int initialAnalyticJacobianD(DATA* data){
\r
485 int functionJacA(DATA* data, double* jac){
\r
489 int functionJacB(DATA* data, double* jac){
\r
493 int functionJacC(DATA* data, double* jac){
\r
497 int functionJacD(DATA* data, double* jac){
\r
501 const char *linear_model_frame =
\r
502 "model linear_FMUAllTypesOfVariablesTestModel\n parameter Integer n = 3; // states \n parameter Integer k = 0; // top-level inputs \n parameter Integer l = 0; // top-level outputs \n"
\r
503 " parameter Real x0[3] = {%s};\n"
\r
504 " parameter Real u0[0] = {%s};\n"
\r
505 " parameter Real A[3,3] = [%s];\n"
\r
506 " parameter Real B[3,0] = zeros(3,0);%s\n"
\r
507 " parameter Real C[0,3] = zeros(0,3);%s\n"
\r
508 " parameter Real D[0,0] = zeros(0,0);%s\n"
\r
509 " Real x[3](start=x0);\n"
\r
510 " input Real u[0];\n"
\r
511 " output Real y[0];\n"
\r
512 "\n Real x_PstockBoolean = x[1];\n Real x_PstockInteger = x[2];\n Real x_PstockReal = x[3];\n \n"
\r
513 "equation\n der(x) = A * x + B * u;\n y = C * x + D * u;\nend linear_FMUAllTypesOfVariablesTestModel;\n"
\r
520 /* forward the main in the simulation runtime */
\r
521 extern int _main_SimulationRuntime(int argc, char**argv, DATA *data);
\r
523 /* call the simulation runtime main from our main! */
\r
524 int main(int argc, char**argv)
\r
527 setupDataStruc(&data);
\r
528 return _main_SimulationRuntime(argc, argv, &data);
\r