Пример #1
0
    def __init__(self, network=None, phase=None, geometry=None,
                 pores=[], throats=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        # Associate with Network
        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._physics.append(self)  # Register self with network

        # Associate with Phase
        if phase is None:
            phase = GenericPhase(network=self._net)
        phase._physics.append(self)  # Register self with phase
        self._phases.append(phase)  # Register phase with self

        if geometry is not None:
            if (sp.size(pores) > 0) or (sp.size(throats) > 0):
                raise Exception('Cannot specify a Geometry AND pores or throats')
            pores = self._net.toindices(self._net['pore.' + geometry.name])
            throats = self._net.toindices(self._net['throat.' + geometry.name])

        # Initialize a label dictionary in the associated phase and network
        self._phases[0]['pore.'+self.name] = False
        self._phases[0]['throat.'+self.name] = False
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        try:
            self.set_locations(pores=pores, throats=throats)
        except:
            self.controller.purge_object(self)
            raise Exception('Provided locations are in use, instantiation cancelled')
Пример #2
0
    def __init__(self, network=None, components=[], **kwargs):
        super(GenericPhase, self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network

        # Initialize label 'all' in the object's own info dictionaries
        self['pore.all'] = self._net['pore.all']
        self['throat.all'] = self._net['throat.all']

        #Set standard conditions on the fluid to get started
        self['pore.temperature'] = 298.0
        self['pore.pressure'] = 101325.0

        # Register Ohase object in Network dictionary
        self._net['pore.' + self.name] = True
        self._net['throat.' + self.name] = True

        if components != []:
            for comp in components:
                self.set_component(phase=comp)
        self._net._phases.append(self)  # Append this Phase to the Network
Пример #3
0
    def __init__(self,network=None,phase=None,geometry=None,pores=[],throats=[],**kwargs):
        super(GenericPhysics,self).__init__(**kwargs)
        logger.name = self.name

        #Associate with Network
        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._physics.append(self)  # Register self with network

        #Associate with Phase
        if phase is None:
            self._phases.append(GenericPhase())
        else:
            phase._physics.append(self)  # Register self with phase
            self._phases.append(phase)  # Register phase with self
            
        if geometry is not None:
            if (pores != []) or (throats != []):
                raise Exception('Cannot specify a Geometry AND pores or throats')
            pores = self._net.toindices(self._net['pore.'+geometry.name])
            throats = self._net.toindices(self._net['throat.'+geometry.name])

        #Initialize a label dictionary in the associated fluid
        self._phases[0]['pore.'+self.name] = False
        self._phases[0]['throat.'+self.name] = False
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        self.set_locations(pores=pores,throats=throats)
Пример #4
0
    def __init__(self, network=None, pores=[], throats=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            # Register self with network.geometries
            self._net._geometries.append(self)

        # Initialize a label dictionary in the associated network
        self._net['pore.' + self.name] = False
        self._net['throat.' + self.name] = False
        try:
            self.set_locations(pores=pores, throats=throats)
        except:
            self.controller.purge_object(self)
            raise Exception(
                'Provided locations are in use, instantiation cancelled')
Пример #5
0
    def __init__(self, network=None, **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        if network is None:
            network = GenericNetwork()
        self.network.update({network.name: network})

        # Initialize label 'all' in the object's own info dictionaries
        self['pore.all'] = self._net['pore.all']
        self['throat.all'] = self._net['throat.all']
Пример #6
0
    def __init__(self,
                 network=None,
                 phase=None,
                 geometry=None,
                 pores=[],
                 throats=[],
                 **kwargs):
        super(GenericPhysics, self).__init__(**kwargs)
        logger.name = self.name

        #Associate with Network
        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._physics.append(self)  # Register self with network

        #Associate with Phase
        if phase is None:
            self._phases.append(GenericPhase())
        else:
            phase._physics.append(self)  # Register self with phase
            self._phases.append(phase)  # Register phase with self

        if geometry is not None:
            if (pores != []) or (throats != []):
                raise Exception(
                    'Cannot specify a Geometry AND pores or throats')
            pores = self._net.toindices(self._net['pore.' + geometry.name])
            throats = self._net.toindices(self._net['throat.' + geometry.name])

        #Initialize a label dictionary in the associated fluid
        self._phases[0]['pore.' + self.name] = False
        self._phases[0]['throat.' + self.name] = False
        self._net['pore.' + self.name] = False
        self._net['throat.' + self.name] = False
        self.set_locations(pores=pores, throats=throats)
Пример #7
0
    def __init__(self,
                 network=None,
                 pores=[],
                 throats=[],
                 seed=None,
                 **kwargs):
        r"""
        Initialize
        """
        super(GenericGeometry, self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._geometries.append(
                self)  # Register self with network.geometries

        #Initialize a label dictionary in the associated network
        self._net['pore.' + self.name] = False
        self._net['throat.' + self.name] = False
        self.set_locations(pores=pores, throats=throats)
        self._seed = seed
Пример #8
0
    def __init__(self,network=None,pores=[],throats=[],seed=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericGeometry,self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._geometries.append(self)  # Register self with network.geometries

        #Initialize a label dictionary in the associated network
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        self.set_locations(pores=pores,throats=throats)
        self._seed = seed
Пример #9
0
    def __init__(self, network=None, pores=[], throats=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            # Register self with network.geometries
            self._net._geometries.append(self)

        # Initialize a label dictionary in the associated network
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        try:
            self.set_locations(pores=pores, throats=throats)
        except:
            self.controller.purge_object(self)
            raise Exception('Provided locations are in use, instantiation cancelled')
Пример #10
0
    def __init__(self, network=None, components=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        if network is None:
            network = GenericNetwork()
        self.network.update({network.name: network})

        # Initialize label 'all' in the object's own info dictionaries
        self['pore.all'] = self._net['pore.all']
        self['throat.all'] = self._net['throat.all']

        # Set standard conditions on the fluid to get started
        self['pore.temperature'] = 298.0
        self['pore.pressure'] = 101325.0

        # Register Ohase object in Network dictionary
        self._net['pore.'+self.name] = True
        self._net['throat.'+self.name] = True

        if components != []:
            for comp in components:
                self.set_component(phase=comp)
        self._net.phases.update({self.name: self})  # Connect Phase to Network
Пример #11
0
class GenericPhysics(OpenPNM.Base.Core):
    r"""
    Generic class to generate Physics objects

    Parameters
    ----------
    network : OpenPNM Network object
        The network to which this Physics should be attached

    phase : OpenPNM Phase object
        The Phase object to which this Physics applies
        
    geometry : OpenPNM Geometry object
        The Geometry object that defines the pores/throats where this Physics
        should be applied.  If this argument is supplied, then pores and 
        throats cannot be specified.

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the physics nowhere.  The locations can be
        change after instantiation using ``set_locations()``.  If pores and
        throats are supplied, than a geometry cannot be specified.

    name : str, optional
        A unique string name to identify the Physics object, typically same as
        instance name but can be anything.  If left blank, and name will be
        generated that include the class name and a random string.
        
    

    """
    def __init__(self,
                 network=None,
                 phase=None,
                 geometry=None,
                 pores=[],
                 throats=[],
                 **kwargs):
        super(GenericPhysics, self).__init__(**kwargs)
        logger.name = self.name

        #Associate with Network
        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._physics.append(self)  # Register self with network

        #Associate with Phase
        if phase is None:
            self._phases.append(GenericPhase())
        else:
            phase._physics.append(self)  # Register self with phase
            self._phases.append(phase)  # Register phase with self

        if geometry is not None:
            if (pores != []) or (throats != []):
                raise Exception(
                    'Cannot specify a Geometry AND pores or throats')
            pores = self._net.toindices(self._net['pore.' + geometry.name])
            throats = self._net.toindices(self._net['throat.' + geometry.name])

        #Initialize a label dictionary in the associated fluid
        self._phases[0]['pore.' + self.name] = False
        self._phases[0]['throat.' + self.name] = False
        self._net['pore.' + self.name] = False
        self._net['throat.' + self.name] = False
        self.set_locations(pores=pores, throats=throats)

    def __getitem__(self, key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'

        if key in self.keys():  # Look for data on self...
            return super(GenericPhysics, self).__getitem__(key)
        else:  # ...Then check Network
            return self._phases[0][key][self._phases[0][element + '.' +
                                                        self.name]]

    def set_locations(self, pores=[], throats=[], mode='add'):
        r'''
        Set the pore and throat locations of the Physics object

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats where the object should be applied.
        mode : string
            Indicates whether list of pores or throats is to be added or removed
            from the object.  Options are 'add' (default) or 'remove'.
        '''
        if len(pores) > 0:
            pores = sp.array(pores, ndmin=1)
            self._set_locations(element='pore', locations=pores, mode=mode)
        if len(throats) > 0:
            throats = sp.array(throats, ndmin=1)
            self._set_locations(element='throat', locations=throats, mode=mode)
Пример #12
0
class GenericGeometry(Core):
    r"""
    GenericGeometry - Base class to construct a Geometry object

    Parameters
    ----------
    network : OpenPNM Network Object

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the physics nowhere.  The locations can be
        change after instantiation using ``set_locations()``.

    name : string
        A unique name to apply to the object.  This name will also be used as a
        label to identify where this this geometry applies.

    Examples
    --------
    >>> pn = OpenPNM.Network.TestNet()
    >>> Ps = pn.pores()  # Get all pores
    >>> Ts = pn.throats()  # Get all throats
    >>> geom = OpenPNM.Geometry.GenericGeometry(network=pn,pores=Ps,throats=Ts)
    """

    def __init__(self,network=None,pores=[],throats=[],seed=None,**kwargs):
        r"""
        Initialize
        """
        super(GenericGeometry,self).__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._geometries.append(self)  # Register self with network.geometries

        #Initialize a label dictionary in the associated network
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        self.set_locations(pores=pores,throats=throats)
        self._seed = seed

    def __getitem__(self,key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'

        if key in self.keys():  # Look for data on self...
            return super(GenericGeometry,self).__getitem__(key)
        if key == 'throat.conns':  # Handle specifically
            [P1,P2] = self._net['throat.conns'][self._net[element+'.'+self.name]].T
            Pmap = sp.zeros((self._net.Np,),dtype=int)-1
            Pmap[self._net.pores(self.name)] = self.Ps
            conns = sp.array([Pmap[P1],Pmap[P2]]).T
            # Replace -1's with nans
            if sp.any(conns==-1):
                conns = sp.array(conns,dtype=object)
                conns[sp.where(conns==-1)] = sp.nan
            return conns
        else:  # ...Then check Network
            return self._net[key][self._net[element+'.'+self.name]]

    def set_locations(self,pores=[],throats=[],mode='add'):
        r'''
        Set the pore and throat locations of the Geometry object

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats in the Network where the object 
            should be applied
        mode : string
            Indicates whether list of pores or throats is to be added or removed
            from the object.  Options are 'add' (default) or 'remove'.

        '''
        if len(pores) > 0:
            pores = sp.array(pores,ndmin=1)
            self._set_locations(element='pore',locations=pores,mode=mode)
        if len(throats) > 0:
            throats = sp.array(throats,ndmin=1)
            self._set_locations(element='throat',locations=throats,mode=mode)
Пример #13
0
class GenericPhysics(OpenPNM.Base.Core):
    r"""
    Generic class to generate Physics objects

    Parameters
    ----------
    network : OpenPNM Network object
        The network to which this Physics should be attached

    phase : OpenPNM Phase object
        The Phase object to which this Physics applies

    geometry : OpenPNM Geometry object
        The Geometry object that defines the pores/throats where this Physics
        should be applied.  If this argument is supplied, then pores and
        throats cannot be specified.

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the physics nowhere.  The locations can be
        change after instantiation using ``set_locations()``.  If pores and
        throats are supplied, than a geometry cannot be specified.

    name : str, optional
        A unique string name to identify the Physics object, typically same as
        instance name but can be anything.  If left blank, and name will be
        generated that include the class name and a random string.

    """

    def __init__(self, network=None, phase=None, geometry=None,
                 pores=[], throats=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        # Associate with Network
        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            self._net._physics.append(self)  # Register self with network

        # Associate with Phase
        if phase is None:
            phase = GenericPhase(network=self._net)
        phase._physics.append(self)  # Register self with phase
        self._phases.append(phase)  # Register phase with self

        if geometry is not None:
            if (sp.size(pores) > 0) or (sp.size(throats) > 0):
                raise Exception('Cannot specify a Geometry AND pores or throats')
            pores = self._net.toindices(self._net['pore.' + geometry.name])
            throats = self._net.toindices(self._net['throat.' + geometry.name])

        # Initialize a label dictionary in the associated phase and network
        self._phases[0]['pore.'+self.name] = False
        self._phases[0]['throat.'+self.name] = False
        self._net['pore.'+self.name] = False
        self._net['throat.'+self.name] = False
        try:
            self.set_locations(pores=pores, throats=throats)
        except:
            self.controller.purge_object(self)
            raise Exception('Provided locations are in use, instantiation cancelled')

    def __getitem__(self, key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'
        if key in self.keys():  # Look for data on self...
            return super(GenericPhysics, self).__getitem__(key)
        else:  # ...Then check Network
            return self._phases[0][key][self._phases[0][element + '.' + self.name]]

    def _set_phase(self, phase):
        current_phase = self._phases[0]
        # Remove labels of self from current phase
        pore_label = current_phase.pop('pore.'+self.name)
        throat_label = current_phase.pop('throat.'+self.name)
        # Add labels of self to new phase
        phase['pore.'+self.name] = pore_label
        phase['throat.'+self.name] = throat_label
        # Replace phase reference on self
        self._phases[0] = phase
        # Remove physics reference on current phase
        current_phase._physics.remove(self)
        phase._physics.append(self)

    def _get_phase(self):
        return self._phases[0]

    parent_phase = property(fget=_get_phase, fset=_set_phase)

    def set_locations(self, pores=[], throats=[], mode='add'):
        r"""
        Set the pore and throat locations of the Physics object

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats where the object should be applied.
        mode : string
            Indicates whether list of pores or throats is to be added or removed
            from the object.  Options are 'add' (default) or 'remove'.
        """
        if sp.size(pores) > 0:
            self._set_locations(element='pore', locations=pores, mode=mode)
        if sp.size(throats) > 0:
            self._set_locations(element='throat', locations=throats, mode=mode)
Пример #14
0
class GenericGeometry(Core):
    r"""
    GenericGeometry - Base class to construct a Geometry object

    Parameters
    ----------
    network : OpenPNM Network Object

    pores and/or throats : array_like
        The list of pores and throats where this physics applies. If either are
        left blank this will apply the Geometry nowhere.  The locations can be
        changed after instantiation using ``set_locations()``.

    name : string
        A unique name to apply to the object.  This name will also be used as a
        label to identify where this geometry applies.

    Examples
    --------
    >>> import OpenPNM
    >>> pn = OpenPNM.Network.TestNet()
    >>> Ps = pn.pores()  # Get all pores
    >>> Ts = pn.throats()  # Get all throats
    >>> geom = OpenPNM.Geometry.GenericGeometry(network=pn,
    ...                                         pores=Ps,
    ...                                         throats=Ts)
    """
    def __init__(self, network=None, pores=[], throats=[], **kwargs):
        super().__init__(**kwargs)
        logger.name = self.name

        if network is None:
            self._net = GenericNetwork()
        else:
            self._net = network  # Attach network to self
            # Register self with network.geometries
            self._net._geometries.append(self)

        # Initialize a label dictionary in the associated network
        self._net['pore.' + self.name] = False
        self._net['throat.' + self.name] = False
        try:
            self.set_locations(pores=pores, throats=throats)
        except:
            self.controller.purge_object(self)
            raise Exception(
                'Provided locations are in use, instantiation cancelled')

    def __getitem__(self, key):
        element = key.split('.')[0]
        # Convert self.name into 'all'
        if key.split('.')[-1] == self.name:
            key = element + '.all'

        if key in list(self.keys()):  # Look for data on self...
            return super(GenericGeometry, self).__getitem__(key)
        if key == 'throat.conns':  # Handle specifically
            [P1, P2] = \
                self._net['throat.conns'][self._net[element+'.'+self.name]].T
            Pmap = sp.zeros((self._net.Np, ), dtype=int) - 1
            Pmap[self._net.pores(self.name)] = self.Ps
            conns = sp.array([Pmap[P1], Pmap[P2]]).T
            # Replace -1's with nans
            if sp.any(conns == -1):
                conns = sp.array(conns, dtype=object)
                conns[sp.where(conns == -1)] = sp.nan
            return conns
        else:  # ...Then check Network
            return self._net[key][self._net[element + '.' + self.name]]

    def set_locations(self, pores=[], throats=[], mode='add'):
        r"""
        Set the pore and throat locations of the Geometry object

        Parameters
        ----------
        pores and throats : array_like
            The list of pores and/or throats in the Network where the object
            should be applied
        mode : string
            Indicates whether list of pores or throats is to be added or
            removed from the object.  Options are 'add' (default) or 'remove'.

        """
        if sp.size(pores) > 0:
            self._set_locations(element='pore', locations=pores, mode=mode)
        if sp.size(throats) > 0:
            self._set_locations(element='throat', locations=throats, mode=mode)

    def plot_histograms(self,
                        throat_diameter='throat.diameter',
                        pore_diameter='pore.diameter',
                        throat_length='throat.length'):

        Plots.distributions(obj=self,
                            throat_diameter=throat_diameter,
                            pore_diameter=pore_diameter,
                            throat_length=throat_length)

    plot_histograms.__doc__ = Plots.distributions.__doc__