OMCompiler/SimulationRuntime/cpp/Core/System/ContinuousEvents.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 coreSystem | ||
| 29 | * | ||
| 30 | * @{ | ||
| 31 | */ | ||
| 32 | #include <Core/ModelicaDefine.h> | ||
| 33 | #include <Core/Modelica.h> | ||
| 34 | #include <Core/System/FactoryExport.h> | ||
| 35 | #include <Core/System/ContinuousEvents.h> | ||
| 36 | #include <Core/Math/Functions.h> | ||
| 37 | #include <Core/Utils/extension/logger.hpp> | ||
| 38 | |||
| 39 | 43 | ContinuousEvents::ContinuousEvents() | |
| 40 | 43 | : _event_system(NULL) | |
| 41 | 43 | , _countinous_system(NULL) | |
| 42 | 43 | , _mixed_system(NULL) | |
| 43 | 43 | , _conditions0(NULL) | |
| 44 | 43 | , _conditions1(NULL) | |
| 45 | 43 | ,_clockconditions0(NULL) | |
| 46 | 43 | ,_clockconditions1(NULL) | |
| 47 | |||
| 48 | { | ||
| 49 | 43 | } | |
| 50 | |||
| 51 | 86 | ContinuousEvents::~ContinuousEvents(void) | |
| 52 | { | ||
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(_conditions0) |
| 55 | 19 | delete[] _conditions0; | |
| 56 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(_conditions1) |
| 57 | 19 | delete[] _conditions1; | |
| 58 | |||
| 59 | |||
| 60 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockconditions0) |
| 61 | 7 | delete[] _clockconditions0; | |
| 62 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockconditions1) |
| 63 | 7 | delete[] _clockconditions1; | |
| 64 | |||
| 65 | |||
| 66 | 86 | } | |
| 67 | |||
| 68 | /** | ||
| 69 | Inits the event variables | ||
| 70 | */ | ||
| 71 | 43 | void ContinuousEvents::initialize(IEvent* system) | |
| 72 | { | ||
| 73 | // _dimH=dim; | ||
| 74 | 43 | _event_system=system; | |
| 75 | 43 | unsigned int dimZero = _event_system->getDimZeroFunc(); | |
| 76 | 43 | unsigned int dimClock = _event_system->getDimClock(); | |
| 77 | |||
| 78 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | _countinous_system = dynamic_cast<IContinuous*>(_event_system); |
| 79 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | _mixed_system= dynamic_cast<IMixedSystem*>(_event_system); |
| 80 | |||
| 81 | |||
| 82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if(_conditions0) |
| 83 | ✗ | delete[] _conditions0; | |
| 84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if(_conditions1) |
| 85 | ✗ | delete[] _conditions1; | |
| 86 | |||
| 87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if(_clockconditions0) |
| 88 | ✗ | delete[] _clockconditions0; | |
| 89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if(_clockconditions1) |
| 90 | ✗ | delete[] _clockconditions1; | |
| 91 | |||
| 92 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(dimZero> 0) |
| 93 | { | ||
| 94 | 19 | _conditions0 = new bool[_event_system->getDimZeroFunc()]; | |
| 95 | 19 | _conditions1 = new bool[_event_system->getDimZeroFunc()]; | |
| 96 | } | ||
| 97 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(dimClock > 0) |
| 98 | { | ||
| 99 | 7 | _clockconditions0 = new bool[_event_system->getDimClock()]; | |
| 100 | 7 | _clockconditions1 = new bool[_event_system->getDimClock()]; | |
| 101 | } | ||
| 102 | 43 | } | |
| 103 | |||
| 104 | |||
| 105 | |||
| 106 | /** | ||
| 107 | Handles all events occurred a the same time. | ||
| 108 | */ | ||
| 109 | 7794 | bool ContinuousEvents::startEventIteration(bool& state_vars_reinitialized) | |
| 110 | { | ||
| 111 | //save discrete variables | ||
| 112 | //Deactivated: _event_system->saveDiscreteVars(); // store values of discrete vars vor next check | ||
| 113 | |||
| 114 | 7794 | unsigned int dim = _event_system->getDimZeroFunc(); | |
| 115 | //unsigned int dimClock = _event_system->getDimClock(); | ||
| 116 | |||
| 117 | 7794 | _event_system->getConditions(_conditions0); | |
| 118 | //_event_system->getClockConditions(_clockconditions0); | ||
| 119 | |||
| 120 | //Handle all events | ||
| 121 | bool assert = false; | ||
| 122 | bool drestart = false; | ||
| 123 | bool crestart = false; | ||
| 124 | try | ||
| 125 | { | ||
| 126 | |||
| 127 |
1/1✓ Branch 1 taken 7794 times.
|
7794 | state_vars_reinitialized = _countinous_system->evaluateConditions(); |
| 128 | |||
| 129 | |||
| 130 | //check if discrete variables changed | ||
| 131 |
1/1✓ Branch 1 taken 7794 times.
|
7794 | drestart = _event_system->checkForDiscreteEvents(); //discrete time conditions |
| 132 | |||
| 133 |
1/1✓ Branch 1 taken 7794 times.
|
7794 | _event_system->getConditions(_conditions1); |
| 134 | //_event_system->getClockConditions(_clockconditions1); | ||
| 135 | |||
| 136 |
2/2✓ Branch 0 taken 7161 times.
✓ Branch 1 taken 633 times.
|
7794 | if (dim > 0) |
| 137 | { | ||
| 138 | ✗ | LOGGER_WRITE_VECTOR("conditions", _conditions1, dim, LC_EVENTS, LL_DEBUG); | |
| 139 |
1/2✓ Branch 0 taken 7161 times.
✗ Branch 1 not taken.
|
14322 | crestart = !std::equal(_conditions1, _conditions1 + dim, _conditions0); |
| 140 | } | ||
| 141 | } | ||
| 142 | ✗ | catch (std::exception& ex) | |
| 143 | { | ||
| 144 | ✗ | LOGGER_WRITE(string("Failed evaluating event conditions: ") + ex.what(), LC_EVENTS, LL_DEBUG); | |
| 145 | // if evaluateConditions throws and error during event iteration the event iteration will restarted | ||
| 146 | assert = true; | ||
| 147 | ✗ | } | |
| 148 |
3/4✓ Branch 0 taken 3340 times.
✓ Branch 1 taken 4454 times.
✓ Branch 2 taken 3340 times.
✗ Branch 3 not taken.
|
11134 | return(drestart || crestart || assert); //returns true if new events occurred |
| 149 | } | ||
| 150 | |||
| 151 |