Skip to content

Notes on Simulation speed

Damien Picard edited this page Feb 10, 2016 · 6 revisions

IDEAS: Slow linear buiding + non-linear HVAC + discrete control

Time t n variables y(t) m(=n) equations F(y,t)

  • 0 = H(x,z,t) -> Algebraic equations, are solved first using the known state values
  • der(x) = G(x,z,t) -> Differential equations (states brake algebraic loops)

1st step: solve algebraic equations

2nd steps: solving differential equation

(as used in Dymola)

1. Alias variables are eliminated

2. Sequential equations are solved (=cheap)

3. Linear algebraic loops are solved with constant coefficients (=cheap)

  • annotation(evaluate=true) hardcodes the inverse of A in equation Ax=b whereby the parameter cannot be changed any more after translation
  • evaluate=true in command line sets this for all variables in the model

4. Linear algebraic loops are solved with non-constant coefficients (requires 1 iteration)

5. Non-linear algebraic loops are solved (requires many iterations)

  • Always with a Newton-solver
  • Requires for every step the residual, the Jacobian (i.e. derivatives)

6. Mixed algebraic loops are loved (requirs many iterations)

  • e.g. use of TAir is more efficient for hysteresis control compared to TRad, because it's directly connected to a state and not to an algebraic equation (causing an algebraic loop)

3rd step: time integration of der(x)

  • Explicit Euler (fixed time step) solvers need a short enough timestep to avoid oscillation, typically 10 times as small as smallest time constant. Implicit Euler (fixed time step) don't have this problems, but may lead to large sets of equations. Dymola's Euler solver is explicit
  • Higher order implicit methods (Radau, LSodar, Dassl) have a variable step due to polynomial approximation of the derivative. This is more expensive per step, but larger steps can be taken which requires less steps.
  • Performance of the implicit solver can be checked at the number of F-evaluations which indicates the number of integration iterations during all step.
  • Sources of small time constants are small (fast varying states). These are introduced in IDEAS models as 'tau' e.g. in the pumps, which sets the size of the water volume and thus of the state. If you set energyDynamics = false, the state is removed from this model, which means tau is ignored and the outlet equals the inlet Also: A filter is introduced in some models. It smoothens input signals by introducing some states i.e. it has a riseTime. A filter can be disabled using a through a which can be cancelled by the booleanBoolean parameter.
  • A high order explicit method with variable step is Dopri45
  • Implicit solvers use Euler methods which require derivatives in the Jacobian. These derivatives can be either numerical(automatic numerical differentiation) or analytical (user provided function). The latter doesn't work for Modelica functions or algorithms.

Total computational cost of a simulation is the number of iteration times the cost of one iteration (C = N.k))

  • Trade-off: if you remove states: N goes down, but k goes up
  • Advanced.GenerateBlockTimers = true gives more information

Algebraic loops, e.g. fluid loop

  • When the model is compiled, it is restructured in a number of non-linear systems of equations. The size of such a system is an indicator of the time to solve it. The size after manipulation (by Dymola) indicates the number of equations from which the derivative is needed and is therefore even more important. By introducing states in your system model, a larger system of equations is decoupled in smaller ones. When introducing a new state (e.g. a small water volume in a pump (tau>1)) a timeconstant is introduced which comes with a trade-off: small timeconstants limit the stepsize of the time integration (see section above) but large timeconstants might alter the physical correctness of your model. Sometimes a timedelay (filter) is introduced for the control signals, which is often present in the real system.
  • Thermal enthalpy calculation: Either you add states to reduce the set of equations or you set the Boolean parameter (from partial model TwoPort) allowFlowReversal = false to allow forward solving of the loop because the flow direction is known.
  • Pressure drop: in advanced, if Boolean parameter from_dp = true the solver computes the mass flow rate from the pressure.
    • In a parallel circuit, the pressure drop dp is the same in all branches and setting from_dp = true reduces the system size to 1.
    • In a series circuit on the other hand, the mass low rate is the same for all series pipes and thus setting from_dp = false is advantageous.
  • If a variable a = b/c, with c a parameter it's evaluated every step checking if c isn't equal to 0. If you make d=1/c a parameter and compute a = b*d, it's not.
  • Don't use Dassl when you have a lot of events
  • Events cut down the potential of large time steps in implicit integrators

You can remove the pressure drop in bypasses by setting dp_nominal = 0, which decouples the circuits

Gain from explicit integrator

  • The need to set all time constants > 60s or so.
  • Set one enthalpy-state in each allowFlowReversal=false loop

For further details see: Jorissen, F., Wetter, M., & Helsen, L. (2015). Simulation Speed Analysis and Improvements of Modelica Models for Building Energy Simulation. In 11th International Modelica Conference (pp. 59–69). Paris, France. doi:10.3384/ecp1511859