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
def SplitVtuFilename(filename): """ Split the supplied vtu filename into project, ID and file extension """ first = filehandling.StripFileExtension(filename) ext = filehandling.FileExtension(filename) split = first.split("_") + [ext] idIndex = None for i, val in enumerate(split[1:]): if utils.IsIntString(val): idIndex = i + 1 break assert (not idIndex is None) project = utils.FormLine(split[:idIndex], delimiter="_", newline=False) id = int(split[idIndex]) ext = utils.FormLine([""] + split[idIndex + 1:len(split) - 1], delimiter="_", newline=False) + split[-1] return project, id, ext