Ticket #1680: Test.Test1.c

File Test.Test1.c, 13.4 KB (added by chenouard-r, 13 years ago)
Line 
1/* Simulation code for Test.Test1 generated by the OpenModelica Compiler 1.8.0 (r10946). */
2
3#include "openmodelica.h"
4#include "openmodelica_func.h"
5#include "simulation_data.h"
6#include "simulation_runtime.h"
7#include "error.h"
8
9#include <assert.h>
10#include <string.h>
11
12#include "Test.Test1_functions.h"
13
14#include "_Test.Test1.h"
15#include "Test.Test1_functions.c"
16#define _OMC_SEED_HACK char* _omc_hack
17#define _OMC_SEED_HACK_2 NULL
18/* dummy VARINFO and FILEINFO */
19const FILE_INFO dummyFILE_INFO = {"",-1,-1,-1,-1,1};
20const VAR_INFO dummyVAR_INFO = {-1,"","",(FILE_INFO){"",-1,-1,-1,-1,1}};
21#ifdef __cplusplus
22extern "C" {
23#endif
24#ifdef _OMC_MEASURE_TIME
25int measure_time_flag = 1;
26#else
27int measure_time_flag = 0;
28#endif
29
30void initializeDataStruc_X_(DATA *data)
31{
32 ASSERT(data,"Error while initialize Data");
33 data->modelData.modelName = "Test.Test1";
34 data->modelData.modelFilePrefix = "Test.Test1";
35 data->modelData.modelDir = "";
36 data->modelData.modelGUID = "{8c4e810f-3df3-4a00-8276-176fa3c9f9e0}";
37
38 data->modelData.nStates = 1;
39 data->modelData.nVariablesReal = 2*1+2;
40 data->modelData.nVariablesInteger = 1;
41 data->modelData.nVariablesBoolean = 0;
42 data->modelData.nVariablesString = 0;
43 data->modelData.nParametersReal = 11;
44 data->modelData.nParametersInteger = 7;
45 data->modelData.nParametersBoolean = 0;
46 data->modelData.nParametersString = 0;
47 data->modelData.nInputVars = 0;
48 data->modelData.nOutputVars = 0;
49 data->modelData.nJacobianVars = 0;
50 data->modelData.nHelpVars = 0;
51
52 data->modelData.nAliasReal = 1;
53 data->modelData.nAliasInteger = 0;
54 data->modelData.nAliasBoolean = 0;
55 data->modelData.nAliasString = 0;
56
57 data->modelData.nZeroCrossings = 2;
58 data->modelData.nSamples = 0;
59 data->modelData.nInitEquations = 0;
60 data->modelData.nResiduals = 2;
61 data->modelData.nExtObjs = 0;
62 data->modelData.nFunctions = 1;
63 data->modelData.nEquations = 5;
64
65 data->modelData.nDelayExpressions = 0;
66
67}
68
69void initializeDataStruc_X_2(DATA *data)
70{
71 const struct FUNCTION_INFO funcInfo[1] = {
72 {1005,"Test.F1",{"test.mo",17,3,33,9,0}}
73 };
74 memcpy(data->modelData.functionNames, &funcInfo, data->modelData.nFunctions*sizeof(FUNCTION_INFO));
75
76 const VAR_INFO** equationInfo_cref1 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
77 equationInfo_cref1[0] = &$P$DER$P$dummy__varInfo;
78 const VAR_INFO** equationInfo_cref3 = (const VAR_INFO**)calloc(1,sizeof(VAR_INFO*));
79 equationInfo_cref3[0] = &$Prp$Py__varInfo;
80 const struct EQUATION_INFO equationInfo[5] = {
81 {1006,"SES_ALGORITHM 0",0,NULL},
82 {1007,"SES_SIMPLE_ASSIGN 1",1,equationInfo_cref1},
83 {1008,"SES_ALGORITHM 2",0,NULL},
84 {1009,"SES_SIMPLE_ASSIGN 3",1,equationInfo_cref3},
85 {1010,"SES_ALGORITHM 4",0,NULL}
86 };
87 const int n_omc_equationInfo_reverse_prof_index = 0;
88 const int omc_equationInfo_reverse_prof_index[] = {
89
90 };
91 memcpy(data->modelData.equationInfo, &equationInfo, data->modelData.nEquations*sizeof(EQUATION_INFO));
92
93 data->modelData.nProfileBlocks = n_omc_equationInfo_reverse_prof_index;
94 data->modelData.equationInfo_reverse_prof_index = (int*) malloc(data->modelData.nProfileBlocks*sizeof(int));
95 memcpy(data->modelData.equationInfo_reverse_prof_index, omc_equationInfo_reverse_prof_index, data->modelData.nProfileBlocks*sizeof(int));
96}
97
98/* Has to be performed after _init.xml file has been read */
99void callExternalObjectConstructors(DATA *data)
100{
101 state mem_state;
102 mem_state = get_memory_state();
103 /* data->simulationInfo.extObjs = NULL; */
104}
105
106void callExternalObjectDestructors(DATA *data)
107{
108 if (data->simulationInfo.extObjs) {
109 free(data->simulationInfo.extObjs);
110 data->simulationInfo.extObjs = 0;
111 }
112}
113
114
115int input_function(DATA *data)
116{
117 return 0;
118}
119
120int output_function(DATA *data)
121{
122 return 0;
123}
124
125/* Initializes the raw time events of the simulation using the now
126 calcualted parameters. */
127void function_sampleInit(DATA *data)
128{
129}
130
131int function_updateSample(DATA *data)
132{
133 state mem_state;
134
135 mem_state = get_memory_state();
136 restore_memory_state(mem_state);
137
138 return 0;
139}
140
141int function_storeDelayed(DATA *data)
142{
143 state mem_state;
144
145 mem_state = get_memory_state();
146 restore_memory_state(mem_state);
147
148 return 0;
149}
150
151int updateBoundStartValues(DATA *data)
152{
153
154
155
156 return 0;
157}
158
159int initial_residual(DATA *data, double $P$_lambda, double* initialResiduals)
160{
161 int i = 0;
162 state mem_state;
163
164 mem_state = get_memory_state();
165 initialResiduals[i++] = ($P$_lambda * ($P$dummy - $P$START$P$dummy));
166 DEBUG_INFO2(LOG_RES_INIT,"Residual[%d] : $_lambda * ($dummy - $_start($dummy)) = %f",i,initialResiduals[i-1]);
167 initialResiduals[i++] = ((1.0 - $P$_lambda) * ($Pm$Pn - $P$START$Pm$Pn));
168 DEBUG_INFO2(LOG_RES_INIT,"Residual[%d] : (1.0 - $_lambda) * (m.n - $_start(m.n)) = %f",i,initialResiduals[i-1]);
169 restore_memory_state(mem_state);
170
171 return 0;
172}
173
174
175void eqFunction_0(DATA *data, _OMC_SEED_HACK) {
176 /*#modelicaLine [/opt/local/lib/omlibrary/msl31/../Modelica 3.1/Blocks/Sources.mo:442:9-443:26]*/#
177 if (!($Prp$Pduration >= 1e-60)) {
178 FILE_INFO info = {"/opt/local/lib/omlibrary/msl31/../Modelica 3.1/Blocks/Sources.mo",442,9,443,26,1};
179 MODELICA_ASSERT(info, "Variable rp.duration out of limit");
180 }
181 /*#endModelicaLine*/
182}
183
184int updateBoundParameters(DATA *data)
185{
186 state mem_state;
187
188 mem_state = get_memory_state();
189 eqFunction_0(data, _OMC_SEED_HACK_2);
190 restore_memory_state(mem_state);
191
192 return 0;
193}
194
195
196void eqFunction_1(DATA *data, _OMC_SEED_HACK) {
197 /* Dummy Line */
198 $P$DER$P$dummy = 0.0;
199 /*#endModelicaLine*/
200}
201
202static void functionODE_system0(DATA *data,int omc_thread_number)
203{
204 eqFunction_1(data, _OMC_SEED_HACK_2);
205}
206static void (*functionODE_systems[1])(DATA *, int) = {
207 functionODE_system0
208};
209
210void function_initMemoryState()
211{
212 push_memory_states(1);
213}
214
215int functionODE(DATA *data)
216{
217 int id,th_id;
218 state mem_state; /* We need to have separate memory pools for separate systems... */
219 mem_state = get_memory_state();
220 for (id=0; id<1; id++) {
221 th_id = omp_get_thread_num();
222 functionODE_systems[id](data,th_id);
223 }
224 restore_memory_state(mem_state);
225
226 return 0;
227}
228#include <simulation_inline_solver.h>
229const char *_omc_force_solver=_OMC_FORCE_SOLVER;
230const int inline_work_states_ndims=_OMC_SOLVER_WORK_STATES_NDIMS;
231int functionODE_inline(DATA* data, double stepSize)
232{
233 return 0;
234}
235
236
237void eqFunction_2(DATA *data, _OMC_SEED_HACK) {
238 modelica_boolean tmp0;
239 modelica_boolean tmp1;
240 modelica_real tmp2;
241 modelica_boolean tmp3;
242 modelica_real tmp4;
243 modelica_boolean tmp5;
244 modelica_real tmp6;
245 /*#modelicaLine [/opt/local/lib/omlibrary/msl31/../Modelica 3.1/Blocks/Sources.mo:450:9-451:73]*/
246 RELATIONTOZC(tmp0, time, $Prp$PstartTime, 0,Less,<);
247 tmp5 = (modelica_boolean)tmp0;
248 if (tmp5) {
249 tmp6 = (modelica_real)0.0;
250 } else {
251 RELATIONTOZC(tmp1, time, ($Prp$PstartTime + $Prp$Pduration), 1,Less,<);
252 tmp3 = (modelica_boolean)tmp1;
253 if (tmp3) {
254 tmp2 = DIVISION(((time - $Prp$PstartTime) * $Prp$Pheight), $Prp$Pduration, _OMC_LIT3);
255 tmp4 = (modelica_real)tmp2;
256 } else {
257 tmp4 = (modelica_real)$Prp$Pheight;
258 }
259 tmp6 = (modelica_real)tmp4;
260 }
261 $Prp$Py = ($Prp$Poffset + tmp6);
262 /*#endModelicaLine*/
263}
264
265
266void eqFunction_3(DATA *data, _OMC_SEED_HACK) {
267 state tmp7;
268 modelica_real tmp11;
269 integer_array tmp12;
270 real_array tmp13;
271 Test_F1_rettype tmp14;
272 /*#modelicaLine [test.mo:13:2-13:34]*/#
273 {
274 integer_array tmp8;
275 int tmp9;
276 integer_array tmp10;
277 modelica_real _$reductionFoldTmpB;
278 modelica_real _$reductionFoldTmpA;
279 integer_array_create(&tmp10, ((modelica_integer*)&($Pm$Pt1)), 1, :);
280 tmp8 = tmp10;
281 tmp9 = 1;
282 _$reductionFoldTmpB = 0.0; /* defaultValue */
283 while (tmp9 <= size_of_dimension_integer_array(tmp8, 1)) {
284 modelica_integer $Pi;
285 $Pi = *(integer_array_element_addr1(&tmp8, 1, tmp9++));
286 tmp7 = get_memory_state();
287 if (1) {
288 _$reductionFoldTmpA = (&$Pm$Pt2)[(((modelica_integer)$Pi))];
289 _$reductionFoldTmpB = ($P$reductionFoldTmpA + $P$reductionFoldTmpB);
290 }
291 restore_memory_state(tmp7);
292 }
293 tmp11 = _$reductionFoldTmpB;
294 }
295 $Pm$Ps = tmp11;
296 /*#endModelicaLine*/
297 /*#modelicaLine [test.mo:14:2-14:22]*/#
298 integer_array_create(&tmp12, ((modelica_integer*)&($Pm$Pt1)), 1, 7);
299 real_array_create(&tmp13, ((modelica_real*)&($Pm$Pt2)), 1, 7);
300 #ifdef _OMC_MEASURE_TIME
301 SIM_PROF_TICK_FN(Test_F1_index);
302 #endif
303 tmp14 = _Test_F1((modelica_integer)$Pm$Pn, $Prp$Py, $Pm$Ps, tmp12, tmp13);
304 #ifdef _OMC_MEASURE_TIME
305 SIM_PROF_ACC_FN(Test_F1_index);
306 #endif
307 $Pm$Pn = tmp14.Test_F1_rettype_1;
308 /*#endModelicaLine*/
309}
310
311/* for continuous time variables */
312int functionAlgebraics(DATA *data)
313{
314 state mem_state;
315
316 mem_state = get_memory_state();
317 eqFunction_2(data, _OMC_SEED_HACK_2);
318 eqFunction_3(data, _OMC_SEED_HACK_2);
319 restore_memory_state(mem_state);
320
321 return 0;
322}
323
324/* for continuous time variables */
325int functionAliasEquations(DATA *data)
326{
327 state mem_state;
328
329 mem_state = get_memory_state();
330 restore_memory_state(mem_state);
331
332 return 0;
333}
334
335
336void eqFunction_4(DATA *data, _OMC_SEED_HACK) {
337 /* Dummy Line */
338 $P$DER$P$dummy = 0.0;
339 /*#endModelicaLine*/
340}
341
342
343void eqFunction_5(DATA *data, _OMC_SEED_HACK) {
344 modelica_boolean tmp15;
345 modelica_boolean tmp16;
346 modelica_real tmp17;
347 modelica_boolean tmp18;
348 modelica_real tmp19;
349 modelica_boolean tmp20;
350 modelica_real tmp21;
351 /*#modelicaLine [/opt/local/lib/omlibrary/msl31/../Modelica 3.1/Blocks/Sources.mo:450:9-451:73]*/
352 SAVEZEROCROSS(tmp15, time, $Prp$PstartTime, 0,Less,<);
353 tmp20 = (modelica_boolean)tmp15;
354 if (tmp20) {
355 tmp21 = (modelica_real)0.0;
356 } else {
357 SAVEZEROCROSS(tmp16, time, ($Prp$PstartTime + $Prp$Pduration), 1,Less,<);
358 tmp18 = (modelica_boolean)tmp16;
359 if (tmp18) {
360 tmp17 = DIVISION(((time - $Prp$PstartTime) * $Prp$Pheight), $Prp$Pduration, _OMC_LIT3);
361 tmp19 = (modelica_real)tmp17;
362 } else {
363 tmp19 = (modelica_real)$Prp$Pheight;
364 }
365 tmp21 = (modelica_real)tmp19;
366 }
367 $Prp$Py = ($Prp$Poffset + tmp21);
368 /*#endModelicaLine*/
369}
370
371
372void eqFunction_6(DATA *data, _OMC_SEED_HACK) {
373 state tmp22;
374 modelica_real tmp26;
375 integer_array tmp27;
376 real_array tmp28;
377 Test_F1_rettype tmp29;
378 /*#modelicaLine [test.mo:13:2-13:34]*/#
379 {
380 integer_array tmp23;
381 int tmp24;
382 integer_array tmp25;
383 modelica_real _$reductionFoldTmpB;
384 modelica_real _$reductionFoldTmpA;
385 integer_array_create(&tmp25, ((modelica_integer*)&($Pm$Pt1)), 1, :);
386 tmp23 = tmp25;
387 tmp24 = 1;
388 _$reductionFoldTmpB = 0.0; /* defaultValue */
389 while (tmp24 <= size_of_dimension_integer_array(tmp23, 1)) {
390 modelica_integer $Pi;
391 $Pi = *(integer_array_element_addr1(&tmp23, 1, tmp24++));
392 tmp22 = get_memory_state();
393 if (1) {
394 _$reductionFoldTmpA = (&$Pm$Pt2)[(((modelica_integer)$Pi))];
395 _$reductionFoldTmpB = ($P$reductionFoldTmpA + $P$reductionFoldTmpB);
396 }
397 restore_memory_state(tmp22);
398 }
399 tmp26 = _$reductionFoldTmpB;
400 }
401 $Pm$Ps = tmp26;
402 /*#endModelicaLine*/
403 /*#modelicaLine [test.mo:14:2-14:22]*/#
404 integer_array_create(&tmp27, ((modelica_integer*)&($Pm$Pt1)), 1, 7);
405 real_array_create(&tmp28, ((modelica_real*)&($Pm$Pt2)), 1, 7);
406 #ifdef _OMC_MEASURE_TIME
407 SIM_PROF_TICK_FN(Test_F1_index);
408 #endif
409 tmp29 = _Test_F1((modelica_integer)$Pm$Pn, $Prp$Py, $Pm$Ps, tmp27, tmp28);
410 #ifdef _OMC_MEASURE_TIME
411 SIM_PROF_ACC_FN(Test_F1_index);
412 #endif
413 $Pm$Pn = tmp29.Test_F1_rettype_1;
414 /*#endModelicaLine*/
415}
416
417int functionDAE(DATA *data, int *needToIterate)
418{
419 state mem_state;
420 *needToIterate = 0;
421
422 mem_state = get_memory_state();
423 eqFunction_4(data, _OMC_SEED_HACK_2);
424 eqFunction_5(data, _OMC_SEED_HACK_2);
425 eqFunction_6(data, _OMC_SEED_HACK_2);
426 restore_memory_state(mem_state);
427
428 return 0;
429}
430
431int function_onlyZeroCrossings(DATA *data, double *gout,double *t)
432{
433 state mem_state;
434
435 mem_state = get_memory_state();
436 ZEROCROSSING(0, Less(time, $Prp$PstartTime));
437 ZEROCROSSING(1, Less(time, ($Prp$PstartTime + $Prp$Pduration)));
438 restore_memory_state(mem_state);
439
440 return 0;
441}
442
443int checkForDiscreteChanges(DATA *data)
444{
445 int needToIterate = 0;
446
447 if ($Pm$Pn != $P$PRE$Pm$Pn) { DEBUG_INFO2(LOG_EVENTS,"Discrete Var m.n : %ld to %ld", $P$PRE$Pm$Pn, $Pm$Pn); needToIterate=1; }
448
449 return needToIterate;
450}
451
452/* for continuous time variables */
453int checkForAsserts(DATA *data)
454{
455
456
457 return 0;
458}
459
460 int functionJacA(DATA* data, double* jac){
461 return 0;
462 }
463
464 int functionJacB(DATA* data, double* jac){
465 return 0;
466 }
467
468 int functionJacC(DATA* data, double* jac){
469 return 0;
470 }
471
472 int functionJacD(DATA* data, double* jac){
473 return 0;
474 }
475
476const char *linear_model_frame =
477 "model linear_Test.Test1\n parameter Integer n = 1; // states \n parameter Integer k = 0; // top-level inputs \n parameter Integer l = 0; // top-level outputs \n"
478 " parameter Real x0[1] = {%s};\n"
479 " parameter Real u0[0] = {%s};\n"
480 " parameter Real A[1,1] = [%s];\n"
481 " parameter Real B[1,0] = zeros(1,0);%s\n"
482 " parameter Real C[0,1] = zeros(0,1);%s\n"
483 " parameter Real D[0,0] = zeros(0,0);%s\n"
484 " Real x[1](start=x0);\n"
485 " input Real u[0];\n"
486 " output Real y[0];\n"
487 "\n Real x_P$dummy = x[1];\n \n"
488 "equation\n der(x) = A * x + B * u;\n y = C * x + D * u;\nend linear_Test.Test1;\n"
489;
490
491#ifdef __cplusplus
492}
493#endif
494
495/* forward the main in the simulation runtime */
496extern int _main_SimulationRuntime(int argc, char**argv, DATA *data);
497
498/* call the simulation runtime main from our main! */
499int main(int argc, char**argv)
500{
501 DATA data;
502 initializeDataStruc_X_(&data);
503 return _main_SimulationRuntime(argc, argv, &data);
504}
505