-
Notifications
You must be signed in to change notification settings - Fork 69
runoff scaling module to adjust Antarctic surface runoff #837
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
GMHuettner
wants to merge
3
commits into
main
Choose a base branch
from
runoff_scaling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| module runoff_scaling_interface | ||
JanStreffing marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| interface | ||
| subroutine runoff_scaling_init() | ||
| end subroutine runoff_scaling_init | ||
|
|
||
| subroutine runoff_scaling(runoff_in, partit, mesh) | ||
| use MOD_PARTIT | ||
| use MOD_MESH | ||
| use o_PARAM, only: WP | ||
| real(kind=WP), intent(inout) :: runoff_in(:) | ||
| type(t_partit), intent(inout), target :: partit | ||
| type(t_mesh), intent(in), target :: mesh | ||
| end subroutine runoff_scaling | ||
| end interface | ||
| end module runoff_scaling_interface | ||
|
|
||
| !============================================= | ||
| ! | ||
| ! Module to set antarctic surface runoff to reference or constant values, | ||
| ! or to multiply runoff by any factor. | ||
| ! | ||
| ! Intended purpose is to use this for sets of experiments, where the net freshwater flux from surface runoff | ||
| ! stays consistent. For runs with different cavities/icebergs setup, these modules add freshwater that would | ||
| ! be counted double if runoff remains unchanged/unmasked. This module does both, depending on runscript parameters. | ||
| ! | ||
| !============================================= | ||
|
|
||
| module runoff_scaling_state | ||
| use o_PARAM , only: WP | ||
| implicit none | ||
| save | ||
|
|
||
| logical :: loaded = .false. | ||
| real(kind=WP), allocatable :: runoff_ref(:) | ||
| end module runoff_scaling_state | ||
|
|
||
| ! read reference file and apply values to callable variable | ||
| ! For now just monthly reference | ||
| ! runoff reference filename required to be 'runoff_ref_YYYY.dat' | ||
| ! file structure: 12 lines with monthly ref value in Sv | ||
|
|
||
| subroutine runoff_scaling_init() | ||
| use g_config | ||
| use g_clock | ||
| use runoff_scaling_state | ||
|
|
||
| implicit none | ||
|
|
||
| character(len=300) :: filename | ||
| integer :: iunit, ios, m | ||
| !real(kind=WP),allocatable :: runoff_ref(:) | ||
| !logical :: loaded = .false. | ||
|
|
||
| select case (trim(runoff_scaling_method)) | ||
|
|
||
| case ('ref') | ||
| allocate(runoff_ref(12)) | ||
| write(filename, '(A,"/runoff_ref_",I4.4,".dat")') trim(runoff_dir), yearnew | ||
|
|
||
| iunit = 99 | ||
| open(unit=iunit, file=filename, status='old', action='read', iostat=ios) | ||
| if (ios /= 0) then | ||
| write(*,*) "ERROR: Could not open runoff reference file:", trim(filename) | ||
| stop | ||
| end if | ||
|
|
||
| ! if (trim(runoff_scaling_time) == 'y') then | ||
| ! write cases for y/m/d -> how do leap years work? | ||
| ! as reference and model years should be the same, i think i just need to find the leap year flag and set | ||
| ! one do to 365 and one to 366 | ||
|
|
||
| do m = 1, 12 | ||
| read(iunit, *, iostat=ios) runoff_ref(m) | ||
| if (ios /= 0) then | ||
| write(*,*) "ERROR reading month ", m, " in ", trim(filename) | ||
| stop | ||
| end if | ||
| end do | ||
| close(iunit) | ||
|
|
||
| loaded = .true. | ||
| write(*,*) "Runoff scaling: Loaded ", trim(filename) | ||
| write (*,*) "Reference runoff: ", runoff_ref | ||
|
|
||
| case ('const') | ||
|
|
||
| write(*,*) "Case const" | ||
| ! runoff_ref = runoff_const_ref | ||
|
|
||
| case ('mult') | ||
|
|
||
| write(*,*) "Case mult" | ||
| ! runoff_ref = runoff_mult_factor | ||
|
|
||
| ! could add additional case for constant addition - alternative to fwflandice hosing | ||
| ! would apply evenly spread flux on all SO runoff nodes | ||
|
|
||
| case default | ||
|
|
||
| write(*,*) "Case default" | ||
|
|
||
| end select | ||
|
|
||
| end subroutine runoff_scaling_init | ||
|
|
||
| ! take the runoff for each timestep, calc the spatial integral for the southern ocean, compare with | ||
| ! the reference for the appropriate time, and finally apply the scaling factor from the integral | ||
| ! difference to each SO node | ||
| ! | ||
| ! For now just monthly reference | ||
|
|
||
| subroutine runoff_scaling(runoff_in, partit, mesh) | ||
| use MOD_PARTIT | ||
| use MOD_MESH | ||
| use g_support | ||
| use g_forcing_arrays | ||
| use g_clock | ||
| use runoff_scaling_state | ||
|
|
||
| implicit none | ||
|
|
||
| real(kind=WP), intent(inout) :: runoff_in(:) | ||
| integer :: i | ||
| !real(kind=WP), allocatable :: runoff_ref(:) | ||
| real(kind=WP), allocatable :: runoff_mask(:) | ||
| real(kind=WP) :: runoff_south | ||
| real(kind=WP) :: runoff_factor | ||
| type(t_partit), intent(inout), target :: partit | ||
| type(t_mesh), intent(in), target :: mesh | ||
| !logical :: loaded | ||
| #include "associate_part_def.h" | ||
| #include "associate_mesh_def.h" | ||
| #include "associate_part_ass.h" | ||
| #include "associate_mesh_ass.h" | ||
|
|
||
| if (mype==0) write (*,*) "In runoff_scaling()" | ||
| if (mype==0) write (*,*) "size of runoff_in: ", size(runoff_in) | ||
|
|
||
| allocate(runoff_mask(size(runoff_in))) | ||
|
|
||
| if (mype==0) write (*,*) "allocated runoff_mask" | ||
| if (mype==0) write (*,*) "size of runoff_mask: ", size(runoff_mask) | ||
|
|
||
| runoff_mask = 0.0_WP | ||
| if (mype==0) write (*,*) "size of runoff_mask: ", size(runoff_mask) | ||
|
|
||
| if (mype==0) write (*,*) "set runoff_mask to 0" | ||
|
|
||
| where (geo_coord_nod2D(2, :) < -60.0_WP * rad) | ||
| runoff_mask = runoff_in | ||
| end where | ||
|
|
||
| if (mype==0) write (*,*) "size of geo_coord_nod2D: ", size(geo_coord_nod2D(2, :)) | ||
| if (mype==0) write (*,*) "size of runoff_mask: ", size(runoff_mask) | ||
| if (mype==0) write (*,*) "size of runoff_in: ", size(runoff_in) | ||
| if (mype==0) write (*,*) "set runoff_mask to runoff_in fuer < -60" | ||
|
|
||
| call integrate_nod(runoff_mask, runoff_south, partit, mesh) | ||
|
|
||
| if (mype==0) write (*,*) "runoff south: ", runoff_south | ||
|
|
||
| select case (trim(runoff_scaling_method)) | ||
|
|
||
| case ('ref') | ||
|
|
||
| if (.not. loaded) then | ||
| write(*,*) "ERROR: runoff_scaling called before initialization." | ||
| stop | ||
| end if | ||
|
|
||
| if (runoff_south == 0.0_WP) then | ||
| runoff_factor = 1.0_WP | ||
| if (mype==0) write(*,*) "Warning: runoff_south = 0, skipping scaling, setting factor to 1.0" | ||
| else | ||
| runoff_factor = runoff_ref(month) * 1.0e6_WP / runoff_south | ||
| if (mype==0) write(*,*) "runoff factor:", runoff_factor | ||
| end if | ||
|
|
||
| !$OMP PARALLEL DO | ||
| do i = 1, myDim_nod2D + eDim_nod2D | ||
| if (geo_coord_nod2D(2, i) < -60.0_WP * rad) then | ||
| runoff_in(i) = runoff_in(i) * runoff_factor | ||
| end if | ||
| end do | ||
| !$OMP END PARALLEL DO | ||
|
|
||
| case ('const') | ||
|
|
||
| if (runoff_south == 0.0_WP) then | ||
| runoff_factor = 1.0_WP | ||
| if (mype==0) write(*,*) "Warning: runoff_south = 0, skipping scaling, setting factor to 1.0" | ||
| else | ||
| runoff_factor = runoff_const_ref * 1.0e6_WP / runoff_south | ||
| if (mype==0) write(*,*) "runoff factor:", runoff_factor | ||
| end if | ||
|
|
||
| !$OMP PARALLEL DO | ||
| do i = 1, myDim_nod2D + eDim_nod2D | ||
| if (geo_coord_nod2D(2, i) < -60.0_WP * rad) then | ||
| runoff_in(i) = runoff_in(i) * runoff_factor | ||
| end if | ||
| end do | ||
| !$OMP END PARALLEL DO | ||
|
|
||
| case ('mult') | ||
|
|
||
| !$OMP PARALLEL DO | ||
| do i = 1, myDim_nod2D + eDim_nod2D | ||
| if (geo_coord_nod2D(2, i) < -60.0_WP * rad) then | ||
| runoff_in(i) = runoff_in(i) * runoff_mult_factor | ||
| end if | ||
| end do | ||
| !$OMP END PARALLEL DO | ||
|
|
||
| case default | ||
|
|
||
| write(*,*) "Ended up in default case in runoff_scaling" | ||
|
|
||
| end select | ||
|
|
||
| deallocate(runoff_mask) | ||
| end subroutine runoff_scaling | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.