bem_iterate.tcl 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923
  1. #----------------------------------------------*-TCL-*------------
  2. #
  3. # mmtl_iterate.tcl
  4. #
  5. # Copyright 2002-2004 Mayo Foundation. All Rights Reserved.
  6. # $Id: bem_iterate.tcl,v 1.6 2004/07/22 21:44:47 techenti Exp $
  7. #
  8. #----------------------------------------------*-TCL-*------------
  9. package require Itcl
  10. package require csdl
  11. package provide bem 1.0
  12. ############################################################################
  13. # Build the gui interface containing all items that the
  14. # application can iterate.
  15. #
  16. # nodename: name of the cross-section file (without the extension)
  17. # cSegs : number of C segments to mesh
  18. # pSegs : number of P segments to mesh
  19. # doGui : 1 - being run from mmtl.tcl 0 - outside of mmtl.tcl
  20. # parent : widget id or 0
  21. #
  22. ############################################################################
  23. proc ::bem::bemRunIterateMMTL { nodename cSegs pSegs {doGui 0} {parent 0} \
  24. {wdgt 0} } {
  25. set ::bem::Csegs $cSegs
  26. set ::bem::Psegs $pSegs
  27. set ::bem::Gui $doGui
  28. set ::bem::Parent $parent
  29. if { $::bem::Gui } {
  30. # set the cursor bitmap to busy
  31. #::gui::guiSetCursorBusy $parent
  32. # pop-up the window showing the program is busy
  33. #::gui::guiPopupBusy $wdgt "Running an iteration........"
  34. }
  35. #--------------------------------------------
  36. # Allow for iterating the width, height, conductivi
  37. # and pitch of a RectangleConductors object.
  38. #--------------------------------------------
  39. set ::bem::BuildCount 0
  40. #------------------------------------------------------------
  41. # unset any data from previous runs.
  42. #------------------------------------------------------------
  43. array unset ::bem::_arrStartList
  44. array unset ::bem::_arrEndImpList
  45. array unset ::bem::_arrEndOddImpList
  46. array unset ::bem::_arrEndEvenImpList
  47. array unset ::bem::_arrNumList
  48. array unset ::bem::_arrRectWidthList
  49. array unset ::bem::_arrCircDiamList
  50. array unset ::bem::_arrTrapWidthTopList
  51. array unset ::bem::_arrTrapWidthBotList
  52. #--------------------------------------------------------------
  53. # Build the iteration window.
  54. #--------------------------------------------------------------
  55. set ::bem::_iterateDialog [Dialog .iterate -title "BEM MMTL Iterations" \
  56. -side bottom -anchor e -cancel 1]
  57. $::bem::_iterateDialog add -text "Ok"
  58. $::bem::_iterateDialog add -text "Cancel"
  59. set f [$::bem::_iterateDialog getframe]
  60. grid [label $f.title -text "Select Iteration Parameter"]
  61. #--------------------------------------------------------------
  62. # Build a check-box for each attribute the user may change. The
  63. # values that may change are the dimensions on the conductors, but
  64. # the user must pick only one.
  65. #--------------------------------------------------------------
  66. set rbcount 0
  67. foreach itm [itcl::find objects -class RectangleConductors] {
  68. set ::bem::_arrRectWidthList($itm) 0
  69. incr rbcount
  70. set rb [radiobutton $f.rb$rbcount -text "$itm width" \
  71. -variable ::bem::_iterateObject -value "$itm"]
  72. grid $rb -sticky w
  73. }
  74. foreach itm [itcl::find objects -class CircleConductors] {
  75. set ::bem::_arrCircDiamList($itm) 0
  76. incr rbcount
  77. set rb [radiobutton $f.rb$rbcount -text "$itm diameter" \
  78. -variable ::bem::_iterateObject -value "$itm"]
  79. grid $rb -sticky w
  80. }
  81. foreach itm [itcl::find objects -class TrapezoidConductors] {
  82. set ::bem::_arrTrapWidthTopList($itm) 0
  83. incr rbcount
  84. set rb [radiobutton $f.rb$rbcount -text "$itm Top Width" \
  85. -variable ::bem::_iterateObject -value "$itm"]
  86. grid $rb -sticky w
  87. }
  88. #--------------------------------------------------------------
  89. # Display the dialog
  90. #--------------------------------------------------------------
  91. set result [$::bem::_iterateDialog draw]
  92. destroy $::bem::_iterateDialog
  93. if { $result == 0 } {
  94. # decode the selected item into a flag that corresponds
  95. # to the way that _doIterate wants to get the data.
  96. set obj $::bem::_iterateObject
  97. set class [$obj info class]
  98. switch -- $class {
  99. ::RectangleConductors {set ::bem::_arrRectWidthList($obj) 1}
  100. ::CircleConductors {set ::bem::_arrCircDiamList($obj) 1}
  101. ::TrapezoidConductors {set ::bem::_arrTrapWidthTopList($obj) 1}
  102. }
  103. ::bem::_doIterate
  104. }
  105. }
  106. ############################################################################
  107. # _setArgToProcess
  108. # flg - 0 Process a rectangle.
  109. # 1 Process a circle
  110. # 2 Process a trapezoid
  111. ############################################################################
  112. proc ::bem::_setArgToProcess { flg } {
  113. switch -- $flg {
  114. 0 {
  115. foreach itm [itcl::find objects -class CircleConductors] {
  116. set ::bem::_arrCircDiamList($itm) 0
  117. }
  118. foreach itm [itcl::find objects -class TrapezoidConductors] {
  119. set ::bem::_arrTrapWidthTopList($itm) 0
  120. }
  121. }
  122. 1 {
  123. foreach itm [itcl::find objects -class RectangleConductors] {
  124. set ::bem::_arrRectWidthList($itm) 0
  125. }
  126. foreach itm [itcl::find objects -class TrapezoidConductors] {
  127. set ::bem::_arrTrapWidthTopList($itm) 0
  128. }
  129. }
  130. 2 {
  131. foreach itm [itcl::find objects -class RectangleConductors] {
  132. set ::bem::_arrRectWidthList($itm) 0
  133. }
  134. foreach itm [itcl::find objects -class CircleConductors] {
  135. set ::bem::_arrCircDiamList($itm) 0
  136. }
  137. foreach itm [itcl::find objects -class TrapezoidConductors] {
  138. set ::bem::_arrTrapWidthBotList($itm) 0
  139. }
  140. }
  141. }
  142. update
  143. }
  144. ############################################################################
  145. ############################################################################
  146. proc ::bem::_doIterate {} {
  147. set ::bem::_row 1
  148. set ::bem::_col 0
  149. set ::bem::_spFrame [toplevel .width \
  150. -relief sunken -borderwidth 5]
  151. wm iconname $::bem::_spFrame "Iterate1"
  152. wm iconify $::bem::_spFrame
  153. #--------------------------------------------
  154. # Allow for iterating the width of a
  155. # RectangleConductors object.
  156. #--------------------------------------------
  157. foreach nme [itcl::find objects -class RectangleConductors] {
  158. if { $::bem::_arrRectWidthList($nme) } {
  159. ::bem::_buildIterateEntryFrame $nme RW [$nme cget -width] \
  160. "$nme Width"
  161. }
  162. }
  163. #--------------------------------------------
  164. # Allow for iterating the diameter of a
  165. # CircleConductors object.
  166. #--------------------------------------------
  167. foreach nme [itcl::find objects -class CircleConductors] {
  168. if { $::bem::_arrCircDiamList($nme) } {
  169. ::bem::_buildIterateEntryFrame $nme CD \
  170. [$nme cget -diameter] \
  171. "$nme Diameter"
  172. }
  173. }
  174. #--------------------------------------------
  175. # Allow for iterating the top width
  176. # of a TrapezoidConductors object.
  177. #--------------------------------------------
  178. foreach nme [itcl::find objects -class TrapezoidConductors] {
  179. if { $::bem::_arrTrapWidthTopList($nme) } {
  180. ::bem::_buildIterateEntryFrame $nme TWT \
  181. [$nme cget -topWidth] \
  182. "$nme TopWidth" [$nme cget -bottomWidth]
  183. }
  184. }
  185. set but1 [::gui::guiBuildButton $::bem::_spFrame "OK" \
  186. "::bem::_finishIterate" "Proceed with the requested iterate"]
  187. set but2 [::gui::guiBuildButton $::bem::_spFrame "Cancel" \
  188. "::bem::_cancelBldIterate" "Cancel the iterate"]
  189. grid $but1 $but2 -sticky nw
  190. wm deiconify $::bem::_spFrame
  191. grab $::bem::_spFrame
  192. }
  193. ############################################################################
  194. ############################################################################
  195. proc ::bem::_buildIterateEntryFrame { nme type value txtStrg {botwidth ""} } {
  196. set ::bem::_maxIterations 100
  197. set indx [format "%s-$type" $nme]
  198. set ::bem::_arrStartList($indx) $value
  199. set ::bem::_arrIncrList($indx) 0
  200. set ::bem::_arrEndImpList($indx) 0
  201. set ::bem::_arrEndOddImpList($indx) 0
  202. set ::bem::_arrEndEvenImpList($indx) 0
  203. ::bem::_buildIterateParameters $::bem::_spFrame $txtStrg \
  204. ::bem::_arrStartList($indx) ::bem::_arrIncrList($indx) \
  205. ::bem::_arrEndImpList($indx) ::bem::_arrEndOddImpList($indx) \
  206. ::bem::_arrEndEvenImpList($indx) ::bem::_maxIterations $botwidth
  207. }
  208. ############################################################################
  209. ############################################################################
  210. proc ::bem::_cancelBldIterate {} {
  211. destroy $::bem::_spFrame
  212. }
  213. ############################################################################
  214. ############################################################################
  215. proc ::bem::_buildIterateParameters { parent title startVar incrVar \
  216. imp1 imp2 imp3 maxIter botwidth } {
  217. incr ::bem::BuildCount
  218. set frme [frame $parent.frme$::bem::BuildCount]
  219. set seglbl [Label $frme.seglbl$::bem::BuildCount \
  220. -justify center -text $title]
  221. grid $seglbl -columnspan 2 -sticky w
  222. set startlab [label $frme.startlab -text "Starting Value"]
  223. set startent [entry $frme.startent -textvariable $startVar]
  224. grid $startlab $startent -sticky news -padx 2 -pady 2
  225. set inclab [label $frme.inclab -text "Increment"]
  226. set incent [entry $frme.incent -textvariable $incrVar]
  227. grid $inclab $incent -sticky news -padx 2 -pady 2
  228. #-------------------------------------------------------------------
  229. # Is the object being processed a trapezoid?
  230. #-------------------------------------------------------------------
  231. if { [string length $botwidth] > 0 } {
  232. set ::bem::_botWidthStart $botwidth
  233. set botstartlab [label $frme.botstartlab -text "Starting Bottom Width"]
  234. set botstartent [entry $frme.botstartent \
  235. -textvariable ::bem::_botWidthStart]
  236. grid $botstartlab $botstartent -sticky news -padx 2 -pady 2
  237. set ::bem::_botWidthIncr 0
  238. set botinclab [label $frme.botinclab -text "Increment Bottom Width"]
  239. set botincent [entry $frme.botincent \
  240. -textvariable ::bem::_botWidthIncr]
  241. grid $botinclab $botincent -sticky news -padx 2 -pady 2
  242. }
  243. set lblImp [label $frme.lblImp \
  244. -text "Enter value for only one of 3 impedance fields"]
  245. grid $lblImp -columnspan 2 -sticky w
  246. set imp1lab [label $frme.imp1lab -text "Target Impedance"]
  247. set imp1ent [entry $frme.imp1ent -textvariable $imp1]
  248. grid $imp1lab $imp1ent -sticky news -padx 2 -pady 2
  249. set imp2lab [label $frme.imp2lab -text "Target Odd Impedance"]
  250. set imp2ent [entry $frme.imp2ent -textvariable $imp2]
  251. grid $imp2lab $imp2ent -sticky news -padx 2 -pady 2
  252. set imp3lab [label $frme.imp3lab -text "Target Even Impedance"]
  253. set imp3ent [entry $frme.imp3ent -textvariable $imp3]
  254. grid $imp3lab $imp3ent -sticky news -padx 2 -pady 2
  255. set numlab [label $frme.numlab -text "Maximum # of Iterations"]
  256. set nument [entry $frme.nument -textvariable $maxIter]
  257. grid $numlab $nument -sticky news -padx 2 -pady 2
  258. grid $frme -row $::bem::_row -column $::bem::_col -sticky new
  259. if { $::bem::_col == 0 } {
  260. set ::bem::_col 1
  261. } else {
  262. incr ::bem::_row
  263. set ::bem::_col 0
  264. }
  265. }
  266. ############################################################################
  267. ############################################################################
  268. proc ::bem::_buildIterateScript { fp nme value strt incrv impedanceType \
  269. endImpedance } {
  270. #--------------------------------------------------------
  271. # Call the length function in case a conversion is needed.
  272. #--------------------------------------------------------
  273. set vala [length $strt]
  274. set incra [length $incrv]
  275. if { $vala <= 0 } {
  276. ::gui::guiPopupWarning \
  277. "The x dimension must be greater than 0."
  278. return 1
  279. }
  280. if { $incra == 0 } {
  281. ::gui::guiPopupWarning \
  282. "The increment cannot be 0."
  283. return 1
  284. }
  285. if { $endImpedance <= 0 } {
  286. ::gui::guiPopupWarning \
  287. "The impedance cannot be 0."
  288. return 1
  289. }
  290. if { ([scan $::bem::_maxIterations {%d} numLoops] != 1) || \
  291. ($numLoops < 1) } {
  292. ::gui::guiPopupWarning \
  293. "The # of iterations must an integer > 0."
  294. return 1
  295. }
  296. if { [string compare $value "topWidth"] == 0 } {
  297. #--------------------------------------------------------
  298. # Call the length function in case a conversion is needed.
  299. #--------------------------------------------------------
  300. set valb [length $::bem::_botWidthStart]
  301. set incrb [length $::bem::_botWidthIncr]
  302. if { $valb <= 0 } {
  303. ::gui::guiPopupWarning \
  304. "The x dimension must be greater than 0."
  305. return 1
  306. }
  307. if { $incrb == 0 } {
  308. ::gui::guiPopupWarning \
  309. "The increment cannot be 0."
  310. return 1
  311. }
  312. }
  313. #---------------------------------------------------------
  314. # Number of nested loops being created in the processing
  315. # script.
  316. #---------------------------------------------------------
  317. incr ::bem::_curls
  318. #---------------------------------------------------------
  319. # Create the for loop.
  320. #---------------------------------------------------------
  321. puts $fp " set val$::bem::_curls $vala"
  322. if { [string compare $value "topWidth"] == 0 } {
  323. puts $fp " set valbot $valb"
  324. }
  325. puts $fp " set impType $impedanceType"
  326. puts $fp " set closeTo $endImpedance"
  327. puts $fp " set oldDiff 99999999"
  328. puts $fp " set diff 88888888"
  329. puts $fp " set oldImp 0"
  330. puts $fp " set loopct 0"
  331. set strg [ format " while \{ 1 \} \{"]
  332. puts $fp $strg
  333. puts $fp " $nme configure -$value \$val$::bem::_curls "
  334. if { [string compare $value "topWidth"] == 0 } {
  335. puts $fp " $nme configure -bottomWidth \$valbot"
  336. }
  337. puts $fp " set cname $nme"
  338. puts $fp " set cdimName $value"
  339. puts $fp " set cdimValue \$val$::bem::_curls"
  340. puts $fp " set val$::bem::_curls \[ expr \{ \$val$::bem::_curls + $incra \}\]"
  341. if { [string compare $value "topWidth"] == 0 } {
  342. puts $fp " puts \"Conductor $nme: botWidth of \$valbot\""
  343. puts $fp " set valbot \[ expr \{ \$valbot + $incrb \}\]"
  344. }
  345. return 0
  346. }
  347. ############################################################################
  348. ############################################################################
  349. proc ::bem::_setWhichImpedance { indx } {
  350. set ::bem::_impedanceType 0
  351. set prefix " "
  352. set ::bem::_endImpedance $::bem::_arrEndImpList($indx)
  353. if { $::bem::_arrEndOddImpList($indx) > 0 } {
  354. set ::bem::_impedanceType 1
  355. set prefix " Odd"
  356. set ::bem::_endImpedance $::bem::_arrEndOddImpList($indx)
  357. }
  358. if { $::bem::_arrEndEvenImpList($indx) > 0 } {
  359. set ::bem::_impedanceType 2
  360. set prefix " Even"
  361. set ::bem::_endImpedance $::bem::_arrEndEvenImpList($indx)
  362. }
  363. return $prefix
  364. }
  365. ############################################################################
  366. ############################################################################
  367. proc ::bem::_finishIterate {} {
  368. set ::bem::_curls 0
  369. set flenme "$::gui::_nodename.iterate_script"
  370. set fp [open $flenme w]
  371. puts $fp "proc _runIterate \{\} \{"
  372. puts $fp " global _nodename"
  373. puts $fp " global _num_c_segs"
  374. puts $fp " global _num_p_segs"
  375. puts $fp " global oldDiff"
  376. puts $fp " global oldImp"
  377. puts $fp ""
  378. puts $fp " set resultsFle \[ open \"$::gui::_nodename.iterate_result\" w \] "
  379. puts $fp " set logFle \[ open \"$::gui::_nodename.iterate_result_log\" w \] "
  380. puts $fp " puts \"_____________________________________________\""
  381. #--------------------------------------------
  382. # Allow for iterating the width, height, conductivity
  383. # and pitch of a RectangleConductors object.
  384. #--------------------------------------------
  385. foreach nme [itcl::find objects -class RectangleConductors] {
  386. if { $::bem::_arrRectWidthList($nme) } {
  387. set indx [ format "%s-RW" $nme ]
  388. set prefix [_setWhichImpedance $indx]
  389. puts $fp " # RectangleConductors $nme \
  390. start: $::bem::_arrStartList($indx) \
  391. incr: $::bem::_arrIncrList($indx) \
  392. $prefix Impedance close to: $::bem::_endImpedance"
  393. if { [_buildIterateScript $fp $nme "width" $::bem::_arrStartList($indx) \
  394. $::bem::_arrIncrList($indx) $::bem::_impedanceType $::bem::_endImpedance ] } {
  395. return
  396. }
  397. }
  398. }
  399. #--------------------------------------------
  400. # Allow for iterating the diameter, conductivity
  401. # and pitch of a CircleConductors object.
  402. #--------------------------------------------
  403. foreach nme [itcl::find objects -class CircleConductors] {
  404. if { $::bem::_arrCircDiamList($nme) } {
  405. set indx [ format "%s-CD" $nme ]
  406. set prefix [_setWhichImpedance $indx]
  407. puts $fp " # CircleConductors $nme \
  408. start: $::bem::_arrStartList($indx) \
  409. incr: $::bem::_arrIncrList($indx) \
  410. Impedance close to: $::bem::_endImpedance"
  411. if { [_buildIterateScript $fp $nme "diameter" \
  412. $::bem::_arrStartList($indx) \
  413. $::bem::_arrIncrList($indx) $::bem::_impedanceType $::bem::_endImpedance ] } {
  414. return
  415. }
  416. }
  417. }
  418. #--------------------------------------------
  419. # Allow for iterating the top and bottom width, height,
  420. # conductivity and pitch of a TrapezoidConductors object.
  421. #--------------------------------------------
  422. foreach nme [itcl::find objects -class TrapezoidConductors] {
  423. if { $::bem::_arrTrapWidthTopList($nme) } {
  424. set indx [ format "%s-TWT" $nme ]
  425. set prefix [_setWhichImpedance $indx]
  426. puts $fp " # TrapezoidConductors $nme \
  427. start: $::bem::_arrStartList($indx) \
  428. incr: $::bem::_arrIncrList($indx) \
  429. Impedance close to: $::bem::_endImpedance"
  430. if { [_buildIterateScript $fp $nme "topWidth" \
  431. $::bem::_arrStartList($indx) \
  432. $::bem::_arrIncrList($indx) $::bem::_impedanceType $::bem::_endImpedance ] } {
  433. return
  434. }
  435. }
  436. }
  437. ::bem::_finishIterateFile $fp
  438. close $fp
  439. ::bem::_runTheSimulations iterate_script _runIterate \
  440. "The generated script will run the\
  441. simulation until the Impedance is closest to $::bem::_endImpedance."
  442. }
  443. proc ::bem::_runTheSimulations { type command message } {
  444. destroy $::bem::_spFrame
  445. set retrn [tk_dialog .tkd "Warning" \
  446. $message warning {} "Run Simulation" "Cancel"]
  447. if { $retrn == 0 } {
  448. #--------------------------------------------------
  449. # Source and run the iterate.
  450. #--------------------------------------------------
  451. if { $::bem::Gui } {
  452. console::show
  453. }
  454. #--------------------------------------------------
  455. # Save a copy of the current display -- as a temp file.
  456. #--------------------------------------------------
  457. set flename "$::gui::_nodename.xsctn.temp"
  458. puts "Write: \"$flename\""
  459. ::csdl::csdlWriteTCL $flename $::bem::Title $::bem::Csegs $::bem::Psegs
  460. #--------------------------------------------------
  461. # Run the iterations.
  462. #--------------------------------------------------
  463. ::csdl::csdlReadTCL $::gui::_nodename.$type
  464. # make the feedback window the top window on the screen.
  465. #::gui::guiRaiseConsole
  466. $command
  467. if { $::bem::Gui } {
  468. # set the display data to the user's choice
  469. ::gui::_setDisplayData
  470. }
  471. }
  472. }
  473. ##########################################################
  474. # Output the rectangle conductor attributes.
  475. ##########################################################
  476. proc ::bem::bemPutRectangleConductorsToFile { nme fp } {
  477. set rname $nme
  478. set rheight [$nme cget -height]
  479. set rwidth [$nme cget -width]
  480. set rconductivity [$nme cget -conductivity]
  481. set rnumber [$nme cget -number]
  482. set rpitch [$nme cget -pitch]
  483. set rxoffset [$nme cget -xOffset]
  484. set ryoffset [$nme cget -yOffset]
  485. puts $fp "$nme: RectangleConductors"
  486. puts $fp " height : $rheight"
  487. puts $fp " width : $rwidth"
  488. puts $fp " conductivity: $rconductivity"
  489. puts $fp " number : $rnumber"
  490. puts $fp " pitch : $rpitch"
  491. puts $fp " x-offset : $rxoffset"
  492. puts $fp " y-offset : $ryoffset"
  493. }
  494. ##########################################################
  495. # Output the circle conductor attributes.
  496. ##########################################################
  497. proc ::bem::bemPutCircleConductorsToFile { nme fp } {
  498. set cname $nme
  499. set cdiameter [$nme cget -diameter]
  500. set cconductivity [$nme cget -conductivity]
  501. set cnumber [$nme cget -number]
  502. set cpitch [$nme cget -pitch]
  503. set cxoffset [$nme cget -xOffset]
  504. set cyoffset [$nme cget -yOffset]
  505. puts $fp "$nme: CircleConductors"
  506. puts $fp " diameter : $cdiameter"
  507. puts $fp " conductivity: $cconductivity"
  508. puts $fp " number : $cnumber"
  509. puts $fp " pitch : $cpitch"
  510. puts $fp " x-offset : $cxoffset"
  511. puts $fp " y-offset : $cyoffset"
  512. }
  513. ##########################################################
  514. # Output the trapezoid conductor attributes.
  515. ##########################################################
  516. proc ::bem::bemPutTrapezoidConductorsToFile { nme fp } {
  517. set tname $nme
  518. set theight [$nme cget -height]
  519. set ttopwidth [$nme cget -topWidth]
  520. set tbotwidth [$nme cget -bottomWidth]
  521. set tconductivity [$nme cget -conductivity]
  522. set tnumber [$nme cget -number]
  523. set tpitch [$nme cget -pitch]
  524. set txoffset [$nme cget -xOffset]
  525. set tyoffset [$nme cget -yOffset]
  526. puts $fp "$nme: TrapezoidConductors"
  527. puts $fp " height : $theight"
  528. puts $fp " topWidth : $ttopwidth"
  529. puts $fp " botWidth : $tbotwidth"
  530. puts $fp " conductivity: $tconductivity"
  531. puts $fp " number : $tnumber"
  532. puts $fp " pitch : $tpitch"
  533. puts $fp " x-offset : $txoffset"
  534. puts $fp " y-offset : $tyoffset"
  535. }
  536. ##########################################################
  537. # Output the dielectric attributes.
  538. ##########################################################
  539. proc ::bem::bemPutDielectricLayerToFile { nme fp } {
  540. set dname $nme
  541. set thickness [$nme cget -thickness]
  542. set permittivity [$nme cget -permittivity]
  543. set permeability [$nme cget -permeability]
  544. set lossTangent [$nme cget -lossTangent]
  545. puts $fp "$nme: DielectricLayer"
  546. puts $fp " thickness : $thickness"
  547. puts $fp " permittivity: $permittivity"
  548. puts $fp " permeability: $permeability"
  549. puts $fp " lossTangent : $lossTangent"
  550. }
  551. ##########################################################
  552. # Output the ground plane attributes.
  553. ##########################################################
  554. proc ::bem::bemPutGroundPlaneToFile { nme fp } {
  555. set gname $nme
  556. puts $fp "$nme: GroundPlane"
  557. }
  558. ############################################################################
  559. ############################################################################
  560. proc ::bem::_finishIterateFile { fp } {
  561. global env
  562. puts $fp " puts \$resultsFle \"\""
  563. puts $fp " puts \$resultsFle \"________________________\
  564. _______________________________\""
  565. puts $fp " puts \$logFle \"____________________________\
  566. ___________________________\""
  567. puts $fp " puts \$resultsFle \"\""
  568. puts $fp " puts \$logFle \"\""
  569. puts $fp " foreach itm \$Stackup\:\:structureList \{"
  570. puts $fp " set lgt \[string length \$itm]"
  571. puts $fp " set nme \[string range \$itm 2 \$lgt]"
  572. puts $fp " if \{ \[\$nme isa GroundPlane\] \} \{"
  573. puts $fp " ::bem::bemPutGroundPlaneToFile \$nme \$resultsFle"
  574. puts $fp " ::bem::bemPutGroundPlaneToFile \$nme \$logFle"
  575. puts $fp " \}"
  576. puts $fp " if \{ \[\$nme isa DielectricLayer\] \} \{"
  577. puts $fp " ::bem::bemPutDielectricLayerToFile \$nme \$resultsFle"
  578. puts $fp " ::bem::bemPutDielectricLayerToFile \$nme \$logFle"
  579. puts $fp " \}"
  580. puts $fp " if \{ \[\$nme isa RectangleConductors\] \} \{"
  581. puts $fp " ::bem::bemPutRectangleConductorsToFile \$nme \$resultsFle"
  582. puts $fp " ::bem::bemPutRectangleConductorsToFile \$nme \$logFle"
  583. puts $fp " \}"
  584. puts $fp " if \{ \[\$nme isa CircleConductors\] \} \{"
  585. puts $fp " ::bem::bemPutCircleConductorsToFile \$nme \$resultsFle"
  586. puts $fp " ::bem::bemPutCircleConductorsToFile \$nme \$logFle"
  587. puts $fp " \}"
  588. puts $fp " if \{ \[\$nme isa TrapezoidConductors\] \} \{"
  589. puts $fp " ::bem::bemPutTrapezoidConductorsToFile \$nme \$resultsFle"
  590. puts $fp " ::bem::bemPutTrapezoidConductorsToFile \$nme \$logFle"
  591. puts $fp " \}"
  592. puts $fp " \}"
  593. puts $fp " ::gui::_replaceNamedValues"
  594. set workingNode [format {%sTMP} $::gui::_nodename]
  595. puts $fp " ::csdl::csdlWriteTCL \"$workingNode.xsctn\" \"$::gui::_title\" \
  596. $::bem::Csegs $::bem::Psegs"
  597. set cmdName [auto_execok bem]
  598. puts $fp " set cmmnd {$cmdName \
  599. \"$workingNode\" \$::bem::Csegs \$::bem::Psegs } "
  600. set strg [ format " set msg \[catch \{ eval exec \$cmmnd \} \
  601. result]" ]
  602. puts $fp $strg
  603. puts $fp " set fin \[open \"$workingNode.result\" r\]"
  604. puts $fp " set results \[read \$fin\]"
  605. puts $fp " puts \$resultsFle \$results"
  606. puts $fp " close \$fin"
  607. puts $fp " set done \[::bem::bemParseIterationResults \$results \
  608. \$cname \$cdimName \$cdimValue \$impType \$closeTo\]"
  609. puts $fp " if \{ \$done > 0 \} \{"
  610. puts $fp " close \$logFle"
  611. puts $fp " close \$resultsFle"
  612. puts $fp " return"
  613. puts $fp " \}"
  614. puts $fp " puts \$resultsFle \"\""
  615. puts $fp " puts \$logFle \"\""
  616. puts $fp " puts \"__________________________________\
  617. __________________\""
  618. puts $fp " puts \$logFle \$result"
  619. puts $fp " incr loopct"
  620. #------------------------------------------------------------
  621. # # of iterations
  622. #------------------------------------------------------------
  623. puts $fp " if \{ \$loopct > $::bem::_maxIterations \} \{"
  624. puts $fp " close \$logFle"
  625. puts $fp " close \$resultsFle"
  626. puts $fp " return"
  627. puts $fp " \}"
  628. #------------------------------------------------------------
  629. # # of nested loops
  630. #------------------------------------------------------------
  631. global ::bem::_curls
  632. for { set i 0 } { $i < $::bem::_curls } { incr i } {
  633. set strg " \} "
  634. puts $fp $strg
  635. }
  636. puts $fp " close \$logFle"
  637. puts $fp " close \$resultsFle"
  638. set strg " \}"
  639. puts $fp $strg
  640. }
  641. ############################################################################
  642. ############################################################################
  643. proc ::bem::bemParseIterationResults { results cName cdimName cdimValue \
  644. impType closeTo } {
  645. set indx [string first "Asymmetry Ratios:" $results]
  646. set newstrg2 [string range $results $indx [string length $results] ]
  647. set indx1 [string first "Asymmetry ratio for" $newstrg2 ]
  648. set newstrg [string range $newstrg2 [expr { $indx1 + 42 }] \
  649. [string length $newstrg2]]
  650. set indx2 [string first "*******" $newstrg2]
  651. set tmp [string range $newstrg2 $indx2 [expr { $indx2 + 150 }] ]
  652. set indx [string first "%" $newstrg]
  653. set maxx [ string range $newstrg 0 $indx ]
  654. set newstrg2 [string range $newstrg [expr {$indx + 7 }] \
  655. [expr { $indx + 100 }] ]
  656. set indx [string first "%" $newstrg2]
  657. set average [string range $newstrg2 0 $indx ]
  658. if { $impType == 0 } {
  659. set indx [string first Impedance $results]
  660. set newstrg [string range $results $indx [string length $results]]
  661. set indx [string first $cName $newstrg]
  662. set newstrg [string range $newstrg $indx [string length $newstrg]]
  663. set indx [string first "=" $newstrg]
  664. set newstrg [string range $newstrg $indx [string length $newstrg]]
  665. set num [ scan $newstrg {= %g} impedance ]
  666. if { $num < 1 } {
  667. puts "Cannot continue because the impedance value for $cName\
  668. is set to \"nan\""
  669. return 1
  670. }
  671. puts "$cName: $cdimName = $cdimValue Impedance = $impedance"
  672. }
  673. #----------------------------------------------------------------
  674. # Are we processing the old impedance values?
  675. #----------------------------------------------------------------
  676. if { $impType == 1 } {
  677. set indx [string first odd= $results]
  678. if { $indx < 0 } {
  679. puts stderr "**************************************************"
  680. puts stderr "Cannot continue because the odd impedance value\
  681. for $cName is not in the result file"
  682. puts stderr "**************************************************"
  683. return 1
  684. }
  685. set newstrg [string range $results [expr { $indx + 4 }] \
  686. [string length $results]]
  687. set num [ scan $newstrg {%g} impedance ]
  688. if { $num < 1 } {
  689. puts stderr "**************************************************"
  690. puts stderr "Cannot continue because the odd impedance value\
  691. for $cName is set to \"nan\""
  692. puts stderr "**************************************************"
  693. return 1
  694. }
  695. puts "$cName: $cdimName = $cdimValue Odd Impedance = $impedance"
  696. }
  697. #----------------------------------------------------------------
  698. # Are we processing the even impedance values?
  699. #----------------------------------------------------------------
  700. if { $impType == 2 } {
  701. set indx [string first even= $results]
  702. if { $indx < 0 } {
  703. puts stderr "**************************************************"
  704. puts stderr "Cannot continue because the even impedance value\
  705. for $cName is not in the result file"
  706. puts stderr "**************************************************"
  707. return 1
  708. }
  709. set newstrg [string range $results [expr { $indx + 5 }] \
  710. [string length $results]]
  711. set num [ scan $newstrg {%g} impedance ]
  712. if { $num < 1 } {
  713. puts stderr "**************************************************"
  714. puts stderr "Cannot continue because the even impedance value\
  715. for $cName is set to \"nan\""
  716. puts stderr "**************************************************"
  717. return 1
  718. }
  719. puts "$cName: $cdimName = $cdimValue \
  720. Even Impedance = $impedance"
  721. }
  722. if { $indx1 > $indx2 } {
  723. puts "** Asymmetry ratio for inductance matrix:"
  724. puts "$maxx (max), $average (average) **"
  725. }
  726. set diff [expr { $closeTo - $impedance }]
  727. if { $diff < 0 } {
  728. set diff [expr { $diff * -1 }]
  729. }
  730. global oldDiff
  731. global oldImp
  732. if { $diff > $oldDiff } {
  733. puts "Impedance of $oldImp closest to $closeTo"
  734. return 1
  735. } else {
  736. set oldImp $impedance
  737. set oldDiff $diff
  738. }
  739. return -1
  740. }