Skip to content
InterpolatedTableTest.md

InterpolatedTableTest ​

Usage ​

BlockComponents.InterpolatedTableTest(m=1.0, k=100.0)

Parameters: ​

NameDescriptionUnitsDefault value
input_file–"dyad://BlockComponents/data/damper_force_table.csv"
damper_table–DyadData.DyadInterpolationTable2D(input_file, axis1_name="velocity", axis2_name="temperature", data_name="damping_force")
mkg1
kN/m100

Variables ​

NameDescriptionUnits
xm
vm/s
TK
F_damperN

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
test component InterpolatedTableTest
  damper_interp = BlockComponents.InterpolatedTable(axis1 = damper_table["velocity"], axis2 = damper_table["temperature"], data = damper_table["damping_force"], interpolation_dim1 = BlockComponents.InterpolationDimension.LinearInterpolationDimension(), interpolation_dim2 = BlockComponents.InterpolationDimension.LinearInterpolationDimension())
  parameter m::Mass = 1.0
  parameter k::TranslationalSpringConstant = 100.0
  variable x::Position
  variable v::Velocity
  variable T::Temperature
  variable F_damper::Force
  structural parameter input_file::String = "dyad://BlockComponents/data/damper_force_table.csv"
  structural parameter damper_table::DyadData.DyadInterpolationTable2D = DyadData.DyadInterpolationTable2D(input_file, axis1_name = "velocity", axis2_name = "temperature", data_name = "damping_force")
relations
  initial x = 1.0
  initial v = 0.0
  damper_interp.u1 = v
  damper_interp.u2 = T
  F_damper = damper_interp.y
  T = 300.0 + 50.0 * sin(2 * pi * 0.1 * time)
  v = der(x)
  m * der(v) = -k * x - F_damper
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 0.1, "expect": {"signals": ["v"]}}},
    "doc": {"behavior": false}
  }
}
end
Flattened Source
dyad
test component InterpolatedTableTest
  damper_interp = BlockComponents.InterpolatedTable(axis1 = damper_table["velocity"], axis2 = damper_table["temperature"], data = damper_table["damping_force"], interpolation_dim1 = BlockComponents.InterpolationDimension.LinearInterpolationDimension(), interpolation_dim2 = BlockComponents.InterpolationDimension.LinearInterpolationDimension())
  parameter m::Mass = 1.0
  parameter k::TranslationalSpringConstant = 100.0
  variable x::Position
  variable v::Velocity
  variable T::Temperature
  variable F_damper::Force
  structural parameter input_file::String = "dyad://BlockComponents/data/damper_force_table.csv"
  structural parameter damper_table::DyadData.DyadInterpolationTable2D = DyadData.DyadInterpolationTable2D(input_file, axis1_name = "velocity", axis2_name = "temperature", data_name = "damping_force")
relations
  initial x = 1.0
  initial v = 0.0
  damper_interp.u1 = v
  damper_interp.u2 = T
  F_damper = damper_interp.y
  T = 300.0 + 50.0 * sin(2 * pi * 0.1 * time)
  v = der(x)
  m * der(v) = -k * x - F_damper
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 0.1, "expect": {"signals": ["v"]}}},
    "doc": {"behavior": false}
  }
}
end


Test Cases ​

julia
using BlockComponents
using DyadInterface: TransientAnalysis, rebuild_sol
using ModelingToolkit: toggle_namespacing, get_defaults, @named
using CSV, DataFrames, Plots

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1 ​

julia
@named model_case1 = InterpolatedTableTest()
model_case1 = toggle_namespacing(model_case1, false)

model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = "auto", start = 0e+0, stop = 1e-1, 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.v])
dfr_case1 = try CSV.read(joinpath(snapshotsdir, "InterpolatedTableTest_case1_sig0.ref"), DataFrame); catch e; nothing; end
plt = plot(sol_case1, idxs=[model_case1.v], width=2, label="Actual value of v")
if !isnothing(dfr_case1)
  scatter!(plt, dfr_case1.t, dfr_case1.expected, mc=:red, ms=3, label="Expected value of v")
end
<< @setup-block not executed in draft mode >>
julia
plt
<< @example-block not executed in draft mode >>