From 67d834b397d2bd62a30b16ebc04aecf94e6dc43b Mon Sep 17 00:00:00 2001 From: pdziekan Date: Tue, 22 Feb 2022 16:53:01 +0100 Subject: [PATCH 01/11] wip on coal tele mass flux --- include/libcloudph++/lgrngn/particles.hpp | 2 ++ src/impl/particles_impl.ipp | 3 +- src/impl/particles_impl_coal.ipp | 32 ++++++++++++++----- src/impl/particles_impl_init_hskpng_ncell.ipp | 1 + 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/include/libcloudph++/lgrngn/particles.hpp b/include/libcloudph++/lgrngn/particles.hpp index f494b8d9a..51774b5ce 100644 --- a/include/libcloudph++/lgrngn/particles.hpp +++ b/include/libcloudph++/lgrngn/particles.hpp @@ -108,6 +108,7 @@ namespace libcloudphxx virtual void diag_incloud_time_mom(const int&) { assert(false); } // requires opts_init.diag_incloud_time==true virtual void diag_max_rw() { assert(false); } virtual void diag_vel_div() { assert(false); } + virtual void diag_coal_tele_mass_flux() { assert(false); } virtual std::map diag_puddle() { assert(false); return std::map(); } virtual real_t *outbuf() { assert(false); return NULL; } @@ -197,6 +198,7 @@ namespace libcloudphxx void diag_precip_rate(); void diag_max_rw(); void diag_vel_div(); + void diag_coal_tele_mass_flux(); std::map diag_puddle(); real_t *outbuf(); diff --git a/src/impl/particles_impl.ipp b/src/impl/particles_impl.ipp index b07d3332c..387b3e7cd 100644 --- a/src/impl/particles_impl.ipp +++ b/src/impl/particles_impl.ipp @@ -147,7 +147,8 @@ namespace libcloudphxx p, // pressure [Pa] RH, // relative humisity eta,// dynamic viscosity - diss_rate; // turbulent kinetic energy dissipation rate + diss_rate, // turbulent kinetic energy dissipation rate + coal_tele_mass_flux; // vertical mass flux due to mass "teleportation" at collision (diagnostic) thrust_device::vector w_LS; // large-scale subsidence velocity profile thrust_device::vector SGS_mix_len; // SGS mixing length profile diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 205ccacb2..e679c7d8f 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -102,15 +102,22 @@ namespace libcloudphxx typename tup_t > BOOST_GPU_ENABLED - void collide(tup_t tpl, const n_t &col_no) + void collide(tup_t tpl, const n_t &col_no, const real_t &z_a, const real_t &z_b, real_t &coal_tele_mass_flux) { #if !defined(__NVCC__) using std::cbrt; using std::sqrt; #endif + // multiplicity change (eq. 12 in Shima et al. 2009) thrust::get(tpl) -= col_no * thrust::get(tpl); + // calculate vertical mass flux from _a to _b + // teleported mass = col_no * n_b * mass_a + // distance = z_b - z_a, >0 mean upward flux + coal_tele_mass_flux += (thrust::get(tpl) - thrust::get(tpl)) * col_no * thrust::get(tpl) * thrust::get(tpl) * sqrt(thrust::get(tpl)); + // done later: * 4/3 PI rho_w / dt + // wet radius change (eq. 13 in Shima et al. 2009) const real_t rw_b = cbrt( col_no * thrust::get(tpl) * sqrt(thrust::get(tpl)) + @@ -132,15 +139,17 @@ namespace libcloudphxx template struct collider { - // read-only parameters + // read-only parameters (not really, coal_tele_mass_flux is overwritten) typedef thrust::tuple< real_t, // random number (u01) real_t, // scaling factor thrust_size_t, thrust_size_t, // ix thrust_size_t, thrust_size_t, // off (index within cell) - real_t // dv + real_t, // dv + real_t, real_t, // z + real_t // coal_tele_mass_flux > tpl_ro_t; - enum { u01_ix, scl_ix, ix_a_ix, ix_b_ix, off_a_ix, off_b_ix, dv_ix }; + enum { u01_ix, scl_ix, ix_a_ix, ix_b_ix, off_a_ix, off_b_ix, dv_ix, z_a_ix, z_b_ix, coal_tele_mass_flux_ix }; // read-write parameters = return type typedef thrust::tuple< @@ -236,7 +245,7 @@ namespace libcloudphxx rw2_a_ix, rw2_b_ix, rd3_a_ix, rd3_b_ix, vt_a_ix, vt_b_ix - >(thrust::get<1>(tpl_ro_rw), col_no); + >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(tpl_ro), thrust::get(tpl_ro), thrust::get(tpl_ro)); thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(na_ge_nb); // col vector for the second in a pair stores info on which one has greater multiplicity } else @@ -248,7 +257,7 @@ namespace libcloudphxx rw2_b_ix, rw2_a_ix, rd3_b_ix, rd3_a_ix, vt_b_ix, vt_a_ix - >(thrust::get<1>(tpl_ro_rw), col_no); + >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(tpl_ro), thrust::get(tpl_ro), thrust::get(tpl_ro)); thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(nb_gt_na); // col vector for the second in a pair stores info on which one has greater multiplicity } thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(col_no); // col vector for the first in a pair stores info on number of collisions @@ -338,7 +347,9 @@ namespace libcloudphxx thrust::counting_iterator, // ix_a thrust::counting_iterator, // ix_b pi_size_t, pi_size_t, // off_a & off_b - pi_real_t // dv + pi_real_t, // dv + pi_real_t, pi_real_t, // z_a & z_b + pi_real_t // col_tele_mass_flux > > zip_ro_t; @@ -365,7 +376,12 @@ namespace libcloudphxx thrust::make_permutation_iterator(off.begin(), sorted_ijk.begin()), thrust::make_permutation_iterator(off.begin(), sorted_ijk.begin())+1, // dv - thrust::make_permutation_iterator(dv.begin(), sorted_ijk.begin()) + thrust::make_permutation_iterator(dv.begin(), sorted_ijk.begin()), + // vertical position + thrust::make_permutation_iterator(z.begin(), sorted_id.begin()), + thrust::make_permutation_iterator(z.begin(), sorted_id.begin())+1, + // mass flux caused by teleportation in the coalescence algorithm - its overwritten, not read-only! + thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), sorted_ijk.begin()) ) ); diff --git a/src/impl/particles_impl_init_hskpng_ncell.ipp b/src/impl/particles_impl_init_hskpng_ncell.ipp index 2b92d6601..eab153a47 100644 --- a/src/impl/particles_impl_init_hskpng_ncell.ipp +++ b/src/impl/particles_impl_init_hskpng_ncell.ipp @@ -35,6 +35,7 @@ namespace libcloudphxx sstp_tmp_th.resize(n_cell); sstp_tmp_rh.resize(n_cell); } + coal_tele_mass_flux.resize(n_cell, 0); } }; }; From 43125f769142b16d1b898af030eb3efa5bc79189 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 24 Feb 2022 11:29:32 +0100 Subject: [PATCH 02/11] coal tele mass flux: store in per-particle tmp in coalescence, later add to per-cell vector --- include/libcloudph++/lgrngn/opts_init.hpp | 4 +++ src/impl/particles_impl.ipp | 2 +- src/impl/particles_impl_coal.ipp | 31 +++++++++++++++++-- src/impl/particles_impl_hskpng_resize.ipp | 2 +- src/impl/particles_impl_init_hskpng_ncell.ipp | 3 +- .../particles_impl_reserve_hskpng_npart.ipp | 2 +- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/include/libcloudph++/lgrngn/opts_init.hpp b/include/libcloudph++/lgrngn/opts_init.hpp index c012d8823..08f120d88 100644 --- a/include/libcloudph++/lgrngn/opts_init.hpp +++ b/include/libcloudph++/lgrngn/opts_init.hpp @@ -104,6 +104,9 @@ namespace libcloudphxx // do we want to track the time SDs spend inside clouds bool diag_incloud_time; + // do we want to calculate mass flux caused by mass teleportation in the coalescence algorithm + bool diag_coal_tele_mass_flux; + // RH threshold for calculating equilibrium condition at t=0 real_t RH_max; @@ -232,6 +235,7 @@ namespace libcloudphxx supstp_rlx(1), rd_min(0.), diag_incloud_time(false), + diag_coal_tele_mass_flux(true), no_ccn_at_init(false), open_side_walls(false), periodic_topbot_walls(false), diff --git a/src/impl/particles_impl.ipp b/src/impl/particles_impl.ipp index 387b3e7cd..d764f3d1e 100644 --- a/src/impl/particles_impl.ipp +++ b/src/impl/particles_impl.ipp @@ -148,7 +148,7 @@ namespace libcloudphxx RH, // relative humisity eta,// dynamic viscosity diss_rate, // turbulent kinetic energy dissipation rate - coal_tele_mass_flux; // vertical mass flux due to mass "teleportation" at collision (diagnostic) + coal_tele_mass_flux; // vertical mass flux due to mass "teleportation" at collision (diagnostic, accumulated over time) thrust_device::vector w_LS; // large-scale subsidence velocity profile thrust_device::vector SGS_mix_len; // SGS mixing length profile diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index e679c7d8f..b0828793f 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -283,14 +283,19 @@ namespace libcloudphxx // references to tmp data thrust_device::vector &scl(tmp_device_real_cell), // scale factor for probablility - &col(tmp_device_real_part); // number of collisions, used in chemistry, NOTE: it's the same as u01, so it overwrites already used random numbers + &col(tmp_device_real_part), // number of collisions, used in chemistry, NOTE: it's the same as u01, so it overwrites already used random numbers // 1st one of a pair stores number of collisions, 2nd one stores info on which one has greater multiplicity + &coal_tele_mass_flux_pp(tmp_device_real_part2); // mass flux caused by teleportation of droplets at coalescence + // 1st one of a pair - data, 2nd - empty thrust_device::vector &off(tmp_device_size_cell); // offset for getting index of particle within a cell // laying out scale factor onto ijk grid // fill with 0s if not all cells will be updated in the following copy if(count_n!=n_cell) thrust::fill(scl.begin(), scl.end(), real_t(0.)); + + if(opts_init.diag_coal_tele_mass_flux) + thrust::fill(coal_tele_mass_flux_pp.begin(), coal_tele_mass_flux_pp.end()); thrust::copy( count_mom.begin(), // input - begin @@ -381,7 +386,8 @@ namespace libcloudphxx thrust::make_permutation_iterator(z.begin(), sorted_id.begin()), thrust::make_permutation_iterator(z.begin(), sorted_id.begin())+1, // mass flux caused by teleportation in the coalescence algorithm - its overwritten, not read-only! - thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), sorted_ijk.begin()) + // TODO: pass it only if opts_init.diag_coal_tele_mass_flux==true + thrust::make_permutation_iterator(coal_tele_mass_flux_pp.begin(), sorted_id.begin()) ) ); @@ -519,6 +525,27 @@ namespace libcloudphxx ); nancheck(incloud_time, "incloud_time - post coalescence"); } + + // per-cell sum of coalescence teleportation mass flux + if(opts_init.diag_coal_tele_mass_flux) + { + thrust::pair< + thrust_device::vector::iterator, + typename thrust_device::vector::iterator + > it_pair = thrust::reduce_by_key( + // input - keys + sorted_ijk.begin(), sorted_ijk.begin()+npart, + // input - values + coal_tele_mass_flux_pp.begin(), coal_tele_mass_flux_pp.end(), + // output - keys + count_ijk.begin(), + // output - values + coal_tele_mass_flux.begin() + ); + + count_n = it_pair.first - count_ijk.begin(); + assert(count_n <= n_cell); + } } }; }; diff --git a/src/impl/particles_impl_hskpng_resize.ipp b/src/impl/particles_impl_hskpng_resize.ipp index d9f494bb7..f3a561c98 100644 --- a/src/impl/particles_impl_hskpng_resize.ipp +++ b/src/impl/particles_impl_hskpng_resize.ipp @@ -53,7 +53,7 @@ namespace libcloudphxx { tmp_device_real_part1.resize(n_part); } - if((allow_sstp_cond && opts_init.exact_sstp_cond) || n_dims==3 || opts_init.turb_cond_switch) + if((allow_sstp_cond && opts_init.exact_sstp_cond) || n_dims==3 || opts_init.turb_cond_switch || opts_init.diag_coal_tele_mass_flux) { tmp_device_real_part2.resize(n_part); } diff --git a/src/impl/particles_impl_init_hskpng_ncell.ipp b/src/impl/particles_impl_init_hskpng_ncell.ipp index eab153a47..8be126c84 100644 --- a/src/impl/particles_impl_init_hskpng_ncell.ipp +++ b/src/impl/particles_impl_init_hskpng_ncell.ipp @@ -35,7 +35,8 @@ namespace libcloudphxx sstp_tmp_th.resize(n_cell); sstp_tmp_rh.resize(n_cell); } - coal_tele_mass_flux.resize(n_cell, 0); + if(opts_init.diag_coal_tele_mass_flux) + coal_tele_mass_flux.resize(n_cell, 0); } }; }; diff --git a/src/impl/particles_impl_reserve_hskpng_npart.ipp b/src/impl/particles_impl_reserve_hskpng_npart.ipp index 063969e7f..5ab28e6b1 100644 --- a/src/impl/particles_impl_reserve_hskpng_npart.ipp +++ b/src/impl/particles_impl_reserve_hskpng_npart.ipp @@ -56,7 +56,7 @@ namespace libcloudphxx { tmp_device_real_part1.reserve(opts_init.n_sd_max); } - if((allow_sstp_cond && opts_init.exact_sstp_cond) || n_dims==3 || opts_init.turb_cond_switch) + if((allow_sstp_cond && opts_init.exact_sstp_cond) || n_dims==3 || opts_init.turb_cond_switch || opts_init.diag_coal_tele_mass_flux) { tmp_device_real_part2.reserve(opts_init.n_sd_max); } From 16516d969e5ccba4c636d4236bdca38dad2e3e0a Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 24 Feb 2022 11:58:43 +0100 Subject: [PATCH 03/11] implement diag_coal_tele_mass_flux --- src/particles_diag.ipp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/particles_diag.ipp b/src/particles_diag.ipp index a948143a3..790e84869 100644 --- a/src/particles_diag.ipp +++ b/src/particles_diag.ipp @@ -349,6 +349,18 @@ namespace libcloudphxx assert(0 && "diag_incloud_time_mom called, but opts_init.diag_incloud_time==false"); } + // output accumulated mass flux due to coalescence teleportation + template + void particles_t::diag_coal_tele_mass_flux() + { + assert(pimpl->opts_init.diag_coal_tele_mass_flux && "diag_coal_tele_mass_flux called, but opts_init.diag_coal_tele_mass_flux==false"); + thrust::copy(pimpl->coal_tele_mass_flux.begin(), pimpl->coal_tele_mass_flux.end(), pimpl->count_mom.begin()); + + // mass flux defined in all cells + pimpl->count_n = pimpl->n_cell; + thrust::sequence(pimpl->count_ijk.begin(), pimpl->count_ijk.end()); + } + // computes mass density function for wet radii using estimator from Shima et al. (2009) template void particles_t::diag_wet_mass_dens(const real_t &rad, const real_t &sig0) From a3441f2da39718056d34d86928fe86788fc5fa4c Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 24 Feb 2022 12:21:11 +0100 Subject: [PATCH 04/11] fix diag coal tele mass transport in coal() --- src/impl/particles_impl_coal.ipp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index b0828793f..37f3dfb6a 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -102,7 +102,7 @@ namespace libcloudphxx typename tup_t > BOOST_GPU_ENABLED - void collide(tup_t tpl, const n_t &col_no, const real_t &z_a, const real_t &z_b, real_t &coal_tele_mass_flux) + void collide(tup_t tpl, const n_t &col_no, const real_t &z_a, const real_t &z_b, real_t &coal_tele_mass_flux_pp) { #if !defined(__NVCC__) using std::cbrt; @@ -115,7 +115,7 @@ namespace libcloudphxx // calculate vertical mass flux from _a to _b // teleported mass = col_no * n_b * mass_a // distance = z_b - z_a, >0 mean upward flux - coal_tele_mass_flux += (thrust::get(tpl) - thrust::get(tpl)) * col_no * thrust::get(tpl) * thrust::get(tpl) * sqrt(thrust::get(tpl)); + coal_tele_mass_flux_pp += (z_b - z_a) * col_no * thrust::get(tpl) * thrust::get(tpl) * sqrt(thrust::get(tpl)); // done later: * 4/3 PI rho_w / dt // wet radius change (eq. 13 in Shima et al. 2009) @@ -139,7 +139,7 @@ namespace libcloudphxx template struct collider { - // read-only parameters (not really, coal_tele_mass_flux is overwritten) + // read-only parameters (not really, coal_tele_mass_flux_pp is overwritten) typedef thrust::tuple< real_t, // random number (u01) real_t, // scaling factor @@ -147,9 +147,9 @@ namespace libcloudphxx thrust_size_t, thrust_size_t, // off (index within cell) real_t, // dv real_t, real_t, // z - real_t // coal_tele_mass_flux + real_t // coal_tele_mass_flux_pp > tpl_ro_t; - enum { u01_ix, scl_ix, ix_a_ix, ix_b_ix, off_a_ix, off_b_ix, dv_ix, z_a_ix, z_b_ix, coal_tele_mass_flux_ix }; + enum { u01_ix, scl_ix, ix_a_ix, ix_b_ix, off_a_ix, off_b_ix, dv_ix, z_a_ix, z_b_ix, coal_tele_mass_flux_pp_ix }; // read-write parameters = return type typedef thrust::tuple< @@ -245,7 +245,7 @@ namespace libcloudphxx rw2_a_ix, rw2_b_ix, rd3_a_ix, rd3_b_ix, vt_a_ix, vt_b_ix - >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(tpl_ro), thrust::get(tpl_ro), thrust::get(tpl_ro)); + >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(thrust::get<0>(tpl_ro_rw)), thrust::get(thrust::get<0>(tpl_ro_rw)), thrust::get(thrust::get<0>(tpl_ro_rw))); thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(na_ge_nb); // col vector for the second in a pair stores info on which one has greater multiplicity } else @@ -257,7 +257,7 @@ namespace libcloudphxx rw2_b_ix, rw2_a_ix, rd3_b_ix, rd3_a_ix, vt_b_ix, vt_a_ix - >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(tpl_ro), thrust::get(tpl_ro), thrust::get(tpl_ro)); + >(thrust::get<1>(tpl_ro_rw), col_no, thrust::get(thrust::get<0>(tpl_ro_rw)), thrust::get(thrust::get<0>(tpl_ro_rw)), thrust::get(thrust::get<0>(tpl_ro_rw))); thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(nb_gt_na); // col vector for the second in a pair stores info on which one has greater multiplicity } thrust::get(thrust::get<1>(tpl_ro_rw)) = real_t(col_no); // col vector for the first in a pair stores info on number of collisions @@ -295,7 +295,7 @@ namespace libcloudphxx if(count_n!=n_cell) thrust::fill(scl.begin(), scl.end(), real_t(0.)); if(opts_init.diag_coal_tele_mass_flux) - thrust::fill(coal_tele_mass_flux_pp.begin(), coal_tele_mass_flux_pp.end()); + thrust::fill(coal_tele_mass_flux_pp.begin(), coal_tele_mass_flux_pp.end(), real_t(0)); thrust::copy( count_mom.begin(), // input - begin @@ -529,14 +529,15 @@ namespace libcloudphxx // per-cell sum of coalescence teleportation mass flux if(opts_init.diag_coal_tele_mass_flux) { - thrust::pair< - thrust_device::vector::iterator, - typename thrust_device::vector::iterator - > it_pair = thrust::reduce_by_key( +// thrust::pair< +// thrust_device::vector::iterator, +// typename thrust_device::vector::iterator +// > + auto it_pair = thrust::reduce_by_key( // input - keys - sorted_ijk.begin(), sorted_ijk.begin()+npart, + sorted_ijk.begin(), sorted_ijk.begin()+n_part, // input - values - coal_tele_mass_flux_pp.begin(), coal_tele_mass_flux_pp.end(), + coal_tele_mass_flux_pp.begin(), // output - keys count_ijk.begin(), // output - values From a423650572e9b2afb1b358c85cd9be113aa0b374 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 24 Feb 2022 14:21:59 +0100 Subject: [PATCH 05/11] tele coal mass flux: fix --- src/impl/particles_impl_coal.ipp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 37f3dfb6a..252a71a9c 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -533,6 +533,8 @@ namespace libcloudphxx // thrust_device::vector::iterator, // typename thrust_device::vector::iterator // > + + // store sum from this step in tmp_device_real_cell auto it_pair = thrust::reduce_by_key( // input - keys sorted_ijk.begin(), sorted_ijk.begin()+n_part, @@ -541,8 +543,10 @@ namespace libcloudphxx // output - keys count_ijk.begin(), // output - values - coal_tele_mass_flux.begin() + tmp_device_real_cell.begin() ); + // add to accumulated values from previous steps + thrust::transform(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), coal_tele_mass_flux.begin(), coal_tele_mass_flux.begin(), thrust::plus()); count_n = it_pair.first - count_ijk.begin(); assert(count_n <= n_cell); From 733866cd894549e2da4d90be45afc70812f9346d Mon Sep 17 00:00:00 2001 From: pdziekan Date: Fri, 4 Mar 2022 13:59:57 +0100 Subject: [PATCH 06/11] coal tele mass flux fix --- src/impl/particles_impl_coal.ipp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 252a71a9c..9308f0e1b 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -115,7 +115,7 @@ namespace libcloudphxx // calculate vertical mass flux from _a to _b // teleported mass = col_no * n_b * mass_a // distance = z_b - z_a, >0 mean upward flux - coal_tele_mass_flux_pp += (z_b - z_a) * col_no * thrust::get(tpl) * thrust::get(tpl) * sqrt(thrust::get(tpl)); + coal_tele_mass_flux_pp = (z_b - z_a) * col_no * thrust::get(tpl) * thrust::get(tpl) * sqrt(thrust::get(tpl)); // done later: * 4/3 PI rho_w / dt // wet radius change (eq. 13 in Shima et al. 2009) @@ -534,6 +534,8 @@ namespace libcloudphxx // typename thrust_device::vector::iterator // > + thrust::fill(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), 0); + // store sum from this step in tmp_device_real_cell auto it_pair = thrust::reduce_by_key( // input - keys @@ -545,11 +547,12 @@ namespace libcloudphxx // output - values tmp_device_real_cell.begin() ); - // add to accumulated values from previous steps - thrust::transform(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), coal_tele_mass_flux.begin(), coal_tele_mass_flux.begin(), thrust::plus()); count_n = it_pair.first - count_ijk.begin(); assert(count_n <= n_cell); + + // add to accumulated values from previous steps + thrust::transform(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), coal_tele_mass_flux.begin(), coal_tele_mass_flux.begin(), thrust::plus()); } } }; From 57911548d4ec4311dc9ddb2486b2bfc8ad450883 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Wed, 9 Mar 2022 18:43:26 +0100 Subject: [PATCH 07/11] coal tele mass flux: dont permute it with sorted_id --- src/impl/particles_impl_coal.ipp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 9308f0e1b..116ca4cf7 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -354,7 +354,7 @@ namespace libcloudphxx pi_size_t, pi_size_t, // off_a & off_b pi_real_t, // dv pi_real_t, pi_real_t, // z_a & z_b - pi_real_t // col_tele_mass_flux + i_real_t // col_tele_mass_flux > > zip_ro_t; @@ -387,7 +387,7 @@ namespace libcloudphxx thrust::make_permutation_iterator(z.begin(), sorted_id.begin())+1, // mass flux caused by teleportation in the coalescence algorithm - its overwritten, not read-only! // TODO: pass it only if opts_init.diag_coal_tele_mass_flux==true - thrust::make_permutation_iterator(coal_tele_mass_flux_pp.begin(), sorted_id.begin()) + coal_tele_mass_flux_pp.begin() ) ); From e265e7a5cf5a07dceeb3e29df603729f18cd9732 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 10 Mar 2022 14:07:38 +0100 Subject: [PATCH 08/11] Revert "coal tele mass flux: dont permute it with sorted_id" This reverts commit 57911548d4ec4311dc9ddb2486b2bfc8ad450883. --- src/impl/particles_impl_coal.ipp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 116ca4cf7..9308f0e1b 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -354,7 +354,7 @@ namespace libcloudphxx pi_size_t, pi_size_t, // off_a & off_b pi_real_t, // dv pi_real_t, pi_real_t, // z_a & z_b - i_real_t // col_tele_mass_flux + pi_real_t // col_tele_mass_flux > > zip_ro_t; @@ -387,7 +387,7 @@ namespace libcloudphxx thrust::make_permutation_iterator(z.begin(), sorted_id.begin())+1, // mass flux caused by teleportation in the coalescence algorithm - its overwritten, not read-only! // TODO: pass it only if opts_init.diag_coal_tele_mass_flux==true - coal_tele_mass_flux_pp.begin() + thrust::make_permutation_iterator(coal_tele_mass_flux_pp.begin(), sorted_id.begin()) ) ); From 92a7519517f0e8a1adc4ca280ddb0a6f12d62ff7 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Thu, 10 Mar 2022 14:46:30 +0100 Subject: [PATCH 09/11] Revert "Revert "coal tele mass flux: dont permute it with sorted_id"" This reverts commit e265e7a5cf5a07dceeb3e29df603729f18cd9732. --- src/impl/particles_impl_coal.ipp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 9308f0e1b..116ca4cf7 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -354,7 +354,7 @@ namespace libcloudphxx pi_size_t, pi_size_t, // off_a & off_b pi_real_t, // dv pi_real_t, pi_real_t, // z_a & z_b - pi_real_t // col_tele_mass_flux + i_real_t // col_tele_mass_flux > > zip_ro_t; @@ -387,7 +387,7 @@ namespace libcloudphxx thrust::make_permutation_iterator(z.begin(), sorted_id.begin())+1, // mass flux caused by teleportation in the coalescence algorithm - its overwritten, not read-only! // TODO: pass it only if opts_init.diag_coal_tele_mass_flux==true - thrust::make_permutation_iterator(coal_tele_mass_flux_pp.begin(), sorted_id.begin()) + coal_tele_mass_flux_pp.begin() ) ); From a5beaef6a22f08668b256e0e009d18b0fc612000 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Fri, 11 Mar 2022 13:26:00 +0100 Subject: [PATCH 10/11] diag coal tele: account for count_ijk --- src/impl/particles_impl_coal.ipp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index 116ca4cf7..b63b61bf1 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -529,12 +529,7 @@ namespace libcloudphxx // per-cell sum of coalescence teleportation mass flux if(opts_init.diag_coal_tele_mass_flux) { -// thrust::pair< -// thrust_device::vector::iterator, -// typename thrust_device::vector::iterator -// > - - thrust::fill(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), 0); + thrust::fill(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), 0); // TODO: not needed? // store sum from this step in tmp_device_real_cell auto it_pair = thrust::reduce_by_key( @@ -552,7 +547,14 @@ namespace libcloudphxx assert(count_n <= n_cell); // add to accumulated values from previous steps - thrust::transform(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), coal_tele_mass_flux.begin(), coal_tele_mass_flux.begin(), thrust::plus()); +// thrust::transform(tmp_device_real_cell.begin(), tmp_device_real_cell.end(), coal_tele_mass_flux.begin(), coal_tele_mass_flux.begin(), thrust::plus()); + thrust::transform( + tmp_device_real_cell.begin(), + tmp_device_real_cell.begin() + count_n, + thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), count_ijk.begin()), + thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), count_ijk.begin()), + thrust::plus() + } } }; From 15c3e01eb0d24794ca3c4e01ac2214c33b4e3015 Mon Sep 17 00:00:00 2001 From: pdziekan Date: Fri, 11 Mar 2022 13:26:41 +0100 Subject: [PATCH 11/11] diag coal tele: account for count_ijk 2 --- src/impl/particles_impl_coal.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl/particles_impl_coal.ipp b/src/impl/particles_impl_coal.ipp index b63b61bf1..ccd1d96ec 100644 --- a/src/impl/particles_impl_coal.ipp +++ b/src/impl/particles_impl_coal.ipp @@ -554,7 +554,7 @@ namespace libcloudphxx thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), count_ijk.begin()), thrust::make_permutation_iterator(coal_tele_mass_flux.begin(), count_ijk.begin()), thrust::plus() - + ); } } };