from_grid#
- classmethod Mesh.from_grid(array, *arrays, triangulate=False, order='C', name=None, quiet=False)#
Construct mesh from grid data.
Added in version 1.1.0.
A quadrilateral mesh with m⋅n faces is generated from k coordinate arrays of shape (m, n). Alternatively a single stacked coordinate array of shape (m, n, k) can be provided.
- Parameters:
- arrayndarray, shape (m, n, k)
Stacked coordinate arrays. Points in k-d space are defined by the last axis.
- *arrays
Variable number of coordinate arrays of shape (m, n). If given, array has to be of shape (m, n), too.
- triangulatebool, optional
Triangulate quadrilateral faces.
- orderstr, optional
Flatten coordinate arrays in row-major mode ‘C’ or column-major mode ‘F’.
- namestr, optional
Name tag. Defaults to the string ‘None’ if not specified.
- quietbool, optional
Suppress console output if
True.
- Returns:
- meshMesh
Mesh instance.
Notes
As a rule of thumb, use ‘C’ order when meshgrid was used with the ‘xy’ option and ‘F’ order when meshgrid was used with the ‘ij’ option.
Examples
Create a quadrilateral mesh of the graph of \(\frac{1}{2} x^2 - y^2\) over \([-1, 1] \times [-1, 1]\) where the interval in x-direction is sampled at n=10 points and the y-direction at m=20 points:
>>> x = np.linspace(-1.0, 1.0, 10) >>> y = np.linspace(-1.0, 1.0, 20)
Prepare the three coordinate arrays using meshgrid with the default ‘xy’ indexing (resulting in coordinate arrays of shape (m, n) each) and create the mesh:
>>> X, Y = np.meshgrid(x, y) >>> Z = 0.5 * X**2 - Y**2 >>> mesh = Mesh.from_grid(X, Y, Z)
The mesh stores rows of the grid contiguously (‘C’ order is used by default). Hence, all points of the slice
mesh.points[i*n:(i+1)*n]of length n have equal y-coordinatey[i].