Circuit Components
What you'll learn
- Component-based modeling with Modelica packages
- Connectors,
flowvariables, andconnectequations - Inheritance with
extendsto share common structure
So far every model has been a flat list of equations. One advantage of Modelica is that it supports component-based modeling — you build reusable parts and wire them together. This tutorial models an RC circuit from first principles using connectors, inheritance, and connect equations.
connect statements in Test wire these components edge to edge.
Key Modelica concepts
- connector Pin — defines an electrical interface with voltage (across variable) and current (
flowvariable). Kirchhoff’s current law is enforced automatically at every connection point. - extends TwoPin — Resistor, Capacitor, and VoltageSource all inherit the two-pin interface, avoiding duplicated boilerplate.
- connect(a, b) — equates across variables and sums flow variables. The topology of your circuit is declared, not hand-wired with equations.
Things to try
- Change the resistance
R = 2.5to a smaller value and watch the capacitor charge faster. - Add an inductor component modeled after the Resistor (hint:
v = L * der(i)) and wire it in series to build a full RLC circuit. - Try adding a second resistor in parallel with the capacitor — you only need a new instance and two
connectstatements. - Notice how the flat RLC model from the previous tutorial and this component model produce equivalent results — the component approach scales better to complex systems.