Class Circuit
java.lang.Object
org.episteme.natural.physics.classical.waves.electromagnetism.circuit.Circuit
A headless circuit simulator using Modified Nodal Analysis (MNA).
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(CircuitElement element) Adds a circuit element to this circuit.booleananalyze()Analyzes the circuit and builds the MNA matrix.getElement(int index) Returns the element at the specified index.intReturns the number of elements in the circuit.getNode(int index) Returns the circuit node at the specified index.intReturns the number of nodes in the circuit.Returns any error message from the simulation.doublegetTime()Returns the current simulation time.doubleReturns the simulation time step.booleanremove(CircuitElement element) Removes a circuit element from this circuit.voidreset()Resets all circuit elements.voidsetTimeStep(double dt) Sets the simulation time step.voidstampCurrentSource(int n1, int n2, double current) Stamps a current source between two nodes.voidstampMatrix(int row, int col, double value) Stamps a value into the circuit matrix.voidstampResistor(int n1, int n2, double resistance) Stamps a resistor between two nodes.voidstampRightSide(int row) Marks that the right-hand side of a row changes during doStep().voidstampRightSide(int row, double value) Stamps a value into the right-hand side vector.voidstampVoltageSource(int n1, int n2, int vs, double voltage) Stamps a voltage source between two nodes.booleanstep()Performs one simulation step.voidupdateVoltageSource(int n1, int n2, int vs, double voltage) Updates the value of a voltage source.
-
Constructor Details
-
Circuit
public Circuit()Creates a new empty circuit.
-
-
Method Details
-
add
Adds a circuit element to this circuit.- Parameters:
element- The element to add
-
remove
Removes a circuit element from this circuit.- Parameters:
element- The element to remove- Returns:
- true if the element was removed
-
getElement
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
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
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 beforestep().- 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 noden2- Second noderesistance- 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 noden2- Negative nodevs- Voltage source indexvoltage- 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 noden2- Negative nodevs- Voltage source indexvoltage- New voltage value
-
reset
public void reset()Resets all circuit elements.
-