# BLUE KENUE channel mesh.t3s to CCHE2D mesh.geo --Clemens Dorfmann-- #---------------------------------------------------------------------# # Give here the filenames for Input and Output files: Input_file = 'Mesh_j10.t3s' Output_file = 'Mesh_j10.t3s.geo' # give here the number of crosswise channel nodes j! j = 10 #---------------------------------------------------------------------# # read BlueKenue t3s mesh file file BK_file = open(Input_file, 'r') BK_text = BK_file.readlines() BK_file.close() # initialisation of some empty lists liste_x_BK = [] liste_y_BK = [] liste_z_BK = [] liste_x_CC = [] liste_y_CC = [] liste_z_CC = [] liste_i = [] liste_j = [] line_noden = [] # get total number of nodes and number of streamwise nodes i hE = BK_text.index(':EndHeader\n') line_noden.append(BK_text[hE-4].split()) nodenumbers = int(line_noden[0][1]) i = nodenumbers / j # delete header and connectivity table in BlueKenue t3s format del BK_text[:hE+1] del BK_text[nodenumbers:] # read x y z values into lists for lines in BK_text: BK_text = lines.split() liste_x_BK.append(float(BK_text[0])) liste_y_BK.append(float(BK_text[1])) liste_z_BK.append(float(BK_text[2])) for k in range(i): liste_x_CC += liste_x_BK[k::i] liste_y_CC += liste_y_BK[k::i] liste_z_CC += liste_z_BK[k::i] # fill columns 3, 5 and 6 col_3 = [1.0] * i * j # water surface level col_5 = [0] * i * j # boundary conditions col_6 = [0.0] * i * j # manning roughness values # write to CCHE2D geo file CCHE2D_file= open(Output_file, 'w') CCHE2D_file.write(str(j) + '\t' + str(i) + '\n') for k in range(i*j): CCHE2D_file.write(str(liste_x_CC[k]) + '\t' + str(liste_y_CC[k]) + '\t' + str(col_3[k]) \ + '\t' + str(liste_z_CC[k]) + '\t' + str(col_5[k]) + '\t' + str(col_6[k]) + '\n') CCHE2D_file.close()