Beispiel #1
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
Beispiel #2
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}
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