Skip to content

Conversation

@katsmith133
Copy link

@katsmith133 katsmith133 commented Sep 16, 2025

Adds a global constants header file with many commonly used physical constants and conversion factors, and replaces uses of Gravity, Pi, and Pa2Dbar in several files. This is a temporary solution for a consolidated constants file (brough up in #179), to be replaced when a shared E3SM constants file becomes available. Values are a combination of what is in https://github.com/E3SM-Project/E3SM/blob/09b9b7e21e3d381eafa962e178a5951580e2fc74/share/util/shr_const_mod.F90 and https://github.com/E3SM-Project/Omega/blob/develop/components/mpas-ocean/src/shared/mpas_ocn_constants.F. Making the assumption that those are the agreed upon values we want to use (please correct me if I am wrong or if we want to add additional/remove unnecessary values).

Passes CTests on pm-cpu, pm-gpu, and frontier. Note: There is currently no documentation that goes with this PR and no new Ctests were added (though I am happy to add those if we think they are valuable).

Checklist

  • Building
    • CMake build does not produce any new warnings from changes in this PR
  • Testing
    • A comment in the PR documents testing used to verify the changes including any tests that are added/modified/impacted.
    • Unit tests have passed. Please provide a relevant CDash build entry for verification.

Copy link

@philipwjones philipwjones left a comment

Choose a reason for hiding this comment

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

This is mostly fine. I have one needed change and two suggestions that others can weigh in on:

  • this fails Ctests for the three Tendency tests (TEND_SPHERE, TEND_PLANE, TEND_PLANE_SINGLE_PRECISION), probably due to roundoff-level changes in expected results. So we either need to look into that or modify the expected values appropriately
  • it might be good to have a Pi2 = 2.0*Pi since that combination is very common
  • should we declare these as Real rather than double? When running in single-precision mode, this would prevent any extra conversions/truncations during computations

@sbrus89
Copy link

sbrus89 commented Sep 17, 2025

I think defining them as Real is a good idea. I talked about this a bit with @rljacob. Once the universal constants file is merged to E3SM, we can include it in this header and type cast variables to the Omega Real type (and rename variables).

@katsmith133 katsmith133 force-pushed the omega/add-global-constants branch from 20c1823 to 4581cfd Compare September 18, 2025 16:36
@katsmith133
Copy link
Author

katsmith133 commented Sep 18, 2025

This is mostly fine. I have one needed change and two suggestions that others can weigh in on:

  • this fails Ctests for the three Tendency tests (TEND_SPHERE, TEND_PLANE, TEND_PLANE_SINGLE_PRECISION), probably due to roundoff-level changes in expected results. So we either need to look into that or modify the expected values appropriately
  • it might be good to have a Pi2 = 2.0*Pi since that combination is very common
  • should we declare these as Real rather than double? When running in single-precision mode, this would prevent any extra conversions/truncations during computations

Thanks, @philipwjones and @sbrus89!

Fixed the failed CTests. (I missed some hardcoded 9.8###s in those tests)
Added in TwoPi = 2 * Pi.
Declared as Real.
Rebased and replaced a few more constants in the code.
Note: I updated Pi = M_PI... if we don't like that, let me know. Or if we don't like the name I've chosen for any of the constants, I'm happy to change them.

Removing the "Draft" label from this PR now that the tests are fixed and the VertCoord has gone in.

@katsmith133 katsmith133 marked this pull request as ready for review September 18, 2025 16:42
Copy link

@philipwjones philipwjones left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. I verified it passes Ctests now. You could still propagate the new TwoPi into ManufacturedSolution, but I'll go ahead and approve this.

@brian-oneill
Copy link

Looks good. Ran the ctests successfully on chrysalis.

@katsmith133
Copy link
Author

Question for the reviewers (@philipwjones, @sbrus89, @brian-oneill, @xylar, @mwarusz)... do we want to add things like SqrtTwo = 1.4142135623730951 or SqrtThree = 1.7320508075688772, like they are planning to add in the universal constants file (E3SM-Project#7719), and thus we can just replace the value here with that once it goes through and its consistent with the rest of E3SM? Or do we want to stick with the Kokkos::sqrt(2) option?

@philipwjones
Copy link

The hard requirement is that any quantity shared with other components should use common constants so that any quantities are calculated consistently. If we want to be safe, we should probably use all available constants from the shared constants file but we'll need to be sure to use them correctly in Kokkos kernels.

Copy link

@xylar xylar left a comment

Choose a reason for hiding this comment

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

This looks good to me. I think it will provide a great place for the shared constants to plug in in the near future.

@xylar
Copy link

xylar commented Oct 10, 2025

Actually, now that E3SM-Project#7719 has been merged, do we want to make use of that here? Or do we want to follow up later?

@xylar
Copy link

xylar commented Oct 10, 2025

Presumably, the answer is later because this has already been stale awhile.

Copy link

@sbrus89 sbrus89 left a comment

Choose a reason for hiding this comment

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

This looks great. Thanks @katsmith133!

@xylar
Copy link

xylar commented Nov 3, 2025

I'm sorry to sneak in a last-minute request for this branch, but could we change:

Err += TendConfig->get("Density0", this->WindForcing.SaltWaterDensity);

to use RhoSw instead of the Density0 config option?

Density0 is also used for the computation of the pseudo-height in the vertical coordinate and I think that should be the only use of Density0. (I'll follow up elsewhere to hopefully improve the commenting related to that config option.)

See #312

@katsmith133
Copy link
Author

@xylar I will update this PR so that its not stale, and then include E3SM-Project#7719 and your suggestion for RhoSw in an update shortly. Thanks!

@katsmith133 katsmith133 force-pushed the omega/add-global-constants branch from 86d3678 to 8605f34 Compare November 6, 2025 21:50
@katsmith133
Copy link
Author

@xylar please let me know if this covers the changes you requested:

(1) changed it so that Tendencies.cpp uses RhoSw from GlobalConstants.h, instead of Density0 in Config.yml
(2) moved Density0 to VertCoord in Config.yml
(3) Included pcd_const.h from E3SM-Project#7719 into setting relevant constants in GlobalConstants.h (and as a part of this I had to update some tests that used the Earth's radius, as the one in pcd_const.h was just ever so slightly different)

And @sbrus89, @philipwjones, @brian-oneill, and @mwarusz, if you could all take one last look at this now that's I've made a few more changes, that would be great!

It compiles and runs on pm-cpu and pm-gpu.

@xylar
Copy link

xylar commented Nov 7, 2025

@katsmith133, yes, these changes look excellent to me!

@philipwjones
Copy link

Looks fine to me and verified Ctests on Frontier cpu/gpu

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants