Limitations and Usages
Limitations and usages of the FromModelica function.
In general, the OML expression defining the value of a parameter is calculated at model evaluation time by OML. But when the expression includes a value retrieved by the FromModelica function, this expression is translated into Modelica syntax, and is evaluated later by the Modelica compiler behind the scenes. For this reason, these expressions have limitations. The translation of an expression is possible only if it can be expressed similarly in both OML and Modelica.
Consider for example the valid OML expression FromModelicawhere A and B are matrices. This syntax is not supported in Modelica and the implementation of such an expression requires the use of an intermediary variable. So, if A and/or B are obtained from FromModelica, the above expression cannot be used to define a component parameter.
There are also cases where an OML expression has no OML counterpart. Consider for example the valid Modelica expression:
if x>0 then 2 else
3
This construction does not have an equivalent in OML. But the OML function ifexpr can be used to replace it. In particular the above Modelica expression can be obtained from the following OML expression:
ifexpr(x>0, 2, 3)
The use of FromModelica should be limited to situations where the retrieval of values from the Modelica environment is absolutely necessary. In most examples presented in this document, chosen for their simplicity, the constants and functions retrieved from Modelica can be defined directly in OML. The FromModelica function is required mainly when the return object does not have an OML counterpart.
The usage of FromModelica function to access parameters of other components in the model, especially when the other component is a record, can also be avoided by defining an equivalent record in the Context of the diagram using an OML structure.
Similarly, the value of the parameters of a block depending on the values of parameters of other blocks in the model is not in line with the “usual” behavior of Twin Activate. The dependency between parameters of different blocks in Twin Activate are realized through the use of Context variables and the scoping rules. For Modelica components however, this Modelica feature, is preserved using FromModelica, but should be avoided when possible.
The use of FromModelica allows other Modelica constructions, which are even less Twin Activate-like. In Modelica, not only can a component parameter depend on other components’ parameters, but its output can also depend on other block parameters and even outputs or inputs. This can be seen in the following example, where the expression of the ModelicaRealExpression
block depends on the output of another
block (Ramp
in this case). The FromModelica function
is used to retrieve, not a parameter of the Ramp
block, but its
output.