* 6BX7-GT -- LTspice validation of GX-TXT triode.koren_v1
* New fit: 440 points, lsqnonlin
* Static plate-current model only
*
* IMPORTANT LTspice syntax note:
* The B-source expression is NOT enclosed in curly braces.
* Curly braces force immediate parameter evaluation and cannot contain V(node).

.param mu=10.813884978151192
.param Kp=77.284607645620596
.param Kvb=654.33045589862036
.param Kg1=485.64217355533503
.param Ex=1.3034825268711401
.param Vgk=-20

* GX-TXT implementation:
* den = sqrt(max(Kvb + Vak^2, eps))
* z   = Kp*(1/mu + Vgk/den)
* sp  = max(z,0) + ln(1 + exp(-abs(z)))
* E1  = max((Vak/Kp)*sp,0)
* Ia  = 2000*E1^Ex/Kg1 [mA]
*
* LTspice B-source current is in A, therefore:
* Ia[A] = 2*E1^Ex/Kg1

.func den(vak)      {sqrt(max(Kvb + vak*vak, 1e-30))}
.func zk(vak,vgk)   {Kp*(1/mu + vgk/den(vak))}
.func softplus(x)    {max(x,0) + ln(1 + exp(-abs(x)))}
.func eone(vak,vgk) {max((vak/Kp)*softplus(zk(vak,vgk)),0)}
.func ia_koren(vak,vgk) {2*pwr(eone(vak,vgk),Ex)/Kg1}

* Plate voltage sweep, cathode = 0 V
VA A 0 0

* Grid voltage relative to cathode
VG G 0 {Vgk}

* Positive current flows from plate A to cathode 0
* Do NOT write I={...} here.
BTRIODE A 0 I=ia_koren(V(A),V(G))

.step param Vgk -50 0 5
.dc VA 0 500 1

.options plotwinsize=0

* Plot in LTspice:
*   1000*I(BTRIODE)     plate current [mA]
* x axis is the .dc sweep VA = Vak [V]

.end
