Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions examples/electrical.jl
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
using ModelingToolkit
# using ModelingToolkit: t_nounits as t
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks: Constant
using ModelingToolkitDesigner
using CairoMakie
using GLMakie

@component function PassThru2(; name)
@variables t
@mtkmodel PassThru2 begin

systems = @named begin
@components begin
p1 = Pin()
p2 = Pin()
end

eqs = [connect(p1, p2)]

return ODESystem(eqs, t, [], []; name, systems)
@equations begin
connect(p1, p2)
end
end

@component function PassThru3(; name)
@variables t
@mtkmodel PassThru3 begin

systems = @named begin
@components begin
p1 = Pin()
p2 = Pin()
p3 = Pin()
end

eqs = [connect(p1, p2, p3)]

return ODESystem(eqs, t, [], []; name, systems)
@equations begin
connect(p1, p2, p3)
end
end

@component function Circuit(; name)
@mtkmodel Circuit begin

R = 1.0
C = 1.0
V = 1.0
@variables t
@parameters begin
R = 1.0
C = 1.0
V = 1.0
end

systems = @named begin
@components begin
resistor = Resistor(R = R)
capacitor = Capacitor(C = C)
source = Voltage()
Expand All @@ -49,36 +49,32 @@ end
pt3 = PassThru3()
end

eqs = [
@equations begin
connect(resistor.p, pt2.p1)
connect(source.p, pt2.p2)
connect(source.n, pt3.p2)
connect(capacitor.n, pt3.p1)
connect(resistor.n, capacitor.p)
connect(ground.g, pt3.p3)
connect(source.V, constant.output)
]

# eqs = [connect(constant.output, source.V)
# connect(source.p, resistor.p)
# connect(resistor.n, capacitor.p)
# connect(capacitor.n, source.n, ground.g)]
end

ODESystem(eqs, t, [], []; systems, name)
# @equations begin
# connect(constant.output, source.V)
# connect(source.p, resistor.p)
# connect(resistor.n, capacitor.p)
# connect(capacitor.n, source.n, ground.g)
# end
end

@named rc = Circuit()

# using OrdinaryDiffEq
# sys = structural_simplify(rc)
# prob = ODEProblem(sys, Pair[], (0, 10.0))
# sol = solve(prob, Tsit5())

path = joinpath(@__DIR__, "design")
design = ODESystemDesign(rc, path)
GLMakie.set_theme!(Theme(; fontsize = 12))
ModelingToolkitDesigner.view(design)

# CairoMakie.set_theme!(Theme(;fontsize=12))
# fig = ModelingToolkitDesigner.view(design, false)
CairoMakie.set_theme!(Theme(;fontsize=12))
fig = ModelingToolkitDesigner.view(design, false)
save(joinpath(@__DIR__, "electrical.svg"), fig; size=(300,300))
# save(joinpath(@__DIR__, "electrical.svg"), fig; resolution=(300,300))
Loading