* Native high-field tanh resistor -- self-contained regression test.
*
* GENERIC (non-PDK) coefficients only.  Verifies that the native ngspice
* resistor device (pvc1/pvc2/pvc3 high-field term + tc1/tc2) reproduces the
* mathematically-equivalent behavioral B-source, for both field conventions:
*   case 1  field = |V|/Leff   (geometry/body segment; 1/Leff folded into pvc2)
*   case 2  field = |V|        (value/end segment)
* R(V,T) = R0*(1+tc1*dT+tc2*dT^2)*(1 + pvc1*(tanh(pvc2*|field| + pvc3) - tanh(pvc3)))
*
* Expect: max |Inative - Ibehavioral| ~ 1e-15 A (currents are ~mA) -> bit-equal.
.param R0=500 pv1=-0.25 pv2=1e-5 pv3=2.0 t1=1e-3 t2=3e-7 leff=5u
.temp 25
Vt a 0 dc 0

* ---- case 1: field = |V|/Leff ----
.model rn1 R tnom=25 vsmooth=1e-9 pvc1='pv1' pvc3='pv3' tc1='t1' tc2='t2'
Rn1  a n1  rn1 'R0' pvc2='pv2/leff'
Vm1  n1 0 dc 0
Bb1  a nb1 I='v(a,nb1)/(R0*(1+t1*(temper-25)+t2*(temper-25)*(temper-25))*(1+pv1*(tanh(pv2*abs(v(a,nb1)/leff)+pv3)-tanh(pv3))))'
Vmb1 nb1 0 dc 0

* ---- case 2: field = |V| (no Leff) ----
.model rn2 R tnom=25 vsmooth=1e-9 pvc1='pv1' pvc3='pv3' tc1='t1' tc2='t2'
Rn2  a n2  rn2 'R0' pvc2='pv2'
Vm2  n2 0 dc 0
Bb2  a nb2 I='v(a,nb2)/(R0*(1+t1*(temper-25)+t2*(temper-25)*(temper-25))*(1+pv1*(tanh(pv2*abs(v(a,nb2))+pv3)-tanh(pv3))))'
Vmb2 nb2 0 dc 0

.dc Vt -1.8 1.8 0.05
.control
run
let d1 = abs(i(vm1)-i(vmb1))
let d2 = abs(i(vm2)-i(vmb2))
print vecmax(d1) vecmax(d2)
.endc
.end
