Documentation

Electrical Component — Ideal Capacitor

The following file, ideal_capacitor.ssc, implements a component called ideal_capacitor.

The declaration section of the component contains:

• Two electrical nodes, p and n, for + and – terminals, respectively.

• One parameter, C, with a default value of 1 F, specifying the capacitance.

• Through and Across variables, current i and voltage v, to be connected to the electrical domain Through and Across variables later in the file.

Variable v is declared with high initialization priority, to ensure the initial voltage of 0 V.

The branches section establishes the relationship between the component Through variable and the component nodes (and therefore the domain Through variable). The i : p.i -> n.i statement indicates that the current through the capacitor flows from node p to node n.

The equation section starts with an assert construct, which checks that the capacitance value is greater than zero. If the block parameter is set incorrectly, the assert triggers a run-time error.

The first equation, v == p.v - n.v, establishes the relationship between the component Across variable and the component nodes (and therefore the domain Across variable). It defines the voltage across the capacitor as the difference between the node voltages.

The second equation defines the capacitor action: I = C*dV/dt, that is, output current equals capacitance multiplied by the time derivative of the input voltage.

component ideal_capacitor
% Ideal Capacitor
% Models an ideal (lossless) capacitor. The output current I is related
% to the input voltage V by I = C*dV/dt where C is the capacitance.

nodes
p = foundation.electrical.electrical; % +:top
n = foundation.electrical.electrical; % -:bottom
end

parameters
C = { 1, 'F' };   % Capacitance
end

variables
i = { 0, 'A' }; % Current
v = {value = { 0, 'V' }, priority = priority.high}; % Voltage
end

branches
i : p.i -> n.i; % Current through from node p to node n
end

equations
assert(C > 0)
v == p.v - n.v; % Voltage across between node p and node n
i == C*v.der;   % Equation defining the capacitor action
end
end