calcRL.tcl 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # calcRL.tcl
  4. #
  5. # Copyright 2002-2004 Mayo Foundation. All Rights Reserved.
  6. # $Id: calcRL.tcl,v 1.8 2004/07/29 13:03:14 techenti Exp $
  7. #
  8. #-----------------------------------------------------------------
  9. package require Itcl
  10. package provide calcRL 1.0
  11. namespace eval ::calcRL:: {
  12. namespace export runBatch
  13. namespace export genInputFiles
  14. }
  15. ##########################################################
  16. # Write the input file for the program the calculates
  17. # resistance/inductance.
  18. ##########################################################
  19. proc ::calcRL::genInputFile { nodename frequency } {
  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 condCount 1
  27. set condList ""
  28. set circList ""
  29. set trapList ""
  30. set conductivity 5e7
  31. foreach struct $structureList {
  32. #--------------------------------------------------------------
  33. # Add the heights of the ground-planes and dielectrics.
  34. #--------------------------------------------------------------
  35. if {[$struct isa GroundPlane] || [$struct isa DielectricLayer]} {
  36. set totHeight [expr {$totHeight + [$struct height]}]
  37. continue
  38. }
  39. #--------------------------------------------------------------
  40. # Get the largest conductor width and the shortest conductor
  41. # height.
  42. #--------------------------------------------------------------
  43. set width [$struct width]
  44. if { $width > $totWidth } {
  45. set totWidth $width
  46. }
  47. if { [$struct isa RectangleConductors] } {
  48. set conductivity [$struct cget -conductivity]
  49. set nRectConds [expr { $nRectConds + [$struct cget -number] }]
  50. }
  51. if { [$struct isa CircleConductors] } {
  52. set conductivity [$struct cget -conductivity]
  53. set nCircConds [expr { $nCircConds + [$struct cget -number] }]
  54. }
  55. if { [$struct isa TrapezoidConductors] } {
  56. set conductivity [$struct cget -conductivity]
  57. set nTrapConds [expr { $nTrapConds + [$struct cget -number] }]
  58. }
  59. }
  60. set expWidth [expr { $totWidth * 3 }]
  61. puts "Width: $totWidth ($expWidth) Height: $totHeight"
  62. set units $::Stackup::defaultLengthUnits
  63. puts "units: $units"
  64. #--------------------------------------------------------------
  65. # Convert lengths to SI units
  66. #--------------------------------------------------------------
  67. set scaleFactors(meters) 1
  68. set scaleFactors(microns) 1e-6
  69. set scaleFactors(inches) 0.0254
  70. set scaleFactors(mils) 0.0254e-3
  71. set scaleFactors(UNDEFINED) UNDEFINED
  72. puts " $scaleFactors($units)"
  73. set scale $scaleFactors($units)
  74. puts "scale $scale"
  75. set maxXcoord 700.00
  76. set maxYcoord 400.00
  77. set rlOut [open $nodename.ri.dat w]
  78. set inOut [open $nodename.ri.in w]
  79. puts $rlOut "[expr { $expWidth * $scale }]"
  80. puts $rlOut "[expr { $totHeight * $scale }]"
  81. puts $rlOut "[expr { $maxXcoord / ($expWidth * $scale) }]"
  82. puts $rlOut "[expr { $maxYcoord / ($expWidth * $scale) }]"
  83. ## puts $rlOut "[expr { $totWidth / $scale }]"
  84. ## puts $rlOut "[expr { $totWidth / $scale }]"
  85. puts $rlOut "-[expr { $totWidth * 0.5 * $scale }]"
  86. puts $rlOut "0"
  87. puts $rlOut "1024"
  88. puts $rlOut "40"
  89. puts $rlOut "6"
  90. puts $rlOut "8"
  91. puts $rlOut "10"
  92. puts $rlOut "5"
  93. puts $rlOut "0.0"
  94. puts $rlOut "1.0e5"
  95. puts $rlOut "1"
  96. puts $rlOut "1.0e6"
  97. puts $rlOut "$conductivity"
  98. puts $rlOut "0 $nRectConds $nCircConds 0 0 $nTrapConds 1"
  99. puts $rlOut ""
  100. puts $inOut "1"
  101. puts $inOut "$nRectConds"
  102. puts $inOut "$nCircConds"
  103. puts $inOut "$nTrapConds"
  104. #
  105. # Ground plane
  106. #
  107. puts $inOut "0"
  108. puts $inOut "0"
  109. puts $inOut "[expr { $expWidth * $scale }]"
  110. puts $inOut "[expr { 10 * $scale }]"
  111. puts $inOut "0"
  112. set yat 0.0
  113. set numConds 0
  114. set condCount 1
  115. set condList ""
  116. set circList ""
  117. set trapList ""
  118. foreach struct $structureList {
  119. #--------------------------------------------------------------
  120. # Ground Planes and Dielectrics
  121. #--------------------------------------------------------------
  122. if {[$struct isa GroundPlane] || [$struct isa DielectricLayer]} {
  123. set yat [expr {$yat + [$struct height]}]
  124. continue
  125. }
  126. if {[$struct isa RectangleDielectric]} {
  127. continue
  128. }
  129. set numConds [expr { $numConds + [$struct cget -number] }]
  130. set xat [expr { ( $totWidth + \
  131. [$struct cget -xOffset]) * $scale }]
  132. set pitch [expr { [$struct cget -pitch] * $scale }]
  133. for { set ix 0 } { $ix < [$struct cget -number]} { incr ix } {
  134. if { [$struct isa RectangleConductors] } {
  135. set width [expr { [$struct cget -width] * $scale }]
  136. set height [expr { [$struct cget -height] * $scale }]
  137. set yloc [expr { $yat * $scale }]
  138. append condList "REC [expr { $condCount + 1 }]\
  139. recTags$condCount $condCount $xat \
  140. $yloc $width \
  141. $height 0 "
  142. #
  143. # rectangular conductor
  144. #
  145. puts $inOut "$xat"
  146. puts $inOut "$yloc"
  147. puts $inOut "$width"
  148. puts $inOut "$height"
  149. puts $inOut "0"
  150. }
  151. if { [$struct isa CircleConductors] } {
  152. set radius [expr { [$struct cget -diameter] * $scale * 0.5 }]
  153. set yloc [expr { $yat * $scale }]
  154. append circList "CIR [expr { $condCount + 1 }]\
  155. recTags$condCount $condCount $xat \
  156. $yloc $radius 0 "
  157. #
  158. # rectangular conductor
  159. #
  160. puts $inOut "$xat"
  161. puts $inOut "$yloc"
  162. puts $inOut "$radius"
  163. puts $inOut "0"
  164. }
  165. if { [$struct isa TrapezoidConductors] } {
  166. set topwidth [expr { [$struct cget -topWidth] * $scale }]
  167. set botwidth [expr { [$struct cget -bottomWidth] * $scale }]
  168. set height [expr { [$struct cget -height] * $scale }]
  169. set ybot [expr { $yat * $scale }]
  170. set ytop [expr { $ybot + $height }]
  171. set xatT [expr { $xat - (($topwidth - $botwidth) * 0.5) }]
  172. set xrgt [expr { $xat + $botwidth }]
  173. set xrgtT [expr { $xatT + $topwidth }]
  174. append trapList "POLY [expr { $condCount + 1 }]\
  175. recTags$condCount $condCount 4 $xat $ybot $xat\
  176. $ytop $xrgtT $ytop $xrgt $ybot 0 "
  177. #
  178. # rectangular conductor
  179. #
  180. puts $inOut "$xat"
  181. puts $inOut "$ybot"
  182. puts $inOut "$xat"
  183. puts $inOut "$ytop"
  184. puts $inOut "$xrgtT"
  185. puts $inOut "$ytop"
  186. puts $inOut "$xrgt"
  187. puts $inOut "$ybot"
  188. puts $inOut "0"
  189. }
  190. set xat [expr { $xat + $pitch }]
  191. }
  192. }
  193. puts $rlOut "$condList"
  194. puts $rlOut "$circList"
  195. puts $rlOut ""
  196. puts $rlOut ""
  197. puts $rlOut "$trapList"
  198. puts $rlOut "GND 1 gndTags1 1 0 0 [expr { $expWidth * $scale }]\
  199. [expr { 10 * $scale }] 0"
  200. close $rlOut
  201. puts $inOut "1024"
  202. puts $inOut "40"
  203. puts $inOut "6"
  204. puts $inOut "8"
  205. puts $inOut "10"
  206. puts $inOut "5"
  207. puts $inOut "0.0"
  208. puts $inOut "1.0e5"
  209. puts $inOut "1"
  210. puts $inOut "$frequency"
  211. puts $inOut "$conductivity"
  212. close $inOut
  213. }
  214. proc ::calcRL::calcRL_RunGraphical { nodename } {
  215. global env
  216. puts "Running the graphical version of calcRL!"
  217. set cmdName [file join $env(CALCRL_LIBRARY) calcRL_exe.tcl]
  218. set cmmnd {$cmdName $nodename.ri.dat}
  219. if { [catch { eval exec $cmmnd} result] } {
  220. puts "Finished with calcRL_exe.tcl"
  221. }
  222. puts $result
  223. puts "Display the data using xmgr!"
  224. set cmdName [file join $env(CALCRL_LIBRARY) xmgrPlotParameters]
  225. set cmmnd {$cmdName $nodename.ri.out}
  226. if { [catch { eval exec $cmmnd} result] } {
  227. puts "xmgr display does not work!"
  228. }
  229. puts $result
  230. }
  231. proc ::calcRL::runBatch { nodename } {
  232. set cmdName [auto_execok calcRL]
  233. set ret [catch {exec $cmdName $nodename.ri} result]
  234. return $ret
  235. }