OMCompiler/SimulationRuntime/cpp/Core/System/SystemDefaultImplementation.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 | |||
| 35 | #include <Core/System/FactoryExport.h> | ||
| 36 | #include <Core/Utils/extension/logger.hpp> | ||
| 37 | #include <Core/System/EventHandling.h> | ||
| 38 | #include <Core/System/SystemDefaultImplementation.h> | ||
| 39 | #include <Core/System/AlgLoopSolverFactory.h> | ||
| 40 | |||
| 41 | |||
| 42 | template <class T> | ||
| 43 | 10622 | void InitVars<T>::setStartValue(T& variable,T val,bool overwriteOldValue) | |
| 44 | { | ||
| 45 | //only add a start value if it was not already defined | ||
| 46 |
22/24InitVars<bool>::setStartValue(bool&, bool, bool):
✓ Branch 0 taken 429 times.
✓ Branch 1 taken 653 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 317 times.
✓ Branch 4 taken 112 times.
✗ Branch 5 not taken.
InitVars<double>::setStartValue(double&, double, bool):
✓ Branch 0 taken 3018 times.
✓ Branch 1 taken 5351 times.
✓ Branch 2 taken 2209 times.
✓ Branch 3 taken 809 times.
✓ Branch 4 taken 2147 times.
✓ Branch 5 taken 62 times.
InitVars<int>::setStartValue(int&, int, bool):
✓ Branch 0 taken 453 times.
✓ Branch 1 taken 625 times.
✓ Branch 2 taken 160 times.
✓ Branch 3 taken 293 times.
✓ Branch 4 taken 155 times.
✓ Branch 5 taken 5 times.
InitVars<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::setStartValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool):
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
|
10622 | if(!_start_values.count(&variable) || overwriteOldValue) |
| 47 | 8232 | _start_values[&variable] = val; | |
| 48 | else | ||
| 49 |
1/8InitVars<bool>::setStartValue(bool&, bool, bool):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
InitVars<double>::setStartValue(double&, double, bool):
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
InitVars<int>::setStartValue(int&, int, bool):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
InitVars<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::setStartValue(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool):
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
16 | LOGGER_WRITE("SystemDefaultImplementation: start value for variable is already defined",LC_INIT,LL_DEBUG); |
| 50 | 10622 | }; | |
| 51 | |||
| 52 | template <class T> | ||
| 53 | T& InitVars<T>::getGetStartValue(T& variable) | ||
| 54 | { | ||
| 55 | 2088 | return _start_values[&variable]; | |
| 56 | }; | ||
| 57 | |||
| 58 | |||
| 59 | ✗ | bool greaterTime( pair<unsigned int,double> t1, double t2) | |
| 60 | { | ||
| 61 | ✗ | return t1.second > t2; | |
| 62 | } | ||
| 63 | |||
| 64 | 43 | SystemDefaultImplementation::SystemDefaultImplementation(IGlobalSettings *globalSettings,shared_ptr<ISimObjects> simObjects,string modelName) | |
| 65 | 43 | : _simTime (0.0) | |
| 66 | , _simObjects (simObjects) | ||
| 67 |
7/10✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
✓ Branch 9 taken 43 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 37 times.
✓ Branch 14 taken 43 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
135 | , __z (_simObjects->getSimVars(modelName)->getStateVector()) |
| 68 |
6/9✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
✓ Branch 9 taken 43 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 37 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
129 | , __zDot (_simObjects->getSimVars(modelName)->getDerStateVector()) |
| 69 |
1/1✓ Branch 1 taken 43 times.
|
43 | , __daeResidual (NULL) |
| 70 | 43 | , _conditions (NULL) | |
| 71 | 43 | , _time_conditions(NULL) | |
| 72 | 43 | , _zeroTol (1e-6) | |
| 73 | 43 | , _dimContinuousStates(0) | |
| 74 | 43 | , _dimRHS (0) | |
| 75 | 43 | , _dimReal (0) | |
| 76 | 43 | , _dimInteger (0) | |
| 77 | 43 | , _dimBoolean (0) | |
| 78 | 43 | , _dimString (0) | |
| 79 | 43 | , _dimZeroFunc (0) | |
| 80 | 43 | , _dimTimeEvent (0) | |
| 81 | 43 | , _dimClock (0) | |
| 82 | 43 | , _dimAE (0) | |
| 83 | 43 | , _timeEventData (NULL) | |
| 84 | 43 | , _currTimeEvents (NULL) | |
| 85 | 43 | , _clockInterval (NULL) | |
| 86 | 43 | , _clockShift (NULL) | |
| 87 | 43 | , _clockTime (NULL) | |
| 88 | 43 | , _clockEventBased(NULL) | |
| 89 | 43 | , _clockCondition (NULL) | |
| 90 | 43 | , _clockStart (NULL) | |
| 91 | 43 | , _clockSubactive (NULL) | |
| 92 | 43 | , _outputStream (NULL) | |
| 93 | 43 | , _callType (IContinuous::UNDEF_UPDATE) | |
| 94 | 43 | , _initial (false) | |
| 95 | 43 | , _delay_max (0.0) | |
| 96 | 43 | , _start_time (0.0) | |
| 97 | 43 | , _terminal (false) | |
| 98 | 43 | , _terminate (false) | |
| 99 | 43 | , _global_settings(globalSettings) | |
| 100 |
1/1✓ Branch 1 taken 43 times.
|
43 | , _conditions0 (NULL) |
| 101 | 43 | , _event_system (NULL) | |
| 102 |
1/1✓ Branch 1 taken 43 times.
|
43 | , _modelName (modelName) |
| 103 | 43 | , _freeVariablesLock(false) | |
| 104 | { | ||
| 105 | 43 | } | |
| 106 | |||
| 107 | ✗ | SystemDefaultImplementation::SystemDefaultImplementation(SystemDefaultImplementation& instance) | |
| 108 | ✗ | : _simTime (0.0) | |
| 109 | ✗ | , _simObjects (shared_ptr<ISimObjects>(instance.getSimObjects()->clone())) | |
| 110 | ✗ | , __z (_simObjects->getSimVars(instance.getModelName())->getStateVector()) | |
| 111 | ✗ | , __zDot (_simObjects->getSimVars(instance.getModelName())->getDerStateVector()) | |
| 112 | ✗ | , __daeResidual (NULL) | |
| 113 | ✗ | , _conditions (NULL) | |
| 114 | ✗ | , _time_conditions(NULL) | |
| 115 | ✗ | , _zeroTol (1e-6) | |
| 116 | ✗ | , _dimContinuousStates(0) | |
| 117 | ✗ | , _dimRHS (0) | |
| 118 | ✗ | , _dimReal (0) | |
| 119 | ✗ | , _dimInteger (0) | |
| 120 | ✗ | , _dimBoolean (0) | |
| 121 | ✗ | , _dimString (0) | |
| 122 | ✗ | , _dimZeroFunc (0) | |
| 123 | ✗ | , _dimTimeEvent (0) | |
| 124 | ✗ | , _dimClock (0) | |
| 125 | ✗ | , _dimAE (0) | |
| 126 | ✗ | , _timeEventData (NULL) | |
| 127 | ✗ | , _currTimeEvents (NULL) | |
| 128 | ✗ | , _clockInterval (NULL) | |
| 129 | ✗ | , _clockShift (NULL) | |
| 130 | ✗ | , _clockTime (NULL) | |
| 131 | ✗ | , _clockEventBased(NULL) | |
| 132 | ✗ | , _clockCondition (NULL) | |
| 133 | ✗ | , _clockStart (NULL) | |
| 134 | ✗ | , _clockSubactive (NULL) | |
| 135 | ✗ | , _outputStream (NULL) | |
| 136 | ✗ | , _callType (IContinuous::UNDEF_UPDATE) | |
| 137 | ✗ | , _initial (false) | |
| 138 | ✗ | , _delay_max (0.0) | |
| 139 | ✗ | , _start_time (0.0) | |
| 140 | ✗ | , _terminal (false) | |
| 141 | ✗ | , _terminate (false) | |
| 142 | ✗ | , _global_settings(instance.getGlobalSettings()) | |
| 143 | ✗ | , _conditions0 (NULL) | |
| 144 | ✗ | , _event_system (NULL) | |
| 145 | ✗ | , _modelName (instance.getModelName()) | |
| 146 | ✗ | , _freeVariablesLock(false) | |
| 147 | { | ||
| 148 | ✗ | } | |
| 149 | |||
| 150 | /* | ||
| 151 | template<class T> | ||
| 152 | T SystemDefaultImplementation::getStartValue(T variable,string key) | ||
| 153 | { | ||
| 154 | try | ||
| 155 | { | ||
| 156 | return boost::any_cast<T>(_start_values[key]); | ||
| 157 | } | ||
| 158 | catch(const boost::bad_any_cast & ex) | ||
| 159 | { | ||
| 160 | std::runtime_error("No such start value"); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | */ | ||
| 164 | 43 | SystemDefaultImplementation::~SystemDefaultImplementation() | |
| 165 | { | ||
| 166 | /* | ||
| 167 | changed: is handled in SimVars class | ||
| 168 | if(__z) delete [] __z; | ||
| 169 | if(__zDot) delete [] __zDot; | ||
| 170 | */ | ||
| 171 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(_conditions) delete [] _conditions ; |
| 172 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 29 times.
|
43 | if(_time_conditions) delete [] _time_conditions ; |
| 173 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | if(_timeEventData) delete [] _timeEventData; |
| 174 |
1/2✓ Branch 0 taken 43 times.
✗ Branch 1 not taken.
|
43 | if(_currTimeEvents) delete [] _currTimeEvents; |
| 175 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(_conditions0) delete [] _conditions0; |
| 176 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockInterval) delete [] _clockInterval; |
| 177 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockShift) delete [] _clockShift; |
| 178 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockTime) delete [] _clockTime; |
| 179 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockEventBased) delete [] _clockEventBased; |
| 180 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockCondition) delete [] _clockCondition; |
| 181 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockStart) delete [] _clockStart; |
| 182 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if(_clockSubactive) delete [] _clockSubactive; |
| 183 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 25 times.
|
43 | if(__daeResidual) delete [] __daeResidual; |
| 184 | 43 | } | |
| 185 | |||
| 186 | ✗ | void SystemDefaultImplementation::Assert(bool cond,const string& msg) | |
| 187 | { | ||
| 188 | ✗ | if(!cond) | |
| 189 | ✗ | throw ModelicaSimulationError(MODEL_EQ_SYSTEM,msg); | |
| 190 | ✗ | } | |
| 191 | |||
| 192 | ✗ | void SystemDefaultImplementation::Terminate(string msg) | |
| 193 | { | ||
| 194 | ✗ | cerr << "Model terminate() at " << _simTime << std::endl; | |
| 195 | cerr << "Message: " << msg << std::endl; | ||
| 196 | ✗ | _terminate = true; | |
| 197 | ✗ | } | |
| 198 | |||
| 199 | ✗ | int SystemDefaultImplementation::getDimBoolean() const | |
| 200 | { | ||
| 201 | ✗ | return _dimBoolean; | |
| 202 | } | ||
| 203 | |||
| 204 | 40 | int SystemDefaultImplementation::getDimContinuousStates() const | |
| 205 | { | ||
| 206 | 40 | return _dimContinuousStates; | |
| 207 | } | ||
| 208 | |||
| 209 | 40 | int SystemDefaultImplementation::getDimAE() const | |
| 210 | { | ||
| 211 | 40 | return _dimAE; | |
| 212 | } | ||
| 213 | |||
| 214 | ✗ | int SystemDefaultImplementation::getDimInteger() const | |
| 215 | { | ||
| 216 | ✗ | return _dimInteger; | |
| 217 | } | ||
| 218 | |||
| 219 | ✗ | int SystemDefaultImplementation::getDimReal() const | |
| 220 | { | ||
| 221 | ✗ | return _dimReal; | |
| 222 | } | ||
| 223 | |||
| 224 | 2 | int SystemDefaultImplementation::getDimString() const | |
| 225 | { | ||
| 226 | 2 | return _dimString; | |
| 227 | } | ||
| 228 | |||
| 229 | ✗ | int SystemDefaultImplementation::getDimClock() const | |
| 230 | { | ||
| 231 | ✗ | return _dimClock; | |
| 232 | } | ||
| 233 | |||
| 234 | ✗ | void SystemDefaultImplementation::setIntervalInTimEventData(int clockIdx, double interval) | |
| 235 | { | ||
| 236 | ✗ | _timeEventData[_dimTimeEvent-_dimClock+clockIdx].second = interval; | |
| 237 | ✗ | } | |
| 238 | |||
| 239 | /// Provide number (dimension) of right hand sides (equations and/or residuals) according to the index | ||
| 240 | 11734 | int SystemDefaultImplementation::getDimRHS() const | |
| 241 | { | ||
| 242 | 11734 | return _dimRHS; | |
| 243 | }; | ||
| 244 | |||
| 245 | |||
| 246 | /// (Re-) initialize the system of equations | ||
| 247 | 43 | void SystemDefaultImplementation::initialize() | |
| 248 | { | ||
| 249 | 43 | _callType = IContinuous::CONTINUOUS; | |
| 250 | |||
| 251 | /* | ||
| 252 | changed: is handled in SimVars class | ||
| 253 | if((_dimContinuousStates) > 0) | ||
| 254 | { | ||
| 255 | // Initialize "extended state vector" | ||
| 256 | if(__z) delete [] __z ; | ||
| 257 | if(__zDot) delete [] __zDot; | ||
| 258 | |||
| 259 | __z = new double[_dimContinuousStates]; | ||
| 260 | __zDot = new double[_dimContinuousStates]; | ||
| 261 | |||
| 262 | memset(__z,0,(_dimContinuousStates)*sizeof(double)); | ||
| 263 | memset(__zDot,0,(_dimContinuousStates)*sizeof(double)); | ||
| 264 | } | ||
| 265 | */ | ||
| 266 | |||
| 267 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 24 times.
|
43 | if(_dimZeroFunc > 0) |
| 268 | { | ||
| 269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if(_conditions) delete [] _conditions ; |
| 270 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if(_conditions0) delete [] _conditions0 ; |
| 271 | 19 | _conditions = new bool[_dimZeroFunc]; | |
| 272 | 19 | _conditions0= new bool[_dimZeroFunc]; | |
| 273 | |||
| 274 | 19 | memset(_conditions,false,(_dimZeroFunc)*sizeof(bool)); | |
| 275 | 19 | _event_system = dynamic_cast<IEvent*>(this); | |
| 276 | } | ||
| 277 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 29 times.
|
43 | if(_dimTimeEvent > 0) |
| 278 | { | ||
| 279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if(_time_conditions) delete [] _time_conditions ; |
| 280 | 14 | _time_conditions = new bool[_dimTimeEvent]; | |
| 281 | 14 | memset(_time_conditions, 0, _dimTimeEvent * sizeof(bool)); | |
| 282 | } | ||
| 283 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 36 times.
|
43 | if (_dimClock > 0) |
| 284 | { | ||
| 285 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockInterval) delete [] _clockInterval; |
| 286 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | _clockInterval = new double [_dimClock]; |
| 287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockShift) delete [] _clockShift; |
| 288 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | _clockShift = new double [_dimClock]; |
| 289 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockTime) delete [] _clockTime; |
| 290 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | _clockTime = new double [_dimClock]; |
| 291 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockEventBased) delete [] _clockEventBased; |
| 292 | 7 | _clockEventBased = new bool [_dimClock]; | |
| 293 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | memset(_clockEventBased, 0, _dimClock * sizeof(bool)); |
| 294 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockCondition) delete [] _clockCondition; |
| 295 | 7 | _clockCondition = new bool [_dimClock]; | |
| 296 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | memset(_clockCondition, 0, _dimClock * sizeof(bool)); |
| 297 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockStart) delete [] _clockStart; |
| 298 | 7 | _clockStart = new bool [_dimClock]; | |
| 299 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (_clockSubactive) delete [] _clockSubactive; |
| 300 | 7 | _clockSubactive = new bool [_dimClock]; | |
| 301 | } | ||
| 302 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 25 times.
|
43 | if(_dimRHS>0) |
| 303 | { | ||
| 304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (__daeResidual) delete [] __daeResidual; |
| 305 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | __daeResidual = new double [_dimRHS]; |
| 306 | } | ||
| 307 | 43 | _start_time = 0.0; | |
| 308 | 43 | _terminal = false; | |
| 309 | 43 | _terminate = false; | |
| 310 | 43 | }; | |
| 311 | |||
| 312 | /// Set current integration time | ||
| 313 | 2289005 | void SystemDefaultImplementation::setTime(double t) | |
| 314 | { | ||
| 315 | 2289005 | _simTime = t; | |
| 316 | 2289005 | } | |
| 317 | |||
| 318 | // Get current integration time | ||
| 319 | 2206 | double SystemDefaultImplementation::getTime() | |
| 320 | { | ||
| 321 | 2206 | return _simTime; | |
| 322 | } | ||
| 323 | |||
| 324 | /// Set tolerance for zero crossings | ||
| 325 | 39 | void SystemDefaultImplementation::setZeroTol(double dt) | |
| 326 | { | ||
| 327 | 39 | _zeroTol = dt; | |
| 328 | 39 | } | |
| 329 | |||
| 330 | // Get tolerance for zero crossings | ||
| 331 | ✗ | double SystemDefaultImplementation::getZeroTol() | |
| 332 | { | ||
| 333 | ✗ | return _zeroTol; | |
| 334 | } | ||
| 335 | |||
| 336 | /// Set status of independent variables | ||
| 337 | 43791844 | void SystemDefaultImplementation::setFreeVariablesLock(bool freeVariablesLock) | |
| 338 | { | ||
| 339 | 43791844 | _freeVariablesLock = freeVariablesLock; | |
| 340 | 43791844 | } | |
| 341 | |||
| 342 | // Get status of independent variables | ||
| 343 | 24015868 | bool SystemDefaultImplementation::getFreeVariablesLock() | |
| 344 | { | ||
| 345 | 24015868 | return _freeVariablesLock; | |
| 346 | } | ||
| 347 | |||
| 348 | /// getter for variables of different types | ||
| 349 | ✗ | void SystemDefaultImplementation::getBoolean(bool* z) | |
| 350 | { | ||
| 351 | for(int i=0; i< _dimBoolean; ++i) | ||
| 352 | { | ||
| 353 | //z[i] = __z[i]; | ||
| 354 | // TODO: insert Code here | ||
| 355 | } | ||
| 356 | ✗ | }; | |
| 357 | |||
| 358 | ✗ | void SystemDefaultImplementation::getReal(double* z) | |
| 359 | { | ||
| 360 | for(int i=0; i< _dimReal; ++i) | ||
| 361 | { | ||
| 362 | //z[i] = __z[i]; | ||
| 363 | // TODO: insert Code here | ||
| 364 | } | ||
| 365 | ✗ | }; | |
| 366 | |||
| 367 | ✗ | void SystemDefaultImplementation::getInteger(int* z) | |
| 368 | { | ||
| 369 | for(int i=0; i< _dimInteger; ++i) | ||
| 370 | { | ||
| 371 | //z[i] = __z[i]; | ||
| 372 | // TODO: insert Code here | ||
| 373 | } | ||
| 374 | |||
| 375 | ✗ | }; | |
| 376 | |||
| 377 | ✗ | void SystemDefaultImplementation::getString(string* z) | |
| 378 | { | ||
| 379 | for(int i=0; i< _dimString; ++i) | ||
| 380 | { | ||
| 381 | //z[i] = __z[i]; | ||
| 382 | // TODO: insert Code here | ||
| 383 | } | ||
| 384 | |||
| 385 | ✗ | }; | |
| 386 | |||
| 387 | ✗ | void SystemDefaultImplementation::getClock(bool* z) | |
| 388 | { | ||
| 389 | ✗ | for(int i = _dimTimeEvent - _dimClock; i < _dimTimeEvent; i++) { | |
| 390 | ✗ | z[i] = _time_conditions[i]; | |
| 391 | } | ||
| 392 | ✗ | } | |
| 393 | |||
| 394 | ✗ | double *SystemDefaultImplementation::clockInterval() | |
| 395 | { | ||
| 396 | ✗ | return _clockInterval; | |
| 397 | } | ||
| 398 | |||
| 399 | ✗ | double *SystemDefaultImplementation::clockShift() | |
| 400 | { | ||
| 401 | ✗ | return _clockShift; | |
| 402 | } | ||
| 403 | |||
| 404 | 1867 | void SystemDefaultImplementation::getContinuousStates(double* z) | |
| 405 | { | ||
| 406 |
2/2✓ Branch 0 taken 1239 times.
✓ Branch 1 taken 628 times.
|
1867 | std::copy(__z ,__z + _dimContinuousStates, z); |
| 407 | 1867 | } | |
| 408 | |||
| 409 | 40 | IGlobalSettings* SystemDefaultImplementation::getGlobalSettings() | |
| 410 | { | ||
| 411 | 40 | return _global_settings; | |
| 412 | } | ||
| 413 | |||
| 414 | 40 | shared_ptr<ISimObjects> SystemDefaultImplementation::getSimObjects() const | |
| 415 | { | ||
| 416 | 40 | return _simObjects; | |
| 417 | } | ||
| 418 | |||
| 419 | ✗ | string SystemDefaultImplementation::getModelName() const | |
| 420 | { | ||
| 421 | ✗ | return _modelName; | |
| 422 | } | ||
| 423 | |||
| 424 | ✗ | shared_ptr<ISimData> SystemDefaultImplementation::getSimData() | |
| 425 | { | ||
| 426 | ✗ | return _simObjects->getSimData(_modelName); | |
| 427 | } | ||
| 428 | |||
| 429 | 338645 | shared_ptr<ISimVars> SystemDefaultImplementation::getSimVars() | |
| 430 | { | ||
| 431 |
1/1✓ Branch 2 taken 338645 times.
|
677290 | return _simObjects->getSimVars(_modelName); |
| 432 | } | ||
| 433 | |||
| 434 | ✗ | bool SystemDefaultImplementation::isConsistent() | |
| 435 | { | ||
| 436 | ✗ | if(_dimZeroFunc > 0) | |
| 437 | { | ||
| 438 | ✗ | getConditions(_conditions0); | |
| 439 | ✗ | IContinuous::UPDATETYPE pre_call_type=_callType; | |
| 440 | ✗ | _callType = IContinuous::DISCRETE; | |
| 441 | ✗ | for(int i=0;i<_dimZeroFunc;i++) | |
| 442 | { | ||
| 443 | ✗ | _event_system->getCondition(i); | |
| 444 | } | ||
| 445 | ✗ | bool isConsistent = std::equal (_conditions, _conditions+_dimZeroFunc,_conditions0); | |
| 446 | ✗ | _callType = pre_call_type; | |
| 447 | ✗ | setConditions(_conditions0); | |
| 448 | ✗ | return isConsistent; | |
| 449 | } | ||
| 450 | else | ||
| 451 | return true; | ||
| 452 | } | ||
| 453 | |||
| 454 | ✗ | void SystemDefaultImplementation::setConditions(bool* c) | |
| 455 | { | ||
| 456 | ✗ | memcpy(_conditions,c,_dimZeroFunc*sizeof(bool)); | |
| 457 | ✗ | } | |
| 458 | |||
| 459 | 136214 | void SystemDefaultImplementation::getConditions(bool* c) | |
| 460 | { | ||
| 461 | 136214 | memcpy(c,_conditions,_dimZeroFunc*sizeof(bool)); | |
| 462 | 136214 | } | |
| 463 | ✗ | void SystemDefaultImplementation::getClockConditions(bool* c) | |
| 464 | { | ||
| 465 | ✗ | memcpy(c,_clockCondition,_dimClock*sizeof(bool)); | |
| 466 | ✗ | } | |
| 467 | /// setter for variables of different types | ||
| 468 | |||
| 469 | ✗ | void SystemDefaultImplementation::setBoolean(const bool* z) | |
| 470 | { | ||
| 471 | for(int i=0; i< _dimBoolean; ++i) | ||
| 472 | { | ||
| 473 | //z[i] = __z[i]; | ||
| 474 | // TODO: insert Code here | ||
| 475 | } | ||
| 476 | ✗ | }; | |
| 477 | |||
| 478 | ✗ | void SystemDefaultImplementation::setInteger(const int* z) | |
| 479 | { | ||
| 480 | for(int i=0; i< _dimInteger; ++i) | ||
| 481 | { | ||
| 482 | //z[i] = __z[i]; | ||
| 483 | // TODO: insert Code here | ||
| 484 | } | ||
| 485 | ✗ | }; | |
| 486 | |||
| 487 | ✗ | void SystemDefaultImplementation::setString(const string* z) | |
| 488 | { | ||
| 489 | for(int i=0; i< _dimString; ++i) | ||
| 490 | { | ||
| 491 | //z[i] = __z[i]; | ||
| 492 | // TODO: insert Code here | ||
| 493 | } | ||
| 494 | ✗ | }; | |
| 495 | |||
| 496 | ✗ | void SystemDefaultImplementation::setReal(const double* z) | |
| 497 | { | ||
| 498 | for(int i=0; i< _dimReal; ++i) | ||
| 499 | { | ||
| 500 | //z[i] = __z[i]; | ||
| 501 | // TODO: insert Code here | ||
| 502 | } | ||
| 503 | ✗ | }; | |
| 504 | |||
| 505 | ✗ | void SystemDefaultImplementation::setClock(const bool* tick, const bool* subactive) | |
| 506 | { | ||
| 507 | ✗ | for (int i = 0; i < _dimClock; i++) { | |
| 508 | ✗ | _time_conditions[_dimTimeEvent - _dimClock + i] = tick[i]; | |
| 509 | ✗ | _clockSubactive[i] = subactive[i]; | |
| 510 | } | ||
| 511 | ✗ | } | |
| 512 | |||
| 513 | 2595860 | void SystemDefaultImplementation::setContinuousStates(const double* z) | |
| 514 | { | ||
| 515 |
2/2✓ Branch 0 taken 2571406 times.
✓ Branch 1 taken 24454 times.
|
2595860 | std::copy(z ,z + _dimContinuousStates,__z); |
| 516 | /*for(int i=0; i<_dimContinuousStates; ++i) | ||
| 517 | { | ||
| 518 | __z[i] = z[i]; | ||
| 519 | }*/ | ||
| 520 | |||
| 521 | 2595860 | }; | |
| 522 | |||
| 523 | 219006 | void SystemDefaultImplementation::setStateDerivatives(const double* f) | |
| 524 | { | ||
| 525 |
1/2✓ Branch 0 taken 219006 times.
✗ Branch 1 not taken.
|
219006 | std::copy(f ,f + _dimContinuousStates, __zDot); |
| 526 | /*for(int i=0; i<_dimRHS; ++i) | ||
| 527 | { | ||
| 528 | __zDot[i] = f[i]; | ||
| 529 | }*/ | ||
| 530 | 219006 | }; | |
| 531 | |||
| 532 | |||
| 533 | /// Provide the right hand side (according to the index) | ||
| 534 | 1776595 | void SystemDefaultImplementation::getRHS(double* f) | |
| 535 | { | ||
| 536 |
2/2✓ Branch 0 taken 1766178 times.
✓ Branch 1 taken 10417 times.
|
1776595 | std::copy(__zDot, __zDot+_dimContinuousStates, f); |
| 537 | // for(int i=0; i<_dimRHS; ++i) | ||
| 538 | // f[i] = __zDot[i]; | ||
| 539 | 1776595 | }; | |
| 540 | |||
| 541 | 168349 | void SystemDefaultImplementation::getResidual(double* f) | |
| 542 | { | ||
| 543 |
1/2✓ Branch 0 taken 168349 times.
✗ Branch 1 not taken.
|
168349 | std::copy(__daeResidual, __daeResidual+_dimRHS, f); |
| 544 | 168349 | } | |
| 545 | |||
| 546 | 1 | void SystemDefaultImplementation::intDelay(vector<unsigned int> expr, vector<double> delay_max) | |
| 547 | { | ||
| 548 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 2 taken 1 time.
|
9 | FOREACH(unsigned int expr_id, expr) |
| 549 | { | ||
| 550 | buffer_type delay_buffer; | ||
| 551 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 | _delay_buffer[expr_id]=delay_buffer; |
| 552 | } | ||
| 553 | vector<double>::iterator iter = std::max_element(delay_max.begin(),delay_max.end()); | ||
| 554 | 1 | _delay_max = *iter; | |
| 555 | 1 | } | |
| 556 | |||
| 557 | 6216 | void SystemDefaultImplementation::storeDelay(unsigned int expr_id, double expr_value, double time) | |
| 558 | { | ||
| 559 | map<unsigned int,buffer_type>::iterator iter; | ||
| 560 |
1/2✓ Branch 0 taken 6216 times.
✗ Branch 1 not taken.
|
6216 | if ((iter = _delay_buffer.find(expr_id)) != _delay_buffer.end()) { |
| 561 |
2/2✓ Branch 0 taken 6120 times.
✓ Branch 1 taken 96 times.
|
6216 | iter->second.push_back(expr_value); |
| 562 | } | ||
| 563 | else | ||
| 564 | ✗ | throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"invalid delay expression id"); | |
| 565 | 6216 | } | |
| 566 | |||
| 567 | 324992 | void SystemDefaultImplementation::storeTime(double time) | |
| 568 | { | ||
| 569 | // delete up to last value < time - _delay_max | ||
| 570 | buffer_type::iterator first = _time_buffer.begin(); | ||
| 571 | 324992 | buffer_type::iterator pos = find_if(first, _time_buffer.end(), | |
| 572 |
10/10✓ Branch 0 taken 65 times.
✓ Branch 1 taken 19 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1482 times.
✓ Branch 4 taken 1 time.
✓ Branch 5 taken 324859 times.
✓ Branch 6 taken 1485 times.
✓ Branch 7 taken 323406 times.
✓ Branch 9 taken 324892 times.
✓ Branch 10 taken 100 times.
|
976310 | [=](double t) { return t >= time - _delay_max; }); |
| 573 |
4/4✓ Branch 0 taken 324892 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 323376 times.
✓ Branch 3 taken 1516 times.
|
649884 | if (pos != first && --pos != first) { |
| 574 | difference_type n = std::distance(first, pos); | ||
| 575 | 323376 | _time_buffer.erase(first, first + n); | |
| 576 | map<unsigned int, buffer_type>::iterator iter; | ||
| 577 |
2/2✓ Branch 0 taken 4856 times.
✓ Branch 1 taken 323376 times.
|
328232 | for (iter = _delay_buffer.begin(); iter != _delay_buffer.end(); iter++) { |
| 578 | first = iter->second.begin(); | ||
| 579 | 4856 | iter->second.erase(first, first + n); | |
| 580 | } | ||
| 581 | } | ||
| 582 | // store new value | ||
| 583 |
2/2✓ Branch 0 taken 319931 times.
✓ Branch 1 taken 5061 times.
|
324992 | _time_buffer.push_back(time); |
| 584 | 324992 | } | |
| 585 | |||
| 586 | 19232 | double SystemDefaultImplementation::delay(unsigned int expr_id,double expr_value,double delayTime, double delayMax) | |
| 587 | { | ||
| 588 | map<unsigned int,buffer_type>::iterator iter; | ||
| 589 | //find buffer for delay expression | ||
| 590 |
1/2✓ Branch 0 taken 19232 times.
✗ Branch 1 not taken.
|
19232 | if((iter = _delay_buffer.find(expr_id))!=_delay_buffer.end()) |
| 591 | { | ||
| 592 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19232 times.
|
19232 | if(delayTime < 0.0) |
| 593 | { | ||
| 594 | ✗ | throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"Negative delay requested"); | |
| 595 | } | ||
| 596 |
2/2✓ Branch 0 taken 19160 times.
✓ Branch 1 taken 72 times.
|
19232 | if(_time_buffer.size()==0) //occurs in the initialization phase |
| 597 | { | ||
| 598 | |||
| 599 | return expr_value; | ||
| 600 | } | ||
| 601 |
1/2✓ Branch 0 taken 19160 times.
✗ Branch 1 not taken.
|
19160 | if(_simTime<=_start_time) |
| 602 | return expr_value; | ||
| 603 | |||
| 604 | double ts; //difference of current time and delay time | ||
| 605 | double tl; //last buffer entry | ||
| 606 | double res0, res1, t0, t1; | ||
| 607 | |||
| 608 |
2/2✓ Branch 0 taken 552 times.
✓ Branch 1 taken 18608 times.
|
19160 | if(_simTime <= delayTime) |
| 609 | { | ||
| 610 | 552 | res0 = iter->second[0]; | |
| 611 | 552 | return res0; | |
| 612 | } | ||
| 613 | else //time > delay time | ||
| 614 | { | ||
| 615 |
2/2✓ Branch 0 taken 360 times.
✓ Branch 1 taken 18248 times.
|
18608 | ts = _simTime -delayTime; |
| 616 | |||
| 617 | 18608 | tl = _time_buffer.back(); | |
| 618 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18608 times.
|
18608 | if(ts > tl) |
| 619 | { | ||
| 620 | t0 = tl; | ||
| 621 | ✗ | res0=iter->second.back(); | |
| 622 | t1=_simTime; | ||
| 623 | res1=expr_value; | ||
| 624 | } | ||
| 625 | else | ||
| 626 | { | ||
| 627 | //find posion in value buffer for queried time | ||
| 628 |
1/2✓ Branch 1 taken 18608 times.
✗ Branch 2 not taken.
|
18608 | buffer_type::iterator pos = find_if(_time_buffer.begin(),_time_buffer.end(), [=](double t) { return t >= ts; }); |
| 629 | |||
| 630 |
1/2✓ Branch 0 taken 18608 times.
✗ Branch 1 not taken.
|
18608 | if(pos!=_time_buffer.end()) |
| 631 | { | ||
| 632 | buffer_type::iterator first = _time_buffer.begin(); // first time entry | ||
| 633 | difference_type index = std::distance(first, pos); //index of found time | ||
| 634 | 18608 | t1 = *pos; | |
| 635 | 18608 | res1 = iter->second[index]; | |
| 636 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18608 times.
|
18608 | if(index == 0) |
| 637 | return res1; | ||
| 638 | 18608 | t0 = _time_buffer[index-1]; | |
| 639 | 18608 | res0 = iter->second[index-1]; | |
| 640 | } | ||
| 641 | else | ||
| 642 | { | ||
| 643 | ✗ | throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"time not found in delay buffer"); | |
| 644 | } | ||
| 645 | } | ||
| 646 |
1/2✓ Branch 0 taken 18608 times.
✗ Branch 1 not taken.
|
18608 | if(t0==ts)//found exact time |
| 647 | return res0; | ||
| 648 |
1/2✓ Branch 0 taken 18608 times.
✗ Branch 1 not taken.
|
18608 | else if(t1==ts) |
| 649 | return res1; | ||
| 650 | else //linear interpolation | ||
| 651 | { | ||
| 652 | 18608 | double timedif = t1 - t0; | |
| 653 | 18608 | double dt0 = t1 - ts; | |
| 654 | 18608 | double dt1 = ts - t0; | |
| 655 | 18608 | double res2 = (res0 * dt0 + res1 * dt1) / timedif; | |
| 656 | 18608 | return res2; | |
| 657 | } | ||
| 658 | } | ||
| 659 | } | ||
| 660 | else | ||
| 661 | ✗ | throw ModelicaSimulationError(MODEL_EQ_SYSTEM,"invalid delay expression id"); | |
| 662 | } | ||
| 663 | |||
| 664 | 837 | double& SystemDefaultImplementation::getRealStartValue(double& key) | |
| 665 | { | ||
| 666 | 837 | return _real_start_values.getGetStartValue(key); | |
| 667 | } | ||
| 668 | |||
| 669 | 134 | bool& SystemDefaultImplementation::getBoolStartValue(bool& var) | |
| 670 | { | ||
| 671 | 134 | return _bool_start_values.getGetStartValue(var); | |
| 672 | } | ||
| 673 | |||
| 674 | 73 | int& SystemDefaultImplementation::getIntStartValue(int& var) | |
| 675 | { | ||
| 676 | 73 | return _int_start_values.getGetStartValue(var); | |
| 677 | } | ||
| 678 | ✗ | string& SystemDefaultImplementation::getStringStartValue(string& var) | |
| 679 | { | ||
| 680 | ✗ | return _string_start_values.getGetStartValue(var); | |
| 681 | } | ||
| 682 | |||
| 683 | 8355 | void SystemDefaultImplementation::setRealStartValue(double& var, double val, bool overwriteOldValue) | |
| 684 | { | ||
| 685 | 8355 | var = val; | |
| 686 | 8355 | _real_start_values.setStartValue(var, val, overwriteOldValue); | |
| 687 | 8355 | } | |
| 688 | |||
| 689 | ✗ | void SystemDefaultImplementation::setRealStartValue(BaseArray<double>& avar, double val, bool overwriteOldValue) | |
| 690 | { | ||
| 691 | ✗ | double *varp = avar.getData(); | |
| 692 | ✗ | size_t nel = avar.getNumElems(); | |
| 693 | ✗ | for (size_t i = 0; i < nel; varp++, i++) { | |
| 694 | ✗ | *varp = val; | |
| 695 | ✗ | _real_start_values.setStartValue(*varp, val, overwriteOldValue); | |
| 696 | } | ||
| 697 | ✗ | } | |
| 698 | |||
| 699 | 6 | void SystemDefaultImplementation::setRealStartValue(BaseArray<double>& avar, const BaseArray<double>& aval, bool overwriteOldValue) | |
| 700 | { | ||
| 701 | 6 | double *varp = avar.getData(); | |
| 702 | 6 | const double *valp = aval.getData(); | |
| 703 | 6 | size_t nel = avar.getNumElems(); | |
| 704 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 6 times.
|
20 | for (size_t i = 0; i < nel; varp++, valp++, i++) { |
| 705 | 14 | *varp = *valp; | |
| 706 | 14 | _real_start_values.setStartValue(*varp, *valp, overwriteOldValue); | |
| 707 | } | ||
| 708 | 6 | } | |
| 709 | |||
| 710 | 1082 | void SystemDefaultImplementation::setBoolStartValue(bool& var, bool val, bool overwriteOldValue) | |
| 711 | { | ||
| 712 | 1082 | var = val; | |
| 713 | 1082 | _bool_start_values.setStartValue(var, val, overwriteOldValue); | |
| 714 | 1082 | } | |
| 715 | |||
| 716 | ✗ | void SystemDefaultImplementation::setBoolStartValue(BaseArray<bool>& avar, bool val, bool overwriteOldValue) | |
| 717 | { | ||
| 718 | ✗ | bool *varp = avar.getData(); | |
| 719 | ✗ | size_t nel = avar.getNumElems(); | |
| 720 | ✗ | for (size_t i = 0; i < nel; varp++, i++) { | |
| 721 | ✗ | *varp = val; | |
| 722 | ✗ | _bool_start_values.setStartValue(*varp, val, overwriteOldValue); | |
| 723 | } | ||
| 724 | ✗ | } | |
| 725 | |||
| 726 | ✗ | void SystemDefaultImplementation::setBoolStartValue(BaseArray<bool>& avar, const BaseArray<bool>& aval, bool overwriteOldValue) | |
| 727 | { | ||
| 728 | ✗ | bool *varp = avar.getData(); | |
| 729 | ✗ | const bool *valp = aval.getData(); | |
| 730 | ✗ | size_t nel = avar.getNumElems(); | |
| 731 | ✗ | for (size_t i = 0; i < nel; varp++, valp++, i++) { | |
| 732 | ✗ | *varp = *valp; | |
| 733 | ✗ | _bool_start_values.setStartValue(*varp, *valp, overwriteOldValue); | |
| 734 | } | ||
| 735 | ✗ | } | |
| 736 | |||
| 737 | 1078 | void SystemDefaultImplementation::setIntStartValue(int& var, int val, bool overwriteOldValue) | |
| 738 | { | ||
| 739 | 1078 | var = val; | |
| 740 | 1078 | _int_start_values.setStartValue(var, val, overwriteOldValue); | |
| 741 | 1078 | } | |
| 742 | |||
| 743 | ✗ | void SystemDefaultImplementation::setIntStartValue(BaseArray<int>& avar, int val, bool overwriteOldValue) | |
| 744 | { | ||
| 745 | ✗ | int *varp = avar.getData(); | |
| 746 | ✗ | size_t nel = avar.getNumElems(); | |
| 747 | ✗ | for (size_t i = 0; i < nel; varp++, i++) { | |
| 748 | ✗ | *varp = val; | |
| 749 | ✗ | _int_start_values.setStartValue(*varp, val, overwriteOldValue); | |
| 750 | } | ||
| 751 | ✗ | } | |
| 752 | |||
| 753 | ✗ | void SystemDefaultImplementation::setIntStartValue(BaseArray<int>& avar, const BaseArray<int>& aval, bool overwriteOldValue) | |
| 754 | { | ||
| 755 | ✗ | int *varp = avar.getData(); | |
| 756 | ✗ | const int *valp = aval.getData(); | |
| 757 | ✗ | size_t nel = avar.getNumElems(); | |
| 758 | ✗ | for (size_t i = 0; i < nel; varp++, valp++, i++) { | |
| 759 | ✗ | *varp = *valp; | |
| 760 | ✗ | _int_start_values.setStartValue(*varp, *valp, overwriteOldValue); | |
| 761 | } | ||
| 762 | ✗ | } | |
| 763 | |||
| 764 | 93 | void SystemDefaultImplementation::setStringStartValue(string& var, string val, bool overwriteOldValue) | |
| 765 | { | ||
| 766 | var = val; | ||
| 767 |
1/2✓ Branch 2 taken 93 times.
✗ Branch 3 not taken.
|
93 | _string_start_values.setStartValue(var, val, overwriteOldValue); |
| 768 | 93 | } | |
| 769 | |||
| 770 | ✗ | void SystemDefaultImplementation::setStringStartValue(BaseArray<string>& avar, string val, bool overwriteOldValue) | |
| 771 | { | ||
| 772 | ✗ | string *varp = avar.getData(); | |
| 773 | ✗ | size_t nel = avar.getNumElems(); | |
| 774 | ✗ | for (size_t i = 0; i < nel; varp++, i++) { | |
| 775 | *varp = val; | ||
| 776 | ✗ | _string_start_values.setStartValue(*varp, val, overwriteOldValue); | |
| 777 | } | ||
| 778 | ✗ | } | |
| 779 | |||
| 780 | ✗ | void SystemDefaultImplementation::setStringStartValue(BaseArray<string>& avar, const BaseArray<string>& aval, bool overwriteOldValue) | |
| 781 | { | ||
| 782 | ✗ | string *varp = avar.getData(); | |
| 783 | ✗ | const string *valp = aval.getData(); | |
| 784 | ✗ | size_t nel = avar.getNumElems(); | |
| 785 | ✗ | for (size_t i = 0; i < nel; varp++, valp++, i++) { | |
| 786 | *varp = *valp; | ||
| 787 | ✗ | _string_start_values.setStartValue(*varp, *valp, overwriteOldValue); | |
| 788 | } | ||
| 789 | ✗ | } | |
| 790 | |||
| 791 | /** | ||
| 792 | Computes whether time event conditions are active at current time | ||
| 793 | @param The current time | ||
| 794 | */ | ||
| 795 | 4045 | void SystemDefaultImplementation::computeTimeEventConditions(double currTime) | |
| 796 | { | ||
| 797 | 4045 | int clockOffset = _dimTimeEvent - _dimClock; | |
| 798 | |||
| 799 |
2/2✓ Branch 0 taken 14659 times.
✓ Branch 1 taken 4045 times.
|
18704 | for (int i=0; i< _dimTimeEvent; i++) |
| 800 | { | ||
| 801 | // skip event clocks | ||
| 802 |
4/4✓ Branch 0 taken 484 times.
✓ Branch 1 taken 14175 times.
✓ Branch 2 taken 158 times.
✓ Branch 3 taken 326 times.
|
14659 | if (i >= clockOffset && _clockEventBased[i - clockOffset]) |
| 803 | 158 | continue; | |
| 804 | |||
| 805 |
2/2✓ Branch 0 taken 14029 times.
✓ Branch 1 taken 472 times.
|
14501 | if (std::abs(_currTimeEvents[i] - currTime) <= 1e4*UROUND) |
| 806 | { | ||
| 807 | 14029 | _time_conditions[i] = true; | |
| 808 | } | ||
| 809 | else | ||
| 810 | { | ||
| 811 | 472 | _time_conditions[i] = false; | |
| 812 | } | ||
| 813 | } | ||
| 814 | 4045 | } | |
| 815 | |||
| 816 | /** | ||
| 817 | Sets all time event conditions to false | ||
| 818 | */ | ||
| 819 | 1844 | void SystemDefaultImplementation::resetTimeConditions() | |
| 820 | { | ||
| 821 |
2/2✓ Branch 0 taken 14659 times.
✓ Branch 1 taken 1844 times.
|
16503 | for (int i=0; i< _dimTimeEvent; i++) |
| 822 | { | ||
| 823 | 14659 | _time_conditions[i] = false; | |
| 824 | } | ||
| 825 | 1844 | } | |
| 826 | |||
| 827 | /** | ||
| 828 | Computes the next time events for each time event sampler | ||
| 829 | @param The current Time | ||
| 830 | @param The definition of the time event samplers (starttime, intervall) | ||
| 831 | @param An array of the next time events for each sampler | ||
| 832 | @return the closest time event | ||
| 833 | */ | ||
| 834 | 1875 | double SystemDefaultImplementation::computeNextTimeEvents(double currTime, std::pair<double, double>* timeEventPairs) | |
| 835 | { | ||
| 836 | 1875 | double closestTimeEvent = std::numeric_limits<double>::max(); | |
| 837 | 1875 | double nextTimeEvent = 0; | |
| 838 | double pastIntervalls; | ||
| 839 | 1875 | int clockOffset = _dimTimeEvent - _dimClock; | |
| 840 | |||
| 841 |
2/2✓ Branch 0 taken 14659 times.
✓ Branch 1 taken 1875 times.
|
16534 | for (int timerIdx = 0; timerIdx < _dimTimeEvent; timerIdx++) |
| 842 | { | ||
| 843 | // skip event clocks | ||
| 844 |
4/4✓ Branch 0 taken 484 times.
✓ Branch 1 taken 14175 times.
✓ Branch 2 taken 158 times.
✓ Branch 3 taken 326 times.
|
14659 | if (timerIdx >= clockOffset && _clockEventBased[timerIdx - clockOffset]) |
| 845 | 158 | continue; | |
| 846 | |||
| 847 | // the time event samples started already | ||
| 848 |
2/2✓ Branch 0 taken 14462 times.
✓ Branch 1 taken 39 times.
|
14501 | if (timeEventPairs[timerIdx].first <= currTime) |
| 849 | { | ||
| 850 | 14462 | pastIntervalls = std::floor((currTime - timeEventPairs[timerIdx].first + 1e4*UROUND) / timeEventPairs[timerIdx].second); | |
| 851 | 14462 | _currTimeEvents[timerIdx] = timeEventPairs[timerIdx].first + (pastIntervalls) * timeEventPairs[timerIdx].second; | |
| 852 | 14462 | nextTimeEvent = _currTimeEvents[timerIdx] + timeEventPairs[timerIdx].second; | |
| 853 | } | ||
| 854 | else | ||
| 855 | { | ||
| 856 | 39 | nextTimeEvent = timeEventPairs[timerIdx].first; | |
| 857 | 39 | _currTimeEvents[timerIdx] = 1.0; | |
| 858 | } | ||
| 859 | 14501 | closestTimeEvent = std::min(closestTimeEvent, nextTimeEvent); | |
| 860 | } | ||
| 861 | 1875 | return closestTimeEvent; | |
| 862 | } | ||
| 863 | |||
| 864 | /** @} */ // end of coreSystem | ||
| 865 | |||
| 866 | /* | ||
| 867 | template int SystemDefaultImplementation::getStartValue(int variable,string key); | ||
| 868 | template double SystemDefaultImplementation::getStartValue(double variable,string key); | ||
| 869 | template bool SystemDefaultImplementation::getStartValue(bool variable,string key); | ||
| 870 | */ | ||
| 871 |