1010#include < libcloudph++/blk_2m/extincl.hpp>
1111
1212#include < libcloudph++/common/theta_dry.hpp>
13+ #include < libcloudph++/common/theta_std.hpp>
1314
1415namespace libcloudphxx
1516{
@@ -26,13 +27,15 @@ namespace libcloudphxx
2627 cont_t &dot_rr_cont,
2728 cont_t &dot_nr_cont,
2829 const cont_t &rhod_cont,
29- const cont_t &th_cont,
30+ const cont_t &th_cont, // dry potential temperature (if const_p == false) or "standard" potential temperature (if const_p == true)
3031 const cont_t &rv_cont,
3132 const cont_t &rc_cont,
3233 const cont_t &nc_cont,
3334 const cont_t &rr_cont,
3435 const cont_t &nr_cont,
35- const real_t &dt
36+ const real_t &dt,
37+ const bool const_p = false , // is pressure constant (e.g. anelastic approximation on UWLCM)?
38+ const cont_t &p_cont = cont_t () // pressure, required if const_p == true
3639 )
3740// </listing>
3841 {
@@ -43,10 +46,13 @@ namespace libcloudphxx
4346 assert (min (rr_cont) >= 0 );
4447 assert (min (nc_cont) >= 0 );
4548 assert (min (nr_cont) >= 0 );
49+ assert (!const_p || p_cont.size () == th_cont.size ());
50+ assert (!const_p || min (p_cont) > 0 );
4651
4752 using namespace formulae ;
4853 using namespace common ::moist_air;
4954 using namespace common ::theta_dry;
55+ using namespace common ::theta_std;
5056
5157 for (auto tup : zip (
5258 dot_th_cont,
@@ -61,7 +67,8 @@ namespace libcloudphxx
6167 rc_cont,
6268 nc_cont,
6369 rr_cont,
64- nr_cont
70+ nr_cont,
71+ p_cont // NOTE: for const_p == false, is zipping an empty p_cont safe?
6572 ))
6673 {
6774 real_t
@@ -86,8 +93,19 @@ namespace libcloudphxx
8693 const quantity<divide_typeof_helper<si::dimensionless, si::mass>::type, real_t > nr_dim = nr / si::kilograms;
8794
8895 // helper temperature and pressure
89- const quantity<si::temperature, real_t > T = common::theta_dry::T<real_t >(th, rhod);
90- const quantity<si::pressure, real_t > p = common::theta_dry::p<real_t >(rhod, rv, T);
96+ quantity<si::temperature, real_t > T;
97+ quantity<si::pressure, real_t > p;
98+
99+ if (!const_p)
100+ {
101+ T = common::theta_dry::T<real_t >(th, rhod);
102+ p = common::theta_dry::p<real_t >(rhod, rv, T);
103+ }
104+ else
105+ {
106+ p = std::get<13 >(tup) * si::pascals;
107+ T = th * common::theta_std::exner (p);
108+ }
91109
92110 // rhs only due to rhs_cellwise microphysics functions (needed for limiting)
93111 real_t local_dot_rc = 0 ,
@@ -180,7 +198,10 @@ namespace libcloudphxx
180198 }
181199
182200 dot_rv -= (local_dot_rc + local_dot_rr);
183- dot_th -= (local_dot_rc + local_dot_rr) * d_th_d_rv<real_t >(T, th) / si::kelvins;
201+ if (!const_p)
202+ dot_th -= (local_dot_rc + local_dot_rr) * d_th_d_rv<real_t >(T, th) / si::kelvins;
203+ else
204+ dot_th += common::const_cp::l_v (T) / (common::moist_air::c_pd<real_t >() * common::theta_std::exner (p)) * (local_dot_rc + local_dot_rr) / si::kelvins;
184205 dot_rc += local_dot_rc;
185206 dot_rr += local_dot_rr;
186207 dot_nc += local_dot_nc;
0 commit comments