sfepy/sfepy — Issue #48: Mesh.fromFile raises IndexError: list index out of range
Author: rc
Created: 2012-01-30 10:24:47+00:00
State: open

How to reproduce:

$ hg up 2aed0ddfa79e

apply this patch (to make the mesh faster to generate):

$ hg di
diff -r 2aed0ddfa79e convert.py
--- a/convert.py	Thu Jun 26 13:58:01 2008 +0200
+++ b/convert.py	Thu Jun 26 14:03:13 2008 +0200
@@ -24,7 +24,7 @@ def mesh():
g=geom.read_gmsh("tmp/x.geo")
g.printinfo()
geom.write_tetgen(g,"tmp/t.poly")
- geom.runtetgen("tmp/t.poly",a=0.0003,Q=1.0,quadratic=False,
+ geom.runtetgen("tmp/t.poly",a=0.03,Q=1.0,quadratic=False,
tetgenpath = tetgen_path)

m = Mesh.fromFile("tmp/t.1.node")

and do:

$ ./convert.py
matplotlib import failed!
General geometry information:
points: 8
lines: 12
surfaces: 6
volumes: 1
Physical entities:
surfaces (boundary conditions):
volumes (regions):
1: volume numbers [1]
Generating mesh using /usr/bin/tetgen -pQAq1.000000 -a0.030000 tmp/t.poly
sfe: reading mesh (tmp/t.1.node)...
nodes: 100% |############################################| Time:
00:00:00
elements: 100% |#########################################| Time:
00:00:00
sfe: ...done in 0.74 s
$ ipython
Python 2.4.4 (#2, Jan 3 2008, 13:53:47)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from sfe.fem.mesh import Mesh
matplotlib import failed!

In [2]: f = Mesh.fromFile("tmp/t.1.vtk")
sfe: reading mesh (tmp/t.1.vtk)...
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)

/home/ondra/sfepy/<ipython console>

/home/ondra/sfepy/sfe/fem/mesh.py in fromFile(fileName, io)
356 tt = time.clock()
357 mesh = Mesh( trunk )
--> 358 mesh = io.read( mesh )
359 output( '...done in %.2f s' % (time.clock() - tt) )
360 mesh._setShapeInfo()

/home/ondra/sfepy/sfe/fem/meshio.py in read(self, mesh, **kwargs)
335 elif mode == 'points':
336 line = line.split()
--> 337 if line[0] == 'POINTS':
338 nNod = int( line[1] )
339 nod = readArray( fd, nNod, -1, nm.float64 )

IndexError: list index out of range

In [3]:

Migrated from http://code.google.com/p/sfepy/issues/detail?id=44

earlier comments

robert.cimrman said, at 2008-06-26T13:41:30.000Z:

Apart from other bugs, the generated file 'tmp/t.1.vtk' has not cell attribute matId
(= the extra column in .mesh files, see also database/simple.vtk). I will fix the
reader to provide default (0) in such case.

robert.cimrman said, at 2008-06-26T14:47:34.000Z:

should work now...

ondrej.certik said, at 2008-06-26T15:03:01.000Z:

Works like a charm:

In [1]: from sfepy.fem.mesh import Mesh

In [2]: f = Mesh.fromFile("tmp/t.1.vtk")
sfepy: reading mesh (tmp/t.1.vtk)...
sfepy: ...done in 1.26 s

In [3]:

Thanks for fixing this!