Skip to content

Commit

Permalink
Fix segment labelling
Browse files Browse the repository at this point in the history
  • Loading branch information
danshapero committed Aug 6, 2024
1 parent ecb95b8 commit ef3ce3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
50 changes: 24 additions & 26 deletions src/icepack/meshing.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,27 +222,6 @@ def normalize(input_collection):
return collection


def _add_loop_to_geometry(geometry, multi_line_string):
line_loop = []
for line_index, line_string in enumerate(multi_line_string):
arc = []
for index in range(len(line_string) - 1):
x1 = line_string[index]
x2 = line_string[index + 1]
arc.append(geometry.add_line(x1, x2))

num_lines = len(multi_line_string)
next_line_string = multi_line_string[(line_index + 1) % num_lines]
x1 = line_string[-1]
x2 = next_line_string[0]
arc.append(geometry.add_line(x1, x2))

geometry.add_physical(arc)
line_loop.extend(arc)

return geometry.add_curve_loop(line_loop)


def collection_to_geo(collection, lcar=10e3):
r"""Convert a GeoJSON FeatureCollection into pygmsh geometry that can then
be transformed into an unstructured triangular mesh"""
Expand All @@ -261,12 +240,31 @@ def collection_to_geo(collection, lcar=10e3):
for feature in features
]

line_loops = [
_add_loop_to_geometry(geometry, multi_line_string)
for multi_line_string in points
]
label_count = 0
line_loops = []
for multi_line_string in points:
line_loop = []
for line_index, line_string in enumerate(multi_line_string):
arc = []
for index in range(len(line_string) - 1):
x1 = line_string[index]
x2 = line_string[index + 1]
arc.append(geometry.add_line(x1, x2))

num_lines = len(multi_line_string)
next_line_string = multi_line_string[(line_index + 1) % num_lines]
x1 = line_string[-1]
x2 = next_line_string[0]
arc.append(geometry.add_line(x1, x2))

label_count += 1
geometry.add_physical(arc, label=str(label_count))
line_loop.extend(arc)

line_loops.append(geometry.add_curve_loop(line_loop))

plane_surface = geometry.add_plane_surface(line_loops[0], line_loops[1:])
geometry.add_physical(plane_surface)
geometry.add_physical(plane_surface, label="dummy")
mesh = geometry.generate_mesh()

return mesh
Expand Down
4 changes: 2 additions & 2 deletions test/meshing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def test_pygmsh7():
assert legend is not None


@pytest.mark.xfail
@pytest.mark.parametrize("input_data", test_data)
def test_converting_to_geo(tmpdir, input_data):
collection = input_data()
geometry = icepack.meshing.collection_to_geo(collection, lcar=1e-2)
print(geometry)
assert len(geometry.points) > 0
assert len(geometry.get_cells_type("triangle")) > 0


@pytest.mark.parametrize("input_data", test_data)
Expand Down

0 comments on commit ef3ce3c

Please sign in to comment.