Skip to content

merge new clubb_mf into cam6_4_203 - #1576

Open
jtruesdal wants to merge 63 commits into
ESCOMP:cam_developmentfrom
jtruesdal:clubbdev
Open

jtruesdal wants to merge 63 commits into
ESCOMP:cam_developmentfrom
jtruesdal:clubbdev

Conversation

@jtruesdal

@jtruesdal jtruesdal commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

This PR merges updated CLUBB+MF (clubb-mf) changes into CAM, extending the CLUBB interface to support the enhanced integrate_mf call, adding new EDMF diagnostics/outputs, and introducing additional namelist controls for CLUBB+MF behavior (radiation coupling, microphysics, TKE contribution, etc.).

Changes:

  • Expanded clubb_intr.F90 CLUBB+MF interface: new pbuf fields, history coords, diagnostic outputs, and enhanced MF plumbing.
  • Added new CLUBB+MF namelist entries + defaults, and wired them into build-namelist.

The majority of the code updates reside in clubb_mf.F90. In addition to the new science, clubb_mf is now agnostic to the direction of the vertical level, adjusting the looping and indexes as needed depending on the top down or bottom up nature of the input arrays. Additionally the number of vertical levels for the new mf arrays are consistent with their associated thermodynamic or momentum grid. There are order of operation differences between this update and Adam's original cam6_4_124 version of clubb_mf which cause roundoff precision differences from the base code. On top of these roundoff differences there are bug fixes which are answer changing.

This PR closes #1370

jtruesdal and others added 2 commits June 9, 2026 09:08
…rations on several variables with latest clubb interface and externals.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR merges updated CLUBB+MF (clubb-mf) changes into CAM, extending the CLUBB interface to support the enhanced integrate_mf call, adding new EDMF diagnostics/outputs, and introducing additional namelist controls for CLUBB+MF behavior (radiation coupling, microphysics, TKE contribution, etc.).

Changes:

  • Expanded clubb_intr.F90 CLUBB+MF interface: new pbuf fields, history coords, diagnostic outputs, and enhanced MF plumbing.
  • Added new CLUBB+MF namelist entries + defaults, and wired them into build-namelist.
  • Updated COSP namelist documentation text (but introduced encoding issues that need correction).

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 18 comments.

File Description
src/physics/cam/clubb_intr.F90 Adds/updates CLUBB+MF fields, diagnostics, and MF integration interface wiring.
bld/namelist_files/namelist_definition.xml Adds new CLUBB+MF namelist definitions and edits COSP localtime documentation.
bld/namelist_files/namelist_defaults_cam.xml Adds default values for the new CLUBB+MF namelist entries.
bld/build-namelist Adds add_default(...) plumbing for (most) new CLUBB+MF namelist variables.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread bld/namelist_files/namelist_definition.xml Outdated
Comment thread bld/namelist_files/namelist_definition.xml Outdated
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_defaults_cam.xml Outdated
Comment thread bld/build-namelist Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90
Comment thread src/physics/cam/clubb_intr.F90
Comment thread src/physics/cam/clubb_mf.F90

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 14 comments.

Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread bld/namelist_files/namelist_definition.xml
Comment thread src/physics/cam/clubb_intr.F90 Outdated
@cacraigucar
cacraigucar marked this pull request as ready for review June 23, 2026 16:47
@adamrher
adamrher self-requested a review August 31, 2026 16:08

@adamrher adamrher left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving this provided @jtruesdal merges my PR to this PR branch.

@cacraigucar cacraigucar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am submitting this. I still have clubb_mf.F90 to review, but that will need to be next week.

Comment thread bld/namelist_files/namelist_defaults_cam.xml Outdated
Comment thread bld/namelist_files/namelist_definition.xml Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
#endif

! CFL limiter vars
real(r8), parameter :: cflval = 1._r8

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this is a parameter constant, it would be good to have a comment on what it is

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"Upper limit on Courant number for stability"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/physics/cam/clubb_intr.F90 Outdated
@@ -2726,6 +2991,33 @@ subroutine clubb_tend_cam( state, ptend_all, pbuf, hdtime, &
! Initialize err_info with parallelization and geographical info
call init_err_info_api(ncol, lchnk, iam, state_loc%lat*rad2deg, state_loc%lon*rad2deg, err_info)


if (do_clubb_mf) then
! SVP

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What does this comment mean? If it is just someone's initials, please replace with a comment on what this block is doing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This has since been moved into clubb_mf.F90, and the SVP comment was removed (which referred to saturation vapor pressure; the abbreviation is used elsewhere in comments in our code).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

New comment with words not initials.

Comment thread bld/namelist_files/namelist_definition.xml
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90 Outdated
Comment thread src/physics/cam/clubb_intr.F90

@cacraigucar cacraigucar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I stopped reviewing at line 2709 in clubb_mf.F90 as the routines from this point to the end of the file appear to be copies which are better addressed with the new issue of opening a shared library location in ESCOMP/atmopsheric_physics for these routines. The code from line 2709 to the end of file is not in shape that it should reside in ESCOMP/CAM long-term. There is one possible copyright issue which does need to be addressed before this is committed in that section of the code.

Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment on lines +2412 to +2417
subroutine knuth(kiss_gen,lambda,kout)
!**********************************************************************
! Discrete random poisson from Knuth
! The Art of Computer Programming, v2, 137-138
! By Adam Herrington
!**********************************************************************

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@briandobbins - As we discussed, is there an open source version of this available?

Comment on lines +2442 to +2448
subroutine hormann(kiss_gen,lambda,kout)
!**********************************************************************
! Discrete random poisson
! Implements Poisson Transformed Rejection with Squeeze (PTRS)
! from W. Hormann Insurance: Mathematics and Economics 12, 39-45 (1993)
! By Jake Reschke
!**********************************************************************

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@briandobbins - Here is the other routine to find an open source version of

use shr_kind_mod, only: r8=>shr_kind_r8
use spmd_utils, only: masterproc
use cam_logfile, only: iulog
use cam_abortutils,only: endrun

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I asked Claude to summarize the shared routines I was seeing in this module. For the sake of this PR, let's open an issue to address this at a later date in ESCOMP/atmospheric_physics

Summary

Duplicated / adapted helper routines in clubb_mf.F90

Several helpers in clubb_mf.F90 are copied or adapted from existing code in the tree — uwshcu.F90 and the ZM scheme
src/atmos_phys/schemes/zhang_mcfarlane/zm_convr.F90.

Routine (clubb_mf.F90) Source Relationship
roots (L2495) uwshcu.F90:4728 Verbatim copy (cosmetic diffs only)
qsat_hPa (L3465) zm_convr.F90:2612 Verbatim copy (only kind_phys→r8)
entropy (L3336) zm_convr.F90:1467 Copy, constants renamed to physconst
ientropy (L3359) zm_convr.F90:1495 Copy of Brent-solver core; error handling swapped
buoyan_dilute (L2709) zm_convr.F90:778 Heavily adapted (not verbatim)
parcel_dilute (L2964) zm_convr.F90:1130 Heavily adapted (not verbatim)
enthalpy (L3483) (none in ZM) New, cloned from entropy
ienthalpy (L3502) (none in ZM) New, self-admitted clone of ientropy

Notes

  • qsat_hPa — byte-identical to ZM's version except the kind suffix (same qsat_water call, same p*100 / es*0.01
    conversions).
  • roots — near-verbatim copy of the uwshcu version; only whitespace/comment differences.
  • entropy / ientropy — same algorithm as ZM. ZM passes cpliq,cpwv,rh2o as args (CCPP) and uses ZM constant names (rl,
    tfreez, eps1, cpres, rgas); this copy uses physconst. ientropy's Brent loop is line-for-line identical; only the
    non-convergence path differs (ZM sets errmsg/errflg, this calls endrun).
  • buoyan_dilute / parcel_dilute — same dilute-CAPE algorithm, reworked from multi-column (ncol) to the single-column,
    nup-plume ensemble, made grid-orientation-agnostic, plus the tht_tweaks enthalpy path. Genuinely diverged — not a drop-in
    duplicate.
  • ienthalpy — per its own comment, "identical with iENTROPY, only function calls swapped": a second copy of the Brent
    solver within the same file. enthalpy is likewise a variant of entropy.

Suggested follow-ups (ranked)

  1. qsat_hPa — cleanest win; identical in two files. Hoist to a shared module and use it in both.
  2. ientropy / ienthalpy — collapse the two in-file Brent solvers into one (procedure arg or entropy-vs-enthalpy flag).
  3. entropy / ientropy vs ZM — shareable in principle, but CCPP-vs-endrun and constant-passing differences make it
    non-trivial; lower priority.

buoyan_dilute / parcel_dilute are diverged enough that keeping them independent is reasonable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@cacraigucar @jtruesdal I think I'd rather just remove all this duplicate ZM code entirely. These are used for the Lopt = 4,5 options, which I've never gotten to work properly. I can also just experiment with it on my branch.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@adamrher just to double check, remove lopt = 4,5 as possible options in the released code as well as
qsat_hPa, entropy, ientropy buoyan_dilute, parcel_dilute, enthalpy, ienthalpy routines?

Comment on lines +3525 to +3526
! Invert the entropy equation -- use Brent's method
! Brent, R. P. Ch. 3-4 in Algorithms for Minimization Without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@briandobbins - Here is another routine to see if an open source version exists

…o .gitmodules for updated interp_mod interface, will replace with new official tag once its passes regression testing.
@jtruesdal jtruesdal changed the title merge new clubb_mf into cam6_4_180 merge new clubb_mf into cam6_4_203 Sep 22, 2026
Comment thread .gitmodules
Comment on lines +46 to +49
url = https://github.com/jtruesdal/CAM_FV3_interface.git
fxrequired = AlwaysRequired
fxtag = fv3int_061924
fxDONOTUSEurl = https://github.com/ESCOMP/CAM_FV3_interface.git
fxtag = fv3int_092126
fxDONOTUSEurl = https://github.com/jtruesdal/CAM_FV3_interface.git

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs to become an official tag in the ESCOMP repo

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reminder. I will get this very minor change tagged in fv3 and include the official tag here. I just wanted to test it thoroughly first.

close(iunit)
end if

if (clubb_mf_Lopt < 0 .or. clubb_mf_Lopt > 8 ) &

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If option 4 and 5 get deleted, you will need to check that they are not set here

@cacraigucar cacraigucar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Resolved a number of conversations (and added a few more comments)

Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
Comment thread src/physics/cam/clubb_mf.F90 Outdated
ztopm1(:) = zm(ksfcm)
return

else ! we have positive surface buoyancy and moisture flux lets do mass-flux

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can eliminate this else (and the end if at the end of this routine). I don't have a strong preference that you need to shift the code over space wise if you do this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for resolving that makes it easier to see whats left.

I left the spacing so we don't have that show up in our diffs. I also changed the missed misspelling and made the logicals into parameters.

…up, new parameters for magic numbers, fix for out of bounds array access.

@cacraigucar cacraigucar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

resolved the changes that were made in the recently committed code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants