Skip to content

Commit 858df41

Browse files
authored
Add Mesh.add_points(points) and Mesh.clear_points_without_cells() (#947)
* Add `Mesh.add_points(points)` and `Mesh.clear_points_without_cells()` * Update Examples to use the new mesh-methods
1 parent 87e7291 commit 858df41

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format
33

44
## [Unreleased]
55

6+
### Added
7+
- Add `Mesh.add_points(points)` to update the mesh with additional points.
8+
- Add `Mesh.clear_points_without_cells()` to clear the list of points without cells (useful for center-points of multi-point constraints).
9+
610
## [9.2.0] - 2025-03-04
711

812
### Added

examples/ex08_shear.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
a = min(L / n, H / n)
4545

4646
mesh = fem.Rectangle((0, 0), (L, H), n=(round(L / a), round(H / a)))
47-
mesh.update(points=np.vstack((mesh.points, [L / 2, 1.3 * H])))
48-
mesh.points_without_cells = np.array([], dtype=bool)
47+
mesh.add_points([L / 2, 1.3 * H])
48+
mesh.clear_points_without_cells()
4949

5050
# %%
5151
# A numeric quad-region created on the mesh in combination with a vector-valued

examples/ex19_taylor-hood.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
mesh = fem.Circle(n=6, sections=[0]).triangulate().add_midpoints_edges()
2121
mask = np.isclose(mesh.x**2 + mesh.y**2, 1, atol=0.05)
2222
mesh.points[mask] /= np.linalg.norm(mesh.points[mask], axis=1).reshape(-1, 1)
23-
mesh.update(points=np.vstack([mesh.points, [0, 1.1]]))
23+
mesh.add_points([0, 1.1])
24+
mesh.clear_points_without_cells()
2425

2526
# %%
2627
# Let's create a region for quadratic triangles and a mixed-field container with two

src/felupe/mesh/_mesh.py

+8
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,14 @@ def imshow(self, *args, ax=None, **kwargs):
323323

324324
return ax
325325

326+
def add_points(self, points):
327+
"Add additional points to the mesh."
328+
self.update(points=np.vstack([self.points, points]))
329+
330+
def clear_points_without_cells(self):
331+
"Clear the list of points without cells."
332+
self.points_without_cells = self.points_without_cells[:0]
333+
326334
def get_point_ids(self, value, fun=np.isclose, mode=np.all, **kwargs):
327335
"""Return point ids for points which are close to a given value.
328336

tests/test_mesh.py

+4
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ def test_mesh_update():
545545
mesh.update(points=new_points)
546546
region.reload(mesh)
547547

548+
# add additional point and clear points without cells
549+
mesh.add_points([2, 0, 0])
550+
mesh.clear_points_without_cells()
551+
548552

549553
def test_modify_corners():
550554
fem.Rectangle(n=6).modify_corners()

0 commit comments

Comments
 (0)