コード例 #1
0
def street(nx, nz):
    """ Geometry: Street model.

    Parameters
    ----------
    nx : int
        Width of the domain.
    nz : int
        Height of the domain.
    """

    geo = [
        Obstacle([0, 0, int(0.7 * nx), int(nz * 0.25)], 'WWWW'),
        Obstacle([int(0.8 * nx), 0, nx - 1,
                  int(nz * 0.25)], 'WWWW'),
        Obstacle([0, int(nz * 0.75), nx - 1, nz - 1], 'WWWW'),
        Obstacle(
            [int(0.11 * nx),
             int(nz * 0.7),
             int(0.15 * nx),
             int(0.75 * nz)], 'WWWW'),
        Obstacle(
            [int(0.35 * nx),
             int(nz * 0.69),
             int(0.50 * nx),
             int(0.75 * nz)], 'WWWW'),
        Obstacle(
            [int(0.60 * nx),
             int(nz * 0.72),
             int(0.70 * nx),
             int(0.75 * nz)], 'WWWW'),
        Obstacle(
            [int(0.80 * nx),
             int(nz * 0.73),
             int(0.89 * nx),
             int(0.75 * nz)], 'WWWW'),
        Obstacle(
            [int(0.80 * nx),
             int(nz * 0.25),
             int(0.89 * nx),
             int(0.30 * nz)], 'WWWW'),
        Obstacle(
            [int(0.13 * nx),
             int(nz * 0.25),
             int(0.20 * nx),
             int(0.30 * nz)], 'WWWW'),
        Obstacle(
            [int(0.30 * nx),
             int(nz * 0.25),
             int(0.38 * nx),
             int(0.28 * nz)], 'WWWW'),
        Obstacle(
            [int(0.55 * nx),
             int(nz * 0.25),
             int(0.70 * nx),
             int(0.28 * nz)], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)
コード例 #2
0
def helmholtz_double(nx, nz, cavity=(0.2, 0.2), neck=(0.1, 0.1)):
    """ Geometry: Double Helmholtz resonator.

    Parameters
    ----------
    nx : int
        Width of the domain.
    nz : int
        Height of the domain.
    cavity : tuple, optional
        Normalized (width, height) of the cavity.
    neck : tuple, optional
        Normalized (width, height) of the neck.

    """

    xneck_wdth = int(nx * neck[0])
    xcvty_wdth = int(nx * cavity[0])
    xneck_hght = int(nz * neck[1])
    xcvty_hght = int(nz * cavity[1])

    neck_ix = int((nx - xneck_wdth) / 2)
    cvty_ix = int((nx - xcvty_wdth) / 2)

    zneck_wdth = int(nz * neck[0])
    zcvty_wdth = int(nz * cavity[0])
    zneck_hght = int(nx * neck[1])
    zcvty_hght = int(nx * cavity[1])

    neck_iz = int((nz - zneck_wdth) / 2)
    cvty_iz = int((nz - zcvty_wdth) / 2)

    if cavity[0] + neck[0] > 0.98 or cavity[1] + neck[1] > 0.98:
        raise _exceptions.TemplateConstructionError(
            "resonator must be smaller than the domain")

    geo = [
        Obstacle([0, 0, cvty_ix, xcvty_hght], 'WWWW'),
        Obstacle([cvty_ix + xcvty_wdth, 0, nx - 1, xcvty_hght], 'WWWW'),
        Obstacle([0, xcvty_hght, neck_ix, xcvty_hght + xneck_hght], 'WWWW'),
        Obstacle([
            neck_ix + xneck_wdth, xcvty_hght, nx - 1, xcvty_hght + xneck_hght
        ], 'WWWW'),
        Obstacle([nx - zcvty_hght, xcvty_hght + xneck_hght, nx - 1, cvty_iz],
                 'WWWW'),
        Obstacle([nx - zcvty_hght, cvty_iz + zcvty_wdth, nx - 1, nz - 1],
                 'WWWW'),
        Obstacle([
            nx - zcvty_hght - zneck_hght, neck_iz + zneck_wdth,
            nx - zcvty_hght, nz - 1
        ], 'WWWW'),
        Obstacle([
            nx - zcvty_hght - zneck_hght, xcvty_hght + xneck_hght,
            nx - zcvty_hght, neck_iz
        ], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)
コード例 #3
0
def _check_domain(x, z, domain):

    if isinstance(domain, (_np.ndarray, list, tuple)):
        if isinstance(domain, _np.ndarray):
            domain = domain.tolist()
        domain = Domain((x.shape[0], z.shape[0]), data=domain)

    if not isinstance(domain, Domain):
        raise ValueError(
            'domain must be a Domain, list, tuple or array object')

    return domain
コード例 #4
0
def testcase2(nx, nz):
    """ Geometry: Test case 2. Periodic bc. """

    PML = 16

    geo = [
        Obstacle([0, 0, PML, PML], 'WWWW'),
        Obstacle([0, PML + 23, PML, int(3 * nz / 4) - 5], 'WWWW'),
        Obstacle([30, nz - PML - 1, int(nx / 2) + 10, nz - 1], 'WWWW'),
        Obstacle([int(nx / 2), 0, int(3 * nx / 4), PML], 'WWWW'),
        Obstacle([nx - PML - 1,
                  int(3 * nz / 4), nx - 1,
                  int(3 * nz / 4) + 10], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)
コード例 #5
0
def testcase1(nx, nz):
    """ Geometry: Test case 1. Complex geometry. """

    geo = [
        Obstacle([0, 0, 60, 40], 'WWWW'),
        Obstacle([26, 40, 33, 50], 'WWWW'),
        Obstacle([56, 40, 60, 60], 'WWWW'),
        Obstacle([100, 80, 120, 90], 'WWWW'),
        Obstacle([90, 26, 110, 36], 'WWWW'),
        Obstacle([nx - 90, nz - 90, nx - 60, nz - 1], 'WWWW'),
        Obstacle([nx - 60, nz - 17, nx - 1, nz - 1], 'WWWW'),
        Obstacle([nx - 60, nz - 44, nx - 30, nz - 40], 'WWWW'),
        Obstacle([nx - 60, nz - 80, nx - 40, nz - 67], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)
コード例 #6
0
def plus(nx, nz, ix0=None, iz0=None, size=20):
    """ Geometry: Plus sign.

    Parameters
    ----------
    nx : int
        Width of the domain.
    nz : int
        Height of the domain.
    ix0 : int, optional
        x-location of the pattern.
    iz0 : int, optional
        z-location of the pattern.
    size : int
        Width of the pattern.
    """

    if not ix0:
        ix0 = nx / 2

    if not iz0:
        iz0 = nz / 2

    if ix0 <= 1.5 * size or iz0 <= 0.5 * size:
        msg = "Center of the plus must be greater than 1.5 time the size of a square"
        raise _exceptions.TemplateConstructionError(msg)

    ixstart = int(ix0 - 1.5 * size)
    izstart = int(iz0 - 0.5 * size)

    geo = [
        Obstacle([ixstart, izstart, ixstart + size, izstart + size], 'WWWW'),
        Obstacle(
            [ixstart + 2 * size, izstart, ixstart + 3 * size, izstart + size],
            'WWWW'),
        Obstacle([ixstart + size, izstart - size, ixstart + 2 * size, izstart],
                 'WWWW'),
        Obstacle([
            ixstart + size, izstart + size, ixstart + 2 * size,
            izstart + 2 * size
        ], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)
コード例 #7
0
def moving_square(nx, nz, size_percent=20):
    """ Geometry: Square with moving bc.

    Parameters
    ----------
    nx : int
        Width of the domain.
    nz : int
        Height of the domain.
    size_percent : float
        size of the square (percent of the largest dimension of the domain).
    """

    size = int(min(nx, nz) * size_percent / 100)

    obs1 = Obstacle([
        int(nx / 2) - size,
        int(nz / 2) - size,
        int(nx / 2) + size,
        int(nz / 2) + size
    ], 'VVWV')
    obs2 = Obstacle([nx - 11, 0, nx - 1, nz - 1], 'VWWW')

    obs1.set_moving_bc({
        'f': 70000,
        'A': 1,
        'func': 'sine'
    }, {
        'f': 30000,
        'A': -1,
        'func': 'tukey'
    }, {
        'f': 30000,
        'A': 1,
        'func': 'tukey'
    })
    obs2.set_moving_bc({'f': 73000, 'A': -1, 'func': 'flat'})

    return Domain((nx, nz), data=[obs1, obs2])
コード例 #8
0
def square(nx, nz, size_percent=20):
    """ Geometry: Square at the center of the domain.

    Parameters
    ----------
    nx : int
        Width of the domain.
    nz : int
        Height of the domain.
    size_percent : float
        size of the square (percent of the largest dimension of the domain).
    """

    size = int(min(nx, nz) * size_percent / 100)
    geo = [
        Obstacle([
            int(nx / 2) - size,
            int(nz / 2) - size,
            int(nx / 2) + size,
            int(nz / 2) + size
        ], 'WWWW')
    ]

    return Domain((nx, nz), data=geo)