2 |
|
|
3 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
4 |
|
|
5 |
|
CBOI |
6 |
|
C |
7 |
|
C !TITLE: GRADIENT CHECK |
8 |
|
C !AUTHORS: mitgcm developers ( support@mitgcm.org ) |
9 |
|
C !AFFILIATION: Massachussetts Institute of Technology |
10 |
|
C !DATE: |
11 |
|
C !INTRODUCTION: gradient check package |
12 |
|
c \bv |
13 |
|
c Compare the gradients calculated by the adjoint model with |
14 |
|
c finite difference approximations. |
15 |
|
c |
16 |
|
C !CALLING SEQUENCE: |
17 |
|
c |
18 |
|
c the_model_main |
19 |
|
c | |
20 |
|
c |-- ctrl_unpack |
21 |
|
c |-- adthe_main_loop - unperturbed cost function and |
22 |
|
c |-- ctrl_pack adjoint gradient are computed here |
23 |
|
c | |
24 |
|
c |-- grdchk_main |
25 |
|
c | |
26 |
|
c |-- grdchk_init |
27 |
|
c |-- do icomp=... - loop over control vector elements |
28 |
|
c | |
29 |
|
c |-- grdchk_loc - determine location of icomp on grid |
30 |
|
c | |
31 |
|
c |-- grdchk_getxx - get control vector component from file |
32 |
|
c | perturb it and write back to file |
33 |
|
c |-- grdchk_getadxx - get gradient component calculated |
34 |
|
c | via adjoint |
35 |
|
c |-- the_main_loop - forward run and cost evaluation |
36 |
|
c | with perturbed control vector element |
37 |
|
c |-- calculate ratio of adj. vs. finite difference gradient |
38 |
|
c | |
39 |
|
c |-- grdchk_setxx - Reset control vector element |
40 |
|
c | |
41 |
|
c |-- grdchk_print - print results |
42 |
|
c \ev |
43 |
|
CEOI |
44 |
|
|
45 |
|
CBOP |
46 |
|
C !ROUTINE: grdchk_main |
47 |
|
C !INTERFACE: |
48 |
|
subroutine grdchk_main( mythid ) |
49 |
|
|
50 |
subroutine grdchk_main( |
C !DESCRIPTION: \bv |
|
I mythid |
|
|
& ) |
|
|
|
|
51 |
c ================================================================== |
c ================================================================== |
52 |
c SUBROUTINE grdchk_main |
c SUBROUTINE grdchk_main |
53 |
c ================================================================== |
c ================================================================== |
|
c |
|
54 |
c o Compare the gradients calculated by the adjoint model with |
c o Compare the gradients calculated by the adjoint model with |
55 |
c finite difference approximations. |
c finite difference approximations. |
|
c |
|
56 |
c started: Christian Eckert eckert@mit.edu 24-Feb-2000 |
c started: Christian Eckert eckert@mit.edu 24-Feb-2000 |
57 |
c continued: heimbach@mit.edu: 13-Jun-2001 |
c continued: heimbach@mit.edu: 13-Jun-2001 |
|
c |
|
58 |
c ================================================================== |
c ================================================================== |
59 |
c SUBROUTINE grdchk_main |
c SUBROUTINE grdchk_main |
60 |
c ================================================================== |
c ================================================================== |
61 |
|
C \ev |
62 |
|
|
63 |
|
C !USES: |
64 |
implicit none |
implicit none |
65 |
|
|
66 |
c == global variables == |
c == global variables == |
|
|
|
67 |
#include "SIZE.h" |
#include "SIZE.h" |
68 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
69 |
#include "PARAMS.h" |
#include "PARAMS.h" |
|
|
|
70 |
#include "grdchk.h" |
#include "grdchk.h" |
71 |
#include "cost.h" |
#include "cost.h" |
72 |
|
|
73 |
|
C !INPUT/OUTPUT PARAMETERS: |
74 |
c == routine arguments == |
c == routine arguments == |
|
|
|
75 |
integer mythid |
integer mythid |
76 |
|
|
77 |
#ifdef ALLOW_GRADIENT_CHECK |
#ifdef ALLOW_GRADIENT_CHECK |
78 |
|
C !LOCAL VARIABLES: |
79 |
c == local variables == |
c == local variables == |
80 |
integer myiter |
integer myiter |
81 |
_RL mytime |
_RL mytime |
112 |
cph) |
cph) |
113 |
|
|
114 |
c == end of interface == |
c == end of interface == |
115 |
|
CEOP |
116 |
|
|
117 |
c-- Set the loop ranges. |
c-- Set the loop ranges. |
118 |
jtlo = mybylo(mythid) |
jtlo = mybylo(mythid) |