Class CircuitElement

java.lang.Object
org.episteme.natural.physics.classical.waves.electromagnetism.circuit.CircuitElement
Direct Known Subclasses:
Capacitor, Ground, Inductor, Resistor, VoltageSource

public abstract class CircuitElement extends Object
Abstract base class for all circuit elements (resistors, capacitors, sources, etc.). This class defines the interface for circuit simulation using Modified Nodal Analysis (MNA).

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Circuit
    Reference to the parent circuit (for stamping)
    protected double
    Current through the element
    protected int[]
    Node indices for each terminal of this element
    protected double[]
    Voltage at each terminal
    protected int
    Voltage source index (for elements that act as voltage sources)
    protected int
    X coordinate of first terminal
    protected int
    X coordinate of second terminal
    protected int
    Y coordinate of first terminal
    protected int
    Y coordinate of second terminal
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new circuit element at (0,0) to (0,0).
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Allocates arrays for nodes and voltages based on post count.
    void
    Calculates the current through this element.
    void
    Performs one simulation step for this element.
    Returns the parent circuit.
    boolean
    getConnection(int n1, int n2)
    Returns whether terminals n1 and n2 are connected through this element.
    double
    Returns the current through the element.
    int
    Returns the number of internal nodes used by this element.
    int
    getNode(int post)
    Returns the node index for a terminal.
    int
    Returns the number of external terminals (posts) on this element.
    int[]
    Returns the coordinate of the specified post.
    double
    Returns the power dissipated by this element.
    double
    Returns the voltage difference across the element (post 0 to post 1).
    int
    Returns the voltage source index.
    int
    Returns the number of independent voltage sources in this element.
    boolean
    Returns whether terminal n has a ground connection.
    boolean
    Returns whether this element is nonlinear.
    void
    Resets the element to initial state.
    void
    Sets the parent circuit for this element.
    void
    setCoordinates(int x, int y, int x2, int y2)
    Sets the coordinates of the element's terminals.
    void
    setCurrent(int n, double c)
    Sets the current through the element.
    void
    setNode(int post, int nodeIndex)
    Sets the node index for a terminal.
    void
    setNodeVoltage(int n, double voltage)
    Sets the voltage at a node.
    void
    setVoltageSource(int n, int vs)
    Sets the voltage source index for this element.
    abstract void
    Stamps the element's contribution into the circuit matrix.
    void
    Called at the start of each simulation iteration.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • nodes

      protected int[] nodes
      Node indices for each terminal of this element
    • volts

      protected double[] volts
      Voltage at each terminal
    • current

      protected double current
      Current through the element
    • voltSource

      protected int voltSource
      Voltage source index (for elements that act as voltage sources)
    • circuit

      protected Circuit circuit
      Reference to the parent circuit (for stamping)
    • x

      protected int x
      X coordinate of first terminal
    • y

      protected int y
      Y coordinate of first terminal
    • x2

      protected int x2
      X coordinate of second terminal
    • y2

      protected int y2
      Y coordinate of second terminal
  • Constructor Details

    • CircuitElement

      public CircuitElement()
      Creates a new circuit element at (0,0) to (0,0).
  • Method Details

    • setCoordinates

      public void setCoordinates(int x, int y, int x2, int y2)
      Sets the coordinates of the element's terminals.
      Parameters:
      x - X1
      y - Y1
      x2 - X2
      y2 - Y2
    • getPostPosition

      public int[] getPostPosition(int n)
      Returns the coordinate of the specified post.
      Parameters:
      n - Post index (0 or 1)
      Returns:
      Array containing {x, y}
    • allocNodes

      protected void allocNodes()
      Allocates arrays for nodes and voltages based on post count.
    • setCircuit

      public void setCircuit(Circuit circuit)
      Sets the parent circuit for this element.
      Parameters:
      circuit - The circuit this element belongs to
    • getCircuit

      public Circuit getCircuit()
      Returns the parent circuit.
      Returns:
      The circuit this element belongs to
    • getPostCount

      public int getPostCount()
      Returns the number of external terminals (posts) on this element. Most elements have 2 posts. Override for elements with more.
      Returns:
      Number of external terminals
    • getInternalNodeCount

      public int getInternalNodeCount()
      Returns the number of internal nodes used by this element. Internal nodes are used for complex devices like op-amps.
      Returns:
      Number of internal nodes (default 0)
    • getVoltageSourceCount

      public int getVoltageSourceCount()
      Returns the number of independent voltage sources in this element. Used for voltage sources and elements that model voltage sources.
      Returns:
      Number of voltage sources (default 0)
    • nonLinear

      public boolean nonLinear()
      Returns whether this element is nonlinear. Nonlinear elements require iterative solving at each time step.
      Returns:
      true if nonlinear, false otherwise
    • setNode

      public void setNode(int post, int nodeIndex)
      Sets the node index for a terminal.
      Parameters:
      post - Terminal number
      nodeIndex - Node index in the circuit
    • getNode

      public int getNode(int post)
      Returns the node index for a terminal.
      Parameters:
      post - Terminal number
      Returns:
      Node index
    • setVoltageSource

      public void setVoltageSource(int n, int vs)
      Sets the voltage source index for this element.
      Parameters:
      n - Which voltage source (for multi-source elements)
      vs - The voltage source index
    • getVoltageSource

      public int getVoltageSource()
      Returns the voltage source index.
      Returns:
      Voltage source index
    • setNodeVoltage

      public void setNodeVoltage(int n, double voltage)
      Sets the voltage at a node. Called by the circuit solver after computing voltages.
      Parameters:
      n - Node number
      voltage - The voltage
    • calculateCurrent

      public void calculateCurrent()
      Calculates the current through this element. Called after node voltages are updated.
    • getVoltageDiff

      public double getVoltageDiff()
      Returns the voltage difference across the element (post 0 to post 1).
      Returns:
      Voltage difference
    • getCurrent

      public double getCurrent()
      Returns the current through the element.
      Returns:
      Current in amperes
    • setCurrent

      public void setCurrent(int n, double c)
      Sets the current through the element.
      Parameters:
      n - Which current (for multi-current elements)
      c - Current value
    • getPower

      public double getPower()
      Returns the power dissipated by this element.
      Returns:
      Power in watts
    • reset

      public void reset()
      Resets the element to initial state.
    • stamp

      public abstract void stamp()
      Stamps the element's contribution into the circuit matrix. This is called once during circuit analysis to build the MNA matrix. Linear elements stamp constant coefficients; nonlinear elements stamp initial guesses that will be updated in doStep().
    • doStep

      public void doStep()
      Performs one simulation step for this element. Called during each iteration of the solver. Nonlinear elements update their matrix contributions here.
    • startIteration

      public void startIteration()
      Called at the start of each simulation iteration. Used for time-dependent elements to update their state.
    • getConnection

      public boolean getConnection(int n1, int n2)
      Returns whether terminals n1 and n2 are connected through this element. Used for determining circuit connectivity.
      Parameters:
      n1 - First terminal
      n2 - Second terminal
      Returns:
      true if connected
    • hasGroundConnection

      public boolean hasGroundConnection(int n)
      Returns whether terminal n has a ground connection.
      Parameters:
      n - Terminal number
      Returns:
      true if grounded