<commit_before># -*- coding: utf-8 -*-
"""
===============================================================================
CubicDual: Generate a cubic lattice with an interpentrating dual network
===============================================================================

"""
import scipy as sp
import OpenPNM.Utilities.misc as misc
from OpenPNM.Network import GenericNetwork
from OpenPNM.Base import logging
logger = logging.getLogger(__name__)


class CubicDual(GenericNetwork):
    r"""
    Generates a cubic network of the specified size and shape, then inserts
    as second cubic network to the corners of its lattice cells.  These two
    networks are further connected by throats enabling material to be
    exchanged between them.

    Parameters
    ----------
    name : string
        A unique name for the network

    shape : list of ints
        The size and shape of the primary cubic network in terms of the
        number of pores in each direction.  Secondary nodes will be added at
        corners of each unit cell so the dual network will generaly have a
        size of ''shape'' + 1.

    spacing : list of floats
        The distance between pores of the primary network in each of the
        principal directions

    label_1 and label_2 : strings
        The labels to apply to the primary and secondary cubic lattices, which
        defaults to 'primary' and 'secondary' respectively.

    Examples
    --------
    >>>
    """
    def __init__(self, shape=None, spacing=[1, 1, 1], label_1='corners',
                 label_2='centers', **kwargs):
        super().__init__(**kwargs)
        import OpenPNM as op
        spacing = sp.array(1)
        shape = sp.array([5, 5, 5])
        label_1 = 'primary'
        label_2 = 'secondary'
        net = op.Network.Cubic(shape=shape, spacing=[1, 1, 1])
        net.add_boundaries()
        net['throat.'+label_1] = True
        net['pore.'+label_1] = True
        dual = op.Network.Cubic(shape=shape+1)
        dual['pore.'+label_2] = True
        dual['throat.'+label_2] = True
        dual['pore.coords'] -= 0.5
        op.Network.tools.stitch(net, dual, P_network=net.Ps,
                                P_donor=dual.Ps, len_max=1)
        net['throat.interconnect'] = net['throat.stitched']
        del net['throat.stitched']
        net['pore.surface'] = False
        net['throat.surface'] = False
        # Create center pores on each surface
        offset = {'back': [0.5, 0, 0], 'front': [-0.5, 0, 0],
                  'right': [0, 0.5, 0], 'left': [0, -0.5, 0],
                  'top': [0, 0, 0.5], 'bottom': [0, 0, -0.5]}
        surface_labels = ['top', 'bottom', 'left', 'right', 'front', 'back']
        for item in surface_labels:
            # Clone 'center' pores and shift to surface
            Ps = net.pores(labels=[item, label_2], mode='intersection')
            net['pore.'+item][Ps] = False
            net['pore._clone'] = False
            net['throat._clone'] = False
            net.clone_pores(pores=Ps, apply_label=[label_2, '_clone'])
            Ps = net.pores(labels=['_clone'])
            net['pore.coords'][Ps] += offset[item]
            Ts = net.find_neighbor_throats(pores=Ps)
            # Label pores and throats
            net['pore.surface'][Ps] = True
            net['pore.'+item][Ps] = True
            net['throat.'+label_2][Ts] = True
        # Connect surface pores of both networks to each other
        for item in surface_labels:
            Ps1 = net.pores(labels=['surface', item], mode='intersection')
            Ps2 = net.find_nearby_pores(pores=Ps1, distance=0.7072)
            for row in range(len(Ps1)):
                Ps3 = net.filter_by_label(pores=Ps2[row], labels=[item])
                if Ps3.size:
                    conns = sp.array([list([Ps1[row]])*Ps3.size, Ps3]).T
                    net.extend(throat_conns=conns,
                               labels=['surface', 'interconnect'])

        # Clean-ups
        net['pore.coords'] *= spacing
        Ps = net.pores(labels=surface_labels)
        net['pore.surface'][Ps] = True
        net['pore.internal'] = ~net['pore.surface']
        Ts = net.find_neighbor_throats(pores=net['pore.internal'])
        net['throat.internal'] = False
        net['throat.internal'][Ts] = True
        del net['pore._clone']
        del net['throat._clone']
        [self.update({item: net[item]}) for item in net]
        del self.workspace[net.name]

    def add_boundary_pores(self, pores, offset, apply_label='boundary'):
        r"""
        This method uses ``clone_pores`` to clone the input pores, then shifts
        them the specified amount and direction, then applies the given label.

        Parameters
        ----------
        pores : array_like
            List of pores to offset.  If no pores are specified, then it
            assumes that all surface pores are to be cloned.

        offset : 3 x 1 array
            The distance in vector form which the cloned boundary pores should
            be offset.

        apply_label : string<commit_msg>Forgot to save before last commit, duh<commit_after># -*- coding: utf-8 -*-
"""
===============================================================================
CubicDual: Generate a cubic lattice with an interpentrating dual network
===============================================================================

"""
import scipy as sp
import OpenPNM.Utilities.misc as misc
from OpenPNM.Network import GenericNetwork
from OpenPNM.Base import logging
logger = logging.getLogger(__name__)


class CubicDual(GenericNetwork):
    r"""
    Generates a cubic network of the specified size and shape, then inserts
    as second cubic network to the corners of its lattice cells.  These two
    networks are further connected by throats enabling material to be
    exchanged between them.

    Parameters
    ----------
    name : string
        A unique name for the network

    shape : list of ints
        The size and shape of the primary cubic network in terms of the
        number of pores in each direction.  Secondary nodes will be added at
        corners of each unit cell so the dual network will generaly have a
        size of ''shape'' + 1.

    spacing : list of floats
        The distance between pores of the primary network in each of the
        principal directions

    label_1 and label_2 : strings
        The labels to apply to the primary and secondary cubic lattices, which
        defaults to 'primary' and 'secondary' respectively.

    Examples
    --------
    >>>
    """
    def __init__(self, shape=None, spacing=[1, 1, 1], label_1='corners',
                 label_2='centers', **kwargs):
        super().__init__(**kwargs)
        import OpenPNM as op
        spacing = sp.array(1)
        shape = sp.array([5, 5, 5])
        label_1 = 'primary'
        label_2 = 'secondary'
        net = op.Network.Cubic(shape=shape, spacing=[1, 1, 1])
        net.add_boundaries()
        net['throat.'+label_1] = True
        net['pore.'+label_1] = True
        dual = op.Network.Cubic(shape=shape+1)
        dual['pore.'+label_2] = True
        dual['throat.'+label_2] = True
        dual['pore.coords'] -= 0.5
        op.Network.tools.stitch(net, dual, P_network=net.Ps,
                                P_donor=dual.Ps, len_max=1)
        net['throat.interconnect'] = net['throat.stitched']
        del net['throat.stitched']
        net['pore.surface'] = False
        net['throat.surface'] = False


        # Clean-ups
        net['pore.coords'] *= spacing
        Ps = net.pores(labels=surface_labels)
        net['pore.surface'][Ps] = True
        net['pore.internal'] = ~net['pore.surface']
        Ts = net.find_neighbor_throats(pores=net['pore.internal'])
        net['throat.internal'] = False
        net['throat.internal'][Ts] = True
        del net['pore._clone']
        del net['throat._clone']
        [self.update({item: net[item]}) for item in net]
        del self.workspace[net.name]

    def add_boundary_pores(self, pores, offset, apply_label='boundary'):
        r"""
        This method uses ``clone_pores`` to clone the input pores, then shifts
        them the specified amount and direction, then applies the given label.

        Parameters
        ----------
        pores : array_like
            List of pores to offset.  If no pores are specified, then it
            assumes that all surface pores are to be cloned.

        offset : 3 x 1 array
            The distance in vector form which the cloned boundary pores should
            be offset.

        apply_label : string
{'fraction_non_alphanumeric': 0.14569998836262074, 'fraction_numerical': 0.011404631676946352, 'mean_word_length': 2.332299340829779, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103513', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2380, 'n_words': 762}