.Modelica.UsersGuide.Conventions.ModelicaCode.Format

Format

Information

Comments and Annotations

Comments and annotations should start with a capital letter, for example:
parameter Real a = 1 "Arbitrary factor";.
For Boolean parameters, the description string should start with "= true, …", for example:
parameter Boolean useHeatPort = false "= true, if heatPort is enabled";.

Tabs and Groups

The annotations "tab" and "group" define the placement of component or of variables in a dialog.

Using the group annotation, the following rules shall be followed:

  1. Avoid excessively long group labels.
  2. Use nouns rather than verbs, without ending punctuation.
  3. Use sentence-style capitalization.

Using the tab annotation, the following rules shall be followed:

  1. Try to group components or variables in the default "general" tab first. But feel free to define a new tab it they are so many.
  2. Label tabs based on their pattern. The label shall clearly reflect the content of the collected variables.
  3. Avoid long tab labels. One or two words are mostly sufficient.
  4. Use nouns rather than verbs, without ending punctuation.
  5. Use sentence-style capitalization.
  6. Visibility of parameters collected in one tab shall not be dependent on parameters shown in another tab.
Example

Imagine you define a controlled electric drive being composed of a controller and an electrical machine. The latter has parameters number of pole pairs p, nominal frequency fnom, rotor's moment of inertia Jrotor and others. The controller itself is divided into several sub-controllers – such as the one for speed control with parameters like gain k or time constant T. Then, the above parameters of your electrical drive model could be sorted using tabs and groups as follows: p, fnom and Jrotor grouped in the "Electrical machine" group in the "general" tab; k and T in the group "Speed control" under tab "Controller".

In the Modelica code, for example the parameter k will then be defined like:

parameter Real k=1 "Gain"
  annotation(
    Dialog(
      tab="Controller",
      group="Speed control"));

Whitespace and Indentation

Trailing white-space (i.e., white-space at the end of the lines) shall not be used. The tab-character shall not be used, since the tab-stops are not standardized.

The code in a class shall be indented relative to the class in steps of two spaces; except that the headings public, protected, equation, algorithm, and end of class marker shall not be indented. The keywords public and protected are headings for a group of declarations.

Long modifier lists shall be split into several indented lines with at most one modifier per line.

Full class definitions shall be separated by an empty line.

Example
package MyPackage
  partial model BaseModel
    parameter Real p;
    input Real u(unit="m/s");
  protected
    Real y;
    Real x(
      start=1,
      unit="m",
      nominal=10);
  equation
    der(x) = u;
    y = 2*x;
  end BaseModel;

  model ModelP2
    extends BaseModel(p=2);
  end ModelP2;
end MyPackage;

Generated at 2025-06-06T18:20:43Z by OpenModelicaOpenModelica 1.25.0 using GenerateDoc.mos