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_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_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_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_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 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_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 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 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 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])