Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Add kludge to deal with numpy deprecations #3

Merged
merged 2 commits into from
Nov 9, 2022
Merged

Conversation

nickd4
Copy link

@nickd4 nickd4 commented Mar 6, 2021

I was just experimenting this morning and made a few changes to get python3-eispice to build and run the demo code:

import eispice
cct = eispice.Circuit("Capacitor Test")
cct.Vx = eispice.V(1, eispice.GND, 4,
  eispice.Pulse(4, 8, '10n', '2n', '3n', '5n', '20n'))
cct.Cx = eispice.C(1, eispice.GND, '10n')
cct.tran('0.5n', '100n')
eispice.plot(cct)

I thought it might be useful for others. Although I must say what I did is pretty kludgey, so do feel free to do it better if you prefer.

Update: I have also fixed a bug that prevented repeated solving from working when there were nonlinear sources.

This is what I was trying to do:

#!/usr/bin/env python3

import eispice

CONST_k = 1.3806503e-23 # Boltzmann's Constant (1/JK)
CONST_q = 1.60217646e-19 # Electron Charge (C)
CONST_TNOM = 25.
CONST_V_T = CONST_k * (CONST_TNOM + 273.15) / CONST_q # Thermal Voltage

class D(eispice.Subckt):
  def __init__(self, node_A, node_K, I_S = 1e-12, n = 1.):
    self.I_D = eispice.B(
      node_A,
      node_K,
      eispice.Current,
      f'{I_S:e}*(exp(v({str(node_A):s},{str(node_K):s})/{n*CONST_V_T:e})-1)'
    )

if __name__ == '__main__':
  circuit = eispice.Circuit()
  circuit.V1 = eispice.V(1, eispice.GND)
  circuit.D1 = D(1, eispice.GND)
  circuit.V1.DC = .6
  circuit.op()
  print('circuit.variables', circuit.variables)
  print('circuit.results', circuit.results)
  circuit.V1.DC = .7
  circuit.op()
  print('circuit.results', circuit.results)

The second solve was failing because of a missing initialization in the nonlinear current source code.

Basically when the device code (e.g. nonlinear current source) wants to update the MNA matrix (MNA = Modified Node Analysis), instead of overwriting a cell it always adds / subtracts something to the cell, that's because it doesn't know if another device might be manipulating the same cell, so it needs to be transparent in that case. Therefore, it always remembers what it last "wrote" to the cell and if it wants to "write" a new value to the cell, it adds the difference between new and old values.

What the extra initialization does is to zero the saved copy of what was last "written" to the cell -- since matrix was also zeroed.

@Narrat
Copy link
Owner

Narrat commented Mar 7, 2021

Ha, maybe this is the much missed and needed incentive to get back to this. So thanks for that and thank you for your PR.
Will take a look at your proposed changes, although that might need some time, as I need to get again somewhat familiar with the source.
Although the first commit points to a somewhat fundamental question. Should there be still support for such an old numpy version, or stick to the latest (stable)? I tend to the latter, especially as this lay dormant for years. Up to a fresh start. (Well, sort of at least). May I ask for your opinion on this topic?

@Narrat Narrat merged commit e1279ab into Narrat:master Nov 9, 2022
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants