Skip to content

Commit 5bb9ff3

Browse files
committed
Fix for time events that occur in every cycle in calcOneStep()
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24368 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1378b56 commit 5bb9ff3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

SimulationRuntime/cpp/Core/SimController/SimManager.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void SimManager::initialize()
140140
if (_timeeventcounter)
141141
delete[] _timeeventcounter;
142142
_timeeventcounter = new int[_dimtimeevent];
143+
memset(_timeeventcounter, 0, _dimtimeevent * sizeof(int));
143144
// compute sampleCycles for RT simulation
144145
if (_config->getGlobalSettings()->useEndlessSim())
145146
{
@@ -181,6 +182,9 @@ void SimManager::initialize()
181182
_resetCycle = _sampleCycles[0];
182183
for (int i = 1; i < _dimtimeevent; i++)
183184
_resetCycle *= _sampleCycles[i];
185+
// All Events are updated every cycle. In order to have a change in timeEventCounter, the reset is set to two
186+
if(_resetCycle == 1)
187+
_resetCycle++;
184188
_solver->initialize();
185189
}
186190
//#endif
@@ -195,9 +199,10 @@ void SimManager::initialize()
195199
void SimManager::runSingleStep(double cycletime)
196200
{
197201
// Increase time event counter
198-
if (_dimtimeevent)
202+
if (_dimtimeevent && cycletime > 0.0)
199203
{
200-
if (_lastCycleTime && cycletime != _lastCycleTime)
204+
205+
if (_lastCycleTime && cycletime != _lastCycleTime)
201206
throw std::runtime_error("Cycle time can not be changed, if time events (samples) are present!");
202207
else
203208
_lastCycleTime = cycletime;
@@ -207,21 +212,20 @@ void SimManager::runSingleStep(double cycletime)
207212
if (_cycleCounter % _sampleCycles[i] == 0)
208213
_timeeventcounter[i]++;
209214
}
210-
215+
}
211216
//Handle time event
212217
_timeevent_system->handleTimeEvent(_timeeventcounter);
213218
_cont_system->evaluateAll(IContinuous::CONTINUOUS);
214219
_event_system->saveAll();
215220
_timeevent_system->handleTimeEvent(_timeeventcounter);
216-
}
217-
221+
218222
// Solve
219223
_solver->setcycletime(cycletime);
220224
_solver->solve(_solverTask);
221-
222-
_cycleCounter++;
223-
// Reset everything to prevent overflows
224-
if (_cycleCounter == _resetCycle + 1)
225+
226+
_cycleCounter++;
227+
// Reset everything to prevent overflows
228+
if (_cycleCounter == _resetCycle + 1)
225229
{
226230
_cycleCounter = 1;
227231
for (int i = 0; i < _dimtimeevent; i++)

0 commit comments

Comments
 (0)