From 9e735f7a4f91e94cfc44e1eb8b06edf005367cee Mon Sep 17 00:00:00 2001 From: pf Date: Sun, 25 Jul 2021 10:58:18 -0700 Subject: [PATCH] preserve old node voltages when re-analyzing --- .../lushprojects/circuitjs1/client/CircuitElm.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/com/lushprojects/circuitjs1/client/CircuitElm.java b/src/com/lushprojects/circuitjs1/client/CircuitElm.java index 82c67f20..9512ad34 100644 --- a/src/com/lushprojects/circuitjs1/client/CircuitElm.java +++ b/src/com/lushprojects/circuitjs1/client/CircuitElm.java @@ -502,8 +502,16 @@ public abstract class CircuitElm implements Editable { // number of internal nodes (nodes not visible in UI that are needed for implementation) int getInternalNodeCount() { return 0; } - // notify this element that its pth node is n. This value n can be passed to stampMatrix() - void setNode(int p, CircuitNode n) { nodes[p] = n; } + // notify this element that its pth node is n. This object n can be passed to stampMatrix() + void setNode(int p, CircuitNode n) { + double v = 0; + if (nodes[p] != null) + v = nodes[p].volts; + nodes[p] = n; + // preserve old node voltages + n.volts = v; + n.high = (v > 2.5); + } // notify this element that its nth voltage source is v. This value v can be passed to stampVoltageSource(), etc and will be passed back in calls to setCurrent() void setVoltageSource(int n, VoltageSource v) {