Skip to content

Commit

Permalink
finalized drawing of voltage rectangles
Browse files Browse the repository at this point in the history
  • Loading branch information
leobrowning92 committed Mar 2, 2018
1 parent a813196 commit 8cf99f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
18 changes: 12 additions & 6 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self,network_rows, network_columns, component, ground_nodes, voltag
self.check_values()
#make the grid graph
self.graph=nx.grid_2d_graph(self.network_rows,self.network_columns)
self.scale_graph()
#add the components
self.add_components(component)

Expand All @@ -32,6 +33,11 @@ def check_values(self):
assert len(self.voltage_sources) + len(self.ground_nodes) < self.network_size, "there are more voltage sources and ground nodes than network nodes"
assert len(self.ground_nodes)<self.network_size, "ground nodes out of graph index"
assert len(self.voltage_sources[:,0])<self.network_size, "ground nodes out of graph index"

def scale_graph(self):
max_dimension=max(self.network_rows,self.network_columns)-1
rn={n:(n[0]/max_dimension,n[1]/max_dimension)for n in self.graph.nodes}
self.graph=nx.relabel_nodes(self.graph,rn)
def add_components(self,component):
if type(component)==list:
assert len(component)==len(self.graph.edges), "ERROR: There is a mismatch between the number of components added and the number of graph edges"
Expand Down Expand Up @@ -116,10 +122,10 @@ def show_network(self,v=False):
self.plot_network(ax1,v=v)
plt.show()
def plot_network(self,ax1,v=False):
pos={}
for i in range(self.network_rows):
for j in range(self.network_columns):
pos[(i,j)]=j,i
pos={k:[k[1],k[0]] for k in self.graph.nodes}
# for i in range(self.network_rows):
# for j in range(self.network_columns):
# pos[(i,j)]=j,i
edges,currents = zip(*nx.get_edge_attributes(self.graph,'current').items())

nodes,voltages = zip(*nx.get_node_attributes(self.graph,'voltage').items())
Expand All @@ -135,8 +141,8 @@ def plot_network(self,ax1,v=False):
divider1 = make_axes_locatable(ax1)
cax1 = divider1.append_axes('right', size='5%', pad=0.5)
cax2 = divider1.append_axes('right', size='5%', pad=0.5)
plt.colorbar(edges,label="Current",cax=cax2)
plt.colorbar(nodes,label="Node Voltage",cax=cax1)
plt.colorbar(edges,label="Current A",cax=cax2)
plt.colorbar(nodes,label="Node Voltage V",cax=cax1)



Expand Down
9 changes: 6 additions & 3 deletions transistorDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def __init__(self,network_rows, network_columns, component, vds=1):
ground_nodes = [(x+1)*network_columns-1 for x in range(network_rows)]
voltage_sources = [[x*network_columns,vds] for x in range(network_rows)]
Network.__init__(self,network_rows, network_columns, component, ground_nodes, voltage_sources)
self.vds=vds
self.update_location()
self.gate_areas=[]
def update_location(self):
max_dimension=max(self.network_rows,self.network_columns)
for node in self.graph.nodes:
self.graph.nodes[node]['pos'] = [node[1]/max_dimension, node[0]/max_dimension]
self.graph.nodes[node]['pos'] = [node[1], node[0]]
for n1,n2 in self.graph.edges:
self.graph.edges[(n1,n2)]['pos'] = [ (self.graph.nodes[n1]['pos'][0]+self.graph.nodes[n1]['pos'][0])/2 , (self.graph.nodes[n2]['pos'][1]+self.graph.nodes[n2]['pos'][1])/2 ]

Expand Down Expand Up @@ -67,10 +67,13 @@ def show_device(self,v=False):
ax1=plt.subplot(111)
self.plot_network(ax1,v=v)
self.plot_regions(ax1)
ax1.legend()
plt.show()
def plot_regions(self,ax):
for a in self.gate_areas:
ax.add_patch(patches.Rectangle((a[0][0],a[0][1]),a[0][2],a[0][3], edgecolor='b', fill=False))
ax.add_patch(patches.Rectangle( (a[0][0]-a[0][2]/2,a[0][1]-a[0][3]/2), a[0][2],a[0][3], edgecolor='b', fill=False, label="Local $V_G$ = {} V".format(a[1])))
ax.add_patch(patches.Rectangle( (-1/self.network_columns/2,-1/self.network_rows/2), 1/self.network_columns,1+1/self.network_rows, edgecolor='r', fill=False,label="Source = {} V".format(self.vds)))
ax.add_patch(patches.Rectangle( (1-1/self.network_columns/2,-1/self.network_rows/2), 1/self.network_columns,1+1/self.network_rows, edgecolor='k', fill=False, label="GND = 0 V"))



Expand Down

0 comments on commit 8cf99f3

Please sign in to comment.