fieldconverter.py

This module provides functions for manipulating simulation data objects to be compatible with the underlying machinery of pyvale.

simdata_to_pyvista_interp(sim_data, components, elem_dims)[source]

Converts the mesh and field data in a SimData object into a pyvista UnstructuredGrid for interpolating the data.

Parameters:
  • sim_data (mh.SimData) – Object containing a mesh and associated field data from a simulation.

  • components (tuple[str,...] | None) – String keys for the components of the field to extract from the simulation data.

  • elem_dim (int) – Number of spatial dimensions (2 or 3) used to determine the element types in the mesh from the number of nodes per element.

Returns:

pv.UnstructuredGrid – As pyvista grid with attached field data to allow for interpolation on the mesh using the element shape functions.

simdata_to_pyvista_vis(sim_data, elem_dims)[source]

Converts the mesh and field data in a SimData object into a pyvista UnstructuredGrid or PolyData object for visualisation.

Parameters:
  • sim_data (mh.SimData) – Object containing a mesh and associated field data from a simulation.

  • elem_dim (int) – Number of spatial dimensions (2 or 3) used to determine the element types in the mesh from the number of nodes per element. Set to the dimensionality of the problem for point cloud data as 2D triangulation will be much faster if possible.

Returns:

pv.UnstructuredGrid | pv.PolyData – A pyvista unstructured grid or poly data object that has no field data attached for visualisation purposes.

scale_length_units(scale, sim_data, disp_comps=None)[source]

Used to scale the length units of a simulation. Commonly used to convert SI units to mm for use with visualisation tools and rendering algorithms.

Parameters:
  • scale (float) – Scale multiplier used to scale the coordinates and displacement fields if specified.

  • sim_data (mh.SimData) – Simulation dataclass that will be scaled.

  • disp_comps (tuple[str,...] | None, optional) – Tuple of string keys for the displacement keys to be scaled, by default None. If None then the displacements are not scaled.

Returns:

mh.SimData – Simulation dataclass with scaled length units.

extract_surf_mesh(sim_data)[source]

Extracts a surface mesh from a 3D simulation dataclass. Useful for limiting the memory required for analysing sensors that only measure surface fields. This function currently supports:

  • A single connectivity table

  • Higher order retrahedral and hexahedral elements (but not wedges or pyramids)

NOTE: this function returns the surface mesh with element nodal winding consistent with th exodus output format.

Parameters:

sim_data (mh.SimData) – Simulation dataclass containing the 3D mesh from which the surface mesh is to be extracted.

Returns:

mh.SimData – Simulation data class containing the data for the surface mesh.