T_freeze for silver iodide - #502
Open
pdziekan wants to merge 4 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
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::AgIand implemented an AgI-basedT_freeze_CDF_invbranch (Omanovic et al. 2024-style logistic frozen-fraction fit). - Refactored
T_freeze_CDF_invto 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,
Ais computed with a CUDA-safe pi constant, but then the inverse-CDF uses a separate(4*pi*rd2_insol)term withpi<real_t>()unconditionally, andAis unused. This is easy to get wrong for NVCC and makes the expression harder to maintain. Also,std::maxin aBOOST_GPU_ENABLEDfunction doesn’t follow the project’s CUDA pattern (use unqualifiedmaxwith host-onlyusing 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::maxinside aBOOST_GPU_ENABLEDfunction. This is likely to break NVCC device compilation; elsewhere in the codebase GPU-enabled helpers call unqualifiedmaxand onlyusing std::maxfor 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_freezeis alsoBOOST_GPU_ENABLED, so thethrow std::runtime_error(...)statements here are not CUDA-safe and will likely fail device compilation; thereturn 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.