CartesianMesh

class pysit.core.CartesianMesh(domain, *configs)[source]

Bases: pysit.core.mesh.StructuredMesh

Specification of Cartesian meshes in PySIT.

Parameters:
domain : subclass of pysit.core.domain.DomainBase

The PySIT domain that the mesh discretizes.

configs

A variable number of integers specifying the number of points in each dimension. One entry for each dimension.

Notes

  1. 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.

  2. 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, the top is left and the bottom is right.

  3. A dimension parameters Bunch contains four 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
  4. The parameters dictionary can be accessed by number, by letter, or in the style of an attribute of the RectangularDomain.

    1. Number

      >>> # Assume 3D, z is last
      >>> my_mesh.parameters[2]
      
    2. Letter

      >>> my_mesh.parameters['z']
      
    3. Attribute

      >>> my_mesh.z
      
Attributes:
type : str

String describing the type of mesh, e.g., structured.

dim : int

Dimension \(d\) in \(\mathcal{R}^d\) of the domain.

domain : subclass of pysit.core.domain.DomainBase

The PySIT domain that the mesh discretizes.

parameters : dict of Bunch

Dictionary containing descriptions of each dimension.

Attributes Summary

deltas Tuple of grid deltas
type String describing the type of mesh, e.g., structured.

Methods Summary

dof(self[, include_bc]) Return the number of degrees of freedom as an integer.
inner_product(self, arg1, arg2) Compute the correct scaled inner product on the mesh.
mesh_coords(self[, sparse, include_bc]) Returns coordinate arrays for mesh nodes.
nodes(self[, include_bc]) Returns a self.dof() X self.dim ndarray of node locations.
pad_array(self, in_array[, out_array, …]) Returns a version of in_array, padded to add nodes from the
shape(self[, include_bc, as_grid]) Return the shape, the number of nodes in each dimension.
unpad_array(self, in_array[, copy]) Returns a view of input array, unpadded to the primary or

Attributes Documentation

deltas

Tuple of grid deltas

type

String describing the type of mesh, e.g., structured.

Methods Documentation

dof(self, include_bc=False)[source]

Return the number of degrees of freedom as an integer.

Parameters:
include_bc : bool, optional

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

inner_product(self, arg1, arg2)[source]

Compute the correct scaled inner product on the mesh.

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.

nodes(self, include_bc=False)[source]

Returns a self.dof() X self.dim ndarray of node locations.

Parameters:
include_bc : bool, optional

Optionally include node locations for the boundary padding, defaults to False.

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.
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.

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.