modelExample5

Example 5 model of Modelica code that is inefficiently compiled into C-code

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

Information

This example illustrates the impact of Modelica code formulations on the C-code.

Compare the C-code in dsmodel.c when setting the parameter efficient to true or false and when adding annotation(Evaluate=true) to the parameter efficient.

This produces:

Efficient = false and Evaluate = false

helpvar[0] = sin(Time);
F_[0] = helpvar[0]*(IF DP_[0] THEN W_[0] ELSE DP_[1]+DP_[2]+DP_[3]);

Efficient = false and Evaluate = true

helpvar[0] = sin(Time);
F_[0] = helpvar[0]*(DP_[0]+DP_[1]+DP_[2]);

Efficient = true and Evaluate = true

helpvar[0] = sin(Time);
F_[0] = helpvar[0]*W_[1];

The last option requires much less operations to be performed and is therefore more efficient.

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
Booleanefficientfalse
Reala1:3
Realbsum(a)

Components

TypeNameDefaultDescription
Realc

Revisions

  • July 14, 2015, by Michael Wetter:
    Revised documentation.
  • April 17, 2015, by Filip Jorissen:
    First implementation.