The Gradient class#

class pylife.mesh.Gradient(pandas_obj)[source]#

Estimate nodal gradients from neighboring mesh nodes.

The gradient accessor works on a pyLife finite-element mesh and computes derivatives of a scalar nodal quantity, for example stress in MPa. The result is node-averaged and indexed only by node_id.

Parameters:

pandas_obj (pandas.DataFrame) – Mesh DataFrame with coordinate columns x, y and z in mm, a scalar value column, and a pandas.MultiIndex containing element_id and node_id.

Raises:
  • AttributeError – If at least one of the coordinate columns x or y is missing.

  • AttributeError – If the index of the DataFrame does not contain the levels node_id and element_id.

See also

pylife.mesh.gradient.Gradient3D

Compute element-shape based gradients for tetrahedral and hexahedral 3D elements.

pylife.mesh.meshsignal.Mesh

Define the finite-element mesh signal contract.

Notes

For every node, pyLife collects all directly connected neighboring nodes and fits a local plane to the scalar field by least squares:

\[v(\Delta x, \Delta y, \Delta z) \approx v_0 + \nabla v \cdot \begin{bmatrix}\Delta x & \Delta y & \Delta z\end{bmatrix}^T\]

If value_key contains stress in MPa and coordinates are in mm, the returned gradient components have the unit MPa/mm. The approach follows the least-squares gradient reconstruction described in [MeshGrad-LSQ].

References

[MeshGrad-LSQ]

“How to approximate numerically the gradient of the function on a triangular mesh”, Mathematics Stack Exchange, https://math.stackexchange.com/a/2632616.

gradient_of(value_key)[source]#

Calculate the gradient of a scalar mesh value.

Parameters:

value_key (str) – Name of the column containing the scalar values. If the column contains stress in MPa and coordinates are in mm, the returned gradient is given in MPa/mm.

Returns:

Gradient components indexed by node_id. The columns are d{value_key}_dx, d{value_key}_dy and d{value_key}_dz and carry the unit of value_key divided by mm.

Return type:

pandas.DataFrame