Skip to content
RLCModel.md

RLCModel

An electrical circuit model featuring an inductor in series with a parallel resistor-capacitor combination, driven by a constant voltage source.

This model represents an electrical circuit where an inductor (L) is connected in series with a parallel arrangement of a resistor (R) and a capacitor (C). This L-(R||C) configuration is subjected to a constant voltage provided by a voltage source. The key dynamics are governed by Kirchhoff's laws. Initial conditions are specified for iL(0)=0A and vC(0)=10V. The system is expected to reach a steady state where vC=Vsig=30V.

Usage

RLCModel()

Behavior

[signal.y(t)=source.V(t)connect(source+n,inductor+p)connect(inductor+n,resistor+n,capacitor+n)connect(resistor+p,ground+g,capacitor+p,source+p)resistor.v(t)=resistor.n.v(t)+resistor.p.v(t)resistor.i(t)=resistor.p.i(t)resistor.p.i(t)+resistor.n.i(t)=0resistor.v(t)=resistor.Rresistor.i(t)capacitor.v(t)=capacitor.p.v(t)capacitor.n.v(t)capacitor.i(t)=capacitor.p.i(t)capacitor.p.i(t)+capacitor.n.i(t)=0capacitor.Cdcapacitor.v(t)dt=capacitor.i(t)inductor.v(t)=inductor.n.v(t)+inductor.p.v(t)inductor.i(t)=inductor.p.i(t)inductor.p.i(t)+inductor.n.i(t)=0inductor.Ldinductor.i(t)dt=inductor.v(t)signal.y(t)=signal.ksource.v(t)=source.n.v(t)+source.p.v(t)source.i(t)=source.p.i(t)source.p.i(t)+source.n.i(t)=0source.v(t)=source.uVsource.V(t)ground.g.v(t)=0]

Source

dyad
# An electrical circuit model featuring an inductor in series with a parallel resistor-capacitor combination, driven by a constant voltage source.
#
# This model represents an electrical circuit where an inductor (L) is connected in series with a parallel arrangement of a resistor (R) and a capacitor (C).
# This L-(R||C) configuration is subjected to a constant voltage provided by a voltage source.  The key dynamics are governed by Kirchhoff's laws.
# Initial conditions are specified for $i_L(0) = 0A$ and $v_C(0) = 10V$. The system is expected to reach a steady state where $v_C = V_{sig} = 30V$.
example component RLCModel
  # Resistor subcomponent with a resistance value of 100 Ohms.
  resistor = Resistor(R=100) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 850, "y1": 450, "x2": 950, "y2": 550, "rot": -90}}
    }
  }]
  # Capacitor subcomponent with a capacitance value of 1 milliFarad.
  capacitor = Capacitor(C=1m) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 550, "y1": 450, "x2": 650, "y2": 550, "rot": -90}}
    }
  }]
  # Inductor subcomponent with an inductance value of 1 Henry.
  inductor = Inductor(L=1) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 375, "y1": 250, "x2": 475, "y2": 350, "rot": 0}}
    }
  }]
  # Constant signal generator block providing an output value of 30.
  signal = BlockComponents.Constant(k=30) [{"Dyad": {"placement": {"icon": {"x1": 0, "y1": 450, "x2": 100, "y2": 550}}}}]
  # Voltage source subcomponent providing the electromotive force.
  source = VoltageSource() [{
    "Dyad": {
      "placement": {"diagram": {"x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": -90}}
    }
  }]
  # Ground subcomponent providing the reference potential (0V).
  ground = Ground() [{
    "Dyad": {
      "placement": {"diagram": {"x1": 550, "y1": 800, "x2": 650, "y2": 900, "rot": 0}}
    }
  }]
relations
  initial inductor.i = 0
  initial capacitor.v = 10
  connect(signal.y, source.V) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
  connect(source.n, inductor.p) [{"Dyad": {"edges": [{"S": 1, "M": [{"x": 250, "y": 300}], "E": 2}]}}]
  connect(inductor.n, resistor.n, capacitor.n) [{
    "Dyad": {
      "edges": [
        {"S": 1, "E": -1},
        {"S": 2, "M": [{"x": 900, "y": 300}], "E": -1},
        {"S": 3, "E": -1}
      ],
      "junctions": [{"x": 600, "y": 300}]
    }
  }]
  connect(resistor.p, ground.g, capacitor.p, source.p) [{
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 900, "y": 700}], "E": -1},
        {"S": 2, "E": -1},
        {"S": 3, "E": -1},
        {"S": -1, "M": [{"x": 250, "y": 700}], "E": 4}
      ],
      "junctions": [{"x": 600, "y": 700}]
    }
  }]
metadata {
  "Dyad": {
    "labels": [
      {
        "label": "RLC Model",
        "x": 800,
        "y": 100,
        "layer": "diagram",
        "attrs": {"font-size": "100"}
      }
    ],
    "tests": {
      "case1": {
        "stop": 10,
        "expect": {"initial": {"capacitor.v": 10}, "final": {"capacitor.v": 30}}
      }
    }
  }
}
end
Flattened Source
dyad
# An electrical circuit model featuring an inductor in series with a parallel resistor-capacitor combination, driven by a constant voltage source.
#
# This model represents an electrical circuit where an inductor (L) is connected in series with a parallel arrangement of a resistor (R) and a capacitor (C).
# This L-(R||C) configuration is subjected to a constant voltage provided by a voltage source.  The key dynamics are governed by Kirchhoff's laws.
# Initial conditions are specified for $i_L(0) = 0A$ and $v_C(0) = 10V$. The system is expected to reach a steady state where $v_C = V_{sig} = 30V$.
example component RLCModel
  # Resistor subcomponent with a resistance value of 100 Ohms.
  resistor = Resistor(R=100) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 850, "y1": 450, "x2": 950, "y2": 550, "rot": -90}}
    }
  }]
  # Capacitor subcomponent with a capacitance value of 1 milliFarad.
  capacitor = Capacitor(C=1m) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 550, "y1": 450, "x2": 650, "y2": 550, "rot": -90}}
    }
  }]
  # Inductor subcomponent with an inductance value of 1 Henry.
  inductor = Inductor(L=1) [{
    "Dyad": {
      "placement": {"diagram": {"x1": 375, "y1": 250, "x2": 475, "y2": 350, "rot": 0}}
    }
  }]
  # Constant signal generator block providing an output value of 30.
  signal = BlockComponents.Constant(k=30) [{"Dyad": {"placement": {"icon": {"x1": 0, "y1": 450, "x2": 100, "y2": 550}}}}]
  # Voltage source subcomponent providing the electromotive force.
  source = VoltageSource() [{
    "Dyad": {
      "placement": {"diagram": {"x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": -90}}
    }
  }]
  # Ground subcomponent providing the reference potential (0V).
  ground = Ground() [{
    "Dyad": {
      "placement": {"diagram": {"x1": 550, "y1": 800, "x2": 650, "y2": 900, "rot": 0}}
    }
  }]
relations
  initial inductor.i = 0
  initial capacitor.v = 10
  connect(signal.y, source.V) [{"Dyad": {"edges": [{"S": 1, "E": 2}]}}]
  connect(source.n, inductor.p) [{"Dyad": {"edges": [{"S": 1, "M": [{"x": 250, "y": 300}], "E": 2}]}}]
  connect(inductor.n, resistor.n, capacitor.n) [{
    "Dyad": {
      "edges": [
        {"S": 1, "E": -1},
        {"S": 2, "M": [{"x": 900, "y": 300}], "E": -1},
        {"S": 3, "E": -1}
      ],
      "junctions": [{"x": 600, "y": 300}]
    }
  }]
  connect(resistor.p, ground.g, capacitor.p, source.p) [{
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 900, "y": 700}], "E": -1},
        {"S": 2, "E": -1},
        {"S": 3, "E": -1},
        {"S": -1, "M": [{"x": 250, "y": 700}], "E": 4}
      ],
      "junctions": [{"x": 600, "y": 700}]
    }
  }]
metadata {
  "Dyad": {
    "labels": [
      {
        "label": "RLC Model",
        "x": 800,
        "y": 100,
        "layer": "diagram",
        "attrs": {"font-size": "100"}
      }
    ],
    "tests": {
      "case1": {
        "stop": 10,
        "expect": {"initial": {"capacitor.v": 10}, "final": {"capacitor.v": 30}}
      }
    }
  }
}
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 = RLCModel()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 10))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 67-element Vector{Float64}:
  0.0
  4.9994994251825804e-5
  0.0005499449367700837
  0.0032167091196663167
  0.008799826079128319
  0.016799021642651076
  0.02695613496459187
  0.0396169783491686
  0.05478901733874843
  0.07280192095361755

  3.139080368320423
  3.2874134812890756
  3.4842259930640544
  3.731390687566108
  4.042285806570721
  4.472480148710761
  5.222846207605161
  7.545694580358596
 10.0
u: 67-element Vector{Vector{Float64}}:
 [10.0, 0.0]
 [9.995026743022887, -0.001000024422669102]
 [9.948177995368846, -0.011013438997018265]
 [9.786276803992813, -0.06473559664713348]
 [9.915786617794144, -0.17751938004870632]
 [11.134255146337775, -0.3340740366203665]
 [14.181698659754106, -0.5114836738398562]
 [19.661293917940576, -0.6785701422338856]
 [27.2993233060592, -0.7779232922964245]
 [35.58193299744454, -0.7489207412660243]

 [29.99638407002078, -0.29980250232870975]
 [30.001324495408763, -0.30013004221343176]
 [29.99908692065683, -0.2999321224194253]
 [30.000709727421157, -0.3000269648913133]
 [29.999606988320664, -0.2999945513167103]
 [30.000110665092848, -0.299998714347782]
 [29.99999887566771, -0.30000073240868114]
 [29.999998559649562, -0.2999999773940622]
 [30.00000005286016, -0.29999999788167414]
  • Examples

  • Experiments

  • Analyses