NREL / SOEP-QSS-Test

0 stars 0 forks source link

Event generating functions #19

Open DeadParrot opened 2 years ago

DeadParrot commented 2 years ago

This is a tracking issue for OCT changes under discussion related to treatment of event generating and other functions that can cause variable value or derivative discontinuities.

For QSS purposes, functions that can cause trajectory value or (low-order) derivative discontinuities should be transformed into Modelica when blocks so that these discontinuities are not missed by QSS, most critically for slow-changing states that are using large time steps. This applies for both functions treated as event-generating by Modelica and others such as min and max that do not generate events.

Additionally, the Modelica noEvent() operator should probably be ignored for QSS FMU generation unless it can be determined to have no effect on solution trajectories.

Event generation functions that QSS may need to handle (unlike reinit these can occur outside the context of an event triggered by an if or when conditional action block):

mwetter commented 2 years ago

The noEvent operator must be ignored if and only if the function is C1 or higher. This is the case if noEvent either is combined with smooth(x, .... where x > 0, or if noEvent is used inside a function that has the annotation smoothOrder=x with x > 1. In all other cases, an event must be generated.

Otherwise assertions may be triggered such as in

assert(noEvent(TIn > TMin and TIn < TMax), "In " + getInstanceName() +
     ": Weather data dry bulb temperature out of bounds.\n" + "   TIn = " + String(
    TIn));

or the code will be very inefficient such as due to the function below that is used in pressure drop calculations:

   m_flow := smooth(2, if noEvent(abs(dp)>dp_turbulent)
               then sign(dp)*k*sqrt(abs(dp))
               else (1.40625  + (0.15625*dpNormSq - 0.5625)*dpNormSq)*m_flow_turbulent*dpNorm);
DeadParrot commented 2 years ago

Having min and max generate events can cause solution chattering with some models but without events QSS may take large time steps over these discontinuities and produce bad simulation trajectories. Using the QSS dtMax field could limit the trajectory errors at the cost of performance. We may want to evaluate the possibility of adding event-generating versions of min and max to OCT with a mechanism to use them for a run. The impact of this change could be evaluated for models of modest size by manually changing the use of min and max to zero-crossing conditional blocks.