@@ -582,6 +582,30 @@ def sweep(Ct, Cu, mass, dt, Ts, ds, dn, us, un, w, zb=None, zne=None, rhog=2650.
582582 # print(np.shape(visited[0,:]==False))
583583 pickup [0 ,:,0 ] = pickup [1 ,:,0 ].copy ()
584584 pickup [- 1 ,:,0 ] = pickup [- 2 ,:,0 ].copy ()
585+
586+ # Apply non-erodible layer constraint to boundary cells that were set by copying
587+ if zb is not None and zne is not None :
588+ for boundary_row in [0 , Ct .shape [0 ] - 1 ]:
589+ for s in range (Ct .shape [1 ]):
590+ # Calculate total pickup for this cell
591+ total_pickup = 0.0
592+ for f in range (nf ):
593+ total_pickup += pickup [boundary_row , s , f ]
594+
595+ if total_pickup > 0 :
596+ # Calculate bed level change
597+ dz = total_pickup / (rhog * (1.0 - porosity ))
598+
599+ # Check if bed would drop below non-erodible layer
600+ if zb [boundary_row , s ] - dz < zne [boundary_row , s ]:
601+ # Limit pickup
602+ max_dz = max (0.0 , zb [boundary_row , s ] - zne [boundary_row , s ])
603+ max_pickup_total = max_dz * rhog * (1.0 - porosity )
604+
605+ if total_pickup > 0.0 :
606+ scale_factor = max_pickup_total / total_pickup
607+ for f in range (nf ):
608+ pickup [boundary_row , s , f ] *= scale_factor
585609
586610 k += 1
587611
@@ -657,8 +681,12 @@ def _solve_quadrant1(Ct, Cu, mass, pickup, dt, Ts, ds, dn, ufs, ufn, w, visited,
657681
658682 Ct [n , s , f ] = num_limited / den_limited
659683
660- # Apply non-erodible layer constraint if zb and zne are provided
661- if zb is not None and zne is not None :
684+ # Apply non-erodible layer constraint at domain boundaries only
685+ # Check if cell is at a boundary (any edge of domain)
686+ is_boundary = (n == 1 or n == Ct .shape [0 ] - 1 or
687+ s == 1 or s == Ct .shape [1 ] - 1 )
688+
689+ if zb is not None and zne is not None and is_boundary :
662690 # Calculate total pickup mass for this cell
663691 total_pickup = 0.0
664692 for f in range (nf ):
@@ -736,8 +764,12 @@ def _solve_quadrant2(Ct, Cu, mass, pickup, dt, Ts, ds, dn, ufs, ufn, w, visited,
736764
737765 Ct [n , s , f ] = num_limited / den_limited
738766
739- # Apply non-erodible layer constraint if zb and zne are provided
740- if zb is not None and zne is not None :
767+ # Apply non-erodible layer constraint at domain boundaries only
768+ # Check if cell is at a boundary (edges of domain)
769+ is_boundary = (n == 1 or n == Ct .shape [0 ] - 1 or
770+ s == 1 or s == Ct .shape [1 ] - 2 )
771+
772+ if zb is not None and zne is not None and is_boundary :
741773 # Calculate total pickup mass for this cell
742774 total_pickup = 0.0
743775 for f in range (nf ):
@@ -815,8 +847,12 @@ def _solve_quadrant3(Ct, Cu, mass, pickup, dt, Ts, ds, dn, ufs, ufn, w, visited,
815847
816848 Ct [n , s , f ] = num_limited / den_limited
817849
818- # Apply non-erodible layer constraint if zb and zne are provided
819- if zb is not None and zne is not None :
850+ # Apply non-erodible layer constraint at domain boundaries only
851+ # Check if cell is at a boundary (edges of domain)
852+ is_boundary = (n == 0 or n == Ct .shape [0 ] - 2 or
853+ s == 0 or s == Ct .shape [1 ] - 2 )
854+
855+ if zb is not None and zne is not None and is_boundary :
820856 # Calculate total pickup mass for this cell
821857 total_pickup = 0.0
822858 for f in range (nf ):
@@ -894,8 +930,12 @@ def _solve_quadrant4(Ct, Cu, mass, pickup, dt, Ts, ds, dn, ufs, ufn, w, visited,
894930
895931 Ct [n , s , f ] = num_limited / den_limited
896932
897- # Apply non-erodible layer constraint if zb and zne are provided
898- if zb is not None and zne is not None :
933+ # Apply non-erodible layer constraint at domain boundaries only
934+ # Check if cell is at a boundary (edges of domain)
935+ is_boundary = (n == 0 or n == Ct .shape [0 ] - 2 or
936+ s == 1 or s == Ct .shape [1 ] - 1 )
937+
938+ if zb is not None and zne is not None and is_boundary :
899939 # Calculate total pickup mass for this cell
900940 total_pickup = 0.0
901941 for f in range (nf ):
@@ -1004,8 +1044,12 @@ def _solve_generic_stencil(Ct, Cu, mass, pickup, dt, Ts, ds, dn, ufs, ufn, w, vi
10041044
10051045 Ct [n , s , f ] = num_lim / den_lim
10061046
1007- # Apply non-erodible layer constraint if zb and zne are provided
1008- if zb is not None and zne is not None :
1047+ # Apply non-erodible layer constraint at domain boundaries only
1048+ # Check if cell is at a boundary (edges of domain)
1049+ is_boundary = (n == 0 or n == Ct .shape [0 ] - 2 or
1050+ s == 1 or s == Ct .shape [1 ] - 1 )
1051+
1052+ if zb is not None and zne is not None and is_boundary :
10091053 # Calculate total pickup mass for this cell
10101054 total_pickup = 0.0
10111055 for f in range (nf ):
0 commit comments