Skip to content

T_freeze for silver iodide - #502

Open
pdziekan wants to merge 4 commits into
igfuw:masterfrom
pdziekan:AgI_T_freeze
Open

T_freeze for silver iodide#502
pdziekan wants to merge 4 commits into
igfuw:masterfrom
pdziekan:AgI_T_freeze

Conversation

@pdziekan

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI lite review requested due to automatic review settings August 26, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends the common ice nucleation utilities by adding a new ice-nucleating particle (INP) type for silver iodide (AgI) and using it to compute singular freezing temperatures via an inverse-CDF parameterization, alongside the existing mineral-dust pathway.

Changes:

  • Added INP_t::AgI and implemented an AgI-based T_freeze_CDF_inv branch (Omanovic et al. 2024-style logistic frozen-fraction fit).
  • Refactored T_freeze_CDF_inv to clamp freezing temperatures to a homogeneous-freezing floor.
  • Added an explicit AgI branch in p_freeze (currently unimplemented).
Suppressed comments (3)

include/libcloudph++/common/ice_nucleation.hpp:56

  • In the mineral branch, A is computed with a CUDA-safe pi constant, but then the inverse-CDF uses a separate (4*pi*rd2_insol) term with pi<real_t>() unconditionally, and A is unused. This is easy to get wrong for NVCC and makes the expression harder to maintain. Also, std::max in a BOOST_GPU_ENABLED function doesn’t follow the project’s CUDA pattern (use unqualified max with host-only using std::max;).
            const real_t A = real_t(4)
            #if !defined(__NVCC__)
                * pi<real_t>()
            #else 
                * CUDART_PI
            #endif
            * rd2_insol; // surface area of the insoluble particle

            const real_t Niemand_T_freeze = real_t(real_t(273.15) + (real_t(8.934) - log(- log(real_t(1.) - rand) / (real_t(4) * pi<real_t>() * rd2_insol)) ) / real_t(0.517));
            return std::max(real_t(T_homo / si::kelvin), Niemand_T_freeze) * si::kelvin;

include/libcloudph++/common/ice_nucleation.hpp:65

  • The AgI branch still uses std::max inside a BOOST_GPU_ENABLED function. This is likely to break NVCC device compilation; elsewhere in the codebase GPU-enabled helpers call unqualified max and only using std::max for host builds.
            if(rand > Omanovic_b) return T_homo;
            const real_t Omanovic_T_freeze = real_t(Omanovic_T0/ si::kelvin) - (real_t(1.) / Omanovic_k) * log((real_t(1.) - rand) / (Omanovic_b - real_t(1.) + rand));
            return std::max(real_t(T_homo / si::kelvin), Omanovic_T_freeze) * si::kelvin;
            break;

include/libcloudph++/common/ice_nucleation.hpp:131

  • p_freeze is also BOOST_GPU_ENABLED, so the throw std::runtime_error(...) statements here are not CUDA-safe and will likely fail device compilation; the return 0; after each throw is unreachable anyway. If AgI time-dependent freezing isn’t implemented yet, returning 0 (and possibly leaving a TODO) keeps GPU builds working.
          else if (INP_type == INP_t::AgI)
          {
            throw std::runtime_error("AgI time-dependent freezing not implemented yet");
            return 0;
          }
          else
          {
            throw std::runtime_error("Unrecognized INP type");
            return 0;
          }

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +30 to +38
static constexpr quantity<si::temperature, real_t> T_homo = real_t(235.15) * si::kelvin;
// static constexpr quantity<si::temperature, real_t> Niemand_T_min = real_t(273.15 - 36) * si::kelvin;
// static constexpr quantity<si::temperature, real_t> Niemand_T_max = real_t(273.15 - 12) * si::kelvin;
static constexpr quantity<si::dimensionless, real_t> Omanovic_b = 0.97;
static constexpr quantity<si::dimensionless, real_t> Omanovic_k = 0.88;
static constexpr quantity<si::temperature, real_t> Omanovic_T0 = real_t(263.95) * si::kelvin;

if(rd2_insol < 1e-20) return T_homo;

Comment on lines +67 to +68
default:
throw std::runtime_error("Unrecognized INP type");
Comment on lines +43 to +44
// Shima et al. 2020 (and many others): p(T_f > T) = 1 - exp(A * ns(T))
// Niemand et al. 2012 for mineral dust: ns(T) = exp(-0.517(T - 273.15) + 8.934) [m^-2]
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.

2 participants