Changeset e1dbd879 in OpenModelica
- Timestamp:
- 2022-05-16T11:15:56+02:00 (2 years ago)
- Children:
- 14ac561
- Parents:
- 5b747e9
- git-author:
- Philip Hannebohm <phannebohm@…> (05/16/22 10:46:52)
- git-committer:
- Philip Hannebohm <phannebohm@…> (05/16/22 11:15:56)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OMCompiler/SimulationRuntime/c/simulation/solver/events.c
r5b747e9 re1dbd879 299 299 static LIST tmpEventList = (LIST){NULL, NULL, sizeof(long), 0}; 300 300 301 /* FIXME stop allocating all the time*/302 double *states_right = (double*) malloc(data->modelData->nStates * sizeof(double));303 double *states_left = (double*) malloc(data->modelData->nStates * sizeof(double));301 /* static work arrays */ 302 static double *states_left = NULL; 303 static double *states_right = NULL; 304 304 305 305 double time_left = data->simulationInfo->timeValueOld; 306 306 double time_right = data->localData[0]->timeValue; 307 307 308 assert(states_right); 309 assert(states_left); 310 311 for(it=listFirstNode(eventList); it; it=listNextNode(it)) 312 { 313 infoStreamPrint(LOG_ZEROCROSSINGS, 0, "search for current event. Events in list: %ld", *((long*)listNodeData(it))); 308 /* allocate memory once at first call, never free */ 309 if(!states_left) 310 { 311 states_left = (double*) malloc(data->modelData->nStates * sizeof(double)); 312 assertStreamPrint(NULL, NULL != states_left, "out of memory"); 313 } 314 if(!states_right) 315 { 316 states_right = (double*) malloc(data->modelData->nStates * sizeof(double)); 317 assertStreamPrint(NULL, NULL != states_right, "out of memory"); 314 318 } 315 319 … … 317 321 memcpy(states_left, data->simulationInfo->realVarsOld, data->modelData->nStates * sizeof(double)); 318 322 memcpy(states_right, data->localData[0]->realVars , data->modelData->nStates * sizeof(double)); 323 324 for(it=listFirstNode(eventList); it; it=listNextNode(it)) 325 { 326 infoStreamPrint(LOG_ZEROCROSSINGS, 0, "search for current event. Events in list: %ld", *((long*)listNodeData(it))); 327 } 319 328 320 329 /* Search for event time and event_id with bisection method */ … … 349 358 while(listLen(&tmpEventList) > 0) 350 359 { 360 /* TODO do this directly w/o free-malloc */ 351 361 long event_id = *((long*)listFirstData(&tmpEventList)); 352 362 listPopFront(&tmpEventList); … … 359 369 360 370 data->localData[0]->timeValue = time_left; 361 for(i=0; i < data->modelData->nStates; i++) { 362 data->localData[0]->realVars[i] = states_left[i]; 363 } 371 memcpy(data->localData[0]->realVars, states_left, data->modelData->nStates * sizeof(double)); 364 372 365 373 /* determined continuous system */ … … 369 377 370 378 data->localData[0]->timeValue = time_right; 371 for(i=0; i < data->modelData->nStates; i++) 372 { 373 data->localData[0]->realVars[i] = states_right[i]; 374 } 375 376 free(states_left); 377 free(states_right); 379 memcpy(data->localData[0]->realVars, states_right, data->modelData->nStates * sizeof(double)); 378 380 379 381 TRACE_POP
Note: See TracChangeset
for help on using the changeset viewer.