Skip to content

Avoid division by zero in cloud fraction calculation - #1526

Merged
mgduda merged 1 commit into
MPAS-Dev:developfrom
jihyeonjang:fix_cloud_fraction
Nov 2, 2026
Merged

mgduda merged 1 commit into
MPAS-Dev:developfrom
jihyeonjang:fix_cloud_fraction

Conversation

@jihyeonjang

@jihyeonjang jihyeonjang commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

The original cloud fraction calculation (calc_cldfraction) can produce a zero denominator when the saturation vapor pressure reaches the atmospheric pressure, which can happen in the upper atmosphere.

qvsw = ep_2 * esw / (pres_p(i,k,j) - esw)
qvsi = ep_2 * esi / (pres_p(i,k,j) - esi)

For runs with a high model top (e.g., around 70 km or higher), this can cause the model to stop, especially when compiled with DEBUG=true. The error messages are:

Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation.
Backtrace for this error:
#1  0xeb5531 in calc_cldfraction
    at PATH/MPAS-Model/src/core_atmosphere/physics/mpas_atmphys_driver_cloudiness.F:332

This PR makes two changes:

  1. skip saturation calculations when the cloud condensate (qc+qi+qs) is below qcldmin, since the cloud fraction is zero there;
  2. limit saturation vapor pressures over water and ice to 99% of the air pressure, as in the WSM6 microphysics scheme, to avoid division by zero and negative saturation mixing ratios.

Thanks to Song-You Hong (@Songyou184) for identifying the issue.

The original cloud fraction calculation (calc_cldfraction) can divide by
zero when the saturation vapor pressure reaches or exceeds the atmospheric
pressure, which can happen in the upper atmosphere. This can stops runs
compiled with DEBUG=true.

This commit makes two changes: 1) skip saturation calculations when
the cloud condensate (qc+qi+qs) is below qcldmin, since the cloud
fraction is zero there; 2) limit saturation vapor pressures over water
and ice to 99% of the air pressure, as in the WSM6 microphysics scheme,
to avoid division by zero and negative saturation mixing ratios.

@dudhia dudhia 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.

Looks acceptable. The pressure limit alone would have solved the problem.

@jihyeonjang

Copy link
Copy Markdown
Collaborator Author

Thank you for reviewing this PR, Jimy!

Agreed, the pressure limit alone would solve it. However, the first change is not new logic. The qcldmin check was already in the subroutine, just further down. Moving it to the beginning means we can skip computing qvsw and qvsi at no-cloud points, which avoids unnecessary calculations.

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.

3 participants