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
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
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
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
This is setup code, that must be run before each test case.
using ElectricalComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(ElectricalComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/ElectricalComponents/bmmPM/test/snapshots"
Test Case case1
@mtkbuild model_case1 = SaturatingInductorTest()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 10))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 22-element Vector{Float64}:
0.0
1.0e-6
1.1e-5
0.00011099999999999999
0.0011109999999999998
0.011110999999999996
0.03550902356229728
0.06049817581471583
0.08852252095335103
0.14031295475364364
⋮
0.28995073285601863
0.3609578785195968
0.45698633755002627
0.5975178094844239
0.8360798554817265
1.2879107185853105
2.3723168313975354
6.10193432529563
10.0
u: 22-element Vector{Vector{Float64}}:
[-1.0e-10, 1.9999999999999998e-10, 1.0e-10]
[3.99999000000002e-5, 4.0000200000000193e-5, 2.000010000023989e-5]
[0.00043999990000000237, 0.00044000020000000247, 0.00022000010031915292]
[0.004439999900000012, 0.004440000200000011, 0.0022200004279347993]
[0.0444399999, 0.044440000199999996, 0.0222203289247531]
[0.4444399999000015, 0.4444400002000015, 0.22254920258216795]
[1.420360942391892, 1.420360942691892, 0.7210128828884258]
[2.4199270324886326, 2.4199270327886326, 1.2644171574149647]
[3.540900838034051, 3.5409008383340512, 1.9455243991223434]
[5.612518190045754, 5.612518190345754, 3.5403691166347664]
⋮
[11.598029314140778, 11.59802931444078, 11.685647392414502]
[14.438315140683937, 14.438315140983939, 16.746622049149078]
[18.279453501901145, 18.279453502201143, 23.987419356645173]
[23.900712379277092, 23.90071237957709, 34.90698497632506]
[33.4431942191693, 33.4431942194693, 53.7419001764996]
[51.51642874331285, 51.51642874361284, 89.70206556680185]
[94.89267325580187, 94.89267325610186, 176.31760354889624]
[244.0773730117267, 244.07737301202667, 474.59782106238237]
[399.9999999999008, 400.0000000002008, 786.4221700097229]
Related
Examples
Experiments
Analyses
Tests