more fix on Ec/Ev.
[gss-tcad.git] / lib / template / bipstr.tcl
blobb86bcc6701481798ce484ff7e793ab556f2f233f
1 #-------------------
2 # bipstr
3 #-------------------
4 # Template File for BJT Structures
6 puts "Generate GSS input file..."
8 #COMMENT Only consider X-base implants if XBPEAK >= 1.
9 if {$XBPEAK>1.0} {
10 set XBT 1
11 } else {
12 set XBT 0
15 if {$XBT} {
16 set XYCH [expr ($XBJUNC)/sqrt(log($XBPEAK/$NEPI))]
17 set XXCH [expr $LATD*$XYCH]
18 set XDIF [expr $XXCH*sqrt(log($XBPEAK/$NEPI))]
20 #COMMENT Derived Quantities and Definitions
21 # EPS = roundoff error
22 # WD = collector-base depletion width (microns)
23 # BYCH = base diffusion vertical
24 # characteristic length (microns)
25 # BXCH = base diffusion horizontal
26 # characteristic length (microns)
27 # BDIF = base lateral diffusion distance (microns)
28 # XDIF = lateral diffusion distance beyond BXOVER (microns)
29 # DLBDE = distance from left device edge
30 # to base diffusion edge
31 # DRBDE = distance from right device edge
32 # to base diffusion edge
33 # WBASE = width of base
34 # WMAX = width of device (microns)
35 # LEDE = location of emitter diffusion edge
36 # LECONT = location of emitter contact
37 # LBCONT = location of base contact
38 set EPS [expr .0002]
39 set YBPPE [expr $YBPEAK+$EPS]
40 set WD [expr 3.6E7*sqrt((.8+abs($VCBMAX))/$NEPI)]
41 set WBASE [expr $BEOVER+$WEMIT+$WEXB+$WXBASE+$BXOVER]
42 set BYCH [expr ($BCJUNC-$YBPEAK)/sqrt(log($BPEAK/$NEPI))]
43 set BXCH [expr $LATD*$BYCH]
44 set TMP [expr $BPEAK*exp(- pow($YBPPE/$BYCH,2))]
45 set BDIF [expr $BXCH*sqrt(log($TMP/$NEPI))]
46 set NSRF [expr $TMP-$NEPI]
47 set DLBDE [expr int(2*($BDIF+$WD+1.0))/2]
48 set LEDE [expr $DLBDE+$BEOVER]
49 set LECONT [expr $LEDE+($WEMIT-$WECONT)/2]
50 set LBCONT [expr $LEDE+$WEMIT+$WEXB+($WXBASE-$WBCONT)/2]
51 set TMP [expr $BPEAK*exp(- pow(($YBPPE-$EBJUNC)/$BYCH,2))]
52 set NE [expr $TMP-$NEPI]
53 set EYCH [expr ($EBJUNC)/sqrt(log($EPEAK/$NE))]
54 set EXCH [expr $LATD*$EYCH]
55 set EDIF [expr $EXCH*sqrt(log($EPEAK/$NSRF))]
57 #COMMENT See if XDIF < BDIF+BXOVER+BCSP
58 if {$XBT} {
59 set TMP [expr int($XDIF/($BDIF+$BXOVER+$BCSP))]
60 if { [expr int((2+$TMP)/(1+$TMP))%2] == 1} {
61 set X1 0
62 set X2 1
63 } else {
64 set X1 1
65 set X2 0
69 if {$X1} { set XDIF [expr $BDIF]}
70 if {$X2} { set XDIF [expr $XDIF-$BXOVER]}
71 set DRBDE [expr int(2*($XDIF+$WD+1.0))/2]
72 set WMAX [expr $DLBDE+$WBASE+$DRBDE]
74 #COMMENT Transistor type.
75 if {$TRANTYPE == "PNP"} {
76 set NPN 0
77 set PNP 1
78 } else {
79 set NPN 1
80 set PNP 0
83 set FileID [open $FileName w]
84 puts "Write GSS input statements to $FileName"
86 #-----------------------
87 # MESH statement
88 #-----------------------
89 puts $FileID "MESH Type=GSS ModelFile=$TRANTYPE.cgns Triangle=pzAY"
90 puts $FileID "#---------------------------------------------------"
92 #-----------------------
93 # X.MESH statements
94 #-----------------------
95 puts $FileID "XMESH WIDTH=$DLBDE-$BDIF H2=$BCSP RATIO=$RATIO"
96 set TMP [expr 0.5*($BCSP-$EBSP)/($RATIO-1)]
97 set LX1 [expr ($BDIF+$BEOVER-$EDIF)/2+$TMP]
98 set LX2 [expr ($BDIF+$BEOVER-$EDIF)/2-$TMP]
99 puts $FileID "XMESH WIDTH=$LX2 H1=$BCSP RATIO=$RATIO"
100 puts $FileID "XMESH WIDTH=$LX1 H2=$EBSP RATIO=$RATIO"
102 set W1 [expr $EDIF+($WEMIT-$WECONT)/2]
103 set SPC1 [expr $W1-($W1-$EBSP)/$RATIO]
104 puts $FileID "XMESH WIDTH=$W1 H1=$EBSP RATIO=$RATIO"
105 puts $FileID "XMESH WIDTH=$WECONT/2 H1=$SPC1 RATIO=$RATIO"
106 puts $FileID "XMESH WIDTH=$WECONT/2 H2=$SPC1 RATIO=$RATIO"
107 puts $FileID "XMESH WIDTH=$W1 H2=$EBSP RATIO=$RATIO"
109 set W1 [expr $WEXB-$EDIF+($WXBASE-$WBCONT)/2]
110 set SPC1 [expr $W1-($W1-$EBSP)/$RATIO]
111 set W2 [expr $XDIF+$BXOVER+($WXBASE-$WBCONT)/2]
112 set SPC2 [expr $W2-($W2-$BCSP)/$RATIO]
114 #COMMENT See if SPC1+SPC2 < WBCONT
115 set TMP [expr int(($SPC1+$SPC2)/$WBCONT)]
116 if { [expr int((2+$TMP)/(1+$TMP))%2] == 1} {
117 set X1 0
118 set X2 1
119 } else {
120 set X1 1
121 set X2 0
125 puts $FileID "XMESH WIDTH=$W1 H1=$EBSP RATIO=$RATIO"
126 if {$X1} { puts $FileID "XMESH WIDTH=$WBCONT H1=$SPC1 H2=$SPC2 RATIO=$RATIO"}
127 if {$X2} { puts $FileID "XMESH WIDTH=$WBCONT N.SPACES=2"}
128 puts $FileID "XMESH WIDTH=$W2 H2=$BCSP RATIO=$RATIO"
129 puts $FileID "XMESH X.MAX=$WMAX H1=$BCSP RATIO=$RATIO"
130 puts $FileID "#---------------------------------------------------"
132 #-----------------------
133 # Y.MESH statements
134 #-----------------------
135 puts $FileID "YMESH Y.BOTTOM=0 Y.TOP=0.1 N.SPACES=1"
136 puts $FileID "YMESH Y.BOTTOM=-$EBJUNC H2=$EBSP RATIO=$RATIO"
137 set TMP [expr 0.5*($BCSP-$EBSP)/($RATIO-1)]
138 set LY1 [expr ($BCJUNC-$EBJUNC)/2+$TMP]
139 set LY2 [expr ($BCJUNC-$EBJUNC)/2-$TMP]
140 puts $FileID "YMESH DEPTH=$LY1 H1=$EBSP RATIO=$RATIO"
141 puts $FileID "YMESH Y.BOTTOM=-$BCJUNC H2=$BCSP RATIO=$RATIO"
142 puts $FileID "YMESH Y.BOTTOM=-$TEPI H1=$BCSP RATIO=$RATIO"
143 puts $FileID "YMESH Y.BOTTOM=-$TEPI-0.1 N.SPACES=1"
144 puts $FileID "#---------------------------------------------------"
147 #-----------------------
148 # ELIMINATE ROWS
149 #-----------------------
150 set W12 [expr $EBSP*(2*$RATIO-1)/($RATIO-1)]
151 set W14 [expr $EBSP*(4*$RATIO-1)/($RATIO-1)]
152 set W22 [expr $BCSP*(2*$RATIO-1)/($RATIO-1)]
153 set W24 [expr $BCSP*(4*$RATIO-1)/($RATIO-1)]
154 set WEJBC [expr $WEXB-$EDIF+($WXBASE-$WBCONT)/2]
155 set WXJBC [expr $XDIF+$BXOVER+($WXBASE-$WBCONT)/2]
156 set SFAC [expr 1.6]
157 #-----------------------------------------------------------------------
160 for {set STEPS 0} {$STEPS < 2 } { incr STEPS } {
161 if {$STEPS == 0} {
162 set W1 $W12
163 } else {
164 set W1 $W14
166 set TMP [expr int($W1/$EBJUNC)]
167 if {$STEPS == 0} {
168 set X1 1
169 set X2 0
171 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
172 set X1 [expr !$X1]
173 set X2 [expr !$X2]
175 if {$X1} { set YMN [expr $EBJUNC-$W1]}
176 if {$X2} { set YMN [expr $EPS]}
178 set TMP [expr int($W1/$LY1)]
179 if {$STEPS == 0} {
180 set X1 1
181 set X2 0
183 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
184 set X1 [expr !$X1]
185 set X2 [expr !$X2]
187 if {$X1} { set YMX [expr $EBJUNC+$W1]}
188 if {$X2} { set YMX [expr $EBJUNC+$LY1-$EPS]}
190 set TMP [expr int($W1/$LX1)]
191 if {$STEPS == 0} {
192 set X1 1
194 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
195 set X1 [expr !$X1]
198 set TMP [expr int($W1/$WEJBC)]
199 if {$STEPS == 0} {
200 set X2 1
202 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
203 set X2 [expr !$X1]
206 if {$X1} { set XMX [expr $LEDE-$EDIF-$SFAC*$W1] }
207 if {$X1} { puts $FileID "ELIMINATE Direction=ROWS X.MAX=$XMX Y.TOP=-$YMN Y.BOTTOM=-$YMX" }
208 if {$X2} { set XMN [expr $LEDE+$WEMIT+$EDIF+$SFAC*$W1] }
209 if {$X2} { puts $FileID "ELIMINATE Direction=ROWS X.MIN=$XMN Y.TOP=-$YMN Y.BOTTOM=-$YMX" }
212 #-----------------------------------------------------------------------
213 for {set STEPS 0} {$STEPS < 2 } { incr STEPS } {
214 if {$STEPS == 0} {
215 set W1 $W22
216 } else {
217 set W1 $W24
219 set TMP [expr int($W1/$LY2)]
220 if {$STEPS == 0} {
221 set X1 1
222 set X2 0
224 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
225 set X1 [expr !$X1]
226 set X2 [expr !$X2]
228 if {$X1} { set YMN [expr $BCJUNC-$W1]}
229 if {$X2} { set YMN [expr $EPS]}
231 set YMX [expr $BCJUNC+$W1]
233 set XMX [expr $DLBDE-$BDIF-$SFAC*$W1]
234 puts $FileID "ELIMINATE Direction=ROWS X.MAX=$XMX Y.TOP=-$YMN Y.BOTTOM=-$YMX"
235 set XMN [expr $WMAX-$DRBDE+$XDIF+$SFAC*$W1]
236 puts $FileID "ELIMINATE Direction=ROWS X.MIN=$XMN Y.TOP=-$YMN Y.BOTTOM=-$YMX"
239 #-----------------------
240 # ELIMINATE COLUMNS
241 #-----------------------
242 for {set STEPS 0} {$STEPS < 2 } { incr STEPS } {
243 if {$STEPS == 0} {
244 set W1 $W12
245 } else {
246 set W1 $W14
248 set YMN [expr $EBJUNC+$SFAC*$W1]
250 set TMP [expr int($W1/$LX1)]
251 if {$STEPS == 0} {
252 set X1 1
253 set X2 0
255 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
256 set X1 [expr !$X1]
257 set X2 [expr !$X2]
259 if {$X1} { set XMN [expr $LEDE-$EDIF-$W1]}
260 if {$X2} { set XMN [expr $DLBDE+$LX2+$EPS]}
262 set TMP [expr int($W1/($EDIF+$WEMIT/2)) ]
263 if {$STEPS == 0} {
264 set X1 1
266 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
267 set X1 [expr !$X1]
270 if {$X1} { set XMX [expr $LEDE-$EDIF+$W1]}
271 if {$X1} { puts $FileID "ELIMINATE Direction=COLUMNS X.MIN=$XMN X.MAX=$XMX Y.TOP=-$YMN"}
272 if {$X1} { set XMN [expr $LEDE+$WEMIT+$EDIF-$W1]}
274 set TMP [expr int($W1/$WEJBC)]
275 if {$STEPS == 0} {
276 set X1 1
277 set X2 0
279 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
280 set X1 [expr !$X1]
281 set X2 [expr !$X2]
283 if {$X1} { set XMX [expr $LEDE+$WEMIT+$EDIF+$W1]}
284 if {$X2} { set XMX [expr $LBCONT-$EPS]}
285 puts $FileID "ELIMINATE Direction=COLUMNS X.MIN=$XMN X.MAX=$XMX Y.TOP=-$YMN"
288 #-----------------------------------------------------------------------
289 for {set STEPS 0} {$STEPS < 2 } { incr STEPS } {
290 if {$STEPS == 0} {
291 set W1 $W22
292 } else {
293 set W1 $W24
295 set YMN [expr $BCJUNC+$SFAC*$W1]
296 set XMN [expr $DLBDE-$BDIF-$W1]
297 set TMP [expr int($W1/$LX2)]
298 if {$STEPS == 0} {
299 set X1 1
300 set X2 0
302 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
303 set X1 [expr !$X1]
304 set X2 [expr !$X2]
307 if {$X1} { set XMX [expr $DLBDE-$BDIF+$W1]}
308 if {$X2} { set XMX [expr $DLBDE-$BDIF+$LX2-$EPS]}
309 puts $FileID "ELIMINATE Direction=COLUMNS X.MIN=$XMN X.MAX=$XMX Y.TOP=-$YMN"
311 set TMP [expr int($W1/$WXJBC)]
312 if {$STEPS == 0} {
313 set X1 1
314 set X2 0
316 for {set loop 0} { $loop < [expr int((2+$TMP)/(1+$TMP))]} {incr loop} {
317 set X1 [expr !$X1]
318 set X2 [expr !$X2]
320 if {$X1} { set XMN [expr $WMAX-$DRBDE+$XDIF-$W1]}
321 if {$X2} { set XMN [expr $WMAX-$DRBDE+$XDIF-$WXJBC+$EPS]}
322 set XMX [expr $WMAX-$DRBDE+$XDIF+$W1]
323 puts $FileID "ELIMINATE Direction=COLUMNS X.MIN=$XMN X.MAX=$XMX Y.TOP=-$YMN"
326 #-----------------------
327 # REGIONS
328 #-----------------------
329 puts $FileID "#---------------------------------------------------"
330 puts $FileID "REGION Label=Silicon Material=Si"
331 puts $FileID "REGION Label=Oxide1 Material=Ox IY.MIN=0 IY.MAX=1 X.MIN=0 X.MAX=$LBCONT"
333 #-----------------------
334 # ELECTRODES
335 #-----------------------
336 puts $FileID "REGION Label=Collector Material=Elec Y.TOP=-$TEPI+0.0001"
337 puts $FileID "REGION Label=Emitter Material=Elec IY.MAX=1 X.MIN=$LECONT X.MAX=$LECONT+$WECONT"
338 puts $FileID "REGION Label=Oxide2 Material=Ox IY.MAX=1 X.MIN=$LECONT+$WECONT X.MAX=$LBCONT"
339 puts $FileID "REGION Label=Base Material=Elec IY.MAX=1 X.MIN=$LBCONT X.MAX=$LBCONT+$WBCONT"
340 puts $FileID "REGION Label=Oxide3 Material=Ox IY.MAX=1 X.MIN=$LBCONT+$WBCONT X.MAX=$WMAX"
341 #-----------------------
342 # PROFILES
343 #-----------------------
344 set BLCHAR [expr $BLDEPTH/sqrt(log($BLPEAK/$NEPI))]
345 if {$NPN} {
346 set ECTYP "Donor"
347 set BTYP "Acceptor"
350 if {$PNP} {
351 set ECTYP "Acceptor"
352 set BTYP "Donor"
355 #-----------------------
356 # ANALYTIC PROFILES
357 #-----------------------
358 puts $FileID "#---------------------------------------------------"
359 puts $FileID "PROFILE Ion=$ECTYP N.PEAK=$NEPI Type=Uniform X.MIN=0 X.MAX=$WMAX Y.TOP=0.1 Y.BOTTOM=-$TEPI-0.1"
361 if {$BLPEAK>1.0} {
362 puts $FileID "PROFILE Type=Gauss Ion=$ECTYP N.PEAK=$BLPEAK Y.TOP=-$TEPI Y.CHAR=$BLCHAR X.MIN=0 X.MAX=$WMAX"
365 puts $FileID "PROFILE Type=Gauss Ion=$BTYP N.PEAK=$BPEAK Y.TOP=-$YBPEAK Y.Junction=-$BCJUNC XY.RATIO=$LATD \
366 X.MIN=$DLBDE X.MAX=[expr $DLBDE+$WBASE]"
368 if {$XBT} {
369 puts $FileID "PROFILE Type=Gauss Ion=$BTYP N.PEAK=$XBPEAK Y.CHAR=$XYCH X.CHAR=[expr $LATD*$XYCH] \
370 X.MIN=[expr $LEDE+$WEMIT+$WEXB] X.MAX=[expr $LEDE+$WEMIT+$WEXB+$WXBASE]"
373 puts $FileID "PROFILE Type=Gauss Ion=$ECTYP N.PEAK=$EPEAK Y.Junction=-$EBJUNC XY.RATIO=$LATD \
374 X.MIN=$LEDE X.MAX=[expr $LEDE+$WEMIT]"
376 #-----------------------
377 # Boundary Conditions
378 #-----------------------
379 puts $FileID "#---------------------------------------------------"
380 puts $FileID "CONTACT Type = OhmicContact ID = Emitter"
381 puts $FileID "CONTACT Type = OhmicContact ID = Base"
382 puts $FileID "CONTACT Type = OhmicContact ID = Collector"
384 #-----------------------
385 # PLOTS
386 #-----------------------
387 puts $FileID "#---------------------------------------------------"
388 puts $FileID "PLOT Variable=DeviceMesh"
390 #-----------------------
391 # Solve Equilibrium State
392 #-----------------------
393 puts $FileID "METHOD Type = DDML1 Scheme = Newton NS=LineSearch LS=GMRES"
394 puts $FileID "SOLVE Type = TRANSIENT TStart = 0 TStep=1e-12 TStop = 3e-11"
395 puts $FileID "SOLVE Type = EQUILIBRIUM"
396 puts $FileID "PLOT Variable=Na Resolution=RES.High AzAngle=120 ElAngle=60"
397 puts $FileID "PLOT Variable=Nd Resolution=RES.High AzAngle=120 ElAngle=60"
398 puts $FileID "PLOT Variable=Potential Resolution=RES.High AzAngle=240 ElAngle=20"
399 puts $FileID "PLOT Variable=ElecDensity Resolution=RES.High AzAngle=240 ElAngle=20"
400 puts $FileID "PLOT Variable=HoleDensity Resolution=RES.High AzAngle=240 ElAngle=20"
402 puts $FileID "EXPORT CoreFile = $TRANTYPE.init.cgns"
403 puts $FileID "END"
405 close $FileID