e3_grid.py: Python grid-generation functions for Elmer3.

Builds on the path and basic geometric functions.


class e3_grid.StructuredGrid(nijk=None, label=None)

Storage and service functions for a mesh of points defining the cell vertices within a block-structured grid.

StructuredGrid.__init__(nijk=None, label=None)

Create an object containg coordinates representing a grid of points.

  • nijk – optional tuple of integers specifying the number of points in each direction. If the number of vertices are specified in each direction, we actually create the storage arrays now. Note that the number of grid vertices in each index-direction will be one more than the number of finite-volume cells in that direction.
  • label – optional string name for the grid

Create the storage arrays at the previously-specified sizes.


Writes the grid to an already open file, f.

This function essentially defines the Eilmer3 native format.


Reads the grid from an already open file, f.

StructuredGrid.read_from_plot3d_whole_grid(f, with_blanking=1)

Read one block from plot3D whole-grid format (ASCII or text file).

Note that:

  • the file is already opened.
  • the size of the grid has already been read.

This format, without blanking, seems to be used by GridGen (from Pointwise).

StructuredGrid.read_from_plot3d_in_planes(f, with_blanking=1, verbosity_level=0)

Read one block from plot3D in-planes (ASCII or text) format.

Note that:

  • the file is already opened, f is the file object.
  • the size of the grid has already been read.

This seems to be the format written by ICEM software as used by Bianca and Rowan at EPFL, Lausanne. The only place that this format seemed to be documented is the original Plot3D manual.


Write one block in plot3d format to a text file.

Note that:

  • the file is already opened, f is the file object
  • the headers for the file have already been written to f.
StructuredGrid.read_block_in_VTK_format(f, verbosity_level=0)

Reads the grid from an already open file.

The lines containing some of the metadata at the start of the file are read and then ignored.

StructuredGrid.write_block_in_VTK_format(f, verbosity_level=0)

Writes the grid to an already open file.

Note that this function writes all of the VTK header lines so that it is implicit that only one block grid goes into the file. Note also that this is the legacy VTK format.

StructuredGrid.make_grid_from_surface(surface, cluster_functions=[None, None, None, None], verbosity_level=0)

Given a parametric surface, create a 2D grid via interpolation.

The order of the cluster functions is N,E,S,W.

StructuredGrid.make_TFI_grid_from_volume(pvolume, cluster_functions=[None, None, None, None, None, None, None, None, None, None, None, None], verbosity_level=0)

Given a parametric volume, create the grid via TFI.

The clustering information always comes from the edges. A full compliment of 12 should be supplied but, if any are not already specified correctly, they will be set as standard linear functions.

StructuredGrid.create_subgrid(imin, imax, jmin, jmax, kmin=0, kmax=0)

Returns a new StructuredGrid that is a subgrid of the current grid.

The limits (imin,imax) are included in the new subgrid.


Returns a tuple of coordinates for a single vertex.

The indexing for ivtx corresponds to the VTK convention for a hexahedral cell (scaled up to the whole block).

StructuredGrid.get_vertex_list_for_cell(i, j, k=0)

Returns a list of Vectors defining the vertices of the cell.

See block.hh for the root definition. All 8 points are available in a 3D grid but only p0 through p3 are available in a 2D grid.

StructuredGrid.point_inside_cell(i, j, k, x, y, z, dimensions)

Similar to the point_inside_cell function in cell.cxx Returns 1 if the point p is inside or on the cell surface.

StructuredGrid.suggest_better_cell(i, j, k, x, y, z, dimensions)

Using the method from cell_finder.cxx (ray-tracing) where a cell step is returned (ie di = change in i index, etc) based on what side of the interfaces the point is on.

Reading and writing Plot3D grid files

e3_grid.write_plot3d_grid(fname, grid)

Writes a formatted multiple-block Plot3D grid (ASCII or text) file.

  • fname – name of the plot3d grid file to create
  • grid – list of StructuredGrid objects


e3_grid.read_plot3d_grid(fname, dimensions)

Reads a plot3d grid file, containing one or more block-grids.

  • fname – name of plot3d grid file
  • dimensions – can have the value 2 or 3

a list StructuredGrid object(s)


  • text file, Fortran formatted
  • multiple-block
  • with I-blanking
e3_grid.read_plot3d_grid_from_pointwise(fname, dim, scaleFactor)

Reads a plot3d grid, returns a list StructuredGrid object(s).

  • fname – name of plot3d grid file
  • dim – has the value 2 or 3
  • scaleFactor – allow for correction of dimensions of the grid, if required. For example, from millimetres to metres, scaleFactor would be 1000.

list of StructuredGrid objects


  • formatted
  • multiple-block

Returns a lists of mesh dimensions and coordinate data read from a single plot3d file.

This is Rowan’s function for reading files from Peter Gnoffo’s Laura code.

Parameters:gname – name of plot3d grid file
Returns:a tuple containing lists of the i,j and k dimensions of eash block and a list of the StructuredGrid objects holding the grid points.