The Gradient class#
- class pylife.mesh.Gradient(pandas_obj)[source]#
Estimate nodal gradients from neighboring mesh nodes.
The
gradientaccessor 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 bynode_id.- Parameters:
pandas_obj (pandas.DataFrame) – Mesh DataFrame with coordinate columns
x,yandzin mm, a scalar value column, and apandas.MultiIndexcontainingelement_idandnode_id.- Raises:
AttributeError – If at least one of the coordinate columns
xoryis missing.AttributeError – If the index of the DataFrame does not contain the levels
node_idandelement_id.
See also
pylife.mesh.gradient.Gradient3DCompute element-shape based gradients for tetrahedral and hexahedral 3D elements.
pylife.mesh.meshsignal.MeshDefine 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_keycontains 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 ared{value_key}_dx,d{value_key}_dyandd{value_key}_dzand carry the unit ofvalue_keydivided by mm.- Return type: