modelExample6

Example 6 model of Modelica code that is inefficiently compiled into C-code
Diagram of Example6

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

This example, together with IBPSA.Fluid.Examples.Performance.Example7, illustrates the overhead generated by divisions by parameters. See Jorissen et al. (2015) for a complementary discussion.

Running the following commands allows comparing the CPU times of the two models, disregarding as much as possible the influence of the integrator:

simulateModel("IBPSA.Fluid.Examples.PerformanceExamples.Example6", stopTime=100, numberOfIntervals=1, method="Rkfix4", fixedstepsize=0.001, resultFile="Example6");
simulateModel("IBPSA.Fluid.Examples.PerformanceExamples.Example7", stopTime=100, numberOfIntervals=1, method="Rkfix4", fixedstepsize=0.001, resultFile="Example7");

Comparing the CPU times indicates a speed improvement of 56%. This difference almost disappears when adding annotation(Evaluate=true) to R and C.

In dsmodel.c we find:

DynamicsSection
W_[2] = divmacro(X_[0]-X_[1],"T[1]-T[2]",DP_[0],"R");
F_[0] = divmacro(W_[1]-W_[2],"Q_flow[1]-Q_flow[2]",DP_[1],"C");

This suggests that the parameter division needs to be handled during each function evaluation, probably causing the increased overhead.

The following command allows comparing the CPU times objectively.

simulateModel("IBPSA.Fluid.Examples.Performance.Example6", stopTime=100, numberOfIntervals=1, method="Euler", fixedstepsize=0.001, resultFile="Example6");

See Jorissen et al. (2015) for a discussion.

References

  • Filip Jorissen, Michael Wetter and Lieve Helsen.
    Simulation speed analysis and improvements of Modelica models for building energy simulation.
    Submitted: 11th Modelica Conference. Paris, France. Sep. 2015.

Parameters

TypeNameDefaultDescription
IntegernCapacitors500
RealR0.001
RealC1000

Components

TypeNameDefaultDescription
RealT
RealQ_flow

Revisions

  • April 11, 2016 by Michael Wetter:
    Corrected wrong hyperlink in documentation for issue 450.
  • July 14, 2015, by Michael Wetter:
    Revised documentation.
  • April 17, 2015, by Filip Jorissen:
    First implementation.