PySpice-org / PySpice

Simulate electronic circuit using Python and the Ngspice / Xyce simulators
https://pyspice.fabrice-salvaire.fr
GNU General Public License v3.0
652 stars 170 forks source link

ac analysis not working for NgSpiceShared #343

Closed mborghei-aed closed 1 year ago

mborghei-aed commented 1 year ago

Environment: Python

Expected Behaviour: Frequency analysis using the .ac command should run smoothly.

Actual Behaviour: I get the error of "singular matrix: check nodes 5 and 5" and finally it fails after reducing gmin and reaching the iterations limit.

Steps to reproduce the behaviour

Hello,

I am simulating a simple circuit in python using NgSpiceShared in PySpice (code is attached). When I do a .tran analysis, there is no problem whatsoever. But when I wanna do frequency analysis using .ac, I get the error of "singular matrix: check nodes 5 and 5" and finally it fails after reducing gmin and reaching the iterations limit.

The strange thing is that there is no error in LtSpice when I do this, and even with NgSpice there is no problem in the transient analysis. I wanna know if there is a problem with .ac command or my code.

Any help is very much appreciated.

Code: import PySpice.Logging.Logging as Logging logger = Logging.setup_logging() from PySpice.Spice.NgSpice.Shared import NgSpiceShared

ngspice = NgSpiceShared.new_instance()

circuit = ''' .title Test Circuit

Vinput in 0 dc 0 ac 1 C0 in 1 10560pF ic=0 C1 0 2 10560pF ic=0 C2 1 2 890pF ic=0 L0 1 2 1.08mH ic=0 L1 0 3 1.08mH ic=0 K0 L0 L1 0.45 C3 0 3 890pF ic=0 C4 0 4 10560pF ic=0 C5 3 5 10560pF ic=0 R0 4 5 2KOhm .options filetype = binary .options NOINIT .options TEMP = 25°C .options TNOM = 25°C

.ic v(0)=0 v(1)=0 v(2)=0 v(3)=0 v(4)=0 v(5)=0 .ac lin 10 50k 60K .end ''' print(circuit)

ngspice.load_circuit(circuit) ngspice.run()