17 |
C | On entry: | |
C | On entry: | |
18 |
C | dSigmaDrW,S contains the d/dz Sigma | |
C | dSigmaDrW,S contains the d/dz Sigma | |
19 |
C | SlopeX/Y contains X/Y gradients of sigma | |
C | SlopeX/Y contains X/Y gradients of sigma | |
20 |
C | depthZ contains the height (m) of level | |
C | depthZ contains the depth (< 0 !) [m] | |
21 |
C | On exit: | |
C | On exit: | |
22 |
C | dSigmaDrW,S contains the effective dSig/dz | |
C | dSigmaDrW,S contains the effective dSig/dz | |
23 |
C | SlopeX/Y contains X/Y slopes | |
C | SlopeX/Y contains X/Y slopes | |
47 |
_RL dSigmaDrS(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
_RL dSigmaDrS(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
48 |
_RL LrhoW(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
_RL LrhoW(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
49 |
_RL LrhoS(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
_RL LrhoS(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
50 |
_RL depthZ |
_RS depthZ |
51 |
INTEGER K,bi,bj,myThid |
INTEGER K,bi,bj,myThid |
52 |
CEndOfInterface |
CEndOfInterface |
53 |
|
|
55 |
#ifdef GM_BOLUS_ADVEC |
#ifdef GM_BOLUS_ADVEC |
56 |
|
|
57 |
C == Local variables == |
C == Local variables == |
|
_RL gradSmod(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
|
58 |
_RL dSigmaDrLtd(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
_RL dSigmaDrLtd(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
|
_RL SlopeSqr(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
|
59 |
_RL f1,Smod,f2,Rnondim |
_RL f1,Smod,f2,Rnondim |
60 |
_RL maxSlopeSqr |
_RL maxSlopeSqr |
61 |
_RL slopeCutoff |
_RL slopeCutoff |
62 |
_RL fpi |
_RL fpi |
63 |
PARAMETER(fpi=3.141592653589793047592d0) |
PARAMETER(fpi=3.141592653589793047592d0) |
64 |
INTEGER i,j |
INTEGER i,j |
65 |
|
#ifdef GMREDI_WITH_STABLE_ADJOINT |
66 |
|
_RL slopeTmpSpec,slopeMaxSpec |
67 |
|
#endif |
68 |
|
|
69 |
|
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
70 |
|
|
71 |
slopeCutoff = SQRT( GM_slopeSqCutoff ) |
slopeCutoff = SQRT( GM_slopeSqCutoff ) |
72 |
|
|
84 |
kkey = (igmkey-1)*Nr + k |
kkey = (igmkey-1)*Nr + k |
85 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
#endif /* ALLOW_AUTODIFF_TAMC */ |
86 |
|
|
87 |
|
#ifndef GMREDI_WITH_STABLE_ADJOINT |
88 |
|
c common case: |
89 |
|
|
90 |
IF (GM_taper_scheme.EQ.'orig' .OR. |
IF (GM_taper_scheme.EQ.'orig' .OR. |
91 |
& GM_taper_scheme.EQ.'clipping') THEN |
& GM_taper_scheme.EQ.'clipping') THEN |
92 |
|
|
132 |
DO j=1-Oly,sNy+Oly |
DO j=1-Oly,sNy+Oly |
133 |
DO i=1-Olx+1,sNx+Olx |
DO i=1-Olx+1,sNx+Olx |
134 |
SlopeX(i,j) = -SlopeX(i,j)/dSigmaDrW(i,j) |
SlopeX(i,j) = -SlopeX(i,j)/dSigmaDrW(i,j) |
135 |
taperX(i,j)=1. _d 0 |
taperX(i,j) = 1. _d 0 |
136 |
ENDDO |
ENDDO |
137 |
ENDDO |
ENDDO |
138 |
|
|
167 |
DO j=1-Oly+1,sNy+Oly |
DO j=1-Oly+1,sNy+Oly |
168 |
DO i=1-Olx,sNx+Olx |
DO i=1-Olx,sNx+Olx |
169 |
SlopeY(i,j) = -SlopeY(i,j)/dSigmaDrS(i,j) |
SlopeY(i,j) = -SlopeY(i,j)/dSigmaDrS(i,j) |
170 |
taperY(i,j)=1. _d 0 |
taperY(i,j) = 1. _d 0 |
171 |
ENDDO |
ENDDO |
172 |
ENDDO |
ENDDO |
173 |
|
|
174 |
#endif /* GM_EXCLUDE_CLIPPING */ |
#endif /* GM_EXCLUDE_CLIPPING */ |
175 |
|
|
176 |
|
ELSEIF (GM_taper_scheme.EQ.'fm07') THEN |
177 |
|
|
178 |
|
STOP 'GMREDI_SLOPE_PSI: AdvForm not yet implemented for fm07' |
179 |
|
|
180 |
ELSE |
ELSE |
181 |
|
|
182 |
#ifdef GM_EXCLUDE_TAPERING |
#ifdef GM_EXCLUDE_TAPERING |
190 |
CADJ STORE dSigmaDrW(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
CADJ STORE dSigmaDrW(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
191 |
#endif |
#endif |
192 |
|
|
193 |
C- Compute the slope, no clipping, but avoid reverse slope in negatively |
C- Compute the slope, no clipping, but avoid reverse slope in negatively |
194 |
C stratified (Sigma_Z > 0) region : |
C stratified (Sigma_Z > 0) region : |
195 |
DO j=1-Oly,sNy+Oly |
DO j=1-Oly,sNy+Oly |
196 |
DO i=1-Olx+1,sNx+Olx |
DO i=1-Olx+1,sNx+Olx |
204 |
DO j=1-Oly,sNy+Oly |
DO j=1-Oly,sNy+Oly |
205 |
DO i=1-Olx+1,sNx+Olx |
DO i=1-Olx+1,sNx+Olx |
206 |
SlopeX(i,j) = -SlopeX(i,j)/dSigmaDrW(i,j) |
SlopeX(i,j) = -SlopeX(i,j)/dSigmaDrW(i,j) |
207 |
taperX(i,j)= 1. _d 0 |
taperX(i,j) = 1. _d 0 |
208 |
ENDDO |
ENDDO |
209 |
ENDDO |
ENDDO |
210 |
#ifdef ALLOW_AUTODIFF_TAMC |
#ifdef ALLOW_AUTODIFF_TAMC |
236 |
DO j=1-Oly+1,sNy+Oly |
DO j=1-Oly+1,sNy+Oly |
237 |
DO i=1-Olx,sNx+Olx |
DO i=1-Olx,sNx+Olx |
238 |
SlopeY(i,j) = -SlopeY(i,j)/dSigmaDrS(i,j) |
SlopeY(i,j) = -SlopeY(i,j)/dSigmaDrS(i,j) |
239 |
taperY(i,j)=1. _d 0 |
taperY(i,j) = 1. _d 0 |
240 |
ENDDO |
ENDDO |
241 |
ENDDO |
ENDDO |
242 |
#ifdef ALLOW_AUTODIFF_TAMC |
#ifdef ALLOW_AUTODIFF_TAMC |
273 |
DO i=1-Olx,sNx+Olx |
DO i=1-Olx,sNx+Olx |
274 |
Smod = ABS(SlopeY(i,j)) |
Smod = ABS(SlopeY(i,j)) |
275 |
IF ( Smod .GT. GM_maxSlope .AND. |
IF ( Smod .GT. GM_maxSlope .AND. |
276 |
& Smod .LT. slopeCutoff ) |
& Smod .LT. slopeCutoff ) |
277 |
& taperY(i,j)=GM_maxSlope/(Smod+GM_Small_Number) |
& taperY(i,j)=GM_maxSlope/(Smod+GM_Small_Number) |
278 |
ENDDO |
ENDDO |
279 |
ENDDO |
ENDDO |
285 |
DO j=1-Oly,sNy+Oly |
DO j=1-Oly,sNy+Oly |
286 |
DO i=1-Olx+1,sNx+Olx |
DO i=1-Olx+1,sNx+Olx |
287 |
IF ( ABS(SlopeX(i,j)) .GT. GM_maxSlope .AND. |
IF ( ABS(SlopeX(i,j)) .GT. GM_maxSlope .AND. |
288 |
& ABS(SlopeX(i,j)) .LT. slopeCutoff ) |
& ABS(SlopeX(i,j)) .LT. slopeCutoff ) |
289 |
& taperX(i,j)=maxSlopeSqr/ |
& taperX(i,j)=maxSlopeSqr/ |
290 |
& ( SlopeX(i,j)*SlopeX(i,j) + GM_Small_Number ) |
& ( SlopeX(i,j)*SlopeX(i,j) + GM_Small_Number ) |
291 |
ENDDO |
ENDDO |
323 |
DO i=1-Olx+1,sNx+Olx |
DO i=1-Olx+1,sNx+Olx |
324 |
Smod = ABS(SlopeX(i,j)) |
Smod = ABS(SlopeX(i,j)) |
325 |
IF ( Smod .LT. slopeCutoff ) THEN |
IF ( Smod .LT. slopeCutoff ) THEN |
326 |
f1=op5*( 1. _d 0 + TANH( (GM_Scrit-Smod)/GM_Sd )) |
f1=op5*( 1. _d 0 + TANH( (GM_Scrit-Smod)/GM_Sd )) |
327 |
IF (Smod.NE.0.) THEN |
IF (Smod.NE.0.) THEN |
328 |
Rnondim=depthZ/(LrhoW(i,j)*Smod) |
Rnondim = -depthZ/(LrhoW(i,j)*Smod) |
329 |
ELSE |
ELSE |
330 |
Rnondim=0. |
Rnondim = 1. |
331 |
ENDIF |
ENDIF |
332 |
f2=op5*( 1. _d 0 + SIN( fpi*(Rnondim-op5))) |
IF ( Rnondim.GE.1. _d 0 ) THEN |
333 |
taperX(i,j)=f1*f2 |
f2 = 1. _d 0 |
334 |
|
ELSE |
335 |
|
f2 = op5*( 1. _d 0 + SIN( fpi*(Rnondim-op5) )) |
336 |
|
ENDIF |
337 |
|
taperX(i,j)=f1*f2 |
338 |
ENDIF |
ENDIF |
339 |
ENDDO |
ENDDO |
340 |
ENDDO |
ENDDO |
343 |
DO i=1-Olx,sNx+Olx |
DO i=1-Olx,sNx+Olx |
344 |
Smod = ABS(SlopeY(i,j)) |
Smod = ABS(SlopeY(i,j)) |
345 |
IF ( Smod .LT. slopeCutoff ) THEN |
IF ( Smod .LT. slopeCutoff ) THEN |
346 |
f1=op5*( 1. _d 0 + TANH( (GM_Scrit-Smod)/GM_Sd )) |
f1=op5*( 1. _d 0 + TANH( (GM_Scrit-Smod)/GM_Sd )) |
347 |
IF (Smod.NE.0.) THEN |
IF (Smod.NE.0.) THEN |
348 |
Rnondim=depthZ/(LrhoS(i,j)*Smod) |
Rnondim = -depthZ/(LrhoS(i,j)*Smod) |
349 |
ELSE |
ELSE |
350 |
Rnondim=0. |
Rnondim = 1. |
351 |
ENDIF |
ENDIF |
352 |
f2=op5*( 1. _d 0 + SIN( fpi*(Rnondim-op5))) |
IF ( Rnondim.GE.1. _d 0 ) THEN |
353 |
taperY(i,j)=f1*f2 |
f2 = 1. _d 0 |
354 |
|
ELSE |
355 |
|
f2 = op5*( 1. _d 0 + SIN( fpi*(Rnondim-op5) )) |
356 |
|
ENDIF |
357 |
|
taperY(i,j)=f1*f2 |
358 |
ENDIF |
ENDIF |
359 |
ENDDO |
ENDDO |
360 |
ENDDO |
ENDDO |
367 |
|
|
368 |
ENDIF |
ENDIF |
369 |
|
|
370 |
|
|
371 |
|
#else /* GMREDI_WITH_STABLE_ADJOINT */ |
372 |
|
c special choice for adjoint/optimization of parameters |
373 |
|
c (~ strong clipping, reducing non linearity of psi=f(K)) |
374 |
|
|
375 |
|
|
376 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
377 |
|
CADJ STORE slopeX(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
378 |
|
CADJ STORE dSigmaDrW(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
379 |
|
#endif |
380 |
|
DO j=1-Oly,sNy+Oly |
381 |
|
DO i=1-Olx+1,sNx+Olx |
382 |
|
IF (dSigmaDrW(i,j).GE.-GM_Small_Number) |
383 |
|
& dSigmaDrW(i,j) = -GM_Small_Number |
384 |
|
ENDDO |
385 |
|
ENDDO |
386 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
387 |
|
CADJ STORE dsigmadrW(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
388 |
|
#endif |
389 |
|
DO j=1-Oly,sNy+Oly |
390 |
|
DO i=1-Olx+1,sNx+Olx |
391 |
|
SlopeX(i,j) = -SlopeX(i,j)/dSigmaDrW(i,j) |
392 |
|
taperX(i,j) = 1. _d 0 |
393 |
|
ENDDO |
394 |
|
ENDDO |
395 |
|
|
396 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
397 |
|
CADJ STORE slopeY(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
398 |
|
CADJ STORE dSigmaDrS(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
399 |
|
#endif |
400 |
|
|
401 |
|
DO j=1-Oly+1,sNy+Oly |
402 |
|
DO i=1-Olx,sNx+Olx |
403 |
|
IF (dSigmaDrS(i,j).GE.-GM_Small_Number) |
404 |
|
& dSigmaDrS(i,j) = -GM_Small_Number |
405 |
|
ENDDO |
406 |
|
ENDDO |
407 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
408 |
|
CADJ STORE dsigmadrS(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
409 |
|
#endif |
410 |
|
DO j=1-Oly+1,sNy+Oly |
411 |
|
DO i=1-Olx,sNx+Olx |
412 |
|
SlopeY(i,j) = -SlopeY(i,j)/dSigmaDrS(i,j) |
413 |
|
taperY(i,j) = 1. _d 0 |
414 |
|
ENDDO |
415 |
|
ENDDO |
416 |
|
|
417 |
|
slopeMaxSpec=1. _d -4 |
418 |
|
|
419 |
|
CADJ STORE slopeX(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
420 |
|
CADJ STORE slopeY(:,:) = comlev1_bibj_k, key=kkey, byte=isbyte |
421 |
|
|
422 |
|
DO j=1-Oly,sNy+Oly |
423 |
|
DO i=1-Olx+1,sNx+Olx |
424 |
|
slopeTmpSpec=ABS(SlopeX(i,j)) |
425 |
|
IF ( slopeTmpSpec .GT. slopeMaxSpec ) then |
426 |
|
SlopeX(i,j)=5.*SlopeX(i,j)*slopeMaxSpec/slopeTmpSpec |
427 |
|
ELSE |
428 |
|
SlopeX(i,j)=5.*SlopeX(i,j) |
429 |
|
ENDIF |
430 |
|
taperX(i,j)=1. |
431 |
|
ENDDO |
432 |
|
ENDDO |
433 |
|
DO j=1-Oly+1,sNy+Oly |
434 |
|
DO i=1-Olx,sNx+Olx |
435 |
|
slopeTmpSpec=ABS(SlopeY(i,j)) |
436 |
|
IF ( slopeTmpSpec .GT. slopeMaxSpec ) then |
437 |
|
SlopeY(i,j)=5.*SlopeY(i,j)*slopeMaxSpec/slopeTmpSpec |
438 |
|
ELSE |
439 |
|
SlopeY(i,j)=5.*SlopeY(i,j) |
440 |
|
ENDIF |
441 |
|
taperY(i,j)=1. |
442 |
|
ENDDO |
443 |
|
ENDDO |
444 |
|
|
445 |
|
#endif /* GMREDI_WITH_STABLE_ADJOINT */ |
446 |
|
|
447 |
#endif /* BOLUS_ADVEC */ |
#endif /* BOLUS_ADVEC */ |
448 |
#endif /* ALLOW_GMREDI */ |
#endif /* ALLOW_GMREDI */ |
449 |
|
|