diff --git a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H index 84e0fef8c9c..0ba49e9b09f 100644 --- a/Source/Particles/Collision/BinaryCollision/BinaryCollision.H +++ b/Source/Particles/Collision/BinaryCollision/BinaryCollision.H @@ -8,6 +8,7 @@ #define WARPX_PARTICLES_COLLISION_BINARYCOLLISION_H_ #include "Particles/Collision/BinaryCollision/Coulomb/PairWiseCoulombCollisionFunc.H" +#include "Particles/Collision/BinaryCollision/Coulomb/ComputeTemperature.H" #include "Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H" #include "Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H" #include "Particles/Collision/BinaryCollision/ParticleCreationFunc.H" @@ -360,6 +361,21 @@ public: End of calculations only required when creating product particles */ + // create vectors to store density and temperature on cell level + amrex::Gpu::DeviceVector n1_vec; + amrex::Gpu::DeviceVector n12_vec; + amrex::Gpu::DeviceVector T1_vec; + if (binary_collision_functor.m_computeSpeciesDensities) { + n1_vec.resize(n_cells); + n12_vec.resize(n_cells); + } + if (binary_collision_functor.m_computeSpeciesTemperatures) { + T1_vec.resize(n_cells); + } + amrex::ParticleReal* AMREX_RESTRICT n1_in_each_cell = n1_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT n12_in_each_cell = n12_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT T1_in_each_cell = T1_vec.dataPtr(); + // Loop over cells amrex::ParallelForRNG( n_cells, [=] AMREX_GPU_DEVICE (int i_cell, amrex::RandomEngine const& engine) noexcept @@ -368,12 +384,60 @@ public: // given by the `indices_1[cell_start_1:cell_stop_1]` index_type const cell_start_1 = cell_offsets_1[i_cell]; index_type const cell_stop_1 = cell_offsets_1[i_cell+1]; + index_type const cell_half_1 = (cell_start_1+cell_stop_1)/2; // Do not collide if there is only one particle in the cell if ( cell_stop_1 - cell_start_1 <= 1 ) { return; } + // compute local density [1/m^3] + if (binary_collision_functor.m_computeSpeciesDensities) { + amrex::ParticleReal wtot1 = 0.0; + amrex::ParticleReal * const AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w]; + for (index_type i1=cell_start_1; i1 n1_vec, n2_vec; + amrex::Gpu::DeviceVector n12_vec; + amrex::Gpu::DeviceVector T1_vec, T2_vec; + if (binary_collision_functor.m_computeSpeciesDensities) { + n1_vec.resize(n_cells); + n2_vec.resize(n_cells); + n12_vec.resize(n_cells); + } + if (binary_collision_functor.m_computeSpeciesTemperatures) { + T1_vec.resize(n_cells); + T2_vec.resize(n_cells); + } + amrex::ParticleReal* AMREX_RESTRICT n1_in_each_cell = n1_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT n2_in_each_cell = n2_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT n12_in_each_cell = n12_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT T1_in_each_cell = T1_vec.dataPtr(); + amrex::ParticleReal* AMREX_RESTRICT T2_in_each_cell = T2_vec.dataPtr(); // Loop over cells amrex::ParallelForRNG( n_cells, @@ -579,6 +675,43 @@ public: // ux_1[ indices_1[i] ], where i is between // cell_start_1 (inclusive) and cell_start_2 (exclusive) + // compute local densities [1/m^3] + if (binary_collision_functor.m_computeSpeciesDensities) { + amrex::ParticleReal w1tot = 0.0; + amrex::ParticleReal w2tot = 0.0; + amrex::ParticleReal * const AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w]; + amrex::ParticleReal * const AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w]; + for (index_type i1=cell_start_1; i1 /*get_position_1*/, GetParticlePosition /*get_position_2*/, + amrex::ParticleReal const n1, amrex::ParticleReal const n2, + amrex::ParticleReal const n12, + amrex::ParticleReal const T1, amrex::ParticleReal const T2, amrex::ParticleReal const q1, amrex::ParticleReal const q2, amrex::ParticleReal const m1, amrex::ParticleReal const m2, - amrex::Real const dt, amrex::Real const dV, index_type coll_idx, + amrex::Real const dt, amrex::Real const /*dV*/, index_type coll_idx, index_type const /*cell_start_pair*/, index_type* /*p_mask*/, index_type* /*p_pair_indices_1*/, index_type* /*p_pair_indices_2*/, amrex::ParticleReal* /*p_pair_reaction_weight*/, @@ -99,12 +105,14 @@ public: ElasticCollisionPerez( I1s, I1e, I2s, I2e, I1, I2, - soa_1, soa_2, - q1, q2, m1, m2, -1.0_prt, -1.0_prt, - dt, m_CoulombLog, dV, engine, m_isSameSpecies, coll_idx); + soa_1, soa_2, n1, n2, n12, T1, T2, + q1, q2, m1, m2, + dt, m_CoulombLog, engine, coll_idx); } amrex::ParticleReal m_CoulombLog; + bool m_computeSpeciesDensities = true; + bool m_computeSpeciesTemperatures = false; bool m_isSameSpecies; }; diff --git a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H index f28f3fb984c..152dca4e1a1 100644 --- a/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H +++ b/Source/Particles/Collision/BinaryCollision/DSMC/DSMCFunc.H @@ -96,6 +96,9 @@ public: index_type const* AMREX_RESTRICT I2, const SoaData_type& soa_1, const SoaData_type& soa_2, GetParticlePosition /*get_position_1*/, GetParticlePosition /*get_position_2*/, + amrex::ParticleReal const /*n1*/, amrex::ParticleReal const /*n2*/, + amrex::ParticleReal const /*n12*/, + amrex::ParticleReal const /*T1*/, amrex::ParticleReal const /*T2*/, amrex::ParticleReal const /*q1*/, amrex::ParticleReal const /*q2*/, amrex::ParticleReal const m1, amrex::ParticleReal const m2, amrex::Real const dt, amrex::Real const dV, index_type coll_idx, @@ -189,6 +192,8 @@ public: } int m_process_count; + bool m_computeSpeciesDensities = false; + bool m_computeSpeciesTemperatures = false; ScatteringProcess::Executor* m_scattering_processes_data; }; diff --git a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H index b6d6fe171de..1f3e5e56582 100644 --- a/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H +++ b/Source/Particles/Collision/BinaryCollision/NuclearFusion/NuclearFusionFunc.H @@ -131,6 +131,9 @@ public: index_type const* AMREX_RESTRICT I2, const SoaData_type& soa_1, const SoaData_type& soa_2, GetParticlePosition /*get_position_1*/, GetParticlePosition /*get_position_2*/, + amrex::ParticleReal const /*n1*/, amrex::ParticleReal const /*n2*/, + amrex::ParticleReal const /*n12*/, + amrex::ParticleReal const /*T1*/, amrex::ParticleReal const /*T2*/, amrex::ParticleReal const /*q1*/, amrex::ParticleReal const /*q2*/, amrex::ParticleReal const m1, amrex::ParticleReal const m2, amrex::Real const dt, amrex::Real const dV, index_type coll_idx, @@ -232,6 +235,8 @@ public: amrex::ParticleReal m_probability_threshold; amrex::ParticleReal m_probability_target_value; NuclearFusionType m_fusion_type; + bool m_computeSpeciesDensities = false; + bool m_computeSpeciesTemperatures = false; bool m_isSameSpecies; };