1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340 | ###############################################################################
# Copyright (c) 2008-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform. As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
# @plugin
# Coupled Elements
# @namespace
# Coupled
# @section
# Miscellaneous Userware Examples
# @description
# Add a main menu entry to collect information about all coupled
# K-objects and load all instances to the Mem window.
#
# Coupled instances can be displayed in the Cone window including all
# connected R, C or L devices. If option `Full LRC` is set the
# corresponding R and C to the L are loaded into the cone, too.
#
# Coupled instances can be grouped into a new hierarchy.
# @license
# permit spice
# @files
# coupled.tcl
# @example
# demo/spice/examples.sp
# @cmdline
# -hspice @example[0]
# -userware @files[0]
# @tag
# spice
###############################################################################
# =============================================================================
# Init - Initialize the plugin.
# =============================================================================
#
proc Coupled:Init {} {
global Coupled
##
# Initialize private variables.
#
set Coupled(kElementList) {}
set Coupled(fullLRC) 0
set Coupled(hideK) 0
##
# Add checkbuttons to the main menu.
#
gui menu checkbutton {"Userware" "Full LRC"} \
"" Coupled(fullLRC)
gui menu checkbutton {"Userware" "Hide K"} \
[list Coupled:_hideK] Coupled(hideK)
gui menu command {"Userware" "Group Coupled"} \
[list Coupled:_groupCoupled]
##
# Register Coupled:_coupledInfo to be run on database changes,
# and immediately if there's already is a database.
#
gui database runAndRegisterChangedCallback [list Coupled:_coupledInfo]
##
# Customize the Popup Menu.
#
gui popup append "Show Coupled" [list Coupled:_show]
}
# =============================================================================
# Finit - Finalize the plugin.
# =============================================================================
#
proc Coupled:Finit {} {
##
# Undo modifications of the GUI.
#
gui menu removeEntry {"Userware" "Full LRC"}
gui menu removeEntry {"Userware" "Hide K"}
gui menu removeEntry {"Userware" "Group Coupled"}
##
# Remove the callback registration.
#
gui database removeChangedCallback "Coupled:_coupledInfo"
gui popup remove "Show Coupled"
}
# -----------------------------------------------------------------------------
# _coupledInfo - Collect information about all K-Objects ("_COUPLED_") and
# load all instances to the Mem window.
# -----------------------------------------------------------------------------
#
proc Coupled:_coupledInfo {db} {
global Coupled
##
# Return if the database is empty.
#
if {$db == {}} {
return
}
set Coupled(kElementList) {}
$db foreach primitive prim {
$db flag $prim clear red
if {[$db oid oname $prim] == "_COUPLED_"} {
$db flag $prim set red
}
}
$db foreach top top {
$db flat foreach instOfCell red $top inst {
lappend Coupled(kElementList) $inst
}
}
gui window show Mem
gui mem clear
gui mem append $Coupled(kElementList)
##
# Restore hide state.
#
Coupled:_hideK
}
# -----------------------------------------------------------------------------
# _show - Load the coupled inductors and the K element into the Cone window.
# Also highlight the three elements for visual identification.
# -----------------------------------------------------------------------------
#
proc Coupled:_show {oidList} {
set db [gui database get]
gui window show Cone
gui settings set "cone:autohide" 1
gui settings changed
gui cone clear
$db flathilight * deleteAll 1
foreach oid $oidList {
if {![$db flag [$db down $oid] is red]} {
continue
}
$db flathilight $oid set 1
gui cone append [list $oid]
set module [$db oid module $oid]
set module [$db oid create "module $module $module"]
for {set i 1} {$i} {incr i} {
set name [$db attr $oid getValue "\$INST$i"]
if {$name == ""} {
break
}
set l [$db search inst $module $name]
if {($l != "") || ([$db oid type $l] == "inst")} {
gui cone append [list $l]
$db hilight $l set 1
$db foreach pin $l pin {
gui cone append [Coupled:_collectRC $db $pin]
}
}
}
}
gui cone regenerate
gui highlight changed
}
# -----------------------------------------------------------------------------
# _collectRC - Collect the connected R and C.
# -----------------------------------------------------------------------------
#
proc Coupled:_collectRC {db oid} {
global Coupled
set resList [list $oid]
if {$Coupled(fullLRC) == 0} {
return $resList
}
##
# The given OID is always a pin of the inductor.
#
if {![$db isConnected $oid]} {
return
}
set indx [string first "_" [$db oid oname $oid]]
if {$indx == -1} {
set name [string range [$db oid oname $oid] 1 end]
set appx ""
} else {
set name [string range [$db oid oname $oid] 1 [expr {$indx-1}]]
set appx [string range [$db oid oname $oid] $indx [expr {$indx+1}]]
}
set nextPins [list $oid]
while {[llength $nextPins] > 0} {
set nextLevelPins {}
foreach pin $nextPins {
if {![$db isConnected $pin]} {
continue
}
set net [$db connectedNet $pin]
$db foreach pin $net p {
if {$p == $pin} {
continue
}
if {[$db oid type $p] == "port"} {
lappend resList $p
continue
}
set iName [$db oid oname [$db oid convertTo inst $p]]
if {![string match "*$name*" $iName]} {
continue
}
if {[string match "L*" $iName]} {
continue
}
if {[string match "R*" $iName]} {
if {![string match "R${name}$appx*" $iName]} {
continue
}
}
lappend resList $p
if {[string match "C*" $iName]} {
continue
}
set np [$db tdevice oppositePin $p]
lappend nextLevelPins $np
lappend resList $np
}
}
set nextPins $nextLevelPins
}
return $resList
}
# -----------------------------------------------------------------------------
# _hideK - Toggle the display of the K elements in the Schem and Cone window.
# -----------------------------------------------------------------------------
#
proc Coupled:_hideK {} {
global Coupled
set db [gui database get]
foreach inst $Coupled(kElementList) {
$db ignore $inst $Coupled(hideK)
}
gui database modified
}
# -----------------------------------------------------------------------------
# _groupCoupled - Group coupled objects in new hierarchy.
# -----------------------------------------------------------------------------
#
proc Coupled:_groupCoupled {} {
##
# Return if the database is empty.
#
set db [gui database get]
if {$db == {}} {
return
}
$db foreach primitive prim {
$db flag $prim clear red
if {[$db oid oname $prim] == "_COUPLED_"} {$db flag $prim set red}
}
set coupledList {}
$db foreach top top {
$db flat foreach instOfCell red $top inst {
lappend coupledList $inst
}
}
set newCoupledInst 0
foreach oid $coupledList {
set coupledInst {}
lappend coupledInst $oid
for {set i 1} {$i} {incr i} {
set name [$db attr $oid getValue "\$INST$i"]
if {$name == ""} {
break
}
set l [$db search inst [$db parentModule $oid] $name]
if {[$db oid isnull $l]} {
continue
}
if {($l != "") || ([$db oid type $l] == "inst")} {
lappend coupledInst $l
}
}
set n [$db oid oname $oid]
##
# Check if coupled instance is already created.
#
if {[$db oid isnull [$db search module c_$n]]} {
$db oper addhier c_$n i_$n $coupledInst
set newCoupledInst 1
}
}
##
# If new coupled instance is created update GUI.
#
if {$newCoupledInst} {
Coupled:_hideK
} else {
zmessage print INF "No new coupling elements found."
}
}
# =============================================================================
# Call the initialization procedure.
# =============================================================================
#
Coupled:Init
|