Skip to content

Commit

Permalink
cleaning up the code
Browse files Browse the repository at this point in the history
  • Loading branch information
AgnieszkaMakulska committed Jan 13, 2025
1 parent d75bf4c commit 136eeaa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 54 deletions.
51 changes: 5 additions & 46 deletions include/libcloudph++/blk_1m/formulae.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ namespace libcloudphxx
const quantity<si::dimensionless, real_t> rc_thresh,
const quantity<si::frequency, real_t> k_autoconv
) {
// if (rc <= real_t(0))
// {
// return real_t(0) / si::seconds;
// }
return k_autoconv * std::max(real_t(0) * si::dimensionless(), rc - rc_thresh);
}

Expand All @@ -42,10 +38,6 @@ namespace libcloudphxx
const quantity<si::dimensionless, real_t> &rc,
const quantity<si::dimensionless, real_t> &rr
) {
// if (rr <= real_t(0) || rc <= real_t(0))
// {
// return real_t(0) / si::seconds;
// }
return k_2<real_t>() * rc * std::pow(rr, real_t(.875));
}

Expand All @@ -59,10 +51,6 @@ namespace libcloudphxx
quantity<si::mass_density, real_t> rhod,
quantity<si::pressure, real_t> p
) {
// if (rr <= real_t(0))
// {
// return real_t(0) / si::seconds;
// }
return
(1 - rv / rvs) / rhod
* (
Expand Down Expand Up @@ -129,10 +117,6 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::mass_density, real_t> &rhod_0
) {
if (ria <= real_t(0))
{
return real_t(0) * si::kilograms;
}
using namespace common;
real_t tempc = T / si::kelvin - real_t(273.16);
real_t IWC = std::max(real_t(1.e-9) * si::dimensionless(), rhod_0 / si::kilograms * si::cubic_meters * ria);
Expand Down Expand Up @@ -164,12 +148,8 @@ namespace libcloudphxx
const quantity<si::dimensionless, real_t> &ria,
const quantity<si::mass_density, real_t> &rhod_0
) {
if (ria <= real_t(0))
{
return real_t(0) * si::meters/ si::seconds;
}
using namespace common;
real_t IWC = std::max(real_t(1.e-9) * si::dimensionless(), rhod_0 / si::kilograms * si::cubic_meters * ria);
real_t IWC = std::max(real_t(1.e-9) * si::dimensionless(), rhod_0 * ria / si::kilograms * si::cubic_meters);
real_t IWCS = std::min(std::min(real_t(1.e-3), IWC), real_t(2.52e-4)*std::pow((IWC/real_t(1.e-3)), real_t(0.837)));
real_t IWCL = std::max(real_t(1.e-9), IWC - IWCS);
//velocity of small ice A particle:
Expand Down Expand Up @@ -197,7 +177,6 @@ namespace libcloudphxx
return std::pow(pi<real_t>() * rho_ib<real_t>() * N_0b / (rhod_0 * rib), real_t(0.25)) / si::meters;
}


// mean mass of ice B particle
// eq. A.5 in Grabowski 1999
template <typename real_t>
Expand All @@ -223,7 +202,7 @@ namespace libcloudphxx
) {
if (rib <= real_t(0))
{
return real_t(0) * si::meters/ si::seconds;
return real_t(0) * si::meters / si::seconds;
}
return real_t(31.2) *
std::pow(lambda_ice_b(rib, rhod_0) * si::meters, real_t(-0.37)) * std::pow(
Expand Down Expand Up @@ -292,10 +271,6 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::time, real_t> &dt
) {
if (rv <= real_t(0))
{
return real_t(0) / si::seconds;
}
const quantity<si::time, real_t> taunuc = dt; // timescale for nucleation
real_t beta = (T > real_t(213.16) * si::kelvins)
? real_t(0.1) + real_t(0.9) * (T - real_t(213.16) * si::kelvins) / (real_t(20) * si::kelvins)
Expand All @@ -315,10 +290,6 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::time, real_t> &dt
) {
if (rc <= real_t(0))
{
return real_t(0) / si::seconds;
}
const quantity<si::time, real_t> taunuc = dt; // time scale for nucleation
//homogeneous nucleation rate (only if T < -40 C)
return (T < real_t(233.16) * si::kelvins)
Expand Down Expand Up @@ -363,7 +334,7 @@ namespace libcloudphxx
const quantity<si::mass_density, real_t> &rhod_0
) {
using namespace common;
if (ria <= real_t(1e-10) || rr <= real_t(0) || T > real_t(273.16) * si::kelvins) // ice B is formed only if ice A and rain are present
if (ria <= real_t(0) || rr <= real_t(0) || T > real_t(273.16) * si::kelvins) // ice B is formed only if ice A and rain are present
{
return real_t(0) / si::seconds;
}
Expand Down Expand Up @@ -398,7 +369,7 @@ namespace libcloudphxx
const quantity<si::mass_density, real_t> &rhod_0
) {
using namespace common;
if (ria <= real_t(1e-10) || rr <= real_t(0) || T > real_t(273.16) * si::kelvins) // ice B is formed only if ice A and rain are present
if (ria <= real_t(0) || rr <= real_t(0) || T > real_t(273.16) * si::kelvins) // ice B is formed only if ice A and rain are present
{
return real_t(0) / si::seconds;
}
Expand Down Expand Up @@ -447,8 +418,6 @@ namespace libcloudphxx
//melting rate:
real_t dma_dt = real_t(9.e-7) * D_a / real_t(2) / si::meters * F_a * std::max(real_t(0) * si::dimensionless(), T / si::kelvins - real_t(273.16) * si::dimensionless());
return std::min(ria / dt * si::seconds, dma_dt * ria / m_a * si::kilograms) / si::seconds;
//return real_t(4.5e-7) * ria /
// m_a * D_a * (T / si::kelvins - real_t(273.16)) * F_a * si::kilograms / si::meters / si::seconds;
}

//melting of ice B (rib -> rr)
Expand Down Expand Up @@ -480,8 +449,6 @@ namespace libcloudphxx
//melting rate
real_t dmb_dt = real_t(9.e-7) * D_b / real_t(2) / si::meters * F_b * std::max(real_t(0) * si::dimensionless(), T / si::kelvins - real_t(273.16) * si::dimensionless());
return std::min(rib / dt * si::seconds, dmb_dt * rib / m_b * si::kilograms) / si::seconds;
//return real_t(4.5e-7) * rib /
// m_b * D_b * (T / si::kelvins - real_t(273.16)) * F_b * si::kilograms / si::meters / si::seconds;
}


Expand Down Expand Up @@ -523,7 +490,7 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::mass_density, real_t> &rhod_0
) {
if (ria <= real_t(1e-10) || rc <= real_t(0) || T > real_t(273.16) * si::kelvins)
if (ria <= real_t(0) || rc <= real_t(0) || T > real_t(273.16) * si::kelvins)
{
return real_t(0) / si::seconds;
}
Expand Down Expand Up @@ -645,10 +612,6 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::mass_density, real_t> &rhod_0
) {
if (rc <= real_t(0))
{
return real_t(0) / si::seconds;
}
real_t coeff_rc = rc / (rc + rr + real_t(1e-10));
return coeff_rc * riming_B(rib, rc, rv, rvs, rvsi, T, rhod_0);
}
Expand All @@ -666,10 +629,6 @@ namespace libcloudphxx
const quantity<si::temperature, real_t> &T,
const quantity<si::mass_density, real_t> &rhod_0
) {
if (rr <= real_t(0))
{
return real_t(0) / si::seconds;
}
real_t coeff_rc = rc / (rc + rr + real_t(1e-10));
return (real_t(1) - coeff_rc) * riming_B(rib, rc, rv, rvs, rvsi, T, rhod_0);
}
Expand Down
2 changes: 1 addition & 1 deletion include/libcloudph++/blk_1m/rhs_cellwise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace libcloudphxx
);

// limiting
rr_to_rv = std::min(std::max(real_t(0),rr) / dt, rr_to_rv);
rr_to_rv = std::min(rr / dt, rr_to_rv);

dot_rv += rr_to_rv;
dot_rr -= rr_to_rv;
Expand Down
14 changes: 7 additions & 7 deletions tests/python/unit/blk_1m_ice.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
ria += dt * dot_ria
rib += dt * dot_rib

assert rv >= 0
assert rc >= 0
assert rr >= 0
assert ria >= 0
assert rib >= 0

print('dot_rv='+str(dot_rv))
print('dot_rc='+str(dot_rc))
print('dot_rr='+str(dot_rr))
Expand All @@ -56,4 +50,10 @@
print('rib='+str(rib))
print('rain_flux='+str(flux_rain))
print('iceA_flux='+str(flux_iceA))
print('iceB_flux='+str(flux_iceB))
print('iceB_flux='+str(flux_iceB))

assert rv >= 0
assert rc >= 0
assert rr >= 0
assert ria >= 0
assert rib >= 0

0 comments on commit 136eeaa

Please sign in to comment.