Skip to content
SinRLC.md

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 (iL(0)) and capacitor voltage (vC(0)) are specified directly in the relations section of the component model.

Usage ​

SinRLC()

Behavior ​

julia
using ElectricalComponents #hide
using ModelingToolkit #hide
@named sys = SinRLC() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

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.06781383813851176}}
      }
    }
  }
}
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.06781383813851176}}
      }
    }
  }
}
end


Test Cases ​

julia
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 ​

julia
@mtkbuild model_case1 = SinRLC()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 10))
sol_case1 = solve(prob_case1)
<< @setup-block not executed in draft mode >>
  • Examples

  • Experiments

  • Analyses