dsharlet / LiveSPICE

Real time SPICE simulation for audio signals
MIT License
419 stars 61 forks source link

IndexOutOfRangeException during initial conditions calculation. #148

Closed Federerer closed 1 year ago

Federerer commented 2 years ago

Hi, using switches breaks initial conditions calculation, because of floating nodes.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ComputerAlgebra.NSolveExtension.NewtonsMethod(Int32 M, Int32 N, Func`4 J, Double s, Double[] x, Double Epsilon, Int32 MaxIterations) in C:\Users\08fed\Documents\dev\LiveSPICE\ComputerAlgebra\ComputerAlgebra\Extensions\NSolve.cs:line 102

Minimal reproduction: Switch test.schx

It can be fixed by adding a high value resistance (1GΩ) from switch poles to ground, but this might impact real-time performance. 🤔 Another solution is to remove all 2 terminal components with unconnected terminals, but it gets trickier for components with more than two terminals. Maybe a mixed solution (remove 2 terminal components and add 1G resistance for 2+ terminal ones) would work best?