Class CircuitElement
java.lang.Object
org.episteme.natural.physics.classical.waves.electromagnetism.circuit.CircuitElement
- Direct Known Subclasses:
Capacitor, Ground, Inductor, Resistor, VoltageSource
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
FieldsModifier and TypeFieldDescriptionprotected CircuitReference to the parent circuit (for stamping)protected doubleCurrent through the elementprotected int[]Node indices for each terminal of this elementprotected double[]Voltage at each terminalprotected intVoltage source index (for elements that act as voltage sources)protected intX coordinate of first terminalprotected intX coordinate of second terminalprotected intY coordinate of first terminalprotected intY coordinate of second terminal -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAllocates arrays for nodes and voltages based on post count.voidCalculates the current through this element.voiddoStep()Performs one simulation step for this element.Returns the parent circuit.booleangetConnection(int n1, int n2) Returns whether terminals n1 and n2 are connected through this element.doubleReturns the current through the element.intReturns the number of internal nodes used by this element.intgetNode(int post) Returns the node index for a terminal.intReturns the number of external terminals (posts) on this element.int[]getPostPosition(int n) Returns the coordinate of the specified post.doublegetPower()Returns the power dissipated by this element.doubleReturns the voltage difference across the element (post 0 to post 1).intReturns the voltage source index.intReturns the number of independent voltage sources in this element.booleanhasGroundConnection(int n) Returns whether terminal n has a ground connection.booleanReturns whether this element is nonlinear.voidreset()Resets the element to initial state.voidsetCircuit(Circuit circuit) Sets the parent circuit for this element.voidsetCoordinates(int x, int y, int x2, int y2) Sets the coordinates of the element's terminals.voidsetCurrent(int n, double c) Sets the current through the element.voidsetNode(int post, int nodeIndex) Sets the node index for a terminal.voidsetNodeVoltage(int n, double voltage) Sets the voltage at a node.voidsetVoltageSource(int n, int vs) Sets the voltage source index for this element.abstract voidstamp()Stamps the element's contribution into the circuit matrix.voidCalled at the start of each simulation iteration.
-
Field Details
-
nodes
protected int[] nodesNode indices for each terminal of this element -
volts
protected double[] voltsVoltage at each terminal -
current
protected double currentCurrent through the element -
voltSource
protected int voltSourceVoltage source index (for elements that act as voltage sources) -
circuit
Reference to the parent circuit (for stamping) -
x
protected int xX coordinate of first terminal -
y
protected int yY coordinate of first terminal -
x2
protected int x2X coordinate of second terminal -
y2
protected int y2Y 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- X1y- Y1x2- X2y2- 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
Sets the parent circuit for this element.- Parameters:
circuit- The circuit this element belongs to
-
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 numbernodeIndex- 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 numbervoltage- 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 indoStep(). -
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 terminaln2- 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
-