Skip to content

Commit 06a710f

Browse files
committed
Updated mechanical example working
1 parent b1fc2d8 commit 06a710f

File tree

4 files changed

+389
-26
lines changed

4 files changed

+389
-26
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ FilterHelpers = "d8f44d74-4a63-4059-add9-16c5740a0809"
1010
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
1111
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
1212
ModelingToolkitStandardLibrary = "16a59e39-deab-5bd0-87e4-056b12336739"
13+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
1314
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1415

1516
[compat]
@@ -19,6 +20,7 @@ FilterHelpers = "0.2"
1920
GLMakie = "0.9, 0.10"
2021
ModelingToolkit = "8,9"
2122
ModelingToolkitStandardLibrary = "2"
23+
Revise = "3.7.2"
2224
TOML = "1"
2325
julia = "1.6"
2426

examples/hydraulic.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC
55
import ModelingToolkitStandardLibrary.Blocks as B
66

77

8-
@parameters t
9-
108
@component function System(; name)
119

1210
pars = []
@@ -15,9 +13,9 @@ import ModelingToolkitStandardLibrary.Blocks as B
1513
fluid = IC.HydraulicFluid(; density = 876, bulk_modulus = 1.2e9, viscosity = 0.034)
1614

1715
stp = B.Step(; height = 10e5, start_time = 0.005)
18-
src = IC.InputSource(; p_int = 0)
19-
vol = IC.FixedVolume(; p_int = 0, vol = 10.0)
20-
res = IC.Tube(5; p_int = 0, area = 0.01, length = 500.0)
16+
src = IC.Pressure()
17+
vol = IC.FixedVolume(; vol = 10.0)
18+
res = IC.Tube(5; area = 0.01, length = 500.0)
2119
end
2220

2321
eqs = [

examples/mechanical.jl

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,38 @@ using ModelingToolkitDesigner
44
using ModelingToolkitStandardLibrary.Blocks
55
import ModelingToolkitStandardLibrary.Mechanical.Translational as TV
66

7-
@parameters t
8-
D = Differential(t)
7+
@mtkmodel PassThru3 begin
98

10-
@component function PassThru3(; name)
11-
@variables t
12-
13-
systems = @named begin
9+
@components begin
1410
p1 = TV.MechanicalPort()
1511
p2 = TV.MechanicalPort()
1612
p3 = TV.MechanicalPort()
1713
end
1814

19-
eqs = [connect(p1, p2, p3)]
20-
21-
return ODESystem(eqs, t, [], []; name, systems)
15+
@equations begin
16+
connect(p1, p2, p3)
17+
end
2218
end
2319

24-
@component function MassSpringDamper(; name)
25-
systems = @named begin
26-
dv = TV.Damper(d = 1, v_a_0 = 1)
27-
sv = TV.Spring(k = 1, v_a_0 = 1, delta_s_0 = 1)
28-
bv = TV.Mass(m = 1, v_0 = 1)
20+
@mtkmodel MassSpringDamper begin
21+
@components begin
22+
dv = TV.Damper(d = 1)
23+
sv = TV.Spring(k = 1)
24+
bv = TV.Mass(m = 1)
2925
gv = TV.Fixed()
3026

3127
pt1 = PassThru3()
3228
pt2 = PassThru3()
3329
end
3430

35-
eqs = [
31+
@equations begin
3632
connect(bv.flange, pt2.p2)
3733
connect(sv.flange_a, pt2.p1)
3834
connect(dv.flange_a, pt2.p3)
3935
connect(dv.flange_b, pt1.p3)
4036
connect(sv.flange_b, pt1.p1)
4137
connect(gv.flange, pt1.p2)
42-
]
43-
44-
return ODESystem(eqs, t, [], []; name, systems)
38+
end
4539
end
4640

4741
@named msd = MassSpringDamper()
@@ -50,7 +44,8 @@ path = joinpath(@__DIR__, "design")
5044
design = ODESystemDesign(msd, path)
5145
ModelingToolkitDesigner.view(design)
5246

53-
# using CairoMakie
54-
# CairoMakie.set_theme!(Theme(;fontsize=12))
55-
# fig = ModelingToolkitDesigner.view(design, false)
47+
using CairoMakie
48+
CairoMakie.set_theme!(Theme(;fontsize=12))
49+
fig = ModelingToolkitDesigner.view(design, false)
50+
save(joinpath(@__DIR__, "mechanical.svg"), fig; size=(400,200))
5651
# save(joinpath(@__DIR__, "mechanical.svg"), fig; resolution=(400,200))

0 commit comments

Comments
 (0)