299 constexpr int getpos_offset = 0;
300 for (
int i = 0; i < n_product_species; i++)
302 ParticleTileType& ptile_product = product_species_vector[i]->ParticlesAt(lev, mfi);
303 tile_products.push_back(&ptile_product);
306 products_np.push_back(ptile_product.numParticles());
307 products_mass.push_back(product_species_vector[i]->getMass());
309 auto *tile_products_data = tile_products.data();
317 global_debye_length_data = global_debye_length_fab.
dataPtr();
323#if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE)
325#if defined(WARPX_DIM_RZ)
328 int const nr = hi.x - lo.x + 1;
332 auto const dr = geom_lev.
CellSize(0);
336#if defined(WARPX_DIM_RZ)
339 int const ri = i_cell % nr;
343#elif defined(WARPX_DIM_RCYLINDER)
344 int const ri = i_cell;
348#elif defined(WARPX_DIM_RSPHERE)
350 int const ri = i_cell;
367 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findParticlesInEachCell", prof_findParticlesInEachCell);
374 auto const n_cells =
static_cast<int>(bins_1.
numBins());
376 auto np1 = ptile_1.numParticles();
377 const auto soa_1 = ptile_1.getParticleTileData();
388 const int n_cells_products = have_product_species ? n_cells: 0;
395 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::computeNumberOfPairs", prof_computeNumberOfPairs);
399 const auto n_part_in_cell = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
401 p_n_pairs_in_each_cell[i_cell] = (n_part_in_cell == 1)? 0: (n_part_in_cell+1)/2;
407 const index_type n_total_pairs = (n_cells_products == 0) ? 0:
409 p_n_pairs_in_each_cell, pair_offsets.data());
418 const auto n_part_in_cell = (i_cell < n_cells)? cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell]: 0;
420 p_n_ind_pairs_in_each_cell[i_cell] = n_part_in_cell/2;
445 pair_reaction_weight.
dataPtr();
447 int const n_product_data = (binary_collision_functor.m_need_product_data ? n_total_pairs : 0);
467 if (binary_collision_functor.m_computeSpeciesDensities) {
468 n1_vec.
resize(n_cells, 0.0_prt);
470 if (binary_collision_functor.m_computeSpeciesTemperatures) {
471 T1_vec.
resize(n_cells, 0.0_prt);
472 vx1_vec.
resize(n_cells, 0.0_prt);
473 vy1_vec.
resize(n_cells, 0.0_prt);
474 vz1_vec.
resize(n_cells, 0.0_prt);
475 vs1_vec.
resize(n_cells, 0.0_prt);
493 ww_weighted_sum_vec.
resize(n_cells, 0.0_prt);
494 KE_vec.
resize(n_cells, 0.0_prt);
495 px_vec.
resize(n_cells, 0.0_prt);
496 py_vec.
resize(n_cells, 0.0_prt);
497 pz_vec.
resize(n_cells, 0.0_prt);
517 std::vector<std::string>
const & real_names1 = species_1.
GetRealSoANames();
518 auto const pos1 = std::find(real_names1.begin(), real_names1.end(),
"ux_n");
519 if (pos1 != real_names1.end()) {
521 auto const u1x_ni =
static_cast<int>(std::distance(real_names1.begin(), pos1));
522 int const u1x_runtime_ni = u1x_ni - n_builtin_real;
523 u1x_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni];
524 u1y_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 1];
525 u1z_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 2];
530 u1x_before_ptr = u1x_before.
dataPtr();
531 u1y_before_ptr = u1y_before.
dataPtr();
532 u1z_before_ptr = u1z_before.
dataPtr();
539 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures", prof_findDensityTemperatures);
542 binary_collision_functor.m_computeSpeciesDensities ||
543 binary_collision_functor.m_computeSpeciesTemperatures) {
547 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::atomics", prof_findDensityTemperatures_atomics);
552 if (correct_energy_momentum) {
553 u1x_before_ptr[ip] = u1x[ip];
554 u1y_before_ptr[ip] = u1y[ip];
555 u1z_before_ptr[ip] = u1z[ip];
557 const int i_cell = bins_1_ptr[ip];
570 if (binary_collision_functor.m_computeSpeciesDensities) {
572 w1[ip]/(dV*volume_factor(bins_1_ptr[ip])));
576 if (binary_collision_functor.m_computeSpeciesTemperatures) {
593 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::finishTemperature", prof_findDensityTemperatures_finish);
598 index_type const cell_start_1 = cell_offsets_1[i_cell];
599 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
602 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
605 if (binary_collision_functor.m_computeSpeciesTemperatures) {
607 auto vx1 = vx1_in_each_cell[i_cell] * invsum;
608 auto vy1 = vy1_in_each_cell[i_cell] * invsum;
609 auto vz1 = vz1_in_each_cell[i_cell] * invsum;
610 auto vs1 = vs1_in_each_cell[i_cell] * invsum;
612 T1_in_each_cell[i_cell] = m1/(3._prt)*(vs1 -(vx1*vx1+vy1*vy1+vz1*vz1));
619 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::shuffle", prof_findDensityTemperatures_shuffle);
625 index_type const cell_start_1 = cell_offsets_1[i_cell];
626 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
629 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
644 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::LoopOverCollisions", prof_loopOverCollisions);
652 const int i_cell =
amrex::bisect( p_coll_offsets, 0, n_cells, ui_coll );
656 index_type const cell_start_1 = cell_offsets_1[i_cell];
657 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
658 index_type const cell_half_1 = (cell_start_1+cell_stop_1)/2;
661 const index_type coll_idx = ui_coll - p_coll_offsets[i_cell];
664 index_type const cell_start_pair = have_product_species?
665 p_pair_offsets[i_cell] : 0;
670 if (binary_collision_functor.m_computeSpeciesDensities) {
671 n1 = n1_in_each_cell[i_cell];
673 if (binary_collision_functor.m_computeSpeciesTemperatures) {
674 T1 = T1_in_each_cell[i_cell];
679 global_lamdb = global_debye_length_data[i_cell];
685 binary_collision_functor(
686 cell_start_1, cell_half_1,
687 cell_half_1, cell_stop_1,
688 indices_1, indices_1,
689 soa_1, soa_1, get_position_1, get_position_1,
690 n1, n1, T1, T1, global_lamdb,
691 q1, q1, m1, m1, dt, dV*volume_factor(i_cell), coll_idx,
692 cell_start_pair, p_mask, p_pair_indices_1, p_pair_indices_2,
693 p_pair_reaction_weight, p_product_data, engine);
702 product_species_vector,
705 products_mass, p_mask, products_np,
706 copy_species1, copy_species2,
707 p_pair_indices_1, p_pair_indices_2,
708 p_pair_reaction_weight, p_product_data);
710 for (
int i = 0; i < n_product_species; i++)
712 setNewParticleIDs(*(tile_products_data[i]),
static_cast<int>(products_np[i]), num_added[i]);
719 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::correctEnergyMomentum", prof_correctEnergyMomentum);
724 const int i_cell = bins_1_ptr[i1];
741 const int i_cell = bins_1_ptr[i1];
745 u1x[i1] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
746 u1y[i1] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
747 u1z[i1] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
755 amrex::Long* failed_corrections_ptr = failed_corrections.data();
765 {energy_correction_sort_by_weight_flag},
767 [=]
AMREX_GPU_DEVICE (
int i_cell,
auto energy_correction_sort_by_weight_control)
noexcept
770 index_type const cell_start_1 = cell_offsets_1[i_cell];
771 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
774 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
778 if (deltaEp1 != 0.) {
783 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
784 int const numCell1 = (cell_stop_1 - cell_start_1);
785 heapSortDecreasing(indices_1, w1, cell_start_1, numCell1);
789 const bool correction_failed =
791 cell_start_1, cell_stop_1, m1,
792 energy_fraction, deltaEp1);
793 if (correction_failed) {
796 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
797 u1x[ indices_1[i1] ] = u1x_before_ptr[ indices_1[i1] ];
798 u1y[ indices_1[i1] ] = u1y_before_ptr[ indices_1[i1] ];
799 u1z[ indices_1[i1] ] = u1z_before_ptr[ indices_1[i1] ];
801 int const numCell1 = (cell_stop_1 - cell_start_1);
802 if (numCell1 > np_warning_threshold) {
811 amrex::Long const num_failed_corrections = *(failed_corrections.copyToHost());
812 if (num_failed_corrections > 0) {
814 "The energy correction failed for " + std::to_string(num_failed_corrections) +
" cells " +
816 "The collisions in those cells was cancelled.");
830 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findParticlesInEachCell", prof_findParticlesInEachCell);
838 auto const n_cells =
static_cast<int>(bins_1.
numBins());
840 auto np1 = ptile_1.numParticles();
841 const auto soa_1 = ptile_1.getParticleTileData();
849 auto np2 = ptile_2.numParticles();
850 const auto soa_2 = ptile_2.getParticleTileData();
861 const int n_cells_products = have_product_species ? n_cells: 0;
868 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::computeNumberOfPairs", prof_computeNumberOfPairs);
872 const auto n_part_in_cell_1 = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
873 const auto n_part_in_cell_2 = cell_offsets_2[i_cell+1] - cell_offsets_2[i_cell];
875 if (n_part_in_cell_1 == 0 || n_part_in_cell_2 == 0) {
876 p_n_pairs_in_each_cell[i_cell] = 0;
878 p_n_pairs_in_each_cell[i_cell] =
879 amrex::max(n_part_in_cell_1,n_part_in_cell_2);
886 const index_type n_total_pairs = (n_cells_products == 0) ? 0:
888 p_n_pairs_in_each_cell, pair_offsets.data());
897 if (i_cell < n_cells)
899 const auto n_part_in_cell_1 = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
900 const auto n_part_in_cell_2 = cell_offsets_2[i_cell+1] - cell_offsets_2[i_cell];
901 p_n_ind_pairs_in_each_cell[i_cell] =
amrex::min(n_part_in_cell_1, n_part_in_cell_2);
905 p_n_ind_pairs_in_each_cell[i_cell] = 0;
931 pair_reaction_weight.
dataPtr();
933 int const n_product_data = (binary_collision_functor.m_need_product_data ? n_total_pairs : 0);
958 if (binary_collision_functor.m_computeSpeciesDensities) {
959 n1_vec.
resize(n_cells, 0.0_prt);
960 n2_vec.
resize(n_cells, 0.0_prt);
962 if (binary_collision_functor.m_computeSpeciesTemperatures) {
963 T1_vec.
resize(n_cells, 0.0_prt);
964 T2_vec.
resize(n_cells, 0.0_prt);
965 vx1_vec.
resize(n_cells, 0.0_prt);
966 vx2_vec.
resize(n_cells, 0.0_prt);
967 vy1_vec.
resize(n_cells, 0.0_prt);
968 vy2_vec.
resize(n_cells, 0.0_prt);
969 vz1_vec.
resize(n_cells, 0.0_prt);
970 vz2_vec.
resize(n_cells, 0.0_prt);
971 vs1_vec.
resize(n_cells, 0.0_prt);
972 vs2_vec.
resize(n_cells, 0.0_prt);
996 ww_weighted_sum_vec.
resize(n_cells, 0.0_prt);
997 KE_vec.
resize(n_cells, 0.0_prt);
998 px_vec.
resize(n_cells, 0.0_prt);
999 py_vec.
resize(n_cells, 0.0_prt);
1000 pz_vec.
resize(n_cells, 0.0_prt);
1020 std::vector<std::string>
const & real_names1 = species_1.
GetRealSoANames();
1021 auto const pos1 = std::find(real_names1.begin(), real_names1.end(),
"ux_n");
1022 if (pos1 != real_names1.end()) {
1024 auto const u1x_ni =
static_cast<int>(std::distance(real_names1.begin(), pos1));
1025 int const u1x_runtime_ni = u1x_ni - n_builtin_real;
1026 u1x_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni];
1027 u1y_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 1];
1028 u1z_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 2];
1033 u1x_before_ptr = u1x_before.
dataPtr();
1034 u1y_before_ptr = u1y_before.
dataPtr();
1035 u1z_before_ptr = u1z_before.
dataPtr();
1047 std::vector<std::string>
const & real_names2 = species_2.
GetRealSoANames();
1048 auto const pos2 = std::find(real_names2.begin(), real_names2.end(),
"ux_n");
1049 if (pos2 != real_names2.end()) {
1051 auto const u2x_ni =
static_cast<int>(std::distance(real_names2.begin(), pos2));
1052 int const u2x_runtime_ni = u2x_ni - n_builtin_real;
1053 u2x_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni];
1054 u2y_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni + 1];
1055 u2z_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni + 2];
1060 u2x_before_ptr = u2x_before.
dataPtr();
1061 u2y_before_ptr = u2y_before.
dataPtr();
1062 u2z_before_ptr = u2z_before.
dataPtr();
1068 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures", prof_findDensityTemperatures);
1071 binary_collision_functor.m_computeSpeciesDensities ||
1072 binary_collision_functor.m_computeSpeciesTemperatures) {
1077 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::atomics", prof_findDensityTemperatures_atomics);
1081 if (correct_energy_momentum) {
1084 const int i_cell = bins_1_ptr[i1];
1087 u1x_before_ptr[i1] = u1x[i1];
1088 u1y_before_ptr[i1] = u1y[i1];
1089 u1z_before_ptr[i1] = u1z[i1];
1103 const int i_cell = bins_2_ptr[i2];
1106 u2x_before_ptr[i2] = u2x[i2];
1107 u2y_before_ptr[i2] = u2y[i2];
1108 u2z_before_ptr[i2] = u2z[i2];
1122 if (binary_collision_functor.m_computeSpeciesDensities) {
1125 w1[ip]/(dV*volume_factor(bins_1_ptr[ip])));
1129 w2[ip]/(dV*volume_factor(bins_2_ptr[ip])));
1134 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1163 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::finishTemperature", prof_findDensityTemperatures_finish);
1166 const int i_cell = i < n_cells ? i : i - n_cells;
1170 index_type const cell_start_1 = cell_offsets_1[i_cell];
1171 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1174 index_type const cell_start_2 = cell_offsets_2[i_cell];
1175 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1178 if ( cell_stop_1 - cell_start_1 < 1 ||
1179 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1182 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1185 auto vx1 = vx1_in_each_cell[i_cell] * invsum1;
1186 auto vy1 = vy1_in_each_cell[i_cell] * invsum1;
1187 auto vz1 = vz1_in_each_cell[i_cell] * invsum1;
1188 auto vs1 = vs1_in_each_cell[i_cell] * invsum1;
1190 T1_in_each_cell[i_cell] = m1/(3._prt)*(vs1 -(vx1*vx1+vy1*vy1+vz1*vz1));
1193 auto vx2 = vx2_in_each_cell[i_cell] * invsum2;
1194 auto vy2 = vy2_in_each_cell[i_cell] * invsum2;
1195 auto vz2 = vz2_in_each_cell[i_cell] * invsum2;
1196 auto vs2 = vs2_in_each_cell[i_cell] * invsum2;
1198 T2_in_each_cell[i_cell] = m2/(3._prt)*(vs2 -(vx2*vx2+vy2*vy2+vz2*vz2));
1206 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::shuffle", prof_findDensityTemperatures_shuffle);
1210 const int i_cell = i < n_cells ? i : i - n_cells;
1214 index_type const cell_start_1 = cell_offsets_1[i_cell];
1215 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1218 index_type const cell_start_2 = cell_offsets_2[i_cell];
1219 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1222 if ( cell_stop_1 - cell_start_1 < 1 ||
1223 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1242 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::LoopOverCollisions", prof_loopOverCollisions);
1250 const int i_cell =
amrex::bisect( p_coll_offsets, 0, n_cells, ui_coll );
1254 index_type const cell_start_1 = cell_offsets_1[i_cell];
1255 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1257 index_type const cell_start_2 = cell_offsets_2[i_cell];
1258 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1261 const index_type coll_idx = ui_coll - p_coll_offsets[i_cell];
1264 index_type const cell_start_pair = have_product_species?
1265 p_pair_offsets[i_cell]: 0;
1274 if (binary_collision_functor.m_computeSpeciesDensities) {
1275 n1 = n1_in_each_cell[i_cell];
1276 n2 = n2_in_each_cell[i_cell];
1278 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1279 T1 = T1_in_each_cell[i_cell];
1280 T2 = T2_in_each_cell[i_cell];
1285 global_lamdb = global_debye_length_data[i_cell];
1291 binary_collision_functor(
1292 cell_start_1, cell_stop_1, cell_start_2, cell_stop_2,
1293 indices_1, indices_2,
1294 soa_1, soa_2, get_position_1, get_position_2,
1295 n1, n2, T1, T2, global_lamdb,
1296 q1, q2, m1, m2, dt, dV*volume_factor(i_cell), coll_idx,
1297 cell_start_pair, p_mask, p_pair_indices_1, p_pair_indices_2,
1298 p_pair_reaction_weight, p_product_data, engine);
1308 product_species_vector,
1311 products_mass, p_mask, products_np,
1312 copy_species1, copy_species2,
1313 p_pair_indices_1, p_pair_indices_2,
1314 p_pair_reaction_weight, p_product_data);
1316 for (
int i = 0; i < n_product_species; i++)
1318 setNewParticleIDs(*(tile_products_data[i]),
static_cast<int>(products_np[i]), num_added[i]);
1325 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::correctEnergyMomentum", prof_correctEnergyMomentum);
1332 const int i_cell = bins_1_ptr[i1];
1346 const int i_cell = bins_2_ptr[i2];
1365 const int i_cell = bins_1_ptr[i1];
1369 u1x[i1] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
1370 u1y[i1] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
1371 u1z[i1] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
1376 const int i_cell = bins_2_ptr[i2];
1380 u2x[i2] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
1381 u2y[i2] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
1382 u2z[i2] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
1388 amrex::Long* failed_corrections_ptr = failed_corrections.data();
1398 {energy_correction_sort_by_weight_flag},
1400 [=]
AMREX_GPU_DEVICE (
int i_cell,
auto energy_correction_sort_by_weight_control)
noexcept
1404 index_type const cell_start_1 = cell_offsets_1[i_cell];
1405 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1407 index_type const cell_start_2 = cell_offsets_2[i_cell];
1408 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1411 if ( cell_stop_1 - cell_start_1 < 1 ||
1412 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1415 py_in_each_cell[i_cell]*py_in_each_cell[i_cell] +
1416 pz_in_each_cell[i_cell]*pz_in_each_cell[i_cell];
1422 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
1423 w1_sum += w1[ indices_1[i1] ];
1425 u1y[ indices_1[i1] ],
1426 u1z[ indices_1[i1] ], m1);
1428 for (
index_type i2=cell_start_2; i2<cell_stop_2; ++i2) {
1429 w2_sum += w2[ indices_2[i2] ];
1431 u2y[ indices_2[i2] ],
1432 u2z[ indices_2[i2] ], m2);
1438 int const numCell1 = (cell_stop_1 - cell_start_1);
1439 int const numCell2 = (cell_stop_2 - cell_start_2);
1440 if (numCell1 == 1) {
1443 }
else if (numCell2 == 1) {
1447 const amrex::ParticleReal Etotdenom = w1_sum*KE1_after/numCell1 + w2_sum*KE2_after/numCell2;
1448 deltaEp1 = w1_sum*KE1_after/Etotdenom*deltaE/numCell1;
1449 deltaEp2 = w2_sum*KE2_after/Etotdenom*deltaE/numCell2;
1456 bool correction1_failed =
false;
1457 bool correction2_failed =
false;
1458 if (deltaEp1 != 0. && numCell1 > 1) {
1459 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
1460 heapSortDecreasing(indices_1, w1, cell_start_1, numCell1);
1463 correction1_failed =
1465 cell_start_1, cell_stop_1, m1,
1466 energy_fraction, deltaEp1);
1469 if (deltaEp2 != 0. && numCell2 > 1) {
1470 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
1471 heapSortDecreasing(indices_2, w2, cell_start_2, numCell2);
1474 correction2_failed =
1476 cell_start_2, cell_stop_2, m2,
1477 energy_fraction, deltaEp2);
1480 if (correction1_failed || correction2_failed ||
1481 (numCell1 == 1 && numCell2 == 1)) {
1485 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
1486 u1x[ indices_1[i1] ] = u1x_before_ptr[ indices_1[i1] ];
1487 u1y[ indices_1[i1] ] = u1y_before_ptr[ indices_1[i1] ];
1488 u1z[ indices_1[i1] ] = u1z_before_ptr[ indices_1[i1] ];
1490 for (
index_type i2=cell_start_2; i2<cell_stop_2; ++i2) {
1491 u2x[ indices_2[i2] ] = u2x_before_ptr[ indices_2[i2] ];
1492 u2y[ indices_2[i2] ] = u2y_before_ptr[ indices_2[i2] ];
1493 u2z[ indices_2[i2] ] = u2z_before_ptr[ indices_2[i2] ];
1495 if ((correction1_failed && numCell1 > np_warning_threshold) ||
1496 (correction2_failed && numCell2 > np_warning_threshold)) {
1505 amrex::Long const num_failed_corrections = *(failed_corrections.copyToHost());
1506 if (num_failed_corrections > 0) {
1508 "The energy correction failed for " + std::to_string(num_failed_corrections) +
" cells " +
1510 "The collisions in those cells was cancelled.");