From 5a8f762155d0654e12508f0d63df74ed97dbe444 Mon Sep 17 00:00:00 2001
From: sibylle <sibylle.techene@locean.ipsl.fr>
Date: Fri, 21 Jan 2022 12:10:51 +0100
Subject: [PATCH] vortex restart debug : Kmm_a initialised at Kbb/Nbb for RK3
 not at Kmm/Nnn ( Kmm/Nnn is an intermediary stage, it should not be
 meaningful at the beginning of a time step )

---
 src/NST/agrif_user.F90 |  4 ++++
 src/OCE/DOM/domqco.F90 |  4 +++-
 src/OCE/nemogcm.F90    | 12 ++++++++++++
 src/OCE/stprk3.F90     |  2 +-
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/NST/agrif_user.F90 b/src/NST/agrif_user.F90
index 06bf76ce..bd5416f7 100644
--- a/src/NST/agrif_user.F90
+++ b/src/NST/agrif_user.F90
@@ -28,7 +28,11 @@
       !!----------------------------------------------------------------------
       !
       CALL nemo_init       !* Initializations of each fine grid
+# if defined key_RK3
+      Kbb_a = Nbb; Kmm_a = Nbb; Krhs_a = Nrhs
+# else
       Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# endif
       !
       !                    !* Agrif initialization
       CALL Agrif_InitValues_cont
diff --git a/src/OCE/DOM/domqco.F90 b/src/OCE/DOM/domqco.F90
index 2e981d71..83d424cb 100644
--- a/src/OCE/DOM/domqco.F90
+++ b/src/OCE/DOM/domqco.F90
@@ -118,7 +118,9 @@ CONTAINS
       !                                ! Horizontal interpolation of e3t
 #if defined key_RK3
       CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb), r3f(:,:) )
-      CALL dom_qco_r3c( ssh(:,:,Kmm), r3t(:,:,Kmm), r3u(:,:,Kmm), r3v(:,:,Kmm)           )  !!st needed for Agrif_Grid call in nemo_gcm
+      r3t(:,:,Kmm) = r3t(:,:,Kbb)                            !!st r3 at Kmm needed to be initialised for Agrid_Grid call in nemo_gcm        
+      r3u(:,:,Kmm) = r3u(:,:,Kbb)                            !!             maybe we only need zeros ??? 
+      r3v(:,:,Kmm) = r3v(:,:,Kbb)      
 #else
       CALL dom_qco_r3c( ssh(:,:,Kbb), r3t(:,:,Kbb), r3u(:,:,Kbb), r3v(:,:,Kbb)           )
       CALL dom_qco_r3c( ssh(:,:,Kmm), r3t(:,:,Kmm), r3u(:,:,Kmm), r3v(:,:,Kmm), r3f(:,:) )
diff --git a/src/OCE/nemogcm.F90 b/src/OCE/nemogcm.F90
index dc97bf36..deab2b74 100644
--- a/src/OCE/nemogcm.F90
+++ b/src/OCE/nemogcm.F90
@@ -125,7 +125,11 @@ CONTAINS
       CALL nemo_init               !==  Initialisations  ==!
       !                            !-----------------------!
 #if defined key_agrif
+# if defined key_RK3
+      Kbb_a = Nbb; Kmm_a = Nbb; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# else
       Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# endif
       CALL Agrif_Declare_Var       !  "      "   "   "      "  DYN/TRA
 # if defined key_top
       CALL Agrif_Declare_Var_top   !  "      "   "   "      "  TOP
@@ -150,7 +154,11 @@ CONTAINS
       CALL Agrif_Regrid()
       !
       ! Recursive update from highest nested level to lowest:
+# if defined key_RK3
+      Kbb_a = Nbb; Kmm_a = Nbb; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# else
       Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# endif
       CALL Agrif_step_child_adj(Agrif_Update_All)
       CALL Agrif_step_child_adj(Agrif_Check_parent_bat)
       !
@@ -403,7 +411,11 @@ CONTAINS
       ! Initialise time level indices
       Nbb = 1   ;   Nnn = 2   ;   Naa = 3   ;   Nrhs = Naa
 #if defined key_agrif
+# if defined key_RK3
+      Kbb_a = Nbb   ;   Kmm_a = Nbb   ;   Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# else
       Kbb_a = Nbb   ;   Kmm_a = Nnn   ;   Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+# endif
 #endif
       !                             !-------------------------------!
       !                             !  NEMO general initialization  !
diff --git a/src/OCE/stprk3.F90 b/src/OCE/stprk3.F90
index 9b68d341..c027b91a 100644
--- a/src/OCE/stprk3.F90
+++ b/src/OCE/stprk3.F90
@@ -74,7 +74,7 @@ CONTAINS
 #if defined key_agrif
       IF( nstop > 0 )   RETURN   ! avoid to go further if an error was detected during previous time step (child grid)
       kstp = nit000 + Agrif_Nb_Step()
-      Kbb_a = Nbb   ; Kmm_a = Nnn   ;   Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
+      Kbb_a = Nbb   ; Kmm_a = Nbb   ;   Krhs_a = Nrhs   ! agrif_oce module copies of time level indices
       IF( lk_agrif_debug ) THEN
          IF( Agrif_Root() .AND. lwp)   WRITE(*,*) '---'
          IF(lwp)   WRITE(*,*) 'Grid Number', Agrif_Fixed(),' time step ', kstp, 'int tstep', Agrif_NbStepint()
-- 
GitLab