Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
splitted EventHandling class in DiscreteEvents,ContinuousEvents and P…
…reVariables git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24127 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Showing
17 changed files
with
631 additions
and
505 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#include <Core/Modelica.h> | ||
#include "FactoryExport.h" | ||
#include <Core/System/IEvent.h> | ||
#include <Core/System/ContinuousEvents.h> | ||
#include <Core/Math/Functions.h> | ||
|
||
|
||
ContinuousEvents::ContinuousEvents() : _countinous_system(NULL), _mixed_system(NULL), _conditions0(NULL), _conditions1(NULL) | ||
{ | ||
} | ||
|
||
ContinuousEvents::~ContinuousEvents(void) | ||
{ | ||
|
||
if(_conditions0) | ||
delete[] _conditions0; | ||
if(_conditions1) | ||
delete[] _conditions1; | ||
} | ||
|
||
/** | ||
Inits the event variables | ||
*/ | ||
void ContinuousEvents::initialize(IEvent* system) | ||
{ | ||
// _dimH=dim; | ||
_event_system=system; | ||
_countinous_system = dynamic_cast<IContinuous*>(_event_system); | ||
_mixed_system= dynamic_cast<IMixedSystem*>(_event_system); | ||
|
||
|
||
if(_conditions0) | ||
delete[] _conditions0; | ||
if(_conditions1) | ||
delete[] _conditions1; | ||
|
||
_conditions0 = new bool[_event_system->getDimZeroFunc()]; | ||
_conditions1 = new bool[_event_system->getDimZeroFunc()]; | ||
} | ||
|
||
|
||
|
||
/** | ||
Handles all events occurred a the same time. | ||
*/ | ||
bool ContinuousEvents::startEventIteration(bool& state_vars_reinitialized) | ||
{ | ||
//save discrete variables | ||
//Deactivated: _event_system->saveDiscreteVars(); // store values of discrete vars vor next check | ||
|
||
unsigned int dim = _event_system->getDimZeroFunc(); | ||
|
||
_event_system->getConditions(_conditions0); | ||
//Handle all events | ||
|
||
state_vars_reinitialized = _countinous_system->evaluateConditions(); | ||
|
||
|
||
//check if discrete variables changed | ||
bool drestart= _event_system->checkForDiscreteEvents(); //discrete time conditions | ||
|
||
|
||
_event_system->getConditions(_conditions1); | ||
bool crestart = !std::equal (_conditions1, _conditions1+dim,_conditions0); | ||
|
||
return((drestart||crestart)); //returns true if new events occured | ||
} | ||
|
||
/* | ||
bool ContinuousEvents::checkConditions(const bool* events, bool all) | ||
{ | ||
IEvent* event_system= dynamic_cast<IEvent*>(_system); | ||
int dim = event_system->getDimZeroFunc(); | ||
bool* conditions0 = new bool[dim]; | ||
bool* conditions1 = new bool[dim]; | ||
event_system->getConditions(conditions0); | ||
for(int i=0;i<dim;i++) | ||
{ | ||
if(all||events[i]) | ||
getCondition(i); | ||
} | ||
event_system->getConditions(conditions1); | ||
return !std::equal (conditions1, conditions1+dim,conditions0); | ||
} | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
#include <Core/Modelica.h> | ||
#include "FactoryExport.h" | ||
#include <Core/System/PreVariables.h> | ||
#include <Core/System/DiscreteEvents.h> | ||
#include <Core/Math/Functions.h> | ||
|
||
|
||
DiscreteEvents::DiscreteEvents(PreVariables* preVars) | ||
: _preVars(preVars) | ||
{ | ||
} | ||
|
||
DiscreteEvents::~DiscreteEvents(void) | ||
{ | ||
|
||
|
||
} | ||
|
||
/** | ||
Inits the event variables | ||
*/ | ||
void DiscreteEvents::initialize() | ||
{ | ||
|
||
_preVars->initPreVariables(); | ||
_preVars->_pre_vars.resize((boost::extents[_preVars->_pre_real_vars_idx.size()+_preVars->_pre_int_vars_idx.size()+_preVars->_pre_bool_vars_idx.size()])); | ||
} | ||
|
||
/* | ||
void DiscreteEvents::savePreVars(double vars[], unsigned int n) | ||
{ | ||
_preVars->_pre_vars.assign(vars,vars+n); | ||
} | ||
*/ | ||
|
||
/** | ||
Saves a variable in _preVars->_pre_vars vector | ||
*/ | ||
|
||
void DiscreteEvents::save(double& var) | ||
{ | ||
unsigned int i = _preVars->_pre_real_vars_idx[&var]; | ||
_preVars->_pre_vars[i]=var; | ||
} | ||
|
||
/** | ||
Saves a variable in _preVars->_pre_vars vector | ||
*/ | ||
|
||
void DiscreteEvents::save(int& var) | ||
{ | ||
unsigned int i = _preVars->_pre_int_vars_idx[&var]; | ||
_preVars->_pre_vars[i]=var; | ||
} | ||
|
||
/** | ||
Saves a variable in _preVars->_pre_vars vector | ||
*/ | ||
|
||
void DiscreteEvents::save(bool& var) | ||
{ | ||
unsigned int i = _preVars->_pre_bool_vars_idx[&var]; | ||
_preVars->_pre_vars[i]=var; | ||
} | ||
|
||
/** | ||
Implementation of the Modelica pre operator | ||
*/ | ||
double DiscreteEvents::pre(double& var) | ||
{ | ||
unsigned int i = _preVars->_pre_real_vars_idx[&var]; | ||
return _preVars->_pre_vars[i]; | ||
|
||
} | ||
|
||
/** | ||
Implementation of the Modelica pre operator | ||
*/ | ||
double DiscreteEvents::pre(int& var) | ||
{ | ||
unsigned int i = _preVars->_pre_int_vars_idx[&var]; | ||
return _preVars->_pre_vars[i]; | ||
|
||
} | ||
|
||
/** | ||
Implementation of the Modelica pre operator | ||
*/ | ||
double DiscreteEvents::pre(bool& var) | ||
{ | ||
unsigned int i = _preVars->_pre_bool_vars_idx[&var]; | ||
return _preVars->_pre_vars[i]; | ||
|
||
} | ||
/** | ||
Implementation of the Modelica edge operator | ||
Returns true for a variable when it changes from false to true | ||
*/ | ||
bool DiscreteEvents::edge(double& var) | ||
{ | ||
return var && !pre(var); | ||
} | ||
|
||
/** | ||
Implementation of the Modelica edge operator | ||
Returns true for a variable when it changes from false to true | ||
*/ | ||
bool DiscreteEvents::edge(int& var) | ||
{ | ||
return var && !pre(var); | ||
} | ||
|
||
/** | ||
Implementation of the Modelica edge operator | ||
Returns true for a variable when it changes from false to true | ||
*/ | ||
bool DiscreteEvents::edge(bool& var) | ||
{ | ||
return var && !pre(var); | ||
} | ||
|
||
/** | ||
Implementation of the Modelica change operator | ||
Returns true for a variable when it change value | ||
*/ | ||
bool DiscreteEvents::change(double& var) | ||
{ | ||
return var != pre(var); | ||
} | ||
|
||
/** | ||
Implementation of the Modelica change operator | ||
Returns true for a variable when it change value | ||
*/ | ||
bool DiscreteEvents::change(int& var) | ||
{ | ||
return var != pre(var); | ||
} | ||
|
||
/** | ||
Implementation of the Modelica change operator | ||
Returns true for a variable when it change value | ||
*/ | ||
bool DiscreteEvents::change(bool& var) | ||
{ | ||
return var != pre(var); | ||
} | ||
|
||
|
||
bool DiscreteEvents::changeDiscreteVar(double& var) | ||
{ | ||
unsigned int i = _preVars->_pre_real_vars_idx[&var]; | ||
return var != _preVars->_pre_vars[i]; | ||
|
||
} | ||
bool DiscreteEvents::changeDiscreteVar(int& var) | ||
{ | ||
unsigned int i = _preVars->_pre_int_vars_idx[&var]; | ||
return var != _preVars->_pre_vars[i]; | ||
|
||
} | ||
|
||
bool DiscreteEvents::changeDiscreteVar(bool& var) | ||
{ | ||
unsigned int i = _preVars->_pre_bool_vars_idx[&var]; | ||
return var != _preVars->_pre_vars[i]; | ||
|
||
} | ||
|
||
|
||
|
Oops, something went wrong.