From 50f9854108264b99bc3e322059c9d73b37e8e5e5 Mon Sep 17 00:00:00 2001 From: elisalle Date: Tue, 24 Sep 2024 13:45:04 +0200 Subject: [PATCH 1/5] handle open profiles where the middle is higher than the sides --- .../grid/cross_section_definitions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/threedigrid_builder/grid/cross_section_definitions.py b/threedigrid_builder/grid/cross_section_definitions.py index b69059ad..5c082bf3 100644 --- a/threedigrid_builder/grid/cross_section_definitions.py +++ b/threedigrid_builder/grid/cross_section_definitions.py @@ -319,6 +319,19 @@ def tabulate_yz(shape, width, height): seen.add(x) zs[i] = x + # For open profiles where the left or right sides are not the maximum Z, + # we add a vertical line at each end such that the left and right sides are + # now the maximum Z. This ensures that the profile is not inverted by + # shapely when calculating the widths. + if not is_closed: + highest_z = np.max(zs) + if zs[0] < highest_z: + zs = np.concatenate(([highest_z], zs)) + ys = np.concatenate(([ys[0]], ys)) + if zs[-1] < highest_z: + zs = np.concatenate((zs, [highest_z])) + ys = np.concatenate((ys, [ys[-1]])) + # For open profiles, if left and right sides are not equal in Z, we envision a # vertical line from the left or right most point depending on which is lower. # This is to ensure that the width is non-decreasing for the remaining profile. From 52be1700587817aa7f691a387d8d55dc900a190c Mon Sep 17 00:00:00 2001 From: elisalle Date: Tue, 24 Sep 2024 13:45:25 +0200 Subject: [PATCH 2/5] add test for open profile with middle higher than sides --- .../tests/test_cross_section_definitions.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/threedigrid_builder/tests/test_cross_section_definitions.py b/threedigrid_builder/tests/test_cross_section_definitions.py index 21bc1c58..d0ca0ae6 100644 --- a/threedigrid_builder/tests/test_cross_section_definitions.py +++ b/threedigrid_builder/tests/test_cross_section_definitions.py @@ -381,6 +381,32 @@ def test_tabulate_inverted_egg(): ) ), ), + ( # Open profile, left side rises then falls + "0 5 10 15 20 25 30 35 40", + "5.2 5.26 5.25 5.2 5.1 5.1 0 5 5", + None, + None, + None, + None, + None, + 40.0, + 5.26, + np.column_stack( + ( + [0.0, 5.0, 5.0, 5.1, 5.1, 5.2, 5.2, 5.25, 5.26], + [0.0, 9.902, 14.902, 15.0, 20.005, 24.995, 25.008, 34.167, 40.0], + ) + ), + np.column_stack( + ( + [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0], + [5.2, 5.26, 5.25, 5.2, 5.1, 5.1, 0.0, 5.0, 5.0], + np.zeros(9, dtype=float), + np.zeros(9, dtype=float), + np.zeros(9, dtype=float), + ) + ), + ), ], ) def test_tabulate_yz( From 3e372619a66b2fba11b43eba1b99dcfc11a68551 Mon Sep 17 00:00:00 2001 From: elisalle Date: Tue, 24 Sep 2024 13:46:10 +0200 Subject: [PATCH 3/5] update changelog --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index c9e7a85f..654c874f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,7 @@ Changelog of threedigrid-builder ------------------- - Define new boundary condition types. +- Handle open YZ profiles correctly when the middle is higher than the sides. 1.19.0 (2024-09-10) From 20f956a3ca27eee8d2679e7d1c7c2136c63f971c Mon Sep 17 00:00:00 2001 From: elisalle Date: Tue, 24 Sep 2024 13:59:38 +0200 Subject: [PATCH 4/5] fix lint --- threedigrid_builder/tests/test_cross_section_definitions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/threedigrid_builder/tests/test_cross_section_definitions.py b/threedigrid_builder/tests/test_cross_section_definitions.py index d0ca0ae6..a1ac28fe 100644 --- a/threedigrid_builder/tests/test_cross_section_definitions.py +++ b/threedigrid_builder/tests/test_cross_section_definitions.py @@ -393,14 +393,14 @@ def test_tabulate_inverted_egg(): 5.26, np.column_stack( ( - [0.0, 5.0, 5.0, 5.1, 5.1, 5.2, 5.2, 5.25, 5.26], + [0.0, 5.0, 5.0, 5.1, 5.1, 5.2, 5.2, 5.25, 5.26], [0.0, 9.902, 14.902, 15.0, 20.005, 24.995, 25.008, 34.167, 40.0], ) ), np.column_stack( ( - [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0], - [5.2, 5.26, 5.25, 5.2, 5.1, 5.1, 0.0, 5.0, 5.0], + [0.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0], + [5.2, 5.26, 5.25, 5.2, 5.1, 5.1, 0.0, 5.0, 5.0], np.zeros(9, dtype=float), np.zeros(9, dtype=float), np.zeros(9, dtype=float), From 1e55127f0750fadff42cc3eea0bb8c489af46a62 Mon Sep 17 00:00:00 2001 From: elisalle Date: Tue, 24 Sep 2024 14:16:04 +0200 Subject: [PATCH 5/5] remove old code to equalise open yz profile sides since this is now handled separately --- threedigrid_builder/grid/cross_section_definitions.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/threedigrid_builder/grid/cross_section_definitions.py b/threedigrid_builder/grid/cross_section_definitions.py index 5c082bf3..2f1566ab 100644 --- a/threedigrid_builder/grid/cross_section_definitions.py +++ b/threedigrid_builder/grid/cross_section_definitions.py @@ -332,17 +332,6 @@ def tabulate_yz(shape, width, height): zs = np.concatenate((zs, [highest_z])) ys = np.concatenate((ys, [ys[-1]])) - # For open profiles, if left and right sides are not equal in Z, we envision a - # vertical line from the left or right most point depending on which is lower. - # This is to ensure that the width is non-decreasing for the remaining profile. - if not is_closed: - if zs[0] < zs[-1]: - zs = np.concatenate(([zs[-1]], zs)) - ys = np.concatenate(([ys[0]], ys)) - if zs[0] > zs[-1]: - zs = np.concatenate((zs, [zs[0]])) - ys = np.concatenate((ys, [ys[-1]])) - # shapely will automatically close an open profile profile = shapely.make_valid(shapely.polygons(np.array([ys, zs]).T))