Skip to content
Get started

Electrical components

Standard library · Install Eqiora

The equations are in Electrical.Basic / basic.eqi. Its Pin connector carries voltage (V) as the across quantity and current into the component (A) as the through quantity, so connections conserve current. Dimensions are written in SI base units.

Declaration Required parameter Ports and equations
IdealVoltageSource voltage, V positive, negative: fixes their voltage difference and conserves current
Resistor resistance, ohm positive, negative: voltage difference equals resistance times positive-port current; conserves current
Ground None terminal: fixes its across voltage to zero, without prescribing its current

All three are ideal and time-independent.

electrical.eqi — complete model
import Eqiora.Electrical.Basic.basic as electrical;
/// Ideal 12 V divider with an explicit zero-voltage reference.
/// Ohm and Kirchhoff give 4 mA through both resistors and an 8 V midpoint.
model VoltageDivider() {
instance source: electrical.IdealVoltageSource(voltage = 12[V]);
instance upper: electrical.Resistor(resistance = 1[kOhm]);
instance lower: electrical.Resistor(resistance = 2[kOhm]);
instance ground: electrical.Ground();
connect source.positive, upper.positive;
connect upper.negative, lower.positive;
connect lower.negative, source.negative, ground.terminal;
observable current: A = upper.positive.current;
observable midpoint: V = lower.positive.voltage;
observable upper_power: W = (upper.positive.voltage - upper.negative.voltage) * upper.positive.current;
observable lower_power: W = (lower.positive.voltage - lower.negative.voltage) * lower.positive.current;
observable source_power: W = (source.positive.voltage - source.negative.voltage) * source.positive.current;
}

The supply fixes 12 V across two series resistors, 1 kΩ and 2 kΩ. Ohm’s law and current conservation give 12 / (1000 + 2000) = 0.004 A; the midpoint is 0.004 * 2000 = 8 V relative to ground. The observable declarations name quantities to read after solving; they add no equations.

After installing Eqiora, save the source above as electrical.eqi and run:

python
from pathlib import Path
import eqiora
project = Path("divider")
(project / "src").mkdir(parents=True, exist_ok=True)
(project / "src/main.eqi").write_text(Path("electrical.eqi").read_text())
(project / "eqiora.toml").write_text(
'[package]\nname = "org.example.Divider"\nversion = "0.1.0"\nentry = "main"\n'
)
store = Path("package-store")
store.mkdir(exist_ok=True)
resolution = eqiora.add_bundled_dependency(
project, store, "Eqiora.Electrical.Basic", version="0.1.0"
)
model = eqiora.compile_package(store, resolution, entry="VoltageDivider")
plan = eqiora.resolve(model, solve=eqiora.solve.Linear(
algorithm=eqiora.solve.LinearSolver.SparseLu,
preconditioner=eqiora.solve.Preconditioner.Identity,
reduction=eqiora.solve.Reduction.Fast,
provider=eqiora.solve.SolverProvider.faer(),
relative_tolerance=1e-12, absolute_tolerance=1e-14, maximum_iterations=100,
))
result = eqiora.run(plan, state=eqiora.State.initial(plan))
print(result.observe(model.observable("current")).value) # 0.004 A
print(result.observe(model.observable("midpoint")).value) # 8 V

The current is 0.004 A and the midpoint voltage is 8 V. Read upper_power, lower_power, and source_power in the same way: the resistors dissipate 0.016 W and 0.032 W, while the source absorbs −0.048 W. Their sum is zero.

Ground fixes the otherwise arbitrary voltage offset; without it the circuit has no potential reference and cannot be solved. Ground does not force any current to zero. Because the model is steady and algebraic, it needs a linear solver but no time settings.

For offline reuse, vendor the project dependencies. For a step-by-step derivation, read the resistor divider and conserving networks.

Model source · Complete Python runner · Continuum components