1 | MODULE solsor_tam |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE solsor *** |
---|
4 | !! Ocean solver : Tangent linear and Adjoint of Successive Over-Relaxation solver |
---|
5 | !!===================================================================== |
---|
6 | !! History : OPA ! 1990-10 (G. Madec) Original code |
---|
7 | !! 7.1 ! 1993-04 (G. Madec) time filter |
---|
8 | !! ! 1996-05 (G. Madec) merge sor and pcg formulations |
---|
9 | !! ! 1996-11 (A. Weaver) correction to preconditioning |
---|
10 | !! NEMO 1.0 ! 2003-04 (C. Deltel, G. Madec) Red-Black SOR in free form |
---|
11 | !! 2.0 ! 2005-09 (R. Benshila, G. Madec) MPI optimization |
---|
12 | !!---------------------------------------------------------------------- |
---|
13 | !! |
---|
14 | !!---------------------------------------------------------------------- |
---|
15 | !! sol_sor : Red-Black Successive Over-Relaxation solver |
---|
16 | !!---------------------------------------------------------------------- |
---|
17 | !! * Modules used |
---|
18 | USE par_oce |
---|
19 | USE in_out_manager |
---|
20 | USE sol_oce |
---|
21 | USE lib_mpp |
---|
22 | USE lbclnk |
---|
23 | USE lbclnk_tam |
---|
24 | USE sol_oce_tam |
---|
25 | USE dom_oce |
---|
26 | USE gridrandom |
---|
27 | USE dotprodfld |
---|
28 | USE tstool_tam |
---|
29 | USE lib_fortran |
---|
30 | USE wrk_nemo |
---|
31 | USE timing |
---|
32 | ! |
---|
33 | IMPLICIT NONE |
---|
34 | PRIVATE |
---|
35 | ! |
---|
36 | !! * Routine accessibility |
---|
37 | PUBLIC sol_sor_adj ! |
---|
38 | PUBLIC sol_sor_tan ! |
---|
39 | PUBLIC sol_sor_adj_tst ! called by tamtst.F90 |
---|
40 | !!---------------------------------------------------------------------- |
---|
41 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
42 | !! $Id$ |
---|
43 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
44 | !!---------------------------------------------------------------------- |
---|
45 | CONTAINS |
---|
46 | |
---|
47 | SUBROUTINE sol_sor_tan( kt, kindic ) |
---|
48 | !!---------------------------------------------------------------------- |
---|
49 | !! *** ROUTINE sol_sor_tan : TL of sol_sor *** |
---|
50 | !! |
---|
51 | !! ** Purpose : Solve the ellipic equation for the barotropic stream |
---|
52 | !! function system (lk_dynspg_rl=T) or the transport divergence |
---|
53 | !! system (lk_dynspg_flt=T) using a red-black successive-over- |
---|
54 | !! relaxation method. |
---|
55 | !! In the former case, the barotropic stream function trend has a |
---|
56 | !! zero boundary condition along all coastlines (i.e. continent |
---|
57 | !! as well as islands) while in the latter the boundary condition |
---|
58 | !! specification is not required. |
---|
59 | !! This routine provides a MPI optimization to the existing solsor |
---|
60 | !! by reducing the number of call to lbc. |
---|
61 | !! |
---|
62 | !! ** Method : Successive-over-relaxation method using the red-black |
---|
63 | !! technique. The former technique used was not compatible with |
---|
64 | !! the north-fold boundary condition used in orca configurations. |
---|
65 | !! Compared to the classical sol_sor, this routine provides a |
---|
66 | !! mpp optimization by reducing the number of calls to lnc_lnk |
---|
67 | !! The solution is computed on a larger area and the boudary |
---|
68 | !! conditions only when the inside domain is reached. |
---|
69 | !! |
---|
70 | !! References : |
---|
71 | !! Madec et al. 1988, Ocean Modelling, issue 78, 1-6. |
---|
72 | !! Beare and Stevens 1997 Ann. Geophysicae 15, 1369-1377 |
---|
73 | !! |
---|
74 | !! History of the direct routine: |
---|
75 | !! ! 90-10 (G. Madec) Original code |
---|
76 | !! ! 91-11 (G. Madec) |
---|
77 | !! 7.1 ! 93-04 (G. Madec) time filter |
---|
78 | !! ! 96-05 (G. Madec) merge sor and pcg formulations |
---|
79 | !! 9.0 ! 03-04 (C. Deltel, G. Madec) Red-Black SOR in free form |
---|
80 | !! 9.0 ! 05-09 (R. Benshila, G. Madec) MPI optimization |
---|
81 | !! History of the T&A routine: |
---|
82 | !! ! 96-11 (A. Weaver) correction to preconditioning |
---|
83 | !! 8.2 ! 03-02 (C. Deltel) OPAVAR tangent-linear version |
---|
84 | !! 9.0 ! 07-09 (K. Mogensen) tangent of the 03-04 version |
---|
85 | !! 9.0 ! 09-02 (A. Vidard) tangent of the 05-09 version |
---|
86 | !!---------------------------------------------------------------------- |
---|
87 | !! * Arguments |
---|
88 | INTEGER, INTENT( in ) :: kt ! Current timestep. |
---|
89 | INTEGER, INTENT( inout ) :: kindic ! solver indicator, < 0 if the conver- |
---|
90 | ! ! gence is not reached: the model is |
---|
91 | ! ! stopped in step |
---|
92 | ! ! set to zero before the call of solsor |
---|
93 | !! * Local declarations |
---|
94 | INTEGER :: ji, jj, jn ! dummy loop indices |
---|
95 | INTEGER :: ishift, icount, istp |
---|
96 | REAL(wp) :: ztmp, zres, zres2 |
---|
97 | |
---|
98 | INTEGER :: ijmppodd, ijmppeven |
---|
99 | INTEGER :: ijpr2d |
---|
100 | !!---------------------------------------------------------------------- |
---|
101 | ! |
---|
102 | IF( nn_timing == 1 ) CALL timing_start('sol_sor_tan') |
---|
103 | ! |
---|
104 | ijmppeven = MOD(nimpp+njmpp+jpr2di+jpr2dj ,2) |
---|
105 | ijmppodd = MOD(nimpp+njmpp+jpr2di+jpr2dj+1,2) |
---|
106 | ijpr2d = MAX(jpr2di,jpr2dj) |
---|
107 | icount = 0 |
---|
108 | ! ! ============== |
---|
109 | DO jn = 1, nn_nmax ! Iterative loop |
---|
110 | ! ! ============== |
---|
111 | ! applied the lateral boundary conditions |
---|
112 | IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp ) |
---|
113 | ! Residuals |
---|
114 | ! --------- |
---|
115 | ! Guess black update |
---|
116 | DO jj = 2-jpr2dj, nlcj - 1 + jpr2dj |
---|
117 | ishift = MOD( jj-ijmppodd-jpr2dj, 2 ) |
---|
118 | DO ji = 2-jpr2di+ishift, nlci - 1 + jpr2di, 2 |
---|
119 | ztmp = gcb_tl(ji ,jj ) & |
---|
120 | & - gcp(ji,jj,1) * gcx_tl(ji ,jj-1) & |
---|
121 | & - gcp(ji,jj,2) * gcx_tl(ji-1,jj ) & |
---|
122 | & - gcp(ji,jj,3) * gcx_tl(ji+1,jj ) & |
---|
123 | & - gcp(ji,jj,4) * gcx_tl(ji ,jj+1) |
---|
124 | ! Estimate of the residual |
---|
125 | zres = ztmp - gcx_tl(ji,jj) |
---|
126 | gcr_tl(ji,jj) = zres * gcdmat(ji,jj) * zres |
---|
127 | ! Guess update |
---|
128 | gcx_tl(ji,jj) = rn_sor * ztmp + ( 1.0_wp - rn_sor ) * gcx_tl(ji,jj) |
---|
129 | END DO |
---|
130 | END DO |
---|
131 | icount = icount + 1 |
---|
132 | ! applied the lateral boundary conditions |
---|
133 | IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp ) |
---|
134 | ! Guess red update |
---|
135 | DO jj = 2-jpr2dj, nlcj-1+jpr2dj |
---|
136 | ishift = MOD( jj-ijmppeven-jpr2dj, 2 ) |
---|
137 | DO ji = 2-jpr2di+ishift, nlci-1+jpr2di, 2 |
---|
138 | ztmp = gcb_tl(ji ,jj ) & |
---|
139 | & - gcp(ji,jj,1) * gcx_tl(ji ,jj-1) & |
---|
140 | & - gcp(ji,jj,2) * gcx_tl(ji-1,jj ) & |
---|
141 | & - gcp(ji,jj,3) * gcx_tl(ji+1,jj ) & |
---|
142 | & - gcp(ji,jj,4) * gcx_tl(ji ,jj+1) |
---|
143 | ! Estimate of the residual |
---|
144 | zres = ztmp - gcx_tl(ji,jj) |
---|
145 | gcr_tl(ji,jj) = zres * gcdmat(ji,jj) * zres |
---|
146 | ! Guess update |
---|
147 | gcx_tl(ji,jj) = rn_sor * ztmp + ( 1.0_wp - rn_sor ) * gcx_tl(ji,jj) |
---|
148 | END DO |
---|
149 | END DO |
---|
150 | icount = icount + 1 |
---|
151 | ! test of convergence |
---|
152 | IF ( (jn > nn_nmin .AND. MOD( jn-nn_nmin, nn_nmod ) == 0) .OR. jn==nn_nmax) THEN |
---|
153 | SELECT CASE ( nn_sol_arp ) |
---|
154 | CASE ( 0 ) |
---|
155 | ! absolute precision (maximum value of the residual) |
---|
156 | zres2 = MAXVAL( gcr_tl(2:nlci - 1,2:nlcj - 1) ) |
---|
157 | IF( lk_mpp ) CALL mpp_max( zres2 ) ! max over the global domain |
---|
158 | ! test of convergence |
---|
159 | IF( zres2 < rn_resmax .OR. jn == nn_nmax ) THEN |
---|
160 | res = SQRT( zres2 ) |
---|
161 | niter = jn |
---|
162 | ncut = 999 |
---|
163 | ! Store number of iterations for adjoint computation |
---|
164 | istp = kt - nit000 + 1 |
---|
165 | nitsor(istp) = niter |
---|
166 | ENDIF |
---|
167 | CASE ( 1 ) ! relative precision |
---|
168 | rnorme = glob_sum(gcr_tl(2:nlci - 1, 2:nlcj - 1)) |
---|
169 | ! test of convergence |
---|
170 | IF( rnorme < epsr .OR. jn == nn_nmax ) THEN |
---|
171 | res = SQRT( rnorme ) |
---|
172 | niter = jn |
---|
173 | ncut = 999 |
---|
174 | ! Store number of iterations for adjoint computation |
---|
175 | istp = kt - nit000 + 1 |
---|
176 | nitsor(istp) = niter |
---|
177 | ENDIF |
---|
178 | END SELECT |
---|
179 | !**** |
---|
180 | IF(lwp)WRITE(numsol,9300) jn, res, sqrt( epsr ) / eps |
---|
181 | 9300 FORMAT(' niter :',i6,' res :',e20.10,' b :',e20.10) |
---|
182 | !**** |
---|
183 | ENDIF |
---|
184 | ! indicator of non-convergence or explosion |
---|
185 | IF( jn == nn_nmax ) nitsor(istp) = jn |
---|
186 | IF( jn == nn_nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2 |
---|
187 | IF( ncut == 999 ) GOTO 999 |
---|
188 | ! ! ===================== |
---|
189 | END DO ! END of iterative loop |
---|
190 | ! ! ===================== |
---|
191 | 999 CONTINUE |
---|
192 | ! Output in gcx_tl |
---|
193 | ! ---------------- |
---|
194 | CALL lbc_lnk_e( gcx_tl, c_solver_pt, 1.0_wp ) ! Lateral BCs |
---|
195 | ! |
---|
196 | IF( nn_timing == 1 ) CALL timing_stop('sol_sor_tan') |
---|
197 | ! |
---|
198 | END SUBROUTINE sol_sor_tan |
---|
199 | SUBROUTINE sol_sor_adj( kt, kindic ) |
---|
200 | !!---------------------------------------------------------------------- |
---|
201 | !! *** ROUTINE sol_sor_adj : adjoint of sol_sor *** |
---|
202 | !! |
---|
203 | !! ** Purpose : Solve the ellipic equation for the barotropic stream |
---|
204 | !! function system (lk_dynspg_rl=T) or the transport divergence |
---|
205 | !! system (lk_dynspg_flt=T) using a red-black successive-over- |
---|
206 | !! relaxation method. |
---|
207 | !! In the former case, the barotropic stream function trend has a |
---|
208 | !! zero boundary condition along all coastlines (i.e. continent |
---|
209 | !! as well as islands) while in the latter the boundary condition |
---|
210 | !! specification is not required. |
---|
211 | !! This routine provides a MPI optimization to the existing solsor |
---|
212 | !! by reducing the number of call to lbc. |
---|
213 | !! |
---|
214 | !! ** Method : Successive-over-relaxation method using the red-black |
---|
215 | !! technique. The former technique used was not compatible with |
---|
216 | !! the north-fold boundary condition used in orca configurations. |
---|
217 | !! Compared to the classical sol_sor, this routine provides a |
---|
218 | !! mpp optimization by reducing the number of calls to lbc_lnk |
---|
219 | !! The solution is computed on a larger area and the boudary |
---|
220 | !! conditions only when the inside domain is reached. |
---|
221 | !! ** Comments on adjoint routine : |
---|
222 | !! When the step in a tangent-linear DO loop is an arbitrary |
---|
223 | !! integer then care must be taken in computing the lower bound |
---|
224 | !! of the adjoint DO loop; i.e., |
---|
225 | !! |
---|
226 | !! If the tangent-linear DO loop is: low_tl, up_tl, step |
---|
227 | !! |
---|
228 | !! then the adjoint DO loop is: low_ad, up_ad, -step |
---|
229 | !! |
---|
230 | !! where low_ad = low_tl + step * INT( ( up_tl - low_tl ) / step ) |
---|
231 | !! up_ad = low_tl |
---|
232 | !! |
---|
233 | !! NB. If step = 1 then low_ad = up_tl |
---|
234 | !! |
---|
235 | !! References : |
---|
236 | !! Madec et al. 1988, Ocean Modelling, issue 78, 1-6. |
---|
237 | !! Beare and Stevens 1997 Ann. Geophysicae 15, 1369-1377 |
---|
238 | !! |
---|
239 | !! History of the direct routine: |
---|
240 | !! ! 90-10 (G. Madec) Original code |
---|
241 | !! ! 91-11 (G. Madec) |
---|
242 | !! 7.1 ! 93-04 (G. Madec) time filter |
---|
243 | !! ! 96-05 (G. Madec) merge sor and pcg formulations |
---|
244 | !! 9.0 ! 03-04 (C. Deltel, G. Madec) Red-Black SOR in free form |
---|
245 | !! 9.0 ! 05-09 (R. Benshila, G. Madec) MPI optimization |
---|
246 | !! History of the T&A routine: |
---|
247 | !! ! 96-11 (A. Weaver) correction to preconditioning |
---|
248 | !! 8.2 ! 03-02 (C. Deltel) OPAVAR tangent-linear version |
---|
249 | !! 9.0 ! 07-09 (K. Mogensen, A. Weaver) adjoint of the 03-04 version |
---|
250 | !! 9.0 ! 09-02 (A. Vidard) adjoint of the 05-09 version |
---|
251 | !!---------------------------------------------------------------------- |
---|
252 | !! * Arguments |
---|
253 | INTEGER, INTENT( in ) :: kt ! Current timestep. |
---|
254 | INTEGER, INTENT( inout ) :: kindic ! solver indicator, < 0 if the conver- |
---|
255 | ! ! gence is not reached: the model is |
---|
256 | ! ! stopped in step |
---|
257 | ! ! set to zero before the call of solsor |
---|
258 | !! * Local declarations |
---|
259 | INTEGER :: ji, jj, jn ! dummy loop indices |
---|
260 | INTEGER :: ishift, icount, istp, iter, ilower |
---|
261 | REAL(wp) :: ztmpad |
---|
262 | |
---|
263 | INTEGER :: ijmppodd, ijmppeven |
---|
264 | INTEGER :: ijpr2d |
---|
265 | !!---------------------------------------------------------------------- |
---|
266 | IF( nn_timing == 1 ) CALL timing_start('sol_sor_adj') |
---|
267 | ! |
---|
268 | ijmppeven = MOD(nimpp+njmpp+jpr2di+jpr2dj,2) |
---|
269 | ijmppodd = MOD(nimpp+njmpp+jpr2di+jpr2dj+1,2) |
---|
270 | ijpr2d = MAX(jpr2di,jpr2dj) |
---|
271 | ! |
---|
272 | ! Fixed number of iterations |
---|
273 | istp = kt - nit000 + 1 |
---|
274 | iter = nitsor(istp) |
---|
275 | icount = iter * 2 |
---|
276 | ! Output in gcx_ad |
---|
277 | ! ---------------- |
---|
278 | CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp ) ! Lateral BCs |
---|
279 | ! ! ============== |
---|
280 | DO jn = iter, 1, -1 ! Iterative loop |
---|
281 | ! ! ============== |
---|
282 | ! Guess red update |
---|
283 | DO jj = nlcj-1+jpr2dj, 2-jpr2dj, -1 |
---|
284 | ishift = MOD( jj-ijmppeven-jpr2dj, 2 ) |
---|
285 | ! this weird computation is to cope with odd end of loop in the tangent |
---|
286 | ilower = 2-jpr2dj+ishift + 2 * INT( ( ( nlci-1+jpr2dj )-( 2-jpr2dj+ishift ) ) / 2 ) |
---|
287 | DO ji = ilower, 2-jpr2dj+ishift, -2 |
---|
288 | ! Guess update |
---|
289 | ztmpad = rn_sor * gcx_ad(ji,jj) |
---|
290 | gcx_ad(ji ,jj ) = gcx_ad(ji ,jj ) * ( 1.0_wp - rn_sor ) |
---|
291 | |
---|
292 | gcb_ad(ji ,jj ) = gcb_ad(ji ,jj ) + ztmpad |
---|
293 | gcx_ad(ji ,jj-1) = gcx_ad(ji ,jj-1) - ztmpad * gcp(ji,jj,1) |
---|
294 | gcx_ad(ji-1,jj ) = gcx_ad(ji-1,jj ) - ztmpad * gcp(ji,jj,2) |
---|
295 | gcx_ad(ji+1,jj ) = gcx_ad(ji+1,jj ) - ztmpad * gcp(ji,jj,3) |
---|
296 | gcx_ad(ji ,jj+1) = gcx_ad(ji ,jj+1) - ztmpad * gcp(ji,jj,4) |
---|
297 | END DO |
---|
298 | END DO |
---|
299 | icount = icount - 1 |
---|
300 | ! applied the lateral boundary conditions |
---|
301 | IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp ) ! Lateral BCs |
---|
302 | ! Residus |
---|
303 | ! ------- |
---|
304 | ! Guess black update |
---|
305 | DO jj = nlcj-1+jpr2dj, 2-jpr2dj, -1 |
---|
306 | ishift = MOD( jj-ijmppodd-jpr2dj, 2 ) |
---|
307 | ilower = 2-jpr2dj+ishift + 2 * INT( ( ( nlci-1+jpr2dj )-( 2-jpr2dj+ishift ) ) / 2 ) |
---|
308 | DO ji = ilower, 2-jpr2dj+ishift, -2 |
---|
309 | ! Guess update |
---|
310 | ztmpad = rn_sor * gcx_ad(ji,jj) |
---|
311 | gcx_ad(ji ,jj ) = gcx_ad(ji ,jj ) * ( 1.0_wp - rn_sor ) |
---|
312 | |
---|
313 | gcb_ad(ji ,jj ) = gcb_ad(ji ,jj ) + ztmpad |
---|
314 | gcx_ad(ji ,jj-1) = gcx_ad(ji ,jj-1) - ztmpad * gcp(ji,jj,1) |
---|
315 | gcx_ad(ji-1,jj ) = gcx_ad(ji-1,jj ) - ztmpad * gcp(ji,jj,2) |
---|
316 | gcx_ad(ji+1,jj ) = gcx_ad(ji+1,jj ) - ztmpad * gcp(ji,jj,3) |
---|
317 | gcx_ad(ji ,jj+1) = gcx_ad(ji ,jj+1) - ztmpad * gcp(ji,jj,4) |
---|
318 | END DO |
---|
319 | END DO |
---|
320 | icount = icount - 1 |
---|
321 | ! applied the lateral boundary conditions |
---|
322 | IF( MOD(icount,ijpr2d+1) == 0 ) CALL lbc_lnk_e_adj( gcx_ad, c_solver_pt, 1.0_wp ) ! Lateral BCs |
---|
323 | ! ! ===================== |
---|
324 | END DO ! END of iterative loop |
---|
325 | ! ! ===================== |
---|
326 | IF( nn_timing == 1 ) CALL timing_stop('sol_sor_adj') |
---|
327 | |
---|
328 | END SUBROUTINE sol_sor_adj |
---|
329 | SUBROUTINE sol_sor_adj_tst( kumadt ) |
---|
330 | !!----------------------------------------------------------------------- |
---|
331 | !! |
---|
332 | !! *** ROUTINE example_adj_tst *** |
---|
333 | !! |
---|
334 | !! ** Purpose : Test the adjoint routine. |
---|
335 | !! |
---|
336 | !! ** Method : Verify the scalar product |
---|
337 | !! |
---|
338 | !! ( L dx )^T W dy = dx^T L^T W dy |
---|
339 | !! |
---|
340 | !! where L = tangent routine |
---|
341 | !! L^T = adjoint routine |
---|
342 | !! W = diagonal matrix of scale factors |
---|
343 | !! dx = input perturbation (random field) |
---|
344 | !! dy = L dx |
---|
345 | !! |
---|
346 | !! |
---|
347 | !! History : |
---|
348 | !! ! 08-08 (A. Vidard) |
---|
349 | !!----------------------------------------------------------------------- |
---|
350 | !! * Modules used |
---|
351 | |
---|
352 | !! * Arguments |
---|
353 | INTEGER, INTENT(IN) :: & |
---|
354 | & kumadt ! Output unit |
---|
355 | |
---|
356 | !! * Local declarations |
---|
357 | INTEGER :: & |
---|
358 | & ji, & ! dummy loop indices |
---|
359 | & jj, & |
---|
360 | & jn, & |
---|
361 | & jk, & |
---|
362 | & kindic,& ! flags fo solver convergence |
---|
363 | & kmod, & ! frequency of test for the SOR solver |
---|
364 | & kt ! number of iteration |
---|
365 | REAL(KIND=wp) :: & |
---|
366 | & zsp1, & ! scalar product involving the tangent routine |
---|
367 | & zsp2 ! scalar product involving the adjoint routine |
---|
368 | REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: & |
---|
369 | & zgcb_tlin , & ! Tangent input |
---|
370 | & zgcx_tlin , & ! Tangent input |
---|
371 | & zgcx_tlout, & ! Tangent output |
---|
372 | & zgcx_adin , & ! Adjoint input |
---|
373 | & zgcb_adout, & ! Adjoint output |
---|
374 | & zgcx_adout, & ! Adjoint output |
---|
375 | & zr ! 3D random field |
---|
376 | CHARACTER(LEN=14) :: cl_name |
---|
377 | ! Allocate memory |
---|
378 | |
---|
379 | |
---|
380 | ALLOCATE( & |
---|
381 | & zgcb_tlin( jpi,jpj), & |
---|
382 | & zgcx_tlin( jpi,jpj), & |
---|
383 | & zgcx_tlout(jpi,jpj), & |
---|
384 | & zgcx_adin( jpi,jpj), & |
---|
385 | & zgcx_adout(jpi,jpj), & |
---|
386 | & zgcb_adout(jpi,jpj), & |
---|
387 | & zr( jpi,jpj) & |
---|
388 | & ) |
---|
389 | !================================================================== |
---|
390 | ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and |
---|
391 | ! dy = ( hdivb_tl, hdivn_tl ) |
---|
392 | !================================================================== |
---|
393 | |
---|
394 | !-------------------------------------------------------------------- |
---|
395 | ! Reset the tangent and adjoint variables |
---|
396 | !-------------------------------------------------------------------- |
---|
397 | zgcb_tlin( :,:) = 0.0_wp |
---|
398 | zgcx_tlin( :,:) = 0.0_wp |
---|
399 | zgcx_tlout(:,:) = 0.0_wp |
---|
400 | zgcx_adin( :,:) = 0.0_wp |
---|
401 | zgcx_adout(:,:) = 0.0_wp |
---|
402 | zgcb_adout(:,:) = 0.0_wp |
---|
403 | zr( :,:) = 0.0_wp |
---|
404 | !-------------------------------------------------------------------- |
---|
405 | ! Initialize the tangent input with random noise: dx |
---|
406 | !-------------------------------------------------------------------- |
---|
407 | kt=nit000 |
---|
408 | kindic=0 |
---|
409 | ! kmod = nn_nmod ! store frequency of test for the SOR solver |
---|
410 | ! nn_nmod = 1 ! force frequency to one (remove adj_tst dependancy to nn_nmin) |
---|
411 | |
---|
412 | CALL grid_random( zr, c_solver_pt, 0.0_wp, stdgc ) |
---|
413 | DO jj = nldj, nlej |
---|
414 | DO ji = nldi, nlei |
---|
415 | zgcb_tlin(ji,jj) = zr(ji,jj) |
---|
416 | END DO |
---|
417 | END DO |
---|
418 | CALL grid_random( zr, c_solver_pt, 0.0_wp, stdgc ) |
---|
419 | DO jj = nldj, nlej |
---|
420 | DO ji = nldi, nlei |
---|
421 | zgcx_tlin(ji,jj) = zr(ji,jj) |
---|
422 | END DO |
---|
423 | END DO |
---|
424 | ncut = 1 ! reinitialize the solver convergence flag |
---|
425 | gcr_tl(:,:) = 0.0_wp |
---|
426 | gcb_tl(:,:) = zgcb_tlin(:,:) |
---|
427 | gcx_tl(:,:) = zgcx_tlin(:,:) |
---|
428 | CALL sol_sor_tan(kt, kindic) |
---|
429 | zgcx_tlout(:,:) = gcx_tl(:,:) |
---|
430 | |
---|
431 | !-------------------------------------------------------------------- |
---|
432 | ! Initialize the adjoint variables: dy^* = W dy |
---|
433 | !-------------------------------------------------------------------- |
---|
434 | |
---|
435 | DO jj = nldj, nlej |
---|
436 | DO ji = nldi, nlei |
---|
437 | zgcx_adin(ji,jj) = zgcx_tlout(ji,jj) & |
---|
438 | & * e1t(ji,jj) * e2t(ji,jj) & |
---|
439 | & * tmask(ji,jj,1) |
---|
440 | END DO |
---|
441 | END DO |
---|
442 | !-------------------------------------------------------------------- |
---|
443 | ! Compute the scalar product: ( L dx )^T W dy |
---|
444 | !-------------------------------------------------------------------- |
---|
445 | zsp1 = DOT_PRODUCT( zgcx_tlout, zgcx_adin ) |
---|
446 | !-------------------------------------------------------------------- |
---|
447 | ! Call the adjoint routine: dx^* = L^T dy^* |
---|
448 | !-------------------------------------------------------------------- |
---|
449 | gcb_ad(:,:) = 0.0_wp |
---|
450 | gcx_ad(:,:) = zgcx_adin(:,:) |
---|
451 | CALL sol_sor_adj(kt, kindic) |
---|
452 | zgcx_adout(:,:) = gcx_ad(:,:) |
---|
453 | zgcb_adout(:,:) = gcb_ad(:,:) |
---|
454 | |
---|
455 | zsp2 = DOT_PRODUCT( zgcx_tlin, zgcx_adout ) & |
---|
456 | & + DOT_PRODUCT( zgcb_tlin, zgcb_adout ) |
---|
457 | |
---|
458 | cl_name = 'sol_sor_adj ' |
---|
459 | CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 ) |
---|
460 | ! nn_nmod = kmod ! restore initial frequency of test for the SOR solver |
---|
461 | |
---|
462 | DEALLOCATE( & |
---|
463 | & zgcb_tlin, & |
---|
464 | & zgcx_tlin, & |
---|
465 | & zgcx_tlout, & |
---|
466 | & zgcx_adin, & |
---|
467 | & zgcx_adout, & |
---|
468 | & zgcb_adout, & |
---|
469 | & zr & |
---|
470 | & ) |
---|
471 | END SUBROUTINE sol_sor_adj_tst |
---|
472 | END MODULE solsor_tam |
---|
473 | |
---|