Mesh (pysit.core.mesh)

Introduction

A PySIT Mesh object specifies the computational properties of the domain being imaged. For example, this may include grid spacing, node count, units, etc.

Like everything in PySIT, meshes are specified in physical coordinates. Currently, PySIT supports Structured Cartesian Meshes through the pysit.core.mesh.CartesianMesh class.

Boundary conditions are also specified for each mesh boundary. Currently, PySIT supports homogeneous Dirichlet boundaries (StructuredDirichlet) and perfectly matched layers (StructuredPML) on CartesianMesh meshes.

Getting Started

Constructing a mesh requires a domain.

from pysit import RectangularDomain, PML
pml = PML(0.1, 100)
x_config = (0.0, 1.0, pml, pml)
z_config = (0.0, 1.0, pml, pml)
domain = RectangularDomain(x_config, z_config)

Then, import the relevant class:

from pysit import CartesianMesh

Next, construct the actual mesh. The mesh infers the problem dimension from the domain and the number of arguments after it. An integer number of nodes is required for each dimension. Both endpoints are included in the count.

nx = 101
nz = 101
mesh = CartesianMesh(domain, nx, nz)

Using mesh

Structured Cartesian Meshes

Storage of Dimensional Information

For the CartesianMesh class, information about a dimension is stored as an entry in the parameters dictionary attribute. Each dimension has the following keys:

  1. n: an integer number of points for the dimension
  2. delta: the distance between points
  3. lbc: the mesh description of the left boundary condition
  4. rbc: the mesh description of the the right boundary condition

The coordinate system is stored in a left-handed ordering (the positive z-direction points downward). In any iterable which depends on dimension, the z-dimension is always the last element. Thus, in 1D, the dimension is assumed to be z.

The negative direction is always referred to as the left side and the positive direction is always the right side. For example, for the z-dimension, our intuitive top dimension is referred to as the left and the bottom as the right.

The parameters dictionary can be accessed by number, by letter, or in the style of an attribute of the CartesianMesh. E.g.,

# Number
mesh.parameters[2] # Assume 3D, z is last entry

# Letter
mesh.parameters['z']

# Attribute-style
mesh.z

The boundary condition information is given in the lbc and rbc properties of each dimension. For example, to get the number of padding nodes the right PML,

print mesh.z.rbc.length

A big key of PySIT is that most code is dimension independent. To iterate over the dimensions of a mesh, without knowing their number ahead of time,

# Print the number of nodes in each dimension
for i in xrange(mesh.dim):
    print mesh[i].n

Key Methods

CartesianMesh.shape(self, include_bc=False, as_grid=False)[source]

Return the shape, the number of nodes in each dimension.

The shape as a grid means the result is a tuple containing the number of nodes in each dimension. As a vector means a column vector, so shape is nx1, where n is the total degrees of freedom.

Parameters:
include_bc : bool, optional

Include the ghost/boundary condition nodes in the shape; defaults to False.

as_grid : bool, optional

Return the shape as a self.dim tuple of nodes in each dimension, rather than the column vector shape (self.dof(),1); defaults to False.

CartesianMesh.mesh_coords(self, sparse=False, include_bc=False)[source]

Returns coordinate arrays for mesh nodes.

Makes ndarray arrays for each dimension, similar to meshgrid. Always in ([X, [Y]], Z) order. Optionally include nodes due to boundary padding and optionally return sparse arrays to save memory.

Parameters:
sparse : boolean

Returns a list of [X, [Y]], Z locations but not for each grid point, rather each dimesion.

include_bc : boolean

Optionally include physical locations of ghost/boundary points.

CartesianMesh.pad_array(self, in_array, out_array=None, padding_mode=None)[source]
Returns a version of in_array, padded to add nodes from the
boundary conditions or ghost nodes.
Parameters:
in_array : ndarray

Input array

out_array : ndarray, optional

If specifed, pad into a pre-allocated array

padding_mode : string

Padding mode option for numpy.pad. None indicates to pad with zeros (see Note 2).

Notes

  1. padding_mode options are found in the numpy pad() function.
  2. If padding_mode is left at its default (None), the array will be padded with zeros without calling pad() and will instead use a faster method.
  3. Recommended value for padding_mode is ‘edge’ for repeating the edge value.
  4. This function preserves array shape. If the input is grid shaped, the return is grid shaped. Similarly, if the input is vector shaped, the output will be vector shaped.
CartesianMesh.unpad_array(self, in_array, copy=False)[source]
Returns a view of input array, unpadded to the primary or

boundary-condition- or ghost-node-free shape.

Truncates the array, information in the padded area is discarded.

Parameters:
in_array : numpy.ndarray

Input array

copy : boolean, optional

Optionally return a copy of the unpadded array rather than a view.

Notes

  1. This function preserves array shape. If the input is grid shaped, the return is grid shaped. Similarly, if the input is vector shaped, the output will be vector shaped.

Reference/API

pysit.core.mesh Module

Classes

MeshBase Base Class for Pysit mesh objects
CartesianMesh(domain, *configs) Specification of Cartesian meshes in PySIT.
StructuredNeumann(mesh, domain_bc, dim, …) Specification of the Neumann boundary condition on structured meshes.
StructuredDirichlet(mesh, domain_bc, dim, …) Specification of the Dirichlet boundary condition on structured meshes.
StructuredPML(mesh, domain_bc, dim, side, …) Specification of the PML-absorbing boundary condition on structured meshes.