11#include <fhsim/NFhSim.h>
12#include <fhsim/PrintDuringExec.h>
47 explicit SampleClock(
const double period,
const double firstSampleTime = 0.0)
49 , m_next(firstSampleTime)
57 void SetLogger(PrintDuringExec*
const print) { m_print = print; }
65 bool Due(
const double t)
79 double Period()
const {
return m_period; }
86 void WarnOnceIfLate(
const double t)
88 const double lateness = t - m_next;
89 if (lateness <= kLatenessFraction * m_period || m_latenessWarningGiven)
92 m_latenessWarningGiven =
true;
93 if (m_print ==
nullptr)
96 m_print->WriteLog(
"In SampleClock. A sample due at t = " + std::to_string(m_next) +
" s was taken " + std::to_string(lateness) +
" s late, which is more than " + std::to_string(kLatenessFraction) +
" of the sample period of " + std::to_string(m_period) +
" s. The integrator step is too coarse for this "
97 "sample rate; set StepMax to " +
98 std::to_string(kLatenessFraction * m_period) +
" s or less. This warning is given once.",
99 fhsim::LogLevel_Warning);
103 static constexpr double kLatenessFraction = 0.25;
108 PrintDuringExec* m_print =
nullptr;
109 bool m_latenessWarningGiven =
false;
Definition SampleClock.h:40
bool Due(const double t)
Definition SampleClock.h:65
SampleClock(const double period, const double firstSampleTime=0.0)
Definition SampleClock.h:47
void SetLogger(PrintDuringExec *const print)
Definition SampleClock.h:57
double NextSampleTime() const
The time at which the next sample is due, s.
Definition SampleClock.h:76
double Period() const
The time between samples, s.
Definition SampleClock.h:79