Linux GNU 11.4.0 Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 62.4% 151 / 0 / 242
Functions: 60.0% 6 / 0 / 10
Branches: 26.4% 98 / 0 / 371

OMCompiler/SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Line Branch Exec Source
1 /*
2 * This file belongs to the OpenModelica Run-Time System
3 *
4 * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), c/o Linköpings
5 * universitet, Department of Computer and Information Science, SE-58183 Linköping, Sweden. All rights
6 * reserved.
7 *
8 * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF THE BSD NEW LICENSE OR THE
9 * AGPL VERSION 3 LICENSE OR THE OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. ANY
10 * USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
11 * ACCEPTANCE OF THE BSD NEW LICENSE OR THE OSMC PUBLIC LICENSE OR THE AGPL
12 * VERSION 3, ACCORDING TO RECIPIENTS CHOICE.
13 *
14 * The OpenModelica software and the OSMC (Open Source Modelica Consortium) Public License
15 * (OSMC-PL) are obtained from OSMC, either from the above address, from the URLs:
16 * http://www.openmodelica.org or https://github.com/OpenModelica/ or
17 * http://www.ida.liu.se/projects/OpenModelica, and in the OpenModelica distribution. GNU
18 * AGPL version 3 is obtained from: https://www.gnu.org/licenses/licenses.html#GPL. The BSD NEW
19 * License is obtained from: http://www.opensource.org/licenses/BSD-3-Clause.
20 *
21 * This program is distributed WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY
23 * SET FORTH IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF
24 * OSMC-PL.
25 *
26 */
27
28 /** @addtogroup coreSimcontroller
29 *
30 * @{
31 */
32 #include <Core/ModelicaDefine.h>
33 #include <Core/Modelica.h>
34 #include <Core/SimController/FactoryExport.h>
35 #include <Core/Utils/extension/logger.hpp>
36 #include <Core/SimController/SimManager.h>
37
38 #include <sstream>
39
40 40 SimManager::SimManager(shared_ptr<IMixedSystem> system, Configuration* config)
41 40 : _mixed_system (system)
42
1/1
✓ Branch 1 taken 40 times.
40 , _config (config)
43 40 , _dimTimeEvent (0)
44 40 , _dimZeroFunc (0)
45 40 , _timeEventCounter (NULL)
46 40 , _zeroVal (NULL)
47 40 , _events (NULL)
48 40 , _sampleCycles (NULL)
49 40 , _cycleCounter (0)
50 40 , _resetCycle (0)
51 40 , _solverTask (ISolver::UNDEF_CALL)
52 40 , _H (0)
53 40 , _dbgId (0)
54 40 , _tStart (0)
55 40 , _tEnd (0)
56 40 , _lastCycleTime (0)
57 40 , _continueSimulation(false)
58
1/1
✓ Branch 1 taken 40 times.
40 , _checkTimeout(false)
59 {
60
1/1
✓ Branch 1 taken 40 times.
40 _solver = _config->createSelectedSolver(system.get());
61
4/10
✓ Branch 2 taken 40 times.
✓ Branch 5 taken 40 times.
✓ Branch 7 taken 40 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 40 times.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
160 _initialization = shared_ptr<Initialization>(new Initialization(dynamic_pointer_cast<ISystemInitialization>(_mixed_system), _solver));
62
63 #ifdef RUNTIME_PROFILING
64 if(MeasureTime::getInstance() != NULL)
65 {
66 measureTimeFunctionsArray = new std::vector<MeasureTimeData*>(2, NULL); //0 runSimulation, initializeSimulation
67 (*measureTimeFunctionsArray)[0] = new MeasureTimeData("initializeSimulation");
68 (*measureTimeFunctionsArray)[1] = new MeasureTimeData("runSimulation");
69
70 MeasureTime::addResultContentBlock(system->getModelName(),"simmanager",measureTimeFunctionsArray);
71
72 initSimStartValues = MeasureTime::getZeroValues();
73 initSimEndValues = MeasureTime::getZeroValues();
74 runSimStartValues = MeasureTime::getZeroValues();
75 runSimEndValues = MeasureTime::getZeroValues();
76 }
77 else
78 {
79 measureTimeFunctionsArray = new std::vector<MeasureTimeData*>();
80 initSimStartValues = NULL;
81 initSimEndValues = NULL;
82 runSimStartValues = NULL;
83 runSimEndValues = NULL;
84 }
85 #endif
86 40 }
87
88 40 SimManager::~SimManager()
89 {
90
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (_timeEventCounter)
91 40 delete[] _timeEventCounter;
92
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (_zeroVal)
93 40 delete[] _zeroVal;
94
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (_events)
95 40 delete[] _events;
96
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (_sampleCycles)
97 ✗ delete[] _sampleCycles;
98
99 #ifdef RUNTIME_PROFILING
100 if(initSimStartValues)
101 delete initSimStartValues;
102 if(initSimEndValues)
103 delete initSimEndValues;
104 if(runSimStartValues)
105 delete runSimStartValues;
106 if(runSimEndValues)
107 delete runSimEndValues;
108 #endif
109 40 }
110
111 40 void SimManager::initialize()
112 {
113 #ifdef RUNTIME_PROFILING
114 MEASURETIME_REGION_DEFINE(initSimHandler, "initializeSimulation");
115 if (MeasureTime::getInstance() != NULL)
116 {
117 MEASURETIME_START(initSimStartValues, initSimHandler, "initializeSimulation");
118 }
119 #endif
120
121 40 _cont_system = dynamic_pointer_cast<IContinuous>(_mixed_system);
122 40 _timeevent_system = dynamic_pointer_cast<ITime>(_mixed_system);
123 40 _event_system = dynamic_pointer_cast<IEvent>(_mixed_system);
124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 40 times.
80 _step_event_system = dynamic_pointer_cast<IStepEvent>(_mixed_system);
125
126 // Check dynamic casts
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!_event_system)
128 {
129 ✗ throw ModelicaSimulationError(SIMMANAGER,"Could not get event system.");
130 }
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!_cont_system)
132 {
133 ✗ throw ModelicaSimulationError(SIMMANAGER,"Could not get continuous-event system.");
134 }
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!_timeevent_system)
136 {
137 ✗ throw ModelicaSimulationError(SIMMANAGER,"Could not get time-event system.");
138 }
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (!_step_event_system)
140 {
141 ✗ throw ModelicaSimulationError(SIMMANAGER,"Could not get step-event system.");
142 }
143
144 40 shared_ptr<IGlobalSettings> global_settings = _config->getGlobalSettings();
145
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 _tStart = global_settings->getStartTime();
146
2/3
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
40 _tEnd = global_settings->getEndTime();
147
148
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
2 LOGGER_WRITE("SimManager: Start initialization", LC_SOLVER, LL_INFO);
149
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 LOGGER_STATUS_STARTING(_tStart, _tEnd);
150
151 // Reset debug ID
152
1/1
✓ Branch 1 taken 40 times.
40 _dbgId = 0;
153
154
1/1
✓ Branch 1 taken 40 times.
40 _solver->setStartTime(_tStart);
155 try
156 {
157 // Build up system and update once
158
1/1
✓ Branch 1 taken 40 times.
40 _initialization->initializeSystem();
159 }
160 ✗ catch (std::exception& ex)
161 {
162 ✗ LOGGER_WRITE("SimManager: Could not initialize system", LC_INIT, LL_ERROR);
163 ✗ LOGGER_WRITE("SimManager: " + string(ex.what()), LC_INIT, LL_ERROR);
164 // Write current values as they might help to analyse the error
165 ✗ _solver->solve(ISolver::RECORDCALL);
166 ✗ throw ModelicaSimulationError(SIMMANAGER, "Could not initialize system",
167 ✗ string(ex.what()), LOGGER_IS_SET(LC_INIT, LL_ERROR));
168 ✗ }
169 // Write initial values
170
1/1
✓ Branch 1 taken 40 times.
40 _solver->solve(ISolver::RECORDCALL);
171
172
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (_timeevent_system)
173 {
174
1/1
✓ Branch 1 taken 40 times.
40 _dimTimeEvent = _timeevent_system->getDimTimeEvent();
175
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (_timeEventCounter)
176 ✗ delete[] _timeEventCounter;
177
2/3
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
40 _timeEventCounter = new int[_dimTimeEvent];
178
1/1
✓ Branch 1 taken 40 times.
40 memset(_timeEventCounter, 0, _dimTimeEvent * sizeof(int));
179 // compute sampleCycles for RT simulation
180
3/4
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
80 if (_config->getGlobalSettings()->useEndlessSim())
181 {
182 ✗ if (_sampleCycles)
183 ✗ delete[] _sampleCycles;
184 ✗ _sampleCycles = new int[_dimTimeEvent];
185 ✗ computeSampleCycles();
186 }
187 }
188 else
189 ✗ _dimTimeEvent = 0;
190
191 // Set flag for endless simulation (if solver returns)
192 40 _continueSimulation = _tEnd > _tStart;
193
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if(_checkTimeout)
195 {
196 //being uncomment for labeling reduction
197 ✗ _solver->setTimeOut(_config->getGlobalSettings()->getAlarmTime());
198 }
199
1/1
✓ Branch 1 taken 40 times.
40 _dimZeroFunc = _event_system->getDimZeroFunc();
200
1/1
✓ Branch 1 taken 40 times.
40 _solverTask = ISolver::SOLVERCALL(ISolver::FIRST_CALL);
201
2/3
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
40 if (_dimZeroFunc == _event_system->getDimZeroFunc())
202 {
203
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (_zeroVal)
204 ✗ delete[] _zeroVal;
205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
40 if (_events)
206 ✗ delete[] _events;
207
2/3
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 40 times.
40 _zeroVal = new double[_dimZeroFunc];
208
1/1
✓ Branch 1 taken 40 times.
40 _events = new bool[_dimZeroFunc];
209 40 memset(_zeroVal, 0, _dimZeroFunc * sizeof(double));
210 40 memset(_events, false, _dimZeroFunc * sizeof(bool));
211 }
212
213 ✗ LOGGER_WRITE("SimManager: Assemble completed",LC_INIT,LL_DEBUG);
214
215 // Initialization for RT simulation
216
3/6
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
80 if (_config->getGlobalSettings()->useEndlessSim())
217 {
218 ✗ _cycleCounter = 0;
219 ✗ _resetCycle = _sampleCycles[0];
220 ✗ for (int i = 1; i < _dimTimeEvent; i++)
221 ✗ _resetCycle *= _sampleCycles[i];
222 // All Events are updated every cycle. In order to have a change in timeEventCounter, the reset is set to two
223 ✗ if(_resetCycle == 1)
224 ✗ _resetCycle++;
225 ✗ _solver->initialize();
226 }
227
228 #ifdef RUNTIME_PROFILING
229 if (MeasureTime::getInstance() != NULL)
230 {
231 MEASURETIME_END(initSimStartValues, initSimEndValues, (*measureTimeFunctionsArray)[0], initSimHandler);
232 }
233 #endif
234 40 }
235
236 ✗ void SimManager::runSingleStep()
237 {
238 // Increase time event counter
239 ✗ double cycletime = _config->getGlobalSettings()->gethOutput();
240 ✗ if (_dimTimeEvent && cycletime > 0.0)
241 {
242
243 ✗ if (_lastCycleTime && cycletime != _lastCycleTime)
244 ✗ throw ModelicaSimulationError(SIMMANAGER,"Cycle time can not be changed, if time events (samples) are present!");
245 else
246 ✗ _lastCycleTime = cycletime;
247
248 ✗ for (int i = 0; i < _dimTimeEvent; i++)
249 {
250 ✗ if (_cycleCounter % _sampleCycles[i] == 0)
251 ✗ _timeEventCounter[i]++;
252 }
253
254 // Handle time event
255 ✗ _timeevent_system->computeTimeEventConditions(cycletime);
256 ✗ _cont_system->evaluateAll(IContinuous::CONTINUOUS);
257 ✗ _event_system->saveAll();
258 ✗ _timeevent_system->resetTimeConditions();
259 }
260 // Solve
261 ✗ _solver->solve(_solverTask);
262
263 ✗ _cycleCounter++;
264 // Reset everything to prevent overflows
265 ✗ if (_cycleCounter == _resetCycle + 1)
266 {
267 ✗ _cycleCounter = 1;
268 ✗ for (int i = 0; i < _dimTimeEvent; i++)
269 ✗ _timeEventCounter[i] = 0;
270 }
271 ✗ }
272
273 ✗ void SimManager::computeSampleCycles()
274 {
275 int counter = 0;
276
277 ✗ _timeevent_system->initTimeEventData();
278 ✗ int dimTimeEvent = _timeevent_system->getDimTimeEvent();
279 ✗ std::pair<double, double>* timeEventData = _timeevent_system->getTimeEventData();
280
281 ✗ for (int i = 0; i < dimTimeEvent; i++)
282 {
283 ✗ double startTime = timeEventData[i].first;
284 ✗ double interval = timeEventData[i].second;
285
286 ✗ if (startTime != 0.0 || interval == 0.0)
287 {
288 ✗ throw ModelicaSimulationError(SIMMANAGER,"Time event not starting at t=0.0 or not cyclic!");
289 }
290 else
291 {
292 // Check if sample time is a multiple of the cycle time (with a tolerance)
293 ✗ if (std::fabs((interval / _config->getGlobalSettings()->gethOutput()) - int((interval / _config->getGlobalSettings()->gethOutput()) + 0.5)) <= 1e6 * UROUND)
294 {
295 ✗ _sampleCycles[counter] = int((interval / _config->getGlobalSettings()->gethOutput()) + 0.5);
296 }
297 else
298 {
299 ✗ throw ModelicaSimulationError(SIMMANAGER,"Sample time is not a multiple of the cycle time!");
300 }
301
302 }
303 ✗ counter++;
304 }
305 ✗ }
306
307
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 void SimManager::runSimulation()
308 {
309 #ifdef RUNTIME_PROFILING
310 MEASURETIME_REGION_DEFINE(runSimHandler, "runSimulation");
311 if (MeasureTime::getInstance() != NULL)
312 {
313 MEASURETIME_START(runSimStartValues, runSimHandler, "runSimulation");
314 }
315 #endif
316 try
317 {
318
4/7
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
2 LOGGER_WRITE("SimManager: Start simulation at t = " + to_string(_tStart), LC_SOLVER, LL_INFO);
319
1/1
✓ Branch 1 taken 40 times.
40 runSingleProcess();
320 // Measure time; Output SimInfos
321
1/1
✓ Branch 1 taken 40 times.
40 ISolver::SOLVERSTATUS status = _solver->getSolverStatus();
322
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 if ((status & ISolver::DONE) || (status & ISolver::USER_STOP))
323 {
324 //LOGGER_WRITE("SimManager: Simulation done at t = " + to_string(_tEnd), LC_SOLVER, LL_INFO);
325
1/1
✓ Branch 1 taken 32 times.
32 writeProperties();
326 }
327 }
328 ✗ catch (std::exception & ex)
329 {
330 ✗ LOGGER_WRITE("SimManager: Simulation stopped with errors before t = " +
331 to_string(_tEnd), LC_SOLVER, LL_ERROR);
332 ✗ LOGGER_WRITE("SimManager: " + string(ex.what()), LC_SOLVER, LL_ERROR);
333 ✗ writeProperties();
334 // rethrow with suppress depending on logger setting to not appear twice
335 ✗ throw ModelicaSimulationError(SIMMANAGER, "Simulation stopped with errors before t = " + to_string(_tEnd),
336 ✗ string(ex.what()), LOGGER_IS_SET(LC_SOLVER, LL_ERROR));
337 ✗ }
338 #ifdef RUNTIME_PROFILING
339 if (MeasureTime::getInstance() != NULL)
340 {
341 MEASURETIME_END(runSimStartValues, runSimEndValues, (*measureTimeFunctionsArray)[1], runSimHandler);
342 }
343 #endif
344 40 }
345
346 ✗ void SimManager::stopSimulation()
347 {
348 ✗ if (_solver)
349 ✗ _solver->stop();
350 ✗ }
351
352 ✗ void SimManager::SetCheckTimeout(bool checkTimeout)
353 {
354 ✗ _checkTimeout=checkTimeout;
355 ✗ }
356
357
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 void SimManager::writeProperties()
358 {
359 // declaration for Logging
360 std::pair<LogCategory, LogLevel> logM = Logger::getLogMode(LC_SOLVER, LL_INFO);
361
362
3/6
✓ Branch 2 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
2 LOGGER_WRITE_TUPLE("SimManager: Simulation stop time: " + to_string(_tEnd), logM);
363 //LOGGER_WRITE("Rechenzeit in Sekunden: " + to_string>(_tClockEnd-_tClockStart), logM);
364
365
1/1
✓ Branch 2 taken 1 time.
2 LOGGER_WRITE_BEGIN("Simulation info from solver:", LC_SOLVER, LL_INFO);
366 32 _solver->writeSimulationInfo();
367 1 LOGGER_WRITE_END(LC_SOLVER, LL_INFO);
368 32 }
369
370 40 void SimManager::runSingleProcess()
371 {
372 double startTime, endTime;
373 double closestTimeEvent = 0.0;
374
375 40 _H = _tEnd;
376 //nw _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECORDCALL);
377 40 _solver->setStartTime(_tStart);
378 40 _solver->setEndTime(_tEnd);
379
380 //nw _solver->solve(_solverTask);
381 //initialize();
382 //nw _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL);
383
384 //get information about time events
385 40 _timeevent_system->initTimeEventData();
386 40 closestTimeEvent = _timeevent_system->computeNextTimeEvents(_tStart);
387
388 /* Logs temporarily disabled
389 BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) <<"Run single process." ; */
390 ✗ LOGGER_WRITE("SimManager: Run single process", LC_SOLVER, LL_DEBUG);
391
392 40 memset(_timeEventCounter, 0, _dimTimeEvent * sizeof(int));
393 40 _timeevent_system->setTime(_tStart);
394
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 26 times.
40 if (_dimTimeEvent)
395 {
396 14 _timeevent_system->computeTimeEventConditions(_tStart);
397 }
398 // _cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate
399 40 _event_system->getZeroFunc(_zeroVal);
400
401
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 40 times.
148 for (int i = 0; i < _dimZeroFunc; i++)
402 {
403 108 _events[i] = bool(_zeroVal[i]);
404 }
405 40 _mixed_system->handleSystemEvents(_events);
406 //_cont_system->evaluateODE(IContinuous::CONTINUOUS);
407 // Reset the time-events after the evaluation of handleSystemEvents()
408
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 26 times.
40 if (_dimTimeEvent)
409 {
410 14 _timeevent_system->resetTimeConditions();
411 }
412
413 40 _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECORDCALL);
414 40 _solver->setStartTime(_tStart);
415 40 _solver->setEndTime(_tEnd);
416 40 _solver->solve(_solverTask);
417 40 _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL);
418
419 /* time measurement temporary disabled
420 // Startzeit messen
421 _tClockStart = Time::Time().getSeconds();
422 */
423 40 startTime = endTime = _tStart;
424 bool user_stop = false;
425
426
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 40 times.
72 while (_continueSimulation)
427 {
428
2/2
✓ Branch 0 taken 1830 times.
✓ Branch 1 taken 32 times.
1862 while (closestTimeEvent <= _tEnd)
429 {
430
431 // Set start time, end time, initial step size
432 1830 endTime = closestTimeEvent;//endTime = iter->first;
433 1830 _solver->setStartTime(startTime);
434 1830 _solver->setEndTime(endTime);
435
3/6
✓ Branch 2 taken 1830 times.
✓ Branch 5 taken 1830 times.
✓ Branch 7 taken 1830 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
3660 _solver->setInitStepSize(_config->getGlobalSettings()->gethOutput());
436 1830 _solver->solve(_solverTask);
437
438
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 1818 times.
1830 if (_solverTask & ISolver::FIRST_CALL)
439 {
440 12 _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL);
441 12 _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL);
442 }
443 //prepare next step, starting from last endTime
444 1830 startTime = endTime;
445
1/2
✓ Branch 0 taken 1830 times.
✗ Branch 1 not taken.
1830 if (_dimTimeEvent)
446 {
447 // Find all time events at the current time and compute next one
448 1830 closestTimeEvent = _timeevent_system->computeNextTimeEvents(startTime);
449 1830 _timeevent_system->computeTimeEventConditions(startTime);
450
451 1830 _event_system->getZeroFunc(_zeroVal);
452
2/2
✓ Branch 0 taken 29645 times.
✓ Branch 1 taken 1830 times.
31475 for (int i = 0; i < _dimZeroFunc; i++)
453 {
454 29645 _events[i] = bool(_zeroVal[i]);
455 }
456 //handleSystemEvents calls evaluateAll() at some point and evaluates the sampler conditions
457 1830 _mixed_system->handleSystemEvents(_events);
458 // Reset time-events after the evaluation in handleSystemEvents
459 1830 _timeevent_system->resetTimeConditions();
460
461 // Record result of time event (important for pulses)
462 1830 _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECORDCALL);
463 1830 _solver->setStartTime(startTime);
464 1830 _solver->solve(_solverTask);
465 1830 _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL);
466
467 //evaluate all to finish the step
468 1830 _cont_system->evaluateAll(IContinuous::CONTINUOUS);
469 1830 _event_system->saveAll();
470 }
471
472 1830 user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP);
473
1/2
✓ Branch 0 taken 1830 times.
✗ Branch 1 not taken.
1830 if (user_stop)
474 break;
475 } // end for time events
476
477
3/4
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
32 if (abs(_tEnd - endTime) > _config->getSolverSettings()->getEndTimeTol() && !user_stop)
478 {
479 23 startTime = endTime;
480 23 _solver->setStartTime(startTime);
481 23 _solver->setEndTime(_tEnd);
482
3/6
✓ Branch 2 taken 23 times.
✓ Branch 5 taken 23 times.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
46 _solver->setInitStepSize(_config->getGlobalSettings()->gethOutput());
483 23 _solver->solve(_solverTask);
484 // In _solverTask FIRST_CALL Bit löschen und RECALL Bit setzen
485
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 3 times.
23 if (_solverTask & ISolver::FIRST_CALL)
486 {
487 20 _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL);
488 20 _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL);
489 }
490 if (user_stop)
491 break;
492 } // end if weiter nach Time Events
493
494 // Finish Simulation
495
4/16
✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 32 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 32 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
64 if ((!(_config->getGlobalSettings()->useEndlessSim())) || (_solver->getSolverStatus() & ISolver::SOLVERERROR) || (_solver->getSolverStatus() & ISolver::USER_STOP))
496 {
497 32 _continueSimulation = false;
498 }
499
500 // Endless simulation
501 else
502 {
503 // increase time intervall
504 ✗ _tStart = _tEnd;
505 ✗ _tEnd += _H;
506
507 ✗ if (_dimTimeEvent)
508 {
509 ✗ if (_zeroVal)
510 {
511 ✗ closestTimeEvent = _timeevent_system->computeNextTimeEvents(startTime);
512 ✗ _timeevent_system->computeTimeEventConditions(_tEnd);
513 ✗ _cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate
514 ✗ _event_system->getZeroFunc(_zeroVal);
515 ✗ for (int i = 0; i < _dimZeroFunc; i++)
516 {
517 ✗ _events[i] = bool(_zeroVal[i]);
518 }
519 //_cont_system->evaluateODE(IContinuous::CONTINUOUS);
520 //reset time-events
521 ✗ _timeevent_system->resetTimeConditions();
522 ✗ _cont_system->evaluateAll(IContinuous::CONTINUOUS);
523 ✗ _event_system->saveAll();
524 }
525 }
526 }
527
528 } // end while continue
529
530 // treat terminal() and continuous events at final time
531 40 _step_event_system->setTerminal(true);
532 40 _cont_system->evaluateZeroFuncs(IContinuous::DISCRETE);
533 40 _event_system->getZeroFunc(_zeroVal);
534
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 40 times.
148 for (int i = 0; i < _dimZeroFunc; i++)
535 108 _events[i] = bool(_zeroVal[i]);
536 40 _mixed_system->handleSystemEvents(_events);
537
538 // record final values
539 40 _solverTask = ISolver::SOLVERCALL(ISolver::RECORDCALL);
540 40 _solver->solve(_solverTask);
541
542
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 LOGGER_STATUS("Finished", endTime, 0.0);
543 40 } // end singleprocess
544 /** @} */ // end of coreSimcontroller
545