Skip to content

Commit 5f87d41

Browse files
committed
Bug fixes
1 parent d4b4a8a commit 5f87d41

7 files changed

Lines changed: 31 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to the model will be documented in this file. Breaking chang
44

55
## [Unreleased]
66

7+
## [0.0.7] - 2026-08-19
8+
9+
### Fixed
10+
11+
- Fixed `V_w_b` being carried between iterations in `BedSediment%deposit` (`depositSediment1`). It is assigned only inside the `if (O%A_f(s) > 0 .or. O%A_w(s) > 0)` capacity check but consumed unconditionally when tallying `V_w_tot`, so a layer with no free capacity re-added the previous iteration's value, compounding once per sediment layer and inflating the water volume returned to the water column. It is now reset at the top of each layer iteration. `V_w_tot` only feeds the reporting-only depth adjustment in `depositToBed`, so this makes no difference to model results (verified bit-identical over the Thames scenario), but the previous behaviour was unbounded.
12+
- `water__depth` (and the `depth(m)` CSV column) now report the hydraulic depth implied by the reach volume, `volume / bedArea`, rather than the `me%depth` attribute. `depositToBed` subtracts the water displaced into the bed sediment from `me%depth`, which left the reported depth inconsistent with the reported `water__volume` and `sediment__bed_area` by ~1e-4 relative.
13+
- Fixed an error stop in `depositToBed` when `&sediment > include_bed_sediment = .false.`. `V_water_toDeposit = .dp. depositRslt` sat outside the `includeBedSediment` block, so `depositRslt` was never assigned and asking it for its data aborted the run on the first time step with "Error trying to return 0D data as REAL(DP)". The extraction is now inside the block and `V_water_toDeposit` defaults to zero.
14+
715
## [0.0.6] - 2026-08-18
816

917
### Fixed
@@ -79,7 +87,8 @@ All notable changes to the model will be documented in this file. Breaking chang
7987
- Added option to aggregate CSV output for waterbodies at grid cell level, rather than breaking it down to waterbody level. Internal functions for aggregating to grid cell added (e.g. weighted means, fetching outflow reaches). This option can be used by specifying `&output > include_waterbody_breakdown = .false.` in the [model config file](./config.example/config.example.nml). Default is `.true.`.
8088
- This changelog.
8189

82-
[unreleased]: https://github.com/nerc-ceh/nanofase/compare/0.0.6...HEAD
90+
[unreleased]: https://github.com/nerc-ceh/nanofase/compare/0.0.7...HEAD
91+
[0.0.7]: https://github.com/nerc-ceh/nanofase/releases/tag/0.0.7
8392
[0.0.6]: https://github.com/nerc-ceh/nanofase/releases/tag/0.0.6
8493
[0.0.5]: https://github.com/nerc-ceh/nanofase/releases/tag/0.0.5
8594
[0.0.4]: https://github.com/nerc-ceh/nanofase/releases/tag/0.0.4

‎src/BedSediment/BedSedimentModule.f90‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ function depositSediment1(me, FS_dep) result(r)
521521
do s = 1, me%nSizeClasses ! now add in the depositing sediment, work by size class
522522
do l = C%nSedimentLayers, 1, -1 ! start with the bottom layer and work upwards
523523
if (FS_dep(s)%M_f() > 0.0_dp) then
524+
V_w_b = 0.0_dp ! reset the receiving layer's water requirement for THIS layer.
525+
! V_w_b is only assigned inside the capacity check below but is
526+
! consumed unconditionally when tallying V_w_tot, so without this
527+
! reset a layer with no free capacity re-adds the previous
528+
! iteration's value, compounding once per layer
524529
associate(O => me%colBedSedimentLayers(l)%item) ! size class S in Layer L
525530
if (O%A_f(s) > 0.0_dp .or. &
526531
O%A_w(s) > 0.0_dp) then ! if there is available capacity in this layer, add deposition here

‎src/Data/DataOutputModule.f90‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ subroutine updateWaterDataOutput(me, t, tInChunk, x, y, date, easts, norths)
207207
trim(str(sum(reach%j_spm%inflow))) // "," // trim(str(sum(reach%j_spm%outflow))) // "," // &
208208
trim(str(sum(reach%j_spm%bankErosion))) // ","
209209
end if
210-
write(iouOutputWater, '(a)') trim(str(reach%volume)) // "," // trim(str(reach%depth)) // "," // &
210+
write(iouOutputWater, '(a)') trim(str(reach%volume)) &
211+
// "," // trim(str(divideCheckZero(reach%volume, reach%bedArea))) // "," // &
211212
trim(str(reach%Q%outflow / C%timeStep))
212213
end associate
213214
end do

‎src/Data/NetCDFOutputModule.f90‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ subroutine updateWaterNetCDFOutput(me, t, tInChunk, x, y)
205205
me%output_water__m_spm_bank_erosion(w,x,y,tInChunk) = sum(reach%j_spm%bankErosion)
206206
end if
207207
me%output_water__volume(w,x,y,tInChunk) = reach%volume
208-
me%output_water__depth(w,x,y,tInChunk) = reach%depth
208+
me%output_water__depth(w,x,y,tInChunk) = divideCheckZero(reach%volume, reach%bedArea)
209209
me%output_water__flow(w,x,y,tInChunk) = reach%Q%outflow / C%timeStep
210210
! If we're in iterative write mode, then write straight to the NetCDF file, which is time-indexed
211211
! by the whole batch, not just this chunk
@@ -235,7 +235,7 @@ subroutine updateWaterNetCDFOutput(me, t, tInChunk, x, y)
235235
call me%nc__water__m_spm_bank_erosion%setData(sum(reach%j_spm%bankErosion), start=[w,x,y,t])
236236
end if
237237
call me%nc__water__volume%setData(reach%volume, start=[w,x,y,t])
238-
call me%nc__water__depth%setData(reach%depth, start=[w,x,y,t])
238+
call me%nc__water__depth%setData(divideCheckZero(reach%volume, reach%bedArea), start=[w,x,y,t])
239239
call me%nc__water__flow%setData(reach%Q%outflow / C%timeStep, start=[w,x,y,t])
240240
end if
241241
end associate

‎src/GridCell/GridCellModule.f90‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,11 @@ function getWaterDepthGridCell(me) result(waterDepth)
10061006
integer :: i
10071007
! Loop over reaches and get their depths and lengths
10081008
do i = 1, me%nReaches
1009-
waterDepth_i(i) = me%colRiverReaches(i)%item%depth
1009+
! Report the hydraulic depth implied by the reach volume, rather than me%depth:
1010+
! depositToBed subtracts the water displaced into the bed sediment from me%depth,
1011+
! which leaves the reported depth inconsistent with the reported volume and bed area
1012+
waterDepth_i(i) = divideCheckZero(me%colRiverReaches(i)%item%volume, &
1013+
me%colRiverReaches(i)%item%bedArea)
10101014
lengths(i) = me%colRiverReaches(i)%item%length
10111015
end do
10121016
waterDepth = weightedAverage(waterDepth_i, lengths)

‎src/VersionModule.f90‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module VersionModule
22
implicit none
3-
character(len=17), parameter :: MODEL_VERSION = "0.0.6"
3+
character(len=17), parameter :: MODEL_VERSION = "0.0.7"
44
end module

‎src/WaterBody/ReachModule.f90‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,20 @@ function depositToBedReach(me, spmDep) result(rslt)
275275
)
276276
end do
277277

278+
! Default to no water being deposited, in case we're not modelling bed sediment
279+
V_water_toDeposit = 0.0_dp
278280
if (C%includeBedSediment) then
279281
! Deposit the fine sediment to the bed sediment
280282
depositRslt = Me%bedSediment%deposit(fineSed)
281283
call rslt%addErrors(.errors. depositRslt)
282284
if (rslt%hasCriticalError()) then
283285
return
284286
end if
287+
! Retrieve the amount of water to be taken from the reach. This must be inside the
288+
! includeBedSediment block: depositRslt is only set by the deposit call above, and
289+
! asking an unset Result0D for its data is an error stop
290+
V_water_toDeposit = .dp. depositRslt ! [m3/m2]
285291
end if
286-
! TODO add error handling to line above as it causes a crash if there is a critical error in the called method
287-
! Retrieve the amount of water to be taken from the reach
288-
V_water_toDeposit = .dp. depositRslt ! [m3/m2]
289292
! Subtract that volume for the reach (as a depth). This doesn't have any effect on
290293
! the model calculations, as the model recalculates depth depth on hydrology at the
291294
! start of every timestep. However, it is this updated depth that is saved to data.

0 commit comments

Comments
 (0)