Skip to content

Commit

Permalink
Multi image hydrology timeloop sync and output bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad-sharior committed Jul 19, 2023
1 parent 54d2142 commit d55e2b8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
15 changes: 15 additions & 0 deletions definitions/define_settings.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1503,6 +1503,21 @@ subroutine define_settings_load()
if (found) setting%Output%DataOut%isVolumeOut = logical_value
if ((.not. found) .and. (jsoncheck)) stop "Error - json file - setting " // 'Output.DataOut.isVolumeOut not found'

!% Dataout.isVolumeConsOut
call json%get('Output.DataOut.isVolumeConsOut', logical_value, found)
if (found) setting%Output%DataOut%isVolumeConsOut = logical_value
if ((.not. found) .and. (jsoncheck)) stop "Error - json file - setting " // 'Output.DataOut.isVolumeConsOut not found'

!% Dataout.isVolumeOverflowOut
call json%get('Output.DataOut.isVolumeOverflowOut', logical_value, found)
if (found) setting%Output%DataOut%isVolumeOverflowOut = logical_value
if ((.not. found) .and. (jsoncheck)) stop "Error - json file - setting " // 'Output.DataOut.isVolumeOverflowOut not found'

!% Dataout.isVolumePondedOut
call json%get('Output.DataOut.isVolumePondedOut', logical_value, found)
if (found) setting%Output%DataOut%isVolumePondedOut = logical_value
if ((.not. found) .and. (jsoncheck)) stop "Error - json file - setting " // 'Output.DataOut.isVolumePondedOut not found'

!% Dataout.isWaveSpeedOut
call json%get('Output.DataOut.isWaveSpeedOut', logical_value, found)
if (found) setting%Output%DataOut%isWaveSpeedOut = logical_value
Expand Down
2 changes: 1 addition & 1 deletion main/output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ subroutine outputML_element_outtype_selection ()
output_typeMultiplyByBarrels_elemR(ii) = oneI
end if
!% --- Face-averaged flow rate
if (setting%Output%DataOut%isFlowrateOut) then
if (setting%Output%DataOut%isFlowrateAvgOut) then
ii = ii+1
output_types_elemR(ii) = er_Flowrate
output_typenames_elemR(ii) = 'FaceAverageFlowrate'
Expand Down
38 changes: 26 additions & 12 deletions timeloop/timeloop.f90
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,10 @@ subroutine tl_outerloop ( &
call tl_hydraulics()

!% --- accumulate RunOn from hydraulic elements to subcatchments
if ((setting%Simulation%useHydrology) .and. (any(subcatchYN(:,sYN_hasRunOn)))) then
call tl_subcatchment_accumulate_runon ()
if (setting%Simulation%useHydrology) then
if (any(subcatchYN(:,sYN_hasRunOn))) then
call tl_subcatchment_accumulate_runon ()
end if
end if

!% --- close the clock tick for hydraulic loop evaluation
Expand Down Expand Up @@ -880,8 +882,9 @@ subroutine tl_increment_timestep_and_counters ( &
end if

!% --- Ensure that all processors use the same time step.
!% Find the minimum hydraulics time and store accross all processors.
!% Find the minimum hydraulics and hydrology time and store accross all processors.
call co_min(nextHydraulicsTime)
call co_min(nextHydrologyTime)
!% --- Take the nextTime as the minimum of either the Hydrology or Hydraulics time
!% Done on a single processor because they all should have identical nextHydrologyTIme
nextTime = min(nextHydraulicsTime, nextHydrologyTime)
Expand Down Expand Up @@ -943,6 +946,7 @@ subroutine tl_update_hydraulics_timestep(inSpinUpYN)
real(8), pointer :: nextHydraulicsTime, lastHydraulicsTime

integer :: neededSteps, pindex(1)
integer(kind=8), pointer :: lastCheckStep

character(64) :: subroutine_name = 'tl_update_hydraulics_timestep'
!%-------------------------------------------------------------------
Expand All @@ -954,7 +958,8 @@ subroutine tl_update_hydraulics_timestep(inSpinUpYN)
useHydrology => setting%Simulation%useHydrology
matchHydrologyStep => setting%Time%matchHydrologyStep
nextHydraulicsTime => setting%Time%Hydraulics%NextTime
lastHydraulicsTime => setting%Time%Hydraulics%LastTime
lastHydraulicsTime => setting%Time%Hydraulics%LastTime
lastCheckStep => setting%VariableDT%LastCheckStep
timeNow => setting%Time%Now
!%----------------------------------------------------------------------
!% --- note oldDT is NOT a alias as we want it fixed while newDT
Expand Down Expand Up @@ -987,6 +992,13 @@ subroutine tl_update_hydraulics_timestep(inSpinUpYN)
!% --- get the dt
call tl_DT_standard(newDT, oldDT, oldCFL)

!% --- match the last check step across images.
!% this ensures new timestep is shecked at
!% the same time across all images. as a result
!% consistancy is maintained across single vs
!% multi processor simulations
call co_max(lastCheckStep)

!% --- neededSteps is irrelevant without hydrology matching,
!% but this using 3 forces a rounding operation below
neededSteps = 3
Expand Down Expand Up @@ -1299,7 +1311,7 @@ real(8) function tl_get_max_CFL(thisCol,dt) result (outvalue)
wavespeed(thisP) = zeroR
Pcelerity(thisP) = zeroR
endwhere

!% --- set the outvalue
if (Npack > 0) then
if (setting%Solver%PreissmannSlot%useSlotTF) then
Expand Down Expand Up @@ -1666,13 +1678,15 @@ subroutine tl_DT_hydrology_match (newDT, oldDT, oldCFL, neededSteps)

real(8), pointer :: nextHydrologyTime, LastHydraulicsTime
real(8), pointer :: CFL_hi, dtTol
integer(kind=8), pointer :: lastCheckStep
real(8) :: timeLeft, timeLeftCFL
!%------------------------------------------------------------------
!% Aliases
CFL_hi => setting%VariableDT%CFL_hi
dtTol => setting%Time%DtTol
nextHydrologyTime => setting%Time%Hydrology%NextTime
lastHydraulicsTime => setting%Time%Hydraulics%LastTime
lastCheckStep => setting%VariableDT%LastCheckStep
!%------------------------------------------------------------------

!% --- for combined hydrology and hydraulics
Expand Down Expand Up @@ -1711,6 +1725,13 @@ subroutine tl_DT_hydrology_match (newDT, oldDT, oldCFL, neededSteps)
neededSteps = 3
end if

!% --- match the last check step across images.
!% this ensures new timestep is shecked at
!% the same time across all images. as a result
!% consistancy is maintained across single vs
!% multi processor simulations
call co_max(lastCheckStep)

end subroutine tl_DT_hydrology_match
!%
!%==========================================================================
Expand Down Expand Up @@ -1819,13 +1840,6 @@ subroutine tl_DT_standard (newDT, oldDT, oldCFL)
end if
endif

!% --- match the last check step across images.
!% this ensures new timestep is shecked at
!% the same time across all images. as a result
!% consistancy is maintained across single vs
!% multi processor simulations
call co_max(lastCheckStep)

!% --- check for minimum limit
if (setting%Limiter%Dt%UseLimitMinYN) then
if (newDT < setting%Limiter%Dt%Minimum) then
Expand Down

0 comments on commit d55e2b8

Please sign in to comment.