Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Modelica
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Basic model components=== A basic model component is defined by a '''model''' and contains equations that describe the relationship between the connector variables in a declarative form (i.e., without specifying the calculation order): <syntaxhighlight lang=modelica> model Capacitor parameter Capacitance C; Voltage u "Voltage drop between pin_p and pin_n"; Pin pin_p, pin_n; equation 0 = pin_p.i + pin_n.i; u = pin_p.v - pin_n.v; C * der(u) = pin_p.i; end Capacitor; </syntaxhighlight> The goal is that a connected set of model components leads to a set of differential, algebraic and discrete equations where the number of unknowns and the number of equations is identical. In Modelica, this is achieved by requiring so called '''balanced models'''. The full rules for defining balanced models are rather complex, and can be read from <ref name="3.5spec"/> in section 4.7. However, for most cases, a simple rule can be issued, that counts variables and equations the same way as most simulation tools do: <pre> A model is balanced when the number of its equations equals the number of its variables. </pre> given that variables and equations must be counted according to the following rule: <pre> ->Number of model equations = Number of equations defined in the model + number of flow variables in the outside connectors ->Number of model variables = Number of variables defined in the model (including the variables in the physical connectors) </pre> ''Note that standard input connectors (such as RealInput or IntegerInput) do not contribute to the count of variables since no new variables are defined inside them.'' The reason for this rule can be understood thinking of the capacitor defined above. Its pins contain a flow variable, i.e. a current, each. When we check it, it is connected to nothing. This corresponds to set an equation pin.i=0 for each pin. That's why we must add an equation for each flow variable. Obviously the example can be extended to other cases, in which other kinds of flow variables are involved (e.g. forces, torques, etc.). When our capacitor is connected to another (balanced) model through one of its pins, a connection equation will be generated that will substitute the two i=0 equations of the pins being connected. Since the connection equation corresponds to two scalar equations, the connection operation will leave the balanced larger model (constituted by our Capacitor and the model it is connected to). The Capacitor model above is '''balanced''', since <pre> number of equations = 3+2=5 (flow variables: pin_p.i, pin_n.i, u) number of variables = 5 (u, pin_p.u, pin_p.i, pin_n.u, pi_n.i) </pre> Verification using OpenModelica<ref name="OpenModelica project"/> of this model gives, in fact <pre> Class Capacitor has 5 equation(s) and 5 variable(s). 3 of these are trivial equation(s). </pre> Another example, containing both input connectors and physical connectors is the following component from Modelica Standard Library: <syntaxhighlight lang=modelica> model SignalVoltage "Generic voltage source using the input signal as source voltage" Interfaces.PositivePin p; Interfaces.NegativePin n; Modelica.Blocks.Interfaces.RealInput v(unit="V") "Voltage between pin p and n (= p.v - n.v) as input signal"; SI.Current i "Current flowing from pin p to pin n"; equation v = p.v - n.v; 0 = p.i + n.i; i = p.i; end SignalVoltage; </syntaxhighlight> The component SignalVoltage is balanced since <pre> number of equations = 3+2=5 (flow variables: pin_p.i, pin_n.i, u) number of variables = 5 (i, pin_p.u, pin_p.i, pin_n.u, pi_n.i) </pre> Again, checking with OpenModelica<ref name="OpenModelica project"/> gives <pre> Class Modelica.Electrical.Analog.Sources.SignalVoltage has 5 equation(s) and 5 variable(s). 4 of these are trivial equation(s). </pre>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)