Resistor

ground 0 

load "resistor.osdi"

model resistor resistor
model vsource vsource
model isource isource

v1 (1 0) vsource dc=1
r1 (1 0) resistor r=2k $mfactor=3

control
  abort always

  options rawfile="binary" op_debug=0
  save (
    default p(r1,i)
  )
  analysis op1 op
  
  postprocess(PYTHON, "runme.py")
endc

embed "runme.py" <<<FILE
from rawfile import rawread
from runtest import *
import numpy as np
import sys

tests=[]

op1 = rawread('op1.raw').get()

i = op1["v1:flow(br)"]
exact = -1/2e3 * 3
status = (relDiff(i, exact, 1e-12) < 1e-3).all()
print("i(v1)=", i, "exact=", exact, status)
tests.append(status)

i = op1["r1.i"]
exact = 1/2e3
status = (relDiff(i, exact, 1e-12) < 1e-3).all()
print("r1.i=", i, "exact=", exact, status)
tests.append(status)

if isTest():
    sys.exit(not all(tests))
>>>FILE
