OpenModelica / BioChem

BioChem is a package for biochemical modeling and simulation with Modelica
7 stars 12 forks source link

Annotations associated with physical units #22

Closed AtiyahElsheikh closed 3 years ago

AtiyahElsheikh commented 3 years ago

Physical units in BioChem are currently declared with annotations, e.g.

type Concentration= Real(quantity="Concentration", unit="mol/l", min=0)              
          annotation(Icon(coordinateSystem(extent={{-100,100},{100,-100}}, preserveAspectRatio=true, grid={10,10})),
                     Diagram(coordinateSystem(extent={{-100,100},{100,-100}}, preserveAspectRatio=true, grid={10,10})));

It resembles somehow Modelica.Icons.TypeReal:

type TypeReal "Icon for Real types"
    extends Real;
    annotation(Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics={
          Rectangle(
            lineColor={160,160,164},
            fillColor={160,160,164},
            fillPattern=FillPattern.Solid,
            extent={{-100.0,-100.0},{100.0,100.0}},
            radius=25.0),
          Text(
            textColor={255,255,255},
            extent={{-90.0,-50.0},{90.0,50.0}},
            textString="R")}),Documentation(info="<html>
<p>
This icon is designed for a <strong>Real</strong> type.
</p>
</html>"));
end TypeReal;

I would rather prefer to get rid of the annotations and make use of TypeReal, something like that:

 type Concentration = Modelica.Icons.TypeReal(final quantity="Concentration",final unit = "mol/l", min = 0)
  " Concentration of a metabolite [mol/l]";

Questions:

sjoelund commented 3 years ago
  • Is there any need to keep the old annotations,
    • the preserveAspectRatio attribute of Icon? its value is true in BioChem and false in TypeReal
    • the Diagram annotation?

It's just a default empty diagram, right? No need to keep it.

  • The Icon will appear with the string "R". Can annotations in subclasses get modified? so that the attribute textString in TypeReal get overwritten by the unit attribute of type Real?

No. You can extend and choose not to inherit graphical primitives. But then you would lose the text and it's basically going to be the same as defining your own icon annotation. Maybe a little shorter since you don't need to define the extents again.

AtiyahElsheikh commented 3 years ago

This is also somehow closely related to the following [issue] in MSL (https://github.com/modelica/ModelicaStandardLibrary/issues/3582)