Skip to content

Commit 64bc744

Browse files
committed
fix: adding option to not store vertices for 2d unstructured supports to save memory
1 parent 5164c47 commit 64bc744

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

LoopStructural/interpolators/supports/_2d_base_unstructured.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ def evaluate_gradient(self, evaluation_points, property_array):
234234
return values
235235

236236
def get_element_for_location(
237-
self, points: np.ndarray
237+
self,
238+
points: np.ndarray,
239+
return_verts=True,
240+
return_bc=True,
241+
return_inside=True,
242+
return_tri=True,
238243
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
239244
"""
240245
Determine the elements from a numpy array of points
@@ -249,14 +254,18 @@ def get_element_for_location(
249254
-------
250255
251256
"""
252-
verts = np.zeros((points.shape[0], self.dimension + 1, self.dimension))
257+
if return_verts:
258+
verts = np.zeros((points.shape[0], self.dimension + 1, self.dimension))
259+
else:
260+
verts = np.zeros((0, 0, 0))
253261
bc = np.zeros((points.shape[0], self.dimension + 1))
254262
tetras = np.zeros(points.shape[0], dtype="int64")
255263
inside = np.zeros(points.shape[0], dtype=bool)
256264
npts = 0
257265
npts_step = int(1e4)
258266
# break into blocks of 10k points
259267
while npts < points.shape[0]:
268+
print(npts, npts_step, points.shape[0])
260269
cell_index, inside = self.aabb_grid.position_to_cell_index(
261270
points[: npts + npts_step, :]
262271
)
@@ -266,6 +275,7 @@ def get_element_for_location(
266275
row = tetra_indices.row
267276
col = tetra_indices.col
268277
# using returned indexes calculate barycentric coords to determine which tetra the points are in
278+
269279
vertices = self.nodes[self.elements[col, : self.dimension + 1]]
270280
pos = points[row, : self.dimension]
271281
row = tetra_indices.row
@@ -286,8 +296,8 @@ def get_element_for_location(
286296
c[:, 2] = 1.0 - c[:, 0] - c[:, 1]
287297

288298
mask = np.all(c >= 0, axis=1)
289-
290-
verts[: npts + npts_step, :, :][row[mask], :, :] = vertices[mask, :, :]
299+
if return_verts:
300+
verts[: npts + npts_step, :, :][row[mask], :, :] = vertices[mask, :, :]
291301
bc[: npts + npts_step, :][row[mask], :] = c[mask, :]
292302
tetras[: npts + npts_step][row[mask]] = col[mask]
293303
inside[: npts + npts_step][row[mask]] = True
@@ -312,5 +322,5 @@ def get_element_gradient_for_location(
312322
-------
313323
314324
"""
315-
verts, c, tri, inside = self.get_element_for_location(pos)
325+
verts, c, tri, inside = self.get_element_for_location(pos, return_verts=False)
316326
return self.evaluate_shape_derivatives(pos, tri)

LoopStructural/interpolators/supports/_2d_p1_unstructured.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def evaluate_shape_derivatives(self, locations, elements=None):
6161

6262
def evaluate_shape(self, locations):
6363
locations = np.array(locations)
64-
vertices, c, tri, inside = self.get_element_for_location(locations)
64+
vertices, c, tri, inside = self.get_element_for_location(locations, return_verts=False)
6565
# c = np.dot(np.array([1,x,y]),np.linalg.inv(M)) # convert to barycentric coordinates
6666
# order of bary coord is (1-s-t,s,t)
6767
N = c # np.zeros((c.shape[0],3)) #evaluate shape functions at barycentric coordinates

0 commit comments

Comments
 (0)