Example #1
0
 def testLowerDimVtuToMesh(self):
   vtu = vtktools.vtu()    
   points = vtk.vtkPoints()
   points.SetDataTypeToDouble()
   points.InsertNextPoint(0.0, 0.0, 0.0)
   points.InsertNextPoint(0.0, 0.0, 1.0)
   vtu.ugrid.SetPoints(points)
   mesh = VtuToMesh(vtu)
   self.assertEquals(mesh.GetDim(), 1)
   self.assertEquals(mesh.NodeCount(), 2)
   self.assertEquals(mesh.GetNodeCoord(0)[0], 0.0)
   self.assertEquals(mesh.GetNodeCoord(1)[0], 1.0)
   
   return
Example #2
0
 def testLowerDimVtuToMesh(self):
   vtu = vtktools.vtu()    
   points = vtk.vtkPoints()
   points.SetDataTypeToDouble()
   points.InsertNextPoint(0.0, 0.0, 0.0)
   points.InsertNextPoint(0.0, 0.0, 1.0)
   vtu.ugrid.SetPoints(points)
   mesh = VtuToMesh(vtu)
   self.assertEquals(mesh.GetDim(), 1)
   self.assertEquals(mesh.NodeCount(), 2)
   self.assertEquals(mesh.GetNodeCoord(0)[0], 0.0)
   self.assertEquals(mesh.GetNodeCoord(1)[0], 1.0)
   
   return
Example #3
0
basename = sys.argv[1]
debug.dprint("vtu basename: " + basename)
nPieces = fluiditytools.FindMaxVtuId(basename) + 1
debug.dprint("Number of pieces: " + str(nPieces))

# Write to a temporary directory so that the first piece isn't overwritten
tempDir = tempfile.mkdtemp()

# Create the parallel writer
writer = vtk.vtkXMLPUnstructuredGridWriter()
writer.SetNumberOfPieces(nPieces)
writer.WriteSummaryFileOn()
pvtuName = basename + ".pvtu"
writer.SetFileName(os.path.join(tempDir, pvtuName))

# Load in the first piece, so that the parallel writer has something to do (and
# knows which fields we have)
pieceName = fluiditytools.VtuFilenames(basename, 0)[0]
pieceVtu = vtktools.vtu(pieceName)
if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
    writer.SetInput(0, pieceVtu.ugrid)
else:
    writer.SetInputData(0, pieceVtu.ugrid)

# Write
writer.Write()

# Move the output back and clean up
filehandling.Move(os.path.join(tempDir, pvtuName), pvtuName)
filehandling.Rmdir(tempDir, force=True)
Example #4
0
basename = sys.argv[1]
debug.dprint("vtu basename: " + basename)
nPieces = fluiditytools.FindMaxVtuId(basename) + 1
debug.dprint("Number of pieces: " + str(nPieces))

# Write to a temporary directory so that the first piece isn't overwritten
tempDir = tempfile.mkdtemp()

# Create the parallel writer
writer = vtk.vtkXMLPUnstructuredGridWriter()
writer.SetNumberOfPieces(nPieces)
writer.WriteSummaryFileOn()
pvtuName = basename + ".pvtu"
writer.SetFileName(os.path.join(tempDir, pvtuName))

# Load in the first piece, so that the parallel writer has something to do (and
# knows which fields we have)
pieceName = fluiditytools.VtuFilenames(basename, 0)[0]
pieceVtu = vtktools.vtu(pieceName)
if vtk.vtkVersion.GetVTKMajorVersion() <= 5:
  writer.SetInput(0, pieceVtu.ugrid)
else:
  writer.SetInputData(0, pieceVtu.ugrid)

# Write
writer.Write()

# Move the output back and clean up
filehandling.Move(os.path.join(tempDir, pvtuName), pvtuName)
filehandling.Rmdir(tempDir, force = True)
Example #5
0
if len(args) > 3:
  debug.FatalError("Unrecognised trailing argument")
inputProject = args[0]

if len(args) == 2:
  try:
    firstId = int(args[1])
    lastId = firstId
  except ValueError:
    debug.FatalError("Invalid first dump ID")

if len(args) == 3:
  try:
    firstId = int(args[1])
    lastId = int(args[2])
    assert(lastId >= firstId)
  except:
    debug.FatalError("Invalid last dump ID")
 
if len(args) == 1:
  filenames = [inputProject + ".pvtu"]
else:
  filenames = fluidity_tools.VtuFilenames(inputProject, firstId, lastId = lastId, extension = ".pvtu")

for filename in filenames:
  debug.dprint("Processing file: " + filename)

  vtu = vtktools.vtu(filename)
  vtu = vtktools.VtuFromPvtu(vtu)
  vtu.Write(filename[:-5] + ".vtu")
Example #6
0
if len(args) < 2:
    debug.FatalError("GMSH 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 + "_?*.msh")
meshBasenames = []
meshIds = []
for possibleMeshBasename in possibleMeshBasenames:
    id = possibleMeshBasename[len(meshBasename) + 1:-4]
    try:
        id = int(id)
    except ValueError:
        continue

    meshBasenames.append(possibleMeshBasename[:-4])
    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 = gmshtools.ReadMsh(meshBasename).ToVtu(includeSurface=False)
    partition = vtktools.RemappedVtu(vtu, meshVtu)
    partition.Write(vtuBasename + "_" + str(meshIds[i]) + "." + vtuExt)
Example #7
0
 def ToVtu(self, includeSurface = True, includeVolume = True, idsName = "IDs"):
   dim = self.GetDim()
   assert(dim <= 3)
 
   ugrid = vtk.vtkUnstructuredGrid()
   
   # Add the points
   points = vtk.vtkPoints()
   points.SetDataTypeToDouble()
   for nodeCoord in self.GetNodeCoords():
     x = 0.0
     y = 0.0
     z = 0.0
     if dim > 0:
       x = nodeCoord[0]
     if dim > 1:
       y = nodeCoord[1]
     if dim > 2:
       z = nodeCoord[2]
     points.InsertNextPoint(x, y, z)
   ugrid.SetPoints(points)
   
   if includeSurface or includeVolume:
     cellData = vtk.vtkDoubleArray()
     cellData.SetNumberOfComponents(1)
     cellData.SetName(idsName)
     
     if includeSurface:
       # Add the surface elements
       for element in self.GetSurfaceElements():
         idList = vtk.vtkIdList()
         type = vtktools.VtkType(dim = dim - 1, nodeCount = element.NodeCount())
         for node in vtktools.ToVtkNodeOrder(element.GetNodes(), type):
           idList.InsertNextId(node)
         cell = ugrid.InsertNextCell(type.GetVtkTypeId(), idList)
         if len(element.GetIds()) > 0:
           # Add just the first ID
           cellData.InsertTuple1(cell, element.GetIds()[0])
         else:
           cellData.InsertTuple1(cell, 0.0)
     
     if includeVolume:
       # Add the volume elements
       for element in self.GetVolumeElements():
         idList = vtk.vtkIdList()
         type = vtktools.VtkType(dim = dim, nodeCount = element.NodeCount())
         for node in vtktools.ToVtkNodeOrder(element.GetNodes(), type):
           idList.InsertNextId(node)
         cellId = ugrid.InsertNextCell(type.GetVtkTypeId(), idList)
         if len(element.GetIds()) > 0:
           # Add just the first ID
           cellData.InsertTuple1(cellId, element.GetIds()[0])
         else:
           cellData.InsertTuple1(cellId, 0.0)
     
     # Add the boundary and/or region IDs
     ugrid.GetCellData().AddArray(cellData)
   
   # Construct the vtu
   vtu = vtktools.vtu()
   vtu.ugrid = ugrid
   
   return vtu
Example #8
0
if len(args) < 2:
  debug.FatalError("GMSH 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 + "_?*.msh")
meshBasenames = []
meshIds = []
for possibleMeshBasename in possibleMeshBasenames:
  id = possibleMeshBasename[len(meshBasename) + 1:-4]
  try:
    id = int(id)
  except ValueError:
    continue
    
  meshBasenames.append(possibleMeshBasename[:-4])
  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 = gmshtools.ReadMsh(meshBasename).ToVtu(includeSurface = False)
  partition = vtktools.RemappedVtu(vtu, meshVtu)
  partition.Write(vtuBasename + "_" + str(meshIds[i]) + "." + vtuExt)
Example #9
0
 def ToVtu(self, includeSurface = True, includeVolume = True, idsName = "IDs"):
   dim = self.GetDim()
   assert(dim <= 3)
 
   ugrid = vtk.vtkUnstructuredGrid()
   
   # Add the points
   points = vtk.vtkPoints()
   points.SetDataTypeToDouble()
   for nodeCoord in self.GetNodeCoords():
     x = 0.0
     y = 0.0
     z = 0.0
     if dim > 0:
       x = nodeCoord[0]
     if dim > 1:
       y = nodeCoord[1]
     if dim > 2:
       z = nodeCoord[2]
     points.InsertNextPoint(x, y, z)
   ugrid.SetPoints(points)
   
   if includeSurface or includeVolume:
     cellData = vtk.vtkDoubleArray()
     cellData.SetNumberOfComponents(1)
     cellData.SetName(idsName)
     
     if includeSurface:
       # Add the surface elements
       for element in self.GetSurfaceElements():
         idList = vtk.vtkIdList()
         type = vtktools.VtkType(dim = dim - 1, nodeCount = element.NodeCount())
         for node in vtktools.ToVtkNodeOrder(element.GetNodes(), type):
           idList.InsertNextId(node)
         cell = ugrid.InsertNextCell(type.GetVtkTypeId(), idList)
         if len(element.GetIds()) > 0:
           # Add just the first ID
           cellData.InsertTuple1(cell, element.GetIds()[0])
         else:
           cellData.InsertTuple1(cell, 0.0)
     
     if includeVolume:
       # Add the volume elements
       for element in self.GetVolumeElements():
         idList = vtk.vtkIdList()
         type = vtktools.VtkType(dim = dim, nodeCount = element.NodeCount())
         for node in vtktools.ToVtkNodeOrder(element.GetNodes(), type):
           idList.InsertNextId(node)
         cellId = ugrid.InsertNextCell(type.GetVtkTypeId(), idList)
         if len(element.GetIds()) > 0:
           # Add just the first ID
           cellData.InsertTuple1(cellId, element.GetIds()[0])
         else:
           cellData.InsertTuple1(cellId, 0.0)
     
     # Add the boundary and/or region IDs
     ugrid.GetCellData().AddArray(cellData)
   
   # Construct the vtu
   vtu = vtktools.vtu()
   vtu.ugrid = ugrid
   
   return vtu