vis Package

vis Package

The vis module provides support for generic vtk file writing, basic mesh writing (unstructured triangular and tetrahedral meshes), visualization of aggregate groupings in 2d and in 3d, and C/F splittings.

pyamg.vis.vis_aggregate_groups(Verts, E2V, Agg, mesh_type, output='vtk', fname='output.vtu')

Coarse grid visualization of aggregate groups. Create .vtu files for use in Paraview or display with Matplotlib

Verts : {array}
coordinate array (N x D)
E2V : {array}
element index array (Nel x Nelnodes)
Agg : {csr_matrix}
sparse matrix for the aggregate-vertex relationship (N x Nagg)
mesh_type : {string}
type of elements: vertex, tri, quad, tet, hex (all 3d)
fname : {string, file object}
file to be written, e.g. ‘output.vtu’
output : {string}
‘vtk’ or ‘matplotlib’
  • Writes data to .vtu file for use in paraview (xml 0.1 format) or displays to screen using matplotlib
  • Works for both 2d and 3d elements. Element groupings are colored with data equal to 2.0 and stringy edges in the aggregate are colored with 3.0
>>> from pyamg.aggregation import standard_aggregation
>>> from pyamg.vis.vis_coarse import vis_aggregate_groups
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_square')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> Agg = standard_aggregation(A)[0]
>>> vis_aggregate_groups(Verts=V, E2V=E2V, Agg=Agg, mesh_type='tri',
                         output='vtk', fname='output.vtu')
>>> from pyamg.aggregation import standard_aggregation
>>> from pyamg.vis.vis_coarse import vis_aggregate_groups
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_cube')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> Agg = standard_aggregation(A)[0]
>>> vis_aggregate_groups(Verts=V, E2V=E2V, Agg=Agg, mesh_type='tet',
                         output='vtk', fname='output.vtu')
pyamg.vis.vis_splitting(Verts, splitting, output='vtk', fname='output.vtu')

Coarse grid visualization for C/F splittings.

Verts : {array}
coordinate array (N x D)
splitting : {array}
coarse(1)/fine(0) flags
fname : {string, file object}
file to be written, e.g. ‘output.vtu’
output : {string}
‘vtk’ or ‘matplotlib’
  • Displays in screen or writes data to .vtu file for use in paraview (xml 0.1 format)
D :
dimension of coordinate space
N :
# of vertices in the mesh represented in Verts
Ndof :

# of dof (= ldof * N)

  • simply color different points with different colors. This works best with classical AMG.
  • writes a file (or opens a window) for each dof
  • for Ndof>1, they are assumed orderd [...dof1..., ...dof2..., etc]
>>> import numpy
>>> from pyamg.vis.vis_coarse import vis_splitting
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0]])
>>> splitting = numpy.array([0,1,0,1,1,0,1,0])    # two variables
>>> vis_splitting(Verts,splitting,output='vtk',fname='output.vtu')
>>> from pyamg.classical import RS
>>> from pyamg.vis.vis_coarse import vis_splitting
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_square')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> splitting = RS(A)
>>> vis_splitting(Verts=V,splitting=splitting,output='vtk',
                  fname='output.vtu')
pyamg.vis.write_basic_mesh(Verts, E2V=None, mesh_type='tri', pdata=None, pvdata=None, cdata=None, cvdata=None, fname='output.vtk')

Write mesh file for basic types of elements

fname : {string}
file to be written, e.g. ‘mymesh.vtu’
Verts : {array}
coordinate array (N x D)
E2V : {array}
element index array (Nel x Nelnodes)
mesh_type : {string}
type of elements: tri, quad, tet, hex (all 3d)
pdata : {array}
scalar data on vertices (N x Nfields)
pvdata : {array}
vector data on vertices (3*Nfields x N)
cdata : {array}
scalar data on cells (Nfields x Nel)
cvdata : {array}
vector data on cells (3*Nfields x Nel)

writes a .vtu file for use in Paraview

The difference between write_basic_mesh and write_vtu is that write_vtu is more general and requires dictionaries of cell information. write_basic_mesh calls write_vtu

>>> import numpy
>>> from pyamg.vis import write_basic_mesh
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [2.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0],
...                      [2.0,1.0],
...                      [0.0,2.0],
...                      [1.0,2.0],
...                      [2.0,2.0],
...                      [0.0,3.0],
...                      [1.0,3.0],
...                      [2.0,3.0]])
>>> E2V = numpy.array([[0,4,3],
...                    [0,1,4],
...                    [1,5,4],
...                    [1,2,5],
...                    [3,7,6],
...                    [3,4,7],
...                    [4,8,7],
...                    [4,5,8],
...                    [6,10,9],
...                    [6,7,10],
...                    [7,11,10],
...                    [7,8,11]])
>>> pdata=numpy.ones((12,2))
>>> pvdata=numpy.ones((12*3,2))
>>> cdata=numpy.ones((12,2))
>>> cvdata=numpy.ones((3*12,2))
>>> write_basic_mesh(Verts, E2V=E2V, mesh_type='tri',pdata=pdata,
                     pvdata=pvdata, cdata=cdata, cvdata=cvdata,
                     fname='test.vtu')

write_vtu

pyamg.vis.write_vtu(Verts, Cells, pdata=None, pvdata=None, cdata=None, cvdata=None, fname='output.vtk')

Write a .vtu file in xml format

fname : {string}
file to be written, e.g. ‘mymesh.vtu’
Verts : {array}
Ndof x 3 (if 2, then expanded by 0) list of (x,y,z) point coordinates
Cells : {dictionary}
Dictionary of with the keys
pdata : {array}
Ndof x Nfields array of scalar values for the vertices
pvdata : {array}
Nfields*3 x Ndof array of vector values for the vertices
cdata : {dictionary}
scalar valued cell data
cvdata : {dictionary}
vector valued cell data
writes a .vtu file for use in Paraview
  • Poly data not supported
  • Non-Poly data is stored in Numpy array: Ncell x vtk_cell_info
  • Each I1 must be >=3
  • pdata = Ndof x Nfields
  • pvdata = 3*Ndof x Nfields
  • cdata,cvdata = list of dictionaries in the form of Cells
keys type n points dim
1 VTK_VERTEX: 1 point 2d
2 VTK_POLY_VERTEX: n points 2d
3 VTK_LINE: 2 points 2d
4 VTK_POLY_LINE: n+1 points 2d
5 VTK_TRIANGLE: 3 points 2d
6 VTK_TRIANGLE_STRIP: n+2 points 2d
7 VTK_POLYGON: n points 2d
8 VTK_PIXEL: 4 points 2d
9 VTK_QUAD: 4 points 2d
10 VTK_TETRA: 4 points 3d
11 VTK_VOXEL: 8 points 3d
12 VTK_HEXAHEDRON: 8 points 3d
13 VTK_WEDGE: 6 points 3d
14 VTK_PYRAMID: 5 points 3d
>>> from pyamg.vis import write_vtu
>>> import numpy
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [2.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0],
...                      [2.0,1.0],
...                      [0.0,2.0],
...                      [1.0,2.0],
...                      [2.0,2.0],
...                      [0.0,3.0],
...                      [1.0,3.0],
...                      [2.0,3.0]])
>>> E2V = numpy.array([[0,4,3],
...                    [0,1,4],
...                    [1,5,4],
...                    [1,2,5],
...                    [3,7,6],
...                    [3,4,7],
...                    [4,8,7],
...                    [4,5,8],
...                    [6,10,9],
...                    [6,7,10],
...                    [7,11,10],
...                    [7,8,11]])
>>> E2edge = numpy.array([[0,1]])
>>> E2point = numpy.array([2,3,4,5])
>>> Cells = {5:E2V,3:E2edge,1:E2point}
>>> pdata=numpy.ones((12,2))
>>> pvdata=numpy.ones((12*3,2))
>>> cdata={5:numpy.ones((12,2)),3:numpy.ones((1,2)),1:numpy.ones((4,2))}
>>> cvdata={5:numpy.ones((3*12,2)),3:numpy.ones((3*1,2)),
            1:numpy.ones((3*4,2))}
>>> write_vtu(Verts=Verts, Cells=Cells, fname='test.vtu')

write_mesh

info Module

The vis module provides support for generic vtk file writing, basic mesh writing (unstructured triangular and tetrahedral meshes), visualization of aggregate groupings in 2d and in 3d, and C/F splittings.

setup Module

pyamg.vis.setup.configuration(parent_package='', top_path=None)[source]

vis_coarse Module

Visualization tools for coarse grids, both C/F splittings and aggregation.

Output is either to file (VTK) or to the screen (matplotlib).

vis_splitting: visualize C/F splittings through vertex elements vis_aggregate_groups: visualize aggregation through groupins of edges, elements

pyamg.vis.vis_coarse.vis_splitting(Verts, splitting, output='vtk', fname='output.vtu')[source]

Coarse grid visualization for C/F splittings.

Verts : {array}
coordinate array (N x D)
splitting : {array}
coarse(1)/fine(0) flags
fname : {string, file object}
file to be written, e.g. ‘output.vtu’
output : {string}
‘vtk’ or ‘matplotlib’
  • Displays in screen or writes data to .vtu file for use in paraview (xml 0.1 format)
D :
dimension of coordinate space
N :
# of vertices in the mesh represented in Verts
Ndof :

# of dof (= ldof * N)

  • simply color different points with different colors. This works best with classical AMG.
  • writes a file (or opens a window) for each dof
  • for Ndof>1, they are assumed orderd [...dof1..., ...dof2..., etc]
>>> import numpy
>>> from pyamg.vis.vis_coarse import vis_splitting
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0]])
>>> splitting = numpy.array([0,1,0,1,1,0,1,0])    # two variables
>>> vis_splitting(Verts,splitting,output='vtk',fname='output.vtu')
>>> from pyamg.classical import RS
>>> from pyamg.vis.vis_coarse import vis_splitting
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_square')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> splitting = RS(A)
>>> vis_splitting(Verts=V,splitting=splitting,output='vtk',
                  fname='output.vtu')
pyamg.vis.vis_coarse.vis_aggregate_groups(Verts, E2V, Agg, mesh_type, output='vtk', fname='output.vtu')[source]

Coarse grid visualization of aggregate groups. Create .vtu files for use in Paraview or display with Matplotlib

Verts : {array}
coordinate array (N x D)
E2V : {array}
element index array (Nel x Nelnodes)
Agg : {csr_matrix}
sparse matrix for the aggregate-vertex relationship (N x Nagg)
mesh_type : {string}
type of elements: vertex, tri, quad, tet, hex (all 3d)
fname : {string, file object}
file to be written, e.g. ‘output.vtu’
output : {string}
‘vtk’ or ‘matplotlib’
  • Writes data to .vtu file for use in paraview (xml 0.1 format) or displays to screen using matplotlib
  • Works for both 2d and 3d elements. Element groupings are colored with data equal to 2.0 and stringy edges in the aggregate are colored with 3.0
>>> from pyamg.aggregation import standard_aggregation
>>> from pyamg.vis.vis_coarse import vis_aggregate_groups
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_square')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> Agg = standard_aggregation(A)[0]
>>> vis_aggregate_groups(Verts=V, E2V=E2V, Agg=Agg, mesh_type='tri',
                         output='vtk', fname='output.vtu')
>>> from pyamg.aggregation import standard_aggregation
>>> from pyamg.vis.vis_coarse import vis_aggregate_groups
>>> from pyamg.gallery import load_example
>>> data = load_example('unit_cube')
>>> A = data['A'].tocsr()
>>> V = data['vertices']
>>> E2V = data['elements']
>>> Agg = standard_aggregation(A)[0]
>>> vis_aggregate_groups(Verts=V, E2V=E2V, Agg=Agg, mesh_type='tet',
                         output='vtk', fname='output.vtu')

vtk_writer Module

VTK output functions.

Create coarse grid views and write meshes/primitives to .vtu files. Use the XML VTK format for unstructured meshes (.vtu)

This will use the XML VTK format for unstructured meshes, .vtu

See here for a guide: http://www.vtk.org/pdf/file-formats.pdf

pyamg.vis.vtk_writer.write_vtu(Verts, Cells, pdata=None, pvdata=None, cdata=None, cvdata=None, fname='output.vtk')[source]

Write a .vtu file in xml format

fname : {string}
file to be written, e.g. ‘mymesh.vtu’
Verts : {array}
Ndof x 3 (if 2, then expanded by 0) list of (x,y,z) point coordinates
Cells : {dictionary}
Dictionary of with the keys
pdata : {array}
Ndof x Nfields array of scalar values for the vertices
pvdata : {array}
Nfields*3 x Ndof array of vector values for the vertices
cdata : {dictionary}
scalar valued cell data
cvdata : {dictionary}
vector valued cell data
writes a .vtu file for use in Paraview
  • Poly data not supported
  • Non-Poly data is stored in Numpy array: Ncell x vtk_cell_info
  • Each I1 must be >=3
  • pdata = Ndof x Nfields
  • pvdata = 3*Ndof x Nfields
  • cdata,cvdata = list of dictionaries in the form of Cells
keys type n points dim
1 VTK_VERTEX: 1 point 2d
2 VTK_POLY_VERTEX: n points 2d
3 VTK_LINE: 2 points 2d
4 VTK_POLY_LINE: n+1 points 2d
5 VTK_TRIANGLE: 3 points 2d
6 VTK_TRIANGLE_STRIP: n+2 points 2d
7 VTK_POLYGON: n points 2d
8 VTK_PIXEL: 4 points 2d
9 VTK_QUAD: 4 points 2d
10 VTK_TETRA: 4 points 3d
11 VTK_VOXEL: 8 points 3d
12 VTK_HEXAHEDRON: 8 points 3d
13 VTK_WEDGE: 6 points 3d
14 VTK_PYRAMID: 5 points 3d
>>> from pyamg.vis import write_vtu
>>> import numpy
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [2.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0],
...                      [2.0,1.0],
...                      [0.0,2.0],
...                      [1.0,2.0],
...                      [2.0,2.0],
...                      [0.0,3.0],
...                      [1.0,3.0],
...                      [2.0,3.0]])
>>> E2V = numpy.array([[0,4,3],
...                    [0,1,4],
...                    [1,5,4],
...                    [1,2,5],
...                    [3,7,6],
...                    [3,4,7],
...                    [4,8,7],
...                    [4,5,8],
...                    [6,10,9],
...                    [6,7,10],
...                    [7,11,10],
...                    [7,8,11]])
>>> E2edge = numpy.array([[0,1]])
>>> E2point = numpy.array([2,3,4,5])
>>> Cells = {5:E2V,3:E2edge,1:E2point}
>>> pdata=numpy.ones((12,2))
>>> pvdata=numpy.ones((12*3,2))
>>> cdata={5:numpy.ones((12,2)),3:numpy.ones((1,2)),1:numpy.ones((4,2))}
>>> cvdata={5:numpy.ones((3*12,2)),3:numpy.ones((3*1,2)),
            1:numpy.ones((3*4,2))}
>>> write_vtu(Verts=Verts, Cells=Cells, fname='test.vtu')

write_mesh

pyamg.vis.vtk_writer.write_basic_mesh(Verts, E2V=None, mesh_type='tri', pdata=None, pvdata=None, cdata=None, cvdata=None, fname='output.vtk')[source]

Write mesh file for basic types of elements

fname : {string}
file to be written, e.g. ‘mymesh.vtu’
Verts : {array}
coordinate array (N x D)
E2V : {array}
element index array (Nel x Nelnodes)
mesh_type : {string}
type of elements: tri, quad, tet, hex (all 3d)
pdata : {array}
scalar data on vertices (N x Nfields)
pvdata : {array}
vector data on vertices (3*Nfields x N)
cdata : {array}
scalar data on cells (Nfields x Nel)
cvdata : {array}
vector data on cells (3*Nfields x Nel)

writes a .vtu file for use in Paraview

The difference between write_basic_mesh and write_vtu is that write_vtu is more general and requires dictionaries of cell information. write_basic_mesh calls write_vtu

>>> import numpy
>>> from pyamg.vis import write_basic_mesh
>>> Verts = numpy.array([[0.0,0.0],
...                      [1.0,0.0],
...                      [2.0,0.0],
...                      [0.0,1.0],
...                      [1.0,1.0],
...                      [2.0,1.0],
...                      [0.0,2.0],
...                      [1.0,2.0],
...                      [2.0,2.0],
...                      [0.0,3.0],
...                      [1.0,3.0],
...                      [2.0,3.0]])
>>> E2V = numpy.array([[0,4,3],
...                    [0,1,4],
...                    [1,5,4],
...                    [1,2,5],
...                    [3,7,6],
...                    [3,4,7],
...                    [4,8,7],
...                    [4,5,8],
...                    [6,10,9],
...                    [6,7,10],
...                    [7,11,10],
...                    [7,8,11]])
>>> pdata=numpy.ones((12,2))
>>> pvdata=numpy.ones((12*3,2))
>>> cdata=numpy.ones((12,2))
>>> cvdata=numpy.ones((3*12,2))
>>> write_basic_mesh(Verts, E2V=E2V, mesh_type='tri',pdata=pdata,
                     pvdata=pvdata, cdata=cdata, cvdata=cvdata,
                     fname='test.vtu')

write_vtu