FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python3-eispice/module/subckt.py at master · Narrat/python3-eispice · GitHub
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
Narrat
/
python3-eispice
Public archive
Notifications
You must be signed in to change notification settings
Fork
1
Star
6
Code
Issues
1
Pull requests
0
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Security and quality
Insights
Expand file tree
Breadcrumbs
python3-eispice
/
module
/
subckt.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
93 lines (80 loc) · 3.32 KB
Breadcrumbs
python3-eispice
/
module
/
subckt.py
Copy path
File metadata and controls
93 lines (80 loc) · 3.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
# Copyright (C) 2006-2007 Cooper Street Innovations Inc.
# Charles Eidsness <charles@cooper-street.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
"""
This module provides a class that can be used as a base class to
create eispice sub-circuits.
Classes:
Subckt -- Base calls used to define a sub-circuit.
"""
_subcktCnt
=
0
class
Subckt
(
list
):
"""
Is used as a base class that is inherited by User Defined a
sub-circuit. Similar to a subckt in Berkely Spice.
Example:
>>> import eispice
>>> class Subckt1(eispice.Subckt):
... def __init__(self, pNode, nNode, Rx, Ry):
... self.Rx = eispice.R(pNode, self.node('node'), Rx)
... self.Ry = eispice.R(nNode, self.node('node'), Ry)
>>> class Subckt2(eispice.Subckt):
... def __init__(self, pNode, nNode, Rx, Ry):
... self.Rx = eispice.R(pNode, self.node('node'), Rx)
... self.Xy = Subckt1(nNode, self.node('node'), Rx, Ry)
>>> cct = eispice.Circuit("Subckt Test")
>>> cct.Vx = eispice.V(1, 0, 10)
>>> cct.Xx = Subckt2(1, 0, 100, 100)
>>> cct.op()
>>> cct.check_i('Vx', -10.0 / 300.0)
True
"""
def
__new__
(
self
,
*
args
,
**
argsk
):
# NOTE: This is not necissailly the best way to do this
self
.
subcktCnt
=
globals
()[
'_subcktCnt'
]
globals
()[
'_subcktCnt'
]
+=
1
return
list
.
__new__
(
self
,
args
,
argsk
)
def
node
(
self
,
name
):
"""Identifys a local node, that doesn't exit the Subckt"""
return
"%s@%s"
%
(
self
.
subcktCnt
,
name
)
def
device
(
self
,
name
):
"""Identifys a local device, that doesn't exit the Subckt"""
return
"%s#%s"
%
(
self
.
subcktCnt
,
name
)
def
__setattr__
(
self
,
name
,
value
):
"""
Adds a device that can be accessed using its name, and creates a
flat version by adding a prefix based on the instantiations id to
uniquly label the device instances. This is done because the base
simulator doesn't support hiearchy and every device needs a unique
identifier. If the device being attached is a Subckt it pulls in
its flat circuit dict.
"""
self
.
__dict__
[
name
]
=
value
try
:
for
(
subName
,
subValue
)
in
value
:
self
.
append
((
subName
,
subValue
))
except
TypeError
:
self
.
append
((
self
.
device
(
name
),
value
))
# --------------------------------------------------------------------------- #
# Test #
# --------------------------------------------------------------------------- #
if
__name__
==
'__main__'
:
import
doctest
doctest
.
testmod
(
verbose
=
False
)
print
(
'Testing Complete'
)
Back
|
FazBrowse Home
|
New Git URL