Пример #1
0
def save_radiation_coefficients(result, filename):
    """
    Saves the radiation coefficient to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    """
    signature = __name__ + '.save_radiation_coefficients(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"result": str(result),
                          'filename': str(filename)})

    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:

        inp.write('VARIABLES="w (rad/s)"\n')

        for k in range(result.n_integration):
            s = '"A\t' + str(result.idx_force[k, 1]) + '\t' + str(result.idx_force[k, 2])
            s = s + '" "B\t' + str(result.idx_force[k, 1]) + '\t' + str(result.idx_force[k, 2]) + '"\n'
            inp.write(s)

        for j in range(result.n_radiation):
            s = 'Zone t="Motion of body\t' + str(result.idx_radiation[j, 1])
            s += '\tin DoF\t' + str(result.idx_radiation[j, 2]) + '",I=\t' + str(result.n_w) + ',F=POINT\n'
            inp.write(s)
            for i in range(result.n_w):
                s = str(result.w[i]) + '\t'
                for k in range(result.n_integration):
                    s += str(result.added_mass[i, j, k]) + '\t' + str(result.radiation_damping[i, j, k]) + '\t'
                inp.write(s + '\n')

    utility.log_and_print(logger, utility.get_abs(filename) + ' contains the radiation coefficients in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #2
0
def save_irf(irf, filename):
    """
    Saves the irf to a file in the tec format
    Args:
        irf: object, the irf
        filename: string, The path to the file where to save the irf
    """
    signature = __name__ + '.save_irf(irf, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"irf": str(irf),
                          'filename': str(filename)})
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        inp.write('VARIABLES="Time (s)"\n')
        for k in range(irf.n_integration):
            inp.write('"AddedMass '+ str(k+1) + '" "IRF ' + str(k+1) +'"\n')
        for j in range(irf.n_radiation):
            inp.write('Zone t="DoF ' + str(j+1) + '",I=\t' + str(irf.n_time) + ',F=POINT\n')
            for i in range(irf.n_time):
                inp.write(' ' + str(irf.time[i]) + ' ')
                s = ''
                for k in range(irf.n_integration):
                    s += ' ' + str(irf.added_mass[j, k]) + ' ' + ' ' + str(irf.k[i, j, k]) + ' '
                inp.write(s + '\n')

    utility.log_and_print(logger, utility.get_abs(filename) + ' contains the irf in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #3
0
def postprocess(custom_config):
    """
    Configure and then run the postprocessor

    Args:
        custom_config, dict The custom configuration dictionary
    """
    signature = __name__ + '.postprocess(custom_config)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                        {'custom_config': custom_config})

    if not custom_config:
        custom_config = {}

    hdf5_file = utility.get_setting(settings.HDF5_FILE, custom_config, 'HDF5_FILE')
    utility.check_is_file(hdf5_file, 'The path to the hdf5 file configured by HDF5_FILE')

    #utility.validate_file(hdf5_file, 'HDF5_FILE')
    with h5py.File(hdf5_file, "a") as hdf5_db:
        run(hdf5_db, custom_config)

    utility.log_and_print(logger, 'The post processing results are saved in the hdf5 file '
                          + utility.get_abs(hdf5_file))

    utility.log_exit(logging.getLogger(__name__), signature, [None])
Пример #4
0
def save_excitation_force(result, filename):
    """
    Saves the excitation forces to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    """
    signature = __name__ + '.save_excitation_force(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"result": str(result),
                          'filename': str(filename)})
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        inp.write('VARIABLES="w (rad/s)"\n')

        for k in range(result.n_integration):
            s = '"abs(F\t' + str(result.idx_force[k, 1]) + '\t' + str(result.idx_force[k, 2])
            s += ')" "angle(F\t' + str(result.idx_force[k, 1]) + '\t' + str(result.idx_force[k, 2]) + ')"\n'
            inp.write(s)

        for j in range(result.n_beta):
            s = 'Zone t="Diffraction force - beta = ' + str(result.beta[j]*180./(4.*np.arctan(1.0)))
            s += ' deg",I=  ' + str(result.n_w) + ',F=POINT\n'
            inp.write(s)
            for i in range(result.n_w):
                s = str(result.w[i]) + '\t'
                for k in range(result.n_integration):
                    temp = result.diffraction_force[i, j, k] + result.froudkrylov_force[i, j, k]
                    s += str(np.abs(temp)) + '\t'
                    s += str(np.arctan2(np.imag(temp), np.real(temp))) + '\t'
                inp.write(s + '\n')

    utility.log_and_print(logger, utility.get_abs(filename) + ' contains the excitation forces in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #5
0
def save_irf(irf, filename):
    """
    Saves the irf to a file in the tec format
    Args:
        irf: object, the irf
        filename: string, The path to the file where to save the irf
    """
    signature = __name__ + '.save_irf(irf, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "irf": str(irf),
        'filename': str(filename)
    })
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        inp.write('VARIABLES="Time (s)"\n')
        for k in range(irf.n_integration):
            inp.write('"AddedMass ' + str(k + 1) + '" "IRF ' + str(k + 1) +
                      '"\n')
        for j in range(irf.n_radiation):
            inp.write('Zone t="DoF ' + str(j + 1) + '",I=\t' +
                      str(irf.n_time) + ',F=POINT\n')
            for i in range(irf.n_time):
                inp.write(' ' + str(irf.time[i]) + ' ')
                s = ''
                for k in range(irf.n_integration):
                    s += ' ' + str(irf.added_mass[j, k]) + ' ' + ' ' + str(
                        irf.k[i, j, k]) + ' '
                inp.write(s + '\n')

    utility.log_and_print(
        logger,
        utility.get_abs(filename) + ' contains the irf in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #6
0
def postprocess(custom_config):
    """
    Configure and then run the postprocessor

    Args:
        custom_config, dict The custom configuration dictionary
    """
    signature = __name__ + '.postprocess(custom_config)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {'custom_config': custom_config})

    if not custom_config:
        custom_config = {}

    hdf5_file = utility.get_setting(settings.HDF5_FILE, custom_config,
                                    'HDF5_FILE')
    utility.check_is_file(hdf5_file,
                          'The path to the hdf5 file configured by HDF5_FILE')

    #utility.validate_file(hdf5_file, 'HDF5_FILE')
    with h5py.File(hdf5_file, "a") as hdf5_db:
        run(hdf5_db, custom_config)

    utility.log_and_print(
        logger, 'The post processing results are saved in the hdf5 file ' +
        utility.get_abs(hdf5_file))

    utility.log_exit(logging.getLogger(__name__), signature, [None])
Пример #7
0
def save_stifness(result, filename):
    """
    Saves the radiation coefficient to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    """
    signature = __name__ + '.save_stifness(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "result": str(result),
        'filename': str(filename)
    })

    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))

    with open(filename, 'w') as inp:
        for i in range(len(result[:, :])):
            for j in range(len(result[:, :])):
                if j == len(result[:, :]) - 1:
                    inp.write(" % E\n" % result[i, j])
                else:
                    inp.write(" % E " % result[i, j])

    utility.log_and_print(
        logger,
        utility.get_abs(filename) + ' contains the hydrostatic stifness.')
    utility.log_exit(logger, signature, [None])
Пример #8
0
def compute_irf(result, irf):
    """
    Computes the froude krylov forces for the given irf
    Args:
        result: object the hydrodynamic coefficients cases
        irf: object, the input irf
    Returns:
        the irf with the froude krylov forces computed.
    """
    signature = __name__ + '.compute_irf(result, irf)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "irf": str(irf),
        'result': str(result)
    })

    logger.info('Computing the froude krylov forces for the given irf')
    for i in range(irf.n_time):
        for j in range(result.n_radiation):
            for k in range(result.n_integration):
                irf.k[i, j, k] = 0.
                for l in range(result.n_w - 1):

                    irf.k[i, j,
                          k] += -0.5 * (result.w[l + 1] - result.w[l]) * (
                              result.radiation_damping[l, j, k] *
                              np.cos(result.w[l] * irf.time[i]) +
                              result.radiation_damping[l + 1, j, k] *
                              np.cos(result.w[l + 1] * irf.time[i]))

                irf.k[i, j, k] = (irf.k[i, j, k] * 2) / np.pi

    logger.info('Computing the added mass for the given irf')
    cm = np.zeros(result.n_w)
    for j in range(result.n_radiation):
        for k in range(result.n_integration):
            irf.added_mass[j, k] = 0
            for l in range(result.n_w):
                cm[l] = 0
                for i in range(irf.n_time - 1):
                    cm[l] += 0.5 * (irf.time[i + 1] - irf.time[i]) * (
                        irf.k[i, j, k] * np.sin(result.w[l] * irf.time[i]) +
                        irf.k[i + 1, j, k] *
                        np.sin(result.w[l] * irf.time[i + 1]))
                cm[l] = (result.added_mass[l, j, k] + cm[l]) / result.w[l]
                irf.added_mass[j, k] = irf.added_mass[j, k] + cm[l]
            irf.added_mass[j, k] = irf.added_mass[j, k] / result.n_w

    utility.log_exit(logger, signature, [str(irf)])

    return irf
Пример #9
0
def get_irf(hdf5_data, result):
    """
    Gets the irf from the hdf5 file
    Args:
        hdf5_data: object, the hdf5 opened file
        result: object the hydrodynamic coefficients cases
    Returns:
        the irf
    """

    signature = __name__ + '.get_irf(hdf5_data, result)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "hdf5_data": str(hdf5_data),
        'result': str(result)
    })

    dset = hdf5_data.get(structure.H5_COMPUTE_IRF)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_COMPUTE_IRF_ATTR['description']),
        location=structure.H5_COMPUTE_IRF)
    switch = dset[0]

    dset = hdf5_data.get(structure.H5_IRF_TIME_STEP)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_IRF_TIME_STEP_ATTR['description']),
        location=structure.H5_IRF_TIME_STEP)
    time_step = dset[0]

    dset = hdf5_data.get(structure.H5_IRF_DURATION)
    utility.check_dataset_type(
        dset,
        name=str(structure.H5_IRF_DURATION_ATTR['description']),
        location=structure.H5_IRF_DURATION)
    duration = dset[0]

    irf = TIRF()

    if switch == 1:
        irf = TIRF(int(duration / time_step), result.n_radiation,
                   result.n_integration)
        for i in range(irf.n_time):
            irf.time[i] = i * time_step
    irf.switch = switch

    utility.log_exit(logger, signature, [str(irf)])

    return irf
Пример #10
0
def save_wave_elevation(w, etai, etap, eta, x, y, filename):
    """
    Save the wave elevation to a file in tec format
    Args:
        w: float, the wave frequency
        etai: 2D array, a wave elevation variable
        eta: 2D array, a wave elevation variable
        etap: 2D array, a wave elevation variable
        x: 1D array, a wave elevation variable
        y: 1D array, a wave elevation variable
        filename: string, the path to the file where to save
    """
    signature = __name__ + '.save_wave_elevation(w, etai, etap, eta, x, y, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"w": w,
                          "etai": etai,
                          "etap": etap,
                          "eta": eta,
                          "x": x,
                          "y": y,
                          "filename": filename})

    nx = len(x)
    ny = len(y)
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        s = 'VARIABLES="X" "Y" "etaI_C" "etaI_S" "etaP_C" "etaC_S" '
        s += '"etaI_C+etaP_C" "etaI_S+etaI_P" "|etaP|" "|etaI+etaP|"\n'
        inp.write(s)

        s = 'ZONE t="Wave frequency - w = '
        s += str(w)+ '",N=\t'+ str(nx*ny) + ', E=\t' + str((nx-1)*(nx-1)) + '\t , F=FEPOINT,ET=QUADRILATERAL\n'
        inp.write(s)
        for i in range(nx):
            for j in range(ny):
                s = str(x[i]) + '\t' + str(y[j]) + '\t' + str(np.real(etai[i, j])) + '\t'
                s += str(np.imag(etai[i,j])) + '\t' + str(np.real(etap[i, j])) + '\t'
                s += str(np.imag(etap[i,j])) + '\t' + str(np.real(etai[i,j]+etap[i,j])) + '\t'
                s += str(np.imag(etai[i,j]+etap[i,j])) + '\t' + str(np.abs(etap[i,j])) + '\t'
                s += str(np.abs(eta[i,j])) + '\n'
                inp.write(s)

        for i in range(nx-1):
            for j in range(ny-1):
                s = str(j+1+i*ny) + '\t' + str(j+1+(i+1)*ny) + '\t' + str(j+2+ i*ny) + '\n'
                inp.write(s)

    utility.log_and_print(logger, utility.get_abs(filename) + ' contains the wave elevation in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #11
0
def compute_irf(result, irf):
    """
    Computes the froude krylov forces for the given irf
    Args:
        result: object the hydrodynamic coefficients cases
        irf: object, the input irf
    Returns:
        the irf with the froude krylov forces computed.
    """
    signature = __name__ + '.compute_irf(result, irf)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"irf": str(irf), 'result': str(result)})

    logger.info('Computing the froude krylov forces for the given irf')
    for i in range(irf.n_time):
        for j in range(result.n_radiation):
            for k in range(result.n_integration):
                irf.k[i,j,k] = 0.
                for l in range(result.n_w -1):

                    irf.k[i, j, k] += 0.5* (result.w[l+1]-result.w[l]) * (result.radiation_damping[l,
                                                                                                                   j,
                     k]*np.cos(result.w[l]*irf.time[i]) + result.radiation_damping[l+1, j, k]*np.cos(result.w[l+1]*irf.time[i]))

                irf.k[i, j, k] = (irf.k[i, j, k] * 2)/np.pi



    logger.info('Computing the added mass for the given irf')
    cm = np.zeros(result.n_w)
    for j in range(result.n_radiation):
        for k in range(result.n_integration):
            irf.added_mass[j, k] = 0
            for l in range(result.n_w):
                cm[l] = 0
                for i in range(irf.n_time-1):
                    cm[l] += 0.5*(irf.time[i+1]-irf.time[i])*(irf.k[i,j,k]*np.sin(result.w[l]*irf.time[i]) +
                                                                     irf.k[i+1, j, k]*np.sin(result.w[l]*irf.time[i+1]))
                cm[l]=result.added_mass[l,j,k] + cm[l]/result.w[l]
                irf.added_mass[j,k]=irf.added_mass[j,k] +cm[l]
            irf.added_mass[j,k] = irf.added_mass[j,k]/result.n_w

    utility.log_exit(logger, signature, [str(irf)])

    return irf
Пример #12
0
def get_irf(hdf5_data, result):
    """
    Gets the irf from the hdf5 file
    Args:
        hdf5_data: object, the hdf5 opened file
        result: object the hydrodynamic coefficients cases
    Returns:
        the irf
    """

    signature = __name__ + '.get_irf(hdf5_data, result)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"hdf5_data": str(hdf5_data), 'result': str(result)})

    dset = hdf5_data.get(structure.H5_COMPUTE_IRF)
    utility.check_dataset_type(dset,
                               name=str(structure.H5_COMPUTE_IRF_ATTR['description']),
                               location=structure.H5_COMPUTE_IRF)
    switch = dset[0]

    dset = hdf5_data.get(structure.H5_IRF_TIME_STEP)
    utility.check_dataset_type(dset,
                               name=str(structure.H5_IRF_TIME_STEP_ATTR['description']),
                               location=structure.H5_IRF_TIME_STEP)
    time_step = dset[0]


    dset = hdf5_data.get(structure.H5_IRF_DURATION)
    utility.check_dataset_type(dset,
                               name=str(structure.H5_IRF_DURATION_ATTR['description']),
                               location=structure.H5_IRF_DURATION)
    duration = dset[0]

    irf = TIRF()

    if switch == 1:
        irf = TIRF(int(duration/time_step), result.n_radiation, result.n_integration)
        for i in range(irf.n_time):
            irf.time[i] = i*time_step
    irf.switch = switch

    utility.log_exit(logger, signature, [str(irf)])

    return irf
Пример #13
0
def save_radiation_coefficients(result, filename):
    """
    Saves the radiation coefficient to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    """
    signature = __name__ + '.save_radiation_coefficients(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "result": str(result),
        'filename': str(filename)
    })

    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:

        inp.write('VARIABLES="w (rad/s)"\n')

        for k in range(result.n_integration):
            s = '"A\t' + str(result.idx_force[k, 1]) + '\t' + str(
                result.idx_force[k, 2])
            s = s + '" "B\t' + str(result.idx_force[k, 1]) + '\t' + str(
                result.idx_force[k, 2]) + '"\n'
            inp.write(s)

        for j in range(result.n_radiation):
            s = 'Zone t="Motion of body\t' + str(result.idx_radiation[j, 1])
            s += '\tin DoF\t' + str(
                result.idx_radiation[j, 2]) + '",I=\t' + str(
                    result.n_w) + ',F=POINT\n'
            inp.write(s)
            for i in range(result.n_w):
                s = str(result.w[i]) + '\t'
                for k in range(result.n_integration):
                    s += str(result.added_mass[i, j, k]) + '\t' + str(
                        result.radiation_damping[i, j, k]) + '\t'
                inp.write(s + '\n')

    utility.log_and_print(
        logger,
        utility.get_abs(filename) +
        ' contains the radiation coefficients in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #14
0
def save_excitation_force(result, filename):
    """
    Saves the excitation forces to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    """
    signature = __name__ + '.save_excitation_force(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {
        "result": str(result),
        'filename': str(filename)
    })
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        inp.write('VARIABLES="w (rad/s)"\n')

        for k in range(result.n_integration):
            s = '"abs(F\t' + str(result.idx_force[k, 1]) + '\t' + str(
                result.idx_force[k, 2])
            s += ')" "angle(F\t' + str(result.idx_force[k, 1]) + '\t' + str(
                result.idx_force[k, 2]) + ')"\n'
            inp.write(s)

        for j in range(result.n_beta):
            s = 'Zone t="Diffraction force - beta = ' + str(
                result.beta[j] * 180. / (4. * np.arctan(1.0)))
            s += ' deg",I=' + str(result.n_w) + ',F=POINT\n'
            inp.write(s)
            for i in range(result.n_w):
                s = str(result.w[i]) + '\t'
                for k in range(result.n_integration):
                    temp = result.diffraction_force[
                        i, j, k] + result.froudkrylov_force[i, j, k]
                    s += str(np.abs(temp)) + '\t'
                    s += str(np.arctan2(np.imag(temp), np.real(temp))) + '\t'
                inp.write(s + '\n')

    utility.log_and_print(
        logger,
        utility.get_abs(filename) +
        ' contains the excitation forces in tec format.')
    utility.log_exit(logger, signature, [None])
Пример #15
0
def save_hydroinfo(cg, cf, disVol, Warea, filename):
    """
    Saves the radiation coefficient to a file in tec format
    Args:
        result: object, the hydrodynamic coefficients cases
        filename: The path to the file where to save
    cb[0] = cf[0] + cg[0] 
    cb[1] = cf[1] + cg[1]
    cb[2] = cf[2] 
    """
    signature = __name__ + '.save_hydroinfo(result, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(
        logger, signature, {
            "cg": str(cg),
            "cf": str(cf),
            "disVol": str(disVol),
            "Warea": str(Warea),
            'filename': str(filename)
        })

    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))

    with open(filename, 'w') as inp:
        #         print "XF = %(cb) 7.3f - XG = %(cg) 7.3f" % {"cb":cb(1), "cg":cb(1)}
        inp.write("XB = %7.3f - XG =  %7.3f\n" % (cf[0] + cg[0], cg[0]))
        inp.write("YB = %7.3f - YG =  %7.3f\n" % (cf[1] + cg[1], cg[1]))
        inp.write("ZB = %7.3f - ZG =  %7.3f\n" % (cf[2], cg[2]))
        inp.write("Displacement = %E\n" % disVol)
        inp.write("Waterplane area = %E" % Warea)


#             inp.write(str(result[i,:])
#             tmpFmt = "%5.3f"*len(result[i,:])+"\n"
#             print(tmpFmt % result[i,:])

    utility.log_and_print(
        logger,
        utility.get_abs(filename) + ' contains the hydrostatic information.')
    utility.log_exit(logger, signature, [None])
Пример #16
0
def write_result(hdf5_data, data):
    """
    Write the result from nemoh fortran to the hdf5
    Args:
        hdf5_data: object the hdf5 opened data
        data: the data sent from nemoh fortran
    """
    signature = __name__ + '.write_result(hdf5_data, data)'
    logger = logging.getLogger(__name__)
    # data is too huge for logging
    utility.log_entrance(logger, signature,
                        {'hdf5_data': hdf5_data})

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_FORCES, data["line"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_FORCES_ATTR)
    dset[:, :] = data["line"].astype(copy=False, dtype='f')

    temp = np.array(data["out_potential"], dtype='f')
    count_skip = 0
    for i in range(data["n_problems"]):
        if data["bc_switch_potential"][i] != 1:
            temp[i, :] = 0
            count_skip += 1
    if count_skip == data["n_problems"]:
        temp = np.zeros((0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_POTENTIAL, temp.shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_POTENTIAL_ATTR)
    dset[:, :] = temp

    kochin = np.zeros((data["n_theta"], 3, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_kochin"][i] == 1:
            for j in range(data["n_theta"]):

                kochin[j, 0, i] = data["theta"][j]
                kochin[j, 1, i] = np.abs(data["out_hkochin"][i, j])
                kochin[j, 2, i] = np.arctan2(np.imag(data["out_hkochin"][i, j]), np.real(data["out_hkochin"][i, j]))
        else:
            count_skip += 1

    if count_skip ==  data["n_problems"]:
        kochin = np.zeros((0, 0, 0), dtype='f')


    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_KOCHIN, kochin.shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_KOCHIN_ATTR)
    dset[:, :, :] = kochin


    temp = np.zeros((data["nfs_points"], 6, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_freesurface"][i] == 1:
            for j in range(data["nfs_points"]):

                temp[j, 0, i] = data["meshfs_x"][0, j]
                temp[j, 1, i] = data["meshfs_x"][1, j]
                temp[j, 2, i] = np.abs(data["out_phi"][i, j])
                temp[j, 3, i] = np.arctan2(np.imag(data["out_phi"][i, j]), np.real(data["out_phi"][i, j]))
                temp[j, 4, i] = -np.imag(data["out_phi"][i, j])
                temp[j, 5, i] = -np.real(data["out_phi"][i, j])
        else:
            count_skip += 1

    if count_skip ==  data["n_problems"]:
        temp = np.zeros((0, 0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_FREE_SURFACE_POINTS, temp.shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_FREE_SURFACE_POINTS_ATTR)
    dset[:, :, :] = temp

    temp = np.zeros((data["nfs_panels"], 4, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_freesurface"][i] == 1:
            for j in range(data["nfs_panels"]):
                temp[j,:, i ] = data["meshfs_p"]
        else:
            count_skip += 1
    if count_skip ==  data["n_problems"]:
        temp = np.zeros((0, 0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_FREE_SURFACE_PANEL, temp.shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_FREE_SURFACE_PANEL_ATTR)
    dset[:, :, :] = temp


    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_DRIFT_FORCES, data["drift_forces"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_DRIFT_FORCES_ATTR)
    dset[:, :, :] = data["drift_forces"]

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_YAW_MOMENT, data["yaw_moment"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_YAW_MOMENT_ATTR)
    dset[:, :] = data["yaw_moment"]

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_CENTER_BUOYANCY, data["center_buoyancy"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_CENTER_BUOYANCY_ATTR)
    dset[:, :] = data["center_buoyancy"]

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_VOLUME_DISPLACEMENT, data["displacement"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_VOLUME_DISPLACEMENT_ATTR)
    dset[:] = data["displacement"]

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_WATER_PLANE_AREA, data["waterplane_area"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_WATER_PLANE_AREA_ATTR)
    dset[:] = data["waterplane_area"]

    dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_STIFNESS, data["stifness"].shape, dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_STIFNESS_ATTR)
    dset[:, :, :] = data["stifness"]

    utility.log_exit(logger, signature, [None])
Пример #17
0
def write_result(hdf5_data, data):
    """
    Write the result from nemoh fortran to the hdf5
    Args:
        hdf5_data: object the hdf5 opened data
        data: the data sent from nemoh fortran
    """
    signature = __name__ + '.write_result(hdf5_data, data)'
    logger = logging.getLogger(__name__)
    # data is too huge for logging
    utility.log_entrance(logger, signature, {'hdf5_data': hdf5_data})

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_FORCES,
                                   data["line"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_FORCES_ATTR)
    dset[:, :] = data["line"].astype(copy=False, dtype='f')

    temp = np.array(data["out_potential"], dtype='f')
    count_skip = 0
    for i in range(data["n_problems"]):
        if data["bc_switch_potential"][i] != 1:
            temp[i, :] = 0
            count_skip += 1
    if count_skip == data["n_problems"]:
        temp = np.zeros((0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_POTENTIAL,
                                   temp.shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_POTENTIAL_ATTR)
    dset[:, :] = temp

    kochin = np.zeros((data["n_theta"], 3, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_kochin"][i] == 1:
            for j in range(data["n_theta"]):

                kochin[j, 0, i] = data["theta"][j]
                kochin[j, 1, i] = np.abs(data["out_hkochin"][i, j])
                kochin[j, 2,
                       i] = np.arctan2(np.imag(data["out_hkochin"][i, j]),
                                       np.real(data["out_hkochin"][i, j]))
        else:
            count_skip += 1

    if count_skip == data["n_problems"]:
        kochin = np.zeros((0, 0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_KOCHIN,
                                   kochin.shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_KOCHIN_ATTR)
    dset[:, :, :] = kochin

    temp = np.zeros((data["nfs_points"], 6, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_freesurface"][i] == 1:
            for j in range(data["nfs_points"]):

                temp[j, 0, i] = data["meshfs_x"][0, j]
                temp[j, 1, i] = data["meshfs_x"][1, j]
                temp[j, 2, i] = np.abs(data["out_phi"][i, j])
                temp[j, 3, i] = np.arctan2(np.imag(data["out_phi"][i, j]),
                                           np.real(data["out_phi"][i, j]))
                temp[j, 4, i] = -np.imag(data["out_phi"][i, j])
                temp[j, 5, i] = -np.real(data["out_phi"][i, j])
        else:
            count_skip += 1

    if count_skip == data["n_problems"]:
        temp = np.zeros((0, 0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_FREE_SURFACE_POINTS,
                                   temp.shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset,
                                structure.H5_RESULTS_FREE_SURFACE_POINTS_ATTR)
    dset[:, :, :] = temp

    temp = np.zeros((data["nfs_panels"], 4, data["n_problems"]), dtype='f')
    count_skip = 0

    for i in range(data["n_problems"]):
        if data["bc_switch_freesurface"][i] == 1:
            for j in range(data["nfs_panels"]):
                temp[j, :, i] = data["meshfs_p"]
        else:
            count_skip += 1
    if count_skip == data["n_problems"]:
        temp = np.zeros((0, 0, 0), dtype='f')

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_FREE_SURFACE_PANEL,
                                   temp.shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset,
                                structure.H5_RESULTS_FREE_SURFACE_PANEL_ATTR)
    dset[:, :, :] = temp

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_DRIFT_FORCES,
                                   data["drift_forces"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_DRIFT_FORCES_ATTR)
    dset[:, :, :] = data["drift_forces"]

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_YAW_MOMENT,
                                   data["yaw_moment"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_YAW_MOMENT_ATTR)
    dset[:, :] = data["yaw_moment"]

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_CENTER_BUOYANCY,
                                   data["center_buoyancy"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset,
                                structure.H5_RESULTS_CENTER_BUOYANCY_ATTR)
    dset[:, :] = data["center_buoyancy"]

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_VOLUME_DISPLACEMENT,
                                   data["displacement"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset,
                                structure.H5_RESULTS_VOLUME_DISPLACEMENT_ATTR)
    dset[:] = data["displacement"]

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_WATER_PLANE_AREA,
                                   data["waterplane_area"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset,
                                structure.H5_RESULTS_WATER_PLANE_AREA_ATTR)
    dset[:] = data["waterplane_area"]

    dset = utility.require_dataset(hdf5_data,
                                   structure.H5_RESULTS_STIFNESS,
                                   data["stifness"].shape,
                                   dtype='f')
    utility.set_hdf5_attributes(dset, structure.H5_RESULTS_STIFNESS_ATTR)
    dset[:, :, :] = data["stifness"]

    utility.log_exit(logger, signature, [None])
Пример #18
0
def read_results(hdf5_data):
    """
    Read the hydrodynamic coefficients cases from the hdf5 file
    Args:
        hdf5_data: object, the hdf5 opened file
    Returns:
        the hydrodynamic coefficients cases
    """
    signature = __name__ + '.read_results(hdf5_data)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature, {"hdf5_data": str(hdf5_data)})

    idx_force = hdf5_data.get(structure.H5_RESULTS_CASE_FORCE)
    utility.check_dataset_type(
        idx_force,
        name=str(structure.H5_RESULTS_CASE_FORCE_ATTR['description']),
        location=structure.H5_RESULTS_CASE_FORCE)
    n_integration = idx_force.shape[0]

    idx_radiation = hdf5_data.get(structure.H5_RESULTS_CASE_MOTION)
    utility.check_dataset_type(
        idx_radiation,
        name=str(structure.H5_RESULTS_CASE_MOTION_ATTR['description']),
        location=structure.H5_RESULTS_CASE_MOTION)
    n_radiation = idx_radiation.shape[0]

    beta = hdf5_data.get(structure.H5_RESULTS_CASE_BETA)
    utility.check_dataset_type(
        beta,
        name=str(structure.H5_RESULTS_CASE_BETA_ATTR['description']),
        location=structure.H5_RESULTS_CASE_BETA)
    n_beta = beta.shape[0]

    w = hdf5_data.get(structure.H5_RESULTS_CASE_W)
    utility.check_dataset_type(
        beta,
        name=str(structure.H5_RESULTS_CASE_W_ATTR['description']),
        location=structure.H5_RESULTS_CASE_W)
    n_w = w.shape[0]

    theta = hdf5_data.get(structure.H5_RESULTS_CASE_THETA)
    n_theta = theta.shape[0]

    result = TResult(n_w, n_radiation, n_integration, n_theta, n_beta)
    result.idx_force = idx_force
    result.idx_radiation = idx_radiation
    result.beta = beta
    result.w = w
    result.theta = theta

    forces = hdf5_data.get(structure.H5_RESULTS_FORCES)
    for k in range(n_integration):
        c = 0
        for i in range(n_w):
            for j in range(n_beta):
                result.diffraction_force[i, j, k] = forces[k, c] * np.exp(
                    complex(0, 1) * forces[k, c + 1])
                c += 2
            for j in range(n_radiation):
                result.added_mass[i, j, k] = forces[k, c]
                result.radiation_damping[i, j, k] = forces[k, c + 1]
                c += 2

    result.froudkrylov_force = hdf5_data.get(
        structure.H5_RESULTS_FK_FORCES_RAW)

    utility.log_exit(logger, signature, [str(result)])
    return result
Пример #19
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
Пример #20
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
Пример #21
0
def read_results(hdf5_data):
    """
    Read the hydrodynamic coefficients cases from the hdf5 file
    Args:
        hdf5_data: object, the hdf5 opened file
    Returns:
        the hydrodynamic coefficients cases
    """
    signature = __name__ + '.read_results(hdf5_data)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(logger, signature,
                         {"hdf5_data": str(hdf5_data)})

    idx_force = hdf5_data.get(structure.H5_RESULTS_CASE_FORCE)
    utility.check_dataset_type(idx_force,
                               name=str(structure.H5_RESULTS_CASE_FORCE_ATTR['description']),
                               location=structure.H5_RESULTS_CASE_FORCE)
    n_integration = idx_force.shape[0]

    idx_radiation = hdf5_data.get(structure.H5_RESULTS_CASE_MOTION)
    utility.check_dataset_type(idx_radiation,
                               name=str(structure.H5_RESULTS_CASE_MOTION_ATTR['description']),
                               location=structure.H5_RESULTS_CASE_MOTION)
    n_radiation = idx_radiation.shape[0]

    beta = hdf5_data.get(structure.H5_RESULTS_CASE_BETA)
    utility.check_dataset_type(beta,
                               name=str(structure.H5_RESULTS_CASE_BETA_ATTR['description']),
                               location=structure.H5_RESULTS_CASE_BETA)
    n_beta = beta.shape[0]

    w = hdf5_data.get(structure.H5_RESULTS_CASE_W)
    utility.check_dataset_type(beta,
                               name=str(structure.H5_RESULTS_CASE_W_ATTR['description']),
                               location=structure.H5_RESULTS_CASE_W)
    n_w = w.shape[0]

    theta = hdf5_data.get(structure.H5_RESULTS_CASE_THETA)
    n_theta = theta.shape[0]

    result = TResult(n_w, n_radiation, n_integration, n_theta, n_beta)
    result.idx_force = idx_force
    result.idx_radiation = idx_radiation
    result.beta = beta
    result.w = w
    result.theta = theta

    forces = hdf5_data.get(structure.H5_RESULTS_FORCES)
    if forces is None:
        print 'DEBUG: forces is none'
    if forces is not None:
        print 'forces is not none '
        for k in range(n_integration):
            c = 0
            for i in range(n_w):
                for j in range(n_beta):
                    result.diffraction_force[i, j, k] = forces[k, c]*np.exp(complex(0, 1)*forces[k, c+1])
                    c += 2
                for j in range(n_radiation):
                    result.added_mass[i, j, k] = forces[k, c]
                    result.radiation_damping[i, j, k] = forces[k, c+1]
                    c += 2

    result.froudkrylov_force = hdf5_data.get(structure.H5_RESULTS_FK_FORCES_RAW)

    utility.log_exit(logger, signature, [str(result)])
    return result
Пример #22
0
def save_wave_elevation(w, etai, etap, eta, x, y, filename):
    """
    Save the wave elevation to a file in tec format
    Args:
        w: float, the wave frequency
        etai: 2D array, a wave elevation variable
        eta: 2D array, a wave elevation variable
        etap: 2D array, a wave elevation variable
        x: 1D array, a wave elevation variable
        y: 1D array, a wave elevation variable
        filename: string, the path to the file where to save
    """
    signature = __name__ + '.save_wave_elevation(w, etai, etap, eta, x, y, filename)'
    logger = logging.getLogger(__name__)
    utility.log_entrance(
        logger, signature, {
            "w": w,
            "etai": etai,
            "etap": etap,
            "eta": eta,
            "x": x,
            "y": y,
            "filename": filename
        })

    nx = len(x)
    ny = len(y)
    utility.mkdir_p(os.path.abspath(os.path.dirname(filename)))
    with open(filename, 'w') as inp:
        s = 'VARIABLES="X" "Y" "etaI_C" "etaI_S" "etaP_C" "etaC_S" '
        s += '"etaI_C+etaP_C" "etaI_S+etaI_P" "|etaP|" "|etaI+etaP|"\n'
        inp.write(s)

        s = 'ZONE t="Wave frequency - w = '
        s += str(w) + '",N=\t' + str(nx * ny) + ', E=\t' + str(
            (nx - 1) * (nx - 1)) + '\t , F=FEPOINT,ET=QUADRILATERAL\n'
        inp.write(s)
        for i in range(nx):
            for j in range(ny):
                s = str(x[i]) + '\t' + str(y[j]) + '\t' + str(
                    np.real(etai[i, j])) + '\t'
                s += str(np.imag(etai[i, j])) + '\t' + str(np.real(
                    etap[i, j])) + '\t'
                s += str(np.imag(etap[i, j])) + '\t' + str(
                    np.real(etai[i, j] + etap[i, j])) + '\t'
                s += str(np.imag(etai[i, j] + etap[i, j])) + '\t' + str(
                    np.abs(etap[i, j])) + '\t'
                s += str(np.abs(eta[i, j])) + '\n'
                inp.write(s)

        for i in range(nx - 1):
            for j in range(ny - 1):
                s = str(j + 1 + i * ny) + '\t' + str(
                    j + 1 + (i + 1) * ny) + '\t' + str(j + 2 + i * ny) + '\n'
                inp.write(s)

    utility.log_and_print(
        logger,
        utility.get_abs(filename) +
        ' contains the wave elevation in tec format.')
    utility.log_exit(logger, signature, [None])