The Gradient3D class

class pylife.mesh.Gradient3D(pandas_obj)[source]

Computes the gradient of a value in a 3D mesh that was imported from Ansys or Abaqus.

Accesses a mesh registered in meshsignal. The accessor for this type of computation is gradient_3D. Example usage:

# given a mesh in `pylife_mesh` with column `mises`, compute the gradient
gradient = pylife_mesh.gradient_3D.gradient_of('mises')

# add the results back in the mesh
pylife_mesh = pylife_mesh.join(grad)

More specifically, the elements in the mesh must be either tetrahedral/simplex or hexahedral elements and the order of the nodes per element matters. Linear tetrahedral elements have 4 nodes, linear hexahedral elements have 8 nodes. Alternatively, quadratic elements may be used with 16 (20) or 10 nodes, respectively. In such a case only the first 4 or 8 nodes are considered for the gradient computation. The result contains zeros for all following nodes.

This is consistent with the node numbering in Ansys/Abaqus, where the first 8 nodes of a quadratic hex elements are the same as the respective linear hex elements, the same applies for the first 4 nodes of a quadratic simplex element which are the same as in the linear simplex element.

This class detects the type of element (tetrahedral or hexahedral) according to the number of nodes of each element and uses the according formula. It also works for mixed meshes that contain both tetrahedral and hexahedral elements.

Note that this gradient computation only works for 3D elements and considers the node order. The other gradient computation accessible via gradient also works for 2D elements and disregards the order of the nodes. However, it is slower and less accurate for tetrahedral elements.

Raises:
  • AttributeError – if at least one of the columns x, y, z is missing

  • AttributeError – if the index of the DataFrame is not a two level MultiIndex with the names node_id and element_id

gradient_of(value_key)[source]

returns the gradient

Parameters:

value_key (str) – The key of the value that forms the gradient. Needs to be found in df

Returns:

gradient – A table describing the gradient indexed by node_id. The keys for the components of the gradients are ['d{value_key}_dx', 'd{value_key}_dy', 'd{value_key}_dz'].

Return type:

pd.DataFrame