Skip to content

Commit

Permalink
adds Free component
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Carman authored and staticfloat committed Oct 11, 2023
1 parent c1ee7fd commit de40dfb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Mechanical/Translational/components.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
"""
Free(; name)
Use to close a system that has un-connected `MechanicalPort`'s.
# Connectors:
- `flange`: 1-dim. translational flange
"""
@component function Free(; name)
@named flange = MechanicalPort()
vars = []
eqs = [
flange.f ~ 0,
]
return compose(ODESystem(eqs, t, vars, []; name, defaults = [flange.v => 0]),
flange)
end

"""
Fixed(;name)
Expand Down
21 changes: 21 additions & 0 deletions test/Mechanical/translational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ import ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition as TP
@parameters t
D = Differential(t)

@testset "Free" begin
function System(; name)
systems = @named begin
mass = TV.Mass(; m = 100, g = -10)
free = TV.Free()
end

eqs = [connect(mass.flange, free.flange)]

ODESystem(eqs, t, [], []; name, systems)
end

@named system = System()
s = complete(system)
sys = structural_simplify(system)
prob = ODEProblem(sys, [], (0, 0.1))
sol = solve(prob, Rosenbrock23())

@test sol[s.mass.flange.v][end]-0.1 * 10 atol=1e-3
end

@testset "spring damper mass fixed" begin
@named dv = TV.Damper(d = 1, v_a_0 = 1)
@named dp = TP.Damper(d = 1, v_a_0 = 1, s_a_0 = 3, s_b_0 = 1)
Expand Down

0 comments on commit de40dfb

Please sign in to comment.