The code testing convergence of currents through each nonlinear device, as described §1.4.2 of the User's Manual, uses node voltages from the previous iteration where it should use the latest matrix solution --- each test computes zero for the change in currents. Also, any reports of needing more iterations (flag CKTnoncon
) are not communicated from the non-linear-device testers to the driver. These issues exist since Berkeley Spice 3f5
This patch addresses only arbitrary source devices (B-devices). There is a similar error in the tests for other nonlinear devices.
The patch prodcues the expected behaviour for the input in bug #695.
The regression test in the patch is a more realistic example, than the one in the bug report.
That is really good news.
Hi all,
are you sure we use NEWCONV by default or is it anyway enabled through configure? I don't remember this.
Second point is: the trouble node is always 0. Is it correct?
@Keith: thanks for the patch! :)
Thank you,
Fra
NEWCONV is a simple always-active #define in src/include/macros.h since 1999.
Berkeley Spice 3f5 has it as an always-active #define in src/include/capabil.h since 1990.
In the circuit in the regression test, there is only one non-ground node, N01
Ok! Good to know! :)
Ok for this circuit, but in general the troubleNode should be discovered, I guess... But anyway, this is a second order problem.
Let's try to fix the main problem and generally extend the methodology.
I also assume (because I don't remember the code now) that you act before the RHSold and RHS are swapped. I'm saying that because RHSold contains always the final solution at the end of NR cycle.
Thank you,
Fra
I misunderstood you earlier about CKTtroubleNode=0.
That field is set to the first voltage node found with voltage not yet converged.
If the first found problem is a branch current not yet converged, the code sets CKTtroubleNode=0 to indicate no node single node has the problem, and sets CKTtroubleElt to point to the device whose current has not yet converged. This was done for linear elements like G current sources, now nonlinear elements as well.
And yes, the iteration routine in niiter calls NIconvTest() after the matrix solve,
So at this point CKTrhs contains the newest node voltages (and linear branch currents) but nonlinear elements still hold their internal state computed from the voltages in CKTrhsOld
Later, at the end of the main loop in niiter.c, CKTrhs is swapped into CKTrhsOld.
(For anyone reading this without context of the code, it might be confusing that "rhs" is first loaded with the currents on the right-hand side of the matrix equation [G] v = i but at the moment under discussion, after solving the matrix equation, CKTrhs holds the solution v, which is mostly node-voltages. This is the world of solving large sparse matrices with limited memory in the 1980s.)
Last edit: Keith OHara 2025-01-06
Updated patch. I notice now that I formed the patch from a version before I had added the code comments.
Sorry about that. Correction attached, with plots
(the amount violation of Kirchhoff's current law, which should be less than 20nA)
from the regression test before versus after patch.
Last edit: Keith OHara 2025-01-06
Ok, now we are on the same page! :)
BTW, you should try the branch KCL where I added a KCL Verification as convervenge criterion for f(v). It's quite old, so it needs to be at least rebased...
Thank you,
Fra
I do not see KCL but suppose you mean KLU-kirchhoff-3. That is interesting.
I have seen the developer of Spectre, which enforces Kirchhoff's current sums at each node,
disparage Spice for failing to ensure that currents sum to zero.
This confused me, because Spice /claimed/ to be enforcing the convergence of each branch current, in the context of a matrix solve that implicitly enforces the sums of currents to balance at each node. Spice's solution seemed, to me, superior in the area Spectre was pointing to.
Yep, that one. Check if there is a more recent Kirchhoff branch, BTW.
Yes, the idea is that the independent variable V can be checked with ABSTOL and RELTOL and RHSold vs RHS, while the dependent variable I is actually a function of V, so only the model knows exactly the convergence criterion for each function of V (which is the NIConvTest part we were talking about before). But this could contain error or being not precise or other things, so I developed another criterion, which is the KCL verification at each node.
The problem is that, as far as I remeber, the model has to be modified, because the currents have to be injected in a separate database visible at circuit level.
However, the idea still stands...
So, I'm quite sure I did only a proof of concept as you did and I have modified only few models...
Thank you,
Fra
Applying this patch, the VDMOS power transistor model stops functioning. All examples from https://sourceforge.net/p/ngspice/ngspice/ci/master/tree/examples/vdmos/ are failing.
Last edit: Holger Vogt 2025-01-19