ViolationStatistics block

Requirements.Verify.ViolationStatistics  ยท source

Icon of ViolationStatistics

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.

OutputMeaning
nViolationsNumber 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)
totalDurationTime with property = Violated in total, every violation, unfiltered (for a comfort band this is the "unmet hours" of building simulation, in seconds)
violatedFractiontotalDuration over the time in which the property was applicable (not Undefined)
longestDuration, tLongestStartThe 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, tWorstThe 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, tEpisodeWorstThe same over the current (or last) episode
currentDurationDuration 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 T approximates its derivative, and a state event fires at every local extremum. The event comes about T after the extremum, so tWorst is about T late, and the value is off by about u''·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 resolution below the least value so far. The value is within resolution (default 0.01: a hundredth of the tolerance) of the exact one; the number of events is the depth of the descent over resolution, 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

DateDescription
Oct. 19, 2026New block (H. Tummescheit, Model Based Innovation LLC)

Parameters

NameTypeDescription
useMargin parameterBoolean= true, if the margin input is enabled: the worst margin over the run and per violation episode
minDuration parameterSI.TimeViolation episodes shorter than this are not counted (0: every one is)
mergeGap parameterSI.TimeA violation that starts within this time after the previous one ended continues that episode (0: only at the same instant)
method parameterRequirements.Types.WorstMarginMethodHow the worst margin is found
T parameterSI.TimeContinuous: time constant of the derivative filter, about a thousandth of the margin's time scale (60 s for a year)
resolution parameterRealRatchet: resolution of the worst margin, in margin units (tolerances)
logStatistics parameterBoolean= true, if the statistics are written to the log file of the inner printViolations and printed in its summary
requirementName parameterStringName the statistics are logged under

Components and variables

NameTypeDescription
propertyRequirements.Interfaces.PropertyInputProperty of the requirement
marginRequirements.Interfaces.MarginInputMargin of the requirement (the check block's margin output)
nViolationsModelica.Blocks.Interfaces.IntegerOutputNumber of violation episodes (merged within mergeGap, at least minDuration long)
totalDurationModelica.Blocks.Interfaces.RealOutputTime in which the property was Violated, in total (every violation, unfiltered)
violatedFractionModelica.Blocks.Interfaces.RealOutputtotalDuration over the time in which the property was applicable (not Undefined)
longestDurationModelica.Blocks.Interfaces.RealOutputDuration of the longest counted violation episode
tLongestStartModelica.Blocks.Interfaces.RealOutputStart of the longest counted violation episode
worstMarginModelica.Blocks.Interfaces.RealOutputLeast margin over the phases in which the property was decided (0 before the first one, or without margin)
tWorstModelica.Blocks.Interfaces.RealOutputInstant of worstMargin
currentDurationModelica.Blocks.Interfaces.RealOutputDuration of the running violation (0 while not violated)
episodeWorstMarginModelica.Blocks.Interfaces.RealOutputLeast margin of the current (or last) violation episode (0 before the first one, or without margin)
tEpisodeWorstModelica.Blocks.Interfaces.RealOutputInstant of episodeWorstMargin
continuousWorstRequirements.Internal.ContinuousWorstWorst margin at every local extremum of the margin (method = Continuous)
ratchetWorstRequirements.Internal.RatchetWorstWorst margin at every new low by more than resolution (method = Ratchet)
loggerRequirements.Internal.StatisticsLoggerWrites the statistics to the log file of the inner printViolations (logStatistics = true)