Skip to content
MassDamperSpringFixedTest.md

MassDamperSpringFixedTest

A one-dimensional translational mechanical system composed of a mass, spring, and damper connected to a fixed point.

This component represents a classic damped harmonic oscillator. A mass (body) is attached to one end of a parallel combination of a linear spring (spring) and a viscous damper (damper). The other end of this spring-damper combination is connected to a fixed reference point (ground). The L=0 parameter for the Mass subcomponent, and the initial condition body.flange_b.s = 0 for the mass's second flange (often specified in simulation setup or test metadata), imply that body.flange_a.s directly represents the absolute displacement x of the mass.

Usage

MassDamperSpringFixedTest()

Behavior

[connect(spring+flangea,body+flangea,damper+flangea)connect(spring+flangeb,damper+flangeb,ground+flange)damper.s_rel(t)=damper.flange_b.s(t)damper.flange_a.s(t)damper.v_rel(t)=ddamper.s_rel(t)dtdamper.flange_b.f(t)=damper.f(t)damper.flange_a.f(t)=damper.f(t)damper.f(t)=damper.ddamper.v_rel(t)damper.lossPower(t)=damper.f(t)damper.v_rel(t)spring.s_rel(t)=spring.flange_a.s(t)+spring.flange_b.s(t)spring.flange_b.f(t)=spring.f(t)spring.flange_a.f(t)=spring.f(t)spring.f(t)=spring.c(spring.s_rel0+spring.s_rel(t))body.flange_a.s(t)=12body.L+body.s(t)body.flange_b.s(t)=12body.L+body.s(t)body.v(t)=dbody.s(t)dtbody.a(t)=dbody.v(t)dt(body.a(t)+body.gsin(body.theta))body.m=body.flange_b.f(t)+body.flange_a.f(t)ground.flange.s(t)=ground.s0]

Source

dyad
# A one-dimensional translational mechanical system composed of a mass, spring, and damper connected to a fixed point.
#
# This component represents a classic damped harmonic oscillator. A mass (`body`) is attached to
# one end of a parallel combination of a linear spring (`spring`) and a viscous damper (`damper`).
# The other end of this spring-damper combination is connected to a fixed reference point (`ground`).
# The `L=0` parameter for the `Mass` subcomponent, and the initial condition `body.flange_b.s = 0`
# for the mass's second flange (often specified in simulation setup or test metadata), imply that
# `body.flange_a.s` directly represents the absolute displacement `x` of the mass.
test component MassDamperSpringFixedTest
  # The viscous damper subcomponent.
  damper = Damper(d=1)
  # The linear spring subcomponent.
  spring = Spring(c=1)
  # The translational mass subcomponent.
  body = Mass(m=1, L=0)
  # The fixed mechanical ground subcomponent.
  ground = Fixed()
relations
  connect(spring.flange_a, body.flange_a, damper.flange_a)
  connect(spring.flange_b, damper.flange_b, ground.flange)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 20,
        "initial": {"body.flange_b.s": 0, "damper.flange_b.f": 0},
        "atol": {"body.v": 0.001},
        "expect": {"final": {"body.v": 0}}
      }
    }
  }
}
end
Flattened Source
dyad
# A one-dimensional translational mechanical system composed of a mass, spring, and damper connected to a fixed point.
#
# This component represents a classic damped harmonic oscillator. A mass (`body`) is attached to
# one end of a parallel combination of a linear spring (`spring`) and a viscous damper (`damper`).
# The other end of this spring-damper combination is connected to a fixed reference point (`ground`).
# The `L=0` parameter for the `Mass` subcomponent, and the initial condition `body.flange_b.s = 0`
# for the mass's second flange (often specified in simulation setup or test metadata), imply that
# `body.flange_a.s` directly represents the absolute displacement `x` of the mass.
test component MassDamperSpringFixedTest
  # The viscous damper subcomponent.
  damper = Damper(d=1)
  # The linear spring subcomponent.
  spring = Spring(c=1)
  # The translational mass subcomponent.
  body = Mass(m=1, L=0)
  # The fixed mechanical ground subcomponent.
  ground = Fixed()
relations
  connect(spring.flange_a, body.flange_a, damper.flange_a)
  connect(spring.flange_b, damper.flange_b, ground.flange)
metadata {
  "Dyad": {
    "tests": {
      "case1": {
        "stop": 20,
        "initial": {"body.flange_b.s": 0, "damper.flange_b.f": 0},
        "atol": {"body.v": 0.001},
        "expect": {"final": {"body.v": 0}}
      }
    }
  }
}
end


Test Cases

This is setup code, that must be run before each test case.

julia
using TranslationalComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(TranslationalComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/TranslationalComponents/khJb7/test/snapshots"

Test Case case1

julia
@mtkbuild model_case1 = MassDamperSpringFixedTest()
u0_case1 = [model_case1.body.flange_b.s => 0, model_case1.damper.flange_b.f => 0]
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 20))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 8-element Vector{Float64}:
  0.0
  9.999999999999999e-5
  0.0010999999999999998
  0.011099999999999997
  0.11109999999999996
  1.1110999999999995
 11.111099999999993
 20.0
u: 8-element Vector{Vector{Float64}}:
 [0.0, -0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]
 [0.0, 0.0]