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])
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])
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])
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])
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])
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])
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])
def solve(custom_config): """ Configure and then run the solver Args: custom_config, dict The custom configuration dictionary Returns: the output of the fortran function as string if successful """ signature = __name__ + '.solve(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') n_tabulatedx = utility.get_setting(settings.GREEN_TABULATION_NUMX, custom_config, 'GREEN_TABULATION_NUMX') n_tabulatedz = utility.get_setting(settings.GREEN_TABULATION_NUMZ, custom_config, 'GREEN_TABULATION_NUMZ') n_points_simpson = utility.get_setting( settings.GREEN_TABULATION_SIMPSON_NPOINTS, custom_config, 'GREEN_TABULATION_SIMPSON_NPOINTS') with h5py.File(hdf5_file, "a") as hdf5_db: if n_tabulatedx and n_tabulatedx > 0: dset = utility.require_dataset( hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_NUMX, (1, ), dtype='i') dset[:] = n_tabulatedx if n_tabulatedz and n_tabulatedz > 0: dset = utility.require_dataset( hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_NUMZ, (1, ), dtype='i') dset[:] = n_tabulatedz if n_points_simpson and n_points_simpson > 0: dset = utility.require_dataset( hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS, (1, ), dtype='i') dset[:] = n_points_simpson return run(hdf5_db)
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
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
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])
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
def solve(custom_config): """ Configure and then run the solver Args: custom_config, dict The custom configuration dictionary Returns: the output of the fortran function as string if successful """ signature = __name__ + '.solve(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') n_tabulatedx = utility.get_setting(settings.GREEN_TABULATION_NUMX, custom_config, 'GREEN_TABULATION_NUMX') n_tabulatedz = utility.get_setting(settings.GREEN_TABULATION_NUMZ, custom_config, 'GREEN_TABULATION_NUMZ') n_points_simpson = utility.get_setting(settings.GREEN_TABULATION_SIMPSON_NPOINTS, custom_config, 'GREEN_TABULATION_SIMPSON_NPOINTS') with h5py.File(hdf5_file, "a") as hdf5_db: if n_tabulatedx and n_tabulatedx > 0: dset = utility.require_dataset(hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_NUMX, (1, ), dtype='i') dset[:] = n_tabulatedx if n_tabulatedz and n_tabulatedz > 0: dset = utility.require_dataset(hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_NUMZ, (1, ), dtype='i') dset[:] = n_tabulatedz if n_points_simpson and n_points_simpson > 0: dset = utility.require_dataset(hdf5_db, structure.H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS, (1, ), dtype='i') dset[:] = n_points_simpson return run(hdf5_db)
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
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])
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])
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])
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
def run(hdf5_data): """ Run the solver Args: hdf5_data: object, the hdf5 opened storage Returns: the output of the fortran function as string if successful """ signature = __name__ + '.run(hdf5_data)' logger = logging.getLogger(__name__) utility.log_entrance(logger, signature, {'hdf5_data': hdf5_data}) data = init_data() data["log_level"] = logging.getLogger().getEffectiveLevel() dset = utility.get_1d_array(logger, hdf5_data, "H5_L10_COUNT", expected_dim=4) offset = 1 l10_i_sym = int(dset[0]) n_points = int(dset[1]) n_panels = int(dset[2]) n_bodies = int(dset[3]) mesh_cpanel = utility.get_dataset(hdf5_data, 'H5_L10_CPANEL') mesh_xm = utility.get_dataset(hdf5_data, 'H5_L10_XM') mesh_n = utility.get_dataset(hdf5_data, 'H5_L10_N') mesh_a = utility.get_dataset(hdf5_data, 'H5_L10_A') dset = utility.get_1d_array(logger, hdf5_data, "H5_L12_COUNT", expected_dim=2) i_sym = int(dset[1]) if l10_i_sym != i_sym or int(dset[0]) != 2: raise ValueError('Stopping because the mesh file format is not correct.' 'The symmetry about xoz axis is inconsistent') data["i_sym"] = i_sym data["mesh_p"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_L12_P'), order='F', dtype='i') data["mesh_x"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_L12_X'), order='F', dtype='f') data["n_points"] = n_points data["n_panels"] = n_panels data["n_bodies"] = n_bodies data["mesh_cpanel"] = np.asarray(mesh_cpanel, order='F', dtype='i') data["mesh_xm"] = np.asarray(mesh_xm, order='F', dtype='f') data["mesh_n"] = np.asarray(mesh_n, order='F', dtype='f') data["mesh_a"] = np.asarray(mesh_a, order='F', dtype='f') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_W') bc_omega = np.asarray(dset, order='F', dtype='f') n_problems = bc_omega.shape[0] data["bc_omega"] = bc_omega data["n_problems"] = n_problems dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_BETA') data["bc_switch_type"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_POTENTIAL') data["bc_switch_potential"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_FREE_SURFACE') data["bc_switch_freesurface"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_KOCHIN') data["bc_switch_kochin"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_VELOCITIES') data["bc_normal_velocity"] = np.asarray(dset, order='F', dtype='F') data["nbc_panels"] = data["bc_normal_velocity"].shape[0] data["rho"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_VOLUME", expected_dim=1)[0] data["g"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_GRAVITY", expected_dim=1)[0] data["depth"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_DEPTH", expected_dim=1)[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_ENV_WAVE_POINT", expected_dim=2) data["xeff"] = dset[0] data["y_eff"] = dset[1] data["indiq_solver"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_TYPE", expected_dim=1)[0] data["max_iterations"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GMRES_MAX_ITERATIONS", 1)[0] data["restart_param"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GMRES_RESTART", expected_dim=1)[0] data["tol_gmres"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GMRES_STOPPING", expected_dim=1)[0] data["nds"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_MESH_INTEGRATION'), order='F', dtype='f') data["n_integration"] = data["nds"].shape[0] data["use_higher_order"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_USE_HIGHER_ORDER", 1)[0] data["num_panel_higher_order"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_NUM_PANEL_HIGHER_ORDER", 1)[0] data["b_spline_order"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_B_SPLINE_ORDER", expected_dim=1)[0] data["theta"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_MESH_KOCHIN'), order='F', dtype='f') data["n_theta"] = data["theta"].shape[0] data["meshfs_x"] = np.asarray(utility.get_2d_array(logger, hdf5_data, "H5_MESH_FREE_SURFACE_VECTORS"), dtype='f') data["nfs_points"] = data["meshfs_x"].shape[1] data["meshfs_p"] = np.asarray(utility.get_2d_array(logger, hdf5_data, "H5_MESH_FREE_SURFACE_INDEX"), order='F', dtype='i') + offset data["nfs_panels"] = data["meshfs_p"].shape[1] data["out_phi"] = np.zeros((n_problems, 1+data["nfs_points"]), dtype='F', order="F") data["out_pressure"] = np.zeros((n_problems, data["nbc_panels"]), dtype='F', order="F") data["out_hkochin"] = np.zeros((n_problems, data["n_theta"]), dtype='F', order="F") data["line"] = np.zeros((data["n_integration"], n_problems*2), order="F", dtype='f') data["drift_forces"] = np.zeros((n_problems, data["n_theta"], 2), order="F", dtype='f') data["yaw_moment"] = np.zeros((n_problems, data["n_theta"]), order="F", dtype='f') data["center_buoyancy"] = np.zeros((n_bodies, 3), order="F", dtype='f') data["displacement"] = np.zeros((n_bodies), order="F", dtype='f') data["waterplane_area"] = np.zeros((n_bodies), order="F", dtype='f') data["stifness"] = np.zeros((n_bodies, 6, 6), order="F", dtype='f') n_potentials = 5*n_points*(1 + (i_sym == 1)) +9*n_panels*(1 + (i_sym == 1)) data["out_potential"] = np.zeros((n_problems, n_potentials), dtype='f', order="F") data["n_potentials"] = n_potentials data["n_tabulatedx"] = int(utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_NUMX", 1)[0]) data["n_tabulatedz"] = int(utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_NUMZ", 1)[0]) data["n_points_simpson"] = int(utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS", 1)[0]) dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_SWITCH_ODE_INFLUENCE') data["fast_influence_switch"] = np.asarray(dset, order='F', dtype='i') data["is_interior_domain"] = np.zeros((n_panels), dtype='i', order="F") remove_irregular_frequencies = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES", 1)[0] if remove_irregular_frequencies: # Bug??? Previous code used dset = hdf5_data.get(structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_IS_INTERIOR_DOMAIN') data["is_interior_domain"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_RESULTS_CASE_BETA') data["beta"] = np.asarray(dset, order='F', dtype='f') data["n_beta"] = data["beta"].shape[0] dset = utility.get_dataset(hdf5_data, 'H5_RESULTS_CASE_RADIATION') data["rad_case"] = np.asarray(dset, order='F', dtype='f') data["n_radiation"] = data["rad_case"].shape[0] dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_THIN_PANELS') data["is_thin_body"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_USE_DIPOLES_IMPLEMENTATION') data["use_dipoles_implementation"] = dset[0] data["remove_irregular_frequencies"] = utility.get_dataset(hdf5_data, 'H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES')[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_COMPUTE_YAW_MOMENT", 1) data["compute_yaw_moment"] = dset[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_COMPUTE_DRIFT_FORCES", 1) data["compute_drift_forces"] = dset[0] # Disable kochin, yaw moments and drift forces if data["use_higher_order"] == 1 or data["use_dipoles_implementation"] == 1: data["n_theta"] = 0 logger.info('Disabling koching, yaw monment and drift forces computation as ' 'not supported when higher order panel or dipoles implementation is ' 'enabled') #with CaptureOutput() as capturer: solver_fortran.run_solver(data) write_result(hdf5_data, data)
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])
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
def run(hdf5_data): """ Run the solver Args: hdf5_data: object, the hdf5 opened storage Returns: the output of the fortran function as string if successful """ signature = __name__ + '.run(hdf5_data)' logger = logging.getLogger(__name__) utility.log_entrance(logger, signature, {'hdf5_data': hdf5_data}) data = init_data() data["log_level"] = logging.getLogger().getEffectiveLevel() dset = utility.get_1d_array(logger, hdf5_data, "H5_L10_COUNT", expected_dim=4) offset = 1 l10_i_sym = int(dset[0]) n_points = int(dset[1]) n_panels = int(dset[2]) n_bodies = int(dset[3]) mesh_cpanel = utility.get_dataset(hdf5_data, 'H5_L10_CPANEL') mesh_xm = utility.get_dataset(hdf5_data, 'H5_L10_XM') mesh_n = utility.get_dataset(hdf5_data, 'H5_L10_N') mesh_a = utility.get_dataset(hdf5_data, 'H5_L10_A') dset = utility.get_1d_array(logger, hdf5_data, "H5_L12_COUNT", expected_dim=2) i_sym = int(dset[1]) if l10_i_sym != i_sym or int(dset[0]) != 2: raise ValueError( 'Stopping because the mesh file format is not correct.' 'The symmetry about xoz axis is inconsistent') data["i_sym"] = i_sym data["mesh_p"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_L12_P'), order='F', dtype='i') data["mesh_x"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_L12_X'), order='F', dtype='f') data["n_points"] = n_points data["n_panels"] = n_panels data["n_bodies"] = n_bodies data["mesh_cpanel"] = np.asarray(mesh_cpanel, order='F', dtype='i') data["mesh_xm"] = np.asarray(mesh_xm, order='F', dtype='f') data["mesh_n"] = np.asarray(mesh_n, order='F', dtype='f') data["mesh_a"] = np.asarray(mesh_a, order='F', dtype='f') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_W') bc_omega = np.asarray(dset, order='F', dtype='f') n_problems = bc_omega.shape[0] data["bc_omega"] = bc_omega data["n_problems"] = n_problems dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_BETA') data["bc_switch_type"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_POTENTIAL') data["bc_switch_potential"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_FREE_SURFACE') data["bc_switch_freesurface"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_SWITCH_KOCHIN') data["bc_switch_kochin"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_NORMAL_VELOCITY_VELOCITIES') data["bc_normal_velocity"] = np.asarray(dset, order='F', dtype='F') data["nbc_panels"] = data["bc_normal_velocity"].shape[0] data["rho"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_VOLUME", expected_dim=1)[0] data["g"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_GRAVITY", expected_dim=1)[0] data["depth"] = utility.get_1d_array(logger, hdf5_data, "H5_ENV_DEPTH", expected_dim=1)[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_ENV_WAVE_POINT", expected_dim=2) data["xeff"] = dset[0] data["y_eff"] = dset[1] data["indiq_solver"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_TYPE", expected_dim=1)[0] data["max_iterations"] = utility.get_1d_array( logger, hdf5_data, "H5_SOLVER_GMRES_MAX_ITERATIONS", 1)[0] data["restart_param"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GMRES_RESTART", expected_dim=1)[0] data["tol_gmres"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GMRES_STOPPING", expected_dim=1)[0] data["nds"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_MESH_INTEGRATION'), order='F', dtype='f') data["n_integration"] = data["nds"].shape[0] data["use_higher_order"] = utility.get_1d_array( logger, hdf5_data, "H5_SOLVER_USE_HIGHER_ORDER", 1)[0] data["num_panel_higher_order"] = utility.get_1d_array( logger, hdf5_data, "H5_SOLVER_NUM_PANEL_HIGHER_ORDER", 1)[0] data["b_spline_order"] = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_B_SPLINE_ORDER", expected_dim=1)[0] data["theta"] = np.asarray(utility.get_dataset(hdf5_data, 'H5_MESH_KOCHIN'), order='F', dtype='f') data["n_theta"] = data["theta"].shape[0] data["meshfs_x"] = np.asarray(utility.get_2d_array( logger, hdf5_data, "H5_MESH_FREE_SURFACE_VECTORS"), dtype='f') data["nfs_points"] = data["meshfs_x"].shape[1] data["meshfs_p"] = np.asarray(utility.get_2d_array( logger, hdf5_data, "H5_MESH_FREE_SURFACE_INDEX"), order='F', dtype='i') + offset data["nfs_panels"] = data["meshfs_p"].shape[1] data["out_phi"] = np.zeros((n_problems, 1 + data["nfs_points"]), dtype='F', order="F") data["out_pressure"] = np.zeros((n_problems, data["nbc_panels"]), dtype='F', order="F") data["out_hkochin"] = np.zeros((n_problems, data["n_theta"]), dtype='F', order="F") data["line"] = np.zeros((data["n_integration"], n_problems * 2), order="F", dtype='f') data["drift_forces"] = np.zeros((n_problems, data["n_theta"], 2), order="F", dtype='f') data["yaw_moment"] = np.zeros((n_problems, data["n_theta"]), order="F", dtype='f') data["center_buoyancy"] = np.zeros((n_bodies, 3), order="F", dtype='f') data["displacement"] = np.zeros((n_bodies), order="F", dtype='f') data["waterplane_area"] = np.zeros((n_bodies), order="F", dtype='f') data["stifness"] = np.zeros((n_bodies, 6, 6), order="F", dtype='f') n_potentials = 5 * n_points * (1 + (i_sym == 1)) + 9 * n_panels * ( 1 + (i_sym == 1)) data["out_potential"] = np.zeros((n_problems, n_potentials), dtype='f', order="F") data["n_potentials"] = n_potentials data["n_tabulatedx"] = int( utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_NUMX", 1)[0]) data["n_tabulatedz"] = int( utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_NUMZ", 1)[0]) data["n_points_simpson"] = int( utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_GREEN_TABULATION_SIMPSON_NPOINTS", 1)[0]) dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_SWITCH_ODE_INFLUENCE') data["fast_influence_switch"] = np.asarray(dset, order='F', dtype='i') data["is_interior_domain"] = np.zeros((n_panels), dtype='i', order="F") remove_irregular_frequencies = utility.get_1d_array( logger, hdf5_data, "H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES", 1)[0] if remove_irregular_frequencies: # Bug??? Previous code used dset = hdf5_data.get(structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_IS_INTERIOR_DOMAIN') data["is_interior_domain"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_RESULTS_CASE_BETA') data["beta"] = np.asarray(dset, order='F', dtype='f') data["n_beta"] = data["beta"].shape[0] dset = utility.get_dataset(hdf5_data, 'H5_RESULTS_CASE_RADIATION') data["rad_case"] = np.asarray(dset, order='F', dtype='f') data["n_radiation"] = data["rad_case"].shape[0] dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_THIN_PANELS') data["is_thin_body"] = np.asarray(dset, order='F', dtype='i') dset = utility.get_dataset(hdf5_data, 'H5_SOLVER_USE_DIPOLES_IMPLEMENTATION') data["use_dipoles_implementation"] = dset[0] data["remove_irregular_frequencies"] = utility.get_dataset( hdf5_data, 'H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES')[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_COMPUTE_YAW_MOMENT", 1) data["compute_yaw_moment"] = dset[0] dset = utility.get_1d_array(logger, hdf5_data, "H5_SOLVER_COMPUTE_DRIFT_FORCES", 1) data["compute_drift_forces"] = dset[0] # Disable kochin, yaw moments and drift forces if data["use_higher_order"] == 1 or data["use_dipoles_implementation"] == 1: data["n_theta"] = 0 logger.info( 'Disabling koching, yaw monment and drift forces computation as ' 'not supported when higher order panel or dipoles implementation is ' 'enabled') #with CaptureOutput() as capturer: solver_fortran.run_solver(data) write_result(hdf5_data, data)
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])
def run(hdf5_data, custom_config): """ This function run the postprocessor Args: hdf5_data: object, the hdf5 opened file custom_config, dict The custom configuration dictionary """ logger = logging.getLogger(__name__) signature = __name__ + '.run(hdf5_data, custom_config)' # No need to log the parameter of the method here as it will only be duplicate. # This function is never called directly by the user and always call from the postprocess function # which already logs the configuration. utility.log_entrance(logger, signature, {}) logger.info('Initialisation the post processing steps') logger.info('Reading environment data ...') environment = utility.read_environment(hdf5_data) logger.info('Read environment data' + str(environment)) logger.info('Reading simulation results') result = read_results(hdf5_data) logger.info('Read solver result ' + str(result)) logger.info('Post processing initialisation done !') # Saving to hdf5 file dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_ADDED_MASS, result.added_mass.shape, dtype='f') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_ADDED_MASS_ATTR) dset[:, :, :] = result.added_mass logger.info('Saved ' + str(structure.H5_RESULTS_ADDED_MASS_ATTR['description']) + ' at ' + structure.H5_RESULTS_ADDED_MASS + ' with characteristics ' + str(dset)) dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_RADIATION_DAMPING, result.radiation_damping.shape, dtype='f') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_RADIATION_DAMPING_ATTR) dset[:, :, :] = result.radiation_damping logger.info('Saved ' + str(structure.H5_RESULTS_RADIATION_DAMPING_ATTR['description']) + ' at ' + structure.H5_RESULTS_RADIATION_DAMPING + ' with characteristics ' + str(dset)) excitation_forces = result.diffraction_force + result.froudkrylov_force dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_EXCITATION_FORCES, excitation_forces.shape, dtype='F') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_EXCITATION_FORCES_ATTR) dset[:, :, :] = excitation_forces logger.info('Saved ' + str(structure.H5_RESULTS_EXCITATION_FORCES_ATTR['description']) + ' at ' + structure.H5_RESULTS_EXCITATION_FORCES + ' with characteristics ' + str(dset)) tec_file = utility.get_setting(settings.RADIATION_COEFFICIENTS_TEC_FILE, custom_config, 'RADIATION_COEFFICIENTS_TEC_FILE') if tec_file: save_radiation_coefficients(result, tec_file) logger.info('Radiation coefficients successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Radiation coefficients tecplot format generation is disabled') tec_file = utility.get_setting(settings.DIFFRACTION_FORCE_TEC_FILE, custom_config, 'DIFFRACTION_FORCE_TEC_FILE') if tec_file: save_diffraction_force(result, tec_file) logger.info('Diffraction forces successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Diffraction forces tecplot format generation is disabled') tec_file = utility.get_setting(settings.EXCITATION_FORCE_TEC_FILE, custom_config, 'EXCITATION_FORCE_TEC_FILE') if tec_file: save_excitation_force(result, tec_file) logger.info('Excitation forces successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Excitation forces tecplot format generation is disabled') irf = get_irf(hdf5_data, result) if irf.switch == 1: irf = compute_irf(result, irf) # Saving to hdf5 file dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_ADDED_MASS_INFINITE, irf.added_mass.shape, dtype='f') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_ADDED_MASS_INFINITE_ATTR) dset[:, :] = irf.added_mass tec_file = utility.get_setting(settings.IRF_TEC_FILE, custom_config, 'IRF_TEC_FILE') if tec_file: save_irf(irf, tec_file) logger.info('IRF successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('IRF tecplot format generation is disabled') else: logger.info('IRF computation is disabled') raos = np.zeros((result.n_integration, result.n_w, result.n_beta), dtype='F') raos = compute_raos(raos, result) tec_file = utility.get_setting(settings.WAVE_FIELD_TEC_FILE, custom_config, 'WAVE_FIELD_TEC_FILE') dset = hdf5_data.get(structure.H5_SOLVER_USE_HIGHER_ORDER) utility.check_dataset_type(dset, name=str(structure.H5_SOLVER_USE_HIGHER_ORDER_ATTR['description']), location=structure.H5_SOLVER_USE_HIGHER_ORDER) use_higher_order = dset[0] dset = hdf5_data.get(structure.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION) utility.check_dataset_type(dset, name=str(structure.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION_ATTR['description']), location=structure.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION) use_dipoles_implementation = dset[0] dset = hdf5_data.get(structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) utility.check_dataset_type(dset, name=str(structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES_ATTR['description']), location=structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) remove_irregular_frequencies = dset[0] # Wave Elevation computation and tec generation if result.n_theta < 1: tec_file = None logger.info('Wave elevation tecplot format generation is disabled because there is no directions (Kochin)') if tec_file: if use_higher_order != 1 and use_dipoles_implementation != 1 and remove_irregular_frequencies != 1: res = compute_wave_elevation(hdf5_data, environment, 0, 0, raos, result) save_wave_elevation(res['w'], res['etai'], res["etap"], res["eta"], res["x"], res["y"], tec_file) logger.info('Wave elevation successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Wave elevation computation is not supported when higher order panel, ' + 'used diplome implementation or remove irregular frequencies are enabled.' + ' Disabling it.') else: logger.info('Wave elevation tecplot format generation is disabled')
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
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])
def run(hdf5_data, custom_config): """ This function run the postprocessor Args: hdf5_data: object, the hdf5 opened file custom_config, dict The custom configuration dictionary """ logger = logging.getLogger(__name__) signature = __name__ + '.run(hdf5_data, custom_config)' # No need to log the parameter of the method here as it will only be duplicate. # This function is never called directly by the user and always call from the postprocess function # which already logs the configuration. utility.log_entrance(logger, signature, {}) logger.info('Initialisation the post processing steps') logger.info('Reading environment data ...') environment = utility.read_environment(hdf5_data) logger.info('Read environment data' + str(environment)) logger.info('Reading simulation results') result = read_results(hdf5_data) logger.info('Read solver result ' + str(result)) logger.info('Post processing initialisation done !') # Saving to hdf5 file dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_ADDED_MASS, result.added_mass.shape, dtype='f') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_ADDED_MASS_ATTR) dset[:, :, :] = result.added_mass logger.info('Saved ' + str(structure.H5_RESULTS_ADDED_MASS_ATTR['description']) + ' at ' + structure.H5_RESULTS_ADDED_MASS + ' with characteristics ' + str(dset)) dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_RADIATION_DAMPING, result.radiation_damping.shape, dtype='f') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_RADIATION_DAMPING_ATTR) dset[:, :, :] = result.radiation_damping logger.info( 'Saved ' + str(structure.H5_RESULTS_RADIATION_DAMPING_ATTR['description']) + ' at ' + structure.H5_RESULTS_RADIATION_DAMPING + ' with characteristics ' + str(dset)) excitation_forces = result.diffraction_force + result.froudkrylov_force dset = utility.require_dataset(hdf5_data, structure.H5_RESULTS_EXCITATION_FORCES, excitation_forces.shape, dtype='F') utility.set_hdf5_attributes(dset, structure.H5_RESULTS_EXCITATION_FORCES_ATTR) dset[:, :, :] = excitation_forces logger.info( 'Saved ' + str(structure.H5_RESULTS_EXCITATION_FORCES_ATTR['description']) + ' at ' + structure.H5_RESULTS_EXCITATION_FORCES + ' with characteristics ' + str(dset)) tec_file = utility.get_setting(settings.RADIATION_COEFFICIENTS_TEC_FILE, custom_config, 'RADIATION_COEFFICIENTS_TEC_FILE') if tec_file: save_radiation_coefficients(result, tec_file) logger.info( 'Radiation coefficients successfully saved in tecplot format at ' + str(tec_file)) else: logger.info( 'Radiation coefficients tecplot format generation is disabled') tec_file = utility.get_setting(settings.DIFFRACTION_FORCE_TEC_FILE, custom_config, 'DIFFRACTION_FORCE_TEC_FILE') if tec_file: save_diffraction_force(result, tec_file) logger.info( 'Diffraction forces successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Diffraction forces tecplot format generation is disabled') tec_file = utility.get_setting(settings.EXCITATION_FORCE_TEC_FILE, custom_config, 'EXCITATION_FORCE_TEC_FILE') if tec_file: save_excitation_force(result, tec_file) logger.info( 'Excitation forces successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('Excitation forces tecplot format generation is disabled') irf = get_irf(hdf5_data, result) if irf.switch == 1: irf = compute_irf(result, irf) # Saving to hdf5 file dset = utility.require_dataset( hdf5_data, structure.H5_RESULTS_ADDED_MASS_INFINITE, irf.added_mass.shape, dtype='f') utility.set_hdf5_attributes( dset, structure.H5_RESULTS_ADDED_MASS_INFINITE_ATTR) dset[:, :] = irf.added_mass tec_file = utility.get_setting(settings.IRF_TEC_FILE, custom_config, 'IRF_TEC_FILE') if tec_file: save_irf(irf, tec_file) logger.info('IRF successfully saved in tecplot format at ' + str(tec_file)) else: logger.info('IRF tecplot format generation is disabled') else: logger.info('IRF computation is disabled') raos = np.zeros((result.n_integration, result.n_w, result.n_beta), dtype='F') raos = compute_raos(raos, result) tec_file = utility.get_setting(settings.WAVE_FIELD_TEC_FILE, custom_config, 'WAVE_FIELD_TEC_FILE') dset = hdf5_data.get(structure.H5_SOLVER_USE_HIGHER_ORDER) utility.check_dataset_type( dset, name=str(structure.H5_SOLVER_USE_HIGHER_ORDER_ATTR['description']), location=structure.H5_SOLVER_USE_HIGHER_ORDER) use_higher_order = dset[0] dset = hdf5_data.get(structure.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION) utility.check_dataset_type( dset, name=str(structure. H5_SOLVER_USE_DIPOLES_IMPLEMENTATION_ATTR['description']), location=structure.H5_SOLVER_USE_DIPOLES_IMPLEMENTATION) use_dipoles_implementation = dset[0] dset = hdf5_data.get(structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) utility.check_dataset_type( dset, name=str(structure. H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES_ATTR['description']), location=structure.H5_SOLVER_REMOVE_IRREGULAR_FREQUENCIES) remove_irregular_frequencies = dset[0] if tec_file: if use_higher_order != 1 and use_dipoles_implementation != 1 and remove_irregular_frequencies != 1: res = compute_wave_elevation(hdf5_data, environment, 0, 0, raos, result) save_wave_elevation(res['w'], res['etai'], res["etap"], res["eta"], res["x"], res["y"], tec_file) logger.info( 'Wave elevation successfully saved in tecplot format at ' + str(tec_file)) else: logger.info( 'Wave elevation computation is not supported when higher order panel, ' + 'used diplome implementation or remove irregular frequencies are enabled.' + ' Disabling it.') else: logger.info('Wave elevation tecplot format generation is disabled')