Skip to content

Add river routing module for offline (GEOSldas) simulations#1143

Draft
weiyuan-jiang wants to merge 125 commits intodevelopfrom
feature/wjiang/Routing_GEOSroute_on_yujin
Draft

Add river routing module for offline (GEOSldas) simulations#1143
weiyuan-jiang wants to merge 125 commits intodevelopfrom
feature/wjiang/Routing_GEOSroute_on_yujin

Conversation

@weiyuan-jiang
Copy link
Contributor

@weiyuan-jiang weiyuan-jiang commented Aug 14, 2025

Add river routing module for offline land modeling (GEOSldas). Replaces #1023


Left for future PRs:

  • Run routing module within the AGCM and coupled model (AOGCM).
  • Run only the routing module (but not Catchment) in GEOSldas.
  • Include landice tiles in routing (GEOSldas and GCM).

Related PRs:


Testing:

  • TBD

List of tasks that remain to be addressed (in no particular order):


@YujiN, I am trying to bring back some codes in develop branch. The develop branch is not working as it is but I believe it would be more efficient. The runoff and the other variables are distributed as needed, which is way more efficient than allgatherV.

Yujin Zeng and others added 30 commits October 23, 2024 21:22
…t in GEOSgcm_GridComp/GEOSagcm_GridComp/GEOSphysics_GridComp/GEOSsurface_GridComp/GEOSland_GridComp/GEOSroute_GridComp
@weiyuan-jiang
Copy link
Contributor Author

@zyj8881357 : Thanks for making the changes. I "resolved" the comments that were fully addressed. I also added another commit 64775ef. Please double-check my changes. You may want to "hide white-space changes" when viewing.

@weiyuan-jiang, @biljanaorescanin:

While I was going through the routing PR I noticed that in the atm topo package we hardwire MAPL_Radius here (4 times):

I assume it would be 0-diff if we replaced the hardcoded value with MAPL_Radius via
"use MAPL_ConstantsMod, only: MAPL_radius"
I'd be ok with making this change on the routing PR.
Same goes for using MAPL_PI here:

That topo package has no dependence on MAPL. It may be used by others without MAPL.

@gmao-rreichle
Copy link
Contributor

gmao-rreichle commented Feb 10, 2026

@zyj8881357 : Thanks for making the changes. I "resolved" the comments that were fully addressed. I also added another commit 64775ef. Please double-check my changes. You may want to "hide white-space changes" when viewing.
@weiyuan-jiang, @biljanaorescanin:
While I was going through the routing PR I noticed that in the atm topo package we hardwire MAPL_Radius here (4 times):

I assume it would be 0-diff if we replaced the hardcoded value with MAPL_Radius via
"use MAPL_ConstantsMod, only: MAPL_radius"
I'd be ok with making this change on the routing PR.
Same goes for using MAPL_PI here:

That topo package has no dependence on MAPL. It may be used by others without MAPL.

@mathomp4, @weiyuan-jiang : I didn't realize that we are avoiding a dependency on MAPL in the new makebcs topo package, which is fine. But that shouldn't stop us from using constants values that are consistent with those in MAPL when we run the package for GEOS. I added a commit to make this a bit clearer: 6efc70f (please double-check my work; PS: I fixed a silly syntax error in the subsequent commit). Fortunately, the value for the Earth radius is already consistent with MAPL_RADIUS. But there are 5 places where the value of PI is hard-coded, and it's hard-coded to two distinct values, which is ugly. Do we really want to keep the distinct values of PI? I realize changing this would not be zero-diff, although it may still be possible to make the change before the soon-to-be-released v12 GCM (which I think is meant to use newly generated topography files) goes any further. At least I think we should make a conscious decision either way.

cc: @biljanaorescanin

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 : Thanks for implementing the change to using the alpha parameters. There is probably a good amount of cleanup to do, see comments below. The comments aren't necessarily complete or 100% correct, I didn't go through the code in great detail. Maybe I missed something.

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'm still struggling to understand what exactly is done in EASE_pfaf_frac.F90.

Yujin Zeng added 2 commits February 12, 2026 20:10
…also change variable pfaf_frac to subtile_area in the *_tile2pfaf.nc4 file
@zyj8881357
Copy link

I’ve changed pfaf_frac to subtile_area in the *_tile2pfaf.nc file. This means the model no longer needs to read the catchment area from the restart file; instead, it can be derived by summing the subtile areas during initialization. This works for non-EASE grids as well.

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 : We're getting close to being done, but I still have a few questions and suggestions, see below. Please let me know if anything is unclear.

Comment on lines +199 to +212
v = Variable(type=PFIO_INT32, dimensions='tile')
call v%add_attribute('units', '1')
call v%add_attribute('long_name', 'tile_id')
call meta%add_variable('tile_id', v)

v = Variable(type=pFio_INT32, dimensions='tile')
call v%add_attribute('units', '1')
call v%add_attribute('long_name', 'pfaf_index')
call meta%add_variable('pfaf_index', v)

v = Variable(type=pFio_REAL32, dimensions='tile')
call v%add_attribute('units', 'm+2')
call v%add_attribute('long_name', 'area_of_subtile')
call meta%add_variable('subtile_area', v)
Copy link
Contributor

Choose a reason for hiding this comment

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

@zyj8881357 : I tried some more to understand what this program is doing, and I think I got further than last time. But I'm still nowhere near understanding enough to meaningfully review this code. I'll need more time (and perhaps some help from you) to work through this.


! ----------------------------------------------------

subroutine create_mapping_handler(tilegrid, pfaf_tilegrid, rc)
Copy link
Contributor

@gmao-rreichle gmao-rreichle Feb 18, 2026

Choose a reason for hiding this comment

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

@weiyuan-jiang : Does the mapping from tile space to Pfaf catch space work when the simulation domain is not global?
And what if the tile space contains landice tiles?

/bin/mv {GRIDNAME}.j geometry/{GRIDNAME}/.
/bin/cp til/{GRIDNAME}{RS}.til geometry/{GRIDNAME}/.
/bin/cp til/{GRIDNAME}{RS}.nc4 geometry/{GRIDNAME}/.
/bin/cp til/{GRIDNAME}_tile_pfaf.nc4 geometry/{GRIDNAME}/.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this read
/bin/cp til/{GRIDNAME}_tile2pfaf.nc4 geometry/{GRIDNAME}/.

(i.e., tile2pfaf instead of tile_pfaf)

Comment on lines +11 to +12
lati09_output_file = "temp/lati_1m_M09.txt"
loni09_output_file = "temp/loni_1m_M09.txt"
Copy link
Contributor

Choose a reason for hiding this comment

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

This py script is specific to the M09 EASE grid. I think its product is only needed by "get_Qr_clmt.f90", and the M09 dependency stems from the fact that "get_Qr_clmt.f90" creates a runoff climatology from a SMAP L4 Open Loop simulation.
Is the above correct?
If so, we need to document this dependency in this file and also in readme.txt

Comment on lines +46 to +49
open(10, file="temp/lati_1m_M09.txt")
read(10, *) lati
open(11, file="temp/loni_1m_M09.txt")
read(11, *) loni
Copy link
Contributor

Choose a reason for hiding this comment

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

This program is specific to the M09 EASE grid. I think what's produced by this program is only needed by "get_Qr_clmt.f90", and the M09 dependency stems from the fact that "get_Qr_clmt.f90" creates a runoff climatology from a SMAP L4 Open Loop simulation.
Is the above correct?
If so, we need to document this dependency in this file and also in readme.txt

WRIVER = WRIVER + QINFLOW_LOCAL*real(route_dt)

if (associated(QSFLOW)) QSFLOW = QSFLOW_OUT ! outflow from local streams
if (associated(QOUTFLOW)) QOUTFLOW = QOUTFLOW_OUT ! outflow from main river
Copy link
Contributor

Choose a reason for hiding this comment

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

@zyj8881357 : I'm a bit confused about the meaning of QOUT_CAT vs. QOUTFLOW_OUT. I think that QOUT_CAT is the outflow from the Catchment, which for active reservoirs is the same as the outflow from the reservoir, whereas QOUTFLOW_OUT is the discharge from the main river before taking into account any reservoir.
If that's indeed the case, it's not a problem as such.
But I'm wondering how users would interpret our export variables (QSFLOW, QOUTFLOW, QRES). I don't think we provide the user with sufficiently clear information in the LONG_NAME attributes to assist them with the correct interpretation. Specifically, I think we're asking the user to apply the "active reservoir flag" on their end if what they want it the outflow from the catchment after the reservoir. I don't think that should be left to the user. It's probably better to also add QOUT_CAT as an export variable.

Comment on lines +873 to +876
call MAPL_GetPointer(EXPORT, QSFLOW, 'QSFLOW', _RC)
call MAPL_GetPointer(EXPORT, QINFLOW, 'QINFLOW' , _RC)
call MAPL_GetPointer(EXPORT, QOUTFLOW, 'QOUTFLOW', _RC)
call MAPL_GetPointer(EXPORT, QRES, 'QRES', _RC)
Copy link
Contributor

Choose a reason for hiding this comment

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

@weiyuan-jiang, @zyj8881357, I think we should add ALLOC=.true. here, as in:

call MAPL_GetPointer(EXPORT, QSFLOW, 'QSFLOW', ALLOC=.true., _RC)

With this change, these export variables are always allocated and can be used regardless of whether the user writes them out via HISTORY.

Then we wouldn't need the corresponding local variables *_IN and *_OUT. It's a bit confusing to essentially have two copies of each of these.

I'm not 100% sure I'm getting this right. @weiyuan-jiang, please advise.

@@ -0,0 +1,193 @@
module river_read
Copy link
Contributor

Choose a reason for hiding this comment

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

This file isn't listed in readme.txt. It looks like it's just a wrapper for netcdf calls, and as such doesn't really require documentation in readme.txt. But the file name river_read.f90 is misleading. I suggest renaming this to something like read_ncfile_helper.F90. It doesn't look like there's anything specific to the river routing model in this helper.

@@ -0,0 +1,1029 @@
module k_module
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest adding the file name k_module_cali.f90 into readme.txt, under what is currently item 6 ("get_K_model_calik.f90"). Currently, this file isn't mentioned in readme.txt

integer,parameter :: nlath = 33600

integer,parameter :: nl_USGS = 3352492 ! Total number of USGS data records
integer,parameter :: nt09 = 1684725 ! Total number of catchment gridcell in M09
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as "nt_global09" above. We shouldn't need this extra parameter

…ld error from earlier commit (routing_model.F90)
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. Contingent - DNA These changes are contingent on other PRs (DNA=do not approve) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments