From b5d32058cd9c63b6f1b46a1566e134f3a0e0e732 Mon Sep 17 00:00:00 2001 From: Francois Colleoni Date: Wed, 12 Jul 2023 11:43:42 +0200 Subject: [PATCH] FIX: resolve issue on flow distances computation This commit fix an error when flow distances are computed on adjacent non-nested catchments --- doc/source/release/0.5.0-notes.rst | 11 +++++++++-- smash/mesh/mw_meshing.f90 | 14 +++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/doc/source/release/0.5.0-notes.rst b/doc/source/release/0.5.0-notes.rst index 37a30cce..1995a957 100644 --- a/doc/source/release/0.5.0-notes.rst +++ b/doc/source/release/0.5.0-notes.rst @@ -92,10 +92,17 @@ Segmentation algorithm If multiple events are detected, the duration of the merged event is no longer constrained by the max duration parameter. Instead, its duration may exceed this value. -``smash.generate_mesh`` segmentation fault -****************************************** +Catchment delineation segmentation fault +**************************************** An error occured when two neighboring cells have antagonistic flow directions ``(1, 5)``, ``(2, 6)``, ``(3, 7)``, ``(4, 8)``. This should be corrected directly in the flow direction file but to avoid segmentation faults when the maximum number of recursions has been reached, a check is added to the code to exit recursion in that case. See issue `#31 `__. + +Catchment flow distances on adjacent non-nested catchments +********************************************************** + +There is a bug when calculating flow distances when two adjacent catchments are considered in the mesh but non-nested. During calculation, a flag is set around the 8 adjacent cells of each upstream cell and not on the upstream cell in particular. As a result, a gauge stuck to a cell of another catchment will not be considered as a non-nested gauge and will be filled with -99. The bug has been solved by flagging only the upstream cell and not the 8 adjacent cells. + +See issue `#38 `__. diff --git a/smash/mesh/mw_meshing.f90 b/smash/mesh/mw_meshing.f90 index d566d2c6..5f9b82aa 100644 --- a/smash/mesh/mw_meshing.f90 +++ b/smash/mesh/mw_meshing.f90 @@ -345,18 +345,18 @@ recursive subroutine distance_upstream_cells(nrow, ncol, ng, & row_imd = row + drow(i) col_imd = col + dcol(i) - do j = 1, ng - - if (row_imd .eq. row_dln(j) .and. & - & col_imd .eq. col_dln(j)) flag(j) = 1 - - end do - if (row_imd .gt. 0 .and. row_imd .le. nrow .and. & & col_imd .gt. 0 .and. col_imd .le. ncol) then if (flwdir(row_imd, col_imd) .eq. i) then + do j = 1, ng + + if (row_imd .eq. row_dln(j) .and. & + & col_imd .eq. col_dln(j)) flag(j) = 1 + + end do + !% Avoid to compute square root if not diagonal if (dcol(i) .eq. 0) then