Warning: Unregistered hobby project. I just want to see if this is something anyone else has been thinking about / wants / has input on.
Circuits.jl
An electrical circuit analysis tool in Julia. I’ll just show the examples from my (currently-only-manually-compiling) docs to show it off:
Examples
c = @circuit a:(0,0) --> Inductor(9e-3) --> b:(0,1) --> Resistor(11) --> c:(1,1) --> Capacitor(1.455e-6) --> d:(1,0)
latexstandalone(c, "example1.png")
# One day this will be `p = Network(c, :a, :d)`, but that's not implemented yet.
# `A --> B --> C` currently doesn't return a single `Series`. That's a bug.
p = Series(Inductor(9e-3), Resistor(11), Capacitor(1.455e-6)) # H, Ω, F
s = range(0, 20000, length=1000) # Hz
plot(s, map(ω->abs(5*voltageDivision(p, im*ω)[3]), s); # `[3]` here means "voltage over the capacitor"
xlabel="\$\\nu / \\mathrm{Hz}\$", ylabel="\$U / \\mathrm{V}\$",
)
vline!([1/sqrt(9e-3*1.455e-6)]) # theoretical resonance frequency of LC circuit
savefig("example2.png")
Features
- Displays circuits using circuitikz
- Simplifies circuits by merging components (
Resistor(a) --> Resistor(b) == Resistor(a+b)
,Inductor(a) // Inductor(b) == Inductor(inv(inv(a)+inv(b)))
etc) - Interfaces well with Unitful.jl, and hopefully some symbolic packages (there are so many choices, I haven’t really had the time to choose – ideally you get one that can perform inverse laplace transforms)
- Performs voltage and current division
Loose ends
- Some uncertainty as to the julia version (I think this only runs on 1.6 because it uses infix
-->
, if someone has a good idea for an alternative infix operator for “series”, let me know) - Should probably use LightGraphs.jl or something to store circuits. I tried writing a version, but I really don’t know the theory or the package well enough. Especially for operations like unfurling a
Circuit
between two nodes as aNetwork
, some kind of graph crawler will probably be necessary - Voltage and current sources don’t quite work right yet
- Doesn’t yet know how to set up proper node analysis matrices (hinges on the previous two points)
- Some bugs in things like merging
Series
s containingSeries
s andParallel
s containingParallel
s - The nomenclature is probably stupid, I’m not an electrical engineer but a lowly physicist
Conclusion
I’m happy for any ideas or discouraging words!