Skip to content

Commit

Permalink
Generalisation for fields that need to be regridded by YATM, WIP. COS…
Browse files Browse the repository at this point in the history
  • Loading branch information
nichannah committed Apr 16, 2020
1 parent 17d87ee commit 1d9fd9b
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 15 deletions.
5 changes: 3 additions & 2 deletions atm/src/atm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ program atm
type(ice_grid_type) :: ice_grid
type(runoff_type) :: runoff
type(field_type), dimension(:), allocatable :: fields
type(field_type) :: runoff_field
type(field_type), dimension(2) :: runoff_fields ! Liquid (river) and solid (iceberg) runoff
character(len=MAX_FILE_NAME_LEN) :: forcing_file, accessom2_config_dir
character(len=9) :: calendar
integer, dimension(2) :: ice_shape
Expand Down Expand Up @@ -92,7 +92,8 @@ program atm

! Initialise OASIS3-MCT fields. Runoff done seperately for now.
do i=1, num_atm_to_ice_fields
if (index(fields(i)%name, 'runof') /= 0) then
if ((index(fields(i)%name, 'runof') /= 0) .or. &
(index(fields(i)%name, 'licalvf') /= 0)) then
call assert(.not. allocated(runoff_field%data_array), &
'Runoff already associated')
runoff_field%name = fields(i)%name
Expand Down
17 changes: 12 additions & 5 deletions atm/src/forcing.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module forcing_mod
use, intrinsic :: iso_fortran_env, only : stderr=>error_unit

implicit none

private

type, public :: forcing
Expand Down Expand Up @@ -67,12 +66,12 @@ subroutine forcing_init_fields(self, fields, forcing_date, min_dt, calendar)

type(json_value), pointer :: fp
integer :: i
character(kind=CK, len=:), allocatable :: cname, fieldname
character(kind=CK, len=:), allocatable :: cname, fieldname, domain
character(kind=CK, len=:), allocatable :: filename_template
character(kind=CK, len=:), allocatable :: scaling_filename
character(len=1024) :: filename
character(len=9) :: calendar_str
logical :: found, scaling_found
logical :: found, scaling_found, domain_found

min_dt = huge(min_dt)
calendar_str = ''
Expand All @@ -92,15 +91,23 @@ subroutine forcing_init_fields(self, fields, forcing_date, min_dt, calendar)
call self%core%get(fp, "cname", cname, found)
call assert(found, "Entry 'cname' not found in forcing config.")

call self%core%get(fp, "domain", domain, domain_found)
if (domain_found) then
call assert(domain == "land" .or. domain == "atmosphere", &
"forcing_init_fields: invalid domain value.")
else
domain = "atmosphere"
endif

! Get the shape of forcing fields
filename = filename_for_year(filename_template, forcing_date%getYear())
! Initialise a new field object.
if (scaling_found) then
call fields(i)%init(cname, fieldname, filename_template, &
filename, self%logger, scaling_filename)
filename, domain, self%logger, scaling_filename)
else
call fields(i)%init(cname, fieldname, filename_template, &
filename, self%logger)
filename, domain, self%logger)
endif

if (fields(i)%dt < min_dt) then
Expand Down
21 changes: 19 additions & 2 deletions libcouple/src/field.F90
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ module field_mod
use logger_mod, only : logger_type => logger, LOG_DEBUG

implicit none

private

! Fields can be either atmospheric or ocean. YATM will treat the differently,
! see atm.F90 for details.
integer, parameter, public :: FIELD_DOMAIN_NONE = 0
integer, parameter, public :: FIELD_DOMAIN_ATMOSPHERE = 10
integer, parameter, public :: FIELD_LAND_LAND = 20

type, public :: field
character(len=64) :: name
integer :: field_type
character(len=1024) :: filename_template
character(len=1024) :: scaling_filename
type(datetime) :: timestamp
Expand All @@ -34,10 +40,11 @@ module field_mod
contains

subroutine field_init(self, name, ncname, filename_template, &
filename, logger, scaling_filename)
filename, domain, logger, scaling_filename)
class(field), intent(inout) :: self
character(len=*), intent(in) :: name, ncname
character(len=*), intent(in) :: filename_template, filename
character(len=*), intent(in) :: domain
type(logger_type), intent(in) :: logger
character(len=*), intent(in), optional :: scaling_filename

Expand All @@ -59,6 +66,16 @@ subroutine field_init(self, name, ncname, filename_template, &
self%scaling_data_array(:, :) = HUGE(1.0)
endif

! Set the field domain
self%domain = FIELD_DOMAIN_NONE
if (domain == 'atmosphere') then
self%domain = FIELD_DOMAIN_ATMOSPHERE
elseif (domain == 'land') then
self%field_type = FIELD_DOMAIN_LAND
endif
call assert(self%domain /= FIELD_DOMAIN_NONE, &
'field_init: invalid field domain')

end subroutine

subroutine field_update_data(self, filename, forcing_date)
Expand Down
6 changes: 4 additions & 2 deletions tests/JRA55_v1p4_IAF/forcing.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
{
"filename": "/g/data1b/qv56/replicas/input4MIPs/CMIP6/OMIP/MRI/MRI-JRA55-do-1-4-0/land/day/friver/gr/v20190429/friver/friver_input4MIPs_atmosphericState_OMIP_MRI-JRA55-do-1-4-0_gr_{{year}}0101-{{year}}1231.nc",
"fieldname": "friver",
"cname": "runof_ai"
"cname": "runof_ai",
"domain": "land"
},
{
"filename": "/g/data1b/qv56/replicas/input4MIPs/CMIP6/OMIP/MRI/MRI-JRA55-do-1-4-0/atmos/3hrPt/tas/gr/v20190429/tas/tas_input4MIPs_atmosphericState_OMIP_MRI-JRA55-do-1-4-0_gr_{{year}}01010000-{{year}}12312100.nc",
Expand All @@ -55,7 +56,8 @@
{
"filename": "/g/data1b/qv56/replicas/input4MIPs/CMIP6/OMIP/MRI/MRI-JRA55-do-1-4-0/landIce/day/licalvf/gr/v20190429/licalvf/licalvf_input4MIPs_atmosphericState_OMIP_MRI-JRA55-do-1-4-0_gr_{{year}}0101-{{year}}1231.nc",
"fieldname": "licalvf",
"cname": "licefw_ai"
"cname": "licalvf_ai",
"domain": "land"
}
]
}
4 changes: 2 additions & 2 deletions tests/JRA55_v1p4_IAF/ice.nml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
&ice_nml
resolution(:) = 360,300
from_atm_field_names = 'swfld_i', 'lwfld_i', 'rain_i', 'snow_i', 'press_i', 'runof_i', 'tair_i', 'qair_i', 'uwnd_i', 'vwnd_i', 'licefw_i'
to_ocean_field_names = 'strsu_io', 'strsv_io', 'rain_io', 'snow_io', 'stflx_io', 'htflx_io', 'swflx_io', 'qflux_io', 'shflx_io', 'lwflx_io', 'runof_io', 'press_io', 'aice_io', 'melt_io', 'form_io', 'licefw_io',
from_atm_field_names = 'swfld_i', 'lwfld_i', 'rain_i', 'snow_i', 'press_i', 'runof_i', 'tair_i', 'qair_i', 'uwnd_i', 'vwnd_i', 'licalvf_i'
to_ocean_field_names = 'strsu_io', 'strsv_io', 'rain_io', 'snow_io', 'stflx_io', 'htflx_io', 'swflx_io', 'qflux_io', 'shflx_io', 'lwflx_io', 'runof_io', 'press_io', 'aice_io', 'melt_io', 'form_io', 'licefw_io', 'liceht_io',
from_ocean_field_names = 'sst_i', 'sss_i', 'ssu_i', 'ssv_i', 'sslx_i', 'ssly_i', 'pfmice_i'
ice_grid_file = '../test_data/grid.nc'
ice_mask_file = '../test_data/kmt.nc'
Expand Down
20 changes: 18 additions & 2 deletions tests/JRA55_v1p4_IAF/namcouple
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ DISTWGT LR VECTOR LATLON 10 4 uwnd_ai
##########
# Field 11 : land ice calving flux, like runoff it is passed on the destination grid
##########
licefw_ai licecfw_i 56 10800 2 a2i.nc EXPORTED
licalvf_ai licalvf_i 56 10800 2 a2i.nc EXPORTED
cict cict LAG=0 SEQ=+1
P 0 P 0
#
Expand Down Expand Up @@ -280,7 +280,23 @@ cict cict LAG=0 SEQ=+1
LOCTRANS
INSTANT
##########
# Field 25 : ice forming eaterflux
# Field 25 : ice forming waterflux
##########
form_io wfiform 36 3600 1 i2o.nc IGNORED
cict cict LAG=0 SEQ=+1
#
LOCTRANS
INSTANT
##########
# Field 26 : land ice waterflux
##########
licefw_io wfiform 36 3600 1 i2o.nc IGNORED
cict cict LAG=0 SEQ=+1
#
LOCTRANS
INSTANT
##########
# Field 26 : land ice heatflux
##########
form_io wfiform 36 3600 1 i2o.nc IGNORED
cict cict LAG=0 SEQ=+1
Expand Down

0 comments on commit 1d9fd9b

Please sign in to comment.