Skip to content

Commit

Permalink
add SpringDamper component
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Sep 11, 2024
1 parent cb95768 commit 8e657d7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using ...Blocks: RealInput, RealOutput
export Flange
include("utils.jl")

export Fixed, Mass, Spring, Damper
export Fixed, Mass, Spring, Damper, SpringDamper
include("components.jl")

export Force
Expand Down
34 changes: 34 additions & 0 deletions src/Mechanical/TranslationalModelica/components.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,37 @@ Linear 1D translational damper
lossPower ~ f * v_rel
end
end

"""
SpringDamper(; name, c = 0.0, d = 0.0, s_rel0 = 0.0)
Linear 1D translational spring and damper in parallel
# Parameters:
- `c`: [N/m] Spring constant
- `d`: [N.s/m] Damping constant
- `s_rel0`: Unstretched spring length
# Connectors:
- `flange_a: 1-dim. translational flange on one side of spring`
- `flange_b: 1-dim. translational flange on opposite side of spring`
# Variables:
- `lossPower`: [W] Power dissipated by the damper
- `f`: [N] Total force
"""
@mtkmodel SpringDamper begin
@extend flange_a, flange_b, s_rel, v_rel, f = pc = PartialCompliantWithRelativeStates()
@parameters begin
d = 0.0, [description = "Damping constant [Ns/m]"]
c = 0.0, [description = "Spring constant [N/m]"]
s_rel0 = 0.0, [description = "Unstretched spring length [m]"]
end
@variables begin
lossPower(t), [description = "Power dissipated by the damper [W]"]
end
@equations begin
f ~ c * (s_rel - s_rel0) + d * v_rel
lossPower ~ d * v_rel^2
end
end
28 changes: 28 additions & 0 deletions test/Mechanical/translational_modelica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,31 @@ end
@test -lbub atol=1e-2
@test -0.11 < lb < -0.1
end

@testset "driven SpringDamper mass" begin
@mtkmodel DrivenSpringDamperMass2 begin
@components begin
springdamper = TranslationalModelica.SpringDamper(; d = 1, c = 1, s_rel0 = 1)
mass = Mass(; m = 1, v = 1, s = 0)
fixed = Fixed(; s0 = 1)
force = Force()
source = Sine(frequency = 3, amplitude = 2)
end

@equations begin
connect(force.f, source.output)
connect(force.flange, mass.flange_a)
connect(springdamper.flange_a, mass.flange_b)
connect(springdamper.flange_b, fixed.flange)
end
end

@mtkbuild sys = DrivenSpringDamperMass2()

prob = ODEProblem(sys, [], (0, 20.0), [])
sol = solve(prob, Rodas4())

lb, ub = extrema(sol(15:0.05:20, idxs = sys.mass.v).u)
@test -lbub atol=1e-2
@test -0.11 < lb < -0.1
end

0 comments on commit 8e657d7

Please sign in to comment.