def TetrahedralizePoly(polyFilename, commandLineSwitches=[]): """ Tetrahedralise the given poly using TetGen """ assert (filehandling.FileExtension(polyFilename) == ".poly") tempDir = tempfile.mkdtemp() tempFile = os.path.join(tempDir, os.path.basename(polyFilename)) filehandling.Cp(polyFilename, tempFile) command = ["tetgen", "-p"] if debug.GetDebugLevel() > 1: command.append("-V") stdout = None stderr = None else: stdout = subprocess.PIPE stderr = subprocess.PIPE command += commandLineSwitches command.append(tempFile) debug.dprint("Tetrahedralization command: " + utils.FormLine(command, delimiter=" ", newline=False)) proc = subprocess.Popen(command, stdout=stdout, stderr=stderr) proc.wait() assert (proc.returncode == 0) mesh = triangletools.ReadTriangle(tempFile[:-5] + ".1") filehandling.Rmdir(tempDir, force=True) return mesh
for ele in mesh.GetSurfaceElements(): ids = ele.GetIds() # squeezing in two zeros, first is tag is the physical ID, last one is the ElementOwner (ID): ele.SetIds([ids[0], 0, 0, ids[1]]) optparser = OptionParser( usage='usage: %prog <filename>', add_help_option=True, description="""Converts Fluidity-generated Triangle """ + """mesh files and converts them to the Gmsh format.""") optparser.add_option("--ascii", "-a", help="Convert to ASCII Gmsh format", action="store_const", const=True, dest="ascii", default=False) (options, argv) = optparser.parse_args() filename = argv[0] mesh = triangletools.ReadTriangle(filename) hasInternalBoundaries = triangletools.hasPeriodicBoundary(filename) if (hasInternalBoundaries): # squeeze in two additional tags before we start writing out the gmsh file: addAdditionalIds(mesh) # now we can write the gmsh file: gmshtools.WriteMsh(mesh, "%s.msh" % (filename), binary=not options.ascii)
debug.FatalError("Triangle base name and vtu name required") elif len(args) > 2: debug.FatalError("Unrecognised trailing argument") meshBasename = args[0] vtuFilename = args[1] possibleMeshBasenames = glob.glob(meshBasename + "_?*.node") meshBasenames = [] meshIds = [] for possibleMeshBasename in possibleMeshBasenames: id = possibleMeshBasename[len(meshBasename) + 1:-5] try: id = int(id) except ValueError: continue meshBasenames.append(possibleMeshBasename[:-5]) meshIds.append(id) vtuBasename = os.path.basename(vtuFilename[:-len(vtuFilename.split(".")[-1]) - 1]) vtuExt = vtuFilename[-len(vtuFilename.split(".")[-1]):] vtu = vtktools.vtu(vtuFilename) for i, meshBasename in enumerate(meshBasenames): debug.dprint("Processing mesh partition " + meshBasename) meshVtu = triangletools.ReadTriangle(meshBasename).ToVtu( includeSurface=False) partition = vtktools.RemappedVtu(vtu, meshVtu) partition.Write(vtuBasename + "_" + str(meshIds[i]) + "." + vtuExt)