Skip to content

Commit 60b2c68

Browse files
committed
Handling time events at one time instant at once
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23780 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent df6a438 commit 60b2c68

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

SimulationRuntime/cpp/Core/SimController/SimManager.cpp

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ void SimManager::runSingleProcess()
578578
{
579579
_timeevent_system->handleTimeEvent(_timeeventcounter);
580580
}
581-
_cont_system->evaluateODE(IContinuous::CONTINUOUS); // vxworksupdate
581+
_cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate
582582
_event_system->getZeroFunc(zeroVal_new);
583583

584584
for (int i = 0; i < _dimZeroFunc; i++)
@@ -605,50 +605,41 @@ void SimManager::runSingleProcess()
605605
for (; iter != _tStops[0].end(); ++iter)
606606
{
607607
endTime = iter->first;
608-
if (endTime - startTime < UROUND)
608+
609+
// Setzen von Start- bzw. Endzeit und initial step size
610+
_solver->setStartTime(startTime);
611+
_solver->setEndTime(endTime);
612+
_solver->setInitStepSize(_config->getGlobalSettings()->gethOutput());
613+
_solver->solve(_solverTask);
614+
615+
if (_solverTask & ISolver::FIRST_CALL)
609616
{
610-
startTime = endTime;
611-
_timeeventcounter[iter->second]++;
612-
_timeevent_system->handleTimeEvent(_timeeventcounter);
613-
_cont_system->evaluateODE(IContinuous::CONTINUOUS); // vxworksupdate
617+
_solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL);
618+
_solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL);
619+
}
620+
startTime = endTime;
621+
if (_dimtimeevent)
622+
{
623+
// Find all time events at the current time
624+
while(abs(iter->first - endTime) <1e4*UROUND)
625+
{
626+
_timeeventcounter[iter->second]++;
627+
iter++;
628+
}
629+
// set the iterator back to the current end time
630+
iter--;
631+
632+
_timeevent_system->handleTimeEvent(_timeeventcounter);
633+
_cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate
614634
_event_system->getZeroFunc(zeroVal_new);
615635
for (int i = 0; i < _dimZeroFunc; i++)
616636
_events[i] = bool(zeroVal_new[i]);
617637
_mixed_system->handleSystemEvents(_events);
618-
//_cont_system->evaluateODE(IContinuous::CONTINUOUS);
619638
//reset time-events
620639
_timeevent_system->handleTimeEvent(_timeeventcounter);
621640
}
622-
else
623-
{
624-
// Setzen von Start- bzw. Endzeit und initial step size
625-
_solver->setStartTime(startTime);
626-
_solver->setEndTime(endTime);
627-
_solver->setInitStepSize(_config->getGlobalSettings()->gethOutput());
628-
_solver->solve(_solverTask);
629-
630-
if (_solverTask & ISolver::FIRST_CALL)
631-
{
632-
_solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL);
633-
_solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL);
634-
}
635-
startTime = endTime;
636-
if (_dimtimeevent)
637-
{
638-
_timeeventcounter[iter->second]++;
639-
_timeevent_system->handleTimeEvent(_timeeventcounter);
640-
_cont_system->evaluateODE(IContinuous::CONTINUOUS); // vxworksupdate
641-
_event_system->getZeroFunc(zeroVal_new);
642-
for (int i = 0; i < _dimZeroFunc; i++)
643-
_events[i] = bool(zeroVal_new[i]);
644-
_mixed_system->handleSystemEvents(_events);
645-
//_cont_system->evaluateODE(IContinuous::CONTINUOUS);
646-
//reset time-events
647-
_timeevent_system->handleTimeEvent(_timeeventcounter);
648-
}
649-
}
650-
651-
user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP);
641+
642+
user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP);
652643
if (user_stop)
653644
break;
654645
} // end for time events
@@ -697,7 +688,7 @@ void SimManager::runSingleProcess()
697688
if (zeroVal_new)
698689
{
699690
_timeevent_system->handleTimeEvent(_timeeventcounter);
700-
_cont_system->evaluateODE(IContinuous::CONTINUOUS); // vxworksupdate
691+
_cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate
701692
_event_system->getZeroFunc(zeroVal_new);
702693
for (int i = 0; i < _dimZeroFunc; i++)
703694
_events[i] = bool(zeroVal_new[i]);

0 commit comments

Comments
 (0)