Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mpi pio read2ndfile #145

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7a0137e
new strcuture, global varibaribles and modified model set up in stand…
Aug 9, 2020
912bfd6
changes in global data
Aug 9, 2020
6e043da
change to wm_data strcuture
Aug 9, 2020
685020c
Update remap.f90
ShervanGharari Aug 10, 2020
56b75d5
Merge pull request #34 from NCAR/feature/mpi-pio
ShervanGharari Aug 11, 2020
4d2ca06
Merge branch 'feature/mpi-pio-read2ndfile-v2' into feature/mpi-pio
ShervanGharari Aug 11, 2020
98d2ae2
Merge pull request #36 from ShervanGharari/feature/mpi-pio
ShervanGharari Aug 11, 2020
00d057e
Merge pull request #37 from ShervanGharari/feature/mpi-pio-read2ndfil…
ShervanGharari Aug 11, 2020
3961e58
minor changes in the model_setup
Aug 11, 2020
6133205
the read_runoff_metadata and read_runoff subroutins are generalized s…
Aug 12, 2020
49d44e4
get basin runoff reads the extra files
Aug 12, 2020
761b44d
changes in read runoff to make it similar to the origin
Aug 12, 2020
bf2e96a
changes in read runoff to make it similar to the origin
Aug 12, 2020
f578fc1
the model setup is fixed so that the seg_id length is similar to the …
Aug 13, 2020
c6c4aa9
print statments and fixing of time correction for second file
Aug 13, 2020
bbc6db7
minor changes in commnets and also reading calendar and time step in …
Aug 17, 2020
dace0e0
cleaing of get basin runoff
Aug 19, 2020
c8e8542
the checks for start and end of the second nc file is incorporated in…
Aug 25, 2020
3e25ec7
chekcing if nc files do not have gap or overlaps
Aug 25, 2020
8e571b7
few changes
Aug 25, 2020
db80cdc
small changes
Aug 25, 2020
1bfc0ca
scatter_wm is implemented in mpi_process.f90
Aug 25, 2020
d9734f6
the checks for scatter runoff, evaporation and precipitation are adde…
Aug 26, 2020
3fb572e
scatter_wm and its check is called in the mpi_process/f90
Aug 26, 2020
085e2d8
the scattered flux and target volumes are passed to main_route.f90 an…
Aug 26, 2020
b778495
passing and allocating the flux and target volume to the RCHFLX_OUT i…
Aug 26, 2020
c536336
small change of nTime to nTime_wm in model setup also print statement…
Sep 1, 2020
15bd6d3
minor changed, commenting the print statments in irt_rote
Sep 1, 2020
dd07ebd
print statements are added
Sep 1, 2020
21f1f11
the abstraction or injection to the river segment is added to irf; at…
Oct 20, 2020
f0261d8
water balance is caluclated for each reach, so the inital streamflow,…
Oct 21, 2020
3fb6039
the commnets where fixed
Oct 23, 2020
a06954b
print statement is removed
Oct 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions route/build/src/dataTypes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ MODULE dataTypes
real(dp) , allocatable :: basinPrecip(:)! remapped river network catchment runoff (size: number of nHRU)
end type runoff

! water management data; fluxes to/from reaches or target volume
type, public :: wm
integer(i4b) :: nTime ! number of time steps
integer(i4b) :: nSpace(1:2) ! number of spatial dimension, in this case only one dimentonal
real(dp) :: time ! time variable at one time step
real(dp) , allocatable :: sim(:) ! user specified flux add/subtract, or volume at one time step (size: nSpace)
real(dp) , allocatable :: sim2D(:,:) ! to provide modularity for reading data
integer(i4b) , allocatable :: seg_id(:) ! id of reach in data (size: nSpace)
integer(i4b) , allocatable :: seg_ix(:) ! Index of river network reach IDs corresponding reach ID in data
real(dp) , allocatable :: flux_wm(:) ! allocated flux to existing river network using sort_flux (size: number of nRCH)
real(dp) , allocatable :: vol_wm(:) ! allocated target vol to existing river network using sort_flux (size: number of nRCH)
end type

! ---------- reach parameters ----------------------------------------------------------------------------

! Reach Parameters
Expand Down Expand Up @@ -264,6 +277,8 @@ MODULE dataTypes
real(dp) :: REACH_Q_IRF ! time-step average streamflow (m3/s) from IRF routing
real(dp) :: UPSTREAM_QI ! sum of upstream streamflow (m3/s)
real(dp) :: REACH_VOL(0:1) ! volume of water at previous and current time step [m3]
real(dp) :: REACH_WM_FLUX ! water management fluxes to and from each reach
real(dp) :: REACH_WM_VOL ! target volume from the second water management file (m3)
real(dp) :: TAKE ! average take
logical(lgt) :: isRoute ! .true. if the reach is routed
END TYPE strflx
Expand Down
10 changes: 9 additions & 1 deletion route/build/src/globalData.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module globalData
! remapping structures
USE dataTypes, ONLY: remap ! remapping data type
USE dataTypes, ONLY: runoff ! runoff data type
USE dataTypes, ONLY: wm ! water management (flux to/from segment, target volume) data type

! basin data structure
USE dataTypes, ONLY: subbasin_omp ! mainstem+tributary data structures
Expand Down Expand Up @@ -73,7 +74,6 @@ module globalData
! ---------- Date/Time data -------------------------------------------------------------------------

integer(i4b) , public :: iTime ! time index at simulation time step
integer(i4b) , public :: iTime_local ! time index at simulation time step for a given input file
real(dp) , public :: startJulday ! julian day: start of routing simulation
real(dp) , public :: endJulday ! julian day: end of routing simulation
real(dp) , public :: refJulday ! julian day: reference
Expand All @@ -88,6 +88,7 @@ module globalData
! ---------- input file information -------------------------------------------------------------------

type(infileinfo) , allocatable , public :: infileinfo_data(:) ! conversion factor to convert time to units of days
type(infileinfo) , allocatable , public :: infileinfo_data_wm(:)! conversion factor to convert time to units of days

! ---------- Misc. data -------------------------------------------------------------------------

Expand Down Expand Up @@ -186,6 +187,13 @@ module globalData
real(dp) , allocatable , public :: basinPrecip_trib(:) ! HRU precipitation array (m/s) for tributaries
real(dp) , allocatable , public :: basinPrecip_main(:) ! HRU precipitation array (m/s) for mainstem

! seg water management fluxes and target volume
type(wm) , public :: wm_data ! SEG flux and target vol data structure for one time step for river network
real(dp) , allocatable , public :: flux_wm_trib(:) ! SEG flux array (m3/s) for tributaries
real(dp) , allocatable , public :: flux_wm_main(:) ! SEG flux array (m3/s) for mainstem
real(dp) , allocatable , public :: vol_wm_trib(:) ! SEG target volume (for lakes) (m3) for tributaries
real(dp) , allocatable , public :: vol_wm_main(:) ! SEG target volume (for lakes) (m3) for mainstem

! domain data
! MPI
type(subbasin_mpi) , public :: domains(maxDomain) ! domain decomposition data structure (maximum domain is set to maxDomain)
Expand Down
38 changes: 32 additions & 6 deletions route/build/src/irf_route.f90
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ MODULE irf_route_module
!numeric type
USE nrtype
! data type
USE dataTypes, ONLY: STRFLX ! fluxes in each reach
USE dataTypes, ONLY: RCHTOPO ! Network topology
USE dataTypes, ONLY: STRFLX ! fluxes in each reach
USE dataTypes, ONLY: RCHTOPO ! Network topology
! global parameters
USE public_var, ONLY: iulog ! i/o logical unit number
USE public_var, ONLY: realMissing ! missing value for real number
USE public_var, ONLY: integerMissing ! missing value for integer number
USE public_var, ONLY: iulog ! i/o logical unit number
USE public_var, ONLY: realMissing ! missing value for real number
USE public_var, ONLY: integerMissing ! missing value for integer number
! subroutines: general
USE perf_mod, ONLY: t_startf,t_stopf ! timing start/stop
USE perf_mod, ONLY: t_startf,t_stopf ! timing start/stop

! privary
implicit none
Expand Down Expand Up @@ -128,6 +128,8 @@ subroutine segment_irf(&
! output
ierr, message) ! output: error control

! shared data
USE public_var, ONLY:is_flux_wm ! logical water management components fluxes should be read
implicit none
! Input
INTEGER(I4B), intent(IN) :: iEns ! runoff ensemble to be routed
Expand All @@ -141,6 +143,9 @@ subroutine segment_irf(&
character(*), intent(out) :: message ! error message
! Local variables to
type(STRFLX), allocatable :: uprflux(:) ! upstream Reach fluxes
real(dp) :: abstract_actual! actual abstraction TO BE DELETED
real(dp) :: WB_check ! water balance TO BE DELETED
real(dp) :: init_STRQ ! init TO BE DELETED
INTEGER(I4B) :: nUps ! number of upstream segment
INTEGER(I4B) :: iUps ! upstream reach index
INTEGER(I4B) :: iRch_ups ! index of upstream reach in NETOPO
Expand Down Expand Up @@ -190,6 +195,27 @@ subroutine segment_irf(&
RCHFLX_out(iens,segIndex)%BASIN_QR(1),RCHFLX_out(iens,segIndex)%REACH_Q_IRF
endif

! print statement to compare the computed REACH_Q_IRF and water management abstraction/injection
! print*, NETOPO_in(segIndex)%REACHID, RCHFLX_out(iens,segIndex)%REACH_Q_IRF, RCHFLX_out(iens,segIndex)%REACH_WM_FLUX

! take out the water from the reach if the wm flag is true and the value are not missing
! here we should make sure the real missing is not injection (or negative abstration)
if((RCHFLX_out(iens,segIndex)%REACH_WM_FLUX /= realMissing).and.(is_flux_wm)) then
ShervanGharari marked this conversation as resolved.
Show resolved Hide resolved
abstract_actual = RCHFLX_out(iens,segIndex)%REACH_Q_IRF ! get the reach streamflow as actual abstration
init_STRQ = RCHFLX_out(iens,segIndex)%REACH_Q_IRF ! TO BE DELETED
! reach streamflow is updated based on abstration (positive) or injection (negative)
RCHFLX_out(iens,segIndex)%REACH_Q_IRF = RCHFLX_out(iens,segIndex)%REACH_Q_IRF - RCHFLX_out(iens,segIndex)%REACH_WM_FLUX
if (RCHFLX_out(iens,segIndex)%REACH_Q_IRF>0) then ! abstration was negative or smaller than reach streamflow
abstract_actual = RCHFLX_out(iens,segIndex)%REACH_WM_FLUX ! actual abstration will be equal to abstration value
else
RCHFLX_out(iens,segIndex)%REACH_Q_IRF = 0._dp ! all the water is taken and actual abstration is reach streamflow
endif
endif

WB_check = RCHFLX_out(iens,segIndex)%REACH_Q_IRF + abstract_actual - init_STRQ

print*, NETOPO_in(segIndex)%REACHID, RCHFLX_out(iens,segIndex)%REACH_Q_IRF, RCHFLX_out(iens,segIndex)%REACH_WM_FLUX, abstract_actual, WB_check
ShervanGharari marked this conversation as resolved.
Show resolved Hide resolved

end subroutine segment_irf


Expand Down
18 changes: 18 additions & 0 deletions route/build/src/main_route.f90
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ SUBROUTINE main_route(&
basinRunoff_in, & ! basin (i.e.,HRU) runoff (m/s)
basinEvapo_in, & ! basin (i.e.,HRU) evaporation (m/s)
basinPrecip_in, & ! basin (i.e.,HRU) precipitation (m/s)
reachflux_in, & ! reach (i.e.,reach) flux (m3/s)
reachvol_in, & ! reach (i.e.,reach) target volume for lakes (m3)
ixRchProcessed, & ! indices of reach to be routed
river_basin, & ! OMP basin decomposition
NETOPO_in, & ! reach topology data structure
Expand Down Expand Up @@ -67,6 +69,8 @@ SUBROUTINE main_route(&
USE public_var, ONLY: impulseResponseFunc
USE globalData, ONLY: TSEC ! beginning/ending of simulation time step [sec]
USE public_var, ONLY: is_lake_sim ! logical whether or not lake should be simulated
USE public_var, ONLY: is_flux_wm ! logical whether or not fluxes should be passed
USE public_var, ONLY: is_vol_wm ! logical whether or not target volume should be passed

implicit none

Expand All @@ -75,6 +79,8 @@ SUBROUTINE main_route(&
real(dp), allocatable, intent(in) :: basinRunoff_in(:) ! basin (i.e.,HRU) runoff (m/s)
real(dp), allocatable, intent(in) :: basinEvapo_in(:) ! basin (i.e.,HRU) evaporation (m/s)
real(dp), allocatable, intent(in) :: basinPrecip_in(:) ! basin (i.e.,HRU) precipitation (m/s)
real(dp), allocatable, intent(in) :: reachflux_in(:) ! reach (i.e.,reach) flux (m3/s)
real(dp), allocatable, intent(in) :: reachvol_in(:) ! reach (i.e.,reach) target volume for lakes (m3)
integer(i4b), allocatable, intent(in) :: ixRchProcessed(:) ! indices of reach to be routed
type(subbasin_omp), allocatable, intent(in) :: river_basin(:) ! OMP basin decomposition
type(RCHTOPO), allocatable, intent(in) :: NETOPO_in(:) ! River Network topology
Expand Down Expand Up @@ -107,6 +113,18 @@ SUBROUTINE main_route(&
allocate(reachRunoff_local(nSeg), stat=ierr)
if(ierr/=0)then; message=trim(message)//'problem allocating arrays for [reachRunoff_local]'; return; endif

! passing of the water management fluxes and lake target vol if presence
if (is_flux_wm) then
do iSeg = 1,nSeg
RCHFLX_out(iens,ixRchProcessed(iSeg))%REACH_WM_FLUX = reachflux_in(iSeg) ! added or subtracted stremflow for each reach
end do
end if
if (is_vol_wm.and.is_lake_sim) then
do iSeg = 1,nSeg
RCHFLX_out(iens,ixRchProcessed(iSeg))%REACH_WM_VOL = reachvol_in(iSeg) ! target volume for the lakes
end do
end if

! 1. subroutine: map basin runoff to river network HRUs
! map the basin runoff to the stream network...
call basin2reach(basinRunoff_in, & ! input: basin runoff (m/s)
Expand Down
Loading