Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing legacy code and cleaning up logic for real processing of aerosol for mp_physics=28 #1567

Merged
merged 8 commits into from
Dec 17, 2021

Conversation

twjuliano
Copy link
Contributor

@twjuliano twjuliano commented Oct 14, 2021

TYPE: enhancement

KEYWORDS: real, Thompson aerosol-aware, microphysics

SOURCE: Timothy W. Juliano and Pedro A. Jimenez (NCAR/RAL)

DESCRIPTION OF CHANGES:
Problem:
Several modifications have been made to the Thompson Aerosol-Aware scheme (mp_physics=28) in an effort to clean the logic in dyn_em/module_initialize_real and enable more flexibility when pre-processing first guess aerosol fields (e.g., GEOS-5). These modifications are made in preparation for upcoming enhancements to the Thompson AA scheme related to the addition of black carbon aerosol (anthropogenic and biomass burning) and organic carbon biomass burning aerosol, as well as time-varying surface emissions.

Solution:

  1. Processing of aerosol in real.exe contained legacy code. Specifically, the monthly qnwfa and qnifa variables (qn?fa_jan, qn?fa_feb, etc.) have been removed from Registry files and dyn_em/module_initialize_real.

  2. Modifications have been made to the METGRID.TBL file to simplify the subsequent logic in the real program's dyn_em/module_initialize_real. Specifically, we:

    • replace FLAG_QNWFA and FLAG_QNIFA with FLAG_QNWFA_CL and FLAG_QNIFA_CL, respectively, in the W_WIF_DEC and I_WIF_DEC entries, where “CL” stands for climatology;
    • add FLAG_QNWFA and FLAG_QNIFA to the QNWFA and QNIFA entries, respectively, for the first guess aerosol arrays;
    • add entry P_WIF to give the user the option to interpolate the first guess aerosol using the native pressure levels of the host model;
    • use num_wif_levels for any z dimension associated with the aerosol field entries (climatology or first guess);
    • add surface aerosol emission arrays QNWFA2D and QNIFA2D to be processed.

The modifications to METGRID.TBL are as follows:

========================================
name=W_WIF_DEC
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA_CL
========================================
name=I_WIF_DEC
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA_CL
========================================
name=QNWFA
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA
========================================
name=QNIFA
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA
========================================
name=P_WIF
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_P_WIF
========================================
name=QNWFA2D
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA2D
========================================
name=QNIFA2D
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA2D
========================================
  1. At present, if the user sets use_aero_icbc=.true. and does not set num_wif_levels to 30, then the code executes without error, even though the climatological aerosols will not be processed properly. Therefore, we have changed the default value of num_wif_levels from 27 to 30 to prevent unintended errors when the user forgets to set this value in the namelist. We note that with our code modifications, namelist variable num_wif_levels will be used to control both climatology and first guess aerosol processing in dyn_em/module_initialize_real.

  2. We have added a new (surrogate) variable, aer_init_opt (integer, default=0), that facilitates much cleaner logic in dyn_em/module_initialize_real while “working in the background” and maintaining backward-compatibility such that namelist options use_aero_icbc and use_rap_aero_icbc may be used in the same manner as before. First, in
    share/module_check_a_mundo, we check if the user has selected Thompson AA and either use_aero_icbc (aer_init_opt=1) or use_rap_aero_icbc (aer_init_opt=2). Here, we also ensure that if aer_init_opt>0, then wif_input_opt=1. Now, in dyn_em/module_initialize_real, we are able to simplify the logic of processing aerosol fields by using select case on aer_init_opt for both the 3D and 2D (surface emissions) aerosol processing.

  3. For the 3D aerosol processing, here is the new workflow. When the user selects use_aero_icbc=.true. (i.e., aer_init_opt=1) for climatology aerosol forcing, we interpolate the aerosol fields to the WRF grid pressure levels as before. No changes have been made to the interpolation routine for use_aero_icbc. However, when the user selects use_rap_aero_icbc=.true. (i.e., aer_init_opt=2) for first guess aerosol forcing, we allow for two possibilities:

    • the user has pre-processed the first guess aerosol such that they are located at the native pressure levels of the host model. In this case, the user will process pressure variable p_wif during metgrid, and flag_p_wif=1, as defined in the modified METGTRID.TBL file, will be written to the met_em files. In dyn_em/module_initialize_real, we check for flag_p_wif=1 and subsequently interpolate the aerosol fields to the WRF grid pressure levels. At this stage, we do not have a way to check to ensure that the user-defined num_wif_levels in the namelist is equal to num_wif_levels written to the met_em files. For now, the best we can do is write a comment to the rsl.out files.
    • the user has pre-processed the first guess aerosol such that they are interpolated to the ungrib pressure levels. In this case, the user will set num_wif_levels in the namelist equal to num_metgrid_levels; otherwise, a fatal error will occur.
  4. For the 2D aerosol processing, here is the new workflow. When the user selects use_aero_icbc=.true. (i.e., aer_init_opt=1) for climatology aerosol forcing, the surface water-friendly and ice-friendly emissions are processed as before. No changes have been made to these routines. However, when the user selects use_rap_aero_icbc=.true. (i.e., aer_init_opt=2) for first guess aerosol forcing, we check for the surface emission flags for water- and ice-friendly and process if they are there; otherwise, the arrays are set to zero.

LIST OF MODIFIED FILES:
M Registry/Registry.EM
M Registry/Registry.EM_CHEM
M Registry/Registry.EM_COMMON
M Registry/Registry.tladj
M Registry/registry.new3d_wif
M dyn_em/module_initialize_real.F
M share/module_check_a_mundo.F
M share/module_optional_input.F

TESTS CONDUCTED:

  1. We have tested the logic to ensure that it catches any issues related to namelist options and flags in met_em files. Also, we have tested to make sure that the 3D aerosol fields interpolated to the WRF grid are nearly identical when using either method for aerosol first guess (i.e., interpolating using the native pressure levels of the host model versus the pre-processed aerosol on metgrid levels).
  2. Jenkins tests are all PASSING

RELEASE NOTE: Code enhancements are introduced to the processing of aerosol information in real.exe for the Thompson Aerosol-Aware microphysics scheme; specifically, legacy code is removed and logic in the real program is improved.

@twjuliano
Copy link
Contributor Author

twjuliano commented Oct 14, 2021

@gthompsnWRF @pedro-jm could you please have a look at this? Thanks!

@davegill
Copy link
Contributor

@weiwangncar @dudhia
Folks,
Should this Thompson MP update go into the develop branch instead of v4.3.1?

@weiwangncar
Copy link
Collaborator

Yes, I think so.

@davegill davegill changed the base branch from release-v4.3.1 to release-v4.3.2 November 7, 2021 19:08
@davegill davegill changed the base branch from release-v4.3.2 to develop November 10, 2021 05:24
@davegill
Copy link
Contributor

@weiwangncar
Wei,
I also think that this is too big for a 4.3.2 bug fix
I am moving it to develop

@twjuliano twjuliano requested review from a team as code owners December 14, 2021 22:50
@davegill
Copy link
Contributor

davegill commented Dec 15, 2021

@twjuliano @mgduda

Modifications have been made to the METGRID.TBL file to simplify the logic in dyn_em/module_initialize_real.

Tim,
Make sure that those mods get into the WPS repo: github/wrf-model/WPS. Submit a PR, similar to WRF. Use the master branch as the base

@davegill
Copy link
Contributor

davegill commented Dec 15, 2021

@twjuliano
Tim,
BIG COMMIT!
Would you resolve the conflict in the module_initialize_real.F file? It looks like just a single location. You can do this from the github pull request conversation page. Typical of this sort user required intervention, there will be <<<<, =====, and >>>> characters to search for. Let me know if you run into any troubles.

@twjuliano
Copy link
Contributor Author

@twjuliano Tim, BIG COMMIT! Would you resolve the conflict in the module_initialize_real.F file? It looks like just a single location. You can do this from the github pull request conversation page. Typical of this sort user required intervention, there will be <<<<, =====, and >>>> characters to search for. Let me know if you run into any troubles.

@davegill I fixed the merge conflict via the github PR conversation page, but then I merged develop. I think this is wrong. I'm not sure how to fix the conflict without merging develop. I can make this change locally and push a new commit if that would be easier. Thanks.

@twjuliano
Copy link
Contributor Author

twjuliano commented Dec 15, 2021

@twjuliano @mgduda

Modifications have been made to the METGRID.TBL file to simplify the logic in dyn_em/module_initialize_real.

Tim, Make sure that those mods get into the WPS repo: github/wrf-model/WPS. Submit a PR, similar to WRF. Use the master branch as the base

Done: wrf-model/WPS#190

@davegill
Copy link
Contributor

@twjuliano
Tim,
Here are the failures:

Please find result of the WRF regression test cases in the attachment. This build is for Commit ID: edb560daf792f2aca1d19357e8b653b8aaae1d83, requested by: twjuliano for PR: https://github.com/scala-computing/WRF/pull/1567. For any query please send e-mail to David Gill.

    Test Type              | Expected  | Received |  Failed
    = = = = = = = = = = = = = = = = = = = = = = = =  = = = =
    Number of Tests        : 23           24
    Number of Builds       : 60           58
    Number of Simulations  : 159           155         3
    Number of Comparisons  : 96           91         0

    Failed Simulations are: 
    output_18:2 = STATUS test_018s em em_real 32 65DF
output_18:2 = STATUS test_018o em em_real 33 65DF
output_18:2 = STATUS test_018m em em_real 34 65DF
    Which comparisons are not bit-for-bit: 
    None

This points to a digital filter run-time issue. I'll take a look after some meetings.

@davegill
Copy link
Contributor

@twjuliano
Tim,
Here is the error message (not at all related to digital filtering - whew!).

d01 2000-01-24_12:00:00 COMMENT: Using monthly climatology aerosols
-------------- FATAL CALLED ---------------
FATAL CALLED FROM FILE:  <stdin>  LINE:    2130
mp_physics=28 and use_aero_icbc=.true. but aerosol climatology field(s) missing
-------------------------------------------

What is the aerosol climatology field? Is this something that comes in from metgrid? Is it a static look-up file in the WRF run directory?

@twjuliano
Copy link
Contributor Author

@twjuliano Tim, Here is the error message (not at all related to digital filtering - whew!).

d01 2000-01-24_12:00:00 COMMENT: Using monthly climatology aerosols
-------------- FATAL CALLED ---------------
FATAL CALLED FROM FILE:  <stdin>  LINE:    2130
mp_physics=28 and use_aero_icbc=.true. but aerosol climatology field(s) missing
-------------------------------------------

What is the aerosol climatology field? Is this something that comes in from metgrid? Is it a static look-up file in the WRF run directory?

@davegill Great to see that it wasn't some cryptic error. That fatal comes from only one place in the code: where we check for the (new) flags, flag_qnwfa_cl and flag_qnifa_cl, which replaced flag_qnwfa and flag_qnifa for the aerosol climatology fields. So yes, this would come in from metgrid. This snag happens early on in the real processing of aerosol, but there is subsequent code that checks for these two new flags, in addition to the (new) flag_p_wif, flag_qnwfa2d, and flag_qnifa2d. Please let me know how we should best deal with this, thanks.

@davegill
Copy link
Contributor

@twjuliano @weiwangncar @kkeene44
Tim,
Where are these climatology data sets? Are they available to users?

@twjuliano
Copy link
Contributor Author

twjuliano commented Dec 16, 2021

@twjuliano @weiwangncar @kkeene44 Tim, Where are these climatology data sets? Are they available to users?

@davegill Hi Dave, the climatology aerosol data set is available on the WRF Users page (https://www2.mmm.ucar.edu/wrf/users/physics/mp28_updated.html). It looks like it is also available on glade for those on Cheyenne: /glade/work/wrfhelp/WPS_files. For this PR, we do not modify the .dat file that is processed during metgrid. Thanks.

@davegill davegill self-requested a review December 16, 2021 20:05
@davegill
Copy link
Contributor

@weiwangncar
Wei,
This is mostly a change to the real program, and I have reviewed the changes. The associated mods for WPS have been submitted. I am OK with this PR. Please feel free to review.

@weiwangncar
Copy link
Collaborator

@davegill I hope I can run a test next week to see how this works.

@davegill davegill merged commit 61a1359 into wrf-model:develop Dec 17, 2021
vlakshmanan-scala pushed a commit to scala-computing/WRF that referenced this pull request Apr 4, 2024
…osol for mp_physics=28 (wrf-model#1567)

TYPE: enhancement

KEYWORDS: real, Thompson aerosol-aware, microphysics

SOURCE: Timothy W. Juliano and Pedro A. Jimenez (NCAR/RAL)

DESCRIPTION OF CHANGES:
Problem:
Several modifications have been made to the Thompson Aerosol-Aware scheme (mp_physics=28) in an effort to clean the logic in dyn_em/module_initialize_real and enable more flexibility when pre-processing first guess aerosol fields (e.g., GEOS-5). These modifications are made in preparation for upcoming enhancements to the Thompson AA scheme related to the addition of black carbon aerosol (anthropogenic and biomass burning) and organic carbon biomass burning aerosol, as well as time-varying surface emissions.

Solution:
1. Processing of aerosol in real.exe contained legacy code. Specifically, the monthly qnwfa and qnifa variables (qn?fa_jan, qn?fa_feb, etc.) have been removed from Registry files and dyn_em/module_initialize_real.

2. Modifications have been made to the METGRID.TBL file to simplify the subsequent logic in the real program's dyn_em/module_initialize_real. Specifically, we: 
   * replace FLAG_QNWFA and FLAG_QNIFA with FLAG_QNWFA_CL and FLAG_QNIFA_CL, respectively, in the W_WIF_DEC and I_WIF_DEC entries, where “CL” stands for climatology; 
   * add FLAG_QNWFA and FLAG_QNIFA to the QNWFA and QNIFA entries, respectively, for the first guess aerosol arrays;
   * add entry P_WIF to give the user the option to interpolate the first guess aerosol using the native pressure levels of the host model;
   * use num_wif_levels for any z dimension associated with the aerosol field entries (climatology or first guess);
   * add surface aerosol emission arrays QNWFA2D and QNIFA2D to be processed.

The modifications to METGRID.TBL are as follows: 
```
========================================
name=W_WIF_DEC
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA_CL
========================================
name=I_WIF_DEC
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA_CL
========================================
name=QNWFA
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA
========================================
name=QNIFA
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA
========================================
name=P_WIF
z_dim_name=num_wif_levels
interp_option=four_pt+average_4pt
flag_in_output=FLAG_P_WIF
========================================
name=QNWFA2D
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNWFA2D
========================================
name=QNIFA2D
interp_option=four_pt+average_4pt
flag_in_output=FLAG_QNIFA2D
========================================
```

3. At present, if the user sets use_aero_icbc=.true. and does not set num_wif_levels to 30, then the code executes without error, even though the climatological aerosols will not be processed properly. Therefore, we have changed the default value of num_wif_levels from 27 to 30 to prevent unintended errors when the user forgets to set this value in the namelist. We note that with our code modifications, namelist variable num_wif_levels will be used to control both climatology and first guess aerosol processing in dyn_em/module_initialize_real.

4. We have added a new (surrogate) variable, aer_init_opt (integer, default=0), that facilitates much cleaner logic in dyn_em/module_initialize_real while “working in the background” and maintaining backward-compatibility such that namelist options use_aero_icbc and use_rap_aero_icbc may be used in the same manner as before. First, in 
share/module_check_a_mundo, we check if the user has selected Thompson AA and either use_aero_icbc (aer_init_opt=1) or use_rap_aero_icbc (aer_init_opt=2). Here, we also ensure that if aer_init_opt>0, then wif_input_opt=1. Now, in dyn_em/module_initialize_real, we are able to simplify the logic of processing aerosol fields by using select case on aer_init_opt for both the 3D and 2D (surface emissions) aerosol processing.

5. For the 3D aerosol processing, here is the new workflow. When the user selects use_aero_icbc=.true. (i.e., aer_init_opt=1) for climatology aerosol forcing, we interpolate the aerosol fields to the WRF grid pressure levels as before. No changes have been made to the interpolation routine for use_aero_icbc. However, when the user selects use_rap_aero_icbc=.true. (i.e., aer_init_opt=2) for first guess aerosol forcing, we allow for two possibilities: 
   * the user has pre-processed the first guess aerosol such that they are located at the native pressure levels of the host model. In this case, the user will process pressure variable p_wif during metgrid, and flag_p_wif=1, as defined in the modified METGTRID.TBL file, will be written to the met_em files. In dyn_em/module_initialize_real, we check for flag_p_wif=1 and subsequently interpolate the aerosol fields to the WRF grid pressure levels. At this stage, we do not have a way to check to ensure that the user-defined num_wif_levels in the namelist is equal to num_wif_levels written to the met_em files. For now, the best we can do is write a comment to the rsl.out files. 
   * the user has pre-processed the first guess aerosol such that they are interpolated to the ungrib pressure levels. In this case, the user will set num_wif_levels in the namelist equal to num_metgrid_levels; otherwise, a fatal error will occur.

6. For the 2D aerosol processing, here is the new workflow. When the user selects use_aero_icbc=.true. (i.e., aer_init_opt=1) for climatology aerosol forcing, the surface water-friendly and ice-friendly emissions are processed as before. No changes have been made to these routines. However, when the user selects use_rap_aero_icbc=.true. (i.e., aer_init_opt=2) for first guess aerosol forcing, we check for the surface emission flags for water- and ice-friendly and process if they are there; otherwise, the arrays are set to zero.

LIST OF MODIFIED FILES:
M Registry/Registry.EM
M Registry/Registry.EM_CHEM
M Registry/Registry.EM_COMMON
M Registry/Registry.tladj
M Registry/registry.new3d_wif
M dyn_em/module_initialize_real.F
M share/module_check_a_mundo.F
M share/module_optional_input.F

TESTS CONDUCTED:
1. We have tested the logic to ensure that it catches any issues related to namelist options and flags in met_em files. Also, we have tested to make sure that the 3D aerosol fields interpolated to the WRF grid are nearly identical when using either method for aerosol first guess (i.e., interpolating using the native pressure levels of the host model versus the pre-processed aerosol on metgrid levels).
2. Jenkins tests are all PASSING

RELEASE NOTE: Code enhancements are introduced to the processing of aerosol information in real.exe for the Thompson Aerosol-Aware microphysics scheme; specifically, legacy code is removed and logic in the real program is improved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants