# Example: Subtropical North Atlantic and Labrador Sea Areas # ========================================================== # - forward/adjoint run # - optimization cost function # - with KPP & shortwave heating # - gmredi turned off (until merge to c48) # - The input data is real*8 # - 4 timesteps #################### # Experiment no. 1 # #################### # Use air-sea fluxes as controls (standard case): # perform gradient checks for first four elements of the # heat flux part of the control vector (grdchkvarindex = 3). # Compile code in bin/: cd bin cp ../verification/natl_box_adjoint/code/.genmakerc . cp ../verification/natl_box_adjoint/code/*.h . # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint make adtaf make adchange # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input/* . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # A reference output is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results/output.txt #################### # Experiment no. 2 # #################### # Use bulk formulae and atmospheric state controls # (only differences to experiment 1 are in # ECCO_CPPOPTIONS.h and in data.grdchk): # perform gradient checks for first four elements of the # air temperture part of the control vector (grdchkvarindex = 7). # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_bulk/.genmakerc . cp ../verification/natl_box_adjoint/code_bulk/*.h . # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint make adtaf make adchange # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_bulk/* . cp ../verification/natl_box_adjoint/input/PH_*.data . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # A reference output is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_bulk/output.txt #################### # Experiment no. 4 # #################### # Same as exp. 2, but with ALLOW_SEAICE defined and useseaice = .true. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . cp ../verification/natl_box_adjoint/code_seaice/SEAICE_OPTIONS.h.FLUXES SEAICE_OPTIONS.h # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_bulk/* . cp ../verification/natl_box_adjoint/input_seaice/data.seaice.cgrid data.seaice cp ../verification/natl_box_adjoint/input_seaice/data.pkg . cp ../verification/natl_box_adjoint/input/PH_*.data . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # A reference output is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_bulk/output.txt #################### # Experiment no. 5 # #################### # Same as exp. 4, but using sea-ice bulk formulae. # This experiment tests pkg/seaice bulk formulae over open water. # No sea-ice is formed anywhere in the domain. # There is a discrepancy of up to 8% between ajoint # model and finite difference gradients. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_bulk/* . cp ../verification/natl_box_adjoint/input_seaice/data.seaice.cgrid data.seaice cp ../verification/natl_box_adjoint/input_seaice/data.pkg . cp ../verification/natl_box_adjoint/input/PH_*.data . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # A reference output is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_bulk/output.exp5 #################### # Experiment no. 6 # #################### # Same as experiment 5, but in the Labrador Sea rather than in # the North Atlantic subduction region. The cost function is # total ice volume over the 4-hour test period. # # The cost function data files are not used. They contain: # labsea_TP_fields : filled with -9999 # labsea_TP_mean : hour 100 ssh (cm) of lab_sea experiment # labsea_ERS_fields : filled with -9999 # labsea_SST_fields : 14 * Levitus annual mean SST # labsea_Lev.ptmp : 14 * Levitus annual mean temperature # labsea_Lev.salt : 14 * Levitus annual mean salinity # labsea_ssh.err : filled with -9999 # labsea_geoid.err : constant 0.2 with -9999 landmask # labsea_totflux.err : 100 with -9999 landmask # labsea_pme.err : 4e-8 with -9999 landmask # labsea_ustress.err : 3 with -9999 landmask # labsea_vstress.err : 3 with -9999 landmask # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # A reference output is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_seaice/output.txt #################### # Experiment no. 7 # #################### # Same as experiment 6, but finite difference gradient check for # air temperature is computed and compared for the complete domain. # # Notes: # variables xx_* contain control vector perturbation # variables adxx_* contain cost function gradient relative to control # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt > ph-grd.txt cd ../verification/natl_box_adjoint/results_seaice matlab lookat_exp8 #################### # Experiment no. 8 # #################### # Same as experiment 7, but starting from a checkpoint file. # To run: cd ../../../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.001 data ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt > ph-grd.txt cd ../verification/natl_box_adjoint/results_seaice matlab lookat_exp8 #################### # Experiment no. 9 # #################### # Same as experiment 8, but starting from time step 180. # This includes a location (12,8) which experiences a phase # transition from no-ice to sea-ice, and which therefore has # a very large and inaccurate gradient. # To run: cd ../../../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.180 data ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt > ph-grd.txt cd ../verification/natl_box_adjoint/results_seaice matlab lookat_exp8 ##################### # Experiment no. 10 # ##################### # Set up a 100-day sensitivity experiment. # Things start falling apart, see below. # Longer integrations periods cause NANs in adjoint gradient. # Note: cost_ssh is hardwired for 1-day ssh records # "topexperiod" in data.cost is never used. # Compile code in bin/: cd ../../../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . rm -f tamc.h cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.100day data cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # For 100 days, adjoint gradient blows up for cost_ice_flag=1,2,3,4,5. # Following table compares adjoint gradient to finite difference gradient # for various choices of grdchk_eps and for cost_ice_flag=1. The finite # difference gradient is unstable, suggesting that tangent linear gradient # is ill defined. 100 day experiment looks equally bad with cost_ice_flag=2. adj grad -.441946498+276 -.143062040+277 -.116360092+277 0.400428239+277 1.d-12 -.177327175E+20 0.140230277E+20 -.254542273E+20 0.138603531E+19 1.d-8 0.174714613E+16 -.527867903E+15 0.403581037E+15 0.377322748E+12 1.d-4 0.999954825E+11 0.156018218E+12 -.474931072E+11 -.357260091E+11 1.d-2 0.634576350E+09 -.185440863E+10 -.599212833E+09 -.334417056E+10 # 100 day experiment with cost_ice_flag = 3, but in North Atlantic # domain, i.e., with no sea-ice is OK adj grad 0.234593317E+17 0.166950683E+17 0.238665515E+17 0.249850733E+17 1.d-4 0.234313954E+17 0.166674930E+17 0.238322031E+17 0.249217155E+17 # with same order of magnitude results as those from pkg/exf bulk formulae adj grad 0.279968788E+17 0.226979382E+17 0.269224396E+17 0.323359773E+17 1.d-4 0.279944626E+17 0.226935335E+17 0.269274317E+17 0.323399293E+17 # 10 day experiment with cost_ice_flag = 3 is OK adj grad 0.353941629E+17 0.955451129E+16 -.265793314E+17 0.232229067E+16 1.d-4 0.353943893E+17 0.955563114E+16 -.265195776E+17 0.232137949E+16 1-fd/adj -.639540199E-05 -.117207086E-03 0.224813073E-02 0.392362727E-03 # 100 day experiment with cost_ice_flag = 3 fails adj grad 0.134326162+285 0.434825818+285 0.353667347+285 -.121707013+286 1.d-4 -.248910431E+20 -.581887317E+20 0.530805948E+18 0.554441614E+20 # 100 day experiment with cost_ice_flag = 4 fails adj grad 0.942881479+279 0.305219181+280 0.248251262+280 -.854303341+280 1.d-4 0.550158678E+19 -.107685572E+20 -.139042495E+20 0.445855968E+20 # 100 day experiment with cost_ice_flag = 5 fails adj grad 0.149606733+285 0.484290396+285 0.393899563+285 -.135552065+286 1.d-4 -.300535490E+20 -.689378119E+20 0.300954675E+19 0.767231924E+20 # It seems that linearization in the presence of a sea-ice model is very # difficult. Consider that a small perturbation at time zero may cause # sea-ice to appear or not at a particular grid point. The model response # with sea-ice is completely different from that with no sea-ice, so that # this small initial perturbation will have a large impact in ocean heat # content, or even ocean plus sea-ice heat content. One way around this # may be a preliminary piece-wise optimization, say 10 days at a time, but # without changing initial conditions, just the surface fluxes. Another # way may be to specify heat fluxes based on observed sea-ice extent, in # order to force the model to have sea-ice where sea-ice is observed. A # third possiblity, similar to that provided by package MIX for KPP scheme # in the telescoping configuration would be to store AREA or HEFF during # forward model integrations and then to specify, rather than recompute, # AREA or HEFF or both during adjoint model calculations. The problem # with this approach is that it would not be possible to compute # sensitivity to a variable that held constant, rather tan computed? # Perhaps sensitivity of cost function to AREA and to HEFF can be computed # separately, by running the adjoint twice, once keeping HEFF constant and # the second keeping AREA constant? # Now need a test to show that this is indeed the problem. ##################### # Experiment no. 11 # ##################### # Same as experiment 8, but using 2-CPU MPI configuration. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . cp ../verification/natl_box_adjoint/code_seaice/SIZE.h.MPI SIZE.h cp ../verification/natl_box_adjoint/code_seaice/CPP_EEOPTIONS.h.MPI CPP_EEOPTIONS.h # Configure and compile the code: ../tools/genmake -mpi -makefile # ==> on alhena use: # ../tools/genmake -platform=o2k -mpi -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.001 data cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . mpirun -np 2 mitgcmuv # To verify the results of the gradient check, type: grep "ph-grd 3" STDOUT.0000 # To plot adjoint sensitivy fields cd ../verification/natl_box_adjoint/results_seaice matlab lookat_exp10 ##################### # Experiment no. 12 # ##################### # Same as experiment 6, but including LSR dynamic solver. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . cp ../verification/natl_box_adjoint/code_seaice/SEAICE_OPTIONS.h.DYN SEAICE_OPTIONS.h # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile.dyn makefile make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.seaice.lsr data.seaice cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # The reference output, without dynamics is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_seaice/output.txt ##################### # Experiment no. 13 # ##################### # Same as experiment 6, but with SEAICE_MULTILEVEL. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . cp ../verification/natl_box_adjoint/code_seaice/SEAICE_OPTIONS.h.MULTILEVEL SEAICE_OPTIONS.h # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # The reference output, with SEAICE_MULTILEVEL undefined is in: grep "ph-grd 3" ../verification/natl_box_adjoint/results_seaice/output.txt # This test suggests that SEAICE_MULTILEVEL decreases the accuracy of # the adjoint model, perhaps because the adjoint model is not handling # multiple recomputations in budget properly. ##################### # Experiment no. 14 # ##################### # Same as in 14 but for a 100-day sensitivity experiment. # Compile code in bin/: cd ../bin rm -rf *.o *.f *.p rii_files rm -rf *.F *.h *.c Makefile* cp ../verification/natl_box_adjoint/code_seaice/*.h . rm -f tamc.h cp ../verification/natl_box_adjoint/code_seaice/.genmakerc . cp ../verification/natl_box_adjoint/code_seaice/SEAICE_OPTIONS.h.MULTILEVEL SEAICE_OPTIONS.h # Configure and compile the code: ../tools/genmake -makefile make depend # Generate the adjoint code: cd ../adjoint cp ../verification/natl_box_adjoint/code_seaice/makefile . make adtaf make adchange rm -f makefile # Go back and compile the code: cd ../bin make # To run: cd ../exe cp ../verification/natl_box_adjoint/input_seaice/* . cp data.100day data cp ../verification/natl_box_adjoint/input_bulk/data.grdchk . ./mitgcmuv >&! output.txt # To verify the results of the gradient check, type: grep "ph-grd 3" output.txt # For 100-day experiment, the adjoint gradient blows up, as in Exp. 10 adj grad -.160660304+210 -.378763253+210 -.239235971+211 -.386444881+209 1.d-4 0.251994583E+11 -.899637862E+10 0.372048919E+10 -.344972301E+10 ##################### # Experiment no. 20 # ##################### # Same as experiment 10, but using divided adjoint.