20 #define EVENTBASE_CHECK_INVERSE
78 virtual void fire(
State *pState,
double t);
86 double getEventTime()
const {
return m_tEvent; }
87 double getInternalTimeLeft()
const {
return m_Tdiff; }
90 double solveForRealTimeInterval(
const State *pState,
double t0);
94 void subtractInternalTimeInterval(
const State *pState,
double t1);
98 bool isInitialized()
const {
return !(m_Tdiff < 0); }
100 bool needsEventTimeCalculation()
const {
return (m_tEvent < 0); }
101 void setNeedEventTimeCalculation() { m_tEvent = -12345; }
146 virtual double solveForRealTimeInterval(
const State *pState,
double Tdiff,
double t0);
152 bool m_willBeRemoved;
155 inline double EventBase::solveForRealTimeInterval(
const State *pState,
double t0)
157 if (!needsEventTimeCalculation())
159 double dt = m_tEvent - t0;
164 double dt = solveForRealTimeInterval(pState, m_Tdiff, t0);
167 #ifdef EVENTBASE_CHECK_INVERSE
169 double diff = std::abs(tmpDT - m_Tdiff);
172 std::cerr <<
"ERROR: mismatch 1 between solveForRealTimeInterval and calculateInternalTimeInterval" << std::endl;
175 #endif // EVENTBASE_CHECK_INVERSE
178 assert(m_tEvent >= 0);
180 #ifdef EVENTBASE_ALWAYS_CHECK_NANTIME
181 if (m_tEvent != m_tEvent)
183 std::cerr <<
"ERROR: NaN detected in real world event time calculation" << std::endl;
186 #endif // EVENTBASE_ALWAYS_CHECK_NANTIME
193 inline void EventBase::subtractInternalTimeInterval(
const State *pState,
double t1)
195 assert(m_Tdiff >= 0);
196 assert(m_tLastCalc >= 0);
200 #ifdef EVENTBASE_CHECK_INVERSE
201 double dt = t1 - m_tLastCalc;
202 double tmpDt = solveForRealTimeInterval(pState, dT, m_tLastCalc);
203 double diff = std::abs(tmpDt - dt);
206 std::cerr <<
"ERROR: mismatch 2 between solveForRealTimeInterval and calculateInternalTimeInterval" << std::endl;
209 #endif // EVENTBASE_CHECK_INVERSE
217 #ifdef EVENTBASE_ALWAYS_CHECK_NANTIME
218 if (m_Tdiff != m_Tdiff)
220 std::cerr <<
"ERROR: NaN detected in internal event time calculation" << std::endl;
223 #endif // EVENTBASE_ALWAYS_CHECK_NANTIME
226 if (!(m_Tdiff > -1e-15))
227 std::cerr <<
"New m_Tdiff is " << m_Tdiff << std::endl;
229 assert(m_Tdiff > -1e-15);
233 setNeedEventTimeCalculation();
237 #endif // EVENTBASE_H
This class both describes the simulation state and contains the core algorithm (as shown on the main ...
Definition: state.h:40
void setWillBeRemoved(bool f)
When an event has fired, by default a new internal fire time will be calculated; setting this flag av...
Definition: eventbase.h:109
bool willBeRemoved() const
Check if the event has been marked for deletion, can avoid a call to the random number generator to c...
Definition: eventbase.h:105
virtual double calculateInternalTimeInterval(const State *pState, double t0, double dt)
This function should map the real world time interval onto an internal time interval and return it...
Definition: eventbase.cpp:42
This class allows you to generate random numbers, and uses the GNU Scientific Library for this...
Definition: gslrandomnumbergenerator.h:16
virtual void fire(State *pState, double t)
This function will be called when the event fires, so this should most likely be re-implemented in yo...
Definition: eventbase.cpp:52
This is the base class for events in the mNRM algorithm.
Definition: eventbase.h:62
virtual double getNewInternalTimeDifference(GslRandomNumberGenerator *pRndGen, const State *pState)
This function will be called to generate a new internal time difference.
Definition: eventbase.cpp:28