Basic fixes for the trends diagnostics
Context
- Branches impacted: main
- Dependencies: TRD
Analysis
The trends diagnostics seem to have been broken since at least the summer body development (16443a0b). For the NEMO 5 release, they should at least be able to run in an ocean-only configuration.
The code is broken due to the following issues:
-
Some of the trends diagnostics subroutines have incorrect array argument declarations
Most of the trends diagnostics subroutines use assumed shape syntax for the input array declarations, which will lead to incorrect results for arrays with less than 2 halo points.
For example, trd_pen is called via trd_tra_mng. These subroutines both use assumed shape syntax for their input array declarations:
REAL(wp), DIMENSION(:,:,:), INTENT(in) :: ptrdx, ptrdy ! Temperature & Salinity trends
REAL(wp), DIMENSION(:,:,:), INTENT(inout) :: ptrdx ! Temperature or U trend REAL(wp), DIMENSION(:,:,:), INTENT(inout) :: ptrdy ! Salinity or V trend
However,
trd_tra_mng
is called using input arrays with no halo points:ALLOCATE( trdtx(T2D(0),jpk), trdty(T2D(0),jpk), trdt(T2D(0),jpk), avt_evd(T2D(0),jpk), STAT= trd_tra_alloc ) ! REAL(wp), DIMENSION(T2D(0),jpk) :: ztrds ! CALL trd_tra_mng( trdt, ztrds, ktrd, kt, Kmm )
The indices of
trdt
/ztrds
will start from 3, but due to the assumed shape declarations intrd_tra_mng
andtrd_pen
the indices forptrdx
/ptrdy
will start from 1. This will result in the wrong part of the arrays being accessed bytrd_pen
, leading to incorrect results. -
XIOS grid definitions are incorrect for most tracer trends diagnostics
At present, most of the trends diagnostics in the tracer section of field_def_nemo-oce.xml are defined on the
grid_T_3D
grid. However, the arrays passed totrd_tra_iom
(viatrd_tra_mng
) have no halo points, which results in XIOS crashing. -
bu
andbv
are accessed outside of array bounds in trd_kenbu
andbv
are declared without halo points:ALLOCATE( bu(T2D(0),jpk) , bv(T2D(0),jpk) , r1_bt(T2D(0),jpk) , STAT= trd_ken_alloc )
but are accessed on halo points:
DO_3D( 0, 0, 0, 0, 1, jpkm1 ) zke(ji,jj,jk) = 0.5_wp * rho0 *( uu(ji ,jj,jk,Kmm) * putrd(ji ,jj,jk) * bu(ji ,jj,jk) & & + uu(ji-1,jj,jk,Kmm) * putrd(ji-1,jj,jk) * bu(ji-1,jj,jk) & & + vv(ji,jj ,jk,Kmm) * pvtrd(ji,jj ,jk) * bv(ji,jj ,jk) & & + vv(ji,jj-1,jk,Kmm) * pvtrd(ji,jj-1,jk) * bv(ji,jj-1,jk) ) * r1_bt(ji,jj,jk) END_3D
Fix
In principle, the arrays input to trd_tra
and trd_dyn
do not need to be defined on halo points for all diagnostics. They can generally be declared with shape DIMENSION(T2D(0),jpk)
, except:
-
In
trd_tra
, wheretrd_tra_adv
(tracer advection trend components) requires the input arrays to be defined over loop bounds(1, 0, 1, 0)
for the horizontal components -
In
trd_dyn
, wheretrd_vor_zint
requires the input arrays to be defined over loop bounds(0, 1, 0, 1)
andtrd_ken
requires them to be defined over loop bounds(1, 0, 1, 0)
The issues described above can mostly be addressed by reducing the shape of these arrays and ensuring they are defined on the required halo points:
-
All arrays passed to
trd_tra
have been declared with shapeDIMENSION(T2D(0),jpk)
, except for those used for the horizontal tracer advection trend components (jptra_xad
/jptra_yad
) which have been declared with shapeDIMENSION(T2D(1),jpk)
-
All arrays passed to
trd_dyn
have been declared with shapeDIMENSION(T2D(0),jpk)
. Intrd_dyn
, input arrays for thetrd_ken
andtrd_vor
diagnostics are copied to working arrays with shapeDIMENSION(T2D(1),jpk)
which are then passed tolbc_lnk
. Thislbc_lnk
replaces the calls intrd_ken
andtrd_vor
and adjusting the TRD subroutines accordingly:
-
A wrapper function has been added to
trd_tra
/trd_tra_adv
so that they correctly handle varying input array shapesThis approach is used elsewhere in the code, e.g. in eosbn2.F90
-
In other subroutines called from
trd_tra
, the input array declarations have been changed toDIMENSION(T2D(0),jpk)
-
Input array declarations in
trd_dyn
and its called subroutines have been changed toDIMENSION(T2D(0),jpk)
, except intrd_ken
/trd_vor
/trd_vor_zint*
where they have been changed toDIMENSION(T2D(1),jpk)
.
Additionally:
-
The XIOS grid definitions for the tracer trends diagnostics have been corrected:
- <field_group id="trendT_odd" grid_ref="grid_T_3D"> - <field_group id="trendT_even" grid_ref="grid_T_3D"> + <field_group id="trendT_odd" grid_ref="grid_T_3D_inner"> + <field_group id="trendT_even" grid_ref="grid_T_3D_inner">
-
The out-of-bounds array accesses in
trd_ken
have been resolved by declaringbu
andbv
withDIMENSION(A2D(1),jpkm1)
and defining them on the required halo points
Other changes
-
Fixed a divide by zero for the
jptra_zdfp
case intrd_tra
:- z1e3w = 1._wp / ( e3w(ji,jj,jk,Kmm) * tmask(ji,jj,jk) ) + z1e3w = ( 1._wp / e3w(ji,jj,jk,Kmm) ) * tmask(ji,jj,jk)
-
Wrapper functions were also added to
trd_trc
/trd_mxl_trc_zint
, but these changes were made mainly becausetrd_trc
is called fromtrd_tra
and they have not been tested. -
Removed some unnecessary uses of
T2D(0)
, e.g. wherez2d(:,:)
would be equivalent toz2d(T2D(0))
-
Replaced uses of
T2D
in module-level array declarations withA2D
This has no impact since the tiling is disabled for trends diagnostics, but it is more consistent with the planned coding conventions for NEMO 5 (
T2D
for local working arrays,A2D
for global and module-level arrays) -
Some other minor optimisations
Other issues that aren't fixed here
-
Several
namtrd
options are disabled byctl_stop
calls-
ln_tra_mxl
/ln_vor_trd
- 'ML tracer and Barotropic vorticity diags are still using old IOIPSL' -
ln_PE_trd
- 'trd_pen_init : PE trends not coded for variable volume' -
ln_dyn_mxl
- 'ML diag on momentum are not yet coded we stop'
-
-
The wind stress trends are not restartable when using RK3
With RK3,
ketrd_tau
(trd_ken) andutrd_tau
/vtrd_tau
(trd_dyn_iom) are not restartable because they depend onutau_b
/vtau_b
, which are only updated at the first timestep.@techene - I haven't fixed this because RK3 doesn't seem to use
utau_b
/vtau_b
and I'm not sure what to replace it with. Perhaps something to add to the list for when TRD is rewritten? -
Calls to
trd_tra
are commented out intra_adv_cen
andtra_adv_mus
These subroutines were rewritten in 16443a0b so that the trends arrays are now 2D instead of 3D. At present,
trd_tra
can only handle 3D input arrays. -
The passive tracer trends diagnostics may still be broken
I haven't done any testing with passive tracers, so I don't know if these trends diagnostics are functional.