aUCBLogo Demos and Tests / tunneleffect
to tunneleffect
xy
end
be XYGraph frm width height ~
xmin xmax ymin ymax ticksx ticksy mode
local [g mx my mw mh x0 y0 w0 h0 zx zy zx0 zy0 p0 p pz
mouseleft mouseright inmotion c
xa ya xxa yya
xmin0 xmax0 ymin0 ymax0
maxx maxy]
g=(Graph frm
wxDefault_Frame_Style+wxFull_Repaint_on_Resize ;+wxStay_on_Top
[0 0] List width height [Graph])
;g=[]
setUpdateGraph false
hideTurtle
mx=0
my=0
x0=0
y0=0
mw=0
mh=0
w0=0
h0=0
zx=1
zy=1
zx0=1
zy0=1
c=0
p0=[0 0 0]
p=[0 0 0]
pz=[0 0 0]
mouseleft=false
mouseright=false
inmotion=false
yminh=ymax
ymax=ymin
ymin=yminh
xminh=xmax
xmax=xmin
xmin=xminh
xmin0=xmin
xmax0=xmax
ymin0=ymin
ymax0=ymax
maxx=330
maxy=250
be init
WindowOnLeftDown g
[
if not mouseleft
[ GraphSetCurrent g
p0=MousePos+p
x0=p0.1+mx
y0=p0.2+my
mouseleft=true
]
]
WindowOnLeftUp g
[
mouseleft=false
GraphSetCurrent g
p0=p0-MousePos+p
mx=p.1
my=p.2
]
WindowOnRightDown g
[
if not mouseright
[ GraphSetCurrent g
p0=MousePos+pz
w0=p0.1+mw
h0=p0.2+mh
mouseright=true
]
]
WindowOnRightUp g
[
mouseright=false
GraphSetCurrent g
p0=p0-MousePos+pz
mw=p.1
mh=p.2
zx0=zx0*(1+mw/800)
zy0=zy0*(1+mh/600)
]
;comment [
WindowOnMotion g
[
if mouseleft and2 not inmotion
[ GraphSetCurrent g
p=p0-MousePos
mx=p.1
my=p.2
xmin=(xmin0+xmax0)/2-(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
xmax=(xmin0+xmax0)/2+(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
ymin=(ymin0+ymax0)/2-(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
ymax=(ymin0+ymax0)/2+(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
clearScreen
drawplot
updateGraph
]
if mouseright and2 not inmotion
[ GraphSetCurrent g
pz=p0-MousePos
mw=pz.1
mh=pz.2
zx=zx0*(1+mw/800)
zy=zy0*(1+mh/600)
xmin=(xmin0+xmax0)/2-(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
xmax=(xmin0+xmax0)/2+(xmax0-xmin0)/2*zx-mx/maxx*(xmax0-xmin0)
ymin=(ymin0+ymax0)/2-(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
ymax=(ymin0+ymax0)/2+(ymax0-ymin0)/2*zy-my/maxy*(ymax0-ymin0)
clearScreen
drawplot
updateGraph
]
]
;]
end
be plot xa_ ya_ c_
xa=xa_
ya=ya_
c=c_
drawplot
end
be drawplot
local [x y y2 i h w hq wq hx hy rx ry]
WindowMode
setPenSize [.5 .5]
setPC 0
PenUp
setXY -maxx -maxy
PenDown
setY maxy
setX maxx
setY -maxy
setX -maxx
tick=10
txtx=25
setH 90
setLabelSize [25 25]
setLabelAlign 0 0
setPrintPrecision 4
setLabelFont "Times
h=ymax-ymin
hq=(ymax0-ymin0)*2^(round -0.5+(ln abs h/(abs ymax0-ymin0))/ln 2)
w=xmax-xmin
wq=(xmax0-xmin0)*2^(int -0.5+(ln abs w/(abs xmax0-xmin0))/ln 2)
for [y -ticksy ticksy]
[
hy=-hq*(y/ticksy-0.5)
hy=hy+(remainder -(ymax+ymin)/2 hq/ticksy)
ry=hy+(ymax+ymin)/2
hy=-hy*maxy*2/h
if hy > maxy or2 hy < -maxy [continueLoop]
;(pr maxy h hy)
;if this == xy::g3 [pr hy]
setY hy
PenDown
setX -maxx+tick
setX -maxx
PenUp
setX maxx-tick
PenDown
setX maxx
PenUp
setX -maxx-txtx
Label ry
;pr ry
setX -maxx
]
setY -maxy
for [x -ticksx 2*ticksx]
[ hx=-wq*(x/ticksx-0.5)
hx=hx+(remainder -(xmax+xmin)/2 wq/ticksx)
rx=hx+(xmax+xmin)/2
hx=-hx*maxx*2/w
if hx > maxx or2 hx < -maxx [continueLoop]
setX hx
PenDown
setY -maxy+tick
setY -maxy
PenUp
setY maxy-tick
PenDown
setY maxy
PenUp
setY -maxy-txtx
label rx
setY -maxy
]
setPenSize [0 0]
x=(xmax+xmin)/2
y=(ymax+ymin)/2
fx=2/(xmax-xmin)*maxx
fy=2/(ymax-ymin)*maxy
xxa=saturateBelow -maxx saturateAbove maxx (-xa+x)*fx
yya=saturateBelow -maxy saturateAbove maxy (-ya+y)*fy
ifelse mode == "pixels
[ setPixelXY xxa yya c
][
setPC c
PenUp
; x=maxx
; repeat count xxa
; [ j=repcount
; if xxa.j < x [x=xxa.j y=yya.j]
; ]
; setXY x y
setXY xxa.1 yya.1
PenDown
setXY xxa yya
PenUp
]
updateGraph
;pause
end
be clean
GraphSetCurrent g
clearScreen
end
end
be xy
K=1
eV=1
kg=1
kb=8.617343e-5*eV/K
me=9.10938188e-31*kg
hbar=6.6260693e-34/(2*pi)
Tf=10000*K
Ef=Tf*kb ;in a free electron gas
iv=200
En=Array rSeq 0.001*Ef 1.2*Ef iv
ni=Array iSeq 1 iv
dE=2*Ef/iv
be Fermidist En T Tf
output reciprocal (exp (En-kb*Tf)/(kb*T))+1
end
be kappa E V0
output sqrt (-E+V0)*2*me/(sqr hbar)
end
be sinh x
output ((exp x)-(exp -x))/2
end
be P E V0 width
output reciprocal (reciprocal E*4*(V0-E))*(sqr V0)
*(sqr sinh ((kappa E V0)*width))+1
end
m=100
Tn=Array rSeq 0.0003*Tf Tf/33 m
Tb=Tf-10*K
P_E=Array m
P_T=Array m
tau=Array m
repeat m
[ i=repcount
f_d=(FermiDist En Tn.i Tf)
f_d=f_d/(0+f_d)
D=real f_d*(sqrt En)/sqrt En.(iv/2)
; D=D/40
; D=D/(0+D)
P_E.i=(float P En Tb*kb 1)*D/iv
P_T.i=0+P_E.i
tau.i=reciprocal P_T.i
]
;g3=XYGraph frm 400 300 -400 400 0 10 8 4 "lines
;g3'init
;comment [
if not Name? "frm
[
frm=Frame [][MyFrame]
wxResize_Border+wxCaption+wxSystem_Menu+wxClose_Box
+wxFull_Repaint_on_Resize
;wxDefault_Frame_Style+wxStay_on_Top)
[0 0][400 300]
g=XYGraph frm 400 300 0 2 0 1.6 4 4 "lines
g'init
g2=XYGraph frm 400 300 0 2 0 0.0002 4 4 "lines
g2'init
g3=XYGraph frm 400 300 0 300 0 1 4 4 "lines
g3'init
g4=XYGraph frm 400 300 0 1/3 3 7 4 4 "lines
g4'init
; txtRe1=StaticText frm [ContrastRe]
bs=BoxSizer wxVertical
bsh=BoxSizer wxHORIZONTAL
bsh2=BoxSizer wxHORIZONTAL
BoxSizerAdd bs bsh 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bs bsh2 100 wxExpand+wxALIGN_CENTER 0
; bsv=BoxSizer wxVertical
; bsv2=BoxSizer wxVertical
; BoxSizerAdd bsh bsv 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsh bsv2 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsh g'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsh g2'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsh2 g3'g 100 wxExpand+wxALIGN_CENTER 0
BoxSizerAdd bsh2 g4'g 100 wxExpand+wxALIGN_CENTER 0
; bst=BoxSizer wxHORIZONTAL
; BoxSizerAdd bs bst 20 wxExpand+wxALIGN_CENTER 0
; bsRe =BoxSizer wxVertical
; bsAbs=BoxSizer wxVertical
; BoxSizerAdd bst bsRe 20 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bst bsAbs 20 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsRe txtRe1 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsRe txtRe2 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsRe txtRe3 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsAbs txtAbs1 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsAbs txtAbs2 100 wxExpand+wxALIGN_CENTER 0
; BoxSizerAdd bsAbs txtAbs3 100 wxExpand+wxALIGN_CENTER 0
FrameSetSizer frm bs
FrameSetClientSize frm 800 950
running=true
stopping=false
FrameOnClose frm
[ running=false
]
FrameOnChar frm
[ running=false
]
]
;]
setPrintPrecision 3
GraphSetCurrent g'g
(g'plot En/Ef D*iv/2 HSBA 0 1 0 1)
GraphSetCurrent g2'g
repeat m
[ i=repcount
(g2'plot En/Ef P_E.i HSBA i/m*300 1 1 1)
]
GraphSetCurrent g3'g
(g3'plot Tn P_T HSBA 0 1 1 1)
GraphSetCurrent g4'g
(g4'plot reciprocal Tn log10 tau HSBA 240 1 1 1)
end