Skip to content

Commit 197434e

Browse files
authored
add SpringDamper component (#327)
* add SpringDamper component * fix Fixed * format
1 parent cb95768 commit 197434e

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

src/Mechanical/TranslationalModelica/TranslationalModelica.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using ...Blocks: RealInput, RealOutput
1010
export Flange
1111
include("utils.jl")
1212

13-
export Fixed, Mass, Spring, Damper
13+
export Fixed, Mass, Spring, Damper, SpringDamper
1414
include("components.jl")
1515

1616
export Force

src/Mechanical/TranslationalModelica/components.jl

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Flange fixed in housing at a given position.
1313
"""
1414
@mtkmodel Fixed begin
1515
@parameters begin
16-
s0
16+
s0 = 0
1717
end
1818

1919
@components begin
20-
flange = Flange(; s = 0.0)
20+
flange = Flange()
2121
end
2222

2323
@equations begin
@@ -113,3 +113,37 @@ Linear 1D translational damper
113113
lossPower ~ f * v_rel
114114
end
115115
end
116+
117+
"""
118+
SpringDamper(; name, c = 0.0, d = 0.0, s_rel0 = 0.0)
119+
120+
Linear 1D translational spring and damper in parallel
121+
122+
# Parameters:
123+
- `c`: [N/m] Spring constant
124+
- `d`: [N.s/m] Damping constant
125+
- `s_rel0`: Unstretched spring length
126+
127+
# Connectors:
128+
- `flange_a: 1-dim. translational flange on one side of spring`
129+
- `flange_b: 1-dim. translational flange on opposite side of spring`
130+
131+
# Variables:
132+
- `lossPower`: [W] Power dissipated by the damper
133+
- `f`: [N] Total force
134+
"""
135+
@mtkmodel SpringDamper begin
136+
@extend flange_a, flange_b, s_rel, v_rel, f = pc = PartialCompliantWithRelativeStates()
137+
@parameters begin
138+
d = 0.0, [description = "Damping constant [Ns/m]"]
139+
c = 0.0, [description = "Spring constant [N/m]"]
140+
s_rel0 = 0.0, [description = "Unstretched spring length [m]"]
141+
end
142+
@variables begin
143+
lossPower(t), [description = "Power dissipated by the damper [W]"]
144+
end
145+
@equations begin
146+
f ~ c * (s_rel - s_rel0) + d * v_rel
147+
lossPower ~ d * v_rel^2
148+
end
149+
end

test/Mechanical/translational_modelica.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ using ModelingToolkit: t_nounits as t, D_nounits as D
33

44
using ModelingToolkitStandardLibrary.Blocks: Sine
55
using ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica: Damper, Spring, Mass,
6-
Fixed, Force
6+
Fixed, Force,
7+
SpringDamper
78

89
@testset "spring damper mass fixed" begin
910
@mtkmodel SpringDamperMassFixed begin
@@ -56,3 +57,31 @@ end
5657
@test -lbub atol=1e-2
5758
@test -0.11 < lb < -0.1
5859
end
60+
61+
@testset "driven SpringDamper mass" begin
62+
@mtkmodel DrivenSpringDamperMass2 begin
63+
@components begin
64+
springdamper = SpringDamper(; d = 1, c = 1, s_rel0 = 1)
65+
mass = Mass(; m = 1, v = 1, s = 0)
66+
fixed = Fixed(; s0 = 1)
67+
force = Force()
68+
source = Sine(frequency = 3, amplitude = 2)
69+
end
70+
71+
@equations begin
72+
connect(force.f, source.output)
73+
connect(force.flange, mass.flange_a)
74+
connect(springdamper.flange_a, mass.flange_b)
75+
connect(springdamper.flange_b, fixed.flange)
76+
end
77+
end
78+
79+
@mtkbuild sys = DrivenSpringDamperMass2()
80+
81+
prob = ODEProblem(sys, [], (0, 20.0), [])
82+
sol = solve(prob, Rodas4())
83+
84+
lb, ub = extrema(sol(15:0.05:20, idxs = sys.mass.v).u)
85+
@test -lbub atol=1e-2
86+
@test -0.11 < lb < -0.1
87+
end

0 commit comments

Comments
 (0)