LIBRARY
Sources.Tests.TestBraking
Test of braking force models.
Tests five different braking force sources applied to individual masses, each starting at v=100 m/s from s=0. Replicates the structure of ModelicaTest.Translational.TestBraking (EddyCurrentForce omitted).
mass1 + LinearSpeedDependentForce (f_nominal=-100, v_nominal=100)
mass2 + QuadraticSpeedDependentForce (f_nominal=-100, v_nominal=100)
mass3 + ConstantForce (f_constant=-100)
mass4 + SignForce (f_nominal=-100, v0=1)
mass5 + InverseSpeedDependentForce (f_nominal=-100, v_nominal=100, v0=1)
Usage
TranslationalComponents.Sources.Tests.TestBraking()
Behavior
julia
using TranslationalComponents #hide
using ModelingToolkit #hide
@named sys = TranslationalComponents.Sources.Tests.TestBraking() #hide
full_equations(sys) #hide<< @example-block not executed in draft mode >>Source
dyad
"""
Test of braking force models.
Tests five different braking force sources applied to individual masses,
each starting at v=100 m/s from s=0. Replicates the structure of
ModelicaTest.Translational.TestBraking (EddyCurrentForce omitted).
- mass1 + LinearSpeedDependentForce (f_nominal=-100, v_nominal=100)
- mass2 + QuadraticSpeedDependentForce (f_nominal=-100, v_nominal=100)
- mass3 + ConstantForce (f_constant=-100)
- mass4 + SignForce (f_nominal=-100, v0=1)
- mass5 + InverseSpeedDependentForce (f_nominal=-100, v_nominal=100, v0=1)
"""
test component TestBraking
"Mass braked by linear speed-dependent force"
mass1 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 680, "x2": 260, "y2": 780, "rot": 0}
},
"tags": []
}
}
linearSpeedDependentForce = TranslationalComponents.Sources.LinearSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 680, "x2": 400, "y2": 780, "rot": 0}
},
"tags": []
}
}
"Mass braked by quadratic speed-dependent force"
mass2 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 150, "y1": 450, "x2": 250, "y2": 550, "rot": 0}
},
"tags": []
}
}
quadraticSpeedDependentForce = TranslationalComponents.Sources.QuadraticSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 450, "x2": 400, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Mass braked by constant force"
mass3 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 880, "x2": 270, "y2": 980, "rot": 0}
},
"tags": []
}
}
constantForce = TranslationalComponents.Sources.ConstantForce(f_constant = -100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 880, "x2": 400, "y2": 980, "rot": 0}
},
"tags": []
}
}
"Mass braked by sign force"
mass4 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 140, "y1": 230, "x2": 240, "y2": 330, "rot": 0}
},
"tags": []
}
}
signForce = TranslationalComponents.Sources.SignForce(f_nominal = -100.0, v0 = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 510, "y1": 230, "x2": 410, "y2": 330, "rot": 0}
},
"tags": []
}
}
"Mass braked by inverse speed-dependent force"
mass5 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 140, "y1": 20, "x2": 240, "y2": 120, "rot": 0}
},
"tags": []
}
}
inverseSpeedDependentForce = TranslationalComponents.Sources.InverseSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0, v0 = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 20, "x2": 400, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Fixed ground for all force supports"
ground = TranslationalComponents.Components.Fixed() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 890, "y1": 450, "x2": 990, "y2": 550, "rot": 270}
},
"tags": []
}
}
relations
initial mass1.s = 0
initial mass1.v = 100
initial mass2.s = 0
initial mass2.v = 100
initial mass3.s = 0
initial mass3.v = 100
initial mass4.s = 0
initial mass4.v = 100
initial mass5.s = 0
initial mass5.v = 100
connect(mass1.flange_b, linearSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass2.flange_b, quadraticSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass3.flange_b, constantForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass4.flange_b, signForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass5.flange_b, inverseSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(inverseSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 190}, {"x": 720, "y": 190}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(signForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 460, "y": 370}, {"x": 720, "y": 370}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(quadraticSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 620}, {"x": 720, "y": 620}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(linearSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 840}, {"x": 720, "y": 840}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(constantForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 1050}, {"x": 720, "y": 1050}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 2,
"atol": {
"mass1.v": 0.01,
"mass2.v": 0.01,
"mass3.v": 0.01,
"mass4.v": 0.01,
"mass5.v": 0.1
},
"expect": {
"final": {
"mass1.v": 13.53353,
"mass2.v": 33.333344,
"mass3.v": -100,
"mass4.v": 0,
"mass5.v": -173.19913
},
"signals": ["mass1.v", "mass2.v", "mass3.v", "mass4.v", "mass5.v"]
}
}
}
}
}
endFlattened Source
dyad
"""
Test of braking force models.
Tests five different braking force sources applied to individual masses,
each starting at v=100 m/s from s=0. Replicates the structure of
ModelicaTest.Translational.TestBraking (EddyCurrentForce omitted).
- mass1 + LinearSpeedDependentForce (f_nominal=-100, v_nominal=100)
- mass2 + QuadraticSpeedDependentForce (f_nominal=-100, v_nominal=100)
- mass3 + ConstantForce (f_constant=-100)
- mass4 + SignForce (f_nominal=-100, v0=1)
- mass5 + InverseSpeedDependentForce (f_nominal=-100, v_nominal=100, v0=1)
"""
test component TestBraking
"Mass braked by linear speed-dependent force"
mass1 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 160, "y1": 680, "x2": 260, "y2": 780, "rot": 0}
},
"tags": []
}
}
linearSpeedDependentForce = TranslationalComponents.Sources.LinearSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 680, "x2": 400, "y2": 780, "rot": 0}
},
"tags": []
}
}
"Mass braked by quadratic speed-dependent force"
mass2 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 150, "y1": 450, "x2": 250, "y2": 550, "rot": 0}
},
"tags": []
}
}
quadraticSpeedDependentForce = TranslationalComponents.Sources.QuadraticSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 450, "x2": 400, "y2": 550, "rot": 0}
},
"tags": []
}
}
"Mass braked by constant force"
mass3 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 170, "y1": 880, "x2": 270, "y2": 980, "rot": 0}
},
"tags": []
}
}
constantForce = TranslationalComponents.Sources.ConstantForce(f_constant = -100.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 880, "x2": 400, "y2": 980, "rot": 0}
},
"tags": []
}
}
"Mass braked by sign force"
mass4 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 140, "y1": 230, "x2": 240, "y2": 330, "rot": 0}
},
"tags": []
}
}
signForce = TranslationalComponents.Sources.SignForce(f_nominal = -100.0, v0 = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 510, "y1": 230, "x2": 410, "y2": 330, "rot": 0}
},
"tags": []
}
}
"Mass braked by inverse speed-dependent force"
mass5 = TranslationalComponents.Components.Mass(m = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 140, "y1": 20, "x2": 240, "y2": 120, "rot": 0}
},
"tags": []
}
}
inverseSpeedDependentForce = TranslationalComponents.Sources.InverseSpeedDependentForce(f_nominal = -100.0, v_nominal = 100.0, v0 = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 500, "y1": 20, "x2": 400, "y2": 120, "rot": 0}
},
"tags": []
}
}
"Fixed ground for all force supports"
ground = TranslationalComponents.Components.Fixed() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 890, "y1": 450, "x2": 990, "y2": 550, "rot": 270}
},
"tags": []
}
}
relations
initial mass1.s = 0
initial mass1.v = 100
initial mass2.s = 0
initial mass2.v = 100
initial mass3.s = 0
initial mass3.v = 100
initial mass4.s = 0
initial mass4.v = 100
initial mass5.s = 0
initial mass5.v = 100
connect(mass1.flange_b, linearSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass2.flange_b, quadraticSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass3.flange_b, constantForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass4.flange_b, signForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(mass5.flange_b, inverseSpeedDependentForce.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(inverseSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 190}, {"x": 720, "y": 190}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(signForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 460, "y": 370}, {"x": 720, "y": 370}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(quadraticSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 620}, {"x": 720, "y": 620}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(linearSpeedDependentForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 840}, {"x": 720, "y": 840}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
connect(constantForce.support, ground.flange) {
"Dyad": {
"edges": [
{
"S": 1,
"M": [{"x": 450, "y": 1050}, {"x": 720, "y": 1050}, {"x": 720, "y": 500}],
"E": 2
}
],
"renderStyle": "standard"
}
}
metadata {
"Dyad": {
"icons": {"default": "dyad://TranslationalComponents/Example.svg"},
"tests": {
"case1": {
"stop": 2,
"atol": {
"mass1.v": 0.01,
"mass2.v": 0.01,
"mass3.v": 0.01,
"mass4.v": 0.01,
"mass5.v": 0.1
},
"expect": {
"final": {
"mass1.v": 13.53353,
"mass2.v": 33.333344,
"mass3.v": -100,
"mass4.v": 0,
"mass5.v": -173.19913
},
"signals": ["mass1.v", "mass2.v", "mass3.v", "mass4.v", "mass5.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.Sources.Tests.TestBraking()
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 = 2e+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.mass1.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Sources.Tests.TestBraking_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.mass1.v], width=2, label="Actual value of mass1.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of mass1.v")
end
scatter!(plt, [df_case1.t[end]], [13.53353], label="Final Condition for `mass1.v`")<< @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.mass2.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Sources.Tests.TestBraking_case1_sig1.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.mass2.v], width=2, label="Actual value of mass2.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of mass2.v")
end
scatter!(plt, [df_case1.t[end]], [33.333344], label="Final Condition for `mass2.v`")<< @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.mass3.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Sources.Tests.TestBraking_case1_sig2.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.mass3.v], width=2, label="Actual value of mass3.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of mass3.v")
end
scatter!(plt, [df_case1.t[end]], [-100], label="Final Condition for `mass3.v`")<< @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.mass4.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Sources.Tests.TestBraking_case1_sig3.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.mass4.v], width=2, label="Actual value of mass4.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of mass4.v")
end
scatter!(plt, [df_case1.t[end]], [0], label="Final Condition for `mass4.v`")<< @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.mass5.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "TranslationalComponents.Sources.Tests.TestBraking_case1_sig4.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.mass5.v], width=2, label="Actual value of mass5.v")
if !isnothing(dfr_case1)
scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of mass5.v")
end
scatter!(plt, [df_case1.t[end]], [-173.19913], label="Final Condition for `mass5.v`")<< @setup-block not executed in draft mode >>julia
plt<< @example-block not executed in draft mode >>Related
Examples
Experiments
Analyses
Tests