Skip to content

Commit 64821c4

Browse files
authored
Merge pull request #388 from pdziekan/cache_mfp
Cache mfp
2 parents 3f03972 + a423ab6 commit 64821c4

36 files changed

+484
-315
lines changed

.travis_scripts/cuda.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ cd build
66
#if [[ $TRAVIS_OS_NAME == 'linux' && $CXX == 'clang++' ]]; then cmake ../; fi
77
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then cmake .. -DPYTHON_LIBRARY=$PY_LIB -DPYTHON_INCLUDE_DIR=$PY_INC; fi
88
cmake -DCMAKE_BUILD_TYPE=Debug ../
9-
VERBOSE=1 travis_wait 20 make -j2
9+
#VERBOSE=1 travis_wait 20 make -j2
10+
VERBOSE=1 make -j2
1011
cmake -DCMAKE_BUILD_TYPE=Release ../
1112
VERBOSE=1 travis_wait 20 make -j2
1213
cd ../..

include/libcloudph++/blk_2m/activation_formulae.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace libcloudphxx
3636
const quantity<si::dimensionless, real_t> &chem_b,
3737
const quantity<si::dimensionless, real_t> beta = beta_default<real_t>()
3838
) {
39-
return pow(mean_rd / si::metres, -(1+beta)) * sqrt(4 * pow(common::kelvin::A<real_t>(T) / si::metres, 3) / 27 / chem_b);
40-
} // can't have pow<3/2>(si:: )
39+
return std::pow(mean_rd / si::metres, -(1+beta)) * std::sqrt(4 * std::pow(common::kelvin::A<real_t>(T) / si::metres, 3) / 27 / chem_b);
40+
} // can't have std::pow<3/2>(si:: )
4141

4242
// helper for activation formulae (see eq. 10 in Morrison and Grabowski 2007)
4343
template <typename real_t>
@@ -55,7 +55,7 @@ namespace libcloudphxx
5555
const quantity<si::dimensionless, real_t> &sdev_rd,
5656
const quantity<si::dimensionless, real_t> beta = beta_default<real_t>()
5757
) {
58-
return pow(sdev_rd, 1+beta);
58+
return std::pow(sdev_rd, 1+beta);
5959
}
6060

6161
//helper for activation formulae (see eq. 10 in Morrison and Grabowski 2007)
@@ -73,7 +73,7 @@ namespace libcloudphxx
7373
return log(
7474
s_0(T, mean_rd, chem_b) /
7575
std::min(real_t(s(p, T, rv)), real_t(RH_max - 1))
76-
) / sqrt(2) / log(sdev_rd_s(sdev_rd));
76+
) / std::sqrt(2) / log(sdev_rd_s(sdev_rd));
7777
}
7878

7979
// helper for activation formulae (see eq. 10 in Morrison and Grabowski 2007)

include/libcloudph++/blk_2m/common_formulae.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ namespace libcloudphxx
4848
inline quantity<si::dimensionless, real_t> miu_c(
4949
const quantity<divide_typeof_helper<si::dimensionless, si::volume>::type, real_t> &n
5050
) {
51-
auto tmp = real_t(1) / pow<2>(eta(n)) - real_t(1);
51+
auto eta_n = eta(n);
52+
auto tmp = real_t(1) / (eta_n * eta_n) - real_t(1);
5253
assert(finite(tmp) && "spectral index n is finite failed");
5354
return tmp;
5455
}
@@ -60,7 +61,7 @@ namespace libcloudphxx
6061
const quantity<si::dimensionless, real_t> &rc,
6162
const quantity<si::mass_density, real_t> &rhod
6263
) {
63-
auto tmp = pow(
64+
auto tmp = std::pow(
6465
c_md<real_t>() * n * std::tgamma(miu_c(n*rhod) + d_md<real_t>() + real_t(1))
6566
/
6667
(rc * std::tgamma(miu_c(n*rhod) + real_t(1))) * si::cubic_metres
@@ -82,7 +83,7 @@ namespace libcloudphxx
8283
const quantity<si::mass_density, real_t> &rhod
8384
) {
8485
auto tmp = nc
85-
* pow(lambda_c(nc, rc, rhod) * si::metres, miu_c(nc * rhod) + real_t(1))
86+
* std::pow(lambda_c(nc, rc, rhod) * si::metres, miu_c(nc * rhod) + real_t(1))
8687
/ std::tgamma(miu_c(nc * rhod) + real_t(1))
8788
/ si::metres;
8889
assert(finite(tmp * si::metres * si::cubic_metres) && "intercept N0_c is finite failed");
@@ -97,7 +98,7 @@ namespace libcloudphxx
9798
const quantity<divide_typeof_helper<si::dimensionless, si::mass>::type, real_t> &nr,
9899
const quantity<si::dimensionless, real_t> &rr
99100
) {
100-
auto tmp = pow(
101+
auto tmp = std::pow(
101102
c_md<real_t>() * nr * std::tgamma(d_md<real_t>() + real_t(1)) / rr * si::cubic_metres
102103
,
103104
real_t(1) / d_md<real_t>()

include/libcloudph++/blk_2m/rhs_cellwise.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ namespace libcloudphxx
215215

216216
// sink of N for cloud droplets is combined with the sink due to accretion
217217
// source of N for drizzle assumes that all the drops have the same radius
218-
local_dot_nr += tmp / (real_t(4)/3 * pi<real_t>() * rho_w<real_t>() * pow<3>(drizzle_radius<real_t>()))
218+
local_dot_nr += tmp / (real_t(4)/3 * pi<real_t>() * rho_w<real_t>() *
219+
drizzle_radius<real_t>() * drizzle_radius<real_t>() * drizzle_radius<real_t>())
219220
* si::kilograms * si::seconds; // to make it dimensionless
220221

221222
if(tmp == rc / (dt * si::seconds)) // all cloud water turned into rain

include/libcloudph++/blk_2m/terminal_vel_formulae.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ namespace libcloudphxx
6060
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, //slope of assumed exponential size distribution
6161
const quantity<si::length, real_t> &D // diameter
6262
) {
63-
auto tmp = - pow(lbd * si::metres, -6) * exp(-lbd * D) *
64-
(pow(real_t(lbd * D), 5) + 5 * pow(real_t(lbd * D), 4) * 20 * pow(real_t(lbd * D), 3) + 60 * pow(real_t(lbd * D), 2) + 120 * real_t(lbd * D) + 120);
63+
auto tmp = - std::pow(lbd * si::metres, -6) * exp(-lbd * D) *
64+
(pow(real_t(lbd * D), 5) + 5 * std::pow(real_t(lbd * D), 4) * 20 * std::pow(real_t(lbd * D), 3) + 60 * std::pow(real_t(lbd * D), 2) + 120 * real_t(lbd * D) + 120);
6565

6666
assert(finite(tmp) && "mint_1 is finite failed");
6767
return tmp;
@@ -72,8 +72,8 @@ namespace libcloudphxx
7272
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, //slope of assumed exponential size distribution
7373
const quantity<si::length, real_t> &D // diameter
7474
) {
75-
auto tmp = - pow(real_t(lbd * si::metres), -5) * exp(-lbd * D) *
76-
(pow(real_t(lbd * D), 4) + 4 * pow(real_t(lbd * D), 3) * 12 * pow(real_t(lbd * D), 2) + 24 * real_t(lbd * D) + 24);
75+
auto tmp = - std::pow(real_t(lbd * si::metres), -5) * exp(-lbd * D) *
76+
(pow(real_t(lbd * D), 4) + 4 * std::pow(real_t(lbd * D), 3) * 12 * std::pow(real_t(lbd * D), 2) + 24 * real_t(lbd * D) + 24);
7777

7878
assert(finite(tmp) && "mint_2 is finite failed");
7979
return tmp;
@@ -84,9 +84,9 @@ namespace libcloudphxx
8484
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, // slope of assumed exponential size distribution
8585
const quantity<si::length, real_t> &D // diameter
8686
) {
87-
auto tmp = real_t(1./16) / pow(real_t(lbd * si::metres), real_t(9./2))
88-
* (105 * sqrt(pi<real_t>()) * std::erf(sqrt(lbd * D))
89-
- 2 * sqrt(lbd * D) * exp(-lbd * D) * (8 * pow(real_t(lbd * D), 3) + 28 * pow(real_t(lbd * D), 2) + 70 * real_t(lbd * D) + 105)
87+
auto tmp = real_t(1./16) / std::pow(real_t(lbd * si::metres), real_t(9./2))
88+
* (105 * std::sqrt(pi<real_t>()) * std::erf(sqrt(lbd * D))
89+
- 2 * std::sqrt(lbd * D) * exp(-lbd * D) * (8 * std::pow(real_t(lbd * D), 3) + 28 * std::pow(real_t(lbd * D), 2) + 70 * real_t(lbd * D) + 105)
9090
);
9191

9292
assert(finite(tmp) && "mint_3 is finite failed");
@@ -99,7 +99,7 @@ namespace libcloudphxx
9999
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, //slope of assumed exponential size distribution
100100
const quantity<si::length, real_t> &D // diameter
101101
) {
102-
auto tmp = - pow(real_t(lbd * si::metres), -1) * exp(-lbd * D);
102+
auto tmp = - std::pow(real_t(lbd * si::metres), -1) * exp(-lbd * D);
103103

104104
assert(finite(tmp) && "int_4 is finite failed");
105105
return tmp;
@@ -112,7 +112,7 @@ namespace libcloudphxx
112112
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, // slope of assumed exponential size distribution
113113
const quantity<si::length, real_t> &D // diameter
114114
) {
115-
auto tmp = pow(real_t(lbd * si::metres), -3) * exp(-lbd * D) * (- real_t(lbd * D) * (real_t(lbd * D) + 2) - 2);
115+
auto tmp = std::pow(real_t(lbd * si::metres), -3) * exp(-lbd * D) * (- real_t(lbd * D) * (real_t(lbd * D) + 2) - 2);
116116

117117
assert(finite(tmp) && "nint_1 is finite failed");
118118
return tmp;
@@ -124,7 +124,7 @@ namespace libcloudphxx
124124
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, //slope of assumed exponential size distribution
125125
const quantity<si::length, real_t> &D // diameter
126126
) {
127-
auto tmp = - pow(real_t(lbd * si::metres), -2) * exp(-lbd * D) * (lbd * D + 1);
127+
auto tmp = - std::pow(real_t(lbd * si::metres), -2) * exp(-lbd * D) * (lbd * D + 1);
128128

129129
assert(finite(tmp) && "nint_2 is finite failed");
130130
return tmp;
@@ -136,8 +136,8 @@ namespace libcloudphxx
136136
const quantity<divide_typeof_helper<si::dimensionless, si::length>::type, real_t> &lbd, //slope of assumed exponential size distribution
137137
const quantity<si::length, real_t> &D //diameter
138138
) {
139-
auto tmp = sqrt(pi<real_t>()) * std::erf(sqrt(lbd * D)) / 2 / pow(real_t(lbd * si::metres), 3./2)
140-
- sqrt(D / si::metres) * exp(-lbd*D) / (lbd * si::metres);
139+
auto tmp = std::sqrt(pi<real_t>()) * std::erf(sqrt(lbd * D)) / 2 / std::pow(real_t(lbd * si::metres), 3./2)
140+
- std::sqrt(D / si::metres) * exp(-lbd*D) / (lbd * si::metres);
141141

142142
assert(finite(tmp) && "nint_3 is finite failed");
143143
return tmp;
@@ -161,15 +161,15 @@ namespace libcloudphxx
161161
* real_t(1000) // mass of the drop in grams
162162
* (
163163
alpha_fall(d1<real_t>() / real_t(2))
164-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() / real_t(2)))
164+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() / real_t(2)))
165165
* (mint_1(lbd, d1<real_t>()) - mint_1(lbd, real_t(0) * si::metres))
166166
+
167167
alpha_fall(d1<real_t>() + d2<real_t>() / real_t(2))
168-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() + d2<real_t>() / real_t(2)))
168+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() + d2<real_t>() / real_t(2)))
169169
* (mint_2(lbd, d2<real_t>()) - mint_2(lbd, d1<real_t>()))
170170
+
171171
alpha_fall(d2<real_t>() + d3<real_t>() / real_t(2))
172-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d2<real_t>() + d3<real_t>() / real_t(2)))
172+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d2<real_t>() + d3<real_t>() / real_t(2)))
173173
* (mint_3(lbd, d3<real_t>()) - mint_3(lbd, d2<real_t>()))
174174
+
175175
alpha_fall(real_t(2) * d3<real_t>())
@@ -197,15 +197,15 @@ namespace libcloudphxx
197197
auto tmp = rho_stp<real_t>() / rhod
198198
* (
199199
alpha_fall(d1<real_t>() / real_t(2))
200-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() / real_t(2)))
200+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() / real_t(2)))
201201
* (nint_1(lbd, d1<real_t>()) - nint_1(lbd, real_t(0) * si::metres))
202202
+
203203
alpha_fall(d1<real_t>() + d2<real_t>() / real_t(2))
204-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() + d2<real_t>() / real_t(2)))
204+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d1<real_t>() + d2<real_t>() / real_t(2)))
205205
* (nint_2(lbd, d2<real_t>()) - nint_2(lbd, d1<real_t>()))
206206
+
207207
alpha_fall(d2<real_t>() + d3<real_t>() / real_t(2))
208-
* pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d2<real_t>() + d3<real_t>() / real_t(2)))
208+
* std::pow(c_md<real_t>() * si::cubic_metres / si::kilograms * real_t(1000), beta_fall(d2<real_t>() + d3<real_t>() / real_t(2)))
209209
* (nint_3(lbd, d3<real_t>()) - nint_3(lbd, d2<real_t>()))
210210
+
211211
alpha_fall(real_t(2) * d3<real_t>()) * (real_t(0) - int_4(lbd, d3<real_t>()))

include/libcloudph++/common/GA17_turbulence.hpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ namespace libcloudphxx
77
// Grabowski and Abade 2017
88
namespace GA17_turbulence
99
{
10+
11+
#if !defined(__NVCC__)
12+
using std::pow;
13+
using std::cbrt;
14+
using std::sqrt;
15+
#endif
16+
1017
libcloudphxx_const_derived(si::dimensionless, C_E, real_t(0.845));
1118
libcloudphxx_const_derived(si::dimensionless, C_tau, real_t(1.5));
1219
libcloudphxx_const_derived(si::dimensionless, cube_root_of_two_pi, pow(real_t(2) *
@@ -18,11 +25,6 @@ namespace libcloudphxx
1825
, real_t(1./3.))
1926
);
2027

21-
#if !defined(__NVCC__)
22-
using std::pow;
23-
using std::sqrt;
24-
#endif
25-
2628
typedef divide_typeof_helper<
2729
si::dimensionless,
2830
si::length
@@ -62,7 +64,8 @@ namespace libcloudphxx
6264
const quantity<si::length, real_t> &L // characteristic length-scale
6365
)
6466
{
65-
return quantity<area_over_time_squared, real_t>(pow((L * diss_rate) / si::cubic_metres * si::seconds * si::seconds * si::seconds / C_E<real_t>(), real_t(2./3.)) * si::metres * si::metres / si::seconds / si::seconds);
67+
const real_t ret = cbrt( (L * diss_rate) / si::cubic_metres * si::seconds * si::seconds * si::seconds / C_E<real_t>());
68+
return quantity<area_over_time_squared, real_t>(ret * ret * si::metres * si::metres / si::seconds / si::seconds);
6669
};
6770

6871
template <typename real_t>

include/libcloudph++/common/SGS_length_scale.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace libcloudphxx
4848
quantity<si::length, real_t> dy,
4949
quantity<si::length, real_t> dz
5050
)
51-
{ return quantity<si::length, real_t>(pow((dx/si::metres)*(dy/si::metres)*(dz/si::metres), real_t(1./3.)) * si::metres);}
51+
{ return quantity<si::length, real_t>(cbrt((dx/si::metres)*(dy/si::metres)*(dz/si::metres)) * si::metres);}
5252

5353
// lambda = (dx+dy+dz) / 3
5454
template <typename real_t>

include/libcloudph++/common/const_cp.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,29 @@ namespace libcloudphxx
3333
)
3434
//</listing-1>
3535
{
36-
return p_tri<real_t>() * exp(
37-
(l_tri<real_t>() + (c_pw<real_t>() - c_pv<real_t>()) * T_tri<real_t>()) / R_v<real_t>() * (real_t(1) / T_tri<real_t>() - real_t(1) / T)
38-
- (c_pw<real_t>() - c_pv<real_t>()) / R_v<real_t>() * std::log(T / T_tri<real_t>())
39-
);
36+
return p_tri<real_t>() * exp(
37+
(l_tri<real_t>() + (c_pw<real_t>() - c_pv<real_t>()) * T_tri<real_t>()) / R_v<real_t>() * (real_t(1) / T_tri<real_t>() - real_t(1) / T)
38+
- (c_pw<real_t>() - c_pv<real_t>()) / R_v<real_t>() * std::log(T / T_tri<real_t>())
39+
);
4040
}
4141

4242
// saturation vapour mixing ratio for water as a function of pressure and temperature
4343
template <typename real_t>
4444
BOOST_GPU_ENABLED
4545
quantity<si::dimensionless, real_t> r_vs(
46-
const quantity<si::temperature, real_t> &T,
47-
const quantity<si::pressure, real_t> &p
46+
const quantity<si::temperature, real_t> &T,
47+
const quantity<si::pressure, real_t> &p
4848
) {
49-
return eps<real_t>() / (p / p_vs<real_t>(T) - 1);
49+
return eps<real_t>() / (p / p_vs<real_t>(T) - 1);
5050
}
5151

5252
// latent heat for constant c_p
5353
template <typename real_t>
5454
BOOST_GPU_ENABLED
5555
quantity<divide_typeof_helper<si::energy, si::mass>::type , real_t> l_v(
56-
const quantity<si::temperature, real_t> &T
56+
const quantity<si::temperature, real_t> &T
5757
) {
58-
return l_tri<real_t>() + (c_pv<real_t>() - c_pw<real_t>()) * (T - T_tri<real_t>());
58+
return l_tri<real_t>() + (c_pv<real_t>() - c_pw<real_t>()) * (T - T_tri<real_t>());
5959
}
6060
};
6161
};

0 commit comments

Comments
 (0)