Commit 08385948 by sfritschi

### Added correctness test for generated network and fixed issue with double connections

parent 7e86880a
 ... @@ -762,12 +762,17 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ ... @@ -762,12 +762,17 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ if (not mute): print("\nconnecting") if (not mute): print("\nconnecting") throats = [] throats = [] # DEBUG # coordination number for each pore #coords = [len(pore.throats) for pore in pores[:n]] avg_throat_diff = 0. avg_throat_diff = 0. count = 0 count = 0 # Throats-To-Be-Realized # Throats-To-Be-Realized # Copy throats of pores to keep track of the ones already realized # Copy throats of pores to keep track of the ones already realized ttbrs = [pore.throats.copy() for pore in pores[:n]] ttbrs = [pore.throats.copy() for pore in pores[:n]] # Set of realized throats Tuple[int, int] realizedThroats = set() if (not mute): print("Total throats: %d" % totalThroats) if (not mute): print("Total throats: %d" % totalThroats) ... @@ -810,7 +815,6 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ ... @@ -810,7 +815,6 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ matches = cellList.fetch_matches(pore) matches = cellList.fetch_matches(pore) conporesInd = set() # Set of connected pores (needed if target size contains 1) for throatIdx, match in zip(pore.throats, matches): for throatIdx, match in zip(pore.throats, matches): if throatIdx not in poreTtbr: if throatIdx not in poreTtbr: ... @@ -832,10 +836,18 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ ... @@ -832,10 +836,18 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ nborTtbr = ttbrs[nbor.index] nborTtbr = ttbrs[nbor.index] if (len(nborTtbr) == 0 or nbor.index in conporesInd): # Make sure tuples of index pairs is unique if (nbor.index < pore.index): throatConn = (nbor.index, pore.index) else: throatConn = (pore.index, nbor.index) # Check that nbor is not fully connected and that # this pore is not already connected to it if (len(nborTtbr) == 0 or throatConn in realizedThroats): continue continue conporesInd.add(nbor.index) # Update set of realized throats realizedThroats.add(throatConn) r = Network.throatR[throatIdx] r = Network.throatR[throatIdx] targetLen = Network.throatL[throatIdx] targetLen = Network.throatL[throatIdx] ... @@ -901,8 +913,10 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ ... @@ -901,8 +913,10 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ # Unrealized throats # Unrealized throats nunrealized = throatsLeft nunrealized = throatsLeft # Free memory associated with cellList (not needed anymore) # Free memory (not needed anymore) del cellList del cellList del ttbrs del realizedThroats # DEBUG # DEBUG if (iterCount == maxIters): if (iterCount == maxIters): ... @@ -922,6 +936,30 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ ... @@ -922,6 +936,30 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \ network.add_pore(pore) network.add_pore(pore) for throat in throats: network.connect_pores(pore1=throat[0], for throat in throats: network.connect_pores(pore1=throat[0], pore2=throat[1], label=throat[2], r=throat[3]) pore2=throat[1], label=throat[2], r=throat[3]) # DEBUG """ # Check for correctness of generated network checkUnrealized = 0 for pore in network.pores: nthroats = len(pore.throats) # Make sure pore coordination number is respected coordNum = coords[pore.index] assert(nthroats <= coordNum) checkUnrealized += coordNum - nthroats nborInd = set() for throat in pore.throats: assert(pore.index == throat.pore1.index or pore.index == throat.pore2.index) nborIdx = throat.pore2.index if (throat.pore1.index == pore.index) else throat.pore1.index nborInd.add(nborIdx) # Make sure pore isn't connected to the same nbor twice assert(len(nborInd) == nthroats) checkUnrealized //= 2 # counted every throat twice # Make sure missing throats are accounted for assert(checkUnrealized == nunrealized) """ return network return network ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment