Skip to content

Commit d1cc99e

Browse files
authored
Merge pull request #391 from pdziekan/blk_2m_p_prof
blk_2m: option to pass pressure to rhs_Cellwise
2 parents 64821c4 + 67f1f96 commit d1cc99e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

include/libcloudph++/blk_2m/rhs_cellwise.hpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <libcloudph++/blk_2m/extincl.hpp>
1111

1212
#include <libcloudph++/common/theta_dry.hpp>
13+
#include <libcloudph++/common/theta_std.hpp>
1314

1415
namespace 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;

models/kinematic_2D/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ find_package(libmpdata++)
3030

3131
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
3232
# make the Release flags the default
33-
set(CMAKE_CXX_FLAGS ${libmpdataxx_CXX_FLAGS_RELEASE})
33+
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}${libmpdataxx_CXX_FLAGS_RELEASE})
3434
# ignore CMake defaults
3535
set(CMAKE_CXX_FLAGS_RELEASE "")
3636
else()

0 commit comments

Comments
 (0)