#NEWLINE# def stitch( network , donor , P_network , P_donor , method = 'nearest' , len_max = _sp . inf , label_suffix = '' ) : #NEWLINE# #INDENT# "\n    Stitches a second a network to the current network.\n\n    Parameters\n    ----------\n    networK : OpenPNM Network Object\n        The Network that will to which to donor Network will be attached\n\n    donor : OpenPNM Network Object\n        The Network to stitch on to the current Network\n\n    P_network : array_like\n        The pores on the current Network\n\n    P_donor : array_like\n        The pores on the donor Network\n\n    label_suffix : string or None\n        Some text to append to each label in the donor Network before\n        inserting them into the recipient.  The default is to append no\n        text, but a common option would be to append the donor Network's\n        name. To insert none of the donor labels, use None.\n\n    len_max : float\n        Set a length limit on length of new throats\n\n    method : string (default = 'delaunay')\n        The method to use when making pore to pore connections. Options are:\n\n        - 'delaunay' : Use a Delaunay tessellation\n        - 'nearest' : Connects each pore on the receptor network to its nearest\n                      pore on the donor network\n\n    Notes\n    -----\n    Before stitching it is necessary to translate the pore coordinates of\n    one of the Networks so that it is positioned correctly relative to the\n    other.\n\n    Examples\n    --------\n    >>> import OpenPNM\n    >>> pn = OpenPNM.Network.TestNet()\n    >>> pn2 = OpenPNM.Network.TestNet()\n    >>> [pn.Np, pn.Nt]\n    [125, 300]\n    >>> [pn2.Np, pn2.Nt]\n    [125, 300]\n    >>> pn2['pore.coords'][:, 2] += 5.0\n    >>> pn.stitch(donor=pn2, P_network=pn.pores('top'),\n    ...           P_donor=pn2.pores('bottom'), method='nearest', len_max=1.0)\n    >>> [pn.Np, pn.Nt]\n    [250, 625]\n\n    " #NEWLINE# if ( ( len ( network . _simulation ( ) ) > 1 ) or ( len ( donor . _simulation ( ) ) > 1 ) ) : #NEWLINE# #INDENT# raise Exception ( 'Cannot stitch a Network with active sibling objects' ) #NEWLINE# #UNINDENT# N_init = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# N_init [ 'pore' ] = network . Np #NEWLINE# N_init [ 'throat' ] = network . Nt #NEWLINE# if ( method == 'nearest' ) : #NEWLINE# #INDENT# P1 = P_network #NEWLINE# P2 = ( P_donor + N_init [ 'pore' ] ) #NEWLINE# C1 = network [ 'pore.coords' ] [ P_network ] #NEWLINE# C2 = donor [ 'pore.coords' ] [ P_donor ] #NEWLINE# D = _sp . spatial . distance . cdist ( C1 , C2 ) #NEWLINE# [ P1_ind , P2_ind ] = _sp . where ( ( D <= len_max ) ) #NEWLINE# conns = _sp . vstack ( ( P1 [ P1_ind ] , P2 [ P2_ind ] ) ) . T #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise RuntimeError ( '<{}> method not supported' . format ( method ) ) #NEWLINE# #UNINDENT# extend ( network = network , pore_coords = donor [ 'pore.coords' ] ) #NEWLINE# extend ( network = network , throat_conns = ( donor [ 'throat.conns' ] + N_init [ 'pore' ] ) ) #NEWLINE# C1 = network [ 'pore.coords' ] [ conns [ : , 0 ] ] #NEWLINE# C2 = network [ 'pore.coords' ] [ conns [ : , 1 ] ] #NEWLINE# L = ( _sp . sum ( ( ( C1 - C2 ) ** 2 ) , axis = 1 ) ** 0.5 ) #NEWLINE# conns = conns [ ( L <= len_max ) ] #NEWLINE# if ( label_suffix is not None ) : #NEWLINE# #INDENT# if ( label_suffix != '' ) : #NEWLINE# #INDENT# label_suffix = ( '_' + label_suffix ) #NEWLINE# #UNINDENT# for label in donor . labels ( ) : #NEWLINE# #INDENT# element = label . split ( '.' ) [ 0 ] #NEWLINE# locations = _sp . where ( ( network . _get_indices ( element ) >= N_init [ element ] ) ) [ 0 ] #NEWLINE# try : #NEWLINE# #INDENT# network [ ( label + label_suffix ) ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# network [ ( label + label_suffix ) ] = False #NEWLINE# #UNINDENT# network [ ( label + label_suffix ) ] [ locations ] = donor [ label ] #NEWLINE# #UNINDENT# #UNINDENT# extend ( network = network , throat_conns = conns , labels = 'stitched' ) #NEWLINE# if ( donor in _ctrl . values ( ) ) : #NEWLINE# #INDENT# _ctrl . purge_object ( donor )