[vtkusers] segfault when writing large unstructured grid
Jeff Becker
jeffrey.c.becker at nasa.gov
Fri May 15 14:07:43 EDT 2015
Hi. I wrote a small python script to read data from a binary file, and
write it out to vtu format for viewing in ParaView. I include it below
for reference. The final write command only completes partially before
getting a segfault. The resulting file has proper xml at the front:
$ head -6 /nobackup/jcbecker/steinBmag.vtu
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian"
compressor="vtkZLibDataCompressor">
<UnstructuredGrid>
<Piece NumberOfPoints="127008000" NumberOfCells="127008000">
<PointData Scalars="B field magnitude">
<DataArray type="Float32" Name="B field magnitude"
format="binary" RangeMin="7.4172352704e-09" RangeMax="63.110340118">
but the file is truncated - when I try to load in ParaView I get:
ERROR: In
/home/kitware/Dashboards/MyTests/NightlyMaster/ParaViewSuperbuild-Release/paraview/src/paraview/VTK/IO/XMLParser/vtkXMLParser.cxx,
line 483
vtkXMLDataParser (0x5fcc070): Error parsing XML in stream at line 17,
column 0, byte index 1132817847: no element found
The file size as written is given here:
$ ls -l /nobackup/jcbecker/steinBmag.vtu
-rw------- 1 jcbecker css 1132817847 May 14 17:03
/nobackup/jcbecker/steinBmag.vtu
I'm new to vtk, so I might not have set up the script below correctly.
Can anyone see why the write command would seg. fault? Also, please
don't hesitate to suggest any other improvements. Thanks.
-jeff
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
import os
import numpy as np
import steinmesh as mesh
import itertools
import vtk
from vtk.util import numpy_support
in_fname='/nobackupp9/pmoran/stein/mhd48-1/dat/mhd48h1new_670.8.dat'
out_fname='/nobackup/jcbecker/steinBmag.vtu'
f = open(in_fname,"rb")
bx = 6
npoints = mesh.MX*mesh.MY*mesh.MZ
f.seek(bx*npoints*np.dtype('f4').itemsize,os.SEEK_SET)
steinbmag = np.square(np.fromfile(f,dtype=np.dtype('f4'),count=npoints))
steinbmag += np.square(np.fromfile(f,dtype=np.dtype('f4'),count=npoints))
steinbmag += np.square(np.fromfile(f,dtype=np.dtype('f4'),count=npoints))
steinbmag = np.sqrt(steinbmag)
f.close()
print 'done reading file'
grid = [x for x in itertools.product(mesh.xcoords, mesh.ycoords,
mesh.zcoords)]
print 'done generating grid'
pcoords = vtk.vtkDoubleArray()
pcoords.SetNumberOfComponents(3)
pcoords.SetNumberOfTuples(npoints)
pcells = vtk.vtkCellArray()
for i in range(npoints):
pcoords.SetTuple3(*((i,) + grid[i]))
pcells.InsertNextCell(i)
pcells.InsertCellPoint(i)
pts = vtk.vtkPoints()
pts.SetData(pcoords)
print 'done converting to vtk grid'
ugrid = vtk.vtkUnstructuredGrid()
ugrid.Allocate(npoints)
ugrid.SetPoints(pts)
ugrid.SetCells(vtk.VTK_VERTEX,pcells)
bmagV = numpy_support.numpy_to_vtk(steinbmag,deep=True)
bmagV.SetName('B field magnitude')
ugrid.GetPointData().SetScalars(bmagV)
print 'done setting up ugrid'
writer = vtk.vtkXMLUnstructuredGridWriter()
writer.SetFileName(out_fname)
writer.SetInputData(ugrid)
writer.SetDataModeToBinary()
writer.Write()
More information about the vtkusers
mailing list