def edit_blockMeshDict(dictionary, stl, cellNumber=40, edge_buffer=2): try: tqdm.write("{}: Editing blockMeshDict: {}".format( datetime.datetime.now(), dictionary)) blockMeshDict = ParsedBlockMeshDict(dictionary) vertices = blockMeshDict["vertices"] # load stl surface reader = vtk.vtkSTLReader() reader.SetFileName(stl) reader.Update() bounds = reader.GetOutput().GetBounds() blockMeshDict["xmin"] = bounds[0] - edge_buffer blockMeshDict["xmax"] = bounds[1] + edge_buffer blockMeshDict["ymin"] = bounds[2] - edge_buffer blockMeshDict["ymax"] = bounds[3] + edge_buffer blockMeshDict["zmin"] = bounds[4] - edge_buffer blockMeshDict["zmax"] = bounds[5] + edge_buffer blocks = blockMeshDict["blocks"] blocks[2] = '({} {} {})'.format(cellNumber, cellNumber, cellNumber) blockMeshDict["blocks"] = blocks try: blockMeshDict.writeFile() except IOError: tqdm.write("Can't write file. Content would have been:") tqdm.write(blockMeshDict) return 0 except IOError: tqdm.write(blockMeshDict_file, " does not exist") return 1