#NEWLINE# def trim( network , pores = [ ] , throats = [ ] ) : #NEWLINE# #INDENT# '\n    Remove pores or throats from the network.  This is an in-place operation,\n    meaning the received Network object will be altered directly.\n\n    Parameters\n    ----------\n    network : OpenPNM Network Object\n        The Network from which pores or throats should be removed\n    pores (or throats) : array_like\n        A boolean mask of length Np (or Nt) or a list of indices of the\n        pores (or throats) to be removed.\n\n    Notes\n    -----\n    Trimming only adjusts Phase, Geometry, and Physics objects. Trimming a\n    Network that has already been used to run simulations will break those\n    simulation objects.\n\n    Examples\n    --------\n    >>> import OpenPNM\n    >>> pn = OpenPNM.Network.TestNet()\n    >>> pn.Np\n    125\n    >>> pn.Nt\n    300\n    >>> pn.trim(pores=[1])\n    >>> pn.Np\n    124\n    >>> pn.Nt\n    296\n\n    ' #NEWLINE# ctrl = network . controller #NEWLINE# for net in ctrl . networks ( ) : #NEWLINE# #INDENT# if ( net . _parent is network ) : #NEWLINE# #INDENT# raise Exception ( 'This Network has been cloned, cannot trim' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( _sp . size ( pores ) > 0 ) and ( _sp . size ( throats ) > 0 ) ) : #NEWLINE# #INDENT# raise Exception ( 'Cannot delete pores and throats simultaneously' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( _sp . size ( pores ) > 0 ) : #NEWLINE# #INDENT# pores = _sp . array ( pores , ndmin = 1 ) #NEWLINE# Pkeep = _sp . ones ( ( network . num_pores ( ) , ) , dtype = bool ) #NEWLINE# Pkeep [ pores ] = False #NEWLINE# Tkeep = _sp . ones ( ( network . num_throats ( ) , ) , dtype = bool ) #NEWLINE# Ts = network . find_neighbor_throats ( pores ) #NEWLINE# if ( len ( Ts ) > 0 ) : #NEWLINE# #INDENT# Tkeep [ Ts ] = False #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( _sp . size ( throats ) > 0 ) : #NEWLINE# #INDENT# throats = _sp . array ( throats , ndmin = 1 ) #NEWLINE# Tkeep = _sp . ones ( ( network . num_throats ( ) , ) , dtype = bool ) #NEWLINE# Tkeep [ throats ] = False #NEWLINE# Pkeep = network [ 'pore.all' ] . copy ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# logger . warning ( 'No pores or throats recieved' ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for item in ( ( network . _geometries + network . _physics ) + network . _phases ) : #NEWLINE# #INDENT# Pnet = ( network [ ( 'pore.' + item . name ) ] * Pkeep ) #NEWLINE# Tnet = ( network [ ( 'throat.' + item . name ) ] * Tkeep ) #NEWLINE# temp = network . map_pores ( pores = _sp . where ( Pnet ) [ 0 ] , target = item , return_mapping = True ) #NEWLINE# Ps = temp [ 'target' ] #NEWLINE# temp = network . map_throats ( throats = _sp . where ( Tnet ) [ 0 ] , target = item , return_mapping = True ) #NEWLINE# Ts = temp [ 'target' ] #NEWLINE# item . update ( { #NEWLINE# #INDENT# 'pore.all' : _sp . ones ( ( _sp . sum ( Pnet ) , ) , dtype = bool ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# item . update ( { #NEWLINE# #INDENT# 'throat.all' : _sp . ones ( ( _sp . sum ( Tnet ) , ) , dtype = bool ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# for key in list ( item . keys ( ) ) : #NEWLINE# #INDENT# if ( key . split ( '.' ) [ 1 ] not in [ 'all' ] ) : #NEWLINE# #INDENT# temp = item . pop ( key ) #NEWLINE# if ( key . split ( '.' ) [ 0 ] == 'throat' ) : #NEWLINE# #INDENT# logger . debug ( 'Trimming {a} from {b}' . format ( a = key , b = ctrl . name ) ) #NEWLINE# item [ key ] = temp [ Ts ] #NEWLINE# #UNINDENT# if ( key . split ( '.' ) [ 0 ] == 'pore' ) : #NEWLINE# #INDENT# logger . debug ( 'Trimming {a} from {b}' . format ( a = key , b = item . name ) ) #NEWLINE# item [ key ] = temp [ Ps ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# Pmap = ( _sp . ones ( ( network . Np , ) , dtype = int ) * ( - 1 ) ) #NEWLINE# Pmap [ Pkeep ] = _sp . arange ( 0 , _sp . sum ( Pkeep ) ) #NEWLINE# tpore1 = network [ 'throat.conns' ] [ : , 0 ] #NEWLINE# tpore2 = network [ 'throat.conns' ] [ : , 1 ] #NEWLINE# Tnew1 = Pmap [ tpore1 [ Tkeep ] ] #NEWLINE# Tnew2 = Pmap [ tpore2 [ Tkeep ] ] #NEWLINE# network . update ( { #NEWLINE# #INDENT# 'throat.all' : _sp . ones ( ( _sp . sum ( Tkeep ) , ) , dtype = bool ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# network . update ( { #NEWLINE# #INDENT# 'pore.all' : _sp . ones ( ( _sp . sum ( Pkeep ) , ) , dtype = bool ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# network . update ( { #NEWLINE# #INDENT# 'throat.conns' : _sp . vstack ( ( Tnew1 , Tnew2 ) ) . T , #NEWLINE# #UNINDENT# } ) #NEWLINE# for item in list ( network . keys ( ) ) : #NEWLINE# #INDENT# if ( item . split ( '.' ) [ ( - 1 ) ] not in [ 'conns' , 'all' ] ) : #NEWLINE# #INDENT# temp = network . pop ( item ) #NEWLINE# if ( item . split ( '.' ) [ 0 ] == 'throat' ) : #NEWLINE# #INDENT# logger . debug ( 'Trimming {a} from {b}' . format ( a = item , b = network . name ) ) #NEWLINE# network [ item ] = temp [ Tkeep ] #NEWLINE# #UNINDENT# if ( item . split ( '.' ) [ 0 ] == 'pore' ) : #NEWLINE# #INDENT# logger . debug ( 'Trimming {a} from {b}' . format ( a = item , b = network . name ) ) #NEWLINE# network [ item ] = temp [ Pkeep ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# network . _update_network ( mode = 'regenerate' ) #NEWLINE# health = network . check_network_health ( ) #NEWLINE# if ( health [ 'trim_pores' ] != [ ] ) : #NEWLINE# #INDENT# logger . warning ( 'Isolated pores exist!  Run check_network_health to ID                         which pores to remove.' ) #NEWLINE# pass