DPsim
Loading...
Searching...
No Matches
Event.cpp
Go to the documentation of this file.
1/* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2 * EONERC, RWTH Aachen University
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7 *********************************************************************************/
8
9#include <dpsim/Event.h>
10
11using namespace DPsim;
12using namespace CPS;
13
15
16void EventQueue::handleEvents(Real currentTime) {
17 Event::Ptr e;
18
19 while (!mEvents.empty()) {
20 e = mEvents.top();
21 // if current time larger or equal to event time, execute event
22 if (currentTime > e->mTime || (e->mTime - currentTime) < 100e-9) {
23 e->execute();
24 std::cout << std::scientific << currentTime << ": Handle event time"
25 << std::endl;
26 //std::cout << std::scientific << e->mTime << ": Original event time" << std::endl;
27 //std::cout << std::scientific << (e->mTime - currentTime)*1e9 << ": Difference to specified event time in ns" << std::endl;
28 mEvents.pop();
29 } else {
30 break;
31 }
32 }
33}
std::shared_ptr< Event > Ptr
Definition Event.h:36
void handleEvents(CPS::Real currentTime)
Definition Event.cpp:16
std::priority_queue< Event::Ptr, std::deque< Event::Ptr >, EventComparator > mEvents
Definition Event.h:111
void addEvent(Event::Ptr e)
Definition Event.cpp:14
CPS::Real Real
Definition Definitions.h:18