← Back to team overview

dolfin team mailing list archive

Re: dolfin/python error

 

Here's a small example of the use of SetVoidArray (a stripped and
slightly modified version of BuildUGrid.py from VTK. It works on my
computer. Hopefully, it will crash at your sides.

Ola

On Wed, Aug 12, 2009 at 9:00 PM, Anders Logg<logg@xxxxxxxxx> wrote:
> On Wed, Aug 12, 2009 at 08:00:07PM +0200, Ola Skavhaug wrote:
>> On Wed, Aug 12, 2009 at 6:13 PM, Anders Logg<logg@xxxxxxxxx> wrote:
>> > It might be something with the call to SetVoidArray in make_vtk_grid
>> > in viper.py. Commenting out the line
>> >
>> >  ita.SetVoidArray(a, len(a), 1)
>> >
>> > it does not crash anymore and I get a plot, but the plot is empty.
>> >
>> > Ola?
>>
>> As long as a is not lost afterwards (i.e. a reference is kept) this
>> should be correct.
>
> The variable a is stored in self.refs so that should be ok, but it
> still crashes...
>
> --
> Anders
>
>
>> Ola
>>
>> >
>> >
>> > On Tue, Aug 11, 2009 at 05:30:18PM -0400, Shawn Walker wrote:
>> >> That fits with the error I got when I tried to run the Stokes demo.
>> >> It plotted the vector velocity with no problem.  But when it tried
>> >> to plot the pressure, it gave me that error.
>> >>
>> >> I've tried googling about the error, but I could not find anything
>> >> definitive.
>> >>
>> >> - Shawn
>> >>
>> >> On Tue, 11 Aug 2009, Anders Logg wrote:
>> >>
>> >> >On Tue, Aug 11, 2009 at 09:26:13PM +0200, Anders Logg wrote:
>> >> >>Yet another update: Same problem with VTK 5.4 and I can use VTK from
>> >> >>Python directly without problem (when not going through Viper).
>> >> >
>> >> >The plot thickens. I can plot vector-valued functions with Viper but
>> >> >not scalars, and not meshes. In particular, I can do
>> >> >
>> >> > plot(grad(u))
>> >> >
>> >> >in the Poisson demo, but not
>> >> >
>> >> > plot(u)
>> >> >
>> >
>> > -----BEGIN PGP SIGNATURE-----
>> > Version: GnuPG v1.4.9 (GNU/Linux)
>> >
>> > iEYEARECAAYFAkqC6iQACgkQTuwUCDsYZdFQSgCfQvcnZKSsCzstxu5mQAcyunBS
>> > /SwAn0VRlNSaIIq6vDuFBZcqcwl1T/Bw
>> > =wpTd
>> > -----END PGP SIGNATURE-----
>> >
>> > _______________________________________________
>> > DOLFIN-dev mailing list
>> > DOLFIN-dev@xxxxxxxxxx
>> > http://www.fenics.org/mailman/listinfo/dolfin-dev
>> >
>> >
>>
>>
>>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkqDEWMACgkQTuwUCDsYZdGVJACfXZmPZzR5O/a/OHJVzHg1jXB8
> 6r0An1pQnEROihp92n801I5r11dWmRoV
> =UssT
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev
>
>



-- 
Ola Skavhaug
#!/usr/bin/env python

# This example shows how to construct unstructured grids
# using Python. 

import vtk
import numpy

# Coordinates as numpy arrays
pts = numpy.array([0,0,0, 1,0,0, .5,1,0, .5,.5,1], dtype='d')
# The cells: length of each cell, and then point numbers (indices in pts)
# Only one cell here
cells = numpy.array([4,0,1,2,3], dtype='i')

# Create several unstructured grids each containing a cell of a
# different type.
pa = vtk.vtkDoubleArray()
pa.SetNumberOfComponents(3)
pa.SetVoidArray(pts, 12, 1)

tetraPoints = vtk.vtkPoints()
tetraPoints.SetNumberOfPoints(4)
tetraPoints.SetData(pa)

cell_array = vtk.vtkIdTypeArray()
cell_array.SetVoidArray(cells, len(cells), 1)
tetraCells = vtk.vtkCellArray()
tetraCells.SetCells(1, cell_array)

aTetraGrid = vtk.vtkUnstructuredGrid()
aTetraGrid.SetPoints(tetraPoints)
aTetraGrid.SetCells(10, tetraCells)

aTetraMapper = vtk.vtkDataSetMapper()
aTetraMapper.SetInput(aTetraGrid)
aTetraActor = vtk.vtkActor()
aTetraActor.SetMapper(aTetraMapper)
aTetraActor.AddPosition(4, 0, 0)
aTetraActor.GetProperty().SetDiffuseColor(0, 1, 0)

# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300, 150)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.SetBackground(1, 1, 1)
ren.AddActor(aTetraActor)

# Render the scene and start interaction.
iren.Initialize()
renWin.Render()
iren.Start()

Follow ups

References