Values in Modelica

Modelica has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

model Values
  String str;
  Integer int;
  Real real;
  Boolean bool;
equation
  // Strings, which can be added together with +.
  str = "modelica" + "lang";
  Modelica.Utilities.Streams.print(str);

  // Integers and floats.
  int = 1 + 1;
  Modelica.Utilities.Streams.print("1+1 = " + String(int));
  real = 7.0/3.0;
  Modelica.Utilities.Streams.print("7.0/3.0 = " + String(real));

  // Booleans, with boolean operators as you'd expect.
  bool = true and false;
  Modelica.Utilities.Streams.print(String(bool));
  bool = true or false;
  Modelica.Utilities.Streams.print(String(bool));
  bool = not true;
  Modelica.Utilities.Streams.print(String(bool));
end Values;

To run this Modelica model, you would typically use a Modelica simulation environment. The output would be:

modelicalang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false

Note that in Modelica, we use the Modelica.Utilities.Streams.print() function to output values, as there isn’t a direct equivalent to fmt.Println(). Also, Modelica uses and, or, and not for boolean operations instead of &&, ||, and !.

In Modelica, variables are typically declared at the beginning of the model and their values are set in the equation section. This is different from imperative languages where you might set values as you go.