Skip to content

River routing for GEOSldas #1023

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

Draft
wants to merge 31 commits into
base: develop
Choose a base branch
from

Conversation

zyj8881357
Copy link

Pull Request Overview

This pull request initiates the implementation of a river routing process within GEOS, starting with an offline model.

Current Implementation: Only the offline version of the river routing model is introduced at this stage.

All model code is located in the directory:
GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOSroute_GridComp

The model reads runoff data from the Catchment model outputs (variables RUNOFF and BASEFLOW, with type tavg24_2d_lnd_Nx) and generates daily river-related outputs for each catchment area.

For detailed information on configuring and running the offline model, please refer to readme.txt in the above directory.

Next Steps:
This is an initial implementation, and many aspects require further discussion with relevant members to plan the next steps.

Additionally, work is ongoing to develop a pre-processing package for creating input data for the routing model.

Yujin Zeng and others added 6 commits October 23, 2024 21:22
@zyj8881357 zyj8881357 added 0 diff The changes in this pull request have verified to be zero-diff with the target branch. Draft labels Oct 31, 2024
@zyj8881357 zyj8881357 self-assigned this Oct 31, 2024
@zyj8881357 zyj8881357 requested a review from a team as a code owner October 31, 2024 17:31
@zyj8881357 zyj8881357 marked this pull request as draft October 31, 2024 17:51
@zyj8881357 zyj8881357 changed the title Feature/yujinz/routing geo sroute River routing for GEOSldas, offline mode Oct 31, 2024
@zyj8881357 zyj8881357 changed the title River routing for GEOSldas, offline mode River routing for GEOSldas Dec 3, 2024
@zyj8881357
Copy link
Author

zyj8881357 commented Dec 3, 2024

New Updates:

1. The river routing model (excluding the reservoir and lake components) is now integrated into GEOSldas.
2. Currently, the model supports EASEv2 M09 and M36 grids. To enable the river routing feature, set RUN_ROUTE to 1 in the exeinp file.
3. Output Details
    River Discharge [m3 s-1]: Daily river discharge data is saved in the "river" directory (created automatically) within the experiment folder.
    The output is in vector format (*.txt files), where each file contains 291,284 values. These values correspond to catchments indexed from 1 to 291,284.
    To convert the vector data into spatial maps, use the 1-minute resolution catchment distribution map available in the CatchIndex variable of the SRTM_PfafData.nc file at:
    /discover/nobackup/projects/gmao/bcs_shared/make_bcs_inputs/land/topo/v1/SRTM-TopoData/SRTM_PfafData.nc
4. Restart Files: Restart files are generated monthly in the restart folder and can be read automatically as it exists. If there is no restart file, zero water storage will be used at the start.
5. The source code of offline routing model has been moved to the "offline" directory under GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOSroute_GridComp/


For questions or further assistance, please contact Yujin Zeng at:
Email: yujin.zeng@nasa.gov

enddo

! Deactivate reservoirs if the use_res flag is set to False
if(use_res == .False.) active_res = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(use_res == .False.) active_res = 0
if(use_res .eqv. .False.) active_res = 0

GNU was tripping on this as, per Fortran, you have to use .eqv. and .neqv. to compare logicals.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just fixed this. Thank you!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zyj8881357 It looks like GNU is finding a couple more. Lines 1007 and 1057 in GEOS_RouteGridComp.F90

I also see similar in lines 66 and 250 in lake_mod.F90

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those have been fixed. Thank you!

@zyj8881357
Copy link
Author

New Updates:

The pre-processing package for the input data to routing model has been added. Related comments and documents were supplemented.
At this stage, the CMAKE file is not created for the pre-processing, so the package can be built and run separately (no need building together with the GEOSldas). It is easier for anyone who wants to test and run.

@zyj8881357 zyj8881357 requested a review from lcandre2 May 13, 2025 15:25
Copy link
Contributor

@gmao-rreichle gmao-rreichle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zyj8881357: I started reviewing the routing model PR. I added a couple of minor commits with some cleanup (just a start). More importantly, we'll need to address the comments below, most of which are quite major and will require substantial revisions in how the model is integrated in GEOS.
cc: @weiyuan-jiang @tclune @biljanaorescanin @rdkoster @amolod @lcandre2

@@ -31,7 +31,7 @@ module GEOS_LandGridCompMod
use GEOS_CatchGridCompMod, only : CatchSetServices => SetServices
use GEOS_CatchCNGridCompMod, only : CatchCNSetServices => SetServices
use GEOS_IgniGridCompMod, only : IgniSetServices => SetServices
! use GEOS_RouteGridCompMod, only : RouteSetServices => SetServices
use GEOS_RouteGridCompMod, only : RouteSetServices => SetServices
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not about this particular line, but rather about the placement of GEOS_RouteGridComp inside GEOS_LandGridComp. Ultimately, we will need to route runoff from the land and the landice tiles. To do that, I think we need to place GEOS_RouteGridComp one level up, within GEOS_SurfaceGridComp (that is, next to GEOS_LandGridComp). Making this change will likely require extensive re-wiring. I wonder if it's best to tackle this re-wiring first or delay the move until later.

integer, parameter :: N_CatG = 291284

integer, parameter :: upmax = 34
character(len=500) :: inputdir = "/discover/nobackup/yzeng3/data/river_input/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot hardwire a user-specific directory here. The inputs that come from this directory need to become part of the bcs datasets. See also comment below about adding parameters into routing restart files.


integer, parameter :: upmax = 34
character(len=500) :: inputdir = "/discover/nobackup/yzeng3/data/river_input/"
logical, parameter :: use_res = .True.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we want to hardwire using the reservoir model (if that's what this switch does)? It may be better to include config information in the "RUN_ROUTE" resource variable. E.g., RUN_ROUTE=1 could be the routing model without reservoirs, and RUN_ROUTE=2 could be the routing model with reservoirs

USE catch_constants, ONLY: &
N_CatG => N_Pfaf_Catchs
#endif
use ROUTING_MODEL, ONLY: river_routing_lin, river_routing_hyd, ROUTE_DT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

river_routing_lin() is commented out below. Do we want to make this a runtime option? We could use RUN_ROUTE for this purpose. E.g., RUN_ROUTE=1 runs the hydraulic model, and RUN_ROUTE=2 runs the linear model. If we never want to run the linear model, it should be removed from the code.


! -----------------------------------------------------------
! RUN -- Run method for the route component
! -----------------------------------------------------------
subroutine RUN1 (GC,IMPORT, EXPORT, CLOCK, RC )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why define an empty subroutine RUN1()? Do we need this for anything? If there's a call to RUN1(), it should be removed, then we can remove the empty subroutine.


! Read sub-catchment data
allocate(nsub_global(N_CatG),subarea_global(nmax,N_CatG))
open(77,file=trim(inputdir)//"/Pfaf_nsub_"//trim(resname)//".txt",status="old",action="read"); read(77,*)nsub_global; close(77)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this and many subsequent read statements do, but my sense is that we need to include the routing model parameters in the routing model restart files. Then the "init" routine would not need tap into external files.
Normally, the process for land model parameters is as follows:

  1. Create parameter datasets that can be archived in the bcs_shared directory (along with all the other bcs files). This is accomplished by make_bcs (and may already be part of the present PR).
  2. Create a routing restart file that includes the routing model parameters. This interfaces with the "remap_restarts" package in the GEOS_Util repo.
  3. When the model is run (in GEOSldas or GEOSgcm), the routing model parameters are read in from the restart file.

if(mapl_am_I_root())print *, "init time is ", YY, "/", MM, "/", DD, " ", HH, ":", MMM, ":", SS
allocate(wriver(ntiles),wstream(ntiles),wres(ntiles))
allocate(wriver_global(n_catg),wstream_global(n_catg),wres_global(n_catg))
open(77,file="../input/restart/river_storage_rs_"//trim(yr_s)//trim(mon_s)//trim(day_s)//".txt",status="old",action="read",iostat=status)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not introduce custom, ASCII restart files for the routing model. Instead, we need to make sure the restarts are handled by MAPL and are netcdf-formatted.

if(mapl_am_I_root())then
!open(88,file="../river/river_storage_"//trim(yr_s)//trim(mon_s)//trim(day_s)//".txt",action="write")
!open(89,file="../river/stream_storage_"//trim(yr_s)//trim(mon_s)//trim(day_s)//".txt",action="write")
open(90,file="../river/river_flow_"//trim(yr_s)//trim(mon_s)//trim(day_s)//".txt",action="write")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output from the routing model should be handled by MAPL HISTORY. We can't publish custom ASCII files with GEOS products.

@gmao-rreichle
Copy link
Contributor

@weiyuan-jiang : In a recent commit (85af5a7), I added a USE statement into GEOS_RouteGridComp.F90 that pulls a constant from:
GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/Shared/catch_constants.f90
But this trips up the build because I didn't add the dependency into CMakeLists.txt, which may also need another fix (replace "esmf" with "ESMF::ESMF" in dependencies?). When you get a chance, please edit:
https://github.com/GEOS-ESM/GEOSgcm_GridComp/blob/feature/yujinz/Routing_GEOSroute/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOSroute_GridComp/CMakeLists.txt
accordingly. Thanks!

@weiyuan-jiang
Copy link
Contributor

weiyuan-jiang commented May 23, 2025

@weiyuan-jiang : In a recent commit (85af5a7), I added a USE statement into GEOS_RouteGridComp.F90 that pulls a constant from: GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/Shared/catch_constants.f90 But this trips up the build because I didn't add the dependency into CMakeLists.txt, which may also need another fix (replace "esmf" with "ESMF::ESMF" in dependencies?). When you get a chance, please edit: https://github.com/GEOS-ESM/GEOSgcm_GridComp/blob/feature/yujinz/Routing_GEOSroute/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOSroute_GridComp/CMakeLists.txt accordingly. Thanks!

I think we need to add dependencies "GEOS_LandShared ESMF::ESMF" . catch_constant is from GEOS_LandShared and ESMF::ESMF is a new standard way. Just added

@zyj8881357 zyj8881357 force-pushed the feature/yujinz/Routing_GEOSroute branch from f4d3c73 to e367061 Compare June 9, 2025 14:48
@weiyuan-jiang
Copy link
Contributor

I am quite confused about the variable names. "N_catg" was used as global tile number before. Can it be changed to N_pfaf_g here? The "ntiles" here seem n_pfaf_local to me. ( correct me if I am wrong)

if(it>0)then
RUNOFF_ACT(i)=RUNOFF_ACT(i)+route%subarea(j,i)*runoff_global(it)/1000.
endif
if(it==0)exit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exit or cycle ?

call MPI_allgatherv ( &
QOUT_CAT, route%scounts_cat(mype+1) ,MPI_REAL, &
QOUTFLOW_GLOBAL, route%scounts_cat, route%rdispls_cat,MPI_REAL, &
MPI_COMM_WORLD, mpierr)
Copy link
Contributor

@weiyuan-jiang weiyuan-jiang Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the MPI_COMM_WORLD should be replaced by the comm obtained from VM


VERIFY_(STATUS)
route%nt_global = nt_global
! Determine the resolution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use gridname to determine the resolution

! define minCatch, maxCatch

allocate(ims(1:ndes))
! define catchment space for this processor
call MAPL_DecomposeDim ( n_catg,ims,ndes ) ! ims(mype+1) gives the size of my partition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to to me the distribution of pfaf has nothing to do with the distribution of tiles. Is there any proximity that can be taken advantage of ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0 diff The changes in this pull request have verified to be zero-diff with the target branch. Draft
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants