calcCAP.tcl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # calcRL.tcl
  4. #
  5. # Copyright (C) Mayo Foundation. All Rights Reserved.
  6. #
  7. #-----------------------------------------------------------------
  8. package require Itcl
  9. package provide calcCAP 1.0
  10. namespace eval ::calcCAP:: {
  11. namespace export calcCAP_RunGraphical
  12. namespace export calcCAP_RunBatch
  13. namespace export calcCAP_GenInputFiles
  14. }
  15. ##########################################################
  16. # Write the input file for the program the calculates
  17. # resistance/inductance.
  18. ##########################################################
  19. proc ::calcCAP::genInputFile { nodename } {
  20. set structureList $Stackup::structureList
  21. set totWidth 0.0
  22. set totHeight 0.0
  23. set nRectConds 0
  24. set nCircConds 0
  25. set nTrapConds 0
  26. set numDiels 0
  27. set condCount 1
  28. set condList ""
  29. set circList ""
  30. set trapList ""
  31. set conductivity 5e7
  32. foreach struct $structureList {
  33. #--------------------------------------------------------------
  34. # Add the heights of the ground-planes and dielectrics.
  35. #--------------------------------------------------------------
  36. if {[$struct isa GroundPlane] || [$struct isa DielectricLayer]} {
  37. if { [$struct height] == 0.0 } {
  38. error "Invalid zero height for $struct"
  39. }
  40. set totHeight [expr {$totHeight + [$struct height]}]
  41. if { [$struct isa DielectricLayer] } {
  42. incr numDiels
  43. }
  44. continue
  45. }
  46. if {[$struct isa RectangleDielectric]} {
  47. incr numDiels
  48. continue
  49. }
  50. #--------------------------------------------------------------
  51. # Get the largest conductor width and the shortest conductor
  52. # height.
  53. #--------------------------------------------------------------
  54. set width [$struct width]
  55. if { $width > $totWidth } {
  56. set totWidth $width
  57. }
  58. if { [$struct isa RectangleConductors] } {
  59. set conductivity [$struct cget -conductivity]
  60. set nRectConds [expr { $nRectConds + [$struct cget -number] }]
  61. }
  62. if { [$struct isa CircleConductors] } {
  63. set conductivity [$struct cget -conductivity]
  64. set nCircConds [expr { $nCircConds + [$struct cget -number] }]
  65. }
  66. if { [$struct isa TrapezoidConductors] } {
  67. set conductivity [$struct cget -conductivity]
  68. set nTrapConds [expr { $nTrapConds + [$struct cget -number] }]
  69. }
  70. }
  71. set expWidth [expr { $totWidth * 3 }]
  72. puts "Width: $totWidth ($expWidth) Height: $totHeight"
  73. set units $::Stackup::defaultLengthUnits
  74. puts "units: $units"
  75. #--------------------------------------------------------------
  76. # Convert lengths to SI units
  77. #--------------------------------------------------------------
  78. # array set scaleFactors "meters 1 microns 1e-6 inches 0.0254 mils 0.0254e-3 UNDEFINED UNDEFINED"
  79. set scaleFactors(meters) 1
  80. set scaleFactors(microns) 1e-6
  81. set scaleFactors(inches) 0.0254
  82. set scaleFactors(mils) 0.0254e-3
  83. set scaleFactors(UNDEFINED) UNDEFINED
  84. puts " $scaleFactors($units)"
  85. set scale $scaleFactors($units)
  86. puts "scale $scale"
  87. set capOut [open $nodename.cap.dat w]
  88. set inOut [open $nodename.cap.in w]
  89. set maxXcoord 700.00
  90. set maxYcoord 400.00
  91. #--------------------------------------------------------------
  92. # Total width
  93. # Total height
  94. #--------------------------------------------------------------
  95. puts $capOut "[expr { $expWidth * $scale }]"
  96. puts $capOut "[expr { $totHeight * $scale }]"
  97. #--------------------------------------------------------------
  98. # X scale factor
  99. # Y scale factor
  100. #--------------------------------------------------------------
  101. puts $capOut "[expr { $maxXcoord / ($expWidth * $scale) }]"
  102. puts $capOut "[expr { $maxYcoord / ($expWidth * $scale) }]"
  103. #--------------------------------------------------------------
  104. # x-offset
  105. # y-offset
  106. #--------------------------------------------------------------
  107. puts $capOut "-[expr { $totWidth * 0.5 * $scale }]"
  108. puts $capOut "0"
  109. #--------------------------------------------------------------
  110. # Nh : 1024 Wavelet point number
  111. # Nit : 40 Number of iterations
  112. # J : 6 Resolution level
  113. # Nwx : 8 Gauss quadrature x
  114. # Nwy : 10 Gauss quadrature y
  115. # Nws : 5 Number of segments/wavelet
  116. # Np : 0.0 OPQ seperation
  117. # Eps : 1.0e5 STAB accuracy
  118. # matr : 1 Matrix solution
  119. # od : 1.0e6 Order of approximation
  120. # maxga: 0 Maximum approximation range
  121. #--------------------------------------------------------------
  122. puts $capOut "1024"
  123. puts $capOut "40"
  124. puts $capOut "6"
  125. puts $capOut "8"
  126. puts $capOut "10"
  127. puts $capOut "5"
  128. puts $capOut "0.0"
  129. puts $capOut "1.0e5"
  130. puts $capOut "2"
  131. puts $capOut "5"
  132. puts $capOut "$conductivity"
  133. puts $capOut "$numDiels $nRectConds $nCircConds 0 0 $nTrapConds 1"
  134. puts $inOut "1"
  135. puts $inOut "$nRectConds"
  136. puts $inOut "$nCircConds"
  137. puts $inOut "$nTrapConds"
  138. #
  139. # Ground plane
  140. #
  141. puts $inOut "$numDiels"
  142. puts $inOut "0"
  143. puts $inOut "0"
  144. puts $inOut "[expr { $expWidth * $scale }]"
  145. puts $inOut "[expr { 10 * $scale }]"
  146. set yat 0.0
  147. set numConds 0
  148. set totCount 2
  149. set condCount 1
  150. set dielCount 1
  151. set dielList ""
  152. set trapList ""
  153. set dList ""
  154. set condList ""
  155. set circList ""
  156. set trapList ""
  157. foreach struct $structureList {
  158. #--------------------------------------------------------------
  159. # Ground Planes and Dielectrics
  160. #--------------------------------------------------------------
  161. if {[$struct isa GroundPlane]} {
  162. set yat [expr { $yat + [$struct height] }]
  163. continue
  164. }
  165. if { [$struct isa DielectricLayer] } {
  166. set thck [expr { [$struct cget -thickness] * $scale }]
  167. set perm [$struct cget -permittivity]
  168. set xat 0
  169. set width [expr {$expWidth * $scale }]
  170. set yloc [expr { $yat * $scale }]
  171. puts "yat: $yat yloc: $yloc totWidth: $totWidth"
  172. append dielList "DIELE $totCount\
  173. recTags$dielCount $dielCount $xat \
  174. $yloc $width \
  175. $thck $perm "
  176. append dList "$xat\n"
  177. append dList "$yloc\n"
  178. append dList "$width\n"
  179. append dList "$thck\n"
  180. append dList "$perm\n"
  181. incr totCount
  182. #incr dielCount
  183. set yat [expr { $yat + [$struct height] }]
  184. continue
  185. }
  186. if { [$struct isa RectangleDielectric] } {
  187. set thck [expr { [$struct cget -height] * $scale }]
  188. set perm [$struct cget -permittivity]
  189. set xat [expr { ( $totWidth + \
  190. [$struct cget -xOffset]) * $scale }]
  191. set width [expr {[$struct cget -width] * $scale}]
  192. set yloc [expr { $yat * $scale }]
  193. puts "yat: $yat yloc: $yloc totWidth: $totWidth"
  194. append dielList "DIELE $totCount\
  195. recTags$dielCount $dielCount $xat \
  196. $yloc $width \
  197. $thck $perm "
  198. append dList "$xat\n"
  199. append dList "$yloc\n"
  200. append dList "$width\n"
  201. append dList "$thck\n"
  202. append dList "$perm\n"
  203. incr totCount
  204. #incr dielCount
  205. continue
  206. }
  207. set numConds [expr { $numConds + [$struct cget -number] }]
  208. set xat [expr { ( $totWidth + \
  209. [$struct cget -xOffset]) * $scale }]
  210. set pitch [expr { [$struct cget -pitch] * $scale }]
  211. for { set ix 0 } { $ix < [$struct cget -number]} { incr ix } {
  212. if { [$struct isa RectangleConductors] } {
  213. set width [expr { [$struct cget -width] * $scale }]
  214. set height [expr { [$struct cget -height] * $scale }]
  215. set yloc [expr { $yat * $scale }]
  216. append condList "REC $totCount\
  217. recTags$condCount $condCount $xat \
  218. $yloc $width \
  219. $height "
  220. incr totCount
  221. #
  222. # rectangular conductor
  223. #
  224. puts $inOut "$xat"
  225. puts $inOut "$yloc"
  226. puts $inOut "$width"
  227. puts $inOut "$height"
  228. }
  229. if { [$struct isa CircleConductors] } {
  230. set radius [expr { [$struct cget -diameter] * $scale * 0.5 }]
  231. set yloc [expr { $yat * $scale }]
  232. append circList "CIR [expr { $condCount + 1 }]\
  233. recTags$condCount $condCount $xat \
  234. $yloc $radius "
  235. #
  236. # rectangular conductor
  237. #
  238. puts $inOut "$xat"
  239. puts $inOut "$yloc"
  240. puts $inOut "$radius"
  241. }
  242. if { [$struct isa TrapezoidConductors] } {
  243. set topwidth [expr { [$struct cget -topWidth] * $scale }]
  244. set botwidth [expr { [$struct cget -bottomWidth] * $scale }]
  245. set height [expr { [$struct cget -height] * $scale }]
  246. set ybot [expr { $yat * $scale }]
  247. set ytop [expr { $ybot + $height }]
  248. set xatT [expr { $xat - (($topwidth - $botwidth) * 0.5) }]
  249. set xrgt [expr { $xat + $botwidth }]
  250. set xrgtT [expr { $xatT + $topwidth }]
  251. append trapList "POLY $totCount\
  252. recTags$condCount $condCount 4 $xat $ybot $xat\
  253. $ytop $xrgtT $ytop $xrgt $ybot 0 "
  254. incr totCount
  255. #
  256. # rectangular conductor
  257. #
  258. puts $inOut "$xat"
  259. puts $inOut "$ybot"
  260. puts $inOut "$xat"
  261. puts $inOut "$ytop"
  262. puts $inOut "$xrgtT"
  263. puts $inOut "$ytop"
  264. puts $inOut "$xrgt"
  265. puts $inOut "$ybot"
  266. }
  267. set xat [expr { $xat + $pitch }]
  268. }
  269. }
  270. puts $capOut "$dielList"
  271. puts $capOut "$condList"
  272. puts $capOut "$circList"
  273. puts $capOut ""
  274. puts $capOut ""
  275. puts $capOut "$trapList"
  276. puts $capOut "GND 1 gndTags1 1 0 0 [expr { $expWidth * $scale }]\
  277. [expr { 10 * $scale }] 0"
  278. close $capOut
  279. set cmnd [format {%s1024} $dList]
  280. puts $inOut "$cmnd"
  281. puts $inOut "40"
  282. puts $inOut "6"
  283. puts $inOut "8"
  284. puts $inOut "10"
  285. puts $inOut "5"
  286. puts $inOut "0.0"
  287. puts $inOut "1.0e5"
  288. puts $inOut "1"
  289. puts $inOut "1.0e6"
  290. puts $inOut "$conductivity"
  291. close $inOut
  292. }
  293. proc ::calcCAP::calcCAP_RunGraphical { nodename } {
  294. global env
  295. set cmdName [file join $env(CALCCAP_LIBRARY) calcCAP_exe.tcl]
  296. set cmmnd {$cmdName $nodename.cap }
  297. puts "-$cmmnd-"
  298. if { [catch { eval exec $cmmnd} result] } {
  299. puts "Finished with clcrl.tcl"
  300. }
  301. puts $result
  302. }
  303. proc ::calcCAP::calcCAP_RunBatch { nodename } {
  304. global env
  305. set cmdName [auto_execok calcCAP]
  306. set ret [catch {exec $cmdName $nodename.cap} result]
  307. return $ret
  308. }