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;
446 pair_reaction_weight.
dataPtr();
448 int const n_product_data = (binary_collision_functor.m_need_product_data ? n_total_pairs : 0);
468 if (binary_collision_functor.m_computeSpeciesDensities) {
469 n1_vec.
resize(n_cells, 0.0_prt);
471 if (binary_collision_functor.m_computeSpeciesTemperatures) {
472 T1_vec.
resize(n_cells, 0.0_prt);
473 vx1_vec.
resize(n_cells, 0.0_prt);
474 vy1_vec.
resize(n_cells, 0.0_prt);
475 vz1_vec.
resize(n_cells, 0.0_prt);
476 vs1_vec.
resize(n_cells, 0.0_prt);
494 ww_weighted_sum_vec.
resize(n_cells, 0.0_prt);
495 KE_vec.
resize(n_cells, 0.0_prt);
496 px_vec.
resize(n_cells, 0.0_prt);
497 py_vec.
resize(n_cells, 0.0_prt);
498 pz_vec.
resize(n_cells, 0.0_prt);
518 std::vector<std::string>
const & real_names1 = species_1.
GetRealSoANames();
519 auto const pos1 = std::find(real_names1.begin(), real_names1.end(),
"ux_n");
520 if (pos1 != real_names1.end()) {
522 auto const u1x_ni =
static_cast<int>(std::distance(real_names1.begin(), pos1));
523 int const u1x_runtime_ni = u1x_ni - n_builtin_real;
524 u1x_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni];
525 u1y_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 1];
526 u1z_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 2];
531 u1x_before_ptr = u1x_before.
dataPtr();
532 u1y_before_ptr = u1y_before.
dataPtr();
533 u1z_before_ptr = u1z_before.
dataPtr();
540 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures", prof_findDensityTemperatures);
543 binary_collision_functor.m_computeSpeciesDensities ||
544 binary_collision_functor.m_computeSpeciesTemperatures) {
548 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::atomics", prof_findDensityTemperatures_atomics);
553 if (correct_energy_momentum) {
554 u1x_before_ptr[ip] = u1x[ip];
555 u1y_before_ptr[ip] = u1y[ip];
556 u1z_before_ptr[ip] = u1z[ip];
558 const int i_cell = bins_1_ptr[ip];
571 if (binary_collision_functor.m_computeSpeciesDensities) {
573 w1[ip]/(dV*volume_factor(bins_1_ptr[ip])));
577 if (binary_collision_functor.m_computeSpeciesTemperatures) {
594 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::finishTemperature", prof_findDensityTemperatures_finish);
599 index_type const cell_start_1 = cell_offsets_1[i_cell];
600 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
603 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
606 if (binary_collision_functor.m_computeSpeciesTemperatures) {
608 auto vx1 = vx1_in_each_cell[i_cell] * invsum;
609 auto vy1 = vy1_in_each_cell[i_cell] * invsum;
610 auto vz1 = vz1_in_each_cell[i_cell] * invsum;
611 auto vs1 = vs1_in_each_cell[i_cell] * invsum;
613 T1_in_each_cell[i_cell] = m1/(3._prt)*(vs1 -(vx1*vx1+vy1*vy1+vz1*vz1));
620 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::shuffle", prof_findDensityTemperatures_shuffle);
626 index_type const cell_start_1 = cell_offsets_1[i_cell];
627 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
630 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
645 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::LoopOverCollisions", prof_loopOverCollisions);
653 const int i_cell =
amrex::bisect( p_coll_offsets, 0, n_cells, ui_coll );
657 index_type const cell_start_1 = cell_offsets_1[i_cell];
658 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
659 index_type const cell_half_1 = (cell_start_1+cell_stop_1)/2;
662 const index_type coll_idx = ui_coll - p_coll_offsets[i_cell];
665 index_type const cell_start_pair = have_product_species?
666 p_pair_offsets[i_cell] : 0;
671 if (binary_collision_functor.m_computeSpeciesDensities) {
672 n1 = n1_in_each_cell[i_cell];
674 if (binary_collision_functor.m_computeSpeciesTemperatures) {
675 T1 = T1_in_each_cell[i_cell];
680 global_lamdb = global_debye_length_data[i_cell];
686 binary_collision_functor(
687 cell_start_1, cell_half_1,
688 cell_half_1, cell_stop_1,
689 indices_1, indices_1,
690 soa_1, soa_1, get_position_1, get_position_1,
691 n1, n1, T1, T1, global_lamdb,
692 q1, q1, m1, m1, dt, dV*volume_factor(i_cell), coll_idx,
693 cell_start_pair, p_mask, p_pair_indices_1, p_pair_indices_2,
694 p_pair_reaction_weight, p_product_data, engine);
703 product_species_vector,
706 products_mass, p_mask, products_np,
707 copy_species1, copy_species2,
708 p_pair_indices_1, p_pair_indices_2,
709 p_pair_reaction_weight, p_product_data);
711 for (
int i = 0; i < n_product_species; i++)
713 setNewParticleIDs(*(tile_products_data[i]),
static_cast<int>(products_np[i]), num_added[i]);
720 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::correctEnergyMomentum", prof_correctEnergyMomentum);
725 const int i_cell = bins_1_ptr[i1];
742 const int i_cell = bins_1_ptr[i1];
746 u1x[i1] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
747 u1y[i1] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
748 u1z[i1] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
756 amrex::Long* failed_corrections_ptr = failed_corrections.data();
766 {energy_correction_sort_by_weight_flag},
768 [=]
AMREX_GPU_DEVICE (
int i_cell,
auto energy_correction_sort_by_weight_control)
noexcept
771 index_type const cell_start_1 = cell_offsets_1[i_cell];
772 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
775 if ( cell_stop_1 - cell_start_1 <= 1 ) {
return; }
779 if (deltaEp1 != 0.) {
784 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
785 int const numCell1 = (cell_stop_1 - cell_start_1);
786 heapSortDecreasing(indices_1, w1, cell_start_1, numCell1);
790 const bool correction_failed =
792 cell_start_1, cell_stop_1, m1,
793 energy_fraction, deltaEp1);
794 if (correction_failed) {
797 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
798 u1x[ indices_1[i1] ] = u1x_before_ptr[ indices_1[i1] ];
799 u1y[ indices_1[i1] ] = u1y_before_ptr[ indices_1[i1] ];
800 u1z[ indices_1[i1] ] = u1z_before_ptr[ indices_1[i1] ];
802 int const numCell1 = (cell_stop_1 - cell_start_1);
803 if (numCell1 > np_warning_threshold) {
812 amrex::Long const num_failed_corrections = *(failed_corrections.copyToHost());
813 if (num_failed_corrections > 0) {
815 "The energy correction failed for " + std::to_string(num_failed_corrections) +
" cells " +
817 "The collisions in those cells was cancelled.");
831 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findParticlesInEachCell", prof_findParticlesInEachCell);
839 auto const n_cells =
static_cast<int>(bins_1.
numBins());
841 auto np1 = ptile_1.numParticles();
842 const auto soa_1 = ptile_1.getParticleTileData();
850 auto np2 = ptile_2.numParticles();
851 const auto soa_2 = ptile_2.getParticleTileData();
862 const int n_cells_products = have_product_species ? n_cells: 0;
869 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::computeNumberOfPairs", prof_computeNumberOfPairs);
873 const auto n_part_in_cell_1 = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
874 const auto n_part_in_cell_2 = cell_offsets_2[i_cell+1] - cell_offsets_2[i_cell];
876 if (n_part_in_cell_1 == 0 || n_part_in_cell_2 == 0) {
877 p_n_pairs_in_each_cell[i_cell] = 0;
879 p_n_pairs_in_each_cell[i_cell] =
880 amrex::max(n_part_in_cell_1,n_part_in_cell_2);
887 const index_type n_total_pairs = (n_cells_products == 0) ? 0:
889 p_n_pairs_in_each_cell, pair_offsets.data());
898 if (i_cell < n_cells)
900 const auto n_part_in_cell_1 = cell_offsets_1[i_cell+1] - cell_offsets_1[i_cell];
901 const auto n_part_in_cell_2 = cell_offsets_2[i_cell+1] - cell_offsets_2[i_cell];
902 p_n_ind_pairs_in_each_cell[i_cell] =
amrex::min(n_part_in_cell_1, n_part_in_cell_2);
906 p_n_ind_pairs_in_each_cell[i_cell] = 0;
933 pair_reaction_weight.
dataPtr();
935 int const n_product_data = (binary_collision_functor.m_need_product_data ? n_total_pairs : 0);
960 if (binary_collision_functor.m_computeSpeciesDensities) {
961 n1_vec.
resize(n_cells, 0.0_prt);
962 n2_vec.
resize(n_cells, 0.0_prt);
964 if (binary_collision_functor.m_computeSpeciesTemperatures) {
965 T1_vec.
resize(n_cells, 0.0_prt);
966 T2_vec.
resize(n_cells, 0.0_prt);
967 vx1_vec.
resize(n_cells, 0.0_prt);
968 vx2_vec.
resize(n_cells, 0.0_prt);
969 vy1_vec.
resize(n_cells, 0.0_prt);
970 vy2_vec.
resize(n_cells, 0.0_prt);
971 vz1_vec.
resize(n_cells, 0.0_prt);
972 vz2_vec.
resize(n_cells, 0.0_prt);
973 vs1_vec.
resize(n_cells, 0.0_prt);
974 vs2_vec.
resize(n_cells, 0.0_prt);
998 ww_weighted_sum_vec.
resize(n_cells, 0.0_prt);
999 KE_vec.
resize(n_cells, 0.0_prt);
1000 px_vec.
resize(n_cells, 0.0_prt);
1001 py_vec.
resize(n_cells, 0.0_prt);
1002 pz_vec.
resize(n_cells, 0.0_prt);
1022 std::vector<std::string>
const & real_names1 = species_1.
GetRealSoANames();
1023 auto const pos1 = std::find(real_names1.begin(), real_names1.end(),
"ux_n");
1024 if (pos1 != real_names1.end()) {
1026 auto const u1x_ni =
static_cast<int>(std::distance(real_names1.begin(), pos1));
1027 int const u1x_runtime_ni = u1x_ni - n_builtin_real;
1028 u1x_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni];
1029 u1y_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 1];
1030 u1z_before_ptr = soa_1.m_runtime_rdata[u1x_runtime_ni + 2];
1035 u1x_before_ptr = u1x_before.
dataPtr();
1036 u1y_before_ptr = u1y_before.
dataPtr();
1037 u1z_before_ptr = u1z_before.
dataPtr();
1049 std::vector<std::string>
const & real_names2 = species_2.
GetRealSoANames();
1050 auto const pos2 = std::find(real_names2.begin(), real_names2.end(),
"ux_n");
1051 if (pos2 != real_names2.end()) {
1053 auto const u2x_ni =
static_cast<int>(std::distance(real_names2.begin(), pos2));
1054 int const u2x_runtime_ni = u2x_ni - n_builtin_real;
1055 u2x_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni];
1056 u2y_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni + 1];
1057 u2z_before_ptr = soa_2.m_runtime_rdata[u2x_runtime_ni + 2];
1062 u2x_before_ptr = u2x_before.
dataPtr();
1063 u2y_before_ptr = u2y_before.
dataPtr();
1064 u2z_before_ptr = u2z_before.
dataPtr();
1070 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures", prof_findDensityTemperatures);
1073 binary_collision_functor.m_computeSpeciesDensities ||
1074 binary_collision_functor.m_computeSpeciesTemperatures) {
1079 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::atomics", prof_findDensityTemperatures_atomics);
1083 if (correct_energy_momentum) {
1086 const int i_cell = bins_1_ptr[i1];
1089 u1x_before_ptr[i1] = u1x[i1];
1090 u1y_before_ptr[i1] = u1y[i1];
1091 u1z_before_ptr[i1] = u1z[i1];
1105 const int i_cell = bins_2_ptr[i2];
1108 u2x_before_ptr[i2] = u2x[i2];
1109 u2y_before_ptr[i2] = u2y[i2];
1110 u2z_before_ptr[i2] = u2z[i2];
1124 if (binary_collision_functor.m_computeSpeciesDensities) {
1127 w1[ip]/(dV*volume_factor(bins_1_ptr[ip])));
1131 w2[ip]/(dV*volume_factor(bins_2_ptr[ip])));
1136 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1165 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::finishTemperature", prof_findDensityTemperatures_finish);
1168 const int i_cell = i < n_cells ? i : i - n_cells;
1172 index_type const cell_start_1 = cell_offsets_1[i_cell];
1173 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1176 index_type const cell_start_2 = cell_offsets_2[i_cell];
1177 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1180 if ( cell_stop_1 - cell_start_1 < 1 ||
1181 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1184 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1187 auto vx1 = vx1_in_each_cell[i_cell] * invsum1;
1188 auto vy1 = vy1_in_each_cell[i_cell] * invsum1;
1189 auto vz1 = vz1_in_each_cell[i_cell] * invsum1;
1190 auto vs1 = vs1_in_each_cell[i_cell] * invsum1;
1192 T1_in_each_cell[i_cell] = m1/(3._prt)*(vs1 -(vx1*vx1+vy1*vy1+vz1*vz1));
1195 auto vx2 = vx2_in_each_cell[i_cell] * invsum2;
1196 auto vy2 = vy2_in_each_cell[i_cell] * invsum2;
1197 auto vz2 = vz2_in_each_cell[i_cell] * invsum2;
1198 auto vs2 = vs2_in_each_cell[i_cell] * invsum2;
1200 T2_in_each_cell[i_cell] = m2/(3._prt)*(vs2 -(vx2*vx2+vy2*vy2+vz2*vz2));
1208 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::findDensityTemperatures::shuffle", prof_findDensityTemperatures_shuffle);
1212 const int i_cell = i < n_cells ? i : i - n_cells;
1216 index_type const cell_start_1 = cell_offsets_1[i_cell];
1217 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1220 index_type const cell_start_2 = cell_offsets_2[i_cell];
1221 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1224 if ( cell_stop_1 - cell_start_1 < 1 ||
1225 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1244 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::LoopOverCollisions", prof_loopOverCollisions);
1252 const int i_cell =
amrex::bisect( p_coll_offsets, 0, n_cells, ui_coll );
1256 index_type const cell_start_1 = cell_offsets_1[i_cell];
1257 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1259 index_type const cell_start_2 = cell_offsets_2[i_cell];
1260 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1263 const index_type coll_idx = ui_coll - p_coll_offsets[i_cell];
1266 index_type const cell_start_pair = have_product_species?
1267 p_pair_offsets[i_cell]: 0;
1276 if (binary_collision_functor.m_computeSpeciesDensities) {
1277 n1 = n1_in_each_cell[i_cell];
1278 n2 = n2_in_each_cell[i_cell];
1280 if (binary_collision_functor.m_computeSpeciesTemperatures) {
1281 T1 = T1_in_each_cell[i_cell];
1282 T2 = T2_in_each_cell[i_cell];
1287 global_lamdb = global_debye_length_data[i_cell];
1293 binary_collision_functor(
1294 cell_start_1, cell_stop_1, cell_start_2, cell_stop_2,
1295 indices_1, indices_2,
1296 soa_1, soa_2, get_position_1, get_position_2,
1297 n1, n2, T1, T2, global_lamdb,
1298 q1, q2, m1, m2, dt, dV*volume_factor(i_cell), coll_idx,
1299 cell_start_pair, p_mask, p_pair_indices_1, p_pair_indices_2,
1300 p_pair_reaction_weight, p_product_data, engine);
1310 product_species_vector,
1313 products_mass, p_mask, products_np,
1314 copy_species1, copy_species2,
1315 p_pair_indices_1, p_pair_indices_2,
1316 p_pair_reaction_weight, p_product_data);
1318 for (
int i = 0; i < n_product_species; i++)
1320 setNewParticleIDs(*(tile_products_data[i]),
static_cast<int>(products_np[i]), num_added[i]);
1327 ABLASTR_PROFILE_VAR(
"BinaryCollision::doCollisionsWithinTile::correctEnergyMomentum", prof_correctEnergyMomentum);
1334 const int i_cell = bins_1_ptr[i1];
1348 const int i_cell = bins_2_ptr[i2];
1367 const int i_cell = bins_1_ptr[i1];
1371 u1x[i1] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
1372 u1y[i1] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
1373 u1z[i1] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
1378 const int i_cell = bins_2_ptr[i2];
1382 u2x[i2] += w_factor*px_in_each_cell[i_cell]/ww_weighted_sum;
1383 u2y[i2] += w_factor*py_in_each_cell[i_cell]/ww_weighted_sum;
1384 u2z[i2] += w_factor*pz_in_each_cell[i_cell]/ww_weighted_sum;
1390 amrex::Long* failed_corrections_ptr = failed_corrections.data();
1400 {energy_correction_sort_by_weight_flag},
1402 [=]
AMREX_GPU_DEVICE (
int i_cell,
auto energy_correction_sort_by_weight_control)
noexcept
1406 index_type const cell_start_1 = cell_offsets_1[i_cell];
1407 index_type const cell_stop_1 = cell_offsets_1[i_cell+1];
1409 index_type const cell_start_2 = cell_offsets_2[i_cell];
1410 index_type const cell_stop_2 = cell_offsets_2[i_cell+1];
1413 if ( cell_stop_1 - cell_start_1 < 1 ||
1414 cell_stop_2 - cell_start_2 < 1 ) {
return; }
1417 py_in_each_cell[i_cell]*py_in_each_cell[i_cell] +
1418 pz_in_each_cell[i_cell]*pz_in_each_cell[i_cell];
1424 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
1425 w1_sum += w1[ indices_1[i1] ];
1427 u1y[ indices_1[i1] ],
1428 u1z[ indices_1[i1] ], m1);
1430 for (
index_type i2=cell_start_2; i2<cell_stop_2; ++i2) {
1431 w2_sum += w2[ indices_2[i2] ];
1433 u2y[ indices_2[i2] ],
1434 u2z[ indices_2[i2] ], m2);
1440 int const numCell1 = (cell_stop_1 - cell_start_1);
1441 int const numCell2 = (cell_stop_2 - cell_start_2);
1442 if (numCell1 == 1) {
1445 }
else if (numCell2 == 1) {
1449 const amrex::ParticleReal Etotdenom = w1_sum*KE1_after/numCell1 + w2_sum*KE2_after/numCell2;
1450 deltaEp1 = w1_sum*KE1_after/Etotdenom*deltaE/numCell1;
1451 deltaEp2 = w2_sum*KE2_after/Etotdenom*deltaE/numCell2;
1458 bool correction1_failed =
false;
1459 bool correction2_failed =
false;
1460 if (deltaEp1 != 0. && numCell1 > 1) {
1461 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
1462 heapSortDecreasing(indices_1, w1, cell_start_1, numCell1);
1465 correction1_failed =
1467 cell_start_1, cell_stop_1, m1,
1468 energy_fraction, deltaEp1);
1471 if (deltaEp2 != 0. && numCell2 > 1) {
1472 if constexpr (energy_correction_sort_by_weight_control ==
sort) {
1473 heapSortDecreasing(indices_2, w2, cell_start_2, numCell2);
1476 correction2_failed =
1478 cell_start_2, cell_stop_2, m2,
1479 energy_fraction, deltaEp2);
1482 if (correction1_failed || correction2_failed ||
1483 (numCell1 == 1 && numCell2 == 1)) {
1487 for (
index_type i1=cell_start_1; i1<cell_stop_1; ++i1) {
1488 u1x[ indices_1[i1] ] = u1x_before_ptr[ indices_1[i1] ];
1489 u1y[ indices_1[i1] ] = u1y_before_ptr[ indices_1[i1] ];
1490 u1z[ indices_1[i1] ] = u1z_before_ptr[ indices_1[i1] ];
1492 for (
index_type i2=cell_start_2; i2<cell_stop_2; ++i2) {
1493 u2x[ indices_2[i2] ] = u2x_before_ptr[ indices_2[i2] ];
1494 u2y[ indices_2[i2] ] = u2y_before_ptr[ indices_2[i2] ];
1495 u2z[ indices_2[i2] ] = u2z_before_ptr[ indices_2[i2] ];
1497 if ((correction1_failed && numCell1 > np_warning_threshold) ||
1498 (correction2_failed && numCell2 > np_warning_threshold)) {
1507 amrex::Long const num_failed_corrections = *(failed_corrections.copyToHost());
1508 if (num_failed_corrections > 0) {
1510 "The energy correction failed for " + std::to_string(num_failed_corrections) +
" cells " +
1512 "The collisions in those cells was cancelled.");