| 1 | dgoldberg | 1.6 | C $Header: /u/gcmpack/MITgcm/pkg/streamice/adstreamice_cg_solve.F,v 1.4 2013/08/22 22:56:18 jmc Exp $ | 
| 2 | dgoldberg | 1.1 | C $Name:  $ | 
| 3 |  |  |  | 
| 4 |  |  | #include "STREAMICE_OPTIONS.h" | 
| 5 |  |  |  | 
| 6 |  |  | C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| | 
| 7 |  |  |  | 
| 8 |  |  | CBOP | 
| 9 | dgoldberg | 1.6 | SUBROUTINE ADSTREAMICE_CG_SOLVE( | 
| 10 |  |  | U                               U_state,    ! velocities - need to be recalc ed | 
| 11 | dgoldberg | 1.1 | I                               cg_Bu,      ! adjoint of vel (input) | 
| 12 | dgoldberg | 1.6 | U                               V_state,    ! velocities - need to be recalc ed | 
| 13 | dgoldberg | 1.1 | I                               cg_Bv,      ! adjoint of vel (input) | 
| 14 |  |  | I                               Bu_state,   ! to recalc velocities | 
| 15 |  |  | U                               cg_Uin,     ! adjoint of RHS (output) | 
| 16 |  |  | I                               Bv_state,   ! to recalc velocities | 
| 17 |  |  | U                               cg_Vin,     ! adjoint of RHS (output) | 
| 18 |  |  | I                               A_uu,       ! section of matrix that multiplies u and projects on u | 
| 19 |  |  | U                               adA_uu,     ! adjoint of matrix coeffs (output) | 
| 20 |  |  | I                               A_uv,       ! section of matrix that multiplies v and projects on u | 
| 21 |  |  | U                               adA_uv,     ! adjoint of matrix coeffs (output) | 
| 22 |  |  | I                               A_vu,       ! section of matrix that multiplies u and projects on v | 
| 23 |  |  | U                               adA_vu,     ! adjoint of matrix coeffs (output) | 
| 24 |  |  | I                               A_vv,       ! section of matrix that multiplies v and projects on v | 
| 25 |  |  | U                               adA_vv,     ! adjoint of matrix coeffs (output) | 
| 26 | dgoldberg | 1.6 | I                               tolerance, | 
| 27 |  |  | I                               maxiters, | 
| 28 | dgoldberg | 1.1 | I                               myThid ) | 
| 29 | dgoldberg | 1.6 | C     *============================================================* | 
| 30 |  |  | C     | SUBROUTINE                                                 | | 
| 31 | dgoldberg | 1.1 | C     | o                                                          | | 
| 32 | dgoldberg | 1.6 | C     *============================================================* | 
| 33 |  |  |  | 
| 34 |  |  | C     !USES: | 
| 35 | dgoldberg | 1.1 | IMPLICIT NONE | 
| 36 |  |  |  | 
| 37 |  |  | C     === Global variables === | 
| 38 |  |  | #include "SIZE.h" | 
| 39 |  |  | #include "EEPARAMS.h" | 
| 40 |  |  | #include "PARAMS.h" | 
| 41 |  |  | #include "STREAMICE.h" | 
| 42 |  |  | #include "STREAMICE_CG.h" | 
| 43 |  |  |  | 
| 44 |  |  | C     !INPUT/OUTPUT ARGUMENTS | 
| 45 |  |  | C     cg_Uin, cg_Vin - input and output velocities | 
| 46 |  |  | C     cg_Bu, cg_Bv - driving stress | 
| 47 |  |  | _RL cg_Uin (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 48 |  |  | _RL cg_Vin (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 49 |  |  | _RL cg_Bu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 50 |  |  | _RL cg_Bv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 51 |  |  | _RL U_state (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 52 |  |  | _RL V_state (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 53 |  |  | _RL Bu_state (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 54 |  |  | _RL Bv_state (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 55 | dgoldberg | 1.6 | _RL | 
| 56 | dgoldberg | 1.1 | & A_uu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 57 |  |  | & A_vu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 58 |  |  | & A_uv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 59 |  |  | & A_vv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 60 |  |  | & adA_uu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 61 |  |  | & adA_vu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 62 |  |  | & adA_uv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1), | 
| 63 |  |  | & adA_vv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1) | 
| 64 |  |  | _RL tolerance | 
| 65 | dgoldberg | 1.6 | INTEGER maxiters | 
| 66 | dgoldberg | 1.1 | INTEGER myThid | 
| 67 |  |  |  | 
| 68 | dgoldberg | 1.6 | C     !LOCAL VARIABLES | 
| 69 | dgoldberg | 1.1 | INTEGER i, j, bi, bj, cg_halo, conv_flag, tmpiter | 
| 70 |  |  | INTEGER iter, is, js, ie, je, colx, coly, k | 
| 71 |  |  | _RL Utemp (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 72 |  |  | _RL Vtemp (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 73 |  |  | _RL UtempSt (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 74 |  |  | _RL VtempSt (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) | 
| 75 |  |  | _RL dot_p1, dot_p2, alpha_k, beta_k, resid, resid_0 | 
| 76 |  |  | _RL dot_p1_tile (nSx,nSy) | 
| 77 |  |  | _RL dot_p2_tile (nSx,nSy) | 
| 78 |  |  | _RL ad_tolerance | 
| 79 | dgoldberg | 1.3 | CHARACTER*(MAX_LEN_MBUF) msgBuf | 
| 80 | dgoldberg | 1.6 | CEOP | 
| 81 | dgoldberg | 1.1 |  | 
| 82 |  |  | !       iters = streamice_max_cg_iter | 
| 83 |  |  |  | 
| 84 |  |  | #ifdef ALLOW_STREAMICE | 
| 85 |  |  |  | 
| 86 | dgoldberg | 1.3 | WRITE(msgBuf,'(A)') 'CALLING MANUAL CG ADJOINT' | 
| 87 |  |  | CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, | 
| 88 |  |  | &                     SQUEEZE_RIGHT , 1) | 
| 89 | dgoldberg | 1.6 |  | 
| 90 |  |  | print *, "GOT HERE mythid=", mythid, tolerance | 
| 91 | dgoldberg | 1.1 |  | 
| 92 |  |  | conv_flag = 0 | 
| 93 |  |  | ad_tolerance = 1.e-14 | 
| 94 |  |  |  | 
| 95 |  |  | DO bj = myByLo(myThid), myByHi(myThid) | 
| 96 |  |  | DO bi = myBxLo(myThid), myBxHi(myThid) | 
| 97 | dgoldberg | 1.6 | DO j=1-OLy,sNy+OLy | 
| 98 |  |  | DO i=1-OLx,sNx+OLx | 
| 99 | dgoldberg | 1.1 | Utemp (i,j,bi,bj) = | 
| 100 |  |  | &     cg_Uin (i,j,bi,bj) | 
| 101 |  |  | Vtemp (i,j,bi,bj) = | 
| 102 |  |  | &     cg_Vin (i,j,bi,bj) | 
| 103 |  |  | UtempSt (i,j,bi,bj) = | 
| 104 |  |  | &     U_state (i,j,bi,bj) | 
| 105 |  |  | VtempSt (i,j,bi,bj) = | 
| 106 |  |  | &     V_state (i,j,bi,bj) | 
| 107 |  |  | ENDDO | 
| 108 |  |  | ENDDO | 
| 109 |  |  | ENDDO | 
| 110 |  |  | ENDDO | 
| 111 |  |  |  | 
| 112 | dgoldberg | 1.6 | print *, "GOT HERE 2 mythid=", mythid, tolerance | 
| 113 | dgoldberg | 1.2 |  | 
| 114 | dgoldberg | 1.6 | CALL STREAMICE_CG_SOLVE( | 
| 115 | dgoldberg | 1.1 | &  U_state, | 
| 116 |  |  | &  V_state, | 
| 117 |  |  | &  Bu_state, | 
| 118 |  |  | &  Bv_state, | 
| 119 |  |  | &  A_uu, | 
| 120 |  |  | &  A_uv, | 
| 121 |  |  | &  A_vu, | 
| 122 | dgoldberg | 1.6 | &  A_vv, | 
| 123 |  |  | &  tolerance, | 
| 124 | dgoldberg | 1.1 | &  tmpiter, | 
| 125 | dgoldberg | 1.6 | &  maxiters, | 
| 126 | dgoldberg | 1.1 | &  myThid ) | 
| 127 |  |  |  | 
| 128 | dgoldberg | 1.6 | print *, "GOT HERE 3 mythid=", mythid, tolerance | 
| 129 |  |  |  | 
| 130 | dgoldberg | 1.1 | tmpiter = 0 | 
| 131 |  |  |  | 
| 132 | dgoldberg | 1.2 | _EXCH_XY_RL( cg_Bu, myThid ) | 
| 133 |  |  | _EXCH_XY_RL( cg_Bv, myThid ) | 
| 134 |  |  |  | 
| 135 | dgoldberg | 1.6 | CALL STREAMICE_CG_SOLVE( | 
| 136 | dgoldberg | 1.1 | &  cg_Uin, | 
| 137 |  |  | &  cg_Vin, | 
| 138 |  |  | &  cg_Bu, | 
| 139 |  |  | &  cg_Bv, | 
| 140 |  |  | &  A_uu, | 
| 141 |  |  | &  A_uv, | 
| 142 |  |  | &  A_vu, | 
| 143 | dgoldberg | 1.6 | &  A_vv, | 
| 144 |  |  | &  ad_tolerance, | 
| 145 | dgoldberg | 1.1 | &  tmpiter, | 
| 146 | dgoldberg | 1.6 | &  maxiters, | 
| 147 | dgoldberg | 1.1 | &  myThid ) | 
| 148 |  |  |  | 
| 149 | dgoldberg | 1.6 | print *, "GOT HERE 4 mythid=", mythid, tolerance | 
| 150 |  |  |  | 
| 151 | dgoldberg | 1.2 | _EXCH_XY_RL( cg_Uin, myThid ) | 
| 152 | dgoldberg | 1.6 | _EXCH_XY_RL( cg_Vin, myThid ) | 
| 153 |  |  | _EXCH_XY_RL( U_state, myThid ) | 
| 154 |  |  | _EXCH_XY_RL( V_state, myThid ) | 
| 155 | dgoldberg | 1.1 |  | 
| 156 |  |  | DO bj = myByLo(myThid), myByHi(myThid) | 
| 157 |  |  | DO bi = myBxLo(myThid), myBxHi(myThid) | 
| 158 | dgoldberg | 1.6 | DO j=1,sNy | 
| 159 |  |  | DO i=1,sNx | 
| 160 | dgoldberg | 1.1 | DO colx=-1,1 | 
| 161 |  |  | DO coly=-1,1 | 
| 162 |  |  |  | 
| 163 |  |  | if (STREAMICE_umask(i,j,bi,bj).eq.1) then | 
| 164 |  |  | if (STREAMICE_umask(i+colx,j+coly,bi,bj).eq.1) then | 
| 165 | dgoldberg | 1.6 | adA_uu(i,j,bi,bj,colx,coly) = | 
| 166 |  |  | &           adA_uu(i,j,bi,bj,colx,coly) - | 
| 167 | dgoldberg | 1.1 | &           cg_Uin(i,j,bi,bj) * | 
| 168 |  |  | &           U_state(i+colx,j+coly,bi,bj) | 
| 169 | dgoldberg | 1.5 |  | 
| 170 | dgoldberg | 1.1 | endif | 
| 171 |  |  | if (STREAMICE_vmask(i+colx,j+coly,bi,bj).eq.1) then | 
| 172 |  |  | adA_uv(i,j,bi,bj,colx,coly) = | 
| 173 | dgoldberg | 1.6 | &           adA_uv(i,j,bi,bj,colx,coly) - | 
| 174 | dgoldberg | 1.1 | &           cg_Uin(i,j,bi,bj) * | 
| 175 |  |  | &           V_state(i+colx,j+coly,bi,bj) | 
| 176 |  |  | endif | 
| 177 |  |  | endif | 
| 178 |  |  |  | 
| 179 |  |  | if (STREAMICE_vmask(i,j,bi,bj).eq.1) then | 
| 180 |  |  | if (STREAMICE_umask(i+colx,j+coly,bi,bj).eq.1) then | 
| 181 |  |  | adA_vu(i,j,bi,bj,colx,coly) = | 
| 182 | dgoldberg | 1.6 | &           adA_vu(i,j,bi,bj,colx,coly) - | 
| 183 | dgoldberg | 1.1 | &           cg_Vin(i,j,bi,bj) * | 
| 184 |  |  | &           U_state(i+colx,j+coly,bi,bj) | 
| 185 |  |  | endif | 
| 186 |  |  | if (STREAMICE_vmask(i+colx,j+coly,bi,bj).eq.1) then | 
| 187 |  |  | adA_vv(i,j,bi,bj,colx,coly) = | 
| 188 | dgoldberg | 1.6 | &           adA_vv(i,j,bi,bj,colx,coly) - | 
| 189 | dgoldberg | 1.1 | &           cg_Vin(i,j,bi,bj) * | 
| 190 |  |  | &           V_state(i+colx,j+coly,bi,bj) | 
| 191 |  |  | endif | 
| 192 |  |  | endif | 
| 193 |  |  |  | 
| 194 |  |  | enddo | 
| 195 |  |  | enddo | 
| 196 |  |  | enddo | 
| 197 |  |  | enddo | 
| 198 |  |  | enddo | 
| 199 |  |  | enddo | 
| 200 |  |  |  | 
| 201 |  |  | DO bj = myByLo(myThid), myByHi(myThid) | 
| 202 |  |  | DO bi = myBxLo(myThid), myBxHi(myThid) | 
| 203 | dgoldberg | 1.6 | DO j=1-OLy,sNy+OLy | 
| 204 |  |  | DO i=1-OLx,sNx+OLx | 
| 205 | dgoldberg | 1.1 | if (i.lt.1.or.i.gt.sNx.or. | 
| 206 |  |  | &        j.lt.1.or.j.gt.sNy) then | 
| 207 |  |  | cg_Uin (i,j,bi,bj) = 0.0 | 
| 208 |  |  | cg_Vin (i,j,bi,bj) = 0.0 | 
| 209 | dgoldberg | 1.6 |  | 
| 210 | dgoldberg | 1.1 | DO colx=-1,1 | 
| 211 | dgoldberg | 1.6 | DO coly=-1,1 | 
| 212 | dgoldberg | 1.1 | ada_uu(i,j,bi,bj,colx,coly)=0.0 | 
| 213 |  |  | ada_uv(i,j,bi,bj,colx,coly)=0.0 | 
| 214 |  |  | ada_vu(i,j,bi,bj,colx,coly)=0.0 | 
| 215 |  |  | ada_vv(i,j,bi,bj,colx,coly)=0.0 | 
| 216 |  |  | enddo | 
| 217 |  |  | enddo | 
| 218 |  |  |  | 
| 219 |  |  | endif | 
| 220 |  |  | cg_Uin (i,j,bi,bj) = | 
| 221 | dgoldberg | 1.6 | &     cg_Uin (i,j,bi,bj) + | 
| 222 | dgoldberg | 1.1 | &     Utemp (i,j,bi,bj) | 
| 223 |  |  | cg_Vin (i,j,bi,bj) = | 
| 224 | dgoldberg | 1.6 | &     cg_Vin (i,j,bi,bj) + | 
| 225 | dgoldberg | 1.1 | &     Vtemp (i,j,bi,bj) | 
| 226 |  |  | cg_bu (i,j,bi,bj) = 0. | 
| 227 |  |  | cg_bv (i,j,bi,bj) = 0. | 
| 228 |  |  | U_state (i,j,bi,bj) = | 
| 229 |  |  | &     UtempSt (i,j,bi,bj) | 
| 230 |  |  | V_state (i,j,bi,bj) = | 
| 231 |  |  | &     VtempSt (i,j,bi,bj) | 
| 232 |  |  | ENDDO | 
| 233 |  |  | ENDDO | 
| 234 |  |  | ENDDO | 
| 235 |  |  | ENDDO | 
| 236 |  |  |  | 
| 237 | dgoldberg | 1.3 | WRITE(msgBuf,'(A,I5,A)') 'DONE WITH MANUAL CG ADJOINT:',tmpiter, | 
| 238 |  |  | & 'ITERS' | 
| 239 |  |  | CALL PRINT_MESSAGE( msgBuf, standardMessageUnit, | 
| 240 |  |  | &                     SQUEEZE_RIGHT , 1) | 
| 241 | dgoldberg | 1.1 |  | 
| 242 |  |  | #endif | 
| 243 |  |  | RETURN | 
| 244 |  |  | END | 
| 245 |  |  |  |