diff --git a/network.py b/network.py index e1a952e..07a8329 100644 --- a/network.py +++ b/network.py @@ -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) @@ -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): diff --git a/percolation.py b/percolation.py index 7aff985..4d1e266 100644 --- a/percolation.py +++ b/percolation.py @@ -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)] @@ -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): @@ -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]] @@ -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) @@ -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()))