def test_label_faces_tol(self): net = op.network.Cubic(shape=[3, 3, 3], spacing=1, connectivity=6) net.clear(mode='labels') net['pore.coords'] += np.array([5, 5, 5]) topotools.label_faces(network=net, tol=0.2) assert net.num_pores('surface') == 26 assert net.num_pores('left') == 9 assert net.num_pores('right') == 9 assert net.num_pores('front') == 9 assert net.num_pores('back') == 9 assert net.num_pores('top') == 9 assert net.num_pores('bottom') == 9
def test_label_faces(self): net = op.network.Cubic(shape=[3, 3, 3], connectivity=6) net.clear(mode='labels') assert net.labels() == ['pore.all', 'throat.all'] topotools.label_faces(network=net) assert net.num_pores('surface') == 26 assert net.num_pores('left') == 9 assert net.num_pores('right') == 9 assert net.num_pores('front') == 9 assert net.num_pores('back') == 9 assert net.num_pores('top') == 9 assert net.num_pores('bottom') == 9
def __init__(self, shape, mode, spacing=1, **kwargs): super().__init__(**kwargs) shape = np.array(shape) if np.any(shape < 2): raise Exception('Bravais lattice networks must have at least 2 ' 'pores in all directions') if mode == 'bcc': # Make a basic cubic for the coner pores net1 = Cubic(shape=shape) net1['pore.net1'] = True # Create a smaller cubic for the body pores, and shift it net2 = Cubic(shape=shape-1) net2['pore.net2'] = True net2['pore.coords'] += 0.5 # Stitch them together topotools.stitch(net1, net2, net1.Ps, net2.Ps, len_max=0.99) self.update(net1) ws.close_project(net1.project) # Deal with labels Ps1 = self['pore.net2'] self.clear(mode='labels') self['pore.corner_sites'] = ~Ps1 self['pore.body_sites'] = Ps1 Ts = self.find_neighbor_throats(pores=self.pores('body_sites'), mode='exclusive_or') self['throat.corner_to_body'] = False self['throat.corner_to_body'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('corner_sites'), mode='xnor') self['throat.corner_to_corner'] = False self['throat.corner_to_corner'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('body_sites'), mode='xnor') self['throat.body_to_body'] = False self['throat.body_to_body'][Ts] = True elif mode == 'fcc': shape = np.array(shape) # Create base cubic network of corner sites net1 = Cubic(shape=shape) # Create 3 networks to become face sites net2 = Cubic(shape=shape - [1, 1, 0]) net3 = Cubic(shape=shape - [1, 0, 1]) net4 = Cubic(shape=shape - [0, 1, 1]) net2['pore.coords'] += np.array([0.5, 0.5, 0]) net3['pore.coords'] += np.array([0.5, 0, 0.5]) net4['pore.coords'] += np.array([0, 0.5, 0.5]) # Remove throats from net2 (trim doesn't work when removing ALL) for n in [net2, net3, net4]: n.clear(element='throat', mode='all') n.update({'throat.all': np.array([], dtype=bool)}) n.update({'throat.conns': np.ndarray([0, 2], dtype=bool)}) # Join networks 2, 3 and 4 into one with all face sites topotools.stitch(net2, net3, net2.Ps, net3.Ps, len_min=0.70, len_max=0.75) topotools.stitch(net2, net4, net2.Ps, net4.Ps, len_min=0.70, len_max=0.75) # Join face sites network with the corner sites network topotools.stitch(net1, net2, net1.Ps, net2.Ps, len_min=0.70, len_max=0.75) self.update(net1) ws.close_project(net1.project) # Deal with labels self.clear(mode='labels') Ps = np.any(np.mod(self['pore.coords'], 1) == 0, axis=1) self['pore.face_sites'] = Ps self['pore.corner_sites'] = ~Ps Ts = self.find_neighbor_throats(pores=self.pores('corner_sites'), mode='xnor') self['throat.corner_to_corner'] = False self['throat.corner_to_corner'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('face_sites')) self['throat.corner_to_face'] = False self['throat.corner_to_face'][Ts] = True elif mode == 'hcp': raise NotImplementedError('hcp is not implemented yet') elif mode == 'sc': net = Cubic(shape=shape, spacing=1) self.update(net) ws.close_project(net.project) self.clear(mode='labels') self['pore.corner_sites'] = True self['throat.corner_to_corner'] = True else: raise Exception('Unrecognized lattice type: ' + mode) # Finally scale network to specified spacing topotools.label_faces(self) Ps = self.pores(['left', 'right', 'top', 'bottom', 'front', 'back']) Ps = self.tomask(pores=Ps) self['pore.surface'] = Ps self['pore.internal'] = ~Ps self['pore.coords'] *= np.array(spacing)
def __init__(self, shape, spacing=[1, 1, 1], connectivity=6, name=None, project=None, **kwargs): super().__init__(name=name, project=project, **kwargs) # Take care of 1D/2D networks shape = np.array(shape, ndmin=1) shape = np.concatenate((shape, [1] * (3 - shape.size))).astype(int) arr = np.atleast_3d(np.empty(shape)) # Store original network shape self.settings['shape'] = np.shape(arr) # Store network spacing spacing = np.float64(spacing) if spacing.size == 2: spacing = np.concatenate((spacing, [1])) spacing = np.ones(3, dtype=float) * np.array(spacing, ndmin=1) self.settings['spacing'] = spacing.tolist() z = np.tile(np.arange(shape[2]), shape[0] * shape[1]) y = np.tile(np.repeat(np.arange(shape[1]), shape[2]), shape[0]) x = np.repeat(np.arange(shape[0]), shape[1] * shape[2]) points = (np.vstack([x, y, z]).T).astype(float) + 0.5 idx = np.arange(arr.size).reshape(arr.shape) face_joints = [(idx[:, :, :-1], idx[:, :, 1:]), (idx[:, :-1], idx[:, 1:]), (idx[:-1], idx[1:])] corner_joints = [(idx[:-1, :-1, :-1], idx[1:, 1:, 1:]), (idx[:-1, :-1, 1:], idx[1:, 1:, :-1]), (idx[:-1, 1:, :-1], idx[1:, :-1, 1:]), (idx[1:, :-1, :-1], idx[:-1, 1:, 1:])] edge_joints = [(idx[:, :-1, :-1], idx[:, 1:, 1:]), (idx[:, :-1, 1:], idx[:, 1:, :-1]), (idx[:-1, :, :-1], idx[1:, :, 1:]), (idx[1:, :, :-1], idx[:-1, :, 1:]), (idx[1:, 1:, :], idx[:-1, :-1, :]), (idx[1:, :-1, :], idx[:-1, 1:, :])] if connectivity == 6: joints = face_joints elif connectivity == 6 + 8: joints = face_joints + corner_joints elif connectivity == 6 + 12: joints = face_joints + edge_joints elif connectivity == 12 + 8: joints = edge_joints + corner_joints elif connectivity == 6 + 8 + 12: joints = face_joints + corner_joints + edge_joints else: raise Exception("Invalid connectivity. Must be 6, 14, 18, 20 or 26.") tails, heads = np.array([], dtype=int), np.array([], dtype=int) for T, H in joints: tails = np.concatenate((tails, T.flatten())) heads = np.concatenate((heads, H.flatten())) pairs = np.vstack([tails, heads]).T self["pore.all"] = np.ones([points.shape[0], ], dtype=bool) self["throat.all"] = np.ones([pairs.shape[0], ], dtype=bool) self["pore.coords"] = points self["throat.conns"] = pairs self["pore.internal"] = True self["throat.internal"] = True self._label_surface_pores() topotools.label_faces(network=self) Ps = self["pore.surface"] self["throat.surface"] = np.all(Ps[self["throat.conns"]], axis=1) # Scale network to requested spacing self["pore.coords"] *= spacing
def __init__(self, shape, mode='sc', spacing=1, **kwargs): super().__init__(**kwargs) shape = np.array(shape) if np.any(shape < 2): raise Exception('Bravais lattice networks must have at least 2 ' 'pores in all directions') if mode == 'bcc': # Make a basic cubic for the coner pores net1 = Cubic(shape=shape) net1['pore.net1'] = True # Create a smaller cubic for the body pores, and shift it net2 = Cubic(shape=shape - 1) net2['pore.net2'] = True net2['pore.coords'] += 0.5 # Stitch them together topotools.stitch(net1, net2, net1.Ps, net2.Ps, len_max=0.99) self.update(net1) ws.close_project(net1.project) # Deal with labels Ps1 = self['pore.net2'] self.clear(mode='labels') self['pore.corner_sites'] = ~Ps1 self['pore.body_sites'] = Ps1 Ts = self.find_neighbor_throats(pores=self.pores('body_sites'), mode='exclusive_or') self['throat.corner_to_body'] = False self['throat.corner_to_body'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('corner_sites'), mode='xnor') self['throat.corner_to_corner'] = False self['throat.corner_to_corner'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('body_sites'), mode='xnor') self['throat.body_to_body'] = False self['throat.body_to_body'][Ts] = True elif mode == 'fcc': shape = np.array(shape) # Create base cubic network of corner sites net1 = Cubic(shape=shape) # Create 3 networks to become face sites net2 = Cubic(shape=shape - [1, 1, 0]) net3 = Cubic(shape=shape - [1, 0, 1]) net4 = Cubic(shape=shape - [0, 1, 1]) net2['pore.coords'] += np.array([0.5, 0.5, 0]) net3['pore.coords'] += np.array([0.5, 0, 0.5]) net4['pore.coords'] += np.array([0, 0.5, 0.5]) # Remove throats from net2 (trim doesn't work when removing ALL) for n in [net2, net3, net4]: n.clear(element='throat', mode='all') n.update({'throat.all': np.array([], dtype=bool)}) n.update({'throat.conns': np.ndarray([0, 2], dtype=bool)}) # Join networks 2, 3 and 4 into one with all face sites topotools.stitch(net2, net3, net2.Ps, net3.Ps, method='radius', len_max=0.75) topotools.stitch(net2, net4, net2.Ps, net4.Ps, method='radius', len_max=0.75) # Join face sites network with the corner sites network topotools.stitch(net1, net2, net1.Ps, net2.Ps, method='radius', len_max=0.75) self.update(net1) ws.close_project(net1.project) # Deal with labels self.clear(mode='labels') Ps = np.any(np.mod(self['pore.coords'], 1) == 0, axis=1) self['pore.face_sites'] = Ps self['pore.corner_sites'] = ~Ps Ts = self.find_neighbor_throats(pores=self.pores('corner_sites'), mode='xnor') self['throat.corner_to_corner'] = False self['throat.corner_to_corner'][Ts] = True Ts = self.find_neighbor_throats(pores=self.pores('face_sites')) self['throat.corner_to_face'] = False self['throat.corner_to_face'][Ts] = True elif mode == 'hcp': raise NotImplementedError('hcp is not implemented yet') elif mode == 'sc': net = Cubic(shape=shape, spacing=1) self.update(net) ws.close_project(net.project) self.clear(mode='labels') self['pore.corner_sites'] = True self['throat.corner_to_corner'] = True else: raise Exception('Unrecognized lattice type: ' + mode) # Finally scale network to specified spacing topotools.label_faces(self) Ps = self.pores(['left', 'right', 'top', 'bottom', 'front', 'back']) Ps = self.to_mask(pores=Ps) self['pore.surface'] = Ps self['pore.coords'] *= np.array(spacing)
def __init__(self, shape, spacing=[1, 1, 1], connectivity=6, name=None, project=None): # Take care of 1D/2D networks shape = sp.array(shape, ndmin=1) shape = np.concatenate((shape, [1]*(3-shape.size))).astype(int) arr = np.atleast_3d(np.empty(shape)) # Store original network shape self._shape = sp.shape(arr) # Store network spacing spacing = sp.float64(spacing) if spacing.size == 2: spacing = sp.concatenate((spacing, [1])) self._spacing = sp.ones(3, dtype=float)*sp.array(spacing, ndmin=1) z = np.tile(np.arange(shape[2]), shape[0]*shape[1]) y = np.tile(np.repeat(np.arange(shape[1]), shape[2]), shape[0]) x = np.repeat(np.arange(shape[0]), shape[1]*shape[2]) points = (np.vstack([x, y, z]).T).astype(float) + 0.5 I = np.arange(arr.size).reshape(arr.shape) face_joints = [(I[:, :, :-1], I[:, :, 1:]), (I[:, :-1], I[:, 1:]), (I[:-1], I[1:])] corner_joints = [(I[:-1, :-1, :-1], I[1:, 1:, 1:]), (I[:-1, :-1, 1:], I[1:, 1:, :-1]), (I[:-1, 1:, :-1], I[1:, :-1, 1:]), (I[1:, :-1, :-1], I[:-1, 1:, 1:])] edge_joints = [(I[:, :-1, :-1], I[:, 1:, 1:]), (I[:, :-1, 1:], I[:, 1:, :-1]), (I[:-1, :, :-1], I[1:, :, 1:]), (I[1:, :, :-1], I[:-1, :, 1:]), (I[1:, 1:, :], I[:-1, :-1, :]), (I[1:, :-1, :], I[:-1, 1:, :])] if connectivity == 6: joints = face_joints elif connectivity == 8: joints = corner_joints elif connectivity == 12: joints = edge_joints elif connectivity == 14: joints = face_joints + corner_joints elif connectivity == 18: joints = face_joints + edge_joints elif connectivity == 20: joints = edge_joints + corner_joints elif connectivity == 26: joints = face_joints + corner_joints + edge_joints else: raise Exception('Invalid connectivity receieved. Must be 6, 8, ' '12, 14, 18, 20 or 26') tails, heads = np.array([], dtype=int), np.array([], dtype=int) for T, H in joints: tails = np.concatenate((tails, T.flatten())) heads = np.concatenate((heads, H.flatten())) pairs = np.vstack([tails, heads]).T super().__init__(Np=points.shape[0], Nt=pairs.shape[0], name=name, project=project) self['pore.coords'] = points self['throat.conns'] = pairs self['pore.internal'] = True self['throat.internal'] = True self._label_surface_pores() topotools.label_faces(network=self) Ps = self['pore.surface'] self['throat.surface'] = sp.all(Ps[self['throat.conns']], axis=1) # Scale network to requested spacing self['pore.coords'] *= spacing