bem.tcl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # mmtl_bem.tcl
  4. #
  5. # Copyright 2002-2004 Mayo Foundation. All Rights Reserved.
  6. # $Id: bem.tcl,v 1.6 2004/05/05 19:31:11 techenti Exp $
  7. #
  8. #-----------------------------------------------------------------
  9. package require Itcl
  10. package require units
  11. package require csdl
  12. package require gui
  13. package provide bem 1.0
  14. namespace eval ::bem:: {
  15. variable BuildCount 0
  16. variable Title {}
  17. variable Csegs
  18. variable Psegs
  19. variable _iterateFrame
  20. variable _maxIterations
  21. variable _row 1
  22. variable _col 0
  23. variable _spFrame
  24. variable _curls
  25. variable _impedanceType
  26. variable _endImpedance
  27. variable _botWidthStart
  28. variable _botWidthIncr
  29. variable _startcl
  30. variable _endcl
  31. variable _numcl
  32. variable _startrt
  33. variable _endrt
  34. variable _numrt
  35. variable _startcs
  36. variable _endcs
  37. variable _numcs
  38. variable _startps
  39. variable _endps
  40. variable _numps
  41. variable _totalLoops
  42. variable _changesArr
  43. #--------------------------------------------
  44. # Allow for sweeping the thickness and permittivity
  45. # of the DielectricLayer object.
  46. #--------------------------------------------
  47. variable _arrDielThckList
  48. variable _arrDielPrmtList
  49. #--------------------------------------------
  50. # Allow for sweeping the width, height, conductivity
  51. # and pitch of a RectangleConductors object.
  52. #--------------------------------------------
  53. variable _arrRectWidthList
  54. variable _arrCircDiamList
  55. variable _arrTrapWidthTopList
  56. variable _arrTrapWidthBotList
  57. variable _iterateFrame
  58. #--------------------------------------------
  59. # Allow for sweeping the diameter, conductivity
  60. # and pitch of a CircleConductors object.
  61. #--------------------------------------------
  62. variable _arrCircDiamList
  63. variable _arrCircCndctList
  64. variable _arrCircPtchList
  65. variable _arrCircXoffList
  66. variable _arrCircYoffList
  67. #--------------------------------------------
  68. # Allow for sweeping the top and bottom width, height,
  69. # conductivity and pitch of a TrapezoidConductors object.
  70. #--------------------------------------------
  71. variable _arrTrapWidthTopList
  72. variable _arrTrapWidthBotList
  73. variable _arrTrapHeightList
  74. variable _arrTrapCndctList
  75. variable _arrTrapPtchList
  76. variable _arrTrapXoffList
  77. variable _arrTrapYoffList
  78. variable _arrStartList
  79. variable _arrEndList
  80. variable _arrNumList
  81. variable _doClngLgt
  82. variable _doRseTme
  83. variable _doCseg
  84. variable _doPseg
  85. variable _sweepFrame
  86. #-------------------------------------------------------
  87. # Used in the script generated for a sweep or an iterate
  88. #-------------------------------------------------------
  89. namespace export _changesArr
  90. namespace export bemDeleteAll
  91. namespace export bemFinishSimulation
  92. namespace export bemWriteGraphicFile
  93. namespace export bemRunSimulation
  94. namespace export bemRunSimulationCS
  95. namespace export bemViewPlotPotential
  96. namespace export bemViewGraph
  97. namespace export bemRunIterateMMTL
  98. namespace export bemRunSweepMMTL
  99. namespace export bemParseSweptResults
  100. namespace export bemParseIterationResults
  101. namespace export bemPutRectangleConductorsToFile
  102. namespace export bemPutCircleConductorsToFile
  103. namespace export bemPutTrapezodConductorsToFile
  104. namespace export bemPutDielectricLayerToFile
  105. namespace export bemPutGroundPlaneToFile
  106. namespace export bemReadFile
  107. namespace export bemShowResultsFile
  108. namespace export bemWriteSweptParameterFile
  109. }
  110. ##########################################################
  111. #
  112. # bemReadFile
  113. # Write the xsctn file
  114. #
  115. # nodename: file name without the extension
  116. #
  117. ##########################################################
  118. proc ::bem::bemReadFile { nodename } {
  119. ::bem::bemDeleteAll
  120. #---------------------------------------------------------
  121. # Set the default units to match the gui-defined units for
  122. # length.
  123. #---------------------------------------------------------
  124. set ::units::default(Length) $::Stackup::defaultLengthUnits
  125. set ::units::default(Time) ps
  126. ::csdl::csdlReadTCL $nodename.xsctn
  127. }
  128. ##########################################################
  129. #
  130. # bemDeleteAll
  131. # Delete all the objects created by the xsctn file
  132. #
  133. ##########################################################
  134. proc ::bem::bemDeleteAll {} {
  135. foreach snme $::Stackup::structureList {
  136. set lgt [string length $snme]
  137. set nme [string range $snme 2 $lgt]
  138. itcl::delete object $nme
  139. }
  140. set ::Stackup::structureList {}
  141. set lst [itcl::find objects]
  142. foreach itm $lst {
  143. itcl::delete object $itm
  144. }
  145. }
  146. ##########################################################
  147. #
  148. # bemWriteGraphicFile
  149. # Write the graphic file needed by the bem simulator
  150. #
  151. # nodename: file name without the extension
  152. #
  153. ##########################################################
  154. proc ::bem::bemWriteGraphicFile { nodename } {
  155. #---------------------------------------------------------
  156. # Set the default units to match the gui-defined units for
  157. # length.
  158. #---------------------------------------------------------
  159. set ::units::default(Length) $::Stackup::defaultLengthUnits
  160. set ::units::default(Time) ps
  161. #------------------------------------------------------------
  162. # Delete the previous object (if exists)
  163. #------------------------------------------------------------
  164. catch { itcl::delete object gpgeObj } result
  165. #------------------------------------------------------------
  166. # Create the gpge object
  167. #------------------------------------------------------------
  168. gpge gpgeObj
  169. set filename $nodename.graphic
  170. #------------------------------------------------------------
  171. # Create the output for the graphic file.
  172. #------------------------------------------------------------
  173. set grph [gpgeObj graphic $filename]
  174. #------------------------------------------------------------
  175. # Open the graphic file and write the information to the file.
  176. #------------------------------------------------------------
  177. set fp [open $filename w]
  178. puts $fp $grph
  179. close $fp
  180. puts "The write of $filename is complete!"
  181. return 0
  182. }
  183. ##################################################################
  184. #
  185. # bemRunSimulation
  186. #
  187. # nodename : file name without the extension
  188. # num_c_segs: number of contour segments
  189. # num_p_segs: number of plane/dielectric segments
  190. #
  191. ##################################################################
  192. proc ::bem::bemRunSimulationCS { nodename {num_c_segs 10} {num_p_segs 10} } {
  193. global env
  194. #---------------------------------------------------
  195. # This application sends some of it's output to stderr
  196. # so the exec will return with an error or 1. The
  197. # catch solves this problem.
  198. #---------------------------------------------------
  199. set exeName [auto_execok bem]
  200. set rtn [::bem::bemFinishSimulation $exeName $nodename \
  201. $num_c_segs $num_p_segs]
  202. return $rtn
  203. }
  204. ##################################################################
  205. #
  206. # bemRunSimulation
  207. #
  208. # nodename : file name without the extension
  209. # num_c_segs: number of contour segments
  210. # num_p_segs: number of plane/dielectric segments
  211. #
  212. ##################################################################
  213. proc ::bem::bemRunSimulation { nodename {num_c_segs 10} {num_p_segs 10} } {
  214. global env
  215. #---------------------------------------------------
  216. # This application sends some of it's output to stderr
  217. # so the exec will return with an error or 1. The
  218. # catch solves this problem.
  219. #---------------------------------------------------
  220. set exeName [file join $env(BEM_LIBRARY) nmmtl]
  221. set rtn [::bem::bemFinishSimulation $exeName $nodename \
  222. $num_c_segs $num_p_segs]
  223. return $rtn
  224. }
  225. ##################################################################
  226. #
  227. # bemFinishSimulation
  228. #
  229. ##################################################################
  230. proc ::bem::bemFinishSimulation { exeName nodename num_c_segs num_p_segs } {
  231. set cmmnd {$exeName $nodename $num_c_segs $num_p_segs}
  232. puts "----------------------------------------------------"
  233. puts "Command: $exeName $nodename $num_c_segs $num_p_segs"
  234. puts "----------------------------------------------------"
  235. set returnStatus 0
  236. set status [catch { eval exec $cmmnd} result ]
  237. puts "status: $status result: $result"
  238. if { $status || ([string first "MMTL is done" $result] == 0) } {
  239. puts stderr "The simulation (Node: $nodename CSEG: $num_c_segs\
  240. PSEG: $num_p_segs) has failed!"
  241. puts stderr $result
  242. set returnStatus 1
  243. } else {
  244. puts "The simulation of $nodename (CSEG: $num_c_segs\
  245. PSEG: $num_p_segs) is done!"
  246. }
  247. set fp [open $nodename.result_log w]
  248. ::gui::_logDesignAttributes $fp
  249. puts $fp $result
  250. close $fp
  251. return $returnStatus
  252. }
  253. ##################################################################
  254. #
  255. # bemViewPlotPotential
  256. #
  257. # nodename: file name without the extension
  258. #
  259. ##################################################################
  260. proc ::bem::bemViewPlotPotential { nodename } {
  261. global env
  262. set cmdName [file join $env(BEM_LIBRARY) staticFieldPlot.exe]
  263. set cmmnd {$cmdName $nodename.result_field_plot_data}
  264. set returnStatus 0
  265. if { [catch { eval exec $cmmnd} result] } {
  266. puts "Finished display of $nodename.result_field_plot_data\
  267. with staticFieldPlot."
  268. } else {
  269. puts "Display of $nodename.result_field_plot_data with\
  270. staticFieldPlot has failed!"
  271. set returnStatus 1
  272. }
  273. return $returnStatus
  274. }
  275. ##################################################################
  276. ##################################################################
  277. proc ::bem::bemShowResultsFile { filename } {
  278. if { ! [file exists $filename] } {
  279. puts stderr "$filename doesn't exist!"
  280. return 1
  281. }
  282. set fp [open $filename r]
  283. set result [read $fp]
  284. close $fp
  285. puts "------------------ $filename --------------------------"
  286. puts $result
  287. return $result
  288. }
  289. ##################################################################
  290. #
  291. # bemViewGraph
  292. #
  293. # filename: file name of swept or iterated results data
  294. #
  295. ##################################################################
  296. proc ::bem::bemViewGraph { filename } {
  297. global env
  298. set cmdName [file join $env(BEM_LIBRARY) bem_view.tcl]
  299. set cmmnd "$cmdName $filename"
  300. set returnStatus 0
  301. if { [ catch { eval exec $cmmnd} result] } {
  302. puts "Finished display of $filename with\
  303. $env(BEM_LIBRARY)/bem_view.tcl"
  304. } else {
  305. puts "Display of $filename with\
  306. $env(BEM_LIBRARY)/bem_view.tcl has failed.!"
  307. set returnStatus 1
  308. }
  309. return $returnStatus
  310. }