def locate_shock_front(stageName, nbi, nbj): """ Reads all flow blocks and returns the coordinates of the shock front, searching along the stagnation line. """ blockData = [] for ib in range(nbi): blockData.append([]) for jb in range(nbj): blkindx = ib * nbj + jb fileName = 'flow/t0001/%s.flow.b%04d.t0001.gz' \ % (stageName, blkindx) fp = gzip.open(fileName, "r") blk = StructuredGridFlow() blk.read(fp) blockData[ib].append(blk) fp.close() jb = 0 nj = blockData[0][jb].nj j = 0 x = [] y = [] p = [] for ib in range(nbi): ni = blockData[ib][jb].ni k = 0 # 2D only for i in range(ni): x.append(blockData[ib][jb].data['pos.x'][i, j, k]) y.append(blockData[ib][jb].data['pos.y'][i, j, k]) p.append(blockData[ib][jb].data['p'][i, j, k]) return locate_shock_along_strip(x, y, p)
def calculate_representative_cell_size(dataFolder): """ Calculate the average cell size by loading in the flow solution, and summing up the volume/area of each cell. This method is not very efficient (computationally). """ fileList = glob.glob(dataFolder+"/flow/t0001/*.gz") GridFlowData = [] blk_volume = [] blk_cells = [] for f in fileList: f1 = gzip.open(f,"r") GridFlowData.append(StructuredGridFlow()) GridFlowData[-1].read(f1) blk_volume.append( sum(sum(GridFlowData[-1].data['volume'][:,:,:])) ) blk_cells.append( GridFlowData[-1].ni * GridFlowData[-1].nj ) f1.close() total_volume = sum(blk_volume) total_cells = sum(blk_cells) if dataFolder in ['case00_fine']: print "total_cells=",total_cells print "total_volume=",total_volume h = np.sqrt( total_volume/float(total_cells) ) return h
def locate_shock_front(stageName, nbi, nbj): """ Reads all flow blocks and returns the coordinates of the shock front in lists of coordinates. """ blockData = [] for ib in range(nbi): blockData.append([]) for jb in range(nbj): blkindx = ib*nbj + jb fileName = 'flow/t0005/%s.flow.b%04d.t0005.gz' \ % (stageName, blkindx) fp = gzip.open(fileName, "r") blockData[ib].append(StructuredGridFlow()) blockData[ib][-1].read(fp) fp.close() x_shock = []; y_shock = [] for jb in range(nbj): nj = blockData[0][jb].nj for j in range(nj): x = []; y = []; p = []; for ib in range(nbi): ni = blockData[ib][jb].ni k = 0 # 2D only for i in range(ni): x.append(blockData[ib][jb].data['pos.x'][i,j,k]) y.append(blockData[ib][jb].data['pos.y'][i,j,k]) p.append(blockData[ib][jb].data['p'][i,j,k]) xshock, yshock = locate_shock_along_strip(x, y, p) x_shock.append(xshock) y_shock.append(yshock) return x_shock, y_shock
def locate_shock_front(jobName, tindx, nbi, nbj): """ Reads flow blocks and returns the coordinates of the shock front. Input: jobName: string name used to construct file names tindx: specify the particular solution frame nbi: number of blocks in the i-index direction nbj: number of blocks in the j-index direction It is assumed that the shock front will be located by scanning along the i-index direction, with j being constant for each search. This function taken from the example 2D/sphere-heat-transfer and has been adapted to the 3D simple_ramp case which has the interesting stuff happening in in the x,z-plane. """ blockData = [] for ib in range(nbi): blockData.append([]) for jb in range(nbj): blkindx = ib * nbj + jb fileName = 'flow/t%04d/%s.flow.b%04d.t%04d.gz' % \ (tindx, jobName, blkindx, tindx) fp = gzip.open(fileName, "r") blockData[ib].append(StructuredGridFlow()) blockData[ib][-1].read(fp) fp.close() x_shock = [] z_shock = [] for jb in range(nbj): nj = blockData[0][jb].nj nk = blockData[0][jb].nk for j in range(nj): for k in range(nk): x = [] z = [] p = [] for ib in range(nbi): ni = blockData[ib][jb].ni for i in range(ni): x.append(blockData[ib][jb].data['pos.x'][i, j, k]) z.append(blockData[ib][jb].data['pos.z'][i, j, k]) p.append(blockData[ib][jb].data['p'][i, j, k]) xshock, zshock = locate_shock_along_strip(x, z, p) x_shock.append(xshock) z_shock.append(zshock) return x_shock, z_shock
def locate_shock_front(jobName, tindx, nbi, nbj): """ Reads flow blocks and returns the coordinates of the shock front. Input: jobName: string name used to construct file names tindx: integer index of the target solution nbi: number of blocks in the i-index direction nbj: number of blocks in the j-index direction It is assumed that the shock front will be located by scanning along the i-index direction, with j being constant for each search. This function taken from the example 2D/sphere-heat-transfer and is a bit more general than needed for the cone20 case. """ blockData = [] for ib in range(nbi): blockData.append([]) for jb in range(nbj): blkindx = ib * nbj + jb fileName = 'flow/t%04d/%s.flow.b%04d.t%04d.gz' % \ (tindx, jobName, blkindx, tindx) fp = gzip.open(fileName, "r") blockData[ib].append(StructuredGridFlow()) blockData[ib][-1].read(fp) fp.close() x_shock = [] y_shock = [] for jb in range(nbj): nj = blockData[0][jb].nj for j in range(nj): x = [] y = [] p = [] for ib in range(nbi): ni = blockData[ib][jb].ni k = 0 # 2D only for i in range(ni): x.append(blockData[ib][jb].data['pos.x'][i, j, k]) y.append(blockData[ib][jb].data['pos.y'][i, j, k]) p.append(blockData[ib][jb].data['p'][i, j, k]) xshock, yshock = locate_shock_along_strip(x, y, p) x_shock.append(xshock) y_shock.append(yshock) return x_shock, y_shock
def readFlowData(jobName, numberBlocks): # tindx = '9999' # These days we have to scan job.times file. fp = open(jobName + ".times", "r") lines = fp.readlines() fp.close() tindx = lines[-1].strip().split()[0] # first item off last line in file zeros = "000" flow = [] grid = [] for block in range(numberBlocks): nZeros = 4 - len(str(block)) bindx = zeros[0:nZeros] + str(block) # read blocks fileName = 'flow/t' + tindx + '/' + jobName + '.flow.b' + bindx + '.t' + tindx + '.gz' fp = gzip.open(fileName, "r") flow.append(StructuredGridFlow()) flow[block].read(fp) fp.close() # print "flow data: ni=", flow[block].ni, "nj=", flow[block].nj, "nk=", flow[block].nk # The grid is always at tindx 0. fileName = 'grid/t0000/' + jobName + '.grid.b' + bindx + '.t0000.gz' fp = gzip.open(fileName, "r") grid.append(StructuredGrid()) grid[block].read(fp) fp.close() # print "Block ", block, "grid data: ni=", grid[block].ni, "nj=", grid[block].nj, "nk=", grid[block].nk return flow, grid
#! /usr/bin/env python # \file locate_bow_shock.py # PJ, 08-Nov-2009, updated for Eilmer3 import sys, os, gzip sys.path.append(os.path.expandvars("$HOME/e3bin")) from e3_flow import StructuredGridFlow print "Locate a bow shock by its pressure jump." # Block 0 contains the stagnation point. fileName = 'flow/t9999/cyl.flow.b0000.t9999.gz' fp = gzip.open(fileName, "r") blockData = StructuredGridFlow() blockData.read(fp) fp.close() # Since this is a 3D simulation, the shock is not expected # to be flat in the k-direction (along the cylinder axis). # Sample the shock layer in a few places near the stagnation line. x_sum = 0.0 n_sample = 6 for k in range(n_sample): j = 0 p_trigger = 10000.0 # Pa x_old = blockData.data['pos.x'][0, j, k] p_old = blockData.data['p'][0, j, k] for i in range(blockData.ni): x = blockData.data['pos.x'][i, j, k] p = blockData.data['p'][i, j, k] if p > p_trigger: break
from math import sin, cos, tan, atan, pi, sqrt print "\n\ncaculate the average temperature and velocity." fileName = 'grid/t0000/tc_flow_nitrogen.grid.b0000.t0000.gz' print "Read grid file:", fileName fin = GzipFile(fileName, "rb") grd = StructuredGrid() grd.read(f=fin) fin.close() print "Read grid: ni=", grd.ni, "nj=", grd.nj, "nk=", grd.nk fileName = 'flow/t0036/tc_flow_nitrogen.flow.b0000.t0036.gz' print "Read solution file:", fileName fin = GzipFile(fileName, "rb") soln = StructuredGridFlow() soln.read(fin) fin.close() ni = soln.ni nj = soln.nj nk = soln.nk print "Read solution: ni=", ni, "nj=", nj, "nk=", nk # Caculate the averaged velocity and temperature along the radial gap # South surface of block 0 fileName = "average.txt" fout = open(fileName, "w") j = 0 v_tan = 0.0 vel_tan = 0.0 T_tan = 0.0
# We'll access the blocks using [i][j] indexing, with i progressing # in the downstream direction. nib = 3 njb = 2 bindx_list = [[0, 1], [2, 3], [4, 5]] flow = [] grd = [] for ib in range(nib): flow.append([]) grd.append([]) for jb in range(njb): bindx = '%04d' % bindx_list[ib][jb] print "bindx=", bindx fileName = 'flow/t' + tindx + '/' + jobName + '.flow.b' + bindx + '.t' + tindx + '.gz' fp = gzip.open(fileName, "r") f = StructuredGridFlow() flow[-1].append(f) f.read(fp) fp.close() print "flow data: ni,nj,nk=", f.ni, f.nj, f.nk # The grid is always at tindx 0. fileName = 'grid/t0000/' + jobName + '.grid.b' + bindx + '.t0000.gz' fp = gzip.open(fileName, "r") g = StructuredGrid() grd[-1].append(g) g.read(fp) fp.close() print "grid data: ni,nj,nk=", g.ni, g.nj, g.nk # Work down the duct (i-direction) and compute fraction of area where gas is not
def main(): """ """ #op = optparse.OptionParser(version=VERSION_STRING) # #op.add_option('--FileToRead',dest='inputFile',default='None', # help="") #op.add_option('--nnj',dest='nnj',default=100.0, # help="") #op.add_option('--FileToWrite',dest='outputFile',default='None', # help="") #opt, args = op.parse_args() test_section_data = True if test_section_data is False: outputFile = "nozzle.data" elif test_section_data is True: outputFile = "test-section-slice.data" # Read in the data fileList = glob.glob("./flow/t9999/*.gz") GridFlowData = [] for f in fileList: f1 = gzip.open(f, "r") GridFlowData.append(StructuredGridFlow()) GridFlowData[-1].read(f1) GridFlowData[-1].add_aux_variables(cmdLineDict={'--add-pitot-p':1,\ '--add-mach':1,'--add-total-p':1,'--add-total-enthalpy':1}) f1.close() variable_list = GridFlowData[0].vars variable_list.append('log10-p') # We calculate this later #variable_list = ['pos.x','pos.y','M_local'] # Write out the header line fout = open(outputFile, 'w') fout.write( '# This file generated by "nenzfr_format_flow_data_for_gnuplot_contour.py"\n#\n' ) fout.write('# Variables: ') count = 0 for var in variable_list: count += 1 fout.write('{0:d}:{1:} '.format(count, var)) fout.write('\n') # Number of blocks in radial direction nbj = 4 # Total number of blocks if test_section_data is False: nb = int(len(fileList)) r = range(nbj) elif test_section_data is True: # For the test-section simulation, modify as required. # This number should be the total number of blocks in the # INNER portion of the test section. The OUTER portion is # treated separately later nb = 68 r = range(nbj, nbj + nbj) #print GridFlowData[0].ni #print GridFlowData[0].nj # Write out the data with strips of j=const. separated # by a blank line #for bj in range(nbj): #for bj in range(nbj,nbj+nbj): # For test-section for bj in r: print "bj=", bj for j in range(GridFlowData[bj].nj): for b in range(bj, nb, nbj): # Row of blocks if j == 0: print "b=", b for i in range(GridFlowData[b].ni): for var in variable_list: # Each variable if var in [ 'log10-p', ]: fout.write( '{0:.6e} '.format(\ math.log10( float(GridFlowData[b].data['p'][i,j,0]) ))) else: #print "bj=",bj #print "j=",j #print "bi=",bi #print "i=",i #print "var=",var #print GridFlowData[bi].data[var][i,j,0] #break fout.write( '{0:.6e} '.format(\ float(GridFlowData[b].data[var][i,j,0])) ) fout.write('\n') fout.write('\n') if test_section_data is True: # For test-section simulation we write out the outer portion of # the test-section last (separately to above loop) start = nb nb = 84 for bj in [ start, ]: print "bj=", bj for j in range(GridFlowData[bj].nj): for b in range(bj, nb): # Row of blocks if j == 0: print "b=", b for i in range(GridFlowData[b].ni): for var in variable_list: # Each variable if var in [ 'log10-p', ]: fout.write( '{0:.6e} '.format(\ math.log10( float(GridFlowData[b].data['p'][i,j,0]) ))) else: fout.write( '{0:.6e} '.format(\ float(GridFlowData[b].data[var][i,j,0])) ) fout.write('\n') fout.write('\n') fout.close()
def writeZone(fileValue, zoneName, blocks, boundaryConditions, blockConnections): tindx = '9999' flow = [] grid = [] for block_index in range(len(blocks)): block = blocks[block_index] bindx = '000' + str(block) # read blocks fileName = 'flow/t' + tindx + '/' + jobName + '.flow.b' + bindx + '.t' + tindx + '.gz' fp = gzip.open(fileName, "r") flow.append(StructuredGridFlow()) flow[block_index].read(fp) fp.close() print "flow data: ni=", flow[block_index].ni, "nj=", flow[ block_index].nj, "nk=", flow[block_index].nk # The grid is always at tindx 0. fileName = 'grid/t0000/' + jobName + '.grid.b' + bindx + '.t0000.gz' fp = gzip.open(fileName, "r") grid.append(StructuredGrid()) grid[block_index].read(fp) fp.close() print "Block ", block, "grid data: ni=", grid[ block_index].ni, "nj=", grid[block_index].nj, "nk=", grid[ block_index].nk numberCells = 0 numberStructuredPoints = 0 startBlockVertex = [] startBlockCell = [] for block_index in range(len(blocks)): startBlockVertex.append(numberStructuredPoints) startBlockCell.append(numberCells) numberCells = numberCells + flow[block_index].ni * flow[ block_index].nj * flow[block_index].nk numberStructuredPoints = numberStructuredPoints + grid[ block_index].ni * grid[block_index].nj * grid[block_index].nk print "Number Cells: ", numberCells print "Number Structured Vertices: ", numberStructuredPoints # copy co-ordinates to lists structured_x = [] structured_y = [] structured_z = [] for block_index in range(len(blocks)): for k in range(grid[block_index].nk): for j in range(grid[block_index].nj): for i in range(grid[block_index].ni): structured_x.append(grid[block_index].x[i, j, k]) structured_y.append(grid[block_index].y[i, j, k]) structured_z.append(grid[block_index].z[i, j, k]) # Hard wire block connections should be ready in" #create Unstructured Vertex Map #print blockConnections vertexMap = range(numberStructuredPoints) for join in range(blockConnections['numberConnections']): block_left = blockConnections['block_left'][join] block_left_index = blocks.index(block_left) block_right = blockConnections['block_right'][join] block_right_index = blocks.index(block_right) face_left = blockConnections['face_left'][join] face_right = blockConnections['face_right'][join] numberJoinVertices_left = getNumberVerticesAtFace( grid[block_left_index], face_left) numberJoinVertices_right = getNumberVerticesAtFace( grid[block_right_index], face_right) try: (numberJoinVertices_left == numberJoinVertices_right) except: print "Error" else: print "Join : ", join, " ", numberJoinVertices_left, numberJoinVertices_right n_i_l = grid[block_left_index].ni n_ij_l = n_i_l * grid[block_left_index].nj n_i_r = grid[block_right_index].ni n_ij_r = n_i_r * grid[block_right_index].nj for i in range(numberJoinVertices_left): i_l, j_l, k_l = getConnVerts(grid[block_left_index], face_left, i) i_r, j_r, k_r = getConnVerts(grid[block_right_index], face_right, i) vert_l = startBlockVertex[ block_left_index] + k_l * n_ij_l + j_l * n_i_l + i_l vert_r = startBlockVertex[ block_right_index] + k_r * n_ij_r + j_r * n_i_r + i_r # print "Map vert ", vert_l, " to ", vert_r vertexMap[vert_l] = vert_r #create list of unstructuredPoints and remove multiple references in vertMap #vertexMap = createVertexMap(structured_x, structured_y, structured_z) unstructuredPoints = [] for i in range(len(vertexMap)): if (vertexMap[i] == i): unstructuredPoints.append(i) else: x1 = 0 refPoint = vertexMap[i] # print "Ref", i, refPoint, vertexMap[refPoint] while (refPoint != vertexMap[refPoint]): refPoint = vertexMap[refPoint] # print "double ref", x1, refPoint try: (x1 < 8) except: print "Error nest too deep" vertexMap[i] = refPoint numberUnstructuredPoints = len(unstructuredPoints) print "Number Unstructured VerticesCells: ", numberUnstructuredPoints # create inverse Map inverseMap = range(numberStructuredPoints) for i in range(numberUnstructuredPoints): inverseMap[unstructuredPoints[i]] = i for i in range(numberStructuredPoints): if (i != vertexMap[i]): inverseMap[i] = inverseMap[vertexMap[i]] #create zone zoneArrayp = CGNS.intArray(3) #vertex size zoneArrayp[0] = numberUnstructuredPoints zoneArrayp[1] = numberCells zoneArrayp[2] = 0 zonePointer = CGNS.intp() ier = CGNS.cg_zone_write(fileValue, bValue, zoneName, zoneArrayp, CGNS.Unstructured, zonePointer) checkCGNSerror(ier) zoneValue = zonePointer.value() #write co-ordinates CoordX = CGNS.doubleArray(numberUnstructuredPoints) CoordY = CGNS.doubleArray(numberUnstructuredPoints) CoordZ = CGNS.doubleArray(numberUnstructuredPoints) for i in range(numberUnstructuredPoints): CoordX[i] = structured_x[unstructuredPoints[i]] CoordY[i] = structured_y[unstructuredPoints[i]] CoordZ[i] = structured_z[unstructuredPoints[i]] coordPointer = CGNS.intp() ier = CGNS.cg_coord_write(fileValue, bValue, zoneValue, CGNS.RealDouble, "CoordinateX", CoordX, coordPointer) checkCGNSerror(ier) ier = CGNS.cg_coord_write(fileValue, bValue, zoneValue, CGNS.RealDouble, "CoordinateY", CoordY, coordPointer) checkCGNSerror(ier) ier = CGNS.cg_coord_write(fileValue, bValue, zoneValue, CGNS.RealDouble, "CoordinateZ", CoordZ, coordPointer) checkCGNSerror(ier) #write cell connections Elements = CGNS.intArray(numberCells * 8) x1 = 0 for block_index in range(len(blocks)): n_i = grid[block_index].ni n_ij = n_i * grid[block_index].nj for k in range(flow[block_index].nk): for j in range(flow[block_index].nj): for i in range(flow[block_index].ni): structPoint = startBlockVertex[ block_index] + k * n_ij + j * n_i + i unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[ block_index] + k * n_ij + j * n_i + i + 1 unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + k * n_ij + ( j + 1) * n_i + i + 1 unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + k * n_ij + ( j + 1) * n_i + i unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + ( k + 1) * n_ij + j * n_i + i unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + ( k + 1) * n_ij + j * n_i + i + 1 unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + ( k + 1) * n_ij + (j + 1) * n_i + i + 1 unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 structPoint = startBlockVertex[block_index] + ( k + 1) * n_ij + (j + 1) * n_i + i unstrPoint = inverseMap[structPoint] Elements[x1] = unstrPoint + 1 x1 = x1 + 1 sectionPointer = CGNS.intp() ier = CGNS.cg_section_write(fileValue, bValue, zoneValue, "Cells", CGNS.HEXA_8, 1, numberCells, 0, Elements, sectionPointer) checkCGNSerror(ier) # write solution solnPointer = CGNS.intp() ier = CGNS.cg_sol_write(fileValue, bValue, zoneValue, "FlowSolution", CGNS.CellCenter, solnPointer) checkCGNSerror(ier) solnValue = solnPointer.value() density = CGNS.doubleArray(numberCells) velx = CGNS.doubleArray(numberCells) vely = CGNS.doubleArray(numberCells) velz = CGNS.doubleArray(numberCells) pressure = CGNS.doubleArray(numberCells) x1 = 0 for block_index in range(len(blocks)): n_i = grid[block_index].ni n_ij = n_i * grid[block_index].nj for k in range(flow[block_index].nk): for j in range(flow[block_index].nj): for i in range(flow[block_index].ni): density[x1] = flow[block_index].data['rho'][i, j, k] velx[x1] = flow[block_index].data['vel.x'][i, j, k] vely[x1] = flow[block_index].data['vel.y'][i, j, k] velz[x1] = flow[block_index].data['vel.z'][i, j, k] pressure[x1] = flow[block_index].data['p'][i, j, k] x1 = x1 + 1 fieldPointer = CGNS.intp() ier = CGNS.cg_field_write(fileValue, bValue, zoneValue, solnValue, CGNS.RealDouble, "Density", density, fieldPointer) ier = CGNS.cg_field_write(fileValue, bValue, zoneValue, solnValue, CGNS.RealDouble, "VelocityX", velx, fieldPointer) ier = CGNS.cg_field_write(fileValue, bValue, zoneValue, solnValue, CGNS.RealDouble, "VelocityY", vely, fieldPointer) ier = CGNS.cg_field_write(fileValue, bValue, zoneValue, solnValue, CGNS.RealDouble, "VelocityZ", velz, fieldPointer) ier = CGNS.cg_field_write(fileValue, bValue, zoneValue, solnValue, CGNS.RealDouble, "Pressure", pressure, fieldPointer) #write boundary conditions to CGNS file element_index = numberCells for bnd in range(boundaryConditions['numberBoundaries']): block = boundaryConditions['block'][bnd] block_index = blocks.index(block) face = boundaryConditions['face'][bnd] bndName = boundaryConditions['name'][bnd] ilo, ihi, jlo, jhi, klo, khi = getFaceRanges(grid[block_index], face) i_size = abs(ihi - ilo) # cells not vertices j_size = abs(jhi - jlo) # cells not vertices k_size = abs(khi - klo) # cells not vertices i_sign = determineSign(ilo, ihi) j_sign = determineSign(jlo, jhi) k_sign = determineSign(klo, khi) n_i = grid[block_index].ni n_ij = n_i * grid[block_index].nj if (face == "west" or face == "east"): numberCellsAtBoundary = j_size * k_size numberPointsAtBoundary = (j_size + 1) * (k_size + 1) elif (face == "bottom" or face == "top"): numberCellsAtBoundary = i_size * j_size numberPointsAtBoundary = (i_size + 1) * (j_size + 1) elif (face == "north" or face == "south"): numberCellsAtBoundary = i_size * k_size numberPointsAtBoundary = (i_size + 1) * (k_size + 1) parentData = CGNS.intArray(numberCellsAtBoundary * 4) array_index = 0 parentIndex = 0 if (face == "west" or face == "east"): i_b = ilo for k in range(k_size): for j in range(j_size): j_b = jlo + j * j_sign k_b = klo + k * k_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[block_index] + ( k_b + 1) * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[block_index] + ( k_b + 1) * n_ij + (j_b + 1) * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[ block_index] + k_b * n_ij + (j_b + 1) * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 parentData[ parentIndex] = startBlockCell[block_index] + k_b * ( n_ij - 1) + j_b * (n_i - 1) + i_b + 1 parentData[numberCellsAtBoundary + parentIndex] = 0 if (face == "west"): parentData[2 * numberCellsAtBoundary + parentIndex] = 1 else: parentData[2 * numberCellsAtBoundary + parentIndex] = 2 parentData[3 * numberCellsAtBoundary + parentIndex] = 0 parentIndex = parentIndex + 1 elif (face == "bottom" or face == "top"): k_b = klo for j in range(j_size): for i in range(i_size): i_b = ilo + i * i_sign j_b = jlo + j * j_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[ block_index] + k_b * n_ij + (j_b + 1) * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[ block_index] + k_b * n_ij + (j_b + 1) * n_i + (i_b + 1) unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + (i_b + 1) unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 elif (face == "north" or face == "south"): j_b = jlo for k in range(k_size): for i in range(i_size): i_b = ilo + i * i_sign k_b = klo + k * k_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b + 1 unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[block_index] + ( k_b + 1) * n_ij + j_b * n_i + (i_b + 1) unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 structPoint = startBlockVertex[block_index] + ( k_b + 1) * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] Elements[array_index] = unstrPoint + 1 array_index = array_index + 1 start = element_index + 1 end = start + numberCellsAtBoundary - 1 element_index = end ier = CGNS.cg_section_write(fileValue, bValue, zoneValue, bndName, CGNS.QUAD_4, start, end, 0, Elements, sectionPointer) checkCGNSerror(ier) # sectionValue = sectionPointer.value() for i in range(numberCellsAtBoundary): Elements[4 * i] = start + i # CGNS.cg_parent_data_write(fileValue, bValue, zoneValue, sectionValue, parentData) parentData.__del__ # write boundary condition boundaryPoints = CGNS.intArray(numberPointsAtBoundary) if (face == "west" or face == "east"): array_index = 0 i_b = ilo for k in range(k_size + 1): for j in range(j_size + 1): j_b = jlo + j * j_sign k_b = klo + k * k_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] boundaryPoints[array_index] = unstrPoint + 1 # print arrayIndex, j_b, k_b, structPoint, unstrPoint array_index = array_index + 1 elif (face == "bottom" or face == "top"): array_index = 0 k_b = klo for j in range(j_size + 1): for i in range(i_size + 1): j_b = jlo + j * j_sign i_b = ilo + i * i_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] boundaryPoints[array_index] = unstrPoint + 1 # print arrayIndex, j_b, k_b, structPoint, unstrPoint array_index = array_index + 1 elif (face == "north" or face == "south"): array_index = 0 j_b = jlo for k in range(k_size + 1): for i in range(i_size + 1): k_b = klo + k * k_sign i_b = ilo + i * i_sign structPoint = startBlockVertex[ block_index] + k_b * n_ij + j_b * n_i + i_b unstrPoint = inverseMap[structPoint] boundaryPoints[array_index] = unstrPoint + 1 # print arrayIndex, j_b, k_b, structPoint, unstrPoint array_index = array_index + 1 boundaryPointer = CGNS.intp() bocotype = getCGNSboundaryType(bndName) ier = CGNS.cg_boco_write(fileValue, bValue, zoneValue, bndName, bocotype, CGNS.PointList, numberPointsAtBoundary, boundaryPoints, boundaryPointer) checkCGNSerror(ier) print "Boundary", bnd, bndName, "block", block, "cells", numberCellsAtBoundary