pysdic.assemble_shape_function_matrix#
- assemble_shape_function_matrix(shape_functions, connectivity, element_indices, n_vertices=None, *, sparse=False, skip_m1=True, default=0.0)[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
connectivityandelement_indiceswill be converted tonumpy.int64.
Warning
No tests are performed to check if the inputs array are consistent (e.g., if the connectivity contains invalid vertex indices, …). Only shapes are validated. The behavior of the function is undefined in this case.
Important
When using
-1inelement_indicesfor invalid elements, ensure to setskip_m1toTrueto avoid indexing errors.- Parameters:
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.
connectivity (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.
n_vertices (Optional[Integral], optional) – The total number of vertices \(N_{v}\) in the mesh. If not provided, it will be inferred as the maximum node index in
connectivityplus one.sparse (
bool, optional) – If set toTrue, the function will usescipy.sparseto create a sparse matrix representation of the shape function matrix. Default isFalse.skip_m1 (
bool, optional) – If set toTrue, any element index of -1 inelement_indiceswill result in the corresponding shape function values being set todefault. Default isTrue.default (Real, optional) – The default value to assign to shape function values for integration points associated with an element index of -1 when
skip_m1isTrue. Default is0.0. Only used for non-sparse matrix construction. For sparse matrices, zero-filling is used.
- 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]
See also
pysdic.compute_shape_functionsTo compute the shape functions at given natural coordinates within elements with shape \((N_{p}, N_{vpe})\).
pysdic.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.
1import numpy 2from pysdic import assemble_shape_function_matrix 3from pysdic import compute_triangle_3_shape_functions 4 5vertices_coordinates = numpy.array( 6 [[0.0, 0.0], 7 [1.0, 0.0], 8 [1.0, 1.0], 9 [0.0, 1.0]] 10) 11 12connectivity = numpy.array( 13 [[0, 1, 2], 14 [0, 2, 3]] 15) 16 17natural_coordinates = numpy.array( 18 [[0.2, 0.3], 19 [0.6, 0.2]] 20) 21 22element_indices = numpy.array([0, 1]) 23 24shape_functions = compute_triangle_3_shape_functions(natural_coordinates) 25 26shape_func_matrix = assemble_shape_function_matrix( 27 shape_functions=shape_functions, 28 connectivity=connectivity, 29 element_indices=element_indices 30) 31 32print(f"shape function matrix (shape={shape_func_matrix.shape}):") 33print(shape_func_matrix)
shape function matrix (shape=(2, 4)): [[0.5 0.2 0.3 0. ] [0.2 0. 0.6 0.2]]