Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event generating functions #19

Open
DeadParrot opened this issue Sep 29, 2021 · 2 comments
Open

Event generating functions #19

DeadParrot opened this issue Sep 29, 2021 · 2 comments
Labels
OCT OPTIMICA Compiler Toolkit performance New feature or request QSS Quantized State System
Milestone

Comments

@DeadParrot
Copy link
Collaborator

DeadParrot commented Sep 29, 2021

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):

  • sample
  • delay
  • spatialDistribution
@DeadParrot DeadParrot added performance New feature or request OCT OPTIMICA Compiler Toolkit QSS Quantized State System labels Sep 29, 2021
@mwetter
Copy link
Collaborator

mwetter commented Sep 30, 2021

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 DeadParrot added this to the 0.0.2 milestone Aug 17, 2022
@DeadParrot
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCT OPTIMICA Compiler Toolkit performance New feature or request QSS Quantized State System
Projects
None yet
Development

No branches or pull requests

2 participants