Skip to content

Commit d372197

Browse files
authored
Merge pull request #582 from TerribleNews/add_co2_run
[PULL REQUEST] Add co2 run
2 parents 12e6049 + e34e0eb commit d372197

26 files changed

Lines changed: 4077 additions & 60 deletions

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ if(POLICY CMP0079)
1414
cmake_policy(SET CMP0079 NEW)
1515
endif()
1616

17+
# Add GEOS-Chem CMake helpers to MODULE_PATH
18+
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/CMakeScripts)
19+
include(GC-Helpers)
1720
#-----------------------------------------------------------------------------
1821
# Print header
1922
#-----------------------------------------------------------------------------

GeosCore/diagnostics_mod.F90

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ MODULE Diagnostics_mod
2727
PUBLIC :: Set_Diagnostics_EndofTimestep
2828
PUBLIC :: Zero_Diagnostics_StartofTimestep
2929
PUBLIC :: Compute_Budget_Diagnostics
30+
#ifdef ADJOINT
31+
PUBLIC :: Set_SpcAdj_Diagnostic
32+
#endif
3033
!
3134
! !PRIVATE MEMBER FUNCTIONS
3235
!
@@ -125,6 +128,25 @@ SUBROUTINE Set_Diagnostics_EndofTimestep( Input_Opt, State_Chm, State_Diag, &
125128
RETURN
126129
ENDIF
127130

131+
#ifdef ADJOINT
132+
!-----------------------------------------------------------------------
133+
! Set species concentration diagnostic in units specified in state_diag_mod
134+
!-----------------------------------------------------------------------
135+
IF ( State_Diag%Archive_SpeciesAdj ) THEN
136+
! if (Input_Opt%IS_FD_SPOT_THIS_PET) THEN
137+
! write(*,*) 'Before diagnostic ', &
138+
! State_Chm%SpeciesAdj(Input_Opt%IFD,Input_Opt%JFD,Input_Opt%LFD,Input_opt%NFD)
139+
! ENDIF
140+
CALL Set_SpcAdj_Diagnostic( Input_Opt, State_Chm, State_Diag, &
141+
State_Grid, State_Met, RC )
142+
143+
! Trap potential errors
144+
IF ( RC /= GC_SUCCESS ) THEN
145+
ErrMsg = 'Error encountered setting species adoint diagnostic'
146+
CALL GC_ERROR( ErrMsg, RC, ThisLoc )
147+
ENDIF
148+
ENDIF
149+
#endif
128150
!-----------------------------------------------------------------------
129151
! Set total dry deposition flux
130152
!-----------------------------------------------------------------------
@@ -312,6 +334,142 @@ SUBROUTINE Zero_Diagnostics_StartofTimestep( Input_Opt, State_Diag, RC )
312334

313335
END SUBROUTINE Zero_Diagnostics_StartofTimestep
314336
!EOC
337+
#ifdef ADJOINT
338+
!------------------------------------------------------------------------------
339+
! GEOS-Chem Global Chemical Transport Model !
340+
!------------------------------------------------------------------------------
341+
!BOP
342+
!
343+
! !IROUTINE: Set_SpcAdj_Diagnostic
344+
!
345+
! !DESCRIPTION: Subroutine Set_SpcAdj\_Diagnostic sets the passed species
346+
! adjoint diagnostic array stored in State_Diag to the instantaneous
347+
! State_Chm%SpeciesAdj values converted to the diagnostic unit stored in
348+
! the State_Diag metadata.
349+
!\\
350+
!\\
351+
! !INTERFACE:
352+
!
353+
SUBROUTINE Set_SpcAdj_Diagnostic( Input_Opt, State_Chm, State_Diag, &
354+
State_Grid, State_Met, RC )
355+
!
356+
! !USES:
357+
!
358+
USE Input_Opt_Mod, ONLY : OptInput
359+
USE State_Met_Mod, ONLY : MetState
360+
USE State_Chm_Mod, ONLY : ChmState
361+
USE State_Diag_Mod, ONLY : DgnMap
362+
USE State_Diag_Mod, ONLY : DgnState
363+
USE State_Grid_Mod, ONLY : GrdState
364+
USE UnitConv_Mod, ONLY : Convert_Spc_Units
365+
!
366+
! !INPUT PARAMETERS:
367+
!
368+
TYPE(OptInput), INTENT(IN) :: Input_Opt ! Input Options object
369+
TYPE(GrdState), INTENT(IN) :: State_Grid ! Grid state object
370+
TYPE(MetState), INTENT(IN) :: State_Met ! Meteorology state object
371+
!
372+
! !INPUT/OUTPUT PARAMETERS:
373+
!
374+
TYPE(ChmState), INTENT(INOUT) :: State_Chm ! Chemistry State object
375+
TYPE(DgnState), INTENT(INOUT) :: State_Diag ! Diagnostics State object
376+
!
377+
! !OUTPUT PARAMETERS:
378+
!
379+
INTEGER, INTENT(OUT) :: RC ! Success or failure?
380+
!
381+
! !REMARKS:
382+
!
383+
! !REVISION HISTORY:
384+
! 15 Dec 2019 - C. Lee - Initial version
385+
! 17 Dec 2020 - C. Lee - Updated to account for changes to Set_SpcConcs
386+
!EOP
387+
!------------------------------------------------------------------------------
388+
!BOC
389+
!
390+
! !LOCAL VARIABLES:
391+
!
392+
! Scalars
393+
LOGICAL :: Found
394+
INTEGER :: D, I, J, L, N, S
395+
REAL(fp) :: TmpVal, Conv
396+
397+
! Strings
398+
CHARACTER(LEN=255) :: ErrMsg, ThisLoc, Units, OrigUnit
399+
400+
! Objects
401+
TYPE(DgnMap), POINTER :: mapData
402+
403+
! Arrays
404+
REAL(fp) :: TmpSpcArr(State_Grid%NX,State_Grid%NY, &
405+
State_Grid%NZ,State_Chm%nSpecies)
406+
407+
!====================================================================
408+
! Set_SpcAdj_Diagnostic begins here!
409+
!====================================================================
410+
411+
! Assume success
412+
RC = GC_SUCCESS
413+
Found = .FALSE.
414+
ThisLoc = ' -> Set_SpcAdj_Diagnostic (in GeosCore/diagnostics_mod.F90)'
415+
416+
417+
! Verify that incoming State_Chm%Species units are kg/kg dry air.
418+
IF ( TRIM( State_Chm%Spc_Units ) /= 'kg/kg dry' ) THEN
419+
ErrMsg = 'Incorrect species units in Set_SpcConc_Diags_VVDry!'
420+
CALL GC_Error( ErrMsg, RC, ThisLoc )
421+
RETURN
422+
ENDIF
423+
424+
!$OMP PARALLEL DO &
425+
!$OMP DEFAULT( SHARED ) &
426+
!$OMP PRIVATE( I, J, L, N )
427+
DO N = 1, State_Chm%nSpecies
428+
DO L = 1, State_Grid%NZ
429+
DO J = 1, State_Grid%NY
430+
DO I = 1, State_Grid%NX
431+
! Forward code
432+
! TmpSpcArr(I,J,L,N) = State_Chm%Species(I,J,L,N) * &
433+
! ( AIRMW / State_Chm%SpcData(N)%Info%MW_g )
434+
TmpSpcArr(I,J,L,N) = State_Chm%SpeciesAdj(I,J,L,N)
435+
ENDDO
436+
ENDDO
437+
ENDDO
438+
ENDDO
439+
!$OMP END PARALLEL DO
440+
441+
!=======================================================================
442+
! Copy species to SpeciesConc (concentrations diagnostic) [v/v dry]
443+
!=======================================================================
444+
IF ( Input_Opt%Is_Adjoint ) THEN
445+
446+
! Point to mapping obj specific to SpeciesConc diagnostic collection
447+
mapData => State_Diag%Map_SpeciesConc
448+
449+
!$OMP PARALLEL DO &
450+
!$OMP DEFAULT( SHARED ) &
451+
!$OMP PRIVATE( N, S )
452+
DO S = 1, mapData%nSlots
453+
N = mapData%slot2id(S)
454+
State_Diag%SpeciesAdj(:,:,:,S) = TmpSpcArr(:,:,:,N)
455+
ENDDO
456+
!$OMP END PARALLEL DO
457+
458+
! Free pointer
459+
mapData => NULL()
460+
461+
ENDIF
462+
463+
! Error handling
464+
IF ( RC /= GC_SUCCESS ) THEN
465+
ErrMsg = 'Error converting species units for archiving diagnostics #2'
466+
CALL GC_Error( ErrMsg, RC, ThisLoc )
467+
RETURN
468+
ENDIF
469+
470+
END SUBROUTINE Set_SpcAdj_Diagnostic
471+
!EOC
472+
#endif
315473
!------------------------------------------------------------------------------
316474
! GEOS-Chem Global Chemical Transport Model !
317475
!------------------------------------------------------------------------------

GeosCore/hco_interface_gc_mod.F90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ SUBROUTINE HCOI_GC_Init( Input_Opt, State_Chm, State_Grid, &
422422
! Set misc. parameter
423423
!=======================================================================
424424

425+
#ifdef ADJOINT
426+
if ( Input_Opt%amIRoot ) WRITE(*,*) 'Setting isAdjoint to ', Input_Opt%is_adjoint
427+
HcoState%isAdjoint = Input_opt%is_adjoint
428+
#endif
425429
! Emission, chemistry and dynamics timestep in seconds
426430
HcoState%TS_EMIS = GET_TS_EMIS()
427431
HcoState%TS_CHEM = GET_TS_CHEM()
@@ -1179,6 +1183,9 @@ SUBROUTINE HCOI_GC_WriteDiagn( Input_Opt, Restart, RC )
11791183

11801184
USE Time_Mod, ONLY : Get_Year, Get_Month, Get_Day, GET_DAY_OF_YEAR
11811185
USE Time_Mod, ONLY : GET_HOUR, GET_MINUTE, GET_SECOND
1186+
#if defined( ADJOINT )
1187+
USE MAPL_CommsMod, ONLY : MAPL_AM_I_ROOT
1188+
#endif
11821189
!
11831190
! !INPUT/OUTPUT PARAMETERS:
11841191
!

GeosCore/input_mod.F90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5393,6 +5393,17 @@ SUBROUTINE CHECK_TIME_STEPS( Input_Opt, State_Grid, RC)
53935393
TS_DYN = Input_Opt%TS_DYN
53945394
TS_RAD = Input_Opt%TS_RAD
53955395

5396+
! If we're doing the reverse integration
5397+
! multiply all the timesteps by -1 here
5398+
if (TS_DYN < 0) THEN
5399+
TS_CHEM = TS_CHEM * -1
5400+
TS_EMIS = TS_EMIS * -1
5401+
TS_CONV = TS_CONV * -1
5402+
TS_DYN = TS_DYN * -1
5403+
TS_RAD = TS_RAD * -1
5404+
endif
5405+
5406+
53965407
! NUNIT is time step in minutes for unit conversion
53975408
TS_UNIT = -1
53985409

GeosCore/mixing_mod.F90

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
282282
! Strings
283283
CHARACTER(LEN=255) :: ErrMsg, ErrorMsg, ThisLoc
284284

285+
#ifdef ADJOINT
286+
LOGICAL :: IS_ADJ
287+
#endif
288+
285289
!=================================================================
286290
! DO_TEND begins here!
287291
!=================================================================
@@ -338,13 +342,34 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
338342
ENDIF
339343
ENDIF
340344

345+
#if defined( ADJOINT ) && defined ( DEBUG )
346+
IF (Input_Opt%is_adjoint .and. Input_Opt%IS_FD_SPOT_THIS_PET) THEN
347+
WRITE(*,*) ' SpcAdj(IFD,JFD) before unit converstion: ', &
348+
State_Chm%SpeciesAdj(Input_Opt%IFD, Input_Opt%JFD, &
349+
Input_Opt%LFD, Input_Opt%NFD)
350+
WRITE(*,*) ' Spc(IFD,JFD) before unit converstion: ', &
351+
State_Chm%Species(Input_Opt%IFD, Input_Opt%JFD, &
352+
Input_Opt%LFD, Input_Opt%NFD)
353+
ENDIF
354+
#endif
341355
! DO_TEND previously operated in units of kg. The species arrays are in
342356
! v/v for mixing, hence needed to convert before and after.
343357
! Now use units kg/m2 as State_Chm%SPECIES units in DO_TEND to
344358
! remove area-dependency (ewl, 9/30/15)
345359
CALL Convert_Spc_Units( Input_Opt, State_Chm, State_Grid, State_Met, &
346360
'kg/m2', RC, OrigUnit=OrigUnit )
347361

362+
#if defined( ADJOINT ) && defined ( DEBUG )
363+
IF (Input_Opt%is_adjoint .and. Input_Opt%IS_FD_SPOT_THIS_PET) THEN
364+
WRITE(*,*) ' SpcAdj(IFD,JFD) after unit converstion: ', &
365+
State_Chm%SpeciesAdj(Input_Opt%IFD, Input_Opt%JFD, &
366+
Input_Opt%LFD, Input_Opt%NFD)
367+
WRITE(*,*) ' Spc(IFD,JFD) after unit converstion: ', &
368+
State_Chm%Species(Input_Opt%IFD, Input_Opt%JFD, &
369+
Input_Opt%LFD, Input_Opt%NFD)
370+
ENDIF
371+
#endif
372+
348373
! Trap potential error
349374
IF ( RC /= GC_SUCCESS ) THEN
350375
ErrMsg = 'Unit conversion error!'
@@ -358,6 +383,11 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
358383
ELSE
359384
TS = GET_TS_DYN()
360385
ENDIF
386+
#ifdef ADJOINT
387+
if (Input_Opt%Is_Adjoint) then
388+
TS = TS * -1
389+
endif
390+
#endif
361391

362392
! First-time setup
363393
IF ( FIRST ) THEN
@@ -473,7 +503,7 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
473503
! dry deposition and/or emissions
474504
!--------------------------------------------------------------------
475505
IF ( .NOT. DryDepSpec .AND. .NOT. EmisSpec ) CYCLE
476-
506+
477507
! Loop over all grid boxes
478508
DO J = 1, State_Grid%NY
479509
DO I = 1, State_Grid%NX
@@ -606,6 +636,12 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
606636
State_Chm%Species(I,J,L,N) = FRAC * &
607637
State_Chm%Species(I,J,L,N)
608638

639+
#ifdef ADJOINT
640+
if (Input_Opt%Is_Adjoint) then
641+
State_Chm%SpeciesAdj(I,J,L,N) = FRAC * &
642+
State_Chm%SpeciesAdj(I,J,L,N)
643+
endif
644+
#endif
609645
! Eventually add PARANOX loss. PNOXLOSS is in kg/m2/s.
610646
! Make sure PARANOx loss is applied to tracers. (ckeller,
611647
! 3/29/16).
@@ -682,6 +718,15 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
682718

683719
! Flux: [kg/m2] = [kg m-2 s-1 ] x [s]
684720
FLUX = TMP * TS
721+
#ifdef ADJOINT
722+
IF ( I .eq. Input_Opt%IFD .and. J .eq. Input_Opt%JFD .and. &
723+
L .eq. Input_Opt%LFD .and. N .eq. Input_Opt%NFD) THEN
724+
WRITE(*,*) ' GetHcoVal(IFD,JFD) = ', TMP, ' FLUX = ', FLUX
725+
IF ( Input_Opt%is_adjoint ) THEN
726+
WRITE(*,*) ' SpeciesAdj(FD) = ', State_Chm%SpeciesAdj(I,J,L,N)
727+
ENDIF
728+
ENDIF
729+
#endif
685730

686731
! Add to species array
687732
State_Chm%Species(I,J,L,N) = State_Chm%Species(I,J,L,N) &
@@ -820,6 +865,17 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
820865

821866
ENDIF
822867

868+
#if defined( ADJOINT ) && defined ( DEBUG )
869+
IF (Input_Opt%is_adjoint .and. Input_Opt%IS_FD_SPOT_THIS_PET) THEN
870+
WRITE(*,*) ' SpcAdj(IFD,JFD) before unit converstion: ', &
871+
State_Chm%SpeciesAdj(Input_Opt%IFD, Input_Opt%JFD, &
872+
Input_Opt%LFD, Input_Opt%NFD)
873+
WRITE(*,*) ' Spc(IFD,JFD) before unit converstion: ', &
874+
State_Chm%Species(Input_Opt%IFD, Input_Opt%JFD, &
875+
Input_Opt%LFD, Input_Opt%NFD)
876+
ENDIF
877+
878+
#endif
823879
! Convert State_Chm%Species back to original units
824880
CALL Convert_Spc_Units( Input_Opt, State_Chm, State_Grid, State_Met, &
825881
OrigUnit, RC )
@@ -828,6 +884,17 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
828884
CALL GC_Error( ErrMsg, RC, ThisLoc )
829885
RETURN
830886
ENDIF
887+
#if defined( ADJOINT ) && defined ( DEBUG )
888+
IF (Input_Opt%is_adjoint .and. Input_Opt%IS_FD_SPOT_THIS_PET) THEN
889+
WRITE(*,*) ' SpcAdj(IFD,JFD) after unit converstion: ', &
890+
State_Chm%SpeciesAdj(Input_Opt%IFD, Input_Opt%JFD, &
891+
Input_Opt%LFD, Input_Opt%NFD)
892+
WRITE(*,*) ' Spc(IFD,JFD) after unit converstion: ', &
893+
State_Chm%Species(Input_Opt%IFD, Input_Opt%JFD, &
894+
Input_Opt%LFD, Input_Opt%NFD)
895+
ENDIF
896+
897+
#endif
831898

832899
!------------------------------------------------------------------------
833900
! Emissions/dry deposition budget diagnostics - Part 2 of 2
@@ -869,5 +936,6 @@ SUBROUTINE DO_TEND( Input_Opt, State_Chm, State_Diag, State_Grid, &
869936
DepFreq => NULL()
870937

871938
END SUBROUTINE DO_TEND
939+
872940
!EOC
873941
END MODULE MIXING_MOD

0 commit comments

Comments
 (0)