[docs]deffind_isolated_clusters(network,mask,inlets):r""" Identifies pores and throats that are invaded but not connected to the inlets Parameters ---------- network : dict The OpenPNM Network mask : ndarray A boolean mask of either Nt or Np length with ``True`` values indicating invaded bonds or sites. If this array is Nt-long then then bond percolation is used to identify clusters, whereas site percolation is used if it is Np-long. inlets : ndarray A array containing indices of the pores which define the inlets. Any clusters not connected to these sites are considered isolated. Returns ------- sites : ndarray An ndarray containing the indices of invaded pores which are not connected to the given ``inlets``. """labels=find_clusters(network=network,mask=mask)isolated=np.in1d(labels.pore_labels,labels.pore_labels[inlets],invert=True)isolated=np.where(isolated)[0]returnisolated
[docs]deffind_clusters(network,mask=[]):r""" Identify connected clusters of pores and throats in the network. Either site and bond percolation can be considered, see description of ``mask`` argument for details. Parameters ---------- network : Network The network mask : array_like, boolean A list of open bonds or sites (throats or pores). If the mask is Np-long, then the method will perform a site percolation to identify clusters, and if the mask is Nt-long bond percolation will be performed. Returns ------- p_labels, t_labels : tuple of ndarrays A tuple containing an Np-long array of pore cluster labels, and an Nt-long array of throat cluster labels. The label numbers correspond such that pores and throats with the same label are part of the same cluster. Uninvaded locations are set to -1. """# Parse the input argumentsmask=np.array(mask,ndmin=1)ifmask.dtype!=bool:raiseException('Mask must be a boolean array of Np or Nt length')# If pore mask was given perform site percolationifnp.size(mask)==network.Np:(p_clusters,t_clusters)= \
simulations.site_percolation(network.conns,mask)# If pore mask was given perform bond percolationelifnp.size(mask)==network.Nt:(p_clusters,t_clusters)= \
simulations.bond_percolation(network.conns,mask)else:raiseException('Mask received was neither Nt nor Np long')result=namedtuple('result',('pore_labels','throat_labels'))result.pore_labels=p_clustersresult.throat_labels=t_clustersreturnresult