<commit_before>"""
module __Cubic__: Generate lattice-like networks
==========================================================

.. warning:: The classes of this module should be loaded through the 'Geometry/__init__.py' file.

"""
import OpenPNM

import numpy as np
import scipy as sp
from OpenPNM.Network.__GenericNetwork__ import GenericNetwork

class Cubic(GenericNetwork):
    r"""
    This class contains the methods to create a cubic network with an arbitrary
    domain shape defined by a supplied template.

    To invoke the actual generation it is necessary to run the `generate` method.

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

    loglevel : int
        Level of the logger (10=Debug, 20=Info, 30=Warning, 40=Error, 50=Critical)

    loggername : string
        Overwrite the name of the logger, which defaults to the class name

    Examples
    --------
    This class is a work in progress, examples forthcoming.
    """
    @classmethod
    def empty(cls, dims, *a, **kw):
        arr = np.zeros(dims)
        return cls(arr, *a, **kw)

    def __init__(self, ndarray, spacing=None, **kwargs):
        super(Cubic, self).__init__(**kwargs)
        ndarray = np.atleast_3d(ndarray)

        points_rel = np.array(
            [idx for idx,val in np.ndenumerate(ndarray)],
            dtype=float)
        self['pore.coords'] = points_rel

        I = np.arange(ndarray.size).reshape(ndarray.shape)
        tails, heads = [], []
        for T,H in [
            (I[:,:,:-1], I[:,:,1:]),
            (I[:,:-1], I[:,1:]),
            (I[:-1], I[1:]),
            ]:
            tails.extend(T.flat)
            tails.extend(H.flat)
            heads.extend(H.flat)
            heads.extend(T.flat)
        self['throat.conns'] = np.vstack([tails, heads]).T

        self['pore.all'] = np.ones(len(self['pore.coords']), dtype=bool)
        self['throat.all'] = np.ones(len(self['throat.conns']), dtype=bool)
        self['pore.values'] = ndarray.ravel()

        x,y,z = self['pore.coords'].T
        self['pore.back'] = z == z.min()
        self['pore.front'] = z == z.max()
        self['pore.bottom'] = y == y.min()
        self['pore.top'] = y == y.max()
        self['pore.left'] = x == x.min()
        self['pore.right'] = x == x.max()

    def add_boundaries(self):
        x,y,z = self['pore.coords'].T
        self['pore.back_face'] = z == z.min()
        self['pore.front_face'] = z == z.max()
        self['pore.bottom_face'] = y == y.min()<commit_msg>Cube able to compress<commit_after>"""
module __Cubic__: Generate lattice-like networks
==========================================================

.. warning:: The classes of this module should be loaded through the 'Geometry/__init__.py' file.

"""
import OpenPNM

import numpy as np
import scipy as sp
from OpenPNM.Network.__GenericNetwork__ import GenericNetwork

class Cubic(GenericNetwork):
    r"""
    This class contains the methods to create a cubic network with an arbitrary
    domain shape defined by a supplied template.

    To invoke the actual generation it is necessary to run the `generate` method.

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

    loglevel : int
        Level of the logger (10=Debug, 20=Info, 30=Warning, 40=Error, 50=Critical)

    loggername : string
        Overwrite the name of the logger, which defaults to the class name

    Examples
    --------
    This class is a work in progress, examples forthcoming.
    """
    @classmethod
    def empty(cls, dims, *a, **kw):
        arr = np.zeros(dims)
        return cls(arr, *a, **kw)

    def __init__(self, ndarray, spacing=None, unit_cube=False, **kwargs):
        super(Cubic, self).__init__(**kwargs)
        ndarray = np.atleast_3d(ndarray)

        points = np.array(
            [idx for idx,val in np.ndenumerate(ndarray)],
            dtype=float)

        if unit_cube:
            spacing = 1 / ( points_rel.max(axis=0) + 2 )
            points = spacing + spacing * points_rel
        self['pore.coords'] = points

        I = np.arange(ndarray.size).reshape(ndarray.shape)
        tails, heads = [], []
        for T,H in [
            (I[:,:,:-1], I[:,:,1:]),
            (I[:,:-1], I[:,1:]),
            (I[:-1], I[1:]),
            ]:
            tails.extend(T.flat)
            tails.extend(H.flat)
            heads.extend(H.flat)
            heads.extend(T.flat)
        self['throat.conns'] = np.vstack([tails, heads]).T

        self['pore.all'] = np.ones(len(self['pore.coords']), dtype=bool)
        self['throat.all'] = np.ones(len(self['throat.conns']), dtype=bool)
        self['pore.values'] = ndarray.ravel()

        x,y,z = self['pore.coords'].T
        self['pore.back'] = z == z.min()
        self['pore.front'] = z == z.max()
        self['pore.bottom'] = y == y.min()
        self['pore.top'] = y == y.max()
        self['pore.left'] = x == x.min()
        self['pore.right'] = x == x.max()

    def add_boundaries(self):
        x,y,z = self['pore.coords'].T
        self['pore.back_face'] = z == z.min()
        self['pore.front_face'] = z == z.max()
        self['pore.bottom_face'] = y == y.min()
{'fraction_non_alphanumeric': 0.17511076863802735, 'fraction_numerical': 0.00712772105567328, 'mean_word_length': 2.3367609254498714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5803357', 'n_tokens_mistral': 1713, 'n_tokens_neox': 1644, 'n_words': 423}