Skip to content
LIBRARY
Analog.Basic.VariableCapacitor.md

Analog.Basic.VariableCapacitor

Ideal linear electrical capacitor with variable capacitance.

The capacitance value C is provided as an external input signal. A lower bound Cmin prevents the effective capacitance from reaching zero, which would cause a variable index change:

Q=max(C,Cmin)v

The branch current follows from the time derivative of charge:

i=dQdt

This charge-based formulation correctly accounts for time-varying capacitance, producing i = C \dot{v} + \dot{C} v.

Corresponds to Modelica.Electrical.Analog.Basic.VariableCapacitor.

This component extends from ElectricalComponents.Analog.Interfaces.OnePort

Usage

ElectricalComponents.Analog.Basic.VariableCapacitor(Cmin=1e-16)

Parameters:

NameDescriptionUnitsDefault value
CminLower bound for variable capacitanceF1e-16

Connectors

  • p - This connector represents an electrical pin with voltage and current as the potential and flow variables, respectively. (Pin)

  • n - This connector represents an electrical pin with voltage and current as the potential and flow variables, respectively. (Pin)

  • C - This connector represents a real signal as an input to a component (RealInput)

Variables

NameDescriptionUnits
vVoltage across the component (between pin p and pin n).V
iCurrent flowing through the component (from pin p to pin n).A
QElectric charge stored in the capacitorC

Behavior

v(t)=p.v(t)n.v(t)i(t)=p.i(t)p.i(t)+n.i(t)=0Q(t)=v(t) max(C(t),Cmin)i(t)=d Q(t)dt

Source

dyad
"""
Ideal linear electrical capacitor with variable capacitance.

The capacitance value `C` is provided as an external input signal.
A lower bound `Cmin` prevents the effective capacitance from reaching
zero, which would cause a variable index change:

math Q = \max(C, C_{min}) \cdot v

The branch current follows from the time derivative of charge:

math i = \frac{dQ}

This charge-based formulation correctly accounts for time-varying
capacitance, producing `i = C \dot{v} + \dot{C} v`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableCapacitor`.
"""
component VariableCapacitor
  extends ElectricalComponents.Analog.Interfaces.OnePort
  "Capacitance input signal"
  C = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Lower bound for variable capacitance"
  parameter Cmin::Capacitance = 1e-16
  "Electric charge stored in the capacitor"
  variable Q::ElectricCharge
relations
  assert(C >= 0, "Capacitance C has to be >= 0!")
  Q = max(C, Cmin) * v
  i = der(Q)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Capacitor.svg"}
  }
}
end
Flattened Source
dyad
"""
Ideal linear electrical capacitor with variable capacitance.

The capacitance value `C` is provided as an external input signal.
A lower bound `Cmin` prevents the effective capacitance from reaching
zero, which would cause a variable index change:

math Q = \max(C, C_{min}) \cdot v

The branch current follows from the time derivative of charge:

math i = \frac{dQ}

This charge-based formulation correctly accounts for time-varying
capacitance, producing `i = C \dot{v} + \dot{C} v`.

Corresponds to `Modelica.Electrical.Analog.Basic.VariableCapacitor`.
"""
component VariableCapacitor
  "Positive electrical pin."
  p = Pin() {
    "Dyad": {
      "placement": {"icon": {"iconName": "pos", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }
  "Negative electrical pin."
  n = Pin() {
    "Dyad": {
      "placement": {"icon": {"iconName": "neg", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }
  "Voltage across the component (between pin p and pin n)."
  variable v::Voltage
  "Current flowing through the component (from pin p to pin n)."
  variable i::Current
  "Capacitance input signal"
  C = RealInput() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": -100, "x2": 550, "y2": 0, "rot": 90}
      },
      "tags": []
    }
  }
  "Lower bound for variable capacitance"
  parameter Cmin::Capacitance = 1e-16
  "Electric charge stored in the capacitor"
  variable Q::ElectricCharge
relations
  v = p.v - n.v
  i = p.i
  p.i + n.i = 0
  assert(C >= 0, "Capacitance C has to be >= 0!")
  Q = max(C, Cmin) * v
  i = der(Q)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://ElectricalComponents/Capacitor.svg"}
  }
}
end


Test Cases

No test cases defined.