def create_grid_from_grid_files(program_data): grid_file = program_data["grid_desc"]["read_grid"] time_steps = program_data["time_steps"] sgf = SpartaGridFile(grid_file) merge_points = create_merge_points(program_data) unstructured_grid = vtk.vtkUnstructuredGrid() unstructured_grid.SetPoints(merge_points.GetPoints()) init_flow_file_arrays(unstructured_grid, program_data) global_ids = {} count = 1 if is_rank_zero(): print("Started sorted grid file read") print("Creating grid") with open(get_bucket_file_name(get_rank(), program_data), 'r') as f: for cell_id in f: cell_id = cell_id.strip() cell = create_grid_cell(cell_id, sgf, program_data, merge_points) unstructured_grid.InsertNextCell(cell.GetCellType(), cell.GetPointIds()) if time_steps: lcid = sgf.get_local_cell_id_from_dashed_cell_id(cell_id) global_ids[lcid] = count - 1 insert_value_in_flow_file_arrays(0.0, unstructured_grid) if is_rank_zero() and count % 10000 == 0: print("Read " + str(count) + " cells") count += 1 if is_rank_zero(): print("Finished sorted grid file read") print("Finished creating grid") return (unstructured_grid, global_ids)
def _calc_origin_and_lengths(self, dashed_id, sparta_grid_file, program_data): top_level_box = program_data['grid_desc']['create_box'] box = {} box["xlo"] = top_level_box['xlo'] box["ylo"] = top_level_box['ylo'] box["zlo"] = top_level_box['zlo'] box["xhi"] = top_level_box['xhi'] box["yhi"] = top_level_box['yhi'] box["zhi"] = top_level_box['zhi'] dimension = program_data['grid_desc']["dimension"] cells = SpartaGridFile.get_cells_in_dashed_id(dashed_id) cells.reverse() for idx, cell in enumerate(cells): lvl_dims = sparta_grid_file.get_level_dimensions(idx + 1) spacing = self._get_level_spacing(box, lvl_dims) location = self._get_location_of_cell_id(cell, lvl_dims, dimension) box["xlo"] += location[0] * spacing[0] box["ylo"] += location[1] * spacing[1] box["zlo"] += location[2] * spacing[2] box["xhi"] = box["xlo"] + spacing[0] box["yhi"] = box["ylo"] + spacing[1] box["zhi"] = box["zlo"] + spacing[2] self.__origin_x = box["xlo"] self.__origin_y = box["ylo"] self.__origin_z = box["zlo"] self.__length_x = spacing[0] self.__length_y = spacing[1] self.__length_z = spacing[2] if dimension == 2: self.__origin_z = 0.0 self.__length_z = 0.0
def check_grid_file(args): error_flag = False if is_rank_zero(): try: sgf = SpartaGridFile(args.sparta_grid_file_path) except: error_flag = True if error_found_on_rank_zero(error_flag): sys.exit(1)
def create_grid_description(args): error_flag = False grid_desc = None if is_rank_zero(): grid_desc = {} gdf = open(args.sparta_grid_description_file, "r") read_grid_description_file(gdf, grid_desc) gdf.close() if "dimension" not in grid_desc: print( "Error: grid description file does not have a dimension statement: ", args.sparta_grid_description_file) error_flag = True if "create_box" not in grid_desc: print( "Error: grid description file does not have a create_box statement: ", args.sparta_grid_description_file) error_flag = True if "read_grid" not in grid_desc: print( "Error: grid description file does not have a read_grid statement: ", args.sparta_grid_description_file) error_flag = True if os.path.isfile(args.paraview_output_file + '.pvd'): print("ParaView output file exists: ", args.paraview_output_file + '.pvd') error_flag = True try: sgf = SpartaGridFile(grid_desc["read_grid"]) except: error_flag = True if error_found_on_rank_zero(error_flag): sys.exit(1) if is_rank_zero(): print("Processing " + str(sgf.number_of_cells) +\ " cell(s) on " + str(get_size()) + " MPI rank(s)") os.mkdir(args.paraview_output_file) return grid_desc
def get_grid_file_cells(grid_file_path): sgf = SpartaGridFile(grid_file_path) sgf.set_iteration_start(get_rank()) sgf.set_iteration_skip(get_size()) if is_rank_zero(): print("Reading Sparta grid file " + grid_file_path) cells = [] count = 0 for cell in sgf: cells.append(cell) count += 1 if is_rank_zero() and count % 10000 == 0: print("Read " + str(count) + " cell(s) from grid file") if is_rank_zero(): print("Finished grid file read") return cells
def loadDataFromGridFile(self, grid_file): sgf = SpartaGridFile(grid_file) sgf.set_iteration_start(get_rank()) sgf.set_iteration_skip(get_size()) return [line for line in sgf]
def testSpartaCircleGridFile(self): cgf = SpartaGridFile(CIRCLE_GRID_FILE) self.checkDashedIdConversion(cgf)
def testSpartaGridFile200(self): sgf = SpartaGridFile(GRID_FILE_200) self.checkDashedIdConversion(sgf)
def readGridFileWithSkip(self, grid_file, start, skip): sgf = SpartaGridFile(grid_file) sgf.set_iteration_start(start) sgf.set_iteration_skip(skip) return [line for line in sgf]