SinRLC
Series RLC circuit driven by a sinusoidal voltage input.
This component models a series RLC circuit. It consists of a resistor (R), an inductor (L), and a capacitor (C) connected in series with an ideal voltage source. The voltage provided by the source is a sinusoidal waveform generated by a Sine block. A ground component provides the reference potential. Initial conditions for the inductor current (relations
section of the component model.
Usage
SinRLC()
Behavior
Source
dyad
# Series RLC circuit driven by a sinusoidal voltage input.
#
# This component models a series RLC circuit. It consists of a resistor (R),
# an inductor (L), and a capacitor (C) connected in series with an ideal
# voltage source. The voltage provided by the source is a sinusoidal waveform
# generated by a Sine block. A ground component provides the reference potential.
# Initial conditions for the inductor current ($i_L(0)$) and capacitor voltage ($v_C(0)$)
# are specified directly in the `relations` section of the component model.
example component SinRLC
# Resistor element with a resistance of 100 Ohms.
resistor = Resistor(R=100) [{
"Dyad": {
"placement": {"icon": {"x1": 1100, "y1": 400, "x2": 1300, "y2": 600, "rot": -90}}
}
}]
# Capacitor element with a capacitance of 1 milliFarad.
capacitor = Capacitor(C=1m) [{
"Dyad": {
"placement": {"icon": {"x1": 800, "y1": 400, "x2": 1000, "y2": 600, "rot": -90}}
}
}]
# Inductor element with an inductance of 1 Henry.
inductor = Inductor(L=1) [{"Dyad": {"placement": {"icon": {"x1": 600, "y1": 100, "x2": 800, "y2": 300}}}}]
# Ideal voltage source whose output voltage is externally defined.
source = VoltageSource() [{
"Dyad": {
"placement": {"icon": {"x1": 400, "y1": 400, "x2": 600, "y2": 600, "rot": -90}}
}
}]
# Sine wave generator block with configured frequency (1 Hz), amplitude (1 unit), and phase (0 rad).
sine = BlockComponents.Sine(frequency=1, amplitude=1, phase=0) [{"Dyad": {"placement": {"icon": {"x1": 100, "y1": 400, "x2": 300, "y2": 600}}}}]
# Ground connection providing the zero-potential reference.
ground = Ground() [{
"Dyad": {"placement": {"icon": {"x1": 800, "y1": 900, "x2": 1000, "y2": 1100}}}
}]
relations
initial inductor.i = 0
initial capacitor.v = 10
connect(sine.y, source.V) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
connect(source.n, inductor.p) [{"Dyad": {"edges": [{"S": 1, "M": [{"x": 500, "y": 200}], "E": 2}]}}]
connect(inductor.n, resistor.n, capacitor.n) [{
"Dyad": {
"edges": [
{"S": 1, "E": -1},
{"S": 2, "M": [{"x": 1200, "y": 200}], "E": -1},
{"S": 3, "E": -1}
],
"junctions": [{"x": 900, "y": 200}]
}
}]
connect(resistor.p, ground.g, capacitor.p, source.p) [{
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 1200, "y": 800}], "E": -1},
{"S": 2, "E": -1},
{"S": 3, "E": -1},
{"S": -1, "M": [{"x": 500, "y": 800}], "E": 4}
],
"junctions": [{"x": 900, "y": 800}]
}
}]
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 10,
"expect": {"initial": {"capacitor.v": 10}, "final": {"capacitor.v": -0.067835084}}
}
}
}
}
end
Flattened Source
dyad
# Series RLC circuit driven by a sinusoidal voltage input.
#
# This component models a series RLC circuit. It consists of a resistor (R),
# an inductor (L), and a capacitor (C) connected in series with an ideal
# voltage source. The voltage provided by the source is a sinusoidal waveform
# generated by a Sine block. A ground component provides the reference potential.
# Initial conditions for the inductor current ($i_L(0)$) and capacitor voltage ($v_C(0)$)
# are specified directly in the `relations` section of the component model.
example component SinRLC
# Resistor element with a resistance of 100 Ohms.
resistor = Resistor(R=100) [{
"Dyad": {
"placement": {"icon": {"x1": 1100, "y1": 400, "x2": 1300, "y2": 600, "rot": -90}}
}
}]
# Capacitor element with a capacitance of 1 milliFarad.
capacitor = Capacitor(C=1m) [{
"Dyad": {
"placement": {"icon": {"x1": 800, "y1": 400, "x2": 1000, "y2": 600, "rot": -90}}
}
}]
# Inductor element with an inductance of 1 Henry.
inductor = Inductor(L=1) [{"Dyad": {"placement": {"icon": {"x1": 600, "y1": 100, "x2": 800, "y2": 300}}}}]
# Ideal voltage source whose output voltage is externally defined.
source = VoltageSource() [{
"Dyad": {
"placement": {"icon": {"x1": 400, "y1": 400, "x2": 600, "y2": 600, "rot": -90}}
}
}]
# Sine wave generator block with configured frequency (1 Hz), amplitude (1 unit), and phase (0 rad).
sine = BlockComponents.Sine(frequency=1, amplitude=1, phase=0) [{"Dyad": {"placement": {"icon": {"x1": 100, "y1": 400, "x2": 300, "y2": 600}}}}]
# Ground connection providing the zero-potential reference.
ground = Ground() [{
"Dyad": {"placement": {"icon": {"x1": 800, "y1": 900, "x2": 1000, "y2": 1100}}}
}]
relations
initial inductor.i = 0
initial capacitor.v = 10
connect(sine.y, source.V) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
connect(source.n, inductor.p) [{"Dyad": {"edges": [{"S": 1, "M": [{"x": 500, "y": 200}], "E": 2}]}}]
connect(inductor.n, resistor.n, capacitor.n) [{
"Dyad": {
"edges": [
{"S": 1, "E": -1},
{"S": 2, "M": [{"x": 1200, "y": 200}], "E": -1},
{"S": 3, "E": -1}
],
"junctions": [{"x": 900, "y": 200}]
}
}]
connect(resistor.p, ground.g, capacitor.p, source.p) [{
"Dyad": {
"edges": [
{"S": 1, "M": [{"x": 1200, "y": 800}], "E": -1},
{"S": 2, "E": -1},
{"S": 3, "E": -1},
{"S": -1, "M": [{"x": 500, "y": 800}], "E": 4}
],
"junctions": [{"x": 900, "y": 800}]
}
}]
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 10,
"expect": {"initial": {"capacitor.v": 10}, "final": {"capacitor.v": -0.067835084}}
}
}
}
}
end
Test Cases
This is setup code, that must be run before each test case.
julia
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
julia
@mtkbuild model_case1 = SinRLC()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 10))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 227-element Vector{Float64}:
0.0
9.99899510149345e-5
0.0010998894611642795
0.0048891035276169195
0.011749327056831304
0.02094570835564214
0.03253018190030981
0.04590065551529248
0.060227460170735554
0.07684010579384991
⋮
9.637095396750185
9.690644126521093
9.743086451161998
9.794298474656477
9.844257672752544
9.892695892915464
9.939126273375102
9.982061054576423
10.0
u: 227-element Vector{Vector{Float64}}:
[10.0, 0.0]
[9.98995604667543, 0.000999366702292552]
[9.884611102723913, 0.010932622387102494]
[9.407509022680724, 0.04745031277194228]
[8.261993300385239, 0.10789249969997661]
[6.278863579377679, 0.17413864960548078]
[3.3536749439669555, 0.22827402809716532]
[-0.08939147679630963, 0.24659391188606963]
[-3.219162152261523, 0.21716216580340936]
[-5.459462540969538, 0.13574245958577913]
⋮
[-0.7423158156233145, 0.011985604316724243]
[-0.9405149166509028, 0.01217435057665034]
[-1.032600046319855, 0.011035737679895666]
[-1.015305945401037, 0.008773725668295521]
[-0.8978742611510304, 0.00569660297424944]
[-0.7000643620692016, 0.002179468886142177]
[-0.4497855914851507, -0.0013844293416365489]
[-0.18399036684305164, -0.004583444316812465]
[-0.06783508461577992, -0.0058346784602437965]
Related
Examples
Experiments
Analyses