from numpy import pi as _pi
import numpy as _np


def cylinder(target, throat_diameter='throat.diameter'):
    r"""
    Calculate throat cross-sectional area for a cylindrical throat

    Parameters
    ----------
    target : OpenPNM Object
        The object which this model is associated with. This controls the
        length of the calculated array, and also provides access to other
        necessary properties.

    throat_diameter : string
        Dictionary key of the throat diameter values

    """
    diams = target[throat_diameter]
    value = _pi/4*(diams)**2
    return value


def cuboid(target, throat_diameter='throat.diameter'):
    r"""
    Calculate throat cross-sectional area for a cuboid throat

    Parameters
    ----------
    target : OpenPNM Object
        The object which this model is associated with. This controls the
        length of the calculated array, and also provides access to other
        necessary properties.

    throat_diameter : string
        Dictionary key of the throat diameter values

    """
    diams = target[throat_diameter]
    value = (diams)**2
    return value


def equivalent_area_spherical_pores(target, throat_diameter='throat.diameter',
                                    throat_area='throat.area',
                                    pore_diameter='pore.diameter'):
    r"""
    Calculate equivalent cross-sectional area for a conduit consisting of two
    spherical pores and a constant cross-section throat. This area can be later
    used to calculate hydraulic or diffusive conductance of the conduit.

    Parameters
    ----------
    target : OpenPNM Object
        The object which this model is associated with. This controls the
        length of the calculated array, and also provides access to other
        necessary properties.

    throat_diameter : string
        Dictionary key of the throat diameter values

    throat_area : string
        Dictionary key of the throat area values

    pore_diameter : string
        Dictionary key of the pore diameter values

    """
    network = target.project.network
    cn = network['throat.conns']
    dp = target[pore_diameter]
    d1 = dp[cn[:, 0]]
    d2 = dp[cn[:, 1]]
    dt = target[throat_diameter]
    L1 = _np.sqrt(d1**2 - dt**2) / 2            # Effective length of pore 1
    L2 = _np.sqrt(d2**2 - dt**2) / 2            # Effective length of pore 2
    C1 = network['pore.coords'][cn[:, 0]]
    C2 = network['pore.coords'][cn[:, 1]]
    L = _np.sqrt(_np.sum((C1-C2)**2, axis=1))   # c2c distance of pores
    Lt = L - (L1+L2)                            # Effective length of throat
    return L / (2 / (d1*_pi) * _np.arctanh(2*L1/d1) + Lt / target[throat_area] +
                2 / (d2*_pi) * _np.arctanh(2*L2/d2))

@@ -2754,8 +2754,1657 @@
 L2/d2))%0A
+%0A%0Adef equivalent_area_circular_pores(target, throat_diameter='throat.diameter',%0A                                   pore_diameter='pore.diameter'):%0A    r%22%22%22%0A    Calculate equivalent cross-sectional area for a conduit consisting of two%0A    spherical pores and a constant cross-section throat. This area can be later%0A    used to calculate hydraulic or diffusive conductance of the conduit.%0A%0A    Parameters%0A    ----------%0A    target : OpenPNM Object%0A        The object which this model is associated with. This controls the%0A        length of the calculated array, and also provides access to other%0A        necessary properties.%0A%0A    throat_diameter : string%0A        Dictionary key of the throat diameter values%0A%0A    throat_area : string%0A        Dictionary key of the throat area values%0A%0A    pore_diameter : string%0A        Dictionary key of the pore diameter values%0A%0A    %22%22%22%0A    network = target.project.network%0A    cn = network%5B'throat.conns'%5D%0A    dp = target%5Bpore_diameter%5D%0A    d1 = dp%5Bcn%5B:, 0%5D%5D%0A    d2 = dp%5Bcn%5B:, 1%5D%5D%0A    dt = target%5Bthroat_diameter%5D%0A    L1 = _np.sqrt(d1**2 - dt**2) / 2            # Effective length of pore 1%0A    L2 = _np.sqrt(d2**2 - dt**2) / 2            # Effective length of pore 2%0A    C1 = network%5B'pore.coords'%5D%5Bcn%5B:, 0%5D%5D%0A    C2 = network%5B'pore.coords'%5D%5Bcn%5B:, 1%5D%5D%0A    L = _np.sqrt(_np.sum((C1-C2)**2, axis=1))   # c2c distance of pores%0A    Lt = L - (L1+L2)                            # Effective length of throat%0A    throat_area = target%5Bthroat_diameter%5D%0A    return L / (1 / 2 * _np.arctan(2*L1/_np.sqrt(d1**2 - 4*L1**2)) +%0A                Lt / throat_area +%0A                1 / 2 * _np.arctan(2*L2/_np.sqrt(d2**2 - 4*L2**2)))%0A

Add model for equivalent area for conduits with circular pores