pysdic.fem.assemble_property_derivative#
- assemble_property_derivative(nodal_values, connectivity_array, element_indices, shape_function_derivatives, jacobian_matrix, *, allow_unlocated_points=False, default=nan)[source]#
Assemble the derivative of a property defined at the nodes of a mesh to given integration points within elements with respect to global coordinates \((x,y,z,...)\) from precomputed shape function derivatives and Jacobian matrices.
gradients[i]contains the derivative of the property at the integration point \(i\).Note
Inputs
nodal_values,shape_function_derivativesandjacobian_matrixwill be converted tonumpy.float64.Inputs
connectivity_arrayandelement_indiceswill be converted tonumpy.int64.
Note
The connectivity is validated (non-negative vertex indices lower than the number of vertices, distinct vertices in each element) and the element indices are checked against the number of elements. The geometry of the elements (e.g. their orientation) is not checked.
Important
The derivatives of the points with element index
-1(only accepted withallow_unlocated_points=True) are set todefault. AValueErroris raised if, for a located point:its shape function derivatives or its Jacobian matrix are not finite,
its Jacobian matrix is degenerated, i.e. the ratio of its smallest to its largest singular value is below
1e-10(e.g. flat element).
- Parameters:
nodal_values (ArrayLike) – An array of shape \((N_{v}, P)\) containing the property values defined at the nodes of the mesh. If 1D-array is provided, it will be treated as a single-component property of shape \((N_{v}, 1)\).
connectivity_array (ArrayLike) – An array of shape \((N_{e}, N_{vpe})\) defining the connectivity of the elements in the mesh, where each row contains the indices of the nodes that form an element.
element_indices (ArrayLike) – An array of shape \((N_{p},)\) containing the indices of each element corresponding to the \(N_{p}\) integration points.
shape_function_derivatives (ArrayLike) – An array of shape \((N_{p}, N_{vpe}, K)\) containing the derivatives of the shape functions evaluated at \(N_{p}\) points for the \(N_{vpe}\) nodes of the element.
jacobian_matrix (ArrayLike) – An array of shape \((N_{p}, E, K)\) containing the Jacobian matrices for each of the \(N_{p}\) points. Each Jacobian matrix has dimensions \((E \times K)\).
allow_unlocated_points (bool, optional (default:
False)) – If False (default), any negative element index raises anIndexError. If True, the element index-1marks a point not located in any element of the mesh, and such a point is treated as invalid (see above). Other negative indices always raise anIndexError.default (Real, optional (default:
numpy.nan)) – The value assigned to the derivatives of the points with element index-1.
- Returns:
gradients – An array of shape \((N_{p}, P, E)\) containing the derivatives of the property at each of the \(N_{p}\) integration points with respect to the global coordinates \((x, y, z, ...)\).
- Return type:
Notes
In a space of dimension \(E\) with a mesh constituted of \(N_{e}\) elements and \(N_{v}\) nodes, the mesh is composed of \(K\)-dimensional elements (with \(K \leq E\)) defined by \(N_{vpe}\) nodes for each element.
For a given set of \(N_p\) integration points located within elements, the gradients array has shape \((N_p, P, E)\) where \(P\) is the number of property components (e.g., 1 for scalar properties, 3 for vector properties), and \(E\) is the dimension of the space.
The derivative of the property at each integration point is computed as:
If the dimension of the elements \(K\) is equal to the space dimension \(E\):
\[\nabla_X P(\xi, \eta, \zeta, ...) = J^{-T} \cdot \sum_{i=1}^{N_{vpe}} \nabla_{\Xi} N_i(\xi, \eta, \zeta, ...) P_i\]If the dimension of the elements \(K\) is less than the space dimension \(E\):
\[\nabla_X P(\xi, \eta, \zeta, ...) = J (J^T J)^{-1} \cdot \sum_{i=1}^{N_{vpe}} \nabla_{\Xi} N_i(\xi, \eta, \zeta, ...) P_i\]where \(N_i\) are the shape functions associated with each node, \(P_i\) are the property values at the nodes of the element, and \(J\) is the Jacobian matrix of the transformation from natural to global coordinates.
Both cases are computed with the Moore-Penrose pseudo-inverse \(J^{+}\) (\((J^{+})^{T} = J^{-T}\) when \(J\) is square and invertible), obtained from the singular value decomposition of \(J\). For \(K < E\), the result is the tangential gradient: its component normal to the element is zero.
Demonstration#
The property field is defined at the nodes of the mesh and can be interpolated to any point within the elements using shape functions.
\[P(\Xi) = \sum_{i=1}^{N_{vpe}} N_i(\Xi) P_i\]The spatial derivative of the property field with respect to global coordinates is defined as:
\[\nabla_X P(\Xi) = \sum_{i=1}^{N_{vpe}} \nabla_{X} N_i(\Xi) P_i\]The derivative of the shape functions with respect to global coordinates is obtained via the chain rule:
\[\nabla_{X} N = J_{\Xi/X}^T \nabla_{\Xi} N\]where \(J_{\Xi/X}\) is the Jacobian matrix of the transformation from global coordinates to natural coordinates, which is the inverse of the Jacobian matrix \(J = J_{X/\Xi}\) of the transformation from natural coordinates to global coordinates.
For \(K = E\), the Jacobian matrix is square and invertible :
\[J_{\Xi/X} = J^{-1} \rightarrow \nabla_{X} N = J^{-T} \nabla_{\Xi} N\]And we obtain the formula as mentioned above:
\[\nabla_X P(\Xi) = J^{-T} \cdot \sum_{i=1}^{N_{vpe}} \nabla_{\Xi} N_i(\Xi) P_i\]For \(K < E\), the Jacobian matrix is not square and thus not invertible. The pseudo-inverse is :
\[J_{\Xi/X} = (J^T J)^{-1} J^T \rightarrow \nabla_{X} N = J (J^T J)^{-1} \nabla_{\Xi} N\]And we obtain the formula as mentioned above:
\[\nabla_X P(\Xi) = J (J^T J)^{-1} \cdot \sum_{i=1}^{N_{vpe}} \nabla_{\Xi} N_i(\Xi) P_i\]See also
pysdic.fem.compute_shape_functionsTo compute the shape functions and their derivatives at given natural coordinates within elements.
pysdic.fem.assemble_jacobian_matrixTo assemble the Jacobian matrices from shape function derivatives and remapped coordinates.
pysdic.fem.compute_property_derivativeTo compute the property derivatives directly from mesh and integration point information.
Examples
Lets construct a simple 2D mesh and compute the derivative of a scalar property at given integration points for triangular elements.
1import numpy 2from pysdic.fem import ( 3 remap_vertices_coordinates, 4 assemble_jacobian_matrix, 5 assemble_property_derivative, 6 compute_triangle_3_shape_functions 7) 8 9vertices_coordinates = numpy.array( 10 [[0.0, 0.0], 11 [1.0, 0.0], 12 [1.0, 1.0], 13 [0.0, 1.0]] 14) 15 16connectivity_array = numpy.array( 17 [[0, 1, 2], 18 [0, 2, 3]] 19) 20 21natural_coordinates = numpy.array( 22 [[0.2, 0.3], 23 [0.6, 0.2]] 24) 25 26element_indices = numpy.array([0, 1]) 27 28nodal_values = numpy.array([10.0, 20.0, 30.0, 40.0]) # Scalar property 29 30remapped_coords = remap_vertices_coordinates( 31 vertices_coordinates=vertices_coordinates, 32 connectivity_array=connectivity_array, 33 element_indices=element_indices 34) 35 36_, shape_func_derivs = compute_triangle_3_shape_functions( 37 natural_coordinates=natural_coordinates, 38 return_derivatives=True 39) 40 41jacobians = assemble_jacobian_matrix( 42 shape_function_derivatives=shape_func_derivs, 43 remapped_coordinates=remapped_coords 44) 45 46gradients = assemble_property_derivative( 47 nodal_values=nodal_values, 48 connectivity_array=connectivity_array, 49 element_indices=element_indices, 50 shape_function_derivatives=shape_func_derivs, 51 jacobian_matrix=jacobians 52) 53 54print(f"gradients (shape={gradients.shape}):") 55print(gradients)
gradients (shape=(2, 1, 2)): [[[ 10. 10.]] [[-10. 30.]]]