diff --git a/code/adjoint/input_adj_mod.f b/code/adjoint/input_adj_mod.f index 404e11e..5384684 100644 --- a/code/adjoint/input_adj_mod.f +++ b/code/adjoint/input_adj_mod.f @@ -18,23 +18,23 @@ ! ! Module Routines: ! ============================================================================ -! (1 ) READ_INPUT_ADJ_FILE : Driver routine for reading GEOS-CHEM input file -! (2 ) READ_ONE_LINE : Reads one line at a time -! (3 ) SPLIT_ONE_LINE : Splits one line into substrings (by spaces) -! (4 ) READ_ADJ_SIMULATION_MENU : Reads the GEOS-Chem adjoint simulation menu -! (5 ) READ_FWD_MODEL_MENU : Reads forward model options -! (6 ) READ_ADJ_OPTIONS_MENU : Reads adjoint model options -! (7 ) READ_ADJ_DIRECTORIES_MENU : Reads the GEOS-Chem adj. directories -! (8 ) READ_CONTROL_VARS_MENU: Reads what are control variables -! (9 ) READ_OBSERVATION_MENU : Reads vars related to observations -! (10) READ_FD_ MENU : Reads finite difference test variables -! (11) READ_ADJ_DIAGNOSTICS_MENU : Reads the GEOS-Chem adj. diagnostic menu -! (12) VALIDATE_DIRECTORIES : Makes sure all given directories are valid -! (13) ARE_FLAGS_VALID : Makes sure all flags are valid/not conflicting -! (14) CHECK_DIRECTORY : Checks a single directory for errors -! (15) CLEAN_FILE_DIRS : Clean out directories -! (16) INIT_DEP_MAPS : Make mapping arrays for dep adjoint forcing -! (17) INIT_INPUT_ADJ : Initializes directory & logical variables +! (1 ) READ_INPUT_ADJ_FILE : Driver routine for reading GEOS-CHEM input file 读取 GC 输入文件 +! (2 ) READ_ONE_LINE : Reads one line at a time 一次读取一行 +! (3 ) SPLIT_ONE_LINE : Splits one line into substrings (by spaces) 通过空格分割文本 +! (4 ) READ_ADJ_SIMULATION_MENU : Reads the GEOS-Chem adjoint simulation menu 读取伴随设定 +! (5 ) READ_FWD_MODEL_MENU : Reads forward model options 读取正向模拟选项 +! (6 ) READ_ADJ_OPTIONS_MENU : Reads adjoint model options 读取伴随模式选项 +! (7 ) READ_ADJ_DIRECTORIES_MENU : Reads the GEOS-Chem adj. directories 读取 GC 伴随路径 +! (8 ) READ_CONTROL_VARS_MENU: Reads what are control variables 读取控制变量 +! (9 ) READ_OBSERVATION_MENU : Reads vars related to observations 读取观测相关变量 +! (10) READ_FD_ MENU : Reads finite difference test variables 读取有限差分测试变量 +! (11) READ_ADJ_DIAGNOSTICS_MENU : Reads the GEOS-Chem adj. diagnostic menu 读取伴随诊断菜单 +! (12) VALIDATE_DIRECTORIES : Makes sure all given directories are valid 确认给定目录有效 +! (13) ARE_FLAGS_VALID : Makes sure all flags are valid/not conflicting 确认所有选项游戏哦啊 +! (14) CHECK_DIRECTORY : Checks a single directory for errors 确认单个路径 +! (15) CLEAN_FILE_DIRS : Clean out directories 清除路径 +! (16) INIT_DEP_MAPS : Make mapping arrays for dep adjoint forcing 创建伴随强迫的映射数组 +! (17) INIT_INPUT_ADJ : Initializes directory & logical variables 初始化路径 ! ! GEOS-CHEM modules referenced by "input_adj_mod.f" ! ============================================================================ diff --git a/code/adjoint/inverse_driver.f b/code/adjoint/inverse_driver.f index 42bb740..8a392e8 100644 --- a/code/adjoint/inverse_driver.f +++ b/code/adjoint/inverse_driver.f @@ -780,7 +780,7 @@ CALL READ_INPUT_FILE IF ( LPRT ) CALL DEBUG_MSG( '### INVERSE: a READ_INPUT_FILE' ) - ! Read final iteration number from file + ! Read final iteration number from file 先读入当前的迭代情况 OPEN( 65, file = 'ITER' ) READ( 65,*) N_CALC_STOP READ ( 65,*) N_CALC_TOTAL @@ -802,7 +802,7 @@ IF (LADJ) CALL INIT_SETULB ! Initialize inverse modeling module - CALL INIT_INVERSE + CALL INIT_INVERSE ! 大概就是初始化了反演相关的数组 ! Curent iteration N_CALC = 0 @@ -908,7 +908,7 @@ ENDDO #endif - task = 'START' + task = 'START' ! 初始化当前过程为开始 ! Mare array of scaling factors into a vector for optimization CALL GET_X_FROM_SF @@ -942,7 +942,7 @@ print*, ' done setulb ' , TASK - CALL SAVE_WEAK_CONSTRAINT_FIELDS + CALL SAVE_WEAK_CONSTRAINT_FIELDS ! 如果是弱约束,会先输出一个弱约束场 ELSE @@ -959,55 +959,55 @@ ENDIF ! Force it to continue for FD tests, as cost func or gradients - ! may be very small or zero (dkh, 02/11/11) - IF ( LFDTEST ) TASK(1:2) = 'FG' + ! may be very small or zero (dkh, 02/11/11) 如果进行有限差分测试,则强制继续进行 + IF ( LFDTEST ) TASK(1:2) = 'FG' ! 不对,可能是要避免迭代出结果的情况? IF ( TASK(1:2) == 'FG' ) THEN - ! Iteration diagnostics (zhe 11/28/10) + ! Iteration diagnostics (zhe 11/28/10) 迭代诊断的输出 IF ( LITR ) THEN IF ( N_CALC .GT. 0 ) CALL ITER_CONDITION( N_CALC ) LATF = .FALSE. ENDIF ! The minimization routine has returned to request the - ! function f and gradient g values at the current x + ! function f and gradient g values at the current x 相当于这里就直接让梯度为 0 了 - ! Update iteration count + ! Update iteration count 继续增加迭代次数 N_CALC = N_CALC + 1 - ! Resent cost function for this iteration + ! Resent cost function for this iteration 咦,这里的代价函数值怎么直接修改了? COST_FUNC = 0.D0 - IF ( N_CALC < N_CALC_STOP ) THEN + IF ( N_CALC < N_CALC_STOP ) THEN ! 如果在停止迭代之前,则从硬盘中读取相关数据 WRITE(6,*) 'READING SAVED DATA for N_CALC = ', N_CALC - ! Read scaling factor values from disk + ! Read scaling factor values from disk 读取缩放因子 CALL GET_SF_FROM_X CALL DISPLAY_STUFF( 1 ) - ! Read gradients from disk + ! Read gradients from disk 读取梯度结果 CALL READ_GDT_FILE - ! Read cost function from disk + ! Read cost function from disk 读取代价函数结果 CALL READ_CFN_FILE - ! Put adjoints into GRADNT vector + ! Put adjoints into GRADNT vector 将伴随放到向量中 CALL GET_GRADNT_FROM_ADJ !mkeller: read gradients with respect to forcing terms IF ( DO_WEAK_CONSTRAINT ) CALL READ_GDT_U_FILE !Save the current adjoint in the finite difference test cell - ! Initial conditions test + ! Initial conditions test 意思是现在不能进行同时优化初始场和排放的有限差分测试? IF ( LFDTEST .AND. LICS .AND. LADJ_EMS) THEN PRINT*, 'WE HAVE A PROBLEM WITH STT_ADJ_FD when LICS & & LADJ_EMS are both TRUE' - ELSEIF ( LFDTEST .AND. LICS ) THEN + ELSEIF ( LFDTEST .AND. LICS ) THEN ! 剩下的部分就是从对应的数组取值,放到 STT_ADJ_FD 中 STT_ADJ_FD(N_CALC) = ICS_SF_ADJ(IFD,JFD,LFD,NFD) @@ -1049,7 +1049,7 @@ ! Return to beginning of loop - ELSEIF ( N_CALC == N_CALC_STOP ) THEN + ELSEIF ( N_CALC == N_CALC_STOP ) THEN ! 达到迭代结束次数,结束迭代 ! Done if we are just estimating inverse Hessian (dkh, 01/12/12, adj32_012) IF ( LINVH ) THEN @@ -1057,20 +1057,20 @@ STOP ENDIF - ! UPDATE THE INITIAL CONDITIONS + ! UPDATE THE INITIAL CONDITIONS 如果达到了最终迭代的条件,则更新初始条件 ! If we're doing a finite difference test, reset to the orginal ! SF and augment by amount FD_DIFF. Don't use X in this case. ! old: !IF ( ACTIVE_VARS == 'FDTEST' .AND. N_CALC == 2 ) THEN - ! new: now support 2nd order FDTEST (MAKE_SAVE_FILE_2) + ! new: now support 2nd order FDTEST (MAKE_SAVE_FILE_2) 还有做二阶有限差分的 IF ( LFDTEST .AND. N_CALC > 1 ) THEN CALL SET_SF_FORFD ELSEIF ( N_CALC == 1 ) THEN - ! don't need to call this again ?? + ! don't need to call this again ?? 笑死,不知道是谁写的注释,反正说明书写的是只做一次就行 !CALL SET_SF #if defined ( LOG_OPT ) CALL SET_LOG_SF @@ -1080,7 +1080,7 @@ ELSE - ! Update the scaling factors to the current X + ! Update the scaling factors to the current X 更新缩放系数 CALL GET_SF_FROM_X ENDIF @@ -1094,12 +1094,12 @@ !CALL READ_SF_FILE !============================================================== - ! FORWARD RUN + ! FORWARD RUN 怎么又做了一次正向模拟 !============================================================== CALL DO_GEOS_CHEM !============================================================== - ! ADJOINT CALCULATION + ! ADJOINT CALCULATION 然后又做了一次伴随 !============================================================== ! For weak constraint 4D-Var (mkeller, 06/15) @@ -1109,7 +1109,7 @@ CALL DO_GEOS_CHEM_ADJ - ! For finite difference test, we may or may not do adjoint + ! For finite difference test, we may or may not do adjoint 哈哈哈哈哈哈哈笑死,MAYBE_DO ELSE CALL MAYBE_DO_GEOS_CHEM_ADJ @@ -1117,31 +1117,31 @@ ENDIF !============================================================== - ! SAVE RESULTS TO DISK and EXIT OPTIMIZATION LOOP + ! SAVE RESULTS TO DISK and EXIT OPTIMIZATION LOOP 将结果写到硬盘,然后退出最优化循环 !============================================================== ! Zero the gradients of the species that we do not wish to optimize - ! or in places that you don't want optimized + ! or in places that you don't want optimized 将那些不想优化的部分设置为 0 CALL SET_OPT_RANGE ! Add to this Kumaresh's spatial filter - ! Write gradients + ! Write gradients 写入梯度文件 CALL MAKE_GDT_FILE - ! Write scaling factors + ! Write scaling factors 写入缩放因子 CALL MAKE_SF_FILE - ! Write cost function + ! Write cost function 写入代价函数 CALL MAKE_CFN_FILE - ! For weak constraint 4D-Var (mkeller, 06/15) + ! For weak constraint 4D-Var (mkeller, 06/15) 写入弱约束项 IF ( DO_WEAK_CONSTRAINT ) CALL MAKE_GDT_U_FILE - ! mkeller: create HDF5 file for satellite diagnostics output + ! mkeller: create HDF5 file for satellite diagnostics output 写入卫星诊断输出 IF ( LSAT_HDF_L2 .OR. LSAT_HDF_L3 .OR. LDCOSAT ) & CALL DO_SAT_DIAGS() - IF ( LEMS_ABS ) CALL MAKE_EMS_ADJ_FILE + IF ( LEMS_ABS ) CALL MAKE_EMS_ADJ_FILE ! 写入排放文件 ! Write results to screen CALL DISPLAY_STUFF( 4 ) @@ -1164,7 +1164,7 @@ ELSE - ! We terminate execution when TASK is neither FG nor NEW_X. + ! We terminate execution when TASK is neither FG nor NEW_X. 好像明白了 FG 是什么,最终迭代么 ! We print the information contained in the string TASK ! if the default output is not used and the execution is ! not stopped intentionally by the user. @@ -1179,7 +1179,7 @@ ENDIF !================================================================= - ! OPTIMIZATION loop ends here! + ! OPTIMIZATION loop ends here! 结束最优化的过程 !================================================================= ENDDO WRITE( 6, '(a)' ) REPEAT( '=', 79 ) @@ -1206,7 +1206,7 @@ ENDIF #endif - ! Clean up and quit + ! Clean up and quit 清除一些中间文件 CALL CLOSE_FILES CALL CLEANUP CALL CLEANUP_ADJ @@ -1214,7 +1214,7 @@ ! For weak constraint 4D-Var (mkeller, 06/15) IF ( DO_WEAK_CONSTRAINT ) CALL CLEAN_WEAK_CONSTRAINT - ! Remove all met files from temporary directory + ! Remove all met files from temporary directory 清除气象场文件 IF ( LUNZIP ) THEN CALL UNZIP_A3_FIELDS( 'remove all' ) CALL UNZIP_A6_FIELDS( 'remove all' ) @@ -1231,7 +1231,7 @@ ENDIF - ! Write the final iteration number for the next iteration to file + ! Write the final iteration number for the next iteration to file 写入迭代文件的信息 OPEN( 65, file = 'ITER' ) WRITE( 65,*) N_CALC_STOP + 1 CLOSE( 65 ) diff --git a/code/adjoint/inverse_mod.f b/code/adjoint/inverse_mod.f index d2657db..d4b4120 100644 --- a/code/adjoint/inverse_mod.f +++ b/code/adjoint/inverse_mod.f @@ -7,17 +7,18 @@ ! on SGI, it didn't work on Linux, so had to move all to a module. ! (dkh, 02/05)! ! Module Variables: +! 模块 INVERSE_MOD 包含了所有用于反演的子程序。只能在 SGI 运行,无法在 Linux 运行? ! ============================================================================ -! (1 ) COST_FUNC (REAL*8) : Value of cost function -! (2 ) N_CALC (INTEGER) : Optimization iteration number -! (3 ) N_CALC_STOP (INTEGER) : Maximum optimization iteration number -! (4 ) F (DOUBLE) : For optimization routine -! (5 ) X (DOUBLE, ALLOC): Vector of active varialbes -! (6 ) GRADNT (DOUBLE, ALLOC): Vector of adjoint gradients -! (7 ) XP (DOUBLE, ALLOC): Vector of active strat prod varialbes -! (8 ) GRADNT_P (DOUBLE, ALLOC): Vector of strat prod adjoint gradients -! (9 ) XL (DOUBLE, ALLOC): Vector of active strat loss varialbes -! (10) GRADNT_L (DOUBLE, ALLOC): Vector of adjoint strat loss gradients +! (1 ) COST_FUNC (REAL*8) : Value of cost function 代价函数值 +! (2 ) N_CALC (INTEGER) : Optimization iteration number 迭代次数 +! (3 ) N_CALC_STOP (INTEGER) : Maximum optimization iteration number 最大迭代次数 +! (4 ) F (DOUBLE) : For optimization routine 用于最优化的进程 +! (5 ) X (DOUBLE, ALLOC): Vector of active varialbes 激活的状态变量 +! (6 ) GRADNT (DOUBLE, ALLOC): Vector of adjoint gradients 伴随梯度向量 +! (7 ) XP (DOUBLE, ALLOC): Vector of active strat prod varialbes 平流层源 +! (8 ) GRADNT_P (DOUBLE, ALLOC): Vector of strat prod adjoint gradients 平流层源梯度 +! (9 ) XL (DOUBLE, ALLOC): Vector of active strat loss varialbes 平流层汇 +! (10) GRADNT_L (DOUBLE, ALLOC): Vector of adjoint strat loss gradients 平流层汇梯度 ! ! Module Routines ! ============================================================================ @@ -5472,7 +5473,7 @@ C ---------- LAST CARD OF DRAN ---------- ! !****************************************************************************** ! Subroutine CALC_NOPT calculates the number of paramteres to optimize -! +! 子程序用于计算需要优化的参数数量 ! NOTES: ! (1 ) Set NOPT for initial conditions to 3D: IIPAR*JJPAR*LLPAR*N_TRACERS to ! be consistent with other parts of the code (mak, 6/18/09) diff --git a/code/new/routines.f b/code/new/routines.f index a216a36..2fb903a 100644 --- a/code/new/routines.f +++ b/code/new/routines.f @@ -64,29 +64,29 @@ c This subroutine partitions the working arrays wa and iwa, and c then uses the limited memory BFGS method to solve the bound c constrained optimization problem by calling mainlb. c (The direct method will be used in the subspace minimization.) -c -c n is an integer variable. +c 看上去就是一个利用有限内存进行最优化的程序? +c n is an integer variable. problem 的维度大小 c On entry n is the dimension of the problem. c On exit n is unchanged. c -c m is an integer variable. +c m is an integer variable. 可用的变量最大数量 c On entry m is the maximum number of variable metric corrections c used to define the limited memory matrix. c On exit m is unchanged. c -c x is a double precision array of dimension n. +c x is a double precision array of dimension n. 状态向量,维度为 n c On entry x is an approximation to the solution. c On exit x is the current approximation. c -c l is a double precision array of dimension n. +c l is a double precision array of dimension n. 状态变量的下边界(预设好的) c On entry l is the lower bound on x. c On exit l is unchanged. c -c u is a double precision array of dimension n. +c u is a double precision array of dimension n. 状态变量的上边界(预设好的) c On entry u is the upper bound on x. c On exit u is unchanged. c -c nbd is an integer array of dimension n. +c nbd is an integer array of dimension n. 指定了边界是如何约束变量的 c On entry nbd represents the type of bounds imposed on the c variables, and must be specified as follows: c nbd(i)=0 if x(i) is unbounded, @@ -95,15 +95,15 @@ c 2 if x(i) has both lower and upper bounds, and c 3 if x(i) has only an upper bound. c On exit nbd is unchanged. c -c f is a double precision variable. +c f is a double precision variable. 代价函数值? c On first entry f is unspecified. c On final exit f is the value of the function at x. c -c g is a double precision array of dimension n. +c g is a double precision array of dimension n. 梯度数组,和状态向量的维度一致 c On first entry g is unspecified. c On final exit g is the value of the gradient at x. c -c factr is a double precision variable. +c factr is a double precision variable. 大概是一个最优化的临界值,到该值后结束迭代 c On entry factr >= 0 is specified by the user. The iteration c will stop when c @@ -115,7 +115,7 @@ c low accuracy; 1.d+7 for moderate accuracy; 1.d+1 for extremely c high accuracy. c On exit factr is unchanged. c -c pgtol is a double precision variable. +c pgtol is a double precision variable. 一个用户指定的值,用于指定迭代结束的条件,用于和梯度投影的长度比较 c On entry pgtol >= 0 is specified by the user. The iteration c will stop when c @@ -124,15 +124,15 @@ c c where pg_i is the ith component of the projected gradient. c On exit pgtol is unchanged. c -c wa is a double precision working array of length +c wa is a double precision working array of length 用于计算的数组,这里就是外面状态向量计算的公式 c (2mmax + 5)nmax + 12mmax^2 + 12mmax. c -c iwa is an integer working array of length 3nmax. +c iwa is an integer working array of length 3nmax. 同样也是用于计算的数组 c -c task is a working string of characters of length 60 indicating +c task is a working string of characters of length 60 indicating 作业状态说明 c the current job when entering and quitting this subroutine. c -c iprint is an integer variable that must be set by the user. +c iprint is an integer variable that must be set by the user. 指定了如何输出结果 c It controls the frequency and type of output generated: c iprint<0 no output is generated; c iprint=0 print only one line at the last iteration; @@ -143,9 +143,9 @@ c iprint>100 print details of every iteration including x and g; c When iprint > 0, the file iterate.dat will be created to c summarize the iteration. c -c csave is a working string of characters of length 60. +c csave is a working string of characters of length 60. 同样保存了作业状态的文本 c -c lsave is a logical working array of dimension 4. +c lsave is a logical working array of dimension 4. 用于指定任务状态的一个逻辑数组 c On exit with 'task' = NEW_X, the following information is c available: c If lsave(1) = .true. then the initial X has been replaced by @@ -154,7 +154,7 @@ c If lsave(2) = .true. then the problem is constrained; c If lsave(3) = .true. then each variable has upper and lower c bounds; c -c isave is an integer working array of dimension 44. +c isave is an integer working array of dimension 44. 一些更具体的状态标记 c On exit with 'task' = NEW_X, the following information is c available: c isave(22) = the total number of intervals explored in the @@ -181,7 +181,7 @@ c active constraints in the current iteration; c isave(41) = the number of variables entering the set of active c constraints in the current iteration. c -c dsave is a double precision working array of dimension 29. +c dsave is a double precision working array of dimension 29. 大概是一些任务的结果 c On exit with 'task' = NEW_X, the following information is c available: c dsave(1) = current 'theta' in the BFGS matrix; @@ -210,7 +210,7 @@ c c L-BFGS-B Library ... mainlb. c c -c References: +c References: 居然还有参考文献 c c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited c memory algorithm for bound constrained optimization'', @@ -494,7 +494,7 @@ c ************ double precision one,zero parameter (one=1.0d0,zero=0.0d0) - if (task .eq. 'START') then + if (task .eq. 'START') then ! 如果作业状态是开始 epsmch = epsilon(one) @@ -634,7 +634,7 @@ c restore the previous iterate. c Compute f0 and g0. - task = 'FG_START' + task = 'FG_START' ! 如果作业状态不是开始,则设置为 FG_START,让驱动器继续计算代价函数和梯度 c return to the driver to calculate f and g; reenter at 111. goto 1000 111 continue