-
Notifications
You must be signed in to change notification settings - Fork 3
/
rcfl_y_ad_init.f90
116 lines (90 loc) · 4.05 KB
/
rcfl_y_ad_init.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
subroutine rcfl_y_ad_init( im, jm, km, jmax, al, bt, fld, jnx, jmx)
!---------------------------------------------------------------------------
! !
! Copyright 2018 Anna Teruzzi, OGS, Trieste !
! !
! This file is part of 3DVarBio.
! 3DVarBio is based on OceanVar (Dobricic, 2006) !
! !
! 3DVarBio is free software: you can redistribute it and/or modify. !
! it under the terms of the GNU General Public License as published by !
! the Free Software Foundation, either version 3 of the License, or !
! (at your option) any later version. !
! !
! 3DVarBio is distributed in the hope that it will be useful, !
! but WITHOUT ANY WARRANTY; without even the implied warranty of !
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the !
! GNU General Public License for more details. !
! !
! You should have received a copy of the GNU General Public License !
! along with OceanVar. If not, see <http://www.gnu.org/licenses/>. !
! !
!---------------------------------------------------------------------------
!-----------------------------------------------------------------------
! !
! Recursive filter in y direction - adjoint
! !
! Version 1: A. Teruzzi 2018 !
!-----------------------------------------------------------------------
use set_knd
use cns_str
implicit none
INTEGER(i4) :: im, jm, km, jmax
REAL(r8) :: fld(im,jm,km)
REAL(r8) :: al(im,jmax,km), bt(im,jmax,km)
INTEGER(i4) :: jnx(im,jm,km), jmx(km)
REAL(r8), allocatable :: a(:,:), b(:,:), c(:,:)
REAL(r8), allocatable :: alp(:,:), bta(:,:)
INTEGER(i4) :: i,j,k, ktr
ALLOCATE ( a(im,jmax), b(im,jmax), c(im,jmax) )
ALLOCATE ( alp(im,jmax), bta(im,jmax) )
alp = huge(alp(1,1)); bta = huge(bta(1,1))
do k=1,km
a(:,:) = 0.0
b(:,:) = 0.0
c(:,:) = 0.0
do j=1,jm
do i=1,im
c(i,jnx(i,j,k)) = fld(i,j,k)
enddo
enddo
alp(:,:) = al(:,:,k)
bta(:,:) = bt(:,:,k)
do ktr = 1,rcf%ntr
! negative direction
b(:,:) = 0.0
do j=1,jmx(k)-1
c(:,j+1) = c(:,j+1) + bta(:,j)*c(:,j)
b(:,j) = (1.-bta(:,j))*c(:,j)
enddo
if( ktr.eq.1 )then
b(:,jmx(k)) = b(:,jmx(k)) + c(:,jmx(k)) / (1.+bta(:,jmx(k)))
else
b(:,jmx(k) ) = b(:,jmx(k) ) + (1.-bta(:,jmx(k))) * c(:,jmx(k)) / (1.-bta(:,jmx(k))**2)**2
b(:,jmx(k)-1) = b(:,jmx(k)-1) - (1.-bta(:,jmx(k))) * bta(:,jmx(k))**3 * c(:,jmx(k)) / (1.-bta(:,jmx(k))**2)**2
endif
! positive direction
a(:,:) = 0.0
do j=jmx(k),2,-1
b(:,j-1) = b(:,j-1) + alp(:,j)*b(:,j)
a(:,j) = a(:,j) + (1.-alp(:,j))*b(:,j)
enddo
if( ktr.eq.1 )then
a(:,1) = a(:,1) + (1.-alp(:,1)) * b(:,1)
elseif( ktr.eq.2 )then
a(:,1) = a(:,1) + b(:,1) / (1.+alp(:,1))
else
a(:,1) = a(:,1) + (1.-alp(:,1)) * b(:,1) / (1.-alp(:,1)**2)**2
a(:,2) = a(:,2) - (1.-alp(:,1)) * alp(:,1)**3 * b(:,1) / (1.-alp(:,1)**2)**2
endif
c(:,:) = a(:,:)
enddo
do j=1,jm
do i=1,im
fld(i,j,k) = c(i,jnx(i,j,k))
enddo
enddo
enddo
DEALLOCATE ( a, b, c )
DEALLOCATE ( alp, bta )
end subroutine rcfl_y_ad_init