export

nutils.export.mplfigure(name, /, **kwargs)

Matplotlib figure context, convenience function.

Returns a matplotlib.figure.Figure object suitable for object-oriented plotting. Upon exit the result is written to the currently active logger.

Requires matplotlib.

Parameters:
  • name (str) – The filename of the resulting figure.
  • **kwargs – Keyword arguments are passed on unchanged to the constructor of the matplotlib.figure.Figure object.
nutils.export.triplot(name, points, values=None, *, tri=None, hull=None, cmap=None, clim=None, linewidth=0.1, linecolor='k', plabel=None, vlabel=None)

Uniform plotting interface to preview 1D/2D/3D results.

This function serves to quickly visualise field data and/or finite element meshes, with a consistent interface that works across dimensions. If the provided data is one-dimensional the resulting plot is a graph; if it is two-dimensional the result is a surface plot; and three-dimensional data is plotted in a fixed ortholinear projection.

The function can be used in two modes, depending on the first argument:

  • Standalone: By providing a filename as the first argument, data is plotted, a colorbar is added if values are provided, and the image is saved to the specified file.
  • Matplotlib component: By providing a Matplotlib axes object as the first argument, data is plotted to the axes and a handle to the scalar mappable (if any) is returned.

Notes on 3D: Due to limitations of the underlying libraries, 3D data can only be visualised on 2D meshes, i.e. the boundary of the topology. Plotting of the 3D hull is supported but without occlusion, meaning that a full wireframe is layed over the (properly occluded) field data. For use as a Matplotlib component the provided axes must have projection=”3d” set.

Parameters:
  • name (str or axes object) – File name of the destination image (with extension) or Matplotlib axes object.
  • points (float array) – Vertex coordinates: a 2D float array shaped as <number of vertices> x <spatial dimension>.
  • values (float array) – Scalar field quantities in the vertices specified by points: a 1D float array shaped as <number of vertices>.
  • tri (int array) – Triangulation of the vertices: a 2D integer array shaped as <number of simplices> x <mesh dimension + 1>, where the mesh dimension may not exceed the spatial dimension.
  • hull (int array) – Triangulation of the element hulls for the visualisation of mesh lines: a 2D integer array shaped as <number of hull simplices> x <mesh dimension>.
  • cmap (str) – Color map used for the visualisation of values. Ignored if the spatial dimension is one.
  • clim (tuple of floats) – Data truncation range.
  • linewidth (float) – Mesh line thickness. Ignored if hull is not specified.
  • linecolor (str) – Mesh line color. Ignored if hull is not specified.
  • plabel (str) – Axis label for the coordinates.
  • vlabel (str) – Axis label for the values.
nutils.export.vtk

Export data to a VTK file.

This method provides a simple interface to the VTK file format with a number of important restrictions:

  • Simplex-only. This makes it possible to define the mesh by a combination of vertex coordinates and a connectivity table.
  • Legacy mode. The newer XML based format is more complex and does not provide benefits within the constraints set by this method.
  • Binary mode. This allows for direct output of binary data, which aids speed, accuracy and file size.

Beyond the mandatory file name, connectivity table, and vertex coordinates, any additional data sets can be provided as keyword arguments, where the keys are the names by which the arrays are stored. The data can be either vertex or point data, with the distinction made based on the length of the array.

Parameters:
  • name (str) – Destination file name (without vtk extension).
  • tri (int array) – Triangulation.
  • x (float array) – Vertex coordinates.
  • **kwargs – Cell and/or point data