Skip to content

Fix hardcoded rair (287.04) in bulk and modal aerosol state modules (#542) - #551

Open
johnpaulalex wants to merge 3 commits into
ESCOMP:developmentfrom
johnpaulalex:fix-issue-542
Open

johnpaulalex wants to merge 3 commits into
ESCOMP:developmentfrom
johnpaulalex:fix-issue-542

Conversation

@johnpaulalex

@johnpaulalex johnpaulalex commented Sep 9, 2026 •

Copy link
Copy Markdown

Tag name (required for release branches): N/A
Originator(s): @johnpaulalex

AI tools used (if applicable; please also add the "AI-generated code" label to the PR):
What: Gemini 3.6 Flash
How: Assisted with repository audit, worktree creation, Fortran refactoring, test execution, and drafting PR documentation.

Description (include the issue title, and the keyword ['closes', 'fixes', 'resolves'] followed by the issue number):

Describe any changes made to build system: N/A

Describe any changes made to the namelist: N/A

List any changes to the defaults for the input datasets (e.g. boundary datasets): N/A

List all files eliminated and why: N/A

List all files added and what they do: N/A

List all existing files that have been modified, and describe the changes:
(Helpful git command: git diff --name-status development...<your_branch_name>)

M       src/aerosol/bulk_aerosol_state_mod.F90
  - Added `use physconst, only: rair` and replaced `287.04_r8` with `rair` in `surf_area_dens`.

M       src/aerosol/modal_aerosol_state_mod.F90
  - Added `rair` to `use physconst` import list and replaced `287.04_r8` with `rair` in `modal_aerosol_water_uptake`.

M       test/unit/fortran/src/aerosol/mock_physconst.F90
  - Added `rair = 287.04_r8` parameter to `mock_physconst` module for Fortran unit testing.

If there are new failures (compared to the test/existing-test-failures.txt file), have them OK'd by the gatekeeper, note them here, and add them to the file.
If there are baseline differences, include the test and the reason for the diff. What is the nature of the change? Roundoff?

  • Python unit tests (pytest test/unit/): 151 passed.
  • Note on local macOS unit test failure: test_bad_registry_xml fails when executed locally on macOS with libxml2 2.11+ due to xmllint omitting the element <name>: prefix in schema validation output. The test passes on HPC/Linux CI environments running libxml2 2.9.x.
  • Nature of change: Bit-for-bit expected (rair in physconst equals 287.04 J/kg/K via shr_const_rdair).

If this changes climate describe any run(s) done to evaluate the new climate in enough detail that it(they) could be reproduced: N/A

CAM-SIMA date used for the baseline comparison tests if different than latest: N/A

Replace hardcoded 287.04_r8 dry air gas constant literals in bulk_aerosol_state_mod.F90 and modal_aerosol_state_mod.F90 with rair imported from physconst.

Assisted-by: gemini-3.6-flash
@jimmielin

Copy link
Copy Markdown
Collaborator

Thanks @johnpaulalex for working on this issue!

With the abstract aerosol interface modules, we're trying to get rid (eventually) of all host model dependencies so it would be best if we threaded through rair from the caller side instead of use physconst, only: rair from within the modules. e.g., like how we do for pi

subroutine water_uptake_diag_i(aero_props, aero_state, ncol, nlev, top_lev, &
pi, rhoh2o, t, pmid, h2ommr, cldn, bin_idx, dgnumwet, qaerwat, errmsg, errflg)
import :: aerosol_properties, aerosol_state, r8
class(aerosol_properties), intent(in) :: aero_props
class(aerosol_state), intent(in) :: aero_state
integer, intent(in) :: ncol ! number of columns
integer, intent(in) :: nlev ! number of vertical levels
integer, intent(in) :: top_lev ! top level for aerosol calculations
real(r8), intent(in) :: pi ! pi

I realize that's a much bigger change surface as then it requires changes on the atmos_phys side, so we might want to survey the callers first and see how many call sites are needed for the paired ESCOMP/atmospheric_physics PR.

… physconst (ESCOMP#542)

Pass dry air gas constant (rair) as an intent(in) argument into aero_surf_area_dens and its implementations, removing 'use physconst' from aerosol state modules to decouple host-model dependencies.

Assisted-by: gemini-3.6-flash
@johnpaulalex

Copy link
Copy Markdown
Author

Hey @jimmielin makes sense. I updated the CAM-SIMA code...but I can't find any prod callers of the method, including in ESCOMP/atmospheric_physics: https://github.com/search?q=repo%3AESCOMP%2Fatmospheric_physics+surf_area_dens&type=code

...but that search did surface a seemingly relevant issue ESCOMP/atmospheric_physics#446, which sounds like it wants to use that function in the future...am I missing something?

@johnpaulalex

Copy link
Copy Markdown
Author

oh and the linter CI is failing but iiuc it's linting all lines, not just the deltas. lmk if there's something for me to fix here.

This branch is waiting to be deployed

1 waiting deployment
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.

2 participants