Skip to content

Commit 154751f

Browse files
authored
Merge pull request #399 from pdziekan/sgs_tke
add diags for up vp wp moms
2 parents 904b6ad + 3e085f6 commit 154751f

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

include/libcloudph++/lgrngn/particles.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ namespace libcloudphxx
102102
virtual void diag_chem(const enum common::chem::chem_species_t&) { assert(false); }
103103
virtual void diag_precip_rate() { assert(false); }
104104
virtual void diag_kappa_mom(const int&) { assert(false); }
105+
virtual void diag_up_mom(const int&) { assert(false); }
106+
virtual void diag_vp_mom(const int&) { assert(false); }
107+
virtual void diag_wp_mom(const int&) { assert(false); }
105108
virtual void diag_incloud_time_mom(const int&) { assert(false); } // requires opts_init.diag_incloud_time==true
106109
virtual void diag_max_rw() { assert(false); }
107110
virtual void diag_vel_div() { assert(false); }
@@ -181,6 +184,9 @@ namespace libcloudphxx
181184
void diag_dry_mom(const int &k);
182185
void diag_wet_mom(const int &k);
183186
void diag_kappa_mom(const int &k);
187+
void diag_up_mom(const int&);
188+
void diag_vp_mom(const int&);
189+
void diag_wp_mom(const int&);
184190
void diag_incloud_time_mom(const int &k);
185191
void diag_wet_mass_dens(const real_t&, const real_t&);
186192

@@ -274,6 +280,9 @@ namespace libcloudphxx
274280
void diag_dry_mom(const int &k);
275281
void diag_wet_mom(const int &k);
276282
void diag_kappa_mom(const int&);
283+
void diag_up_mom(const int&);
284+
void diag_vp_mom(const int&);
285+
void diag_wp_mom(const int&);
277286
void diag_incloud_time_mom(const int&);
278287
void diag_wet_mass_dens(const real_t&, const real_t&);
279288
real_t *outbuf();

src/impl/particles_impl_moms.ipp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,22 @@ namespace libcloudphxx
155155
const real_t n = thrust::get<0>(tpl);
156156
const real_t x = thrust::get<1>(tpl);
157157
#if !defined(NDEBUG)
158-
real_t res = n * pow(x, xp); // TODO: check if xp=0 is optimised
158+
real_t res;
159+
if(x >= 0)
160+
res = n * pow(x, xp);
161+
else
162+
{
163+
int ixp = xp;
164+
assert(ixp == xp);
165+
res = n * pow(x, ixp);
166+
}
159167
if(isnaninf()(res))
160168
{
161169
printf("nan/inf res in moment counter, n = %g x = %g res = %g xp = %g\n", n, x, res, xp);
162170
}
163171
return res;
164172
#else
165-
return n * pow(x, xp); // TODO: check if xp=0 is optimised
173+
return x >= 0 ? n * pow(x, xp) : n * pow(x, int(xp)); // for negative x and non-integer xp, pow = NaN
166174
#endif
167175
}
168176
};

src/particles_diag.ipp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,27 @@ namespace libcloudphxx
318318
pimpl->moms_calc(pimpl->kpa.begin(), n);
319319
}
320320

321+
// compute n-th moment of SGS velocity in x for selected particles
322+
template <typename real_t, backend_t device>
323+
void particles_t<real_t, device>::diag_up_mom(const int &n)
324+
{
325+
pimpl->moms_calc(pimpl->up.begin(), n);
326+
}
327+
328+
// compute n-th moment of SGS velocity in y for selected particles
329+
template <typename real_t, backend_t device>
330+
void particles_t<real_t, device>::diag_vp_mom(const int &n)
331+
{
332+
pimpl->moms_calc(pimpl->vp.begin(), n);
333+
}
334+
335+
// compute n-th moment of SGS velocity in z for selected particles
336+
template <typename real_t, backend_t device>
337+
void particles_t<real_t, device>::diag_wp_mom(const int &n)
338+
{
339+
pimpl->moms_calc(pimpl->wp.begin(), n);
340+
}
341+
321342
// compute n-th moment of incloud_time for selected particles
322343
template <typename real_t, backend_t device>
323344
void particles_t<real_t, device>::diag_incloud_time_mom(const int &n)

src/particles_multi_gpu_diag.ipp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ namespace libcloudphxx
121121
pimpl->mcuda_run(&particles_t<real_t, CUDA>::diag_kappa_mom, k);
122122
}
123123

124+
template <typename real_t>
125+
void particles_t<real_t, multi_CUDA>::diag_up_mom(const int &k)
126+
{
127+
pimpl->mcuda_run(&particles_t<real_t, CUDA>::diag_up_mom, k);
128+
}
129+
130+
template <typename real_t>
131+
void particles_t<real_t, multi_CUDA>::diag_vp_mom(const int &k)
132+
{
133+
pimpl->mcuda_run(&particles_t<real_t, CUDA>::diag_vp_mom, k);
134+
}
135+
136+
template <typename real_t>
137+
void particles_t<real_t, multi_CUDA>::diag_wp_mom(const int &k)
138+
{
139+
pimpl->mcuda_run(&particles_t<real_t, CUDA>::diag_wp_mom, k);
140+
}
141+
124142
template <typename real_t>
125143
void particles_t<real_t, multi_CUDA>::diag_incloud_time_mom(const int &k)
126144
{

0 commit comments

Comments
 (0)