pysdic.fem.compute_shape_function_matrix#
- compute_shape_function_matrix(connectivity_array, element_type, natural_coordinates, element_indices, *, n_vertices=None, sparse=False, sparse_format='csr', allow_unlocated_points=False, tolerance=0.0)[source]#
Compute and assemble the shape function matrix \(\mathcal{N}\) at given integration points within specified elements with shape \((N_{p}, N_{v})\).
This function combines the computation of shape functions at given natural coordinates with the assembly of the shape function matrix for the entire mesh.
shape_function_matrix[i, j]contains the shape function value at integration point \(i\) for vertex \(j\) and a non-zero value only if vertex \(j\) is part of the element containing integration point \(i\).Note
Input
natural_coordinateswill 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 row of a point with element index
-1(only accepted withallow_unlocated_points=True) or with natural coordinates outside the reference element (enlarged bytolerance) is filled with zeros (no entry in sparse matrices), i.e. the point has a zero weight.- Parameters:
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_type (str) – A string specifying the type of element (e.g.,
'segment_2','triangle_3', etc.) to determine which shape function to use.natural_coordinates (ArrayLike) – An array of shape \((N_{p}, K)\) containing the natural coordinates of the integration points within elements where \(K\) is the topological dimension of the element (e.g., 1 for segments, 2 for triangles/quadrangles, etc.).
element_indices (ArrayLike) – An array of shape \((N_{p},)\) containing the indices of each element corresponding to the \(N_{p}\) integration points.
n_vertices (Optional[Integral], optional (default:
None)) – The total number of vertices \(N_{v}\) in the mesh. If not provided, it will be inferred as the maximum node index inconnectivity_arrayplus one.sparse (bool, optional (default:
False)) – If set to True, the function will usescipy.sparseto create a sparse matrix representation of the shape function matrix.sparse_format (str, optional (default:
'csr')) – The format of the sparse matrix to create whensparseis True. Supported formats are'csr'for Compressed Sparse Row and'coo'for Coordinate format. Ignored ifsparseis False.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.tolerance (Real, optional (default:
0.0)) – Non-negative tolerance enlarging the reference element when checking whether the natural coordinates of a point are inside its element (seepysdic.fem.compute_shape_functions()). Useful for points located on the boundary of their element up to rounding errors. With the default0.0, only the points exactly inside the reference element are accepted.
- Returns:
shape_function_matrix – An array of shape \((N_{p}, N_{v})\) or sparse matrix containing the shape function values at each of the \(N_{p}\) integration points for all \(N_{v}\) nodes in the mesh.
- Return type:
Union[numpy.ndarray, scipy.sparse.csr_matrix, scipy.sparse.coo_matrix]
See also
pysdic.fem.compute_shape_functionsTo compute the shape functions at given natural coordinates within elements with shape \((N_{p}, N_{vpe})\).
pysdic.fem.assemble_shape_function_matrixTo assemble the shape function matrix from precomputed shape function values.
Examples
Lets construct a simple 2D mesh and build the shape function matrix at given integration points for triangular elements.
1import numpy 2from pysdic.fem import compute_shape_function_matrix 3 4connectivity_array = numpy.array( 5 [[0, 1, 2], 6 [0, 2, 3]] 7) 8 9natural_coordinates = numpy.array( 10 [[0.2, 0.3], 11 [0.6, 0.2]] 12) 13 14element_indices = numpy.array([0, 1]) 15 16shape_func_matrix = compute_shape_function_matrix( 17 connectivity_array=connectivity_array, 18 element_type='triangle_3', 19 natural_coordinates=natural_coordinates, 20 element_indices=element_indices 21) 22 23print(f"shape function matrix (shape={shape_func_matrix.shape}):") 24print(shape_func_matrix)
shape function matrix (shape=(2, 4)): [[0.5 0.2 0.3 0. ] [0.2 0. 0.6 0.2]]