# UKCA Chemistry and Aerosol vn11.8 Tutorial 9

 Difficulty HARD Time to Complete 2 or more hours Video instructions https://youtu.be/6XqYfW2qHKY?t=681

Remember to run mosrs-cache-password in your Rose suite and UM branch terminals.

## What you will learn in this Tutorial

In this tutorial you will learn about the UKCA diagnostics package and the different diagnostics that you can output using it. You will also learn how to add new diagnostics from the new reactions and deposition that you have added.

## Task 9.1: Output new diagnostics

TASK 9.1: Output diagnostics of the reaction ${\displaystyle {\textrm {ALICE}}+{\textrm {OH}}\longrightarrow {\textrm {BOB}}+{\textrm {SEC}}\_{\textrm {ORG}}}$ to STASH code 50996, the dry deposition of ALICE to STASH code 50997, and the wet deposition of BOB to 50998. They should be outputted as a 3-hour mean to the pa/UPA stream.

If you are using one of the chemistry schemes that uses ASAD (e.g. CheT/TropIsop, CheS/Strat, CheST/StratTrop) then you can make use of the ASAD Reaction Flux Diagnostics module (held in asad_chem_flux_diags.F90). These allow you to straight-forwardly output new reaction and deposition fluxes.

To output new diagnostics you will first need to define them in the asad_flux_dat.F90 module, and then create new STASHmaster file specifications for them.

During this tutorial you will be tasked with outputting the reaction and deposition fluxes that you have added in to your branch.

Within the asad_flux_dat.F90 module the diagnostics are defined in blocks with the format

asad_flux_defn('Diagnostic type',STASH code,'Diagnostic specification',Mask,Reaction number,Number of species, &
(/'Species/Reactant 1','Reactant 2'/),                                                                         &
(/'Product 1','Product 2','Product 3','Product 4'/)),                                                          &


Which have the following meaning:

### Diagnostic Type

This is a three character string which defines what type of diagnostic is being requested. This can take the values

• RXN to output the flux through a reaction (in moles/gridcell/s)
• DEP to output the deposition flux of a species (in moles/gridcell/s)
• NET to output the net chemical tendency of a species (in moles/gridcell/s)
• STE to output the net dynamical tendency of a species (in moles/gridcell/s)
• MAS to output the mass of the atmosphere (in kg/gridcell)
• PSC to output polar stratospheric cloud diagnostics (1 when the gridcell contains a PSC, 0 otherwise - monthly mean field will be a fraction in range 0 → 1)
• TPM to output the tropospheric mask (1 for troposphere, 0 otherwise - monthly mean field will be a fraction in range 0 → 1)
• OUT to output a tracer in mmr. Only really useful if the field is masked to give the tropospheric concentration only (see the discussion of the Mask option)

### STASH Code

This is a 5 digit integer defining the STASH code that the diagnostic will be outputted to (e.g. 50001). Currently this must be in section 50.

### Diagnostic Specification

This is a one character string which is needed to further define what diagnostic is required. If it isn't needed then it should just be set to X or left blank.

• RXN
• B to output the flux through a bimolecular reaction
• T to output the flux through a termolecular reaction
• H to output the flux through a heterogeneous reaction
• J to output the flux through a photolysis reaction
• DEP
• D to output the dry deposition flux
• W to output the wet deposition flux
• PSC
• 1 to output the fraction of Type 1 PSCs
• 2 to output the fraction of Type 2 PSCs

This is a logical which defines whether only the tropospheric values of the diagnostic are outputted (.TRUE.) or not (.FALSE.). It is calculated every timestep.

For the STE diagnostic this is required if you wish to output the diagnosed stratosphere-troposphere exchange of a species. For the OUT diagnostic this can be used to output only the tropospheric concentration of a tracer. This is also used in the calculation of the of the TPM diagnostic.

### Reaction number

This is an integer, and should only be used in the special case of there being two (or more) reactions with the exactly the same reactants and products, but with different rate coefficients. In this case the first reaction in the list would be given number 1 and the second 2 etc. If this is not needed then it should be set to 0 (which will be usual for most reactions).

### Number of Species

This is an integer, and should give the total number of species, so this will be 1 for diagnostics such as DEP, STE, NET etc., which only consider a single species, and the total number of reactants and products for the RXN diagnostic.

### Species

This is a 10-character string giving the exact name of the species that the diagnostic should be considered for (including capitalisation). This is only used for the DEP, NET, STE, and OUT. For the RXN diagnostics the full list of reactants and products should be given (see below). For the MAS, PSC, and TPM diagnostics this isn't needed and could either be set to XXX or left blank. If it is needed the other reactant/product slots should be left blank.

### Reactants and Products

These are 10-character strings, and should be as the reaction is defined in the ukca_chem_master.F90 module.

### Summing Diagnostics

If you define more than one diagnostic to be output to the same STASH code, then the diagnostic routines will sum these diagnostics together. This can be useful (e.g., if you wanted to output the sum of all NO+RO2 reactions to one STASH item), but can be problematic if you accidentally output two fields to the same STASH code, as this will give strange results!

### Changes to asad_flux_dat.F90

After you have defined your new diagnostics in this module, you will need to make sure that they have been added correctly to the asad_chemical_fluxes array, which is defined in the asad_load_default_fluxes subroutine held in the asad_flux_dat.F90 module. You will need to increment the size of this array, given by the n_chemical_fluxes parameter.

Note that as there are several different chemical mechanism with further-sub options, how asad_chemical_fluxes is defined is rather complex:

! Pick up correct version of the aerosol chemistry
IF (ukca_config%l_ukca_offline .OR. ukca_config%l_ukca_offline_be) THEN
n_aero_fluxes = 16
ELSE IF (ukca_config%l_ukca_strattrop) THEN
n_aero_fluxes = 16
ELSE IF (ukca_config%l_ukca_cristrat) THEN
n_aero_fluxes = 24
ELSE
n_aero_fluxes = 16
END IF

! Use pre-determined reaction list

IF (ukca_config%l_ukca_cristrat) THEN
IF (ukca_config%l_ukca_chem_aero) THEN
n_chemical_fluxes = 756
cri_trop_ox_budget_prod01,  & ! 57 57
cri_trop_ox_budget_prod02,  & ! 41 98
cri_aer_trop_ox_budget_loss01,& ! 34 132
cri_aer_trop_ox_budget_loss02,& ! 72 204
cri_trop_ox_budget_drydep,  & ! 26 230
cri_trop_ox_budget_wetdep,  & ! 18 248
cri_aer_trop_other_fluxes,  & ! 56 304
cri_aer_trop_co_budget,     & ! 47 359
cri_rco2no2_pan_prod,       & ! 6  489
cri_ro2ho2_reacn,           & ! 47 536
cri_ro2no3_reacn,           & ! 54 590
cri_ro2ro2_reacn,           & ! 63 653
cri_oxidN_wetdep,           & ! 19 719
cri_oxidN_drydep            & ! 37 756
/)
ELSE
n_chemical_fluxes = 745
cri_trop_ox_budget_prod01,  & ! 57 57
cri_trop_ox_budget_prod02,  & ! 41 98
cri_trop_ox_budget_loss01,  & ! 34 132
cri_trop_ox_budget_loss02,  & ! 72 204
cri_trop_ox_budget_drydep,  & ! 26 230
cri_trop_ox_budget_wetdep,  & ! 18 248
cri_trop_other_fluxes,      & ! 56 304
cri_trop_co_budget,         & ! 47 359
cri_rco2no2_pan_prod,       & ! 6  478
cri_ro2ho2_reacn,           & ! 47 525
cri_ro2no3_reacn,           & ! 54 579
cri_ro2ro2_reacn,           & ! 63 642
cri_oxidN_wetdep,           & ! 19 708
cri_oxidN_drydep            & ! 37 745
/)
END IF
ELSE
IF (ukca_config%l_ukca_ro2_perm) THEN
!- If RO2-permutation chemistry, need different RO2+RO2
!  reactions
n_chemical_fluxes = 338
/)
ELSE
n_chemical_fluxes = 331
/)
END IF
END IF


The first block of code is required to set asad_aerosol_chem, as the reactions that make up this set of diagnostics vary depending on chemistry scheme used. The second longer block sets asad_chemical_fluxes for either the CRI-Strat or StratTrop routines, and then has sub-options depending on whether RO2-permutation chemistry is being used as this then changes a sub-set of reactions again.

When adding your diagnostics to these blocks of code, take care to ensure that you add them to the correct place, otherwise you may have an error or the diagnostics may show zero output.

### Changes to asad_chem_flux_diags.F90 (and other UKCA routines)

You will need to edit asad_chem_flux_diags.F90 module if you want to output a new type of diagnostic. This can be quite involved, but you can look at existing routines to see how things are done. You will also need to add code into the main UKCA routines the pass the data through, e.g.

     ! 3D flux diagnostics
model_levels,dpd_full,dpw_full,prk_full,y_full,                    &
j,i,klevel,volume,ierr)


## STASHmaster file

While the diagnostics are defined in asad_flux_dat.F90 they are turned on by requesting the item through STASH. To do this you will need to edit the STASHmaster_A file in your branch, as covered in the Adding new chemical tracers tutorial. Here, as you are adding new diagnostics to section 50, the equivalent pressure-level diagnostics need to be made in section 52.

Most UKCA diagnostics are 3D, although some, such as emissions (which are outputted in a different way), are 2D. You should take care with the STASH settings in STASHmaster_A between these types, as there some differences that will need to be considered. Note that any 2D (i.e. surface) diagnostics that you create will not have a pressure-level equivalent.

As previously, you may find it easier to copy an existing diagnostic and edit that, but take care to ensure that the settings used are equivalent, e.g. you should copy a 3D section 50 field and not a 2D one, or one from section 34 etc.

### Rose Changes

If you have not done so, you will also need to make sure that you use your new STASHmaster_A file in Rose, as is explained in detail in Tutorial 4.

After you have made your STASmaster_A file changes, you will need to add these diagnostics into STASH, as per Tutorial 3. Remember to run the TidyStashTransform macro. As you will have included your branch's STASHmaster_A file using @HEAD, you won't need to make any further changes to Rose, but you will need to make sure that you have committed your UM branch prior to running. Because the file is taken from fcm:um.xm_br you will need to make sure that the revision has synced to the PUMA mirror (i.e. by waiting a few minutes).

## Solution to Task 9.1: Output new diagnostics

• Output diagnostics of the reaction ${\displaystyle {\textrm {ALICE}}+{\textrm {OH}}\longrightarrow {\textrm {BOB}}+{\textrm {SEC}}\_{\textrm {ORG}}}$ to STASH code 50996, the dry deposition of ALICE to STASH code 50997, and the wet deposition of BOB to 50998. They should be outputted as a 3-hour mean to the pa/UPA stream.

For a working Rose suite that has completed this task, please see

• vm: u-ca024@183251

The specific Rose changes made are:

vm:

Index: app/um/rose-app.conf
===================================================================
--- app/um/rose-app.conf	(revision 182959)
+++ app/um/rose-app.conf	(revision 183251)
@@ -3793,6 +3793,30 @@
tim_name='T3HMN'
use_name='UPA'

+[namelist:umstash_streq(50996_26eab91c)]
+dom_name='DALLTH'
+isec=50
+item=996
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
+[namelist:umstash_streq(50997_e01cc6bc)]
+dom_name='DALLTH'
+isec=50
+item=997
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
+[namelist:umstash_streq(50998_01fd6a94)]
+dom_name='DALLTH'
+isec=50
+item=998
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
[namelist:umstash_streq(51001_3e6241a4)]
dom_name='DP27CCM'
isec=51
@@ -3841,6 +3865,30 @@
tim_name='T3HMN'
use_name='UPA'

+[namelist:umstash_streq(52996_56c5ed16)]
+dom_name='DP27CCM'
+isec=52
+item=996
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
+[namelist:umstash_streq(52997_eb3669f6)]
+dom_name='DP27CCM'
+isec=52
+item=997
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
+[namelist:umstash_streq(52998_c5c157df)]
+dom_name='DP27CCM'
+isec=52
+item=998
+package=
+tim_name='T3HMN'
+use_name='UPA'
+
[namelist:umstash_time(t3hmn_039ecafe)]
!!iedt=0
iend=-1
Index: app/fcm_make/rose-app.conf
===================================================================
--- app/fcm_make/rose-app.conf	(revision 182959)
+++ app/fcm_make/rose-app.conf	(revision 183251)
@@ -43,4 +43,4 @@
timer_version=3A
um_rev=\$BASE_UM_REV
-um_sources=branches/dev/lukeabraham/vn11.8_UKCA_Tutorial_Solns@94120
+um_sources=branches/dev/lukeabraham/vn11.8_UKCA_Tutorial_Solns@94303


These differences can be found in the file Tutorials/vn11.8/worked_solutions/Task09.1/Task09.1_rose.patch.

The specific UM changes made are:

Index: src/atmosphere/UKCA/asad_flux_dat.F90
===================================================================
@@ -4177,6 +4177,18 @@
(/'          ','          ','          ','          '/))                       &
/)

+! Additional diagnostics for UKCA tutorials
+TYPE(asad_flux_defn), PARAMETER, PUBLIC :: ukca_tutorial_fluxes(3) = (/        &
+(/'ALICE     ','OH        '/),                                                 &
+(/'BOB       ','Sec_Org   ','          ','          '/)),                      &
+(/'ALICE     ','          '/),                                                 &
+(/'          ','          ','          ','          '/)),                      &
+(/'BOB       ','          '/),                                                 &
+(/'          ','          ','          ','          '/))                       &
+/)

@@ -4301,7 +4313,7 @@
IF (ukca_config%l_ukca_ro2_perm) THEN
!- If RO2-permutation chemistry, need different RO2+RO2
!  reactions
-    n_chemical_fluxes = 338
+    n_chemical_fluxes = 341
@@ -4326,10 +4338,11 @@
-       asad_oxidN_drydep           & ! 13 338
+       asad_oxidN_drydep,          & ! 13 338
+       ukca_tutorial_fluxes        & ! 3  341
/)
ELSE
-    n_chemical_fluxes = 331
+    n_chemical_fluxes = 334
@@ -4354,7 +4367,8 @@
-       asad_oxidN_drydep           & ! 13 331
+       asad_oxidN_drydep,          & ! 13 331
+       ukca_tutorial_fluxes        & ! 3  334
/)
END IF
END IF
===================================================================
@@ -26284,6 +26284,18 @@
=
=Available only if NetCDF emission system of UKCA is used

+[stashmaster:code(50996)]
+description=RXN FLX: ALICE+OH->BOB+Sec_Org
+help=Flux through the ALICE+OH->BOB+Sec_Org reaction
+
+[stashmaster:code(50997)]
+description=DRY DEP FLUX: ALICE (3D)
+help=Dry deposition flux of ALICE
+
+[stashmaster:code(50998)]
+description=WET DEP FLUX: BOB (3D)
+help=Wet deposition flux of BOB
+
[stashmaster:code(51001)]
description=O3 MASS MIXING RATIO ON PRESS LEVS
help=Ozone Mass Mixing Ratio in kg/kg(Air)
@@ -29792,6 +29804,21 @@
=chemistry on pressure levels
=Available for Strat and StratTrop chemistry only

+[stashmaster:code(52996)]
+description=RXN FLX: ALICE+OH->BOB+Sec_Org PLEV
+help=Flux through the ALICE+OH->BOB+Sec_Org reaction
+    = on Pressure Levels
+
+[stashmaster:code(52997)]
+description=DRY DEP FLUX: ALICE (3D) PLEVS
+help=Dry deposition flux of ALICE
+    = on Pressure Levels
+
+[stashmaster:code(52998)]
+description=WET DEP FLUX: BOB (3D) PLEVS
+help=Wet deposition flux of BOB
+    = on Pressure Levels
+
[stashmaster:code(53181)]
description=Temperature Inc: Idealised  (K/step)
help=Temperature increment from the idealised section in Kelvin per model
===================================================================
@@ -27521,6 +27521,24 @@
4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
5|    0 |    0 |    0 |  129 |    0 |    0 |    0 |    0 |    0 |
#
+1|    1 |   50 |  996 |RXN FLUX: ALICE+OH->BOB+Sec_Org     |
+2|    0 |    0 |   17 |    1 |    2 |   10 |   11 |    0 |    0 |    0 |    0 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |   65 |    0 |    0 |    0 |    0 |    0 |
+#
+1|    1 |   50 |  997 |DRY DEP FLUX: ALICE (3D)            |
+2|    0 |    0 |   17 |    1 |    2 |   10 |   11 |    0 |    0 |    0 |    0 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |   65 |    0 |    0 |    0 |    0 |    0 |
+#
+1|    1 |   50 |  998 |WET DEP FLUX: BOB (3D)              |
+2|    0 |    0 |   17 |    1 |    2 |   10 |   11 |    0 |    0 |    0 |    0 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |   65 |    0 |    0 |    0 |    0 |    0 |
+#
#===============================================================================
# Section 50 Item 999 reserved.
#===============================================================================
@@ -30625,6 +30643,24 @@
# pressure levels not meaningful. Do not use these slots for other diagnostics.
#===============================================================================
#
+1|    1 |   52 |  996 |RXN FLUX: ALICE+OH->BOB+Sec_Org PLEV|
+2|    0 |    0 |   17 |    1 |    3 |    1 |    2 |    0 |    0 |    0 |    1 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |    8 |    0 |    0 |    0 |    0 |    0 |
+#
+1|    1 |   52 |  997 |DRY DEP FLUX: ALICE (3D) PLEVS      |
+2|    0 |    0 |   17 |    1 |    3 |    1 |    2 |    0 |    0 |    0 |    1 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |    8 |    0 |    0 |    0 |    0 |    0 |
+#
+1|    1 |   52 |  998 |WET DEP FLUX: BOB (3D) PLEVS        |
+2|    0 |    0 |   17 |    1 |    3 |    1 |    2 |    0 |    0 |    0 |    1 |
+3| 000000000000000000000000010000 | 00000000000000000001 |    3 |
+4|    1 |    0 | -99  -99  -99  -99  -99  -99  -99  -99  -99  -99 |
+5|    0 |    0 |    0 |    8 |    0 |    0 |    0 |    0 |    0 |
+#
#===============================================================================
# Section 52 Item 999 reserved.
#===============================================================================


If you open the .pa file in Xconv, you should see the following fields:

 2    : 96   72   27    1     unspecified: Stash code = 52996
3    : 96   72   27    1     unspecified: Stash code = 52997
4    : 96   72   27    1     unspecified: Stash code = 52998

29   : 96   72   38    1     unspecified: Stash code = 50996
30   : 96   72   38    1     unspecified: Stash code = 50997
31   : 96   72   38    1     unspecified: Stash code = 50998


These differences can be found in the file Tutorials/vn11.8/worked_solutions/Task09.1/Task09.1_code.patch.

Sample output from this task can be found at Tutorials/vn11.8/sample_output/Task09.1/atmosa.pa19810901_00.

## Checklist

Make the required changes to branch's STASHmaster_A file, to add the new diagnostics. Make a note of the STASH items chosen, and also add the pressure-level diagnostics.
Using a text editor, open the app/um/rose-app.conf file from your roses/[SUITE-ID] directory, and add the line STASHMASTER=STASHmaster in the [env] block, then save and close the file.
Using a text editor, open the rose-suite.conf file from your roses/[SUITE-ID] directory, and add the following lines to the top of the file, before saving and closing it:
[file:app/um/file/STASHmaster]

Point the metadata in your suite to the rose-meta/um-atmos/HEAD of your branch's working copy.
Include your branch in your suite at: fcm_make ${\displaystyle \rightarrow }$ env ${\displaystyle \rightarrow }$ Sources.
In asad_flux_dat.F90, make a new array of type asad_flux_defn and populate it with your new diagnostic specification(s), referencing the same item numbers as in your STASHmaster_A file.
Append this new array at the end of asad_chemical_fluxes, and increment n_chemical_fluxes by the number of new diagnostics.
If required, add new code for new diagnostics into asad_chem_flux_diags.F90 and other UKCA routines as necessary.
Output your diagnostics in STASH at: um ${\displaystyle \rightarrow }$ namelist ${\displaystyle \rightarrow }$ Model Input and Output ${\displaystyle \rightarrow }$ STASH Requests and Profiles ${\displaystyle \rightarrow }$ STASH Requests.
In the roses/[SUITE-ID] directory, run fcm commit to commit your changes to the repository.