Class Circuit

java.lang.Object
org.episteme.natural.physics.classical.waves.electromagnetism.circuit.Circuit

public class Circuit extends Object
A headless circuit simulator using Modified Nodal Analysis (MNA).

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

    Constructors
    Constructor
    Description
    Creates a new empty circuit.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a circuit element to this circuit.
    boolean
    Analyzes the circuit and builds the MNA matrix.
    getElement(int index)
    Returns the element at the specified index.
    int
    Returns the number of elements in the circuit.
    getNode(int index)
    Returns the circuit node at the specified index.
    int
    Returns the number of nodes in the circuit.
    Returns any error message from the simulation.
    double
    Returns the current simulation time.
    double
    Returns the simulation time step.
    boolean
    Removes a circuit element from this circuit.
    void
    Resets all circuit elements.
    void
    setTimeStep(double dt)
    Sets the simulation time step.
    void
    stampCurrentSource(int n1, int n2, double current)
    Stamps a current source between two nodes.
    void
    stampMatrix(int row, int col, double value)
    Stamps a value into the circuit matrix.
    void
    stampResistor(int n1, int n2, double resistance)
    Stamps a resistor between two nodes.
    void
    stampRightSide(int row)
    Marks that the right-hand side of a row changes during doStep().
    void
    stampRightSide(int row, double value)
    Stamps a value into the right-hand side vector.
    void
    stampVoltageSource(int n1, int n2, int vs, double voltage)
    Stamps a voltage source between two nodes.
    boolean
    Performs one simulation step.
    void
    updateVoltageSource(int n1, int n2, int vs, double voltage)
    Updates the value of a voltage source.

    Methods inherited from class Object

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

    • Circuit

      public Circuit()
      Creates a new empty circuit.
  • Method Details

    • add

      public void add(CircuitElement element)
      Adds a circuit element to this circuit.
      Parameters:
      element - The element to add
    • remove

      public boolean remove(CircuitElement element)
      Removes a circuit element from this circuit.
      Parameters:
      element - The element to remove
      Returns:
      true if the element was removed
    • getElement

      public CircuitElement getElement(int index)
      Returns the element at the specified index.
      Parameters:
      index - Element index
      Returns:
      The circuit element
    • getElementCount

      public int getElementCount()
      Returns the number of elements in the circuit.
      Returns:
      Element count
    • getNode

      public CircuitNode getNode(int index)
      Returns the circuit node at the specified index.
      Parameters:
      index - Node index
      Returns:
      The circuit node, or null if index is out of range
    • getNodeCount

      public int getNodeCount()
      Returns the number of nodes in the circuit.
      Returns:
      Node count
    • getTime

      public double getTime()
      Returns the current simulation time.
      Returns:
      Time in seconds
    • setTimeStep

      public void setTimeStep(double dt)
      Sets the simulation time step.
      Parameters:
      dt - Time step in seconds
    • getTimeStep

      public double getTimeStep()
      Returns the simulation time step.
      Returns:
      Time step in seconds
    • getStopMessage

      public String getStopMessage()
      Returns any error message from the simulation.
      Returns:
      Error message, or null if no error
    • analyze

      public boolean analyze()
      Analyzes the circuit and builds the MNA matrix. Must be called before step().
      Returns:
      true if analysis succeeded
    • step

      public boolean step()
      Performs one simulation step.
      Returns:
      true if the step succeeded
    • stampRightSide

      public void stampRightSide(int row, double value)
      Stamps a value into the right-hand side vector.
      Parameters:
      row - Row index (1-indexed, 0 = ground)
      value - Value to add
    • stampRightSide

      public void stampRightSide(int row)
      Marks that the right-hand side of a row changes during doStep().
      Parameters:
      row - Row index (1-indexed)
    • stampMatrix

      public void stampMatrix(int row, int col, double value)
      Stamps a value into the circuit matrix.
      Parameters:
      row - Row index (1-indexed, 0 = ground)
      col - Column index (1-indexed, 0 = ground)
      value - Value to add
    • stampResistor

      public void stampResistor(int n1, int n2, double resistance)
      Stamps a resistor between two nodes.
      Parameters:
      n1 - First node
      n2 - Second node
      resistance - Resistance in ohms
    • stampVoltageSource

      public void stampVoltageSource(int n1, int n2, int vs, double voltage)
      Stamps a voltage source between two nodes.
      Parameters:
      n1 - Positive node
      n2 - Negative node
      vs - Voltage source index
      voltage - Voltage value
    • stampCurrentSource

      public void stampCurrentSource(int n1, int n2, double current)
      Stamps a current source between two nodes.
      Parameters:
      n1 - Source node (current flows out)
      n2 - Sink node (current flows in)
      current - Current in amperes
    • updateVoltageSource

      public void updateVoltageSource(int n1, int n2, int vs, double voltage)
      Updates the value of a voltage source. Used for dynamic elements that change voltage during simulation.
      Parameters:
      n1 - Positive node
      n2 - Negative node
      vs - Voltage source index
      voltage - New voltage value
    • reset

      public void reset()
      Resets all circuit elements.