Using FromModelica with OML Expressions
Learn about using the FromModelica function with OML Expressions.
The FromModelica function returns an OML object of type
ModelicaExpression
, which may in some cases be used in simple
OML expressions involving basic functions and operators. In the OML expression, the
ModelicaExpression
object returned by
FromModelica is treated as an OML variable, of corresponding
type.
The OML expression can then be used for defining parameter values of Modelica components, or as it will be discussed later, in Context scripts.
Consider the parameter value presented earlier:
FromModelica('Modelica.Electrical.MultiPhase.Functions.symmetricOrientation’, {3})
- Now suppose the definition of the parameter value requires the negative of
the above quantity (this is the case in particular for the default value of
the
SineVoltage
source component of the Electrical Multiphase library). This value can be defined as follows: -FromModelica('Modelica.Electrical.MultiPhase.Functions.symmetricOrientation’, {3})
-
The minus operator is applied to the
ModelicaExpression
object returned by the FromModelica function. The reason this construction is allowed is that the negation operator is overloaded for this object, and the resulting object contains the negated Modelica expression. This process is fully transparent to the user. Users can consider the value returned by FromModelica as an OML value.The operator overloading is provided for many basic functions and operators. The following example shows a more complex expression used to define the value of a component parameter:
2*max(maxV,1/sqrt(FromModelica('Modelica.Constants.eps')))
-
Here the square root and max functions, and the inversion and multiplication operators are applied to a
ModelicaExpression
object returned by FromModelica. The expression involves also an OML variable (maxV), which must be available in the diagram workspace, i.e., defined in a Context. This is a legal expression because these functions and operators are overloaded for theModelicaExpression
object.The expression may also contain usage of Modelica functions retrieved by FromModelica, for example:
FromModelica('Modelica.Constants.k')*FromModelica('Modelica.SIunits.Conversions.from_degC',{T})/C
-
Here T and C are OML variables available in the diagram workspace.
The use of FromModelica in OML expressions is also available when the returned entity is from another component in the model. The following is an example, which also shows the use of a non-scalar variable and the application of the extraction operator: