Exemple #1
0
    def mixedBC(self, boundary, userData):
        """Apply mixed boundary conditions."""
        if boundary.marker() != pg.MARKER_BOUND_MIXED:
            return 0

        sourcePos = pg.center(userData['sourcePos'])

        k = userData['k']
        r1 = boundary.center() - sourcePos

        # Mirror on surface at depth=0
        r2 = boundary.center() - pg.RVector3(1.0, -1.0, 1.0) * sourcePos
        r1A = r1.abs()
        r2A = r2.abs()

        rho = 1.

        if self.resistivity is not None:
            rho = self.resistivity[boundary.leftCell().id()]

        n = boundary.norm()

        if r1A > 1e-12 and r2A > 1e-12:
            if (pg.besselK0(r1A * k) + pg.besselK0(r2A * k)) > 1e-12:

                return 1./rho * k * (r1.dot(n) / r1A * pg.besselK1(r1A * k) +
                                     r2.dot(n) / r2A * pg.besselK1(r2A * k)) /\
                                (pg.besselK0(r1A * k) + pg.besselK0(r2A * k))
            else:
                return 0.
        else:
            return 0.
Exemple #2
0
    def mixedBC(self, boundary, userData):
        """Apply mixed boundary conditions."""
        if boundary.marker() != pg.MARKER_BOUND_MIXED:
            return 0

        sourcePos = pg.center(userData['sourcePos'])

        k = userData['k']
        r1 = boundary.center() - sourcePos

        # Mirror on surface at depth=0
        r2 = boundary.center() - pg.RVector3(1.0, -1.0, 1.0) * sourcePos
        r1A = r1.abs()
        r2A = r2.abs()

        rho = 1.

        if self.resistivity is not None:
            rho = self.resistivity[boundary.leftCell().id()]

        n = boundary.norm()

        if r1A > 1e-12 and r2A > 1e-12:
            if (pg.besselK0(r1A * k) + pg.besselK0(r2A * k)) > 1e-12:

                return 1./rho * k * (r1.dot(n) / r1A * pg.besselK1(r1A * k) +
                                     r2.dot(n) / r2A * pg.besselK1(r2A * k)) /\
                                (pg.besselK0(r1A * k) + pg.besselK0(r2A * k))
            else:
                return 0.
        else:
            return 0.
Exemple #3
0
def createPolygon(verts, isClosed=False, isHole=False, **kwargs):
    """Create a polygon from a list of vertices.

    All vertices needs to be unique and duplicate vertices will be ignored.
    If you want the polygon be a closed region you can set the 'isCloses' flag.
    Closed region can be attributed by assigning a region marker.
    The automatic region marker is set in the center of all vertices.

    Parameters
    ----------
    verts : []
        * List of x y pairs [[x0, y0], ... ,[xN, yN]]

    **kwargs:

        * boundaryMarker : int [1]
            Marker for the resulting boundary edges
        * leftDirection : bool [True]
            Rotational direction
        * marker : int [None]
            Marker for the resulting triangle cells after mesh generation.
        * area : float [0]
            Maximum cell size for resulting triangles after mesh generation
        * isHole : bool [False]
            The Polygone will become a hole instead of a triangulation

    isClosed : bool [True]
        Add closing edge between last and first node.

    Returns
    -------
    poly : :gimliapi:`GIMLI::Mesh`
        The resulting polygon is a :gimliapi:`GIMLI::Mesh`.

    Examples
    --------
    >>>  # no need to import matplotlib. pygimli's show does
    >>> import pygimli as pg
    >>> import pygimli.meshtools as mt
    >>> p1 = mt.createPolygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
    ...                       isClosed=True, marker=3, area=0.1)
    >>> p2 = mt.createPolygon([[0.3, 0.15], [0.85, 0.15], [0.85, 0.7]],
    ...                       isClosed=True, marker=3, area=0.1, isHole=True)
    >>> ax, _ = pg.show(mt.mergePLC([p1,p2]))
    """
    poly = pg.Mesh(2)

    for v in verts:
        poly.createNodeWithCheck(v, warn=True)

    boundaryMarker = kwargs.pop('boundaryMarker', 1)
    marker = kwargs.pop('marker', None)
    area = kwargs.pop('area', 0)
    isHole = kwargs.pop('isHole', False)

    polyCreateDefaultEdges_(poly, isClosed=isClosed, isHole=False,
                            boundaryMarker=boundaryMarker)

    if isClosed and marker is not None or area > 0:
        if isHole:
            poly.addHoleMarker(pg.center(poly.positions()))
        else:
            if marker is None:  # in case marker is None but area is given
                marker = 0
            poly.addRegionMarker(pg.center(poly.positions()),
                                 marker=marker, area=area)

    # set a regionmarker here .. somewhere

    pg.warnNonEmptyArgs(kwargs)
    return poly
Exemple #4
0
def createPolygon(verts, isClosed=False, **kwargs):
    """Create a polygon.

    Create a polygon from list of vertices.
    If the polygon is closed region attributes can be assigned.
    The automatic region marker is set in the center of all verts.


    Parameters
    ----------
    verts : []
        * List of x y pairs [[x0, y0], ... ,[xN, yN]]

    **kwargs:

        * boundaryMarker : int [1]
            Marker for the resulting boundary edges
        * leftDirection : bool [True]
            Rotational direction
        * marker : int [1]
            Marker for the resulting triangle cells after mesh generation
        * area : float [0]
            Maximum cell size for resulting triangles after mesh generation

    isClosed : bool [True]
        Add closing edge between last and first node.

    Returns
    -------
    poly : gimliapi:`GIMLI::Mesh`
        The resulting polygon is a gimliapi:`GIMLI::Mesh`.

    Examples
    --------
    >>>  # no need to import matplotlib. pygimli's show does
    >>> import pygimli as pg
    >>> import pygimli.meshtools as plc
    >>> p = plc.createPolygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
    ...                       isClosed=1, marker=3, area=0.1)
    >>> ax,_ = pg.show(p)
    >>> # (<matplotlib.axes.AxesSubplot object at 0x...>, None)
    """
    poly = pg.Mesh(2)

    for v in verts:
        poly.createNode(v)

    marker = kwargs.pop('marker', 0)
    area = kwargs.pop('area', 0)

    polyCreateDefaultEdges_(poly, isClosed=isClosed, **kwargs)

    if isClosed and marker is not 0 or area > 0:

        poly.addRegionMarker(pg.center(poly.positions()),
                             marker=marker,
                             area=area)

    # set a regionmarker here .. somewhere

    return poly
Exemple #5
0
def createPolygon(verts, isClosed=False, isHole=False, **kwargs):
    """Create a polygon.

    Create a polygon from list of vertices.
    If the polygon is closed region attributes can be assigned.
    The automatic region marker is set in the center of all verts.

    Parameters
    ----------
    verts : []
        * List of x y pairs [[x0, y0], ... ,[xN, yN]]

    **kwargs:

        * boundaryMarker : int [1]
            Marker for the resulting boundary edges
        * leftDirection : bool [True]
            Rotational direction
        * marker : int [1]
            Marker for the resulting triangle cells after mesh generation
        * area : float [0]
            Maximum cell size for resulting triangles after mesh generation
        * isHole : bool [False]
            The Polygone will become a hole instead of a triangulation

    isClosed : bool [True]
        Add closing edge between last and first node.

    Returns
    -------
    poly : gimliapi:`GIMLI::Mesh`
        The resulting polygon is a gimliapi:`GIMLI::Mesh`.

    Examples
    --------
    >>>  # no need to import matplotlib. pygimli's show does
    >>> import pygimli as pg
    >>> import pygimli.meshtools as mt
    >>> p1 = mt.createPolygon([[0.0, 0.0], [1.0, 0.0], [1.0, 1.0]],
    ...                       isClosed=True, marker=3, area=0.1)
    >>> p2 = mt.createPolygon([[0.3, 0.15], [0.85, 0.15], [0.85, 0.7]],
    ...                       isClosed=True, marker=3, area=0.1, isHole=True)
    >>> ax, _ = pg.show(mt.mergePLC([p1,p2]))
    """
    poly = pg.Mesh(2)

    for v in verts:
        poly.createNode(v)

    marker = kwargs.pop('marker', 0)
    area = kwargs.pop('area', 0)
    isHole = kwargs.pop('isHole', False)

    polyCreateDefaultEdges_(poly, isClosed=isClosed, isHole=False)

    if isClosed and marker is not 0 or area > 0:
        if isHole:
            poly.addHoleMarker(pg.center(poly.positions()))
        else:
            poly.addRegionMarker(pg.center(poly.positions()),
                                 marker=marker,
                                 area=area)

    # set a regionmarker here .. somewhere

    return poly