Skip to content

sima0_13_001: Fix crash in get_hydrostatic_energy due to thermodynamically active species subsetting#481

Merged
jimmielin merged 1 commit intoESCOMP:developmentfrom
jimmielin:hplin/thermo_idx_fix
Mar 23, 2026
Merged

sima0_13_001: Fix crash in get_hydrostatic_energy due to thermodynamically active species subsetting#481
jimmielin merged 1 commit intoESCOMP:developmentfrom
jimmielin:hplin/thermo_idx_fix

Conversation

@jimmielin
Copy link
Copy Markdown
Member

@jimmielin jimmielin commented Mar 20, 2026

Tag name (required for release branches): sima0_13_001
Originator(s): @jimmielin

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

This happens because CAM-SIMA over-allocates thermodynamic_active_species_idx to 0:num_advected instead of the "true" number of thermodynamically active species

      allocate(thermodynamic_active_species_idx(0:num_advected), stat=ierr, errmsg=errmsg)

this is because the list is constructed at runtime in CAM-SIMA in air_composition.F90, only the actual number of thermodynamically active species is populated, the rest is -huge(1)

      thermodynamic_active_species_idx        = -HUGE(1)
      thermodynamic_active_species_idx_dycore = -HUGE(1)
      ! add prognostic components of air
...
      icnst = 1
      water_species_num = 0
      dry_species_num = 0
      do idx = 1, num_advected
...
         select case (TRIM((cnst_stdname)))
...
            thermodynamic_active_species_idx(icnst) = ix
...
         case default
            cycle ! skip thermodynamically inactive species
         end select
...
      water_species_in_air_num = water_species_num
      dry_air_species_num = dry_species_num
      thermodynamic_active_species_num = water_species_num + dry_species_num

      allocate(thermodynamic_active_species_liq_idx(liq_num), stat=ierr)
      call check_allocate(ierr, subname,'thermodynamic_active_species_liq_idx(liq_num)', &
                          file=__FILE__, line=__LINE__)
      allocate(thermodynamic_active_species_liq_idx_dycore(liq_num), stat=ierr)
      call check_allocate(ierr, subname,'thermodynamic_active_species_liq_idx_dycore(liq_num)', &
                          file=__FILE__, line=__LINE__)
      allocate(thermodynamic_active_species_ice_idx(ice_num), stat=ierr)
      call check_allocate(ierr, subname,'thermodynamic_active_species_ice_idx(ice_num)', &
                          file=__FILE__, line=__LINE__)
      allocate(thermodynamic_active_species_ice_idx_dycore(ice_num), stat=ierr)

you can see how the liq and ice indices are correctly-sized from the start, so the subsetting only needs to happen in thermodynamic_active_species_idx_dycore.

There is no bug in CAM because CAM correctly allocates the array at start

      isize = dry_air_species_num + water_species_in_air_num
      allocate(thermodynamic_active_species_idx(isize), stat=ierr)

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/data/cam_thermo.F90

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?

derecho/intel/aux_sima:

  SMS_Ln9.ne3pg3_ne3pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam_multitape (Overall: NLFAIL) details:
    FAIL SMS_Ln9.ne3pg3_ne3pg3_mg37.FKESSLER.derecho_intel.cam-outfrq_se_cslam_multitape NLCOMP
  - pre-existing failure

derecho/gnu/aux_sima:

  SMS_Ln9.ne3pg3_ne3pg3_mg37.FADIAB.derecho_gnu.cam-outfrq_se_cslam (Overall: DIFF) details:
    FAIL SMS_Ln9.ne3pg3_ne3pg3_mg37.FADIAB.derecho_gnu.cam-outfrq_se_cslam BASELINE /glade/campaign/cesm/community/amwg/sima_baselines/latest_gnu: ERROR BFAIL some baseline files were missing
  - pre-existing failure that randomly works (suspect test)

derecho/nvhpc/aux_sima: All PASS

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

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

@jimmielin jimmielin self-assigned this Mar 20, 2026
@jimmielin jimmielin added the bug-fix This PR was created to fix a specific bug. label Mar 20, 2026
@jimmielin jimmielin temporarily deployed to CI-tests-on-CIRRUS March 20, 2026 14:13 — with GitHub Actions Inactive
@jimmielin jimmielin requested review from nusbaume and peverwhee March 23, 2026 15:48
Copy link
Copy Markdown
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jimmielin!

@jimmielin
Copy link
Copy Markdown
Member Author

Somehow the SMS_Ln9.ne3pg3_ne3pg3_mg37.FADIAB.derecho_gnu.cam-outfrq_se_cslam test started working (despite the existing-test-failures.txt entry) after 2 retries. For this reason, I will make a new SIMA tag for this. But I will keep the existing test failure as I feel the right solution will be in the SE dycore PR.

@jimmielin jimmielin changed the title Fix crash in get_hydrostatic_energy due to thermodynamically active species subsetting sima0_13_001: Fix crash in get_hydrostatic_energy due to thermodynamically active species subsetting Mar 23, 2026
@jimmielin jimmielin merged commit af4b3e8 into ESCOMP:development Mar 23, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix This PR was created to fix a specific bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants