Beispiel #1
0
def compute_one_wave(k, w, beta, wt, environment):
    """
    Calculate the complex potential, pressure and fluid velocities for a regular wave eta=sin(k*wbar-wt)
    Args:
        k: float, the wave number
        w: float, the wave frequency
        beta: float, the wave direction
        wt: 1D array of length 3, the wave position
        environment: object, the environment
    Returns
        A dictionary containing the potential, pressure and fluid velocities
    """

    x = wt[0]
    y = wt[1]
    z = wt[2]

    w_bar = (x-environment.x_eff)*np.cos(beta)+(y-environment.y_eff)*np.sin(beta)
    phi = -environment.g/w*cih(k, z, environment.depth)*np.exp(utility.II*k*w_bar)
    p = -environment.rho*environment.g*utility.II*cih(k, z, environment.depth)*np.exp(utility.II*k*w_bar)
    vx = -environment.g/w*utility.II*k*np.cos(beta)*cih(k, z, environment.depth)*np.exp(utility.II*k*w_bar)
    vy = -environment.g/w*utility.II*k*np.sin(beta)*cih(k, z, environment.depth)*np.exp(utility.II*k*w_bar)
    vz = -environment.g/w*k*sih(k, z, environment.depth)*np.exp(utility.II*k*w_bar)

    return {"phi": phi, "p": p, "vx": vx, "vy": vy, "vz": vz, "v": np.array([vx, vy, vz])}
Beispiel #2
0
def compute_wave(mesh, w, beta, environment):
    """
    Calculate the array of complex potential, pressure and fluid velocities for a wave
    Args:
        mesh: object, the mesh
        w: float, the wave frequency
        beta: float, the wave direction
        environment: object, the environment
    Returns
        A dictionary containing the pressure and fluid velocities
    """

    n_vel = np.zeros(mesh.n_panels*2**mesh.i_sym, settings.NEMOH_COMPLEX)
    pressure = np.zeros(mesh.n_panels*2**mesh.i_sym, settings.NEMOH_COMPLEX)

    k_wave = utility.compute_wave_number(w, environment)

    for i in range(2**mesh.i_sym*mesh.n_panels):
        if i < mesh.n_panels:
            wbar = (mesh.xm[0, i] - environment.x_eff)*np.cos(beta) + (mesh.xm[1, i] - environment.y_eff)*np.sin(beta)

            pressure[i] = -environment.g/w*np.exp(utility.II*k_wave*wbar)

            n_vel[i] = pressure[i]*(utility.II*k_wave*(np.cos(beta)*mesh.n[0,i]+ \
                    np.sin(beta)*mesh.n[1,i])*cih(k_wave,mesh.xm[2, i], environment.depth)+ \
                    k_wave*mesh.n[2,i]*sih(k_wave,mesh.xm[2,i],environment.depth))
            pressure[i] *= cih(k_wave,mesh.xm[2,i], environment.depth)
            one_wave = compute_one_wave(k_wave, w, beta, mesh.xm[0:3, i], environment)
            # This makes previous pressure[i] statement useless
            pressure[i] = one_wave["p"]
            n_vel[i] = np.sum(one_wave["v"].flatten()*mesh.n[:, i].flatten())

        else:
            wbar=(mesh.xm[0, i-mesh.n_panels]-environment.x_eff)*np.cos(beta)+ \
                    (-mesh.xm[1, i-mesh.n_panels]-environment.y_eff)*np.sin(beta)
            pressure[i] = -environment.g/w*np.exp(utility.II*k_wave*wbar)
            n_vel[i] = pressure[i]*(utility.II*k_wave*(np.cos(beta)*mesh.n[0,i-mesh.n_panels]+\
                    np.sin(beta)*(-1.*mesh.n[1,i-mesh.n_panels]))*cih(k_wave, mesh.xm[2, i-mesh.n_panels],\
                    environment.depth)+k_wave*mesh.n[2,i-mesh.n_panels]*sih(k_wave,mesh.xm[2,i-mesh.n_panels],\
                    environment.depth))
            pressure[i] *= cih(k_wave, mesh.xm[2, i-mesh.n_panels], environment.depth)
            #one_wave = compute_one_wave(k_wave, w, beta, mesh.xm[0:3, i-mesh.n_panels], environment)
            #xm = mesh.xm[0:3, i-mesh.n_panels]
            #xm[1] = - xm[1]

            xm = np.array([mesh.xm[0, i-mesh.n_panels], -mesh.xm[1, i-mesh.n_panels], mesh.xm[2, i-mesh.n_panels]])
            one_wave = compute_one_wave(k_wave, w, beta, xm, environment)
            pressure[i] = one_wave["p"]
            #one_wave["v"][1] *= -1
            #n_vel[i] = np.sum(one_wave["v"]*mesh.n[:, i-mesh.n_panels])
            vx = one_wave["v"][0]
            vy = one_wave["v"][1]
            vz = one_wave["v"][2]
            n_vel[i] = vx*mesh.n[0, i-mesh.n_panels] - vy*mesh.n[1, i-mesh.n_panels] + vz*mesh.n[2, i-mesh.n_panels]

    return {"n_vel": n_vel, "pressure": pressure}
Beispiel #3
0
def compute_one_wave(k, w, beta, wt, environment):
    """
    Calculate the complex potential, pressure and fluid velocities for a regular wave eta=sin(k*wbar-wt)
    Args:
        k: float, the wave number
        w: float, the wave frequency
        beta: float, the wave direction
        wt: 1D array of length 3, the wave position
        environment: object, the environment
    Returns
        A dictionary containing the potential, pressure and fluid velocities
    """

    x = wt[0]
    y = wt[1]
    z = wt[2]

    w_bar = (x - environment.x_eff) * np.cos(beta) + (
        y - environment.y_eff) * np.sin(beta)
    phi = -environment.g / w * cih(k, z, environment.depth) * np.exp(
        utility.II * k * w_bar)
    p = -environment.rho * environment.g * utility.II * cih(
        k, z, environment.depth) * np.exp(utility.II * k * w_bar)
    vx = -environment.g / w * utility.II * k * np.cos(beta) * cih(
        k, z, environment.depth) * np.exp(utility.II * k * w_bar)
    vy = -environment.g / w * utility.II * k * np.sin(beta) * cih(
        k, z, environment.depth) * np.exp(utility.II * k * w_bar)
    vz = -environment.g / w * k * sih(k, z, environment.depth) * np.exp(
        utility.II * k * w_bar)

    return {
        "phi": phi,
        "p": p,
        "vx": vx,
        "vy": vy,
        "vz": vz,
        "v": np.array([vx, vy, vz])
    }
Beispiel #4
0
def compute_wave(mesh, w, beta, environment):
    """
    Calculate the array of complex potential, pressure and fluid velocities for a wave
    Args:
        mesh: object, the mesh
        w: float, the wave frequency
        beta: float, the wave direction
        environment: object, the environment
    Returns
        A dictionary containing the pressure and fluid velocities
    """

    n_vel = np.zeros(mesh.n_panels * 2**mesh.i_sym, settings.NEMOH_COMPLEX)
    pressure = np.zeros(mesh.n_panels * 2**mesh.i_sym, settings.NEMOH_COMPLEX)

    k_wave = utility.compute_wave_number(w, environment)

    for i in range(2**mesh.i_sym * mesh.n_panels):
        if i < mesh.n_panels:
            wbar = (mesh.xm[0, i] - environment.x_eff) * np.cos(beta) + (
                mesh.xm[1, i] - environment.y_eff) * np.sin(beta)

            pressure[i] = -environment.g / w * np.exp(
                utility.II * k_wave * wbar)

            n_vel[i] = pressure[i]*(utility.II*k_wave*(np.cos(beta)*mesh.n[0,i]+ \
                    np.sin(beta)*mesh.n[1,i])*cih(k_wave,mesh.xm[2, i], environment.depth)+ \
                    k_wave*mesh.n[2,i]*sih(k_wave,mesh.xm[2,i],environment.depth))
            pressure[i] *= cih(k_wave, mesh.xm[2, i], environment.depth)
            one_wave = compute_one_wave(k_wave, w, beta, mesh.xm[0:3, i],
                                        environment)
            # This makes previous pressure[i] statement useless
            pressure[i] = one_wave["p"]
            n_vel[i] = np.sum(one_wave["v"].flatten() * mesh.n[:, i].flatten())

        else:
            wbar=(mesh.xm[0, i-mesh.n_panels]-environment.x_eff)*np.cos(beta)+ \
                    (-mesh.xm[1, i-mesh.n_panels]-environment.y_eff)*np.sin(beta)
            pressure[i] = -environment.g / w * np.exp(
                utility.II * k_wave * wbar)
            n_vel[i] = pressure[i]*(utility.II*k_wave*(np.cos(beta)*mesh.n[0,i-mesh.n_panels]+\
                    np.sin(beta)*(-1.*mesh.n[1,i-mesh.n_panels]))*cih(k_wave, mesh.xm[2, i-mesh.n_panels],\
                    environment.depth)+k_wave*mesh.n[2,i-mesh.n_panels]*sih(k_wave,mesh.xm[2,i-mesh.n_panels],\
                    environment.depth))
            pressure[i] *= cih(k_wave, mesh.xm[2, i - mesh.n_panels],
                               environment.depth)
            #one_wave = compute_one_wave(k_wave, w, beta, mesh.xm[0:3, i-mesh.n_panels], environment)
            #xm = mesh.xm[0:3, i-mesh.n_panels]
            #xm[1] = - xm[1]

            xm = np.array([
                mesh.xm[0, i - mesh.n_panels], -mesh.xm[1, i - mesh.n_panels],
                mesh.xm[2, i - mesh.n_panels]
            ])
            one_wave = compute_one_wave(k_wave, w, beta, xm, environment)
            pressure[i] = one_wave["p"]
            #one_wave["v"][1] *= -1
            #n_vel[i] = np.sum(one_wave["v"]*mesh.n[:, i-mesh.n_panels])
            vx = one_wave["v"][0]
            vy = one_wave["v"][1]
            vz = one_wave["v"][2]
            n_vel[i] = vx * mesh.n[0, i - mesh.n_panels] - vy * mesh.n[
                1, i - mesh.n_panels] + vz * mesh.n[2, i - mesh.n_panels]

    return {"n_vel": n_vel, "pressure": pressure}
Beispiel #5
0
def compute_wave_elevation(hdf5_data, environment, iw, ibeta, raos, result):
    """
    Computes the wave elevation
    Args:
        hdf5_data: object, the hdf5 opened file
        environment: object, the environment
        iw: int, the index of the wave frequency to use
        ibeta: int, the index of the wave direction to use
        raos: object, the raos
        result: the hydrodynamic coefficients cases

    Returns:
        A dictionary containing the wave elevation variables
    """

    nx = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_X)[0]
    ny = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_Y)[0]
    lx = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_X)[0]
    ly = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_Y)[0]

    x = np.zeros(nx, dtype='f')
    y = np.zeros(ny, dtype='f')
    etai = np.zeros((nx, ny), dtype='F')
    etap = np.zeros((nx, ny), dtype='F')
    eta = np.zeros((nx, ny), dtype='F')

    for i in range(nx):
        x[i] = -0.5*lx+lx*(i)/(nx-1)

    for i in range(ny):
        y[i] = -0.5*ly+ly*(i)/(ny-1)

    w = result.w[iw]
    kwave = utility.compute_wave_number(w, environment)

    for i in range(nx):
        for j in range(ny):
            r = np.sqrt((x[i] - environment.x_eff)**2 + (y[j] - environment.y_eff)**2)
            theta = np.arctan2(y[j]-environment.y_eff, x[i]-environment.x_eff)
            k = 0
            while (k < result.n_theta -1) and (result.theta[k+1] < theta):
                k += 1
            if k == result.n_theta:
                print(' Error: range of theta in Kochin coefficients is too small')
                sys.exit(1)

            coord = np.array([x[i], y[i], 0])
            one_wave = preprocessor.compute_one_wave(kwave, w, result.beta[ibeta], coord, environment)
            potential = one_wave["phi"]
            etai[i, j] = 1./environment.g*utility.II*w*one_wave["phi"]
            HKleft=0.
            HKright=0.
            for l in range(result.n_radiation):
                HKleft=HKleft+raos[l,iw,ibeta]*result.hkochin_radiation[iw,l,k]
                HKright=HKright+raos[l,iw,ibeta]*result.hkochin_radiation[iw,l,k+1]


            HKleft=HKleft+result.hkochin_diffraction[iw,ibeta,k]
            HKright=HKright+result.hkochin_diffraction[iw,ibeta,k+1]
            HKochin=HKleft+(HKright-HKleft)*(theta-result.theta[k])/(result.theta[k+1]-result.theta[k])
            if r > 0:
                potential = np.sqrt(kwave/(2.*np.pi*r))*cih(kwave,0.,environment.depth)* np.exp(utility.II*(kwave*r-0.25*np.pi))*HKochin
            else:
                potential = 0
            etap[i,j]=-utility.II*1./environment.g*utility.II*w*potential
            eta[i,j]=etai[i,j]+etap[i,j]

    return {"w": w, "x": x, "y": y, "eta": eta, "etai": etai, "etap": etap}
Beispiel #6
0
def compute_wave_elevation(hdf5_data, environment, iw, ibeta, raos, result):
    """
    Computes the wave elevation
    Args:
        hdf5_data: object, the hdf5 opened file
        environment: object, the environment
        iw: int, the index of the wave frequency to use
        ibeta: int, the index of the wave direction to use
        raos: object, the raos
        result: the hydrodynamic coefficients cases

    Returns:
        A dictionary containing the wave elevation variables
    """

    signature = __name__ + '.compute_wave_elevation(hdf5_data, environment, iw, ibeta, raos, result)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"hdf5_data": str(hdf5_data),
                          "environment": str(environment),
                          "iw": str(iw),
                          "ibeta": str(ibeta),
                          "raos": str(raos),
                          "result": str(result)})

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_X)
    utility.check_dataset_type(dset, name=str(structure.H5_FREE_SURFACE_POINTS_X_ATTR['description']),
                               location=structure.H5_FREE_SURFACE_POINTS_X)
    nx = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_Y)
    utility.check_dataset_type(dset, name=str(structure.H5_FREE_SURFACE_POINTS_Y_ATTR['description']),
                               location=structure.H5_FREE_SURFACE_POINTS_Y)
    ny = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_X)
    utility.check_dataset_type(dset, name=str(structure.H5_FREE_SURFACE_DIMENSION_X_ATTR['description']),
                               location=structure.H5_FREE_SURFACE_DIMENSION_X)
    lx = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_Y)
    utility.check_dataset_type(dset, name=str(structure.H5_FREE_SURFACE_DIMENSION_Y_ATTR['description']),
     location=structure.H5_FREE_SURFACE_DIMENSION_Y)
    ly = dset[0]

    x = np.zeros(nx, dtype='f')
    y = np.zeros(ny, dtype='f')
    etai = np.zeros((nx, ny), dtype='F')
    etap = np.zeros((nx, ny), dtype='F')
    eta = np.zeros((nx, ny), dtype='F')

    for i in range(nx):
        x[i] = -0.5*lx+lx*(i)/(nx-1)

    for i in range(ny):
        y[i] = -0.5*ly+ly*(i)/(ny-1)

    w = result.w[iw]
    logger.info('Computing the wave number ...')
    kwave = utility.compute_wave_number(w, environment)
    logger.info('Wave number computed is ' + str(kwave))

    for i in range(nx):
        for j in range(ny):
            r = np.sqrt((x[i] - environment.x_eff)**2 + (y[j] - environment.y_eff)**2)
            theta = np.arctan2(y[j]-environment.y_eff, x[i]-environment.x_eff)
            k = 0
            while (k < result.n_theta -1) and (result.theta[k+1] < theta):
                k += 1
            if k == result.n_theta:
                raise ValueError(' Error: range of theta in Kochin coefficients is too small')

            coord = np.array([x[i], y[i], 0])
            one_wave = preprocessor.compute_one_wave(kwave, w, result.beta[ibeta], coord, environment)
            potential = one_wave["phi"]
            etai[i, j] = 1./environment.g*utility.II*w*one_wave["phi"]
            HKleft=0.
            HKright=0.
            for l in range(result.n_radiation):
                HKleft=HKleft+raos[l,iw,ibeta]*result.hkochin_radiation[iw,l,k]
                HKright=HKright+raos[l,iw,ibeta]*result.hkochin_radiation[iw,l,k+1]


            HKleft=HKleft+result.hkochin_diffraction[iw,ibeta,k]
            HKright=HKright+result.hkochin_diffraction[iw,ibeta,k+1]
            HKochin=HKleft+(HKright-HKleft)*(theta-result.theta[k])/(result.theta[k+1]-result.theta[k])
            if r > 0:
                potential = np.sqrt(kwave/(2.*np.pi*r))*cih(kwave,0.,environment.depth)* np.exp(utility.II*(kwave*r-0.25*np.pi))*HKochin
            else:
                potential = 0
            etap[i,j]=-utility.II*1./environment.g*utility.II*w*potential
            eta[i,j]=etai[i,j]+etap[i,j]

    rep = {"w": w, "x": x, "y": y, "eta": eta, "etai": etai, "etap": etap}
    utility.log_exit(logger, signature, [rep])
    return rep
def compute_wave_elevation(hdf5_data, environment, iw, ibeta, raos, result):
    """
    Computes the wave elevation
    Args:
        hdf5_data: object, the hdf5 opened file
        environment: object, the environment
        iw: int, the index of the wave frequency to use
        ibeta: int, the index of the wave direction to use
        raos: object, the raos
        result: the hydrodynamic coefficients cases

    Returns:
        A dictionary containing the wave elevation variables
    """

    signature = __name__ + '.compute_wave_elevation(hdf5_data, environment, iw, ibeta, raos, result)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(
        logger, signature, {
            "hdf5_data": str(hdf5_data),
            "environment": str(environment),
            "iw": str(iw),
            "ibeta": str(ibeta),
            "raos": str(raos),
            "result": str(result)
        })

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_X)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_FREE_SURFACE_POINTS_X_ATTR['description']),
        location=structure.H5_FREE_SURFACE_POINTS_X)
    nx = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_POINTS_Y)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_FREE_SURFACE_POINTS_Y_ATTR['description']),
        location=structure.H5_FREE_SURFACE_POINTS_Y)
    ny = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_X)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_FREE_SURFACE_DIMENSION_X_ATTR['description']),
        location=structure.H5_FREE_SURFACE_DIMENSION_X)
    lx = dset[0]

    dset = hdf5_data.get(structure.H5_FREE_SURFACE_DIMENSION_Y)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_FREE_SURFACE_DIMENSION_Y_ATTR['description']),
        location=structure.H5_FREE_SURFACE_DIMENSION_Y)
    ly = dset[0]

    x = np.zeros(nx, dtype='f')
    y = np.zeros(ny, dtype='f')
    etai = np.zeros((nx, ny), dtype='F')
    etap = np.zeros((nx, ny), dtype='F')
    eta = np.zeros((nx, ny), dtype='F')

    for i in range(nx):
        x[i] = -0.5 * lx + lx * (i) / (nx - 1)

    for i in range(ny):
        y[i] = -0.5 * ly + ly * (i) / (ny - 1)

    w = result.w[iw]
    logger.info('Computing the wave number ...')
    kwave = utility.compute_wave_number(w, environment)
    logger.info('Wave number computed is ' + str(kwave))

    for i in range(nx):
        for j in range(ny):
            r = np.sqrt((x[i] - environment.x_eff)**2 +
                        (y[j] - environment.y_eff)**2)
            theta = np.arctan2(y[j] - environment.y_eff,
                               x[i] - environment.x_eff)
            k = 0
            while (k < result.n_theta - 1) and (result.theta[k + 1] < theta):
                k += 1
            if k == result.n_theta:
                raise ValueError(
                    ' Error: range of theta in Kochin coefficients is too small'
                )

            coord = np.array([x[i], y[i], 0])
            one_wave = preprocessor.compute_one_wave(kwave, w,
                                                     result.beta[ibeta], coord,
                                                     environment)
            potential = one_wave["phi"]
            etai[i, j] = 1. / environment.g * utility.II * w * one_wave["phi"]
            HKleft = 0.
            HKright = 0.
            for l in range(result.n_radiation):
                HKleft = HKleft + raos[
                    l, iw, ibeta] * result.hkochin_radiation[iw, l, k]
                HKright = HKright + raos[
                    l, iw, ibeta] * result.hkochin_radiation[iw, l, k + 1]

            HKleft = HKleft + result.hkochin_diffraction[iw, ibeta, k]
            HKright = HKright + result.hkochin_diffraction[iw, ibeta, k + 1]
            HKochin = HKleft + (HKright - HKleft) * (
                theta - result.theta[k]) / (result.theta[k + 1] -
                                            result.theta[k])
            if r > 0:
                potential = np.sqrt(kwave / (2. * np.pi * r)) * cih(
                    kwave, 0., environment.depth) * np.exp(
                        utility.II * (kwave * r - 0.25 * np.pi)) * HKochin
            else:
                potential = 0
            etap[
                i,
                j] = -utility.II * 1. / environment.g * utility.II * w * potential
            eta[i, j] = etai[i, j] + etap[i, j]

    rep = {"w": w, "x": x, "y": y, "eta": eta, "etai": etai, "etap": etap}
    utility.log_exit(logger, signature, [rep])
    return rep