ViolationStatistics block
Requirements.Verify.ViolationStatistics
ยท source
Violation statistics of a property over a run: how often it was violated, for how long in total, the longest violation, the worst margin and when
Statistics of the violations of one requirement over a run, from its property and (optionally) its normalized
margin: how often it was violated, for how long in total, the longest violation, and the worst violation and when.
For a long run (an annual building simulation, a duty cycle) these answer what a verdict alone cannot: a requirement
violated once for a second and one violated every afternoon for three hours are both violated.
| Output | Meaning |
|---|---|
nViolations | Number of violation episodes: maximal phases with property = Violated,
merged when one starts within mergeGap after the previous one ended, and counted only when at least
minDuration long (an episode still running is counted as soon as it is) |
totalDuration | Time with property = Violated in total, every violation, unfiltered
(for a comfort band this is the "unmet hours" of building simulation, in seconds) |
violatedFraction | totalDuration over the time in which the property was applicable
(not Undefined) |
longestDuration, tLongestStart | The longest counted episode and its start (the first of equally long ones); an episode's duration runs from its first violation to the end of its last, merged gaps included |
worstMargin, tWorst | The least margin over the phases in which the property was
decided (Satisfied or Violated) and its instant: the worst violation if the requirement was
violated, the closest call if not. 0 before the property is first decided |
episodeWorstMargin, tEpisodeWorst | The same over the current (or last) episode |
currentDuration | Duration of the running violation, 0 while not violated |
Every output holds its value at the end of the run without terminal() (which Modelon Impact evaluates to false):
the outputs include the episode still running.
What counts
An episode is a phase of property = Violated, not of a negative margin: while a check is still
Undecided (a duration not yet reached, a sliding window not yet full) its margin is provisional and may be
negative without a violation. For the same reason the worst margin is taken over the decided phases only. This is the
rule the verdict of the requirement follows, so the statistics agree with it: nViolations > 0 exactly when
the requirement is violated (with minDuration = 0), and a negative worstMargin then.
mergeGap and minDuration keep a signal that hovers at its limit from counting as hundreds of
violations: a room temperature that crosses its setpoint band back and forth for ten minutes is one episode with
mergeGap = 10 min. Both only change the episode count and the longest episode, never
totalDuration. With mergeGap = 0 a violation that resumes at the very instant it ended (in the
same event iteration) still continues its episode.
Worst margin
The least value of a continuous signal is found at its local minima, which a block can only locate through events. The
two methods (parameter method, WorstMarginMethod):
- Continuous (default) reuses
Modelica.Blocks.Math.ContinuousSignalExtrema:
a first-order filter of the margin with time constant
Tapproximates its derivative, and a state event fires at every local extremum. The event comes aboutTafter the extremum, sotWorstis aboutTlate, and the value is off by aboutu''·T²/2, negligible. Cost: one event per local extremum of the margin, minima and maxima, plus the filter state. - Ratchet fires an event only when the margin falls more than
resolutionbelow the least value so far. The value is withinresolution(default 0.01: a hundredth of the tolerance) of the exact one; the number of events is the depth of the descent overresolution, however much the margin oscillates.
Choosing T. Near an extremum the filter's event indicator is about T times the margin's
slope. If that is smaller than the solver's absolute tolerance, integration noise flips its sign over and over and the
solver reports chattering at every extremum. This is why the default is 0.01 s, not the 1 µs of the MSL block. Set
T to about a thousandth of the shortest time scale on which the margin varies: 0.01 s for a margin that
moves in seconds, 60 s for an annual building simulation driven by daily cycles.
Either method is more accurate than the minimum over a stored result, which sees only the output points: an annual run stored hourly misses a peak between two of them. The counts and durations need no extra events at all: the property only changes at events the check block produces anyway.
Use
Connect property to a check block's y and margin to its margin. The
requirement blocks Verify.Requirement and
BooleanRequirement contain this block when their parameter
computeStatistics is set, and then write the statistics to the log file and the summary of
PrintViolations beside the verdict (logStatistics
does the same for a stand-alone instance). Examples:
Examples.Elementary.ViolationStatistics.
Copyright © 2026 Model Based Innovation LLC. All rights reserved.
Revisions
| Date | Description |
|---|---|
| Oct. 19, 2026 | New block (H. Tummescheit, Model Based Innovation LLC) |
Parameters
| Name | Type | Description |
|---|---|---|
useMargin parameter | Boolean | = true, if the margin input is enabled: the worst margin over the run and per violation episode |
minDuration parameter | SI.Time | Violation episodes shorter than this are not counted (0: every one is) |
mergeGap parameter | SI.Time | A violation that starts within this time after the previous one ended continues that episode (0: only at the same instant) |
method parameter | Requirements.Types.WorstMarginMethod | How the worst margin is found |
T parameter | SI.Time | Continuous: time constant of the derivative filter, about a thousandth of the margin's time scale (60 s for a year) |
resolution parameter | Real | Ratchet: resolution of the worst margin, in margin units (tolerances) |
logStatistics parameter | Boolean | = true, if the statistics are written to the log file of the inner printViolations and printed in its summary |
requirementName parameter | String | Name the statistics are logged under |
Components and variables
| Name | Type | Description |
|---|---|---|
property | Requirements.Interfaces.PropertyInput | Property of the requirement |
margin | Requirements.Interfaces.MarginInput | Margin of the requirement (the check block's margin output) |
nViolations | Modelica.Blocks.Interfaces.IntegerOutput | Number of violation episodes (merged within mergeGap, at least minDuration long) |
totalDuration | Modelica.Blocks.Interfaces.RealOutput | Time in which the property was Violated, in total (every violation, unfiltered) |
violatedFraction | Modelica.Blocks.Interfaces.RealOutput | totalDuration over the time in which the property was applicable (not Undefined) |
longestDuration | Modelica.Blocks.Interfaces.RealOutput | Duration of the longest counted violation episode |
tLongestStart | Modelica.Blocks.Interfaces.RealOutput | Start of the longest counted violation episode |
worstMargin | Modelica.Blocks.Interfaces.RealOutput | Least margin over the phases in which the property was decided (0 before the first one, or without margin) |
tWorst | Modelica.Blocks.Interfaces.RealOutput | Instant of worstMargin |
currentDuration | Modelica.Blocks.Interfaces.RealOutput | Duration of the running violation (0 while not violated) |
episodeWorstMargin | Modelica.Blocks.Interfaces.RealOutput | Least margin of the current (or last) violation episode (0 before the first one, or without margin) |
tEpisodeWorst | Modelica.Blocks.Interfaces.RealOutput | Instant of episodeWorstMargin |
continuousWorst | Requirements.Internal.ContinuousWorst | Worst margin at every local extremum of the margin (method = Continuous) |
ratchetWorst | Requirements.Internal.RatchetWorst | Worst margin at every new low by more than resolution (method = Ratchet) |
logger | Requirements.Internal.StatisticsLogger | Writes the statistics to the log file of the inner printViolations (logStatistics = true) |