16 use mo_kind,
only: i4, dp
17 use mo_message,
only: message, error_message
18 use mo_string_utils,
only : num2str
21 use mo_optimization_types,
only : optidata_sim
81 use mo_julian,
only : caldat, julday
82 use mo_string_utils,
only : num2str
87 use mo_constants,
only : hoursecs
153 use mo_utils,
only : ge
163 real(dp),
dimension(:),
optional,
intent(in) :: parameterset
165 integer(i4),
dimension(:),
optional,
intent(in) :: opti_domain_indices
167 logical,
optional,
intent(in) :: runoff_present
169 logical,
optional,
intent(in) :: BFI_present
171 integer(i4) :: i, iDomain, domainID
174 if (
present(runoff_present))
run_cfg%output_runoff = runoff_present
176 if (
present(bfi_present))
run_cfg%output_BFI = bfi_present
180 if (.not.
present(parameterset) .and.
optimize)
then
181 call error_message(
"mhm_interface_run_prepare: Can't optimize without parameter!")
182 else if (.not.
present(parameterset))
then
185 run_cfg%parameterset = parameterset
189 if (
optimize .and.
present(opti_domain_indices))
then
190 run_cfg%nDomains =
size(opti_domain_indices)
192 run_cfg%domain_indices = opti_domain_indices
202 if (
run_cfg%output_runoff)
then
204 idomain =
run_cfg%get_domain_index(i)
207 call error_message(
"***ERROR: runoff for domain", trim(num2str(domainid)),&
208 "can not be produced, since routing process is off in Process Matrix")
223 idomain =
run_cfg%get_domain_index(i)
229 call message(
' Resetting mHM states and fluxes from restart files ...')
246 integer(i4),
intent(inout) :: ndomains
254 integer(i4),
intent(in),
optional :: domain
256 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: smOptiSim
258 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: neutronsOptiSim
260 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: etOptiSim
262 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: twsOptiSim
264 integer(i4) :: iDomain, domainID
268 if (
present(domain))
run_cfg%selected_domain = domain
273 if (
present(etoptisim))
call etoptisim(idomain)%init(
l1_etobs(idomain))
275 if (
present(twsoptisim))
call twsoptisim(idomain)%init(
l1_twsaobs(idomain))
277 if (
present(neutronsoptisim))
call neutronsoptisim(idomain)%init(
l1_neutronsobs(idomain))
279 if (
present(smoptisim))
call smoptisim(idomain)%init(
l1_smobs(idomain))
293 run_cfg%InflowDischarge = 0._dp
299 call message(
' Resetting mRM states and fluxes from restart files for domain ', num2str(idomain),
' ...')
326 call run_cfg%domainDateTime%init(idomain)
336 logical,
intent(inout) :: time_loop_finished
337 time_loop_finished =
run_cfg%time_step ==
run_cfg%domainDateTime%nTimeSteps
344 integer(i4) :: iDomain, domainID, tt, jj, s1, e1
355 call run_cfg%domainDateTime%update_LAI_timestep()
360 time=
run_cfg%domainDateTime%newTime - 0.5_dp, &
369 fasp =
l1_fasp(s1 : e1, 1, 1), &
371 latitude = pack(
level1(idomain)%y,
level1(idomain)%mask), &
397 time =
run_cfg%domainDateTime%newTime - 0.5_dp, &
485 if (
run_cfg%tsRoutFactor .lt. 1._dp)
then
505 if ((tt ==
run_cfg%domainDateTime%nTimeSteps) .and. (mod(tt, nint(
run_cfg%tsRoutFactorIn)) /= 0_i4)) &
507 if ((mod(tt, nint(
run_cfg%tsRoutFactorIn)) .eq. 0_i4) .or. (tt .eq.
run_cfg%domainDateTime%nTimeSteps))
then
520 efecarea =
level1(idomain)%CellArea * 1.e-6_dp, &
541 efecarea =
level1(idomain)%CellArea * 1.e-6_dp, &
558 level1(idomain)%CellArea * 1.e-6_dp, &
560 level11(idomain)%CellArea * 1.e-6_dp, &
570 domain_mrm(idomain)%InflowGaugeIndexList(:), &
571 domain_mrm(idomain)%InflowGaugeHeadwater(:), &
602 run_cfg%InflowDischarge = 0._dp
605 if ((.not. (
run_cfg%tsRoutFactorIn .lt. 1._dp)) .and.
run_cfg%doRoute)
then
606 do jj = 1, nint(
run_cfg%tsRoutFactorIn)
610 run_cfg%InflowDischarge = 0._dp
623 call run_cfg%domainDateTime%increment()
626 if (
run_cfg%domainDateTime%is_new_year .and. tt <
run_cfg%domainDateTime%nTimeSteps)
then
631 if (
run_cfg%output_BFI .and. (
run_cfg%domainDateTime%tIndex_out > 0_i4) )
then
643 integer(i4) :: iDomain, tt, s0, e0
651 if ( (.not.
optimize) .and. (
run_cfg%domainDateTime%tIndex_out > 0_i4))
then
654 if (
run_cfg%domainDateTime%tIndex_out == 1)
then
671 if(tt ==
run_cfg%domainDateTime%nTimeSteps)
then
677 if (
run_cfg%domainDateTime%tIndex_out == 1)
then
681 s0 =
level0(idomain)%iStart
685 if (
run_cfg%domainDateTime%writeout(-2, tt))
then
689 if(tt ==
run_cfg%domainDateTime%nTimeSteps)
then
698 if (
run_cfg%domainDateTime%tIndex_out == 1)
then
735 if(tt ==
run_cfg%domainDateTime%nTimeSteps)
then
748 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: smOptiSim
750 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: neutronsOptiSim
752 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: etOptiSim
754 type(optidata_sim),
dimension(:),
optional,
intent(inout) :: twsOptiSim
756 integer(i4) :: gg, s1, e1, lcId
758 integer(i4) :: iDomain, tt
769 lcid =
run_cfg%domainDateTime%yId
776 if (
present(smoptisim))
then
780 call smoptisim(idomain)%average_per_timestep(
l1_smobs(idomain)%timeStepInput, &
781 run_cfg%domainDateTime%is_new_day,
run_cfg%domainDateTime%is_new_month,
run_cfg%domainDateTime%is_new_year)
783 if (tt /=
run_cfg%domainDateTime%nTimeSteps)
then
795 if (
present(neutronsoptisim))
then
800 if (
run_cfg%domainDateTime%is_new_day)
then
801 call neutronsoptisim(idomain)%average()
805 if (tt /=
run_cfg%domainDateTime%nTimeSteps)
then
807 call neutronsoptisim(idomain)%average_add(
l1_neutrons(s1 : e1))
817 if (
present(etoptisim))
then
821 call etoptisim(idomain)%increment_counter(
l1_etobs(idomain)%timeStepInput, &
822 run_cfg%domainDateTime%is_new_day,
run_cfg%domainDateTime%is_new_month,
run_cfg%domainDateTime%is_new_year)
825 if (tt /=
run_cfg%domainDateTime%nTimeSteps)
then
827 call etoptisim(idomain)%add(sum(
l1_aetsoil(s1 : e1, :), dim = 2) * &
828 run_cfg%L1_fNotSealed(s1 : e1, 1, lcid) + &
840 if (
present(twsoptisim))
then
844 call twsoptisim(idomain)%average_per_timestep(
l1_twsaobs(idomain)%timeStepInput, &
845 run_cfg%domainDateTime%is_new_day,
run_cfg%domainDateTime%is_new_month,
run_cfg%domainDateTime%is_new_year)
848 if (tt /=
run_cfg%domainDateTime%nTimeSteps)
then
867 integer(i4) :: iDomain
872 if (
allocated(
run_cfg%InflowDischarge))
deallocate(
run_cfg%InflowDischarge)
885 real(dp),
dimension(:, :),
allocatable,
optional,
intent(out) :: runoff
887 real(dp),
dimension(:),
allocatable,
optional,
intent(out) :: BFI
890 if (
present(bfi))
then
896 if (
allocated(
run_cfg%parameterset))
deallocate(
run_cfg%parameterset)
897 if (
allocated(
run_cfg%L1_fNotSealed))
deallocate(
run_cfg%L1_fNotSealed)
898 if (
allocated(
run_cfg%domain_indices))
deallocate(
run_cfg%domain_indices)
type for date time information with an increment subroutine
Provides structures needed by mHM, mRM and/or mpr.
character(256), dimension(:), allocatable, public mrmfilerestartin
logical, public restart_reset_fluxes_states
flag to reset fluxes and states read from restart to default values
character(256), dimension(:), allocatable, public mhmfilerestartin
real(dp), dimension(:), allocatable, public resolutionrouting
integer(i4), public ntstepday
integer(i4), dimension(:), allocatable, public warmingdays
integer(i4), dimension(:, :), allocatable, public lcyearid
type(period), dimension(:), allocatable, public simper
integer(i4), public timestep
logical, public read_restart
Provides structures needed by mhm_eval to store current run config.
type(run_cfg_t), public run_cfg
This is a container to hold all information while running mHM.
Provides structures needed by mHM, mRM and/or mpr.
real(dp), dimension(:), allocatable, public resolutionhydrology
real(dp), dimension(:, :), allocatable, target, public global_parameters
type(domain_meta), public domainmeta
integer(i4), dimension(nprocesses, 3), public processmatrix
type(grid), dimension(:), allocatable, target, public level1
type(grid), dimension(:), allocatable, target, public level0
Main global variables for mHM.
type(meteo_handler_type), public meteo_handler
the meteo handler class
real(dp), dimension(:), allocatable, public l1_slowrunoff
[mm TS-1] Slow runoff component
real(dp), dimension(:, :), allocatable, public l1_aetsoil
[mm TS-1] Actual ET from soil layers
real(dp), dimension(:), allocatable, public l1_rain
[mm TS-1] Rain precipitation depth
real(dp), dimension(:), allocatable, public l1_aetsealed
[mm TS-1] Real evap.
real(dp), dimension(:), allocatable, public l1_satstw
[mm] groundwater storage
logical, dimension(noutflxstate) outputflxstate
Define model outputs see "mhm_outputs.nml" dim1 = number of output variables to be written.
real(dp), dimension(:), allocatable, public l1_aetcanopy
[mm TS-1] Real evaporation intensity from canopy
type(optidata), dimension(:), allocatable, public l1_twsaobs
this stores L1_tws, the mask, the directory of the observerd data, and the timestepInput of the simul...
real(dp), dimension(:), allocatable, public l1_snow
[mm TS-1] Snow precipitation depth
real(dp), dimension(:), allocatable, public l1_preeffect
[mm TS-1] Effective precip.
type(optidata), dimension(:), allocatable, public l1_neutronsobs
real(dp), dimension(:), allocatable, public l1_inter
[mm] Interception
real(dp), dimension(:), allocatable, public neutron_integral_afast
pre-calculated integrand for
real(dp), dimension(:), allocatable, public l1_sealstw
[mm] Retention storage of impervious areas
real(dp), dimension(:), allocatable, public l1_percol
[mm TS-1] Percolation.
type(optidata), dimension(:), allocatable, public l1_smobs
real(dp), dimension(:, :), allocatable, public l1_soilmoist
[mm] Soil moisture of each horizon
integer(i4) timestep_model_outputs
timestep for writing model outputs
real(dp), dimension(int(yearmonths, i4)), public evap_coeff
[-] Evap.
real(dp), dimension(:), allocatable, public bfi_qbf_sum
q2 weighted sum for each domain
real(dp), dimension(:), allocatable, public bfi_qt_sum
q2 weighted sum for each domain
integer(i4) nsoilhorizons_sm_input
real(dp), dimension(:), allocatable, public l1_pet_calc
[mm TS-1] estimated/corrected potential evapotranspiration
real(dp), dimension(:), allocatable, public l1_unsatstw
[mm] upper soil storage
type(optidata), dimension(:), allocatable, public l1_etobs
real(dp), dimension(:), allocatable, public l1_melt
[mm TS-1] Melting snow depth.
real(dp), dimension(:), allocatable, public l1_fastrunoff
[mm TS-1] Fast runoff component
real(dp), dimension(:), allocatable, public l1_snowpack
[mm] Snowpack
real(dp), dimension(:), allocatable, public l1_neutrons
[mm] Ground Albedo Neutrons
real(dp), dimension(:), allocatable, public l1_prec_calc
[mm TS-1] precipitation for current time step
real(dp), dimension(:), allocatable, public l1_runoffseal
[mm TS-1] Direct runoff from impervious areas
real(dp), dimension(:, :), allocatable, public l1_infilsoil
[mm TS-1] Infiltration intensity each soil horizon
real(dp), dimension(:), allocatable, public l1_baseflow
[mm TS-1] Baseflow
real(dp), dimension(:), allocatable, public l1_throughfall
[mm TS-1] Throughfall.
real(dp), dimension(:), allocatable, public l1_temp_calc
[degC] temperature for current time step
real(dp), dimension(:), allocatable, public l1_total_runoff
[m3 TS-1] Generated runoff
Initialization of all state variables of mHM.
subroutine, public variables_default_init
Default initalization mHM related L1 variables.
subroutine, public fluxes_states_default_init
initialize fluxes and states with default values
Module providing interfaces for running preconfigured mHM.
subroutine mhm_interface_run_get_ndomains(ndomains)
get number of domains for looping
subroutine mhm_interface_run_prepare(parameterset, opti_domain_indices, runoff_present, bfi_present)
prepare single run of mHM
subroutine mhm_interface_run_write_output()
write output after current time-step
subroutine mhm_interface_run_prepare_domain(domain, etoptisim, twsoptisim, neutronsoptisim, smoptisim)
prepare single domain to run mHM on
subroutine mhm_interface_run_update_optisim(etoptisim, twsoptisim, neutronsoptisim, smoptisim)
add simulation data to optimization data types
subroutine mhm_interface_run_finished(time_loop_finished)
check if current time loop is finished
subroutine mhm_interface_run_do_time_step()
do one time-step on current domain
subroutine mhm_interface_run_finalize_domain()
finalize current domain after running
subroutine mhm_interface_run_finalize(runoff, bfi)
finalize run
Call all main processes of mHM.
subroutine, public mpr_eval(parameterset, opti_domain_indices)
Runs MPR and writes to global effective parameters.
Global variables for mpr only.
real(dp), dimension(:, :, :), allocatable, public l1_degday
real(dp), dimension(:, :, :), allocatable, public l1_degdaymax
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistexp
real(dp), dimension(:, :, :), allocatable, public l1_harsamcoeff
real(dp), dimension(:, :, :), allocatable, public l1_karstloss
real(dp), dimension(:, :, :), allocatable, public l1_unsatthresh
real(dp), dimension(:, :, :), allocatable, public l1_kperco
real(dp), dimension(:, :, :), allocatable, public l1_alpha
real(dp), dimension(:, :, :), allocatable, public l1_surfresist
real(dp), dimension(:,:,:), allocatable, public l1_cosmicl3
real(dp), dimension(:, :, :), allocatable, public l1_degdayinc
real(dp), dimension(:, :, :), allocatable, public l1_petlaicorfactor
real(dp), dimension(:, :, :), allocatable, public l1_fasp
real(dp), dimension(:, :, :), allocatable, public l1_kbaseflow
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistfc
integer(i4), public nsoilhorizons_mhm
real(dp), dimension(:, :, :), allocatable, public l1_maxinter
real(dp), dimension(:,:,:), allocatable, public l1_bulkdens
real(dp), dimension(:, :, :), allocatable, public l1_degdaynopre
real(dp), dimension(:, :, :), allocatable, public l1_wiltingpoint
real(dp), dimension(:, :, :), allocatable, public l1_prietayalpha
real(dp), dimension(:, :, :), allocatable, public l1_fsealed
real(dp), dimension(:, :, :), allocatable, public l1_froots
real(dp), dimension(:, :, :), allocatable, public l1_jarvis_thresh_c1
real(dp), dimension(:, :, :), allocatable, public l1_tempthresh
real(dp), dimension(:), allocatable, public horizondepth_mhm
real(dp), dimension(:,:,:), allocatable, public l1_no_count
real(dp), dimension(:, :, :), allocatable, public l1_kfastflow
real(dp), dimension(:, :, :), allocatable, public l1_kslowflow
real(dp), dimension(:, :, :), allocatable, public l1_aeroresist
real(dp), dimension(:, :, :), allocatable, public l1_sealedthresh
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistsat
real(dp), dimension(:,:,:), allocatable, public l1_latticewater
Global variables for mRM only.
type(gaugingstation), public inflowgauge
real(dp), dimension(:, :), allocatable, public l11_qtin
integer(i4), dimension(:), allocatable, public l11_netperm
real(dp), dimension(:), allocatable, public l11_qout
real(dp), dimension(:, :), allocatable, public l11_nlinkfracfpimp
integer(i4), dimension(:), allocatable, public l11_l1_id
integer(i4), dimension(:), allocatable, public l1_l11_id
type(riv_temp_type), public riv_temp_pcs
This is a container for the river temperature routing process (pcs)
real(dp), dimension(:, :), allocatable, public mrm_runoff
integer(i4), dimension(:), allocatable, public l11_fromn
logical, dimension(noutflxstate) outputflxstate_mrm
Define model outputs see "mhm_outputs.nml".
real(dp), dimension(:), allocatable, public l11_length
real(dp), dimension(:), allocatable, public l11_qmod
integer(i4), dimension(:), allocatable, public l11_ton
type(domaininfo_mrm), dimension(:), allocatable, target, public domain_mrm
type(grid), dimension(:), allocatable, target, public level11
integer(i4) timestep_model_outputs_mrm
timestep for writing model outputs
real(dp), dimension(:), allocatable, public l11_c1
real(dp), dimension(:), allocatable, public l11_slope
integer(i4), dimension(:), allocatable, public l11_noutlets
real(dp), dimension(:), allocatable, public l11_tsrout
real(dp), dimension(:), allocatable, public l0_river_head_mon_sum
real(dp), dimension(:, :), allocatable, public l11_qtr
real(dp), dimension(:), allocatable, public l11_areacell
real(dp), dimension(:), allocatable, public l11_c2
Wrapper for initializing Routing.
subroutine, public fluxes_states_default_init_routing(idomain)
initialize fluxes and states with default values for mRM
subroutine, public variables_default_init_routing
Default initalization mRM related L11 variables.
Perform Multiscale Parameter Regionalization on Routing Parameters.
subroutine, public mrm_update_param(idomain, param)
TODO: add description.
subroutine, public mrm_read_restart_states(idomain, domainid, infile)
read routing states
subroutine, public calc_river_head(idomain, l11_qmod, river_head)
calculates the river head
Performs runoff routing for mHM at level L11.
subroutine, public mrm_routing(read_states, processcase, global_routing_param, l1_total_runoff, l1_areacell, l1_l11_id, l11_areacell, l11_l1_id, l11_netperm, l11_fromn, l11_ton, l11_noutlets, timestep, tsroutfactor, nnodes, ninflowgauges, inflowgaugeindexlist, inflowgaugeheadwater, inflowgaugenodelist, inflowdischarge, ngauges, gaugeindexlist, gaugenodelist, map_flag, l11_length, l11_slope, l11_fracfpimp, l11_c1, l11_c2, l11_qout, l11_qtin, l11_qtr, l11_qmod, gaugedischarge)
route water given runoff
Creates NetCDF output for different fluxes and state variables of mHM.
subroutine mrm_updatedataset(nc_mrm, l11_qmod, l11_riv_temp)
Update all variables.
type(outputdataset) function gw_outputdataset(idomain, mask)
Initialize groundwater coupling OutputDataset.
subroutine gw_updatedataset(nc_gw, l0_river_head)
Update riverhead.
type(outputdataset) function mrm_outputdataset(idomain, mask)
Initialize mRM OutputDataset.
reading and writing states, fluxes and configuration for restart of mHM.
subroutine, public read_restart_states(idomain, domainid, infile)
reads fluxes and state variables from file
Creates NetCDF output for different fluxes and state variables of mHM.
type(outputdataset) function mhm_outputdataset(idomain, mask1)
Initialize mHM OutputDataset.
subroutine mhm_updatedataset(nc_mhm, sidx, eidx, l1_fsealed, l1_fnotsealed, l1_inter, l1_snowpack, l1_soilmoist, l1_soilmoistsat, l1_sealstw, l1_unsatstw, l1_satstw, l1_neutrons, l1_pet, l1_aetsoil, l1_aetcanopy, l1_aetsealed, l1_total_runoff, l1_runoffseal, l1_fastrunoff, l1_slowrunoff, l1_baseflow, l1_percol, l1_infilsoil, l1_preeffect, l1_melt)
Update all variables.