0

I am new to modelica. I would like to add two static numbers in OpenModelica and display the result in the Modeling view.

source1 = 10 # Modelica.Blocks.Sources.Constant

source2 = 20 # Modelica.Blocks.Sources.Constant

result = source1 + source2 # Modelica.Blocks.Math.Add

In order to do so, I created two sources with a constant real value and included a Math block for addition (also see full model code below).

enter image description here

I am able to run the simulation and select the result of the add block to show it as a plot in the Plotting view:

enter image description here

However, I would prefer to stay in the Modeling view and have some display element, showing the resulting value of 30:

enter image description here

=> Are there display components in OpenModelica? (could not find any)

Or do I always need to switch to the plotting view (even for static models that would not need to include a time variable)?

If there is no display component... is it possible to create it on my own? (Then components would need to be able to access simulation results.)

model demo
  Modelica.Blocks.Sources.Constant source1(k = 10)  annotation(
    Placement(visible = true, transformation(origin = {-70, 52}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
  Modelica.Blocks.Sources.Constant source2(k = 20) annotation(
    Placement(visible = true, transformation(origin = {-70, -12}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
  Modelica.Blocks.Math.Add add annotation(
    Placement(visible = true, transformation(origin = {-12, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(source1.y, add.u1) annotation(
    Line(points = {{-58, 52}, {-24, 52}, {-24, 16}}, color = {0, 0, 127}));
  connect(source2.y, add.u2) annotation(
    Line(points = {{-58, -12}, {-24, -12}, {-24, 4}}, color = {0, 0, 127}));
  annotation(
    uses(Modelica(version = "4.0.0")),
  Diagram);
end demo;

Related questions:

How to show result of static model (=plain number) in Xcos?

https://softwarerecs.stackexchange.com/questions/87166/python-framework-for-block-simulations-with-graphical-user-interface-like-openm

Stefan
  • 10,010
  • 7
  • 61
  • 117

1 Answers1

0

There is Modelica.Blocks.Interaction.Show.RealValue that does something like what you want. The drawback is that this is not shown in the modeling view, but in the "Diagram Window" of the plotting view (which is in general used to show time-varying results/icon changes, with help of the simulation time scrubber.

model demo

  Modelica.Blocks.Sources.Constant source1(k = 10)  annotation(
    Placement(visible = true, transformation(origin = {-70, 52}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
  Modelica.Blocks.Sources.Constant source2(k = 20) annotation(
    Placement(visible = true, transformation(origin = {-70, -12}, extent = {{-10, 10}, {10, -10}}, rotation = 0)));
  Modelica.Blocks.Math.Add add annotation(
    Placement(visible = true, transformation(origin = {-12, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
  Modelica.Blocks.Interaction.Show.RealValue realValue annotation(
    Placement(visible = true, transformation(origin = {26, 10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
  connect(source1.y, add.u1) annotation(
    Line(points = {{-58, 52}, {-24, 52}, {-24, 16}}, color = {0, 0, 127}));
  connect(source2.y, add.u2) annotation(
    Line(points = {{-58, -12}, {-24, -12}, {-24, 4}}, color = {0, 0, 127}));
  connect(add.y, realValue.numberPort) annotation(
    Line(points = {{0, 10}, {14.5, 10}}, color = {0, 0, 127}));
  annotation(
    uses(Modelica(version = "4.0.0")),
  Diagram);

end demo;

So yeah, there are "display components" in the Modelica Standard Library (not only OpenModelica), but to see the dynamic result you have to use the plotting view.

Christoph
  • 5,480
  • 6
  • 36
  • 61