ROMS
Loading...
Searching...
No Matches
propagator_afte.h
Go to the documentation of this file.
2!
3!git $Id$
4!================================================== Hernan G. Arango ===
5! Copyright (c) 2002-2025 The ROMS Group Andrew M. Moore !
6! Licensed under a MIT/X style license !
7! See License_ROMS.md !
8!=======================================================================
9! !
10! Adjoint Finite Time Eigenvalues Propagator: !
11! !
12! This routine is used during the computation of the eigenvectors of !
13! the adjoint propagator, transpose[R(t,0)]. They are computed in an !
14! analogous way to those of R(t,0). A single integration of an !
15! arbitrary perturbation state vector "u" backward in time over the !
16! interval [t,0] by the adjoint model: transpose[R(t,0)]*u. !
17! !
18! Reference: !
19! !
20! Moore, A.M. et al., 2004: A comprehensive ocean prediction and !
21! analysis system based on the tangent linear and adjoint of a !
22! regional ocean model, Ocean Modelling, 7, 227-258. !
23! !
24!=======================================================================
25!
26 USE mod_kinds
27!
28 implicit none
29!
30 PRIVATE
31 PUBLIC :: propagator_afte
32!
33 CONTAINS
34!
35!***********************************************************************
36 SUBROUTINE propagator_afte (RunInterval, state, ad_state)
37!***********************************************************************
38!
39 USE mod_param
40 USE mod_parallel
41#ifdef SOLVE3D
42 USE mod_coupling
43#endif
44 USE mod_iounits
45 USE mod_ocean
46 USE mod_scalars
47 USE mod_stepping
48!
49 USE close_io_mod, ONLY : close_inp
51 USE packing_mod, ONLY : ad_unpack, ad_pack
52#ifdef SOLVE3D
53 USE set_depth_mod, ONLY : set_depth
54#endif
55 USE strings_mod, ONLY : founderror
56!
57! Imported variable declarations.
58!
59 real(dp), intent(in) :: runinterval
60!
61 TYPE (t_gst), intent(in) :: state(ngrids)
62 TYPE (t_gst), intent(inout) :: ad_state(ngrids)
63!
64! Local variable declarations.
65!
66#ifdef SOLVE3D
67 logical :: firstpass = .true.
68#endif
69!
70 integer :: ng, tile
71!
72 real(r8) :: statenorm(ngrids)
73!
74 character (len=*), parameter :: myfile = &
75 & __FILE__
76!
77!=======================================================================
78! Forward integration of the tangent linear model.
79!=======================================================================
80!
81 nrun=nrun+1
82 IF (master) THEN
83 DO ng=1,ngrids
84 WRITE (stdout,10) ' PROPAGATOR - Grid: ', ng, &
85 & ', Iteration: ', nrun, &
86 & ', number converged RITZ values: ', &
87 & nconv(ng)
88 END DO
89 END IF
90!
91! Initialize time stepping indices and counters.
92!
93 DO ng=1,ngrids
94 iif(ng)=1
95 indx1(ng)=1
96 kstp(ng)=1
97 krhs(ng)=3
98 knew(ng)=2
99 predictor_2d_step(ng)=.false.
100!
101 iic(ng)=0
102 nstp(ng)=1
103 nrhs(ng)=1
104 nnew(ng)=2
105!
106 synchro_flag(ng)=.true.
107 tdays(ng)=dstart+dt(ng)*real(ntimes(ng),r8)*sec2day
108 time(ng)=tdays(ng)*day2sec
109 ntstart(ng)=ntimes(ng)+1
110 ntend(ng)=1
111 ntfirst(ng)=ntend(ng)
112 END DO
113!
114!-----------------------------------------------------------------------
115! Clear adjoint state variables. There is not need to clean the basic
116! state arrays since they were zeroth out at initialization and bottom
117! of previous iteration.
118!-----------------------------------------------------------------------
119!
120 DO ng=1,ngrids
121 DO tile=first_tile(ng),last_tile(ng),+1
122 CALL initialize_ocean (ng, tile, iadm)
123 END DO
124 END DO
125
126#ifdef SOLVE3D
127!
128!-----------------------------------------------------------------------
129! Compute basic state initial level thicknesses used for state norm
130! scaling. It uses zero time averaged free-surface (rest state).
131! Therefore, the norm scaling is time invariant.
132!-----------------------------------------------------------------------
133!
134 DO ng=1,ngrids
135 DO tile=last_tile(ng),first_tile(ng),-1
136 CALL set_depth (ng, tile, iadm)
137 END DO
138 END DO
139#endif
140!
141!-----------------------------------------------------------------------
142! Unpack adjoint initial conditions from state vector.
143!-----------------------------------------------------------------------
144!
145 DO ng=1,ngrids
146 DO tile=first_tile(ng),last_tile(ng),+1
147 CALL ad_unpack (ng, tile, nstr(ng), nend(ng), &
148 & state(ng)%vector)
149 END DO
150 END DO
151!
152!-----------------------------------------------------------------------
153! Compute initial adjoint state dot product norm.
154!-----------------------------------------------------------------------
155!
156 DO ng=1,ngrids
157 DO tile=last_tile(ng),first_tile(ng),-1
158 CALL ad_statenorm (ng, tile, knew(ng), nstp(ng), &
159 & statenorm(ng))
160 END DO
161 IF (master) THEN
162 WRITE (stdout,20) ' PROPAGATOR - Grid: ', ng, &
163 & ', Adjoint Initial Norm: ', statenorm(ng)
164 END IF
165 END DO
166!
167!-----------------------------------------------------------------------
168! Read in initial forcing, climatology and assimilation data from
169! input NetCDF files. It loads the first relevant data record for
170! the time-interpolation between snapshots.
171!-----------------------------------------------------------------------
172!
173 DO ng=1,ngrids
174 CALL close_inp (ng, iadm)
175 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
176
177 CALL ad_get_idata (ng)
178 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
179
180 CALL ad_get_data (ng)
181 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
182 END DO
183!
184!-----------------------------------------------------------------------
185! Time-step the adjoint model backwards.
186!-----------------------------------------------------------------------
187!
188 DO ng=1,ngrids
189 IF (master) THEN
190 WRITE (stdout,30) 'AD', ng, ntstart(ng), ntend(ng)
191 END IF
192 time(ng)=time(ng)+dt(ng)
193 iic(ng)=ntstart(ng)+1
194 END DO
195
196#ifdef SOLVE3D
197 CALL ad_main3d (runinterval)
198#else
199 CALL ad_main2d (runinterval)
200#endif
201 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
202!
203!-----------------------------------------------------------------------
204! Clear nonlinear state (basic state) variables and insure that the
205! time averaged free-surface is zero for scaling below and next
206! iteration.
207!-----------------------------------------------------------------------
208!
209 DO ng=1,ngrids
210 DO tile=first_tile(ng),last_tile(ng),+1
211 CALL initialize_ocean (ng, tile, inlm)
212#ifdef SOLVE3D
213 CALL initialize_coupling (ng, tile, 0)
214#endif
215 END DO
216 END DO
217
218#ifdef SOLVE3D
219!
220!-----------------------------------------------------------------------
221! Compute basic state final level thicknesses used for state norm
222! scaling. It uses zero time averaged free-surface (rest state).
223! Therefore, the norm scaling is time invariant.
224!-----------------------------------------------------------------------
225!
226 DO ng=1,ngrids
227 DO tile=last_tile(ng),first_tile(ng),-1
228 CALL set_depth (ng, tile, iadm)
229 END DO
230 END DO
231#endif
232!
233!-----------------------------------------------------------------------
234! Compute final adjoint state dot product norm.
235!-----------------------------------------------------------------------
236!
237 DO ng=1,ngrids
238 DO tile=first_tile(ng),last_tile(ng),+1
239 CALL ad_statenorm (ng, tile, knew(ng), nstp(ng), &
240 & statenorm(ng))
241 END DO
242 IF (master) THEN
243 WRITE (stdout,20) ' PROPAGATOR - Grid: ', ng, &
244 & ', Adjoint Final Norm: ', statenorm(ng)
245 END IF
246 END DO
247!
248!-----------------------------------------------------------------------
249! Pack final adjoint solution into adjoint state vector.
250!-----------------------------------------------------------------------
251!
252 DO ng=1,ngrids
253 DO tile=last_tile(ng),first_tile(ng),-1
254 CALL ad_pack (ng, tile, nstr(ng), nend(ng), &
255 & ad_state(ng)%vector)
256 END DO
257 END DO
258!
259 10 FORMAT (/,a,i2.2,a,i3.3,a,i3.3/)
260 20 FORMAT (/,a,i2.2,a,1p,e15.6,/)
261 30 FORMAT (/,1x,a,1x,'ROMS: started time-stepping:', &
262 & ' (Grid: ',i2.2,' TimeSteps: ',i8.8,' - ',i8.8,')')
263!
264 RETURN
265 END SUBROUTINE propagator_afte
266
267 END MODULE propagator_mod
subroutine ad_get_data(ng)
Definition ad_get_data.F:4
subroutine ad_get_idata(ng)
Definition ad_get_idata.F:4
subroutine ad_main2d
Definition ad_main2d.F:586
subroutine ad_main3d(runinterval)
Definition ad_main3d.F:4
subroutine, public close_inp(ng, model)
Definition close_io.F:92
subroutine, public ad_statenorm(ng, tile, kinp, ninp, statenorm)
Definition dotproduct.F:383
subroutine, public initialize_coupling(ng, tile, model)
integer stdout
integer, parameter r8
Definition mod_kinds.F:28
integer, parameter dp
Definition mod_kinds.F:25
subroutine, public initialize_ocean(ng, tile, model)
Definition mod_ocean.F:1526
integer, dimension(:), allocatable first_tile
logical master
integer, dimension(:), allocatable last_tile
integer, parameter inlm
Definition mod_param.F:662
integer, dimension(:), allocatable nstr
Definition mod_param.F:646
integer, parameter iadm
Definition mod_param.F:665
integer ngrids
Definition mod_param.F:113
integer, dimension(:), allocatable nend
Definition mod_param.F:647
real(dp), parameter day2sec
integer, dimension(:), allocatable ntimes
integer, dimension(:), allocatable iic
real(dp), dimension(:), allocatable dt
integer, dimension(:), allocatable nconv
logical, dimension(:), allocatable synchro_flag
logical, dimension(:), allocatable predictor_2d_step
real(dp), dimension(:), allocatable tdays
real(dp) dstart
real(dp), parameter sec2day
integer, dimension(:), allocatable ntend
integer exit_flag
integer, dimension(:), allocatable indx1
integer, dimension(:), allocatable ntfirst
real(dp), dimension(:), allocatable time
integer, dimension(:), allocatable ntstart
integer nrun
integer, dimension(:), allocatable iif
integer noerror
integer, dimension(:), allocatable kstp
integer, dimension(:), allocatable knew
integer, dimension(:), allocatable nrhs
integer, dimension(:), allocatable nnew
integer, dimension(:), allocatable krhs
integer, dimension(:), allocatable nstp
subroutine, public propagator_afte(runinterval, state, ad_state)
subroutine, public set_depth(ng, tile, model)
Definition set_depth.F:34
logical function, public founderror(flag, noerr, line, routine)
Definition strings.F:52
subroutine ad_unpack(ng, tile, mstr, mend, state)
Definition packing.F:4712
subroutine ad_pack(ng, tile, mstr, mend, ad_state)
Definition packing.F:341