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

Simplify changes to the generic tracer interface for cobalt-p4: ocean_BGC side #8

Merged
merged 7 commits into from
Jan 26, 2024
Merged
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
5 changes: 4 additions & 1 deletion .github/workflows/cobalt_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

env:
BRANCH_NAME: dev/cefi

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
Expand Down Expand Up @@ -46,7 +49,7 @@ jobs:
- name: git clone MOM6_OBGC_examples and build mom6sis2-cobalt
run: |
cd ..
git clone https://github.com/NOAA-CEFI-Regional-Ocean-Modeling/MOM6_OBGC_examples.git --recursive
git clone -b $BRANCH_NAME https://github.com/NOAA-CEFI-Regional-Ocean-Modeling/MOM6_OBGC_examples.git --recursive
rm -rf MOM6_OBGC_examples/src/ocean_BGC
cp -r ocean_BGC MOM6_OBGC_examples/src
cd MOM6_OBGC_examples/builds
Expand Down
35 changes: 17 additions & 18 deletions generic_tracers/generic_COBALT.F90
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ module generic_COBALT
#ifndef INTERNAL_FILE_NML
use fms_mod, only: open_namelist_file, close_file
#endif
use MOM_EOS, only: calculate_density
use MOM_variables, only: thermo_var_ptrs
use MOM_EOS, only: calculate_density, EOS_type

use g_tracer_utils, only : g_tracer_type,g_tracer_start_param_list,g_tracer_end_param_list
use g_tracer_utils, only : g_tracer_add,g_tracer_add_param, g_tracer_set_files
Expand Down Expand Up @@ -7853,13 +7852,12 @@ end subroutine generic_COBALT_update_from_bottom
!subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,rho_dzt,dzt,hblt_depth,&
! ilb,jlb,tau,dt,grid_dat,model_time,nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff)
! If you'd like to pass the thermodynamic variables for a mld calculation
subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dzt,hblt_depth,&
ilb,jlb,tau,dt,grid_dat,model_time,nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff)
subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,rho_dzt,dzt,hblt_depth,&
ilb,jlb,tau,dt,grid_dat,model_time,nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff,geolat,eqn_of_state)
!subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,rho_dzt,dzt,hblt_depth,&
! ilb,jlb,tau,dt,grid_dat,model_time,nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff)

type(g_tracer_type), pointer :: tracer_list
type(thermo_var_ptrs), intent(in) :: tv
real, dimension(ilb:,jlb:,:), intent(in) :: Temp,Salt,rho_dzt,dzt
real, dimension(ilb:,jlb:), intent(in) :: hblt_depth
integer, intent(in) :: ilb,jlb,tau
Expand All @@ -7873,11 +7871,12 @@ subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dz
real, dimension(:,ilb:,jlb:,:), intent(in) :: opacity_band
real, dimension(ilb:,jlb:), intent(in) :: internal_heat
real, dimension(ilb:,jlb:), intent(in) :: frunoff
real, dimension(ilb:,jlb:), optional, intent(in) :: geolat
type(EOS_type), optional, intent(in) :: eqn_of_state !< Equation of state structure

character(len=fm_string_len), parameter :: sub_name = 'generic_COBALT_update_from_source'
integer :: isc,iec, jsc,jec,isd,ied,jsd,jed,nk,ntau, i, j, k , m, n, k_100, k_200, kbot
real, dimension(:,:,:) ,pointer :: grid_tmask
real, dimension(:,:), pointer :: geolon,geolat
integer, dimension(:,:),pointer :: mask_coast,grid_kmt
!
!------------------------------------------------------------------------
Expand Down Expand Up @@ -7952,8 +7951,7 @@ subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dz
r_dt = 1.0 / dt

call g_tracer_get_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,&
grid_tmask=grid_tmask,grid_mask_coast=mask_coast,grid_kmt=grid_kmt,&
geolon=geolon,geolat=geolat)
grid_tmask=grid_tmask,grid_mask_coast=mask_coast,grid_kmt=grid_kmt)

call mpp_clock_begin(id_clock_carbon_calculations)
!Get necessary fields
Expand Down Expand Up @@ -8317,7 +8315,7 @@ subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dz


! calculate the mld for the photoacclimation calculations
call calculate_density(Temp(i,j,kmld_ref),Salt(i,j,kmld_ref),101325.0,rho_mld_ref,tv%eqn_of_state)
call calculate_density(Temp(i,j,kmld_ref),Salt(i,j,kmld_ref),101325.0,rho_mld_ref,eqn_of_state)
!if ((i.eq.isc).and.(j.eq.jsc)) then
! write(outunit,*) 'rho_mld_ref = ',rho_mld_ref
!endif
Expand All @@ -8332,7 +8330,7 @@ subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dz
deltaRhoAtKm1 = deltaRhoAtK
dKm1 = dK
dK = cobalt%mld_aclm(i,j) + 0.5*dzt(i,j,k)
call calculate_density(Temp(i,j,k),Salt(i,j,k),101325.0,rho_k,tv%eqn_of_state)
call calculate_density(Temp(i,j,k),Salt(i,j,k),101325.0,rho_k,eqn_of_state)
cobalt%rho_test(i,j,k) = rho_k
deltaRhoAtK = rho_k - rho_mld_ref
if (deltaRhoAtK.lt.cobalt%densdiff_mld) then
Expand All @@ -8341,14 +8339,15 @@ subroutine generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dz
afac = (cobalt%densdiff_mld - deltaRhoAtKm1)/(deltaRhoAtK - deltaRhoAtKm1)
cobalt%mld_aclm(i,j) = afac*dK + (1.0-afac)*dKm1
deltaRhoFlag = 1.0
!if ((i.eq.isc).and.(j.eq.jsc)) then
! write(outunit,*) 'lat,lon=',geolat,geolon
! write(outunit,*) 'kmld_ref, k = ',kmld_ref, k
! write(outunit,*) 'rho_mld_ref = ',rho_mld_ref
! write(outunit,*) 'rho_k = ',rho_k
! write(outunit,*) 'deltaRhoAtK = ',deltaRhoAtK
! write(outunit,*) 'mld_aclm = ',cobalt%mld_aclm(i,j)
!endif
! if ((i.eq.isc).and.(j.eq.jsc)) then
! write(outunit,*) 'i,j=',i,j
! write(outunit,*) 'lat,lon=',geolat(i,j)
! write(outunit,*) 'kmld_ref, k = ',kmld_ref, k
! write(outunit,*) 'rho_mld_ref = ',rho_mld_ref
! write(outunit,*) 'rho_k = ',rho_k
! write(outunit,*) 'deltaRhoAtK = ',deltaRhoAtK
! write(outunit,*) 'mld_aclm = ',cobalt%mld_aclm(i,j)
! endif
endif
enddo !} k

Expand Down
32 changes: 20 additions & 12 deletions generic_tracers/generic_tracer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ module generic_tracer
use generic_COBALT, only : generic_COBALT_init, generic_COBALT_update_from_source,generic_COBALT_register_diag
use generic_COBALT, only : generic_COBALT_update_from_bottom,generic_COBALT_update_from_coupler
use generic_COBALT, only : generic_COBALT_set_boundary_values, generic_COBALT_end, do_generic_COBALT
use generic_COBALT, only : as_param_cobalt
use generic_COBALT, only : as_param_cobalt

use MOM_variables, only : thermo_var_ptrs
use MOM_EOS, only: EOS_type

implicit none ; private

Expand Down Expand Up @@ -248,17 +248,16 @@ end subroutine generic_tracer_register
! Grid mask
! </IN>
! </SUBROUTINE>
subroutine generic_tracer_init(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time,geolon,geolat)
subroutine generic_tracer_init(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time)
integer, intent(in) :: isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes(3)
type(time_type), intent(in) :: init_time
real, dimension(:,:,:),target, intent(in) :: grid_tmask
integer, dimension(:,:) , intent(in) :: grid_kmt
real, dimension(:,:),target, intent(in) :: geolon,geolat
type(g_tracer_type), pointer :: g_tracer,g_tracer_next

character(len=fm_string_len), parameter :: sub_name = 'generic_tracer_init'

call g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time,geolon,geolat)
call g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time)

!Allocate and initialize all registered generic tracers
!JGJ 2013/05/31 merged COBALT into siena_201303
Expand Down Expand Up @@ -505,11 +504,10 @@ end subroutine generic_tracer_diag
! </IN>
! </SUBROUTINE>

subroutine generic_tracer_source(Temp,Salt,tv,rho_dzt,dzt,hblt_depth,ilb,jlb,tau,dtts,&
subroutine generic_tracer_source(Temp,Salt,rho_dzt,dzt,hblt_depth,ilb,jlb,tau,dtts,&
grid_dat,model_time,nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,&
frunoff,grid_ht, current_wave_stress, sosga)
frunoff,grid_ht, current_wave_stress, sosga, geolat, eqn_of_state)
real, dimension(ilb:,jlb:,:), intent(in) :: Temp,Salt,rho_dzt,dzt
type(thermo_var_ptrs), intent(in) :: tv
real, dimension(ilb:,jlb:), intent(in) :: hblt_depth
integer, intent(in) :: ilb,jlb,tau
real, intent(in) :: dtts
Expand All @@ -524,7 +522,8 @@ subroutine generic_tracer_source(Temp,Salt,tv,rho_dzt,dzt,hblt_depth,ilb,jlb,tau
real, dimension(ilb:,jlb:),optional, intent(in) :: grid_ht
real, dimension(ilb:,jlb:),optional , intent(in) :: current_wave_stress
real, optional , intent(in) :: sosga ! global avg. sea surface salinity

real, dimension(ilb:,jlb:),optional, intent(in) :: geolat
type(EOS_type), optional, intent(in) :: eqn_of_state


character(len=fm_string_len), parameter :: sub_name = 'generic_tracer_update_from_source'
Expand Down Expand Up @@ -554,9 +553,18 @@ subroutine generic_tracer_source(Temp,Salt,tv,rho_dzt,dzt,hblt_depth,ilb,jlb,tau
hblt_depth,ilb,jlb,tau,dtts,grid_dat,model_time,&
nbands,max_wavelength_band,sw_pen_band,opacity_band, grid_ht)

if(do_generic_COBALT) call generic_COBALT_update_from_source(tracer_list,Temp,Salt,tv,rho_dzt,dzt,&
hblt_depth,ilb,jlb,tau,dtts,grid_dat,model_time,&
nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff)
if (do_generic_COBALT) then
if (present(geolat) .and. present(eqn_of_state)) then
call generic_COBALT_update_from_source(tracer_list,Temp,Salt,rho_dzt,dzt,&
hblt_depth,ilb,jlb,tau,dtts,grid_dat,model_time,&
nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff,&
geolat,eqn_of_state)
else
call generic_COBALT_update_from_source(tracer_list,Temp,Salt,rho_dzt,dzt,&
hblt_depth,ilb,jlb,tau,dtts,grid_dat,model_time,&
nbands,max_wavelength_band,sw_pen_band,opacity_band,internal_heat,frunoff)
endif
endif

if(do_generic_SF6) call generic_SF6_update_from_source(tracer_list,rho_dzt,dzt,hblt_depth,&
ilb,jlb,tau,dtts,grid_dat,model_time)
Expand Down
20 changes: 3 additions & 17 deletions generic_tracers/generic_tracer_utils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,6 @@ module g_tracer_utils
!coast mask
integer, _ALLOCATABLE, dimension(:,:):: grid_mask_coast _NULL

real, _ALLOCATABLE, dimension(:,:) :: geolon _NULL
real, _ALLOCATABLE, dimension(:,:) :: geolat _NULL

! IN and OUT (restart) files
character(len=fm_string_len) :: ice_restart_file, ocean_restart_file
end type g_tracer_common
Expand Down Expand Up @@ -1600,19 +1597,18 @@ end subroutine g_tracer_set_csdiag
! grid_mask array and initial time.
! </DESCRIPTION>
! <TEMPLATE>
! call g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time,geolon,geolat)
! call g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time)
! </TEMPLATE>
! <IN NAME="" TYPE="">
!
! </IN>
! </SUBROUTINE>

subroutine g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time,geolon,geolat)
subroutine g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid_tmask,grid_kmt,init_time)
integer, intent(in) :: isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes(3)
real, dimension(isd:,jsd:,:),intent(in) :: grid_tmask
integer,dimension(isd:,jsd:),intent(in) :: grid_kmt
type(time_type), intent(in) :: init_time
real, dimension(isd:,jsd:), intent(in) :: geolon,geolat

character(len=fm_string_len), parameter :: sub_name = 'g_tracer_set_common'
integer :: i,j
Expand Down Expand Up @@ -1641,12 +1637,6 @@ subroutine g_tracer_set_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,axes,grid

if(.NOT. _ALLOCATED(g_tracer_com%grid_mask_coast)) allocate(g_tracer_com%grid_mask_coast(isd:ied,jsd:jed))

if(.NOT. _ALLOCATED(g_tracer_com%geolon)) allocate(g_tracer_com%geolon(isd:ied,jsd:jed))
g_tracer_com%geolon = geolon

if(.NOT. _ALLOCATED(g_tracer_com%geolat)) allocate(g_tracer_com%geolat(isd:ied,jsd:jed))
g_tracer_com%geolat = geolat

!Determine the coast line.
!In order to that grid_tmask must have the proper value on the data domain boundaries isd,ied,jsd,jed
!so that we can decide if the coast line coinsides with a point on the compute domain boundary
Expand Down Expand Up @@ -1681,16 +1671,14 @@ end subroutine g_tracer_set_common
! </SUBROUTINE>

subroutine g_tracer_get_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,&
axes,grid_tmask,grid_mask_coast,grid_kmt,init_time,diag_CS,geolon,geolat)
axes,grid_tmask,grid_mask_coast,grid_kmt,init_time,diag_CS)

integer, intent(out) :: isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau
integer,optional, intent(out) :: axes(3)
type(time_type), optional, intent(out) :: init_time
real, optional, dimension(:,:,:),pointer :: grid_tmask
integer, optional, dimension(:,:), pointer :: grid_mask_coast
integer, optional, dimension(:,:), pointer :: grid_kmt
real, optional, dimension(:,:), pointer :: geolon
real, optional, dimension(:,:), pointer :: geolat
type(g_diag_ctrl), optional, pointer :: diag_CS

character(len=fm_string_len), parameter :: sub_name = 'g_tracer_get_common'
Expand All @@ -1713,8 +1701,6 @@ subroutine g_tracer_get_common(isc,iec,jsc,jec,isd,ied,jsd,jed,nk,ntau,&
if(present(grid_mask_coast)) grid_mask_coast=> g_tracer_com%grid_mask_coast
if(present(grid_kmt)) grid_kmt => g_tracer_com%grid_kmt
if(present(diag_CS)) diag_CS => g_tracer_com%diag_CS
if(present(geolon)) geolon => g_tracer_com%geolon
if(present(geolat)) geolat => g_tracer_com%geolat
! if(present(ice_restart_file)) ice_restart_file = g_tracer_com%ice_restart_file
! if(present(ocean_restart_file)) ocean_restart_file = g_tracer_com%ocean_restart_file

Expand Down
Loading