API Reference


TensorMesh([h, x0]) TensorMesh is a mesh class that deals with tensor product meshes.
CylMesh([h, x0]) CylMesh is a mesh class for cylindrical problems. It supports both
TreeMesh(h[, x0]) TreeMesh is a class for adaptive QuadTree (2D) and OcTree (3D) meshes.
CurvilinearMesh([nodes]) CurvilinearMesh is a mesh class that deals with curvilinear meshes.

Numerical Operators

DiffOperators.DiffOperators() Class creates the differential operators that you need!
InnerProducts.InnerProducts() This is a base for the discretize mesh classes.

Mesh IO

load_mesh(filename) Open a json file and load the mesh into the target class





View.TensorView() Provides viewing functions for TensorMesh


View.CurviView() Provides viewing functions for CurvilinearMesh
View.Slicer(mesh, v[, xslice, yslice, …]) Plot slices of a 3D volume, interactively (scroll wheel).
mixins.vtkModule This module provides a way for discretize meshes to be converted to VTK data objects (and back when possible) if the `VTK Python package`_ is available.


Tests.OrderTest([methodName]) OrderTest is a base class for testing convergence orders with respect to mesh sizes of integral/differential operators.
Tests.checkDerivative(fctn, x0[, num, …]) Basic derivative check
Tests.getQuadratic(A, b[, c]) Given A, b and c, this returns a quadratic, Q
Tests.Rosenbrock(x[, return_g, return_H]) Rosenbrock function for testing GaussNewton scheme


General Utilities

utils.download(url[, folder, overwrite, verbose]) Function to download all files stored in a cloud directory

Mesh Utilities

utils.exampleLrmGrid(nC, exType)
utils.meshTensor(value) meshTensor takes a list of numbers and tuples that have the form.
utils.closestPoints(mesh, pts[, gridLoc]) Move a list of points to the closest points on a grid.
utils.ExtractCoreMesh(xyzlim, mesh[, mesh_type]) Extracts Core Mesh from Global mesh
utils.random_model(shape[, seed, …]) Create a random model by convolving a kernel with a uniformly distributed model.
utils.mesh_builder_xyz(xyz, h[, …]) Function to quickly generate a Tensor or Tree mesh given a cloud of xyz points, finest core cell size and padding distance.
utils.refine_tree_xyz(mesh, xyz[, method, …]) Refine a TreeMesh based on xyz point locations

Matrix Utilities

utils.mkvc(x[, numDims]) Creates a vector with the number of dimension specified
utils.sdiag(h) Sparse diagonal matrix
utils.sdInv(M) Inverse of a sparse diagonal matrix
utils.speye(n) Sparse identity
utils.kron3(A, B, C) Three kron prods
utils.spzeros(n1, n2) a sparse matrix of zeros
utils.ddx(n) Define 1D derivatives, inner, this means we go from n+1 to n
utils.av(n) Define 1D averaging operator from nodes to cell-centers.
utils.av_extrap(n) Define 1D averaging operator from cell-centers to nodes.
utils.ndgrid(\*args, \*\*kwargs) Form tensorial grid for 1, 2, or 3 dimensions.
utils.ind2sub(shape, inds) From the given shape, returns the subscripts of the given index
utils.sub2ind(shape, subs) From the given shape, returns the index of the given subscript
utils.getSubArray(A, ind) subArray
utils.inv3X3BlockDiagonal(a11, a12, a13, …) inverts a stack of 3x3 matrices
utils.inv2X2BlockDiagonal(a11, a12, a21, a22) Inverts a stack of 2x2 matrices by using the inversion formula
utils.TensorType(M, tensor)
utils.makePropertyTensor(M, tensor)
utils.invPropertyTensor(M, tensor[, …])

Mathematical Operations

utils.rotatePointsFromNormals(XYZ, n0, n1[, x0]) rotates a grid so that the vector n0 is aligned with the vector n1
utils.rotationMatrixFromNormals(v0, v1[, tol]) Performs the minimum number of rotations to define a rotation from the direction indicated by the vector n0 to the direction indicated by n1.
utils.cyl2cart(grid[, vec]) Take a grid defined in cylindrical coordinates \((r, heta, z)\) and transform it to cartesian coordinates.
utils.cart2cyl(grid[, vec]) Take a grid defined in cartesian coordinates and transform it to cyl coordinates
utils.asArray_N_x_Dim(pts, dim)

Curvilinear Mesh Utilities

utils.volTetra(xyz, A, B, C, D) Returns the volume for tetrahedras volume specified by the indexes A to D.
utils.faceInfo(xyz, A, B, C, D[, average, …]) function [N] = faceInfo(y,A,B,C,D)
utils.indexCube(nodes, gridSize[, n]) Returns the index of nodes on the mesh.

Base Mesh

base.BaseMesh(n[, x0]) BaseMesh does all the counting you don’t want to do.
base.BaseRectangularMesh(n[, x0]) BaseRectangularMesh
base.BaseTensorMesh([h, x0]) Base class for tensor-product style meshes