Skip to content

adds Free component to Translational library #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2023
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
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