pysdic.fem.compute_property_projection#
- compute_property_projection(point_values, connectivity_array, element_type, natural_coordinates, element_indices, point_weights=None, *, n_vertices=None, sparse=False, allow_unlocated_points=False, tolerance=0.0, default=nan, return_unaffected=False)[source]#
Project a property defined at integration points within elements back to the nodes of a mesh using mesh and integration point information.
This function combines the computation of the shape function matrix and the assembly of the property projection for the entire mesh.
projected_values[i]contains the projected property at the node \(i\).Note
Inputs
point_values,natural_coordinatesandpoint_weightswill 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 points with element index
-1(only accepted withallow_unlocated_points=True), a zero weight or non-finite values are ignored. A located point whose natural coordinates are outside the reference element (enlarged bytolerance) raises aValueError. The nodes that are not affected by any remaining point are set todefault.- Parameters:
point_values (ArrayLike) – An array of shape \((N_{p}, P)\) containing the property values defined at the \(N_{p}\) integration points. If 1D-array is provided, it will be treated as a single-component property of shape \((N_{p}, 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_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.
point_weights (Optional[ArrayLike], optional (default:
None)) – An array of shape \((N_{p},)\) containing the non-negative weights associated with each integration point. If not provided, all weights will be assumed to be equal to one.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 index inconnectivity_arrayplus one.sparse (bool, optional (default:
False)) – If set to True, the shape functions matrix will be constructed as a sparse matrix to optimize memory usage for large meshes.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.default (Real, optional (default:
numpy.nan)) – The value assigned to the nodes that are not affected by any point (no information to project).return_unaffected (bool, optional (default:
False)) – If set to True, the function will return a tuple containing the projected values and a boolean mask indicating which nodes were unaffected by any integration point.
- Returns:
projected_values (numpy.ndarray) – An array of shape \((N_{v}, P)\) containing the projected property values at the nodes of the mesh.
unaffected_mask (numpy.ndarray) – Only returned if
return_unaffectedis True. A boolean array of shape \((N_{v},)\) indicating which nodes were unaffected by any integration point (True for unaffected nodes). These nodes are set todefault.
- Return type:
Notes
See the documentation of
pysdic.fem.assemble_property_projection()for the mathematical formulation and demonstration of the projection process.See also
pysdic.fem.compute_shape_functionsTo compute the shape functions at given natural coordinates within elements.
pysdic.fem.assemble_property_projectionTo project properties defined at integration points back to the nodes of the mesh using a precomputed shape functions matrix.
pysdic.fem.compute_property_interpolationTo interpolate properties defined at the nodes of the mesh to integration points within elements.
Examples
Lets construct a simple 2D mesh, interpolate a scalar property at 4 points per element and project it back to the nodes. An extra point outside the mesh is ignored by the projection.
1import numpy 2from pysdic.fem import ( 3 compute_property_projection, 4 compute_property_interpolation 5) 6 7connectivity_array = numpy.array( 8 [[0, 1, 2], 9 [0, 2, 3]] 10) 11N_e = connectivity_array.shape[0] 12 13nodal_values = numpy.array([10.0, 20.0, 30.0, 40.0]) # Scalar property 14 15# Define natural coordinates for interpolation (4 points per element) 16natural_coordinates = numpy.array( 17 [[0.3, 0.3], 18 [0.2, 0.5], 19 [0.5, 0.2], 20 [0.1, 0.1]] 21) 22natural_coordinates = numpy.vstack([natural_coordinates] * N_e + [[0.0, 0.0]]) 23element_indices = numpy.append(numpy.repeat(numpy.arange(N_e), 4), -1) 24 25point_values = compute_property_interpolation( 26 nodal_values=nodal_values, 27 connectivity_array=connectivity_array, 28 element_type='triangle_3', 29 natural_coordinates=natural_coordinates, 30 element_indices=element_indices, 31 allow_unlocated_points=True, 32) # NaN for the last point 33 34# Now project back to the nodes 35projected_values = compute_property_projection( 36 point_values=point_values, 37 connectivity_array=connectivity_array, 38 element_type='triangle_3', 39 natural_coordinates=natural_coordinates, 40 element_indices=element_indices, 41 sparse=True, 42 allow_unlocated_points=True, # The last point is ignored 43) 44 45print(f"projected values (shape={projected_values.shape}):") 46print(projected_values)
projected values (shape=(4, 1)): [[10.] [20.] [30.] [40.]]