LIBRARY
Examples.Accelerate
Use of model Accelerate.
Demonstrates usage of component Sources.Accelerate by moving a mass with a predefined constant acceleration of 1 m/s².
Expected results after 1 s:
acceleration a = 1 m/s²
velocity v = 1 m/s
position s = 0.5 m (of the Accelerate source)
Usage
TranslationalComponents.Examples.Accelerate()
Behavior
julia
using TranslationalComponents #hide
using ModelingToolkit #hide
@named sys = TranslationalComponents.Examples.Accelerate() #hide
full_equations(sys) #hide<< @example-block not executed in draft mode >>Source
dyad
"""
Use of model Accelerate.
Demonstrates usage of component `Sources.Accelerate` by moving a mass with a
predefined constant acceleration of 1 m/s².
Expected results after 1 s:
- acceleration a = 1 m/s²
- velocity v = 1 m/s
- position s = 0.5 m (of the Accelerate source)
"""
example component Accelerate
constant_acc = BlockComponents.Sources.Constant(k = 1.0)
accelerate = TranslationalComponents.Sources.Accelerate()
mass = TranslationalComponents.Components.Mass(L = 1.0, m = 1.0)
fixed = TranslationalComponents.Components.Fixed()
relations
connect(constant_acc.y, accelerate.a_ref)
connect(accelerate.flange, mass.flange_a)
connect(accelerate.support, fixed.flange)
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1,
"atol": {"accelerate.v": 0.01, "accelerate.s": 0.01},
"expect": {
"final": {"accelerate.v": 1, "accelerate.s": 0.5},
"signals": ["accelerate.s", "accelerate.v"]
}
}
}
}
}
endFlattened Source
dyad
"""
Use of model Accelerate.
Demonstrates usage of component `Sources.Accelerate` by moving a mass with a
predefined constant acceleration of 1 m/s².
Expected results after 1 s:
- acceleration a = 1 m/s²
- velocity v = 1 m/s
- position s = 0.5 m (of the Accelerate source)
"""
example component Accelerate
constant_acc = BlockComponents.Sources.Constant(k = 1.0)
accelerate = TranslationalComponents.Sources.Accelerate()
mass = TranslationalComponents.Components.Mass(L = 1.0, m = 1.0)
fixed = TranslationalComponents.Components.Fixed()
relations
connect(constant_acc.y, accelerate.a_ref)
connect(accelerate.flange, mass.flange_a)
connect(accelerate.support, fixed.flange)
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 1,
"atol": {"accelerate.v": 0.01, "accelerate.s": 0.01},
"expect": {
"final": {"accelerate.v": 1, "accelerate.s": 0.5},
"signals": ["accelerate.s", "accelerate.v"]
}
}
}
}
}
endTest Cases
julia
using TranslationalComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @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 = TranslationalComponents.Examples.Accelerate()
model_case1 = toggle_namespacing(model_case1, false)
model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 1e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)<< @setup-block not executed in draft mode >>julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.accelerate.s])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.Accelerate_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.accelerate.s], width=2, label="Actual value of accelerate.s")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of accelerate.s")
end
scatter!(plt, [df_case1.t[end]], [0.5], label="Final Condition for `accelerate.s`")<< @setup-block not executed in draft mode >>julia
plt<< @example-block not executed in draft mode >>julia
df_case1 = DataFrame(:t => sol_case1[:t], :actual => sol_case1[model_case1.accelerate.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Examples.Accelerate_case1_sig1.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.accelerate.v], width=2, label="Actual value of accelerate.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of accelerate.v")
end
scatter!(plt, [df_case1.t[end]], [1], label="Final Condition for `accelerate.v`")<< @setup-block not executed in draft mode >>julia
plt<< @example-block not executed in draft mode >>Related
Examples
Experiments
Analyses
Tests