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

Introduce SUBROUTINE GWspatialParameters #224

Merged
merged 1 commit into from
Apr 6, 2024

Conversation

rkutteh
Copy link
Collaborator

@rkutteh rkutteh commented Mar 17, 2024

CABLE ground water hydrology work of Mengyuan Mu

This pull request is part of integrating the ground water hydrology work of Mengyuan Mu into CABLE, which will take place in a sequence of pull requests. The actual integration project itself was completed back in September 2023. The current work involves just a gradual merge into the main branch.

Description

  1. A new SUBROUTINE GWspatialParameters is introduced in src/offline/cable_parameters.F90
  2. This subroutine will eventually be called only once, from src/offline/cable_input.F90. I will add this call at the appropriate time, but for now the subroutine is inactive
  3. Dependencies are introduced in src/offline/cable_parameters.F90 and src/offline/cable_define_types.F90 in order for the code to compile successfully (confirmed)
  4. This pull request involves only code additions, no deletions or modifications of existing code were carried out (some minor typos I came across in existing comments were fixed)
  5. PLEASE do not delete any of my in-code comments (tagged rk4417) for now. Once the integration of the ground water hydrology work is complete and its functionality is confirmed to reproduce the results obtained already outside of the repo, I will clean-up all of my comments in a single pull request. Deleting any of my comments now will just make it much more difficult for me to track down and fix any issues that might arise during this process.

📚 Documentation preview 📚: https://cable--224.org.readthedocs.build/en/224/

@rkutteh rkutteh requested a review from ccarouge March 17, 2024 09:29
@rkutteh rkutteh linked an issue Mar 17, 2024 that may be closed by this pull request
@rkutteh rkutteh added the GWH Ground water hydrology integration work label Mar 17, 2024
@ccarouge
Copy link
Collaborator

@rkutteh I know you were hoping for a quick pull request. But I don't think I can give you that. From what I've seen during the review the GWspatialParameters add to the spaghetti mess of cable_parameters.F90 instead of helping untangling things. So I'm not particularly inclined to accept as is. I'll have a deeper look into it and see if we can adapt things quickly to get the code to a better standard.

@rkutteh
Copy link
Collaborator Author

rkutteh commented Mar 19, 2024

@ccarouge As you might guess from my earlier comments, I prefer that all clean-up of code occurs after all the GW work is in and validated against the copy I have outside the repo. If you change things around while I am moving code in and the final code does not agree with my results, it will be nearly impossible for me to track down the source(s) of the errors. As it stands, we know that the code that I am introducing works with GW on, so my own strategy would be to mirror it in the repo, check that all is good as expected, and only THEN clean-up and check, clean-up and check,...Keep in mind that GWspatialParameters is presently inactive.

Copy link
Collaborator

@ccarouge ccarouge left a comment

Choose a reason for hiding this comment

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

I have written down what I would change (at least what I could see here).
But I have seen that cable_parameters.F90 already has code to read in the GW parameters and assign the values to the CABLE variables (in spatialSoil() and write_default_params()), so we need to ensure there is only one way to do that in the final code.

This clean up will be done separately (#229) once the GW code is committed in to ensure testing is possible.

Comment on lines +1018 to +1023
! mpatch setting below introduced by rk4417 - phase2
!set mpatch, the publically available number of patches
mpatch = npatch ! MMY@13April it makes sense. mpatch is set in cable_define_types_mod
! as a public variable and is used in subroutine GWspatialParameters
! and in get_gw_data

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see why this is needed since we reset to max_vegpatches below. Or did I miss a if statement?

Comment on lines +2860 to +2865
IF (nlon .lt. 0 .or. nlon .ne. xdimsize) &
WRITE(logn,*) 'nlon: found ',nlon,' need to have ',xdimsize,' to match forcing.'
IF (nlat .lt. 0 .or. nlat .ne. ydimsize) &
WRITE(logn,*) 'nlat: found ',nlat,' need to have ',ydimsize,' to match forcing.'
IF (nhorz .lt. 0 .or. nhorz .ne. ms) &
WRITE(logn,*) 'nhorz: found ',nhorz,' need to have ',ms,' to match forcing.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

The negative tests (.lt. 0) are unnecessary as xdimsize, ydimsize and ms will never be negative.

Comment on lines +2850 to +2854
IF( NF90_INQ_DIMID(ncid,'nhorz',layer_id) .eq. nf90_noerr) THEN
IF ( NF90_INQUIRE_DIMENSION(ncid,layer_id,LEN=nhorz) .ne. nf90_noerr) nhorz=1
ELSE
nhorz=ms
ENDIF
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's weird that if that dimension is not found in the file (ELSE statement), we set it to the correct value. Shouldn't it be -1 in the ELSE?

Comment on lines +2869 to +2872
WRITE(logn,*) 'Setting dims to forcing file values, CHECK THE OUTPUT!'
!amu561: code should probably stop here instead of re-writing
!dimensions?
nlon=xdimsize; nlat=ydimsize; npatch=mpatch; nhorz=ms
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wrong indent and I agree with Anna, this should not be done. We should have an exit here to stop the code.

Comment on lines +2879 to +2909
! MMY @Oct2022 give read-in value to non-vec parameters
do e=1,mland
soil%silt(landpt(e)%cstart:landpt(e)%cend) = &
insilt(landpt(e)%ilon, landpt(e)%ilat)
soil%sand(landpt(e)%cstart:landpt(e)%cend) = &
insand(landpt(e)%ilon, landpt(e)%ilat)
soil%clay(landpt(e)%cstart:landpt(e)%cend) = &
inclay(landpt(e)%ilon, landpt(e)%ilat)
soil%swilt(landpt(e)%cstart:landpt(e)%cend) = &
inswilt(landpt(e)%ilon, landpt(e)%ilat)
soil%sfc(landpt(e)%cstart:landpt(e)%cend) = &
insfc(landpt(e)%ilon, landpt(e)%ilat)
soil%ssat(landpt(e)%cstart:landpt(e)%cend) = &
inssat(landpt(e)%ilon, landpt(e)%ilat)
soil%bch(landpt(e)%cstart:landpt(e)%cend) = &
inbch(landpt(e)%ilon, landpt(e)%ilat)
soil%hyds(landpt(e)%cstart:landpt(e)%cend) = &
inhyds(landpt(e)%ilon, landpt(e)%ilat)
soil%sucs(landpt(e)%cstart:landpt(e)%cend) = &
-1.* ABS(insucs(landpt(e)%ilon, landpt(e)%ilat)) !ensure negative
soil%rhosoil(landpt(e)%cstart:landpt(e)%cend) = &
inrhosoil(landpt(e)%ilon, landpt(e)%ilat)
soil%css(landpt(e)%cstart:landpt(e)%cend) = &
incss(landpt(e)%ilon, landpt(e)%ilat)
soil%cnsd(landpt(e)%cstart:landpt(e)%cend) = &
incnsd(landpt(e)%ilon, landpt(e)%ilat)
! 26
! soil%GWrhosoil_vec(landpt(e)%cstart:landpt(e)%cend) = & ! MMY not used
! REAL(inGWrhosoil(landpt(e)%ilon, landpt(e)%ilat),r_2)
end do

Copy link
Collaborator

Choose a reason for hiding this comment

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

This has nothing to do with reading the GW parameters file. It should not be done in this subroutine. It should be done when dealing with derived parameters.

Comment on lines +3135 to +3139
if (.not.cable_user%gw_model) then

GW2d_data(:,:) = default_data(:,:)

else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to remove this case. This should be done outside these routines. Keep these generic.

Comment on lines +3186 to +3191
if (.not. cable_user%gw_model) then
do k=1,ms
GW3d_data(:,:,k) = default_data(:,:)
end do

else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to remove this case. This should be done outside these routines. Keep these generic.

Comment on lines +3240 to +3245
if (.not. cable_user%gw_model) then
do k=1,ms
GW3d_data(:,:,k) = default_data(:,:)
end do

else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to remove this case. This should be done outside these routines. Keep these generic.

Comment on lines +3298 to +3304
if (.not.cable_user%gw_model) then
do k=1,ms
do n=1,npatch
GW4d_data(:,:,k,n) = default_data(:,:)
end do
end do
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to remove this case. This should be done outside these routines. Keep these generic.

Comment on lines +3364 to +3370
if (.not.cable_user%gw_model) then
do k=1,ms
do n=1,npatch
GW4d_data(:,:,k,n) = default_data(:,:)
end do
end do
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to remove this case. This should be done outside these routines. Keep these generic.

@rkutteh
Copy link
Collaborator Author

rkutteh commented Apr 6, 2024

@ccarouge thanks for all the comments. Some I suspect will be resolved "automatically", once I am finished pushing all the remaining changes to src/offline/cable_parameters.F90 . The remaining I agree we can address after testing.

@rkutteh rkutteh merged commit fed2a4c into main Apr 6, 2024
3 checks passed
@rkutteh rkutteh deleted the 220-introduce-subroutine-gwspatialparameters branch April 6, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GWH Ground water hydrology integration work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce SUBROUTINE GWspatialParameters
2 participants