|
FhSim
3.1.0
Marine systems simulation
|
#include <SampleClock.h>
Public Member Functions | |
| SampleClock (const double period, const double firstSampleTime=0.0) | |
| void | StartAt (const double tStart) |
| void | SetLogger (PrintDuringExec *const print) |
| bool | Due (const double t) |
| double | NextSampleTime () const |
| The time at which the next sample is due, s. | |
| double | Period () const |
| The time between samples, s. | |
| bool | LatenessWarningGiven () const |
| True once the too-coarse-step warning has been given. | |
Static Public Member Functions | |
| static SampleClock | Never () |
| A clock that never fires: for a sensor that has no sample rate yet. | |
Decides when a fixed-rate sensor should take its next sample.
FhSim has no discrete event scheduler, so a sensor that samples at a fixed rate has to schedule itself from the accepted simulation time. The idiom is the one used by Signal/Samplifier in fhsim_base: hold the time of the next sample, and advance it by one period whenever it is reached.
The integrator step is not synchronised with the sample period, so more than one sample can fall inside a single accepted step. Due therefore advances by exactly one period per call and is meant to be used in a loop:
A sample fired later than kLatenessFraction of a period after it was due means the integrator step is too coarse for the sample rate, which otherwise shows up only as a quietly aliased signal. The clock says so once, naming the StepMax the user would need, and then stays quiet.
@group block and appears in no model list.
|
inlineexplicit |
Creates a clock with the given rate.
| period | The time between samples, s; finite and positive. |
| firstSampleTime | The time of the first sample, s. A clock for a run that starts at TStart is moved there with StartAt. |
| std::invalid_argument | if period is zero, negative, NaN or infinite: such a clock would never advance, or never fire. |
|
inline |
Reports whether a sample is due at the given time, and consumes it.
| t | The current simulation time, s. |
|
inline |
Sets the logger used for the too-coarse-step warning.
| The simulation logger, or null to log nothing. |
|
inline |
Moves the first sample to the start of the run.
Called from FinalSetup(T, ...) with the run's start time, so that a run with TStart = 1000 s takes one sample on its first step instead of the 10 000 that fit between 0 and TStart. Does nothing for a Never clock.
| tStart | The simulation start time, s. |