Skip to content

Commit

Permalink
Modified event iteration in cpp runtime. Using checkConditions instea…
Browse files Browse the repository at this point in the history
…d of setZeroState from solver

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11212 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
niklwors committed Feb 27, 2012
1 parent 4c24901 commit 0cbef56
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Compiler/susan_codegen/SimCode/CodegenCpp.tpl
Expand Up @@ -2089,7 +2089,7 @@ case SIMCODE(modelInfo = MODELINFO(__)) then
virtual void checkConditions(unsigned int, bool all);
virtual void saveConditions();
//Called to handle all events occured at same time
virtual void handleSystemEvents(const bool* events,update_events_type update_event);
virtual void handleSystemEvents(const bool* events);
//Called to handle an event
virtual void handleEvent(unsigned long index);
//Checks if a discrete variable has changed and triggers an event
Expand Down Expand Up @@ -5746,7 +5746,7 @@ template handleSystemEvents(list<ZeroCrossing> zeroCrossings,list<SimWhenClause>
match simCode
case SIMCODE(modelInfo = MODELINFO(__)) then
<<
void <%lastIdentOfPath(modelInfo.name)%>::handleSystemEvents(const bool* events,update_events_type update_event)
void <%lastIdentOfPath(modelInfo.name)%>::handleSystemEvents(const bool* events)
{
<%varDecls%>
bool restart=true;
Expand All @@ -5758,7 +5758,7 @@ template handleSystemEvents(list<ZeroCrossing> zeroCrossings,list<SimWhenClause>
<%helpvarvector(whenClauses,simCode)%>
_event_handling.setHelpVars(h);
//iterate and handle all events inside the eventqueue
restart=_event_handling.IterateEventQueue(events,update_event);
restart=_event_handling.IterateEventQueue(_conditions1);
saveAll();
}
saveConditions();
Expand Down
Expand Up @@ -339,8 +339,8 @@ void Cvode::doTimeEvents()
//Handle time event
event_system->handleEvent(iter->second);
//Handle all events that occured at this time
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);

//Check if old time events were overrned because step size is not adequate
if(distance(_time_events.begin(),iter)>0)
Expand Down Expand Up @@ -464,8 +464,8 @@ void Cvode::CVodeCore()
//event_system->giveZeroFunc(_zeroVal,dynamic_cast<ISolverSettings*>(_cvodesettings)->getZeroTol());

//Event Iteration starten
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);


// Zustand nach Eventbehandlung recorden
Expand Down
Expand Up @@ -331,8 +331,8 @@ void Euler::doEulerForward()
_h = dynamic_cast<ISolverSettings*>(_eulerSettings)->gethInit() * dynamic_cast<ISolverSettings*>(_eulerSettings)->getZeroRatio();

//handle all events that occured at this t
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);

_zeroStatus = EQUAL_ZERO;
memcpy(_zeroValLastSuccess,_zeroVal,_dimZeroFunc*sizeof(double));
Expand Down Expand Up @@ -564,8 +564,8 @@ void Euler::doEulerBackward()
_h = dynamic_cast<ISolverSettings*>(_eulerSettings)->gethInit() * dynamic_cast<ISolverSettings*>(_eulerSettings)->getZeroRatio();

//handle all events that occured at this t
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);
_zeroStatus = IDAESolver::EQUAL_ZERO;

}
Expand Down Expand Up @@ -754,8 +754,8 @@ void Euler::doMidpoint()
_hUpLim = dynamic_cast<ISolverSettings*>(_eulerSettings)->getUpperLimit();
_h = dynamic_cast<ISolverSettings*>(_eulerSettings)->gethInit()* dynamic_cast<ISolverSettings*>(_eulerSettings)->getZeroRatio();

update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);


}
Expand Down Expand Up @@ -805,8 +805,8 @@ void Euler::doTimeEvents()
//Handle time event
event_system->handleEvent(iter->second);
//Handle all events that occured at this time
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);

//Check if old time events were overrned because step size is not adequate
if(distance(_time_events.begin(),iter)>0)
Expand Down
Expand Up @@ -313,8 +313,8 @@ void Idas::callIDA()
event_system->giveZeroFunc(_zeroVal,dynamic_cast<ISolverSettings*>(_idasSettings)->getZeroTol());

//Event Iteration starten
update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events,boost::ref(update_event));
//update_events_type update_event = boost::bind(&SolverDefaultImplementation::updateEventState, this);
event_system->handleSystemEvents(_events/*,boost::ref(update_event)*/);
//EVENT Iteration beendet
}

Expand Down
Expand Up @@ -144,7 +144,7 @@ void EventHandling::removeEvent(long index)
/**
Handles all events occured a the same time. These are stored the eventqueue
*/
bool EventHandling::IterateEventQueue(const bool* events,update_events_type update_event)
bool EventHandling::IterateEventQueue(const bool* events)
{
IContinous* countinous_system = dynamic_cast<IContinous*>(_system);
IEvent* event_system= dynamic_cast<IEvent*>(_system);
Expand Down
Expand Up @@ -44,7 +44,7 @@ class BOOST_EXTENSION_EVENTHANDLING_DECL EventHandling
//removes an event from the eventqueue
void removeEvent(long index);
//Handles all events occured a the same time. Returns true if a second event iteration is needed
bool IterateEventQueue(const bool* events,update_events_type update_event);
bool IterateEventQueue(const bool* events);


void addTimeEvent(long index,double time);
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Source/System/Interfaces/IEvent.h
Expand Up @@ -16,7 +16,7 @@ Copyright (c) 2008, OSMC
*****************************************************************************/


typedef boost::function<void (void)> update_events_type;
//typedef boost::function<void (void)> update_events_type;
typedef std::map<double,unsigned long/*,std::less_equal<double>*/ > event_times_type;
class IEvent
{
Expand All @@ -36,7 +36,7 @@ class IEvent
//Saves all variables before an event is handled, is needed for the pre, edge and change operator
virtual void saveAll() = 0;
/// Called to handle all events occured at same time
virtual void handleSystemEvents(const bool* events,update_events_type update_event) = 0;
virtual void handleSystemEvents(const bool* events) = 0;
/// Called to handle an event
virtual void handleEvent(unsigned long index) = 0;
///Checks if a discrete variable has changed and triggered an event, returns true if a second event iteration is needed
Expand Down

0 comments on commit 0cbef56

Please sign in to comment.