Skip to content

Commit 16e5683

Browse files
committed
option for periodic top walls
1 parent 495901e commit 16e5683

File tree

2 files changed

+84
-70
lines changed

2 files changed

+84
-70
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: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -173,83 +173,94 @@ 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)
176+
if(!opts_init.periodic_topbot_walls)
178177
{
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-
// precipitation on the bottom edge of the domain
189-
//// first: count the volume of particles below the domain
190-
// TODO! (using tranform_reduce?)
191-
//// second: zero-out multiplicities so they will be recycled
192-
{
193-
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+
}
194189

195-
thrust_device::vector<real_t> &n_filtered(tmp_device_real_part);
190+
// precipitation on the bottom edge of the domain
191+
//// first: count the volume of particles below the domain
192+
// TODO! (using tranform_reduce?)
193+
//// second: zero-out multiplicities so they will be recycled
194+
{
195+
namespace arg = thrust::placeholders;
196196

197-
thrust::fill(n_filtered.begin(), n_filtered.end(), 0.);
197+
thrust_device::vector<real_t> &n_filtered(tmp_device_real_part);
198198

199-
// copy n of SDs that are out of the domain (otherwise remains n_filtered=0)
200-
thrust::transform_if(
201-
n.begin(), n.end(), // input 1
202-
z.begin(), // stencil
203-
n_filtered.begin(), // output
204-
thrust::identity<n_t>(), // operation
205-
arg::_1 < opts_init.z0 // condition
206-
);
199+
thrust::fill(n_filtered.begin(), n_filtered.end(), 0.);
207200

208-
// add total liquid water volume that fell out in this step
209-
output_puddle[common::outliq_vol] +=
210-
thrust::transform_reduce(
211-
thrust::make_zip_iterator(thrust::make_tuple(
212-
n_filtered.begin(), rw2.begin())), // input start
213-
thrust::make_zip_iterator(thrust::make_tuple(
214-
n_filtered.begin(), rw2.begin())) + n_part, // input end
215-
detail::count_vol<real_t>(3./2.), // operation
216-
real_t(0), // init val
217-
thrust::plus<real_t>()
201+
// copy n of SDs that are out of the domain (otherwise remains n_filtered=0)
202+
thrust::transform_if(
203+
n.begin(), n.end(), // input 1
204+
z.begin(), // stencil
205+
n_filtered.begin(), // output
206+
thrust::identity<n_t>(), // operation
207+
arg::_1 < opts_init.z0 // condition
218208
);
219209

220-
// add total dry volume that fell out in this step
221-
output_puddle[common::outdry_vol] +=
222-
thrust::transform_reduce(
223-
thrust::make_zip_iterator(thrust::make_tuple(
224-
n_filtered.begin(), rd3.begin())), // input start
225-
thrust::make_zip_iterator(thrust::make_tuple(
226-
n_filtered.begin(), rd3.begin())) + n_part, // input end
227-
detail::count_vol<real_t>(1.), // operation
228-
real_t(0), // init val
229-
thrust::plus<real_t>()
230-
);
210+
// add total liquid water volume that fell out in this step
211+
output_puddle[common::outliq_vol] +=
212+
thrust::transform_reduce(
213+
thrust::make_zip_iterator(thrust::make_tuple(
214+
n_filtered.begin(), rw2.begin())), // input start
215+
thrust::make_zip_iterator(thrust::make_tuple(
216+
n_filtered.begin(), rw2.begin())) + n_part, // input end
217+
detail::count_vol<real_t>(3./2.), // operation
218+
real_t(0), // init val
219+
thrust::plus<real_t>()
220+
);
231221

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

247-
// zero-out multiplicities
248-
thrust::transform_if(
249-
z.begin(), z.end(), // input
250-
n.begin(), // output
251-
detail::flag<n_t, real_t>(), // operation (zero-out)
252-
arg::_1 < opts_init.z0 // condition
249+
// zero-out multiplicities
250+
thrust::transform_if(
251+
z.begin(), z.end(), // input
252+
n.begin(), // output
253+
detail::flag<n_t, real_t>(), // operation (zero-out)
254+
arg::_1 < opts_init.z0 // condition
255+
);
256+
}
257+
}
258+
else // periodic top/bot walls
259+
{
260+
thrust::transform(
261+
z.begin(), z.end(),
262+
z.begin(),
263+
detail::periodic<real_t>(opts_init.z0, opts_init.z1)
253264
);
254265
}
255266
}

0 commit comments

Comments
 (0)