pysdic.fem.assemble_shape_function_matrix#
- assemble_shape_function_matrix(connectivity_array, element_indices, shape_functions, *, n_vertices=None, sparse=False, sparse_format='csr', allow_unlocated_points=False)[source]#
Assemble the shape function matrix \(\mathcal{N}\) at given integration points within elements with shape \((N_{p}, N_{v})\), from precomputed shape functions values with zero-filling for non-associated nodes/vertices.
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
shape_functionswill 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) is filled with zeros (no entry in sparse matrices), i.e. the point has a zero weight. A non-finite shape function value of a located point raises aValueError.- 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_indices (ArrayLike) – An array of shape \((N_{p},)\) containing the indices of each element corresponding to the \(N_{p}\) integration points.
shape_functions (ArrayLike) – An array of shape \((N_{p}, N_{vpe})\) containing the shape function values evaluated at \(N_{p}\) points for the \(N_{vpe}\) nodes of the element.
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.
- 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.compute_shape_function_matrixTo compute the shape function matrix directly from natural coordinates and mesh connectivity.
Examples
Lets construct a simple 2D mesh and build the shape function matrix at given integration points for triangular elements. The last point is outside the mesh (element index
-1).1import numpy 2from pysdic.fem import assemble_shape_function_matrix 3from pysdic.fem import compute_triangle_3_shape_functions 4 5connectivity_array = numpy.array( 6 [[0, 1, 2], 7 [0, 2, 3]] 8) 9 10natural_coordinates = numpy.array( 11 [[0.2, 0.3], 12 [0.6, 0.2], 13 [0.0, 0.0]] 14) 15 16element_indices = numpy.array([0, 1, -1]) 17 18shape_functions = compute_triangle_3_shape_functions(natural_coordinates) 19 20shape_func_matrix = assemble_shape_function_matrix( 21 connectivity_array=connectivity_array, 22 element_indices=element_indices, 23 shape_functions=shape_functions, 24 allow_unlocated_points=True, # Accept the -1 of the last point 25) 26 27print(f"shape function matrix (shape={shape_func_matrix.shape}):") 28print(shape_func_matrix)
shape function matrix (shape=(3, 4)): [[0.5 0.2 0.3 0. ] [0.2 0. 0.6 0.2] [0. 0. 0. 0. ]]