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

Update MARBL #70

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 33 additions & 3 deletions source/ecosys_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module ecosys_driver
use shr_infnan_mod , only : shr_infnan_isnan

use marbl_interface , only : marbl_interface_class
use marbl_logging , only : marbl_log_type

use namelist_from_str_mod , only : namelist_split_by_line
use namelist_from_str_mod , only : namelist_split_by_nl
Expand Down Expand Up @@ -67,6 +68,7 @@ module ecosys_driver
! !PUBLIC MEMBER FUNCTIONS:

public :: ecosys_driver_init
public :: ecosys_driver_set_compute_now
public :: ecosys_driver_set_interior_forcing
public :: ecosys_driver_set_interior
public :: ecosys_driver_set_global_scalars
Expand Down Expand Up @@ -105,6 +107,7 @@ module ecosys_driver
!-----------------------------------------------------------------------

type(marbl_interface_class) :: marbl_instances(max_blocks_clinic)
type(marbl_log_type) :: driver_status_log

integer (int_kind) :: totChl_surf_nf_ind = 0 ! total chlorophyll in surface layer
integer (int_kind) :: sflux_co2_nf_ind = 0 ! air-sea co2 gas flux
Expand Down Expand Up @@ -232,6 +235,7 @@ subroutine ecosys_driver_init( &
ecosys_qsw_distrb_const, marbl_settings_file

errorCode = POP_Success
call driver_status_log%construct()

lmarginal_seas = .true.
ecosys_tadvect_ctype = 'base_model'
Expand Down Expand Up @@ -571,7 +575,13 @@ subroutine ecosys_driver_init( &
! Initialize tavg ids (need only do this using first block)
!--------------------------------------------------------------------

call ecosys_tavg_init(marbl_instances(1))
call ecosys_tavg_init(marbl_instances(1), driver_status_log)
if (driver_status_log%labort_marbl) then
call driver_status_log%log_error_trace("ecosys_tavg_init", subname)
call print_marbl_log(marbl_instances(1)%StatusLog, 1)
call print_marbl_log(driver_status_log, 1)
end if
call driver_status_log%erase()

!--------------------------------------------------------------------
! Register and set Chl field for short-wave absorption
Expand Down Expand Up @@ -759,7 +769,7 @@ subroutine ecosys_driver_set_interior( &
call marbl_instances(bid)%interior_tendency_compute()
if (marbl_instances(bid)%StatusLog%labort_marbl) then
write(log_message,"(A,I0,A)") "marbl_instances(", bid, &
")%set_interior_forcing()"
")%interior_tendency_compute()"
call marbl_instances(bid)%StatusLog%log_error_trace(log_message, subname)
end if
call print_marbl_log(marbl_instances(bid)%StatusLog, bid, i, c)
Expand Down Expand Up @@ -1105,6 +1115,27 @@ end subroutine ecosys_driver_post_set_sflux

!***********************************************************************

subroutine ecosys_driver_set_compute_now()

use ecosys_tavg, only : ecosys_tavg_set_compute_now
integer :: iblock
logical :: first_call = .true.

! Return if function has already been called
if (.not. first_call) return

! Loop through instances and set compute_now flag for all diagnostics
do iblock=1,nblocks_clinic
call ecosys_tavg_set_compute_now(marbl_instances(iblock)%surface_flux_diags, 'surface_flux', driver_status_log)
call ecosys_tavg_set_compute_now(marbl_instances(iblock)%interior_tendency_diags, 'interior_tendency', driver_status_log)
call print_marbl_log(driver_status_log, iblock)
call driver_status_log%erase()
end do
first_call = .false.
end subroutine ecosys_driver_set_compute_now

!***********************************************************************

subroutine ecosys_driver_comp_global_averages(field_source)

! DESCRIPTION:
Expand Down Expand Up @@ -1520,7 +1551,6 @@ end subroutine gen_marbl_to_pop_index_mapping
subroutine print_marbl_log(log_to_print, iblock, i, j)

use marbl_logging, only : marbl_status_log_entry_type
use marbl_logging, only : marbl_log_type
use grid, only : TLATD, TLOND
use blocks, only : get_block
use domain, only : blocks_clinic
Expand Down
201 changes: 119 additions & 82 deletions source/ecosys_tavg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module ecosys_tavg
use tavg , only : accumulate_tavg_field
use shr_sys_mod , only : shr_sys_abort
use marbl_interface , only : marbl_interface_class
use marbl_logging , only : marbl_log_type
use marbl_interface_public_types , only : marbl_diagnostics_type

use ecosys_diagnostics_operators_mod, only : max_marbl_diags_stream_cnt
Expand All @@ -39,6 +40,7 @@ module ecosys_tavg
public :: ecosys_tavg_accumulate_interior
public :: ecosys_tavg_accumulate_surface
public :: ecosys_tavg_accumulate_scalar_rmeans
public :: ecosys_tavg_set_compute_now

!-----------------------------------------------------------------------
! define tavg id for interior tendency diagnostics, diagnostics related
Expand All @@ -59,7 +61,7 @@ module ecosys_tavg

!***********************************************************************

subroutine ecosys_tavg_init(marbl_instance)
subroutine ecosys_tavg_init(marbl_instance, status_log)

! !DESCRIPTION:
! call define_tavg_field for all tavg fields
Expand All @@ -68,9 +70,8 @@ subroutine ecosys_tavg_init(marbl_instance)
use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface
use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior

implicit none

type(marbl_interface_class) , intent(in) :: marbl_instance
type(marbl_interface_class), intent(in) :: marbl_instance
type(marbl_log_type), intent(inout) :: status_log

!-----------------------------------------------------------------------
! local variables
Expand Down Expand Up @@ -100,11 +101,13 @@ subroutine ecosys_tavg_init(marbl_instance)

call ecosys_tavg_define_from_diag(marbl_diags=interior_tendency, &
stream_cnt=marbl_diags_stream_cnt_interior, &
tavg_ids=tavg_ids_interior_tendency)
tavg_ids=tavg_ids_interior_tendency, &
status_log=status_log)

call ecosys_tavg_define_from_diag(marbl_diags=surface_flux, &
stream_cnt=marbl_diags_stream_cnt_surface, &
tavg_ids=tavg_ids_surface_flux)
tavg_ids=tavg_ids_surface_flux, &
status_log=status_log)

end associate

Expand Down Expand Up @@ -137,8 +140,6 @@ subroutine ecosys_tavg_accumulate_surface(marbl_col_to_pop_i, marbl_col_to_pop_j
use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface
use ecosys_tracers_and_saved_state_mod, only : o2_ind

implicit none

integer, intent(in) :: marbl_col_to_pop_i(:)
integer, intent(in) :: marbl_col_to_pop_j(:)
real (r8) , intent(in) :: STF(:,:,:)
Expand All @@ -165,8 +166,6 @@ subroutine ecosys_tavg_accumulate_interior(i, c, marbl_instance, bid)

use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior

implicit none

integer, intent(in) :: i, c ! column indices
type(marbl_interface_class), intent(in) :: marbl_instance
integer, intent(in) :: bid ! block index
Expand All @@ -188,8 +187,6 @@ subroutine ecosys_tavg_accumulate_from_diag(i, c, bid, marbl_diags, marbl_diags_

! Accumulate diagnostics

implicit none

integer, dimension(:) , intent(in) :: i, c ! column indices
integer , intent(in) :: bid ! block index
type(marbl_diagnostics_type) , intent(in) :: marbl_diags
Expand Down Expand Up @@ -227,8 +224,6 @@ subroutine ecosys_tavg_accumulate_scalar_rmeans(marbl_instance, field_source)

! Accumulate diagnostics for scalar running means

implicit none

type(marbl_interface_class), intent(in) :: marbl_instance
character (*), intent(in) :: field_source ! 'interior_tendency' or 'surface_flux'

Expand All @@ -254,100 +249,142 @@ end subroutine ecosys_tavg_accumulate_scalar_rmeans

!***********************************************************************

subroutine ecosys_tavg_define_from_diag(marbl_diags, stream_cnt, tavg_ids)
subroutine ecosys_tavg_define_from_diag(marbl_diags, stream_cnt, tavg_ids, status_log)

use tavg, only : tavg_method_avg
use pop_constants, only : cmperm
use domain_size, only : km
use grid, only : zw

implicit none

type(marbl_diagnostics_type), intent(in) :: marbl_diags
integer(int_kind), dimension(:), intent(in) :: stream_cnt
integer(int_kind), dimension(:,:), intent(inout) :: tavg_ids
type(marbl_log_type), intent(inout) :: status_log

!-----------------------------------------------------------------------
! local variables
!-----------------------------------------------------------------------
character(char_len) :: err_msg, gloc, coords, short_name
character(char_len) :: err_msg, gloc, coords, short_name, vert_grid
integer :: m, n, ndims

real (r8) :: ref_depth_cm
integer :: ref_k
!-----------------------------------------------------------------------


associate(diags => marbl_diags%diags(:))

do n=1,size(diags)
if (trim(diags(n)%vertical_grid).eq.'none') then
ndims = 2
gloc = '2110'
coords = 'TLONG TLAT time'
! find layer containing ref_depth, i.e., zw(k-1) .le. ref_depth .lt. zw(k)
ref_depth_cm = cmperm * diags(n)%ref_depth
if (ref_depth_cm .lt. zw(km)) then
do ref_k = 1, km
if (ref_depth_cm .lt. zw(ref_k)) exit
end do
do n=1,size(marbl_diags%diags)
vert_grid = marbl_diags%get_str(n, 'vertical_grid', status_log)
if (trim(vert_grid).eq.'none') then
ndims = 2
gloc = '2110'
coords = 'TLONG TLAT time'
! find layer containing ref_depth, i.e., zw(k-1) .le. ref_depth .lt. zw(k)
ref_depth_cm = cmperm * marbl_diags%diags(n)%ref_depth
if (ref_depth_cm .lt. zw(km)) then
do ref_k = 1, km
if (ref_depth_cm .lt. zw(ref_k)) exit
end do
else
ref_k = km
end if
else
ndims = 3
if (trim(vert_grid) .eq. 'layer_avg') then
if (marbl_diags%diags(n)%ltruncated_vertical_extent) then
gloc = '3114'
coords = 'TLONG TLAT z_t_150m time'
else
ref_k = km
gloc = '3111'
coords = 'TLONG TLAT z_t time'
end if
else
ndims = 3
if (trim(diags(n)%vertical_grid).eq.'layer_avg') then
if (diags(n)%ltruncated_vertical_extent) then
gloc = '3114'
coords = 'TLONG TLAT z_t_150m time'
else
gloc = '3111'
coords = 'TLONG TLAT z_t time'
end if
elseif (trim(diags(n)%vertical_grid).eq.'layer_iface') then
gloc = '3112'
coords = 'TLONG TLAT z_w_top time'
else
write(err_msg,*) "'", trim(diags(n)%vertical_grid), &
"' is not a valid vertical grid"
call shr_sys_abort(err_msg)
end if
end if

do m=1,stream_cnt(n)
if (m .eq. 1) then
write(short_name, "(A)") trim(diags(n)%short_name)
else
write(short_name, "(A,'_',I0)") trim(diags(n)%short_name), m
end if
if (ndims .eq. 2) then
call define_tavg_field(tavg_ids(n,m), &
short_name, &
ndims, &
tavg_method = tavg_method_avg, &
long_name=trim(diags(n)%long_name), &
units=trim(diags(n)%units), &
grid_loc=gloc, &
mask_k=ref_k, &
coordinates=coords, &
transpose_field=(ndims .eq. 3))
else
call define_tavg_field(tavg_ids(n,m), &
short_name, &
ndims, &
tavg_method = tavg_method_avg, &
long_name=trim(diags(n)%long_name), &
units=trim(diags(n)%units), &
grid_loc=gloc, &
coordinates=coords, &
transpose_field=(ndims .eq. 3))
end if
end do
elseif (trim(vert_grid).eq.'layer_iface') then
gloc = '3112'
coords = 'TLONG TLAT z_w_top time'
else
write(err_msg,*) "'", trim(vert_grid), &
"' is not a valid vertical grid"
call shr_sys_abort(err_msg)
end if
end if

do m=1,stream_cnt(n)
if (m .eq. 1) then
write(short_name, "(A)") trim(marbl_diags%get_str(n, 'short_name', status_log))
else
write(short_name, "(A,'_',I0)") trim(marbl_diags%get_str(n, 'short_name', status_log)), m
end if
if (ndims .eq. 2) then
call define_tavg_field(tavg_ids(n,m), &
short_name, &
ndims, &
tavg_method = tavg_method_avg, &
long_name=marbl_diags%get_str(n, 'long_name', status_log), &
units=marbl_diags%get_str(n, 'units', status_log), &
grid_loc=gloc, &
mask_k=ref_k, &
coordinates=coords, &
transpose_field=(ndims .eq. 3))
else
call define_tavg_field(tavg_ids(n,m), &
short_name, &
ndims, &
tavg_method = tavg_method_avg, &
long_name=marbl_diags%get_str(n, 'long_name', status_log), &
units=marbl_diags%get_str(n, 'units', status_log), &
grid_loc=gloc, &
coordinates=coords, &
transpose_field=(ndims .eq. 3))
end if
end do
end associate
end do

end subroutine ecosys_tavg_define_from_diag

!***********************************************************************

subroutine ecosys_tavg_set_compute_now(marbl_diags, field_source, status_log)

use tavg, only : set_in_tavg_contents
use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_surface
use ecosys_diagnostics_operators_mod, only : marbl_diags_stream_cnt_interior

type(marbl_diagnostics_type), intent(inout) :: marbl_diags
character(len=*), intent(in) :: field_source
type(marbl_log_type), intent(inout) :: status_log

character(len=char_len) :: err_msg
logical :: in_tavg_contents
integer :: n, m

select case (trim(field_source))
case ('surface_flux')
do n=1,size(marbl_diags%diags)
in_tavg_contents = .false.
do m=1,marbl_diags_stream_cnt_surface(n)
in_tavg_contents = in_tavg_contents .or. set_in_tavg_contents(tavg_ids_surface_flux(n,m))
end do
call marbl_diags%set(n, 'compute_now', in_tavg_contents, status_log)
end do
case ('interior_tendency')
do n=1,size(marbl_diags%diags)
in_tavg_contents = .false.
do m=1,marbl_diags_stream_cnt_interior(n)
in_tavg_contents = in_tavg_contents .or. set_in_tavg_contents(tavg_ids_interior_tendency(n,m))
end do
call marbl_diags%set(n, 'compute_now', in_tavg_contents, status_log)
end do
case DEFAULT
write(err_msg, "(3A)") "'", trim(field_source), "' is not a valid field source"
call shr_sys_abort(err_msg)
end select

do n=1,size(marbl_diags%diags)
write(err_msg, *) "compute_now for '", trim(marbl_diags%get_str(n, 'short_name', status_log)), "': ", marbl_diags%diags(n)%compute_now
call status_log%log_noerror(err_msg, 'tmp_subname')
end do

end subroutine ecosys_tavg_set_compute_now

end module ecosys_tavg

!|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Loading