NREL / SOEP-QSS-Test

0 stars 1 forks source link

Event indicator discrete variable dependency short-circuiting #13

Closed DeadParrot closed 2 years ago

DeadParrot commented 3 years ago

The event indicator dependencies of discrete variables are short-circuited out of the dependency information provided in modelDescription.xml. This works for discrete variables whose forward dependency graph leads to one or more state variables.

The ACControl10, TimeTest and TimeTestCross models show that this doesn't work where the discrete variable is only a reverse dependency of an event indicator. In this case the dependency is lost and changes to the discrete variable are not propagated to its observers, breaking the QSS simulation.

The treatment of discrete variable dependencies will need to be adapted to handle this scenario. The simplest fix is to add discrete variables as forward dependencies of the event indicators whose zero-crossing function they appears in. These dependencies could instead be indicated in the <EventIndicators> sections.

A new model, DepTest was added to demonstrate the key dependency handling changes that are proposed for QSS FMUs. The new proposed rules are:

DeadParrot commented 3 years ago

Versions

The issue was observed with these component versions (may occur with others):

Component Version Date
OCT OCT-r23206_JM-r14295 2021/05
Buildings 9c37781 2021/05/04
QSS e4a0f62 2021/06/08

Build

Build the FMU with bld from the OCT directory as described in the Status page.

The dependencies can be examined in the modelDescription.xml file.

Run

Run the models with PyFMI or QSS from a console configured as described in the Status page.

PyFMI: Use run under the model OCT directories to generate the CVode simulation.

QSS: Use run under the model QSS directory in a method subdirectory such as QSS2.

DeadParrot commented 3 years ago

For my OCT build of TimeTest the event indicator is:

            <EventIndicators>
                <Element index="11" reverseDependencies="45 49"/>
            </EventIndicators>

and the relevant variables are:

        <!-- Variable with index #45 -->
        <ScalarVariable name="nextSample" valueReference="49" causality="output" variability="discrete" initial="exact">
            <Real relativeQuantity="false" start="1.0"/>
        </ScalarVariable>

        <!-- Variable with index #47 -->
        <ScalarVariable name="time" valueReference="44" causality="local" variability="continuous" initial="approx">
            <Real relativeQuantity="false" start="0.0"/>
        </ScalarVariable>

and the QSS simulation is fixed by modifying the event indicator dependency in <Outputs> from:

            <Unknown index="11" dependencies="47" dependenciesKind="constant"/>

to

            <Unknown index="11" dependencies="45 47" dependenciesKind="constant constant"/>

Note that we would need this dependency even if nextSample was a (non-output) local variable for QSS to function correctly.

DeadParrot commented 3 years ago

@mwetter observed that dependencies of x and d on the variables appearing in the zero-crossing function, time and nextSample, are redundant in a QSS FMU, where the event indicator reverse dependencies cover these dependencies more efficiently -- variables modified by the zero-crossing "handler" (x and d in this case) only need to update when the zero-crossing occurs but not at other changes to the variables appearing within the zero-crossing function. Omitting these redundant dependencies in QSS FMUs would benefit efficiency.

DeadParrot commented 3 years ago

The proposed OCT changes related to this issue in the SOEP Software Architecture document are:

  1. State, local, and output variables modified by an event indicator’s block when its state event occurs appear as its reverse dependencies and (for performance reasons) those variables do not have dependencies on variables appearing in the event indicator. State variables modified by a state event should themselves appear as a reverse dependency, not their derivatives.
  2. An event indicator has dependencies on all state, local, and output variables (other than those with variability="fixed") appearing in its expression.
  3. Local variables appearing in event indicator are converted to output variables to give them a place for dependencies in the <Outputs> section of the modelDescription.xml file. To indicate that these are extra outputs that are not declared as outputs in the Modelica model, they are given the prefix _qssLocal_ (this has some potential for user confusion and breaks scripts that specify variables to be compared between PyFMI and QSS runs so should be given more thought).
DeadParrot commented 2 years ago

Instead of changing the dependencies listed when building an FMU for QSS, OCT is being extended to add a <Dependencies> annotation section with the dependencies for all variables, including non-state local variables. QSS can do any desired short-circuiting of the dependency graph from this information. Based on this new capability I am closing this issue.