diff --git a/src/Mechanical/TranslationalModelica/TranslationalModelica.jl b/src/Mechanical/TranslationalModelica/TranslationalModelica.jl index 0b685e429..ee16578d1 100644 --- a/src/Mechanical/TranslationalModelica/TranslationalModelica.jl +++ b/src/Mechanical/TranslationalModelica/TranslationalModelica.jl @@ -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 diff --git a/src/Mechanical/TranslationalModelica/components.jl b/src/Mechanical/TranslationalModelica/components.jl index 9af2166cb..f0b1a532e 100644 --- a/src/Mechanical/TranslationalModelica/components.jl +++ b/src/Mechanical/TranslationalModelica/components.jl @@ -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 diff --git a/test/Mechanical/translational_modelica.jl b/test/Mechanical/translational_modelica.jl index c059527af..4ecbd127b 100644 --- a/test/Mechanical/translational_modelica.jl +++ b/test/Mechanical/translational_modelica.jl @@ -56,3 +56,31 @@ end @test -lb≈ub 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 -lb≈ub atol=1e-2 + @test -0.11 < lb < -0.1 +end