SaturatingInductorTest
Test circuit for a saturating inductor component.
This test component evaluates the behavior of a SaturatingInductor
. It constructs an electrical circuit where the saturating inductor is placed in parallel with a standard linear inductor. A constant voltage source, driven by a signal generator block, applies 40 volts across this parallel inductor arrangement. The primary purpose is to observe and verify the dynamic changes in the saturating inductor's apparent inductance (L_actual
) as current builds up, leading to magnetic saturation. Initial conditions are set for the saturating inductor's current, and the test metadata specifies expected inductance values at the beginning and end of the simulation, facilitating automated verification of the saturating inductor model.
Usage
SaturatingInductorTest()
Behavior
using ElectricalComponents #hide
using ModelingToolkit #hide
@named sys = SaturatingInductorTest() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>
Source
# Test circuit for a saturating inductor component.
#
# This test component evaluates the behavior of a `SaturatingInductor`.
# It constructs an electrical circuit where the saturating inductor is
# placed in parallel with a standard linear inductor. A constant voltage
# source, driven by a signal generator block, applies 40 volts across
# this parallel inductor arrangement. The primary purpose is to observe
# and verify the dynamic changes in the saturating inductor's apparent
# inductance (`L_actual`) as current builds up, leading to magnetic
# saturation. Initial conditions are set for the saturating inductor's
# current, and the test metadata specifies expected inductance values at
# the beginning and end of the simulation, facilitating automated
# verification of the saturating inductor model.
test component SaturatingInductorTest
# Instance of the saturating inductor model being tested.
sat_inductor = SaturatingInductor(L_zero=2, L_inf=0.5, L_nominal=1)
# Constant signal generator providing the input for the voltage source.
signal = BlockComponents.Constant(k=40)
# Ideal voltage source component.
source = VoltageSource()
# Electrical ground connection.
ground = Ground()
# Standard linear inductor used in parallel for the test setup.
inductor = Inductor(L=1)
relations
initial sat_inductor.i = 1e-10
initial inductor.p.i = 0.0
connect(signal.y, source.V)
connect(source.n, ground.g, sat_inductor.n, inductor.n)
connect(sat_inductor.p, source.p, inductor.p)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 10,
"expect": {
"initial": {"sat_inductor.L_actual": 2},
"final": {"sat_inductor.L_actual": 0.50863266}
}
}
}
}
}
end
Flattened Source
# Test circuit for a saturating inductor component.
#
# This test component evaluates the behavior of a `SaturatingInductor`.
# It constructs an electrical circuit where the saturating inductor is
# placed in parallel with a standard linear inductor. A constant voltage
# source, driven by a signal generator block, applies 40 volts across
# this parallel inductor arrangement. The primary purpose is to observe
# and verify the dynamic changes in the saturating inductor's apparent
# inductance (`L_actual`) as current builds up, leading to magnetic
# saturation. Initial conditions are set for the saturating inductor's
# current, and the test metadata specifies expected inductance values at
# the beginning and end of the simulation, facilitating automated
# verification of the saturating inductor model.
test component SaturatingInductorTest
# Instance of the saturating inductor model being tested.
sat_inductor = SaturatingInductor(L_zero=2, L_inf=0.5, L_nominal=1)
# Constant signal generator providing the input for the voltage source.
signal = BlockComponents.Constant(k=40)
# Ideal voltage source component.
source = VoltageSource()
# Electrical ground connection.
ground = Ground()
# Standard linear inductor used in parallel for the test setup.
inductor = Inductor(L=1)
relations
initial sat_inductor.i = 1e-10
initial inductor.p.i = 0.0
connect(signal.y, source.V)
connect(source.n, ground.g, sat_inductor.n, inductor.n)
connect(sat_inductor.p, source.p, inductor.p)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 10,
"expect": {
"initial": {"sat_inductor.L_actual": 2},
"final": {"sat_inductor.L_actual": 0.50863266}
}
}
}
}
}
end
Test Cases
using ElectricalComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(ElectricalComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>
Test Case case1
@mtkbuild model_case1 = SaturatingInductorTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 10))
sol_case1 = solve(prob_case1)
<< @setup-block not executed in draft mode >>
Related
Examples
Experiments
Analyses
Tests