1 |
heimbach |
1.3 |
#include "PACKAGES_CONFIG.h" |
2 |
|
|
|
3 |
utke |
1.1 |
subroutine template() |
4 |
|
|
use OAD_cp |
5 |
|
|
use OAD_tape |
6 |
|
|
use OAD_rev |
7 |
|
|
use revolve |
8 |
|
|
|
9 |
|
|
c we may need these for the checkpointing |
10 |
|
|
use SIZE_mod |
11 |
|
|
use EEPARAMS_mod |
12 |
|
|
use PARAMS_mod |
13 |
|
|
use BAR2_mod |
14 |
|
|
use BARRIER_mod |
15 |
heimbach |
1.3 |
#ifdef ALLOW_CD_CODE |
16 |
utke |
1.1 |
use CD_CODE_VARS_mod |
17 |
heimbach |
1.3 |
#endif |
18 |
utke |
1.1 |
use CG2D_mod |
19 |
|
|
use CG3D_mod |
20 |
|
|
use DYNVARS_mod |
21 |
|
|
use EESUPPORT_mod |
22 |
|
|
use EOS_mod |
23 |
|
|
use EXCH_mod |
24 |
|
|
use FC_NAMEMANGLE_mod |
25 |
|
|
use FFIELDS_mod |
26 |
utke |
1.5 |
#ifdef ALLOW_GENERIC_ADVDIFF |
27 |
utke |
1.1 |
use GAD_mod |
28 |
utke |
1.5 |
#endif |
29 |
utke |
1.1 |
use GLOBAL_MAX_mod |
30 |
|
|
use GLOBAL_SUM_mod |
31 |
heimbach |
1.3 |
#ifdef ALLOW_GMREDI |
32 |
utke |
1.1 |
use GMREDI_mod |
33 |
|
|
use GMREDI_TAVE_mod |
34 |
heimbach |
1.3 |
#endif |
35 |
utke |
1.1 |
use GRID_mod |
36 |
utke |
1.5 |
#ifdef ALLOW_MOM_COMMON |
37 |
heimbach |
1.3 |
use MOM_VISC_mod |
38 |
utke |
1.5 |
#endif |
39 |
utke |
1.1 |
use MPI_INFO_mod |
40 |
heimbach |
1.3 |
#ifdef ALLOW_SHAP_FILT |
41 |
|
|
use SHAP_FILT_mod |
42 |
|
|
#endif |
43 |
heimbach |
1.4 |
#ifdef ALLOW_STREAMICE |
44 |
|
|
use STREAMICE_mod |
45 |
|
|
use STREAMICE_ADV_mod |
46 |
|
|
use STREAMICE_BDRY_mod |
47 |
|
|
use STREAMICE_CG_mod |
48 |
|
|
#endif |
49 |
utke |
1.1 |
use SOLVE_FOR_PRESSURE3D_mod |
50 |
|
|
use SOLVE_FOR_PRESSURE_mod |
51 |
|
|
use SURFACE_mod |
52 |
|
|
use tamc_mod |
53 |
|
|
use tamc_keys_mod |
54 |
|
|
use cost_mod |
55 |
|
|
use g_cost_mod |
56 |
|
|
use ctrl_mod |
57 |
|
|
use ctrl_dummy_mod |
58 |
|
|
use ctrl_weights_mod |
59 |
|
|
use optim_mod |
60 |
|
|
use grdchk_mod |
61 |
|
|
|
62 |
|
|
!$TEMPLATE_PRAGMA_DECLARATIONS |
63 |
|
|
LOGICAL :: initialized=.FALSE. |
64 |
|
|
TYPE(rvAction),save :: theAction |
65 |
utke |
1.2 |
CHARACTER(80) :: errorMsg |
66 |
utke |
1.1 |
integer, save :: jointCPCount |
67 |
|
|
integer, save :: currIter |
68 |
|
|
|
69 |
|
|
integer :: cp_loop_variable_1,cp_loop_variable_2, |
70 |
|
|
+ cp_loop_variable_3,cp_loop_variable_4,cp_loop_variable_5 |
71 |
|
|
|
72 |
|
|
type(modeType) :: our_orig_mode |
73 |
|
|
|
74 |
|
|
integer iaddr |
75 |
|
|
external iaddr |
76 |
|
|
|
77 |
|
|
#ifdef OAD_DEBUG_JOINT |
78 |
|
|
character*(80):: indentation=' |
79 |
|
|
+ ' |
80 |
|
|
our_indent=our_indent+1 |
81 |
|
|
|
82 |
|
|
write(standardmessageunit, '(A,A,A)', ADVANCE='NO') |
83 |
|
|
+'OAD:',indentation(1:our_indent), 'enter __SRNAME__:' |
84 |
|
|
call oad_dump_revmod(); call oad_dump_tapestats() |
85 |
|
|
write(standardmessageunit,*) |
86 |
|
|
#endif |
87 |
|
|
|
88 |
|
|
nIter0 = NINT( (startTime-baseTime)/deltaTClock ) |
89 |
|
|
if (our_rev_mode%arg_store) then |
90 |
|
|
call cp_write_open() |
91 |
|
|
#ifdef OAD_DEBUG_JOINT |
92 |
|
|
write(standardmessageunit,'(A,A,A)') |
93 |
|
|
+'OAD:',indentation(1:our_indent), |
94 |
|
|
+' __SRNAME__: entering arg store' |
95 |
|
|
#endif |
96 |
|
|
!$PLACEHOLDER_PRAGMA$ id=8 |
97 |
|
|
call cp_close() |
98 |
|
|
end if |
99 |
|
|
if (our_rev_mode%arg_restore) then |
100 |
|
|
#ifdef OAD_DEBUG_JOINT |
101 |
|
|
write(standardmessageunit,'(A,A,A)') |
102 |
|
|
+'OAD:',indentation(1:our_indent), |
103 |
|
|
+' __SRNAME__: entering arg restore' |
104 |
|
|
#endif |
105 |
|
|
call cp_read_open() |
106 |
|
|
!$PLACEHOLDER_PRAGMA$ id=9 |
107 |
|
|
call cp_close() |
108 |
|
|
end if |
109 |
|
|
if (our_rev_mode%plain) then |
110 |
|
|
#ifdef OAD_DEBUG_JOINT |
111 |
|
|
write(standardmessageunit,'(A,A,A)') |
112 |
|
|
+'OAD:',indentation(1:our_indent), |
113 |
|
|
+' __SRNAME__: run plain, down plain' |
114 |
|
|
#endif |
115 |
|
|
DO iloop = 1, nTimeSteps |
116 |
|
|
CALL OpenAD_forward_step( iloop, mytime, myiter, mythid ) |
117 |
|
|
enddo |
118 |
|
|
end if |
119 |
|
|
if (our_rev_mode%tape) then |
120 |
|
|
#ifdef OAD_DEBUG_JOINT |
121 |
|
|
write(standardmessageunit,'(A,A,A)') |
122 |
|
|
+'OAD:',indentation(1:our_indent), |
123 |
|
|
+' __SRNAME__: run tape, down revolve until first U turn' |
124 |
|
|
#endif |
125 |
|
|
currIter=0 |
126 |
|
|
jointCPcount=cp_fNumber() |
127 |
|
|
initialized=rvInit(nTimeSteps,120, |
128 |
|
|
+ errorMsg,theAction) |
129 |
|
|
IF (.NOT.initialized) WRITE(*,'(A,A)') 'Error: ', errorMsg |
130 |
|
|
do while (theAction%actionFlag/=rvDone) |
131 |
|
|
theAction=rvNextAction() |
132 |
|
|
select case (theAction%actionFlag) |
133 |
|
|
case (rvStore) |
134 |
|
|
call cp_write_open(theAction%cpNum+jointCPCount) |
135 |
|
|
!$PLACEHOLDER_PRAGMA$ id=8 |
136 |
|
|
call cp_close |
137 |
|
|
case (rvForward) |
138 |
|
|
call OAD_revPlain |
139 |
|
|
do currIter=currIter,theAction%iteration-1 |
140 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, |
141 |
|
|
+myiter, mythid ) |
142 |
|
|
end do |
143 |
|
|
call OAD_revTape |
144 |
|
|
case (rvFirstUTurn) |
145 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, myiter, |
146 |
|
|
+mythid ) |
147 |
|
|
! get out now ... |
148 |
|
|
exit |
149 |
|
|
end select |
150 |
|
|
end do |
151 |
|
|
end if |
152 |
|
|
if (our_rev_mode%adjoint) then |
153 |
|
|
IF (.NOT.initialized) WRITE(*,'(A)') 'Error: not initialized' |
154 |
|
|
do while (theAction%actionFlag/=rvDone) |
155 |
|
|
select case (theAction%actionFlag) |
156 |
|
|
case (rvFirstUTurn) |
157 |
|
|
!we taped already ... see above |
158 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, myiter, |
159 |
|
|
+mythid ) |
160 |
|
|
case (rvStore) |
161 |
|
|
call cp_write_open(theAction%cpNum+jointCPCount) |
162 |
|
|
!$PLACEHOLDER_PRAGMA$ id=8 |
163 |
|
|
call cp_close |
164 |
|
|
case (rvRestore) |
165 |
|
|
call cp_read_open(theAction%cpNum+jointCPCount) |
166 |
|
|
!$PLACEHOLDER_PRAGMA$ id=9 |
167 |
|
|
currIter=theAction%iteration |
168 |
|
|
call cp_close |
169 |
|
|
case (rvForward) |
170 |
|
|
call OAD_revPlain |
171 |
|
|
do currIter=currIter,theAction%iteration-1 |
172 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, myiter, |
173 |
|
|
+ mythid ) |
174 |
|
|
end do |
175 |
|
|
call OAD_revAdjoint |
176 |
|
|
case (rvUTurn) |
177 |
|
|
call OAD_revTape |
178 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, myiter, |
179 |
|
|
+mythid ) |
180 |
|
|
call OAD_revAdjoint |
181 |
|
|
CALL OpenAD_forward_step( currIter+1, mytime, myiter, |
182 |
|
|
+mythid ) |
183 |
|
|
end select |
184 |
|
|
theAction=rvNextAction() |
185 |
|
|
end do |
186 |
|
|
end if |
187 |
|
|
|
188 |
|
|
#ifdef OAD_DEBUG_JOINT |
189 |
|
|
write(standardmessageunit,'(A,A,A)', ADVANCE='NO') |
190 |
|
|
+'OAD:',indentation(1:our_indent), 'leave __SRNAME__:' |
191 |
|
|
call oad_dump_revmod(); call oad_dump_tapestats() |
192 |
|
|
write(standardmessageunit,*) |
193 |
|
|
|
194 |
|
|
our_indent=our_indent-1 |
195 |
|
|
#endif |
196 |
|
|
|
197 |
|
|
end subroutine template |