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 ​
TranslationalComponents.MassDamperSpringFixedTest()
Behavior ​
julia
using TranslationalComponents #hide
using ModelingToolkit #hide
@named sys = TranslationalComponents.MassDamperSpringFixedTest() #hide
full_equations(sys) #hide<< @example-block not executed in draft mode >>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": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"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}}
}
}
}
}
endFlattened 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": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"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}}
}
}
}
}
endTest Cases ​
julia
using TranslationalComponents
using DyadInterface: TransientAnalysis, rebuild_sol
using ModelingToolkit: toggle_namespacing, get_defaults, @named
using CSV, DataFrames, Plots
snapshotsdir = joinpath(dirname(dirname(pathof(TranslationalComponents))), "test", "snapshots")<< @setup-block not executed in draft mode >>Test Case case1 ​
julia
@named model_case1 = MassDamperSpringFixedTest()
model_case1 = toggle_namespacing(model_case1, false)
get_defaults(model_case1)[model_case1.body.flange_b.s] = 0
get_defaults(model_case1)[model_case1.damper.flange_b.f] = 0
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = "auto", start = 0e+0, stop = 2e+1, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>