From b59083bd3d030f4e8debdab81e7b73d93f8bae23 Mon Sep 17 00:00:00 2001 From: Justin Angus Date: Sat, 17 Aug 2024 18:54:08 -0700 Subject: [PATCH] reducing duplicate coding. --- .../NuclearFusion/NuclearFusionFunc.H | 75 +++++++++---------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H index da74acf2a5a..14b1422db27 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H @@ -181,59 +181,54 @@ public: if (idcpu1[ I1[i1] ]==amrex::ParticleIdCpus::Invalid || idcpu2[ I2[i2] ]==amrex::ParticleIdCpus::Invalid ) { p_mask[pair_index] = false; - if (max_N == NI1) { i1 += min_N; } - if (max_N == NI2) { i2 += min_N; } - pair_index += min_N; - continue; } + else { #if (defined WARPX_DIM_RZ) - /* In RZ geometry, macroparticles can collide with other macroparticles - * in the same *cylindrical* cell. For this reason, collisions between macroparticles - * are actually not local in space. In this case, the underlying assumption is that - * particles within the same cylindrical cell represent a cylindrically-symmetry - * momentum distribution function. Therefore, here, we temporarily rotate the - * momentum of one of the macroparticles in agreement with this cylindrical symmetry. - * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; - * there is a corresponding assert statement at initialization.) */ - amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; - amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); - u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); + /* In RZ geometry, macroparticles can collide with other macroparticles + * in the same *cylindrical* cell. For this reason, collisions between macroparticles + * are actually not local in space. In this case, the underlying assumption is that + * particles within the same cylindrical cell represent a cylindrically-symmetry + * momentum distribution function. Therefore, here, we temporarily rotate the + * momentum of one of the macroparticles in agreement with this cylindrical symmetry. + * (This is technically only valid if we use only the m=0 azimuthal mode in the simulation; + * there is a corresponding assert statement at initialization.) */ + amrex::ParticleReal const theta = theta2[I2[i2]]-theta1[I1[i1]]; + amrex::ParticleReal const u1xbuf = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf*std::cos(theta) - u1y[I1[i1]]*std::sin(theta); + u1y[I1[i1]] = u1xbuf*std::sin(theta) + u1y[I1[i1]]*std::cos(theta); #endif - SingleNuclearFusionEvent( - u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], - u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], - m1, m2, w1[ I1[i1] ], w2[ I2[i2] ], - dt, dV, static_cast(pair_index), p_mask, p_pair_reaction_weight, - m_fusion_multiplier, multiplier_ratio, - m_probability_threshold, - m_probability_target_value, - m_fusion_type, engine); + SingleNuclearFusionEvent( + u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ], + u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ], + m1, m2, w1[ I1[i1] ], w2[ I2[i2] ], + dt, dV, static_cast(pair_index), p_mask, p_pair_reaction_weight, + m_fusion_multiplier, multiplier_ratio, + m_probability_threshold, + m_probability_target_value, + m_fusion_type, engine); #if (defined WARPX_DIM_RZ) - amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; - u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); - u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); + amrex::ParticleReal const u1xbuf_new = u1x[I1[i1]]; + u1x[I1[i1]] = u1xbuf_new*std::cos(-theta) - u1y[I1[i1]]*std::sin(-theta); + u1y[I1[i1]] = u1xbuf_new*std::sin(-theta) + u1y[I1[i1]]*std::cos(-theta); #endif - // Remove pair reaction weight from the colliding particles' weights - if (p_mask[pair_index]) { - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w1[ I1[i1] ], idcpu1[ I1[i1] ], p_pair_reaction_weight[pair_index]); - BinaryCollisionUtils::remove_weight_from_colliding_particle( - w2[ I2[i2] ], idcpu2[ I2[i2] ], p_pair_reaction_weight[pair_index]); + // Remove pair reaction weight from the colliding particles' weights + if (p_mask[pair_index]) { + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w1[ I1[i1] ], idcpu1[ I1[i1] ], p_pair_reaction_weight[pair_index]); + BinaryCollisionUtils::remove_weight_from_colliding_particle( + w2[ I2[i2] ], idcpu2[ I2[i2] ], p_pair_reaction_weight[pair_index]); + } + } p_pair_indices_1[pair_index] = I1[i1]; p_pair_indices_2[pair_index] = I2[i2]; - if (max_N == NI1) { - i1 += min_N; - } - if (max_N == NI2) { - i2 += min_N; - } + if (max_N == NI1) { i1 += min_N; } + if (max_N == NI2) { i2 += min_N; } pair_index += min_N; } }