Skip to content

Commit 50737f3

Browse files
authored
add SpringDamper component (#162)
* add SpringDamper component * format
1 parent 87b07ad commit 50737f3

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

docs/src/API/mechanical.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Fixed
3535
Inertia
3636
Spring
3737
Damper
38+
SpringDamper
3839
IdealGear
3940
RotationalFriction
4041
```

src/Mechanical/Rotational/Rotational.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ D = Differential(t)
1212
export Flange, Support
1313
include("utils.jl")
1414

15-
export Fixed, Inertia, Spring, Damper, IdealGear, RotationalFriction
15+
export Fixed, Inertia, Spring, Damper, SpringDamper, IdealGear, RotationalFriction
1616
include("components.jl")
1717

1818
export Torque, ConstantTorque, Speed

src/Mechanical/Rotational/components.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ Linear 1D rotational damper
119119
extend(ODESystem(eqs, t, [], pars; name = name), partial_comp)
120120
end
121121

122+
"""
123+
SpringDamper(;name, d)
124+
125+
Linear 1D rotational spring and damper
126+
127+
# States:
128+
129+
- `phi_rel(t)`: [`rad`] Relative rotation angle (= flange_b.phi - flange_a.phi)
130+
- `w_rel(t)`: [`rad/s`] Relative angular velocity (= D(phi_rel))
131+
- `a_rel(t)`: [`rad/s²`] Relative angular acceleration (= D(w_rel))
132+
- `tau(t)`: [`N.m`] Torque between flanges (= flange_b.tau)
133+
134+
# Connectors:
135+
136+
- `flange_a` [Flange](@ref)
137+
- `flange_b` [Flange](@ref)
138+
139+
# Parameters:
140+
141+
- `d`: [`N.m.s/rad`] Damping constant
142+
- `c`: [`N.m/rad`] Spring constant
143+
"""
144+
@component function SpringDamper(; name, c, d, phi_rel0 = 0.0)
145+
@named partial_comp = PartialCompliantWithRelativeStates()
146+
@unpack phi_rel, w_rel, tau = partial_comp
147+
@variables tau_c(t) [description = "Spring torque"]
148+
@variables tau_d(t) [description = "Damper torque"]
149+
@parameters d=d [description = "Damping constant"]
150+
@parameters c=c [description = "Spring constant"]
151+
@parameters phi_rel0=phi_rel0 [description = "Unstretched spring angle"]
152+
eqs = [tau_c ~ c * (phi_rel - phi_rel0)
153+
tau_d ~ d * w_rel
154+
tau ~ tau_c + tau_d]
155+
extend(ODESystem(eqs, t; name = name), partial_comp)
156+
end
157+
122158
"""
123159
IdealGear(;name, ratio, use_support=false)
124160

test/Mechanical/rotational.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ D = Differential(t)
2424
sys = structural_simplify(model)
2525

2626
prob = ODEProblem(sys, Pair[], (0, 10.0))
27-
sol = solve(prob, Rodas4())
28-
@test SciMLBase.successful_retcode(sol)
27+
sol1 = solve(prob, Rodas4())
28+
@test SciMLBase.successful_retcode(sol1)
2929

3030
prob = ODAEProblem(sys, Pair[], (0, 10.0))
3131
sol = solve(prob, Rodas4())
@@ -37,6 +37,21 @@ D = Differential(t)
3737
@test all(sol[inertia1.w] .== 0)
3838
@test sol[inertia2.w][end]0 atol=1e-3 # all energy has dissipated
3939

40+
@named springdamper = SpringDamper(; c = 1e4, d = 10)
41+
connections = [connect(fixed.flange, inertia1.flange_b)
42+
connect(inertia1.flange_b, springdamper.flange_a)
43+
connect(springdamper.flange_b, inertia2.flange_a)]
44+
45+
@named model = ODESystem(connections, t,
46+
systems = [fixed, inertia1, inertia2, springdamper])
47+
sys = structural_simplify(model)
48+
49+
prob = ODEProblem(sys, Pair[], (0, 10.0))
50+
sol2 = solve(prob, Rodas4())
51+
@test SciMLBase.successful_retcode(sol)
52+
53+
@test sol2(0:1:10, idxs = inertia2.w).usol1(0:1:10, idxs = inertia2.w).u atol=1e-3
54+
4055
# Plots.plot(sol; vars=[inertia1.w, inertia2.w])
4156
end
4257

0 commit comments

Comments
 (0)