Skip to content

Commit 82bb787

Browse files
committed
Merge branch 'periodic_vert' into kida-1d
2 parents 82d0886 + 16e5683 commit 82bb787

File tree

2 files changed

+95
-81
lines changed

2 files changed

+95
-81
lines changed

include/libcloudph++/lgrngn/opts_init.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ namespace libcloudphxx
139139

140140
bool no_ccn_at_init; // if true, no ccn / SD are put at the start of the simulation
141141

142-
bool open_side_walls; // if true, side walls are "open", i.e. SD are removed at contact.
142+
bool open_side_walls, // if true, side walls are "open", i.e. SD are removed at contact. Periodic otherwise.
143+
periodic_topbot_walls; // if true, top and bot walls are periodic. Open otherwise
144+
143145

144146
// ctor with defaults (C++03 compliant) ...
145147
opts_init_t() :
@@ -183,7 +185,8 @@ namespace libcloudphxx
183185
rd_min(0.),
184186
diag_incloud_time(false),
185187
no_ccn_at_init(false),
186-
open_side_walls(false)
188+
open_side_walls(false),
189+
periodic_topbot_walls(false)
187190
{}
188191

189192
// dtor (just to silence -Winline warnings)

src/impl/particles_impl_bcnd.ipp

Lines changed: 90 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -173,94 +173,105 @@ namespace libcloudphxx
173173
// z boundary, no distmem here
174174
if (n_dims > 1)
175175
{
176-
// hardcoded "open" boudary at the top of the domain
177-
// (just for numerical-error-sourced out-of-domain particles)
178-
// {
179-
// namespace arg = thrust::placeholders;
180-
// thrust::transform_if(
181-
// z.begin(), z.end(), // input - arg
182-
// n.begin(), // output
183-
// detail::flag<n_t, real_t>(), // operation (zero-out, so recycling will take care of it)
184-
// arg::_1 >= opts_init.z1 // condition (note: >= seems important as z==z1 would cause out-of-range ijk)
185-
// );
186-
// }
187-
188-
// hardcoded perdiodic boundary at the top of the domain in ther vertical just for KiD 1D
189-
{
190-
namespace arg = thrust::placeholders;
191-
thrust::transform_if(
192-
z.begin(), z.end(), // input - arg
193-
z.begin(), // output
194-
arg::_1 - opts_init.z1 + opts_init.z0, // operation
195-
arg::_1 >= opts_init.z1 // condition (note: >= seems important as z==z1 would cause out-of-range ijk)
196-
);
197-
}
198-
199-
// precipitation on the bottom edge of the domain
200-
//// first: count the volume of particles below the domain
201-
// TODO! (using tranform_reduce?)
202-
//// second: zero-out multiplicities so they will be recycled
176+
if(!opts_init.periodic_topbot_walls)
203177
{
204-
namespace arg = thrust::placeholders;
178+
// default "open" boudary at the top of the domain
179+
// (just for numerical-error-sourced out-of-domain particles)
180+
// {
181+
// namespace arg = thrust::placeholders;
182+
// thrust::transform_if(
183+
// z.begin(), z.end(), // input - arg
184+
// n.begin(), // output
185+
// detail::flag<n_t, real_t>(), // operation (zero-out, so recycling will take care of it)
186+
// arg::_1 >= opts_init.z1 // condition (note: >= seems important as z==z1 would cause out-of-range ijk)
187+
// );
188+
// }
205189

206-
thrust_device::vector<real_t> &n_filtered(tmp_device_real_part);
190+
// hardcoded perdiodic boundary at the top of the domain in ther vertical just for KiD 1D
191+
{
192+
namespace arg = thrust::placeholders;
193+
thrust::transform_if(
194+
z.begin(), z.end(), // input - arg
195+
z.begin(), // output
196+
arg::_1 - opts_init.z1 + opts_init.z0, // operation
197+
arg::_1 >= opts_init.z1 // condition (note: >= seems important as z==z1 would cause out-of-range ijk)
198+
);
199+
}
207200

208-
thrust::fill(n_filtered.begin(), n_filtered.end(), 0.);
201+
// precipitation on the bottom edge of the domain
202+
//// first: count the volume of particles below the domain
203+
// TODO! (using tranform_reduce?)
204+
//// second: zero-out multiplicities so they will be recycled
205+
{
206+
namespace arg = thrust::placeholders;
209207

210-
// copy n of SDs that are out of the domain (otherwise remains n_filtered=0)
211-
thrust::transform_if(
212-
n.begin(), n.end(), // input 1
213-
z.begin(), // stencil
214-
n_filtered.begin(), // output
215-
thrust::identity<n_t>(), // operation
216-
arg::_1 < opts_init.z0 // condition
217-
);
208+
thrust_device::vector<real_t> &n_filtered(tmp_device_real_part);
218209

219-
// add total liquid water volume that fell out in this step
220-
output_puddle[common::outliq_vol] +=
221-
thrust::transform_reduce(
222-
thrust::make_zip_iterator(thrust::make_tuple(
223-
n_filtered.begin(), rw2.begin())), // input start
224-
thrust::make_zip_iterator(thrust::make_tuple(
225-
n_filtered.begin(), rw2.begin())) + n_part, // input end
226-
detail::count_vol<real_t>(3./2.), // operation
227-
real_t(0), // init val
228-
thrust::plus<real_t>()
229-
);
210+
thrust::fill(n_filtered.begin(), n_filtered.end(), 0.);
230211

231-
// add total dry volume that fell out in this step
232-
output_puddle[common::outdry_vol] +=
233-
thrust::transform_reduce(
234-
thrust::make_zip_iterator(thrust::make_tuple(
235-
n_filtered.begin(), rd3.begin())), // input start
236-
thrust::make_zip_iterator(thrust::make_tuple(
237-
n_filtered.begin(), rd3.begin())) + n_part, // input end
238-
detail::count_vol<real_t>(1.), // operation
239-
real_t(0), // init val
240-
thrust::plus<real_t>()
212+
// copy n of SDs that are out of the domain (otherwise remains n_filtered=0)
213+
thrust::transform_if(
214+
n.begin(), n.end(), // input 1
215+
z.begin(), // stencil
216+
n_filtered.begin(), // output
217+
thrust::identity<n_t>(), // operation
218+
arg::_1 < opts_init.z0 // condition
241219
);
242220

243-
if(opts_init.chem_switch)
244-
{
245-
for (int i = 0; i < chem_all; ++i)
246-
output_puddle[static_cast<common::output_t>(i)] +=
247-
thrust::transform_reduce(
248-
thrust::make_zip_iterator(thrust::make_tuple(
249-
n_filtered.begin(), chem_bgn[i])), // input start
250-
thrust::make_zip_iterator(thrust::make_tuple(
251-
n_filtered.end(), chem_end[i])), // input end
252-
detail::count_mass<real_t>(), // operation
253-
real_t(0), // init val
254-
thrust::plus<real_t>()
255-
);
256-
}
221+
// add total liquid water volume that fell out in this step
222+
output_puddle[common::outliq_vol] +=
223+
thrust::transform_reduce(
224+
thrust::make_zip_iterator(thrust::make_tuple(
225+
n_filtered.begin(), rw2.begin())), // input start
226+
thrust::make_zip_iterator(thrust::make_tuple(
227+
n_filtered.begin(), rw2.begin())) + n_part, // input end
228+
detail::count_vol<real_t>(3./2.), // operation
229+
real_t(0), // init val
230+
thrust::plus<real_t>()
231+
);
232+
233+
// add total dry volume that fell out in this step
234+
output_puddle[common::outdry_vol] +=
235+
thrust::transform_reduce(
236+
thrust::make_zip_iterator(thrust::make_tuple(
237+
n_filtered.begin(), rd3.begin())), // input start
238+
thrust::make_zip_iterator(thrust::make_tuple(
239+
n_filtered.begin(), rd3.begin())) + n_part, // input end
240+
detail::count_vol<real_t>(1.), // operation
241+
real_t(0), // init val
242+
thrust::plus<real_t>()
243+
);
257244

258-
// zero-out multiplicities
259-
thrust::transform_if(
260-
z.begin(), z.end(), // input
261-
n.begin(), // output
262-
detail::flag<n_t, real_t>(), // operation (zero-out)
263-
arg::_1 < opts_init.z0 // condition
245+
if(opts_init.chem_switch)
246+
{
247+
for (int i = 0; i < chem_all; ++i)
248+
output_puddle[static_cast<common::output_t>(i)] +=
249+
thrust::transform_reduce(
250+
thrust::make_zip_iterator(thrust::make_tuple(
251+
n_filtered.begin(), chem_bgn[i])), // input start
252+
thrust::make_zip_iterator(thrust::make_tuple(
253+
n_filtered.end(), chem_end[i])), // input end
254+
detail::count_mass<real_t>(), // operation
255+
real_t(0), // init val
256+
thrust::plus<real_t>()
257+
);
258+
}
259+
260+
// zero-out multiplicities
261+
thrust::transform_if(
262+
z.begin(), z.end(), // input
263+
n.begin(), // output
264+
detail::flag<n_t, real_t>(), // operation (zero-out)
265+
arg::_1 < opts_init.z0 // condition
266+
);
267+
}
268+
}
269+
else // periodic top/bot walls
270+
{
271+
thrust::transform(
272+
z.begin(), z.end(),
273+
z.begin(),
274+
detail::periodic<real_t>(opts_init.z0, opts_init.z1)
264275
);
265276
}
266277
}

0 commit comments

Comments
 (0)