Skip to content

Commit

Permalink
Merge pull request festim-dev#665 from JonathanGSDUFOUR/mesh_values_a…
Browse files Browse the repository at this point in the history
…s_vertices

Mesh1D vertices to accept list
  • Loading branch information
jhdark authored Dec 13, 2023
2 parents 2bbdf4e + 0d279c6 commit b7aca0d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions festim/mesh/mesh_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Mesh1D(F.Mesh):
1D Mesh
Args:
vertices (list): the mesh x-coordinates (m)
vertices (list or np.ndarray): the mesh x-coordinates (m)
Attributes:
vertices (list): the mesh x-coordinates (m)
vertices (np.ndarray): the mesh x-coordinates (m)
"""

def __init__(self, vertices, **kwargs) -> None:
Expand All @@ -23,6 +23,14 @@ def __init__(self, vertices, **kwargs) -> None:
mesh = self.generate_mesh()
super().__init__(mesh=mesh, **kwargs)

@property
def vertices(self):
return self._vertices

@vertices.setter
def vertices(self, value):
self._vertices = np.sort(np.unique(value)).astype(float)

def generate_mesh(self):
"""Generates a 1D mesh"""
gdim, shape, degree = 1, "interval", 1
Expand Down
8 changes: 8 additions & 0 deletions test/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ def test_meshtags_from_xdmf(tmp_path, mesh):
assert volume_meshtags.values.all() == my_model.volume_meshtags.values.all()
assert facet_meshtags.dim == my_model.facet_meshtags.dim
assert facet_meshtags.values.all() == my_model.facet_meshtags.values.all()


@pytest.mark.parametrize("vertices", [[1, 2, 3, 4], [0, 0.1, 0.2, 0.3, 0.4, 0.5]])
def test_mesh_vertices_from_list(vertices):
"""Check that giving vertices as a list is correctly processed and ends up as a np.ndarray for the mesh"""
my_mesh = F.Mesh1D(vertices=vertices)

assert isinstance(my_mesh.vertices, np.ndarray)

0 comments on commit b7aca0d

Please sign in to comment.