Skip to content

Commit

Permalink
solved issue of singular matrices. fully functional conduction
Browse files Browse the repository at this point in the history
singular matrices were caused by junctions with no conduction path
to the source and drain nodes. fixed by only calculating conduction
on the spanning cluster
  • Loading branch information
leobrowning92 committed Mar 21, 2018
1 parent e3e4ddd commit eb60430
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 1 addition & 3 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def make_A(self, G):
BTD=np.append(B.T,D,axis=1)
A=np.append(np.append(G,B,axis=1),BTD,axis=0)
A=np.delete(np.delete(A,self.ground_nodes,0),self.ground_nodes,1)
plt.matshow(A,vmin=-1,vmax=1)
plt.show()
return A
def make_z(self):
z = np.append(np.zeros((self.network_size-len(self.ground_nodes),1)), self.voltage_sources[:,1][:,None], axis=0)
Expand Down Expand Up @@ -104,7 +102,7 @@ def show_device(self,v=False,ax=False):
ax=plt.subplot(111)
self.plot_network(ax,v=v)
self.plot_regions(ax)
ax.legend()
# ax.legend()
if not(ax):
plt.show()
def plot_regions(self,ax):
Expand Down
26 changes: 17 additions & 9 deletions percolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ def make_clusters(self, sticks):
intersection=self.check_intersect(sticks.iloc[i].endarray, sticks.iloc[j].endarray)
if intersection and 0<=intersection[0]<=1 and 0<=intersection[1]<=1:
sticks.loc[sticks.cluster==sticks.loc[j,'cluster'],'cluster'] = sticks.loc[i,'cluster']
intersects.append([i,j,*intersection, sticks.iloc[i].kind+sticks.iloc[j].kind])
intersects.append([i,j,*intersection, sticks.iloc[i].kind+sticks.iloc[j].kind],)
self.percolating=sticks.loc[0,"cluster"]==sticks.loc[len(sticks)-1,"cluster"]
return sticks,pd.DataFrame(intersects, columns=["stick1",'stick2','x','y','kind'])
intersects=pd.DataFrame(intersects, columns=["stick1",'stick2','x','y','kind'])
intersects['cluster']=intersects['stick1'].apply(lambda x: sticks.iloc[x].cluster)
return sticks, intersects
def
def show_system(self,clustering=True,junctions=True,conduction=True):
fig = plt.figure(figsize=(15,5))
axes=[fig.add_subplot(1,3,i+1) for i in range(3)]
Expand All @@ -86,7 +89,7 @@ def show_system(self,clustering=True,junctions=True,conduction=True):
if junctions:
self.show_sticks(ax=axes[1])
if conduction and self.percolating:
self.solve_cnet()
self.make_cnet()
self.cnet.show_device(ax=axes[2])
plt.show()
def show_clusters(self,intersects=True,ax=False):
Expand Down Expand Up @@ -140,7 +143,12 @@ def make_test_sticks(self):
self.sticks, self.intersects = self.make_clusters(sticks)

def make_graph(self):
self.graph=nx.from_pandas_edgelist(self.intersects, source='stick1',target='stick2',edge_attr=True)
# only calculates the conduction through the spanning cluster of sticks
# to avoid the creation of a singular adjacency matrix caused by
# disconnected junctions becoming unconnected nodes in the cnet
dom_cluster=self.intersects[self.intersects.cluster==self.sticks.loc[0,'cluster']]

self.graph=nx.from_pandas_edgelist(dom_cluster, source='stick1',target='stick2',edge_attr=True)

self.ground_nodes=[len(self.graph)-1]
self.voltage_sources=[[0,0.1]]
Expand All @@ -153,16 +161,17 @@ def make_graph(self):

def populate_graph(self):
for edge in self.graph.edges():

self.graph.edges[edge]['component']=Transistor()


def solve_cnet(self):
def make_cnet(self):
assert self.percolating, "The network is not conducting!"
self.cnet=ConductionNetwork(*self.make_graph())
# print(self.cnet.make_G(),'\n')
# print(self.cnet.make_A(self.cnet.make_G()))
self.cnet.set_global_gate(0)
# self.cnet.set_local_gate([0.5,.7,0.4,1], 10)
# self.cnet.set_local_gate([0.5,0,0.4,1.2], 10)
self.cnet.update()
# print(self.cnet.source_currents)

Expand All @@ -182,9 +191,8 @@ def solve_cnet(self):
collection=StickCollection(10,l=1,pm=args.pm,scaling=1)
collection.make_test_sticks()
collection.show_system(conduction=False)
collection.solve_cnet()
collection.make_cnet()
else:
collection=StickCollection(args.number,l=args.length,pm=args.pm,scaling=args.scaling)
collection.show_system(conduction=False)
collection.solve_cnet()
collection.show_system()
# print(len(collection.sticks.cluster.drop_duplicates()))

0 comments on commit eb60430

Please sign in to comment.