def readFile(self): self.blockMesh=ParsedBlockMeshDict(self.parser.getArgs()[0]) self.vertices=self.blockMesh.vertices() self.vActors=[None]*len(self.vertices) self.blocks=self.blockMesh.blocks() self.patches=self.blockMesh.patches() self.vRadius=self.blockMesh.typicalLength()/50 for i in range(len(self.vertices)): self.addVertex(i) self.setAxes() self.undefined=[] for i in range(len(self.blocks)): self.addBlock(i) for a in self.blockMesh.arcs(): self.makeArc(a) if len(self.undefined)>0: self.undefinedActor.SetInput("Undefined vertices: "+str(self.undefined)) else: self.undefinedActor.SetInput("")
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
def testRoundtripBlockMesh(self): blk = ParsedBlockMeshDict(SolutionDirectory(self.dest).blockMesh()) txt = str(blk) try: i = int(txt.split("blocks")[1].split("(")[0]) self.assertTrue(False) except ValueError: pass
def testBoundaryRead(self): blk = ParsedBlockMeshDict(SolutionDirectory(self.dest).blockMesh()) self.assertEqual(blk.convertToMeters(), 1.) self.assertEqual(len(blk.vertices()), 22) self.assertEqual(len(blk.blocks()), 5) self.assertEqual(len(blk.patches()), 6) self.assertEqual(len(blk.arcs()), 8) self.assertEqual(blk.typicalLength(), 1.25) self.assertEqual(str(blk.getBounds()), "([0.0, 0.0, 0.0], [2.0, 2.0, 0.5])")
def __init__(self, name, extensionType, frontvalue=0, backvalue=0, ncells=1, backup=False): """:param name: The name of the parameter file :param backup: create a backup-copy of the file """ FileBasisBackup.__init__(self,name,backup=backup) self.parsedBlockMesh=ParsedBlockMeshDict(name) self.vertexNum=len(self.parsedBlockMesh["vertices"]) self.extensionType=extensionType self.frontvalue=frontvalue self.backvalue=backvalue self.ncells=ncells self.minBound=self.getBounds()
import sys from PyFoam.RunDictionary.ParsedBlockMeshDict import ParsedBlockMeshDict bm=ParsedBlockMeshDict(sys.argv[1]) print "Vertices: " print bm.vertices() print "Blocks: " print bm.blocks() print "Patches:" print bm.patches() print "Arcs:" print bm.arcs() print "Min/Max",bm.getBounds() print "Typical Length: ",bm.typicalLength() print bm["edges"]