Commit 7bee3cf2 authored by sfritschi's avatar sfritschi
Browse files

Index attributes of pores only used within generate_dendrogram

parent 851b0ca9
......@@ -19,7 +19,8 @@ class Pore:
"""Class of a pore connected to other pores via throats."""
id = 0
def __init__(self, pos: List[float], r: float, label: str = LABELS[0], \
throats: Set = None, id: int = -1, index: int = -1, originIndex: int = -1):
throats: Set = None, id: int = -1, useIndex: bool = False, \
index: int = -1, originIndex: int = -1):
if id == -1: # no id given
self.id = Pore.id; Pore.id = Pore.id+1
else: # id provided
......@@ -29,8 +30,10 @@ class Pore:
self.throats = throats # throats set
self.r = r # radius
self.label = label # label string like '', 'in', or 'out'
self.index = index
self.originIndex = originIndex # points to original pore inside domain
# Store index of pore in list used in generate_dendrogram
if useIndex:
self.index = index
self.originIndex = originIndex # points to original pore inside domain
def __repr__(self): return str(self.__class__) + ': ' + \
str({k:self.__dict__[k] for k in self.__dict__ if k != 'throats'}) + \
' {0:d} throats'.format(len(self.throats)) # dont flush throat objects
......@@ -597,7 +600,8 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
pos = [random()*l for l in L]
poreThroatIdx = set(throatIdxMap[throat] for throat in pore.throats)
pores.append(Pore(pos=pos, r=pore.r, label=LABELS[0],
throats=poreThroatIdx, index=runningIndex, originIndex=runningIndex))
throats=poreThroatIdx, useIndex=True,
index=runningIndex, originIndex=runningIndex))
runningIndex += 1
else: # dendrogram-based
# extract cluster hierarchy from basenet
......@@ -636,7 +640,8 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
pos = [c-lb + si*(ub-lb) \
for c,si,lb,ub in zip(centroids[k],s,basenet.lb,basenet.ub)]
poreThroatIdx = set(throatIdxMap[throat] for throat in pore.throats)
pores.append(Pore(pos=pos, r=pore.r, label=LABELS[0], throats=poreThroatIdx))
pores.append(Pore(pos=pos, r=pore.r, label=LABELS[0],
useIndex=True, throats=poreThroatIdx))
# Throat index map no longer needed
del throatIdxMap
# Randomly shuffle pores list
......@@ -656,7 +661,7 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
# add pore buffer layers for spatial periodicity
n = len(pores)
copies = __add_buffer_layers(pores, L, basenet.Lmax)
copies = __add_buffer_layers(pores, L, basenet.Lmax, useIndex=True)
# Domain size including periodic buffer layers on all sides
trueDomainSize = [L[i] + 2 * basenet.Lmax for i in range(d)]
......@@ -839,6 +844,9 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
network = Network(lb=[0.0 for k in range(d)],
ub=L, Lmax=basenet.Lmax, label='from_' + basenet.label)
for pore in pores[:n]:
# Remove index attributes before adding pore to network
del pore.index
del pore.originIndex
pore.throats.clear() # remove (potentially) remaining pores
network.add_pore(pore)
for throat in throats: network.connect_pores(pore1=throat[0],
......@@ -848,7 +856,7 @@ def generate_dendrogram(basenet: Network, targetsize: List[int], \
def __add_buffer_layers(pores: List[Pore], targetsize: List[float],
Lbuffer: float) -> Dict[Pore,Set[Pore]]:
Lbuffer: float, useIndex: bool = False) -> Dict[Pore,Set[Pore]]:
"""Add pore buffer layers for spatial periodicity.
Returns a dict where each key is a pore and the corresponding value
......@@ -867,7 +875,7 @@ def __add_buffer_layers(pores: List[Pore], targetsize: List[float],
if targetsize[k]-Lbuffer <= pore.pos[k] < targetsize[k]]
for pore in pores_layer:
pcopy = Pore(pore.pos, pore.r, throats=pore.throats, \
id=pore.id, index=runningIndex)
id=pore.id, useIndex=useIndex, index=runningIndex)
pcopy.pos[k] = pcopy.pos[k]-targetsize[k]
lbl = pore.label.split(); lbl[k + 1] = '-1'
pcopy.label = ' '.join(lbl) # periodicity label
......@@ -881,7 +889,7 @@ def __add_buffer_layers(pores: List[Pore], targetsize: List[float],
if 0 <= pore.pos[k] < Lbuffer]
for pore in pores_layer:
pcopy = Pore(pore.pos, pore.r, throats=pore.throats, \
id=pore.id, index=runningIndex)
id=pore.id, useIndex=useIndex, index=runningIndex)
pcopy.pos[k] = pcopy.pos[k]+targetsize[k]
lbl = pore.label.split(); lbl[k + 1] = '1'
pcopy.label = ' '.join(lbl) # periodicity label
......
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