diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/Diagnostics/ReducedDiags/BeamRelevant.cpp | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp index b194ca9ff..53f697ed8 100644 --- a/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp +++ b/Source/Diagnostics/ReducedDiags/BeamRelevant.cpp @@ -23,18 +23,12 @@ BeamRelevant::BeamRelevant (std::string rd_name) : ReducedDiags{rd_name} { -#if (defined WARPX_DIM_RZ) - // RZ coordinate is not working - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(false, - "BeamRelevant reduced diagnostics does not work for RZ coordinate."); -#endif - // read beam name ParmParse pp(rd_name); pp.get("species",m_beam_name); // resize data array -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) // 0, 1, 2: mean x,y,z // 3, 4, 5: mean px,py,pz // 6: gamma @@ -44,7 +38,7 @@ BeamRelevant::BeamRelevant (std::string rd_name) // 14,15,16: emittance x,y,z // 17: charge m_data.resize(18,0.0); -#elif (AMREX_SPACEDIM == 2) +#elif (defined WARPX_DIM_XZ) // 0, 1: mean x,z // 2, 3, 4: mean px,py,pz // 5: gamma @@ -65,7 +59,7 @@ BeamRelevant::BeamRelevant (std::string rd_name) ofs.open(m_path + m_rd_name + "." + m_extension, std::ofstream::out | std::ofstream::app); // write header row -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) ofs << "#"; ofs << "[1]step()"; ofs << m_sep; ofs << "[2]time(s)"; ofs << m_sep; @@ -87,7 +81,7 @@ BeamRelevant::BeamRelevant (std::string rd_name) ofs << "[18]emittance_y(m)"; ofs << m_sep; ofs << "[19]emittance_z(m)"; ofs << m_sep; ofs << "[20]charge(C)"; ofs << std::endl; -#elif (AMREX_SPACEDIM == 2) +#elif (defined WARPX_DIM_XZ) ofs << "#"; ofs << "[1]step()"; ofs << m_sep; ofs << "[2]time(s)"; ofs << m_sep; @@ -135,9 +129,9 @@ void BeamRelevant::ComputeDiags (int step) Real constexpr inv_c2 = 1.0 / (PhysConst::c * PhysConst::c); // If 2D-XZ, p.pos(1) is z, rather than p.pos(2). -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D) int const index_z = 2; -#elif (AMREX_SPACEDIM == 2) +#elif (defined WARPX_DIM_XZ || defined WARPX_DIM_RZ) int const index_z = 1; #endif @@ -173,16 +167,28 @@ void BeamRelevant::ComputeDiags (int step) return; } +#if (defined WARPX_DIM_RZ) + // x mean + Real x_mean = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { return p.pos(0)*std::cos(p.rdata(PIdx::theta)) * p.rdata(PIdx::w); }); +#else // x mean Real x_mean = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real { return p.pos(0) * p.rdata(PIdx::w); }); +#endif -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D) // y mean Real y_mean = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real { return p.pos(1) * p.rdata(PIdx::w); }); +#elif (defined WARPX_DIM_RZ) + // y mean + Real y_mean = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { return p.pos(0)*std::sin(p.rdata(PIdx::theta)) * p.rdata(PIdx::w); }); #endif // z mean @@ -218,7 +224,7 @@ void BeamRelevant::ComputeDiags (int step) // reduced sum over mpi ranks ParallelDescriptor::ReduceRealSum(x_mean); x_mean /= w_sum; -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) ParallelDescriptor::ReduceRealSum(y_mean); y_mean /= w_sum; #endif ParallelDescriptor::ReduceRealSum(z_mean); z_mean /= w_sum; @@ -227,6 +233,16 @@ void BeamRelevant::ComputeDiags (int step) ParallelDescriptor::ReduceRealSum(uz_mean); uz_mean /= w_sum; ParallelDescriptor::ReduceRealSum(gm_mean); gm_mean /= w_sum; +#if (defined WARPX_DIM_RZ) + // x mean square + Real x_ms = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { + Real const x = p.pos(0)*std::cos(p.rdata(PIdx::theta)); + Real const a = (x-x_mean) * (x-x_mean); + return a * p.rdata(PIdx::w); + }); +#else // x mean square Real x_ms = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real @@ -234,8 +250,9 @@ void BeamRelevant::ComputeDiags (int step) Real const a = (p.pos(0)-x_mean) * (p.pos(0)-x_mean); return a * p.rdata(PIdx::w); }); +#endif -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D) // y mean square Real y_ms = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real @@ -243,6 +260,15 @@ void BeamRelevant::ComputeDiags (int step) Real const a = (p.pos(1)-y_mean) * (p.pos(1)-y_mean); return a * p.rdata(PIdx::w); }); +#elif (defined WARPX_DIM_RZ) + // y mean square + Real y_ms = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { + Real const y = p.pos(0)*std::sin(p.rdata(PIdx::theta)); + Real const a = (y-y_mean) * (y-y_mean); + return a * p.rdata(PIdx::w); + }); #endif // z mean square @@ -293,6 +319,16 @@ void BeamRelevant::ComputeDiags (int step) return a * p.rdata(PIdx::w); }); +#if (defined WARPX_DIM_RZ) + // x times ux + Real xux = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { + Real const x = p.pos(0)*std::cos(p.rdata(PIdx::theta)); + Real const a = (x-x_mean) * (p.rdata(PIdx::ux)-ux_mean); + return a * p.rdata(PIdx::w); + }); +#else // x times ux Real xux = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real @@ -300,8 +336,9 @@ void BeamRelevant::ComputeDiags (int step) Real const a = (p.pos(0)-x_mean) * (p.rdata(PIdx::ux)-ux_mean); return a * p.rdata(PIdx::w); }); +#endif -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D) // y times uy Real yuy = ReduceSum( myspc, [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real @@ -309,6 +346,15 @@ void BeamRelevant::ComputeDiags (int step) Real const a = (p.pos(1)-y_mean) * (p.rdata(PIdx::uy)-uy_mean); return a * p.rdata(PIdx::w); }); +#elif (defined WARPX_DIM_RZ) + // y times uy + Real yuy = ReduceSum( myspc, + [=] AMREX_GPU_HOST_DEVICE (const PType& p) -> Real + { + Real const y = p.pos(0)*std::sin(p.rdata(PIdx::theta)); + Real const a = (y-y_mean) * (p.rdata(PIdx::uy)-uy_mean); + return a * p.rdata(PIdx::w); + }); #endif // z times uz @@ -331,7 +377,7 @@ void BeamRelevant::ComputeDiags (int step) ParallelDescriptor::ReduceRealSum ( x_ms, ParallelDescriptor::IOProcessorNumber()); x_ms /= w_sum; -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) ParallelDescriptor::ReduceRealSum ( y_ms, ParallelDescriptor::IOProcessorNumber()); y_ms /= w_sum; @@ -354,7 +400,7 @@ void BeamRelevant::ComputeDiags (int step) ParallelDescriptor::ReduceRealSum ( xux, ParallelDescriptor::IOProcessorNumber()); xux /= w_sum; -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) ParallelDescriptor::ReduceRealSum ( yuy, ParallelDescriptor::IOProcessorNumber()); yuy /= w_sum; @@ -366,7 +412,7 @@ void BeamRelevant::ComputeDiags (int step) ( charge, ParallelDescriptor::IOProcessorNumber()); // save data -#if (AMREX_SPACEDIM == 3) +#if (defined WARPX_DIM_3D || defined WARPX_DIM_RZ) m_data[0] = x_mean; m_data[1] = y_mean; m_data[2] = z_mean; @@ -385,7 +431,7 @@ void BeamRelevant::ComputeDiags (int step) m_data[15] = std::sqrt(y_ms*uy_ms-yuy*yuy) / PhysConst::c; m_data[16] = std::sqrt(z_ms*uz_ms-zuz*zuz) / PhysConst::c; m_data[17] = charge; -#elif (AMREX_SPACEDIM == 2) +#elif (defined WARPX_DIM_XZ) m_data[0] = x_mean; m_data[1] = z_mean; m_data[2] = ux_mean * m; |