From e9a44ff2aa521201b448a76d5dedfa839c998dfa Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 17 Jan 2025 14:43:14 +0100 Subject: [PATCH 001/123] add m_plot_EM flag --- Source/Diagnostics/ParticleDiag/ParticleDiag.H | 1 + Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index 45bc596a78e..33dc4dc1931 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -24,6 +24,7 @@ public: [[nodiscard]] std::string getSpeciesName() const { return m_name; } amrex::Vector m_plot_flags; bool m_plot_phi = false; // Whether to output the potential phi on the particles + bool m_plot_EM = false; // Whether to output the E and B fields on the particles bool m_do_random_filter = false; bool m_do_uniform_filter = false; diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 1a64ae20f0e..c78f80cb00b 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -42,11 +42,14 @@ ParticleDiag::ParticleDiag ( existing_variable_names["y"] = PIdx::theta; #endif for (const auto& var : variables){ + // User can request phi and/or EM fields on particles. These are *not* part of the variables that + // the particle container carries, and are only added to particles during output. + // Therefore, these cases need to be treated specifically. if (var == "phi") { - // User requests phi on particle. This is *not* part of the variables that - // the particle container carries, and is only added to particles during output. - // Therefore, this case needs to be treated specifically. m_plot_phi = true; + } else if (var=="EM") { + m_plot_EM = true; + } } else { const auto search = existing_variable_names.find(var); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( From bb1947cfbf6ee0d6c8d8a1302ab0d41d4273a96b Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 17 Jan 2025 15:43:22 +0100 Subject: [PATCH 002/123] create storeEMFieldsOnParticles function --- Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 1 - Source/Diagnostics/ParticleIO.cpp | 10 ++++++++-- Source/Diagnostics/WarpXOpenPMD.cpp | 3 +++ Source/Particles/ParticleIO.H | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index c78f80cb00b..0403290c6d7 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -49,7 +49,6 @@ ParticleDiag::ParticleDiag ( m_plot_phi = true; } else if (var=="EM") { m_plot_EM = true; - } } else { const auto search = existing_variable_names.find(var); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 05c44f5f594..e60326e6a9f 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -7,11 +7,12 @@ * License: BSD-3-Clause-LBNL */ -#include "Fields.H" #include "Particles/ParticleIO.H" + +#include "Fields.H" +#include "Particles/LaserParticleContainer.H" #include "Particles/MultiParticleContainer.H" #include "Particles/PhysicalParticleContainer.H" -#include "Particles/LaserParticleContainer.H" #include "Particles/RigidInjectedParticleContainer.H" #include "Particles/SpeciesPhysicalProperties.H" #include "Particles/WarpXParticleContainer.H" @@ -293,3 +294,8 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, } } } + +void +storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp ) { + +} \ No newline at end of file diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index e38ae8c8300..8148a7600aa 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -590,6 +590,9 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { if ( particle_diags[i].m_plot_phi ) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } + if ( particle_diags[i].m_plot_EM ) { + storeEMFieldsOnParticles( tmp ); + } // names of amrex::Real and int particle attributes in SoA data amrex::Vector real_names; diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 8d3516e6890..a875195494f 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -92,4 +92,6 @@ void storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, ElectrostaticSolverAlgo electrostatic_solver_id, bool is_full_diagnostic ); +void +storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp ); #endif /* WARPX_PARTICLEIO_H_ */ From 36381755179d2e1c1680b4a18c6627593c6dcb83 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 17 Jan 2025 17:28:33 +0100 Subject: [PATCH 003/123] First particle EM fields diagnostics draft (not working) --- Source/Diagnostics/ParticleIO.cpp | 104 +++++++++++++++++++++++++++- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- Source/Particles/ParticleIO.H | 3 +- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e60326e6a9f..2e050271c08 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -296,6 +296,108 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, } void -storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp ) { +storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, + ElectromagneticSolverAlgo electromagnetic_solver_id, bool is_full_diagnostic ) { + + using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; + using Dir = ablastr::fields::Direction; + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + electromagnetic_solver_id != ElectromagneticSolverAlgo::None , + "output of the electromagnetic fields on the particles was requested, " + "but this is only available with an electromagnetic solver."); + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + is_full_diagnostic, + "Output of the electromagnetic fields on the particles was requested, " + "but this is only available with `diag_type = Full`."); + + + tmp.NewRealComp("Ex"); + tmp.NewRealComp("Ey"); + tmp.NewRealComp("Ez"); + tmp.NewRealComp("Bx"); + tmp.NewRealComp("By"); + tmp.NewRealComp("Bz"); + + int const Ex_index = tmp.getParticleComps().at("Ex"); + int const Ey_index = tmp.getParticleComps().at("Ey"); + int const Ez_index = tmp.getParticleComps().at("Ez"); + int const Bx_index = tmp.getParticleComps().at("Bx"); + int const By_index = tmp.getParticleComps().at("By"); + int const Bz_index = tmp.getParticleComps().at("Bz"); + + auto& warpx = WarpX::GetInstance(); + + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + warpx.finestLevel() ==0, + "output of the electromagnetic fields on particles only works without mesh refinement" + ); + + constexpr auto lev0=0; + + const amrex::Geometry& geom = warpx.Geom(lev0); + auto plo = geom.ProbLoArray(); + auto dxi = geom.InvCellSizeArray(); + amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_fp, Dir{0}, lev0); + amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_fp, Dir{1}, lev0); + amrex::MultiFab const& Ez = *warpx.m_fields.get(FieldType::Efield_fp, Dir{2}, lev0); + amrex::MultiFab const& Bx = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{0}, lev0); + amrex::MultiFab const& By = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{1}, lev0); + amrex::MultiFab const& Bz = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{2}, lev0); + + const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); + const bool galerkin_interpolation = WarpX::galerkin_interpolation; + const int nox = WarpX::nox; + const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; + +#ifdef AMREX_USE_OMP +#pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (PinnedParIter pti(tmp, lev0); pti.isValid(); ++pti) { + + const auto Ex_grid = Ex[pti].array(); + const auto Ey_grid = Ey[pti].array(); + const auto Ez_grid = Ez[pti].array(); + const auto Bx_grid = Bx[pti].array(); + const auto By_grid = By[pti].array(); + const auto Bz_grid = Bz[pti].array(); + + const auto ex_type = Ex.ixType(); + const auto ey_type = Ey.ixType(); + const auto ez_type = Ez.ixType(); + const auto bx_type = Bx.ixType(); + const auto by_type = By.ixType(); + const auto bz_type = Bz.ixType(); + + const auto getPosition = GetParticlePosition(pti); + amrex::ParticleReal* Ex_particle_arr = pti.GetStructOfArrays().GetRealData(Ex_index).dataPtr(); + amrex::ParticleReal* Ey_particle_arr = pti.GetStructOfArrays().GetRealData(Ey_index).dataPtr(); + amrex::ParticleReal* Ez_particle_arr = pti.GetStructOfArrays().GetRealData(Ez_index).dataPtr(); + amrex::ParticleReal* Bx_particle_arr = pti.GetStructOfArrays().GetRealData(Bx_index).dataPtr(); + amrex::ParticleReal* By_particle_arr = pti.GetStructOfArrays().GetRealData(By_index).dataPtr(); + amrex::ParticleReal* Bz_particle_arr = pti.GetStructOfArrays().GetRealData(Bz_index).dataPtr(); + + const auto box = pti.tilebox(); + const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev0, 0._rt); + const Dim3 lo = lbound(box); + + // Loop over the particles and update their position + amrex::ParallelFor( pti.numParticles(), + [=] AMREX_GPU_DEVICE (long ip) { + // !!!!!!!!!! pas fini + amrex::ParticleReal xp, yp, zp; + getPosition(ip, xp, yp, zp); + + doGatherShapeN( + xp, yp, zp, + Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], + Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip], + Ex_grid, Ey_grid, Ez_grid, + Bx_grid, By_grid, Bz_grid, + ex_type, ey_type, ez_type, + bx_type, by_type, bz_type, + dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation); + }); + } } \ No newline at end of file diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 8148a7600aa..e5a6a60a926 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -591,7 +591,7 @@ for (unsigned i = 0, n = particle_diags.size(); i < n; ++i) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } if ( particle_diags[i].m_plot_EM ) { - storeEMFieldsOnParticles( tmp ); + storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); // !!!!!!!!!!!!! why use_pinned_pc here? and not full_diag ???? } // names of amrex::Real and int particle attributes in SoA data diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index a875195494f..18e7232cf9b 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -93,5 +93,6 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, ElectrostaticSolverAlgo electrostatic_solver_id, bool is_full_diagnostic ); void -storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp ); +storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, + ElectromagneticSolverAlgo electromagnetic_solver_id, bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From dafb2acb8713ec6307edde3281ed2523fd38955d Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 21 Jan 2025 15:30:16 +0100 Subject: [PATCH 004/123] fixed nan --- Source/Diagnostics/ParticleIO.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 2e050271c08..9016e4043c4 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -388,6 +388,13 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); + Ex_particle_arr[ip] = 0._rt; + Ey_particle_arr[ip] = 0._rt; + Ez_particle_arr[ip] = 0._rt; + Bx_particle_arr[ip] = 0._rt; + By_particle_arr[ip] = 0._rt; + Bz_particle_arr[ip] = 0._rt; + doGatherShapeN( xp, yp, zp, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], From c010ec55d97323cfa909e91201a4786d8cd476e0 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 4 Feb 2025 16:17:43 +0100 Subject: [PATCH 005/123] added CI tests for EM diags on particles --- Examples/Tests/CMakeLists.txt | 1 + .../EM_fields_on_particles/CMakeLists.txt | 13 ++ .../EM_fields_on_particles/analysis_2d.py | 170 ++++++++++++++++++ .../analysis_default_regression.py | 1 + .../Tests/EM_fields_on_particles/input_2d | 86 +++++++++ .../test_2d_particle_EM_diagnostics.json | 25 +++ 6 files changed, 296 insertions(+) create mode 100644 Examples/Tests/EM_fields_on_particles/CMakeLists.txt create mode 100755 Examples/Tests/EM_fields_on_particles/analysis_2d.py create mode 120000 Examples/Tests/EM_fields_on_particles/analysis_default_regression.py create mode 100644 Examples/Tests/EM_fields_on_particles/input_2d create mode 100644 Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json diff --git a/Examples/Tests/CMakeLists.txt b/Examples/Tests/CMakeLists.txt index c4713123ae6..5a602428390 100644 --- a/Examples/Tests/CMakeLists.txt +++ b/Examples/Tests/CMakeLists.txt @@ -18,6 +18,7 @@ add_subdirectory(embedded_boundary_diffraction) add_subdirectory(embedded_boundary_python_api) add_subdirectory(embedded_boundary_rotated_cube) add_subdirectory(embedded_circle) +add_subdirectory(EM_fields_on_particles) add_subdirectory(energy_conserving_thermal_plasma) add_subdirectory(field_probe) add_subdirectory(flux_injection) diff --git a/Examples/Tests/EM_fields_on_particles/CMakeLists.txt b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt new file mode 100644 index 00000000000..2b193e166d4 --- /dev/null +++ b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt @@ -0,0 +1,13 @@ +# add tests + +add_warpx_test( + test_2d_particle_EM_diagnostics # name + 2 # dims + 2 # nprocs + input_2d # inputs + "analysis_2d.py" # analysis + "analysis_default_regression.py --path diags/diag_checksum/" # checksum + OFF # dependency +) + + diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py new file mode 100755 index 00000000000..7dc901c2063 --- /dev/null +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python3 + +import numpy as np +from adios2 import Stream + +from scipy.signal import hilbert +from scipy.interpolate import interp1d +from scipy.optimize import minimize + +c = 3e8 +lambda_laser = 800e-9 +T_laser = lambda_laser / c # utile ? + +E_max = 3.26e10 +T_peak = 10e-15 +tau = 5e-15 +delta_t = 1.6e-6 / c # time for the laser to reach the particle + +n_diags = 401 +ex_t = np.zeros((n_diags,)) +ey_t = np.zeros((n_diags,)) +ez_t = np.zeros((n_diags,)) +bx_t = np.zeros((n_diags,)) +by_t = np.zeros((n_diags,)) +bz_t = np.zeros((n_diags,)) + +elec_d = lambda x: f'/data/particles/electron/{x}/__data__' + +# Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries +# This is because the variable based encoding is still experimental +# and OpenPMDTimeSeries does not support it at the time of writing +# If there are only a few diagnostics, using file-based encoding will +# work, but opening/closing files creates A LOT of overhead and +# with a lot of saved iterations the reading time grows very fast +# +# This example should be updated in the future when OpenPMDTimeSeries +# supports variable-based encoding +with Stream('diags/diag1/openpmd.bp', 'r') as s: + for _ in s.steps(): + i = s.current_step() + ex_t[i] = s.read(elec_d('ex')).item() + ey_t[i] = s.read(elec_d('ey')).item() + ez_t[i] = s.read(elec_d('ez')).item() + bx_t[i] = s.read(elec_d('bx')).item() + by_t[i] = s.read(elec_d('by')).item() + bz_t[i] = s.read(elec_d('bz')).item() + +DT = 6.324524234e-17 # @ CFL = 0.99 +# on pourrait juste lire l'input file.... +iterations = np.linspace(0,n_diags-1, n_diags) +T = (iterations * DT) - DT/2 + +T_peak_part = T_peak + delta_t +Ey_max = E_max * 1 / np.sqrt(5) # polarisation vector (0 1 2) +Ez_max = E_max * np.sqrt( 1 - 1/5 ) +By_max = Ez_max / c +Bz_max = Ey_max / c + +def get_laser_th(E_0, T_p, T, tau, T_laser, phi=0): + alpha = np.exp(-(T-T_peak_part)**2 / (tau**2) ) + return E_0 * alpha * np.cos( 2 * np.pi * ( T - T_p ) / T_laser + phi ) + +Ey_th = get_laser_th(Ey_max, T_peak_part, T, tau, T_laser) +Ez_th = get_laser_th(Ez_max, T_peak_part, T, tau, T_laser) +By_th = get_laser_th(By_max, T_peak_part, T, tau, T_laser, phi=np.pi) +Bz_th = get_laser_th(Bz_max, T_peak_part, T, tau, T_laser) + +Ey_th = np.where(T >= delta_t, Ey_th, 0) +Ez_th = np.where(T >= delta_t, Ez_th, 0) +By_th = np.where(T >= delta_t, By_th, 0) +Bz_th = np.where(T >= delta_t, Bz_th, 0) + +# due to injection method the simulated fields have a slight dephasing +# wrt the theoretical field +# here we compute the dephasing and correct it on the theoretical field +def align_cost(shift, sig1, sig2, time): + # Create an interpolation function for the signal to be shifted + interp_func = interp1d(time, sig1, kind='linear', fill_value="extrapolate") + shifted_sig1 = interp_func(time + shift) + # MSE + cost = np.mean((shifted_sig1 - sig2) ** 2) + return cost + +init_shift = 0.0 +res = minimize( + align_cost, + init_shift, + args=(Ey_th, ey_t, T), + method='Nelder-Mead', + options={'xatol': 1e-20, 'fatol':1e-20, 'maxiter':10000} +) +opt_shift = res.x[0] + +interp_func_ey = interp1d(T, Ey_th, kind='cubic', fill_value='extrapolate') +interp_func_ez = interp1d(T, Ez_th, kind='cubic', fill_value='extrapolate') +interp_func_by = interp1d(T, By_th, kind='cubic', fill_value='extrapolate') +interp_func_bz = interp1d(T, Bz_th, kind='cubic', fill_value='extrapolate') + +Ey_aligned = interp_func_ey(T + opt_shift) +Ez_aligned = interp_func_ez(T + opt_shift) +By_aligned = interp_func_by(T + opt_shift) +Bz_aligned = interp_func_bz(T + opt_shift) + +# verif + +# E.1 + +assert np.allclose(np.zeros(ex_t.shape), ex_t, rtol=0, atol=5e-4) + +# E.2 + +ey_p = ey_t[T>=delta_t] +Ey_p = Ey_aligned[T>=delta_t] +ey_p += 1e11 +Ey_p += 1e11 + +ez_p = ez_t[T>=delta_t] +Ez_p = Ez_aligned[T>=delta_t] +ez_p += 1e11 +Ez_p += 1e11 + +assert np.allclose(ey_p, Ey_p, rtol=8e-4, atol=0) +assert np.allclose(ez_p, Ez_p, rtol=2e-3, atol=0) + +# E.3 + +ey_m = ey_t[T=delta_t] +By_p = By_aligned[T>=delta_t] +by_p += 1e3 +By_p += 1e3 + +bz_p = bz_t[T>=delta_t] +Bz_p = Bz_aligned[T>=delta_t] +bz_p += 1e3 +Bz_p += 1e3 + +assert np.allclose(by_p, By_p, rtol=8e-4, atol=0) +assert np.allclose(bz_p, Bz_p, rtol=4e-4, atol=0) + +# B.3 + +by_m = by_t[T Date: Tue, 4 Feb 2025 15:26:06 +0000 Subject: [PATCH 006/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../EM_fields_on_particles/CMakeLists.txt | 2 - .../EM_fields_on_particles/analysis_2d.py | 115 +++++++++--------- .../Tests/EM_fields_on_particles/input_2d | 7 +- Source/Diagnostics/ParticleIO.cpp | 32 ++--- Source/Particles/ParticleIO.H | 2 +- 5 files changed, 79 insertions(+), 79 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/CMakeLists.txt b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt index 2b193e166d4..0e5a7dad435 100644 --- a/Examples/Tests/EM_fields_on_particles/CMakeLists.txt +++ b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt @@ -9,5 +9,3 @@ add_warpx_test( "analysis_default_regression.py --path diags/diag_checksum/" # checksum OFF # dependency ) - - diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 7dc901c2063..4686f63b1d4 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -2,64 +2,65 @@ import numpy as np from adios2 import Stream - -from scipy.signal import hilbert from scipy.interpolate import interp1d from scipy.optimize import minimize +from scipy.signal import hilbert c = 3e8 lambda_laser = 800e-9 -T_laser = lambda_laser / c # utile ? +T_laser = lambda_laser / c # utile ? E_max = 3.26e10 T_peak = 10e-15 tau = 5e-15 -delta_t = 1.6e-6 / c # time for the laser to reach the particle +delta_t = 1.6e-6 / c # time for the laser to reach the particle n_diags = 401 -ex_t = np.zeros((n_diags,)) +ex_t = np.zeros((n_diags,)) ey_t = np.zeros((n_diags,)) ez_t = np.zeros((n_diags,)) bx_t = np.zeros((n_diags,)) by_t = np.zeros((n_diags,)) bz_t = np.zeros((n_diags,)) -elec_d = lambda x: f'/data/particles/electron/{x}/__data__' +elec_d = lambda x: f"/data/particles/electron/{x}/__data__" # Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries -# This is because the variable based encoding is still experimental +# This is because the variable based encoding is still experimental # and OpenPMDTimeSeries does not support it at the time of writing # If there are only a few diagnostics, using file-based encoding will -# work, but opening/closing files creates A LOT of overhead and +# work, but opening/closing files creates A LOT of overhead and # with a lot of saved iterations the reading time grows very fast -# -# This example should be updated in the future when OpenPMDTimeSeries +# +# This example should be updated in the future when OpenPMDTimeSeries # supports variable-based encoding -with Stream('diags/diag1/openpmd.bp', 'r') as s: +with Stream("diags/diag1/openpmd.bp", "r") as s: for _ in s.steps(): i = s.current_step() - ex_t[i] = s.read(elec_d('ex')).item() - ey_t[i] = s.read(elec_d('ey')).item() - ez_t[i] = s.read(elec_d('ez')).item() - bx_t[i] = s.read(elec_d('bx')).item() - by_t[i] = s.read(elec_d('by')).item() - bz_t[i] = s.read(elec_d('bz')).item() - -DT = 6.324524234e-17 # @ CFL = 0.99 + ex_t[i] = s.read(elec_d("ex")).item() + ey_t[i] = s.read(elec_d("ey")).item() + ez_t[i] = s.read(elec_d("ez")).item() + bx_t[i] = s.read(elec_d("bx")).item() + by_t[i] = s.read(elec_d("by")).item() + bz_t[i] = s.read(elec_d("bz")).item() + +DT = 6.324524234e-17 # @ CFL = 0.99 # on pourrait juste lire l'input file.... -iterations = np.linspace(0,n_diags-1, n_diags) -T = (iterations * DT) - DT/2 +iterations = np.linspace(0, n_diags - 1, n_diags) +T = (iterations * DT) - DT / 2 T_peak_part = T_peak + delta_t -Ey_max = E_max * 1 / np.sqrt(5) # polarisation vector (0 1 2) -Ez_max = E_max * np.sqrt( 1 - 1/5 ) +Ey_max = E_max * 1 / np.sqrt(5) # polarisation vector (0 1 2) +Ez_max = E_max * np.sqrt(1 - 1 / 5) By_max = Ez_max / c Bz_max = Ey_max / c + def get_laser_th(E_0, T_p, T, tau, T_laser, phi=0): - alpha = np.exp(-(T-T_peak_part)**2 / (tau**2) ) - return E_0 * alpha * np.cos( 2 * np.pi * ( T - T_p ) / T_laser + phi ) - + alpha = np.exp(-((T - T_peak_part) ** 2) / (tau**2)) + return E_0 * alpha * np.cos(2 * np.pi * (T - T_p) / T_laser + phi) + + Ey_th = get_laser_th(Ey_max, T_peak_part, T, tau, T_laser) Ez_th = get_laser_th(Ez_max, T_peak_part, T, tau, T_laser) By_th = get_laser_th(By_max, T_peak_part, T, tau, T_laser, phi=np.pi) @@ -70,31 +71,33 @@ def get_laser_th(E_0, T_p, T, tau, T_laser, phi=0): By_th = np.where(T >= delta_t, By_th, 0) Bz_th = np.where(T >= delta_t, Bz_th, 0) -# due to injection method the simulated fields have a slight dephasing -# wrt the theoretical field + +# due to injection method the simulated fields have a slight dephasing +# wrt the theoretical field # here we compute the dephasing and correct it on the theoretical field def align_cost(shift, sig1, sig2, time): # Create an interpolation function for the signal to be shifted - interp_func = interp1d(time, sig1, kind='linear', fill_value="extrapolate") + interp_func = interp1d(time, sig1, kind="linear", fill_value="extrapolate") shifted_sig1 = interp_func(time + shift) # MSE cost = np.mean((shifted_sig1 - sig2) ** 2) return cost + init_shift = 0.0 res = minimize( - align_cost, - init_shift, + align_cost, + init_shift, args=(Ey_th, ey_t, T), - method='Nelder-Mead', - options={'xatol': 1e-20, 'fatol':1e-20, 'maxiter':10000} + method="Nelder-Mead", + options={"xatol": 1e-20, "fatol": 1e-20, "maxiter": 10000}, ) opt_shift = res.x[0] -interp_func_ey = interp1d(T, Ey_th, kind='cubic', fill_value='extrapolate') -interp_func_ez = interp1d(T, Ez_th, kind='cubic', fill_value='extrapolate') -interp_func_by = interp1d(T, By_th, kind='cubic', fill_value='extrapolate') -interp_func_bz = interp1d(T, Bz_th, kind='cubic', fill_value='extrapolate') +interp_func_ey = interp1d(T, Ey_th, kind="cubic", fill_value="extrapolate") +interp_func_ez = interp1d(T, Ez_th, kind="cubic", fill_value="extrapolate") +interp_func_by = interp1d(T, By_th, kind="cubic", fill_value="extrapolate") +interp_func_bz = interp1d(T, Bz_th, kind="cubic", fill_value="extrapolate") Ey_aligned = interp_func_ey(T + opt_shift) Ez_aligned = interp_func_ez(T + opt_shift) @@ -103,29 +106,29 @@ def align_cost(shift, sig1, sig2, time): # verif -# E.1 +# E.1 assert np.allclose(np.zeros(ex_t.shape), ex_t, rtol=0, atol=5e-4) # E.2 -ey_p = ey_t[T>=delta_t] -Ey_p = Ey_aligned[T>=delta_t] +ey_p = ey_t[T >= delta_t] +Ey_p = Ey_aligned[T >= delta_t] ey_p += 1e11 Ey_p += 1e11 -ez_p = ez_t[T>=delta_t] -Ez_p = Ez_aligned[T>=delta_t] +ez_p = ez_t[T >= delta_t] +Ez_p = Ez_aligned[T >= delta_t] ez_p += 1e11 Ez_p += 1e11 assert np.allclose(ey_p, Ey_p, rtol=8e-4, atol=0) assert np.allclose(ez_p, Ez_p, rtol=2e-3, atol=0) -# E.3 +# E.3 -ey_m = ey_t[T=delta_t] -By_p = By_aligned[T>=delta_t] +by_p = by_t[T >= delta_t] +By_p = By_aligned[T >= delta_t] by_p += 1e3 By_p += 1e3 -bz_p = bz_t[T>=delta_t] -Bz_p = Bz_aligned[T>=delta_t] +bz_p = bz_t[T >= delta_t] +Bz_p = Bz_aligned[T >= delta_t] bz_p += 1e3 Bz_p += 1e3 assert np.allclose(by_p, By_p, rtol=8e-4, atol=0) assert np.allclose(bz_p, Bz_p, rtol=4e-4, atol=0) -# B.3 +# B.3 -by_m = by_t[T Date: Tue, 4 Feb 2025 16:33:31 +0100 Subject: [PATCH 007/123] deleted unused variables --- Source/Diagnostics/ParticleIO.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9016e4043c4..7ad79499a82 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -336,8 +336,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; const amrex::Geometry& geom = warpx.Geom(lev0); - auto plo = geom.ProbLoArray(); - auto dxi = geom.InvCellSizeArray(); amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_fp, Dir{0}, lev0); amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_fp, Dir{1}, lev0); amrex::MultiFab const& Ez = *warpx.m_fields.get(FieldType::Efield_fp, Dir{2}, lev0); From bb5a285c11df23481689e73f317bbf06559030d7 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 4 Feb 2025 18:00:41 +0100 Subject: [PATCH 008/123] Fixed example lambda function and inputs name --- Examples/Tests/EM_fields_on_particles/CMakeLists.txt | 2 +- Examples/Tests/EM_fields_on_particles/analysis_2d.py | 3 ++- .../{input_2d => inputs_test_2d_particle_EM_diagnostics} | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename Examples/Tests/EM_fields_on_particles/{input_2d => inputs_test_2d_particle_EM_diagnostics} (100%) diff --git a/Examples/Tests/EM_fields_on_particles/CMakeLists.txt b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt index 0e5a7dad435..4ef51e5894e 100644 --- a/Examples/Tests/EM_fields_on_particles/CMakeLists.txt +++ b/Examples/Tests/EM_fields_on_particles/CMakeLists.txt @@ -4,7 +4,7 @@ add_warpx_test( test_2d_particle_EM_diagnostics # name 2 # dims 2 # nprocs - input_2d # inputs + inputs_test_2d_particle_EM_diagnostics # inputs "analysis_2d.py" # analysis "analysis_default_regression.py --path diags/diag_checksum/" # checksum OFF # dependency diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 4686f63b1d4..1a8a0cedd37 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -23,7 +23,8 @@ by_t = np.zeros((n_diags,)) bz_t = np.zeros((n_diags,)) -elec_d = lambda x: f"/data/particles/electron/{x}/__data__" +def elec_d(x): + return f"/data/particles/electron/{x}/__data__" # Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries # This is because the variable based encoding is still experimental diff --git a/Examples/Tests/EM_fields_on_particles/input_2d b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics similarity index 100% rename from Examples/Tests/EM_fields_on_particles/input_2d rename to Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics From addaf67e96314c171d1f789a271b361d7c1459a6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:09:12 +0000 Subject: [PATCH 009/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Examples/Tests/EM_fields_on_particles/analysis_2d.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 1a8a0cedd37..37fab11239f 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -23,9 +23,11 @@ by_t = np.zeros((n_diags,)) bz_t = np.zeros((n_diags,)) + def elec_d(x): return f"/data/particles/electron/{x}/__data__" + # Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries # This is because the variable based encoding is still experimental # and OpenPMDTimeSeries does not support it at the time of writing From 4de04088572c3295f47a69f90c2d71195a1e9247 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 4 Feb 2025 18:11:09 +0100 Subject: [PATCH 010/123] removed unused variable geom --- Source/Diagnostics/ParticleIO.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index ca37f70bd50..1ff1640a44e 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -335,7 +335,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; - const amrex::Geometry& geom = warpx.Geom(lev0); amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_fp, Dir{0}, lev0); amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_fp, Dir{1}, lev0); amrex::MultiFab const& Ez = *warpx.m_fields.get(FieldType::Efield_fp, Dir{2}, lev0); From 3c08a8b6abd958e6b6d8c9d4dbcceda1eaa41c38 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 4 Feb 2025 18:29:48 +0100 Subject: [PATCH 011/123] Fixed undefined identifier --- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 872809ef5e1..50623970456 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -590,7 +590,7 @@ for (const auto & particle_diag : particle_diags) { if ( particle_diag.m_plot_phi ) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } - if ( particle_diags[i].m_plot_EM ) { + if ( particle_diags.m_plot_EM ) { storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); // !!!!!!!!!!!!! why use_pinned_pc here? and not full_diag ???? } From 18275a289958809b88547162cd1da96290db704c Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 4 Feb 2025 18:35:09 +0100 Subject: [PATCH 012/123] fixed no member error --- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 50623970456..c42552116a9 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -590,7 +590,7 @@ for (const auto & particle_diag : particle_diags) { if ( particle_diag.m_plot_phi ) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } - if ( particle_diags.m_plot_EM ) { + if ( particle_diag.m_plot_EM ) { storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); // !!!!!!!!!!!!! why use_pinned_pc here? and not full_diag ???? } From 8c50b0b901e81ce2a2b14cfd6dd821cf85866af3 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 5 Feb 2025 11:22:32 +0100 Subject: [PATCH 013/123] Removed adios2 from test --- .../EM_fields_on_particles/analysis_2d.py | 18 ++++++++++++++++-- .../inputs_test_2d_particle_EM_diagnostics | 5 ++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 37fab11239f..a064721096c 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -5,6 +5,7 @@ from scipy.interpolate import interp1d from scipy.optimize import minimize from scipy.signal import hilbert +from openpmd_viewer import OpenPMDTimeSeries c = 3e8 lambda_laser = 800e-9 @@ -15,7 +16,19 @@ tau = 5e-15 delta_t = 1.6e-6 / c # time for the laser to reach the particle +ts_particle = OpenPMDTimeSeries("diags/diag1/") + +ex_t, ey_t, ez_t, bx_t, by_t, bz_t = ts_particle.iterate(ts_particle.get_particle, ['ex', 'ey', 'ez', 'bx', 'by', 'bz'], species='electron') + +ex_t = np.squeeze(ex_t) +ey_t = np.squeeze(ey_t) +ez_t = np.squeeze(ez_t) +bx_t = np.squeeze(bx_t) +by_t = np.squeeze(by_t) +bz_t = np.squeeze(bz_t) + n_diags = 401 +""" ex_t = np.zeros((n_diags,)) ey_t = np.zeros((n_diags,)) ez_t = np.zeros((n_diags,)) @@ -26,7 +39,7 @@ def elec_d(x): return f"/data/particles/electron/{x}/__data__" - + """ # Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries # This is because the variable based encoding is still experimental @@ -37,6 +50,7 @@ def elec_d(x): # # This example should be updated in the future when OpenPMDTimeSeries # supports variable-based encoding +""" with Stream("diags/diag1/openpmd.bp", "r") as s: for _ in s.steps(): i = s.current_step() @@ -45,7 +59,7 @@ def elec_d(x): ez_t[i] = s.read(elec_d("ez")).item() bx_t[i] = s.read(elec_d("bx")).item() by_t[i] = s.read(elec_d("by")).item() - bz_t[i] = s.read(elec_d("bz")).item() + bz_t[i] = s.read(elec_d("bz")).item() """ DT = 6.324524234e-17 # @ CFL = 0.99 # on pourrait juste lire l'input file.... diff --git a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics index d65ae3bcd70..779abd3b377 100644 --- a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics +++ b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics @@ -68,8 +68,7 @@ diagnostics.diags_names = diag1 diag_checksum diag1.intervals = 1 diag1.diag_type = Full diag1.format = openpmd -diag1.openpmd_backend = bp -diag1.openpmd_encoding = v +diag1.openpmd_backend = h5 diag1.fields_to_plot = none diag1.write_species = 1 diag1.species = electron @@ -78,7 +77,7 @@ diag1.electron.variables = EM # will emit a warning because no position diag_checksum.intervals = 400:400 diag_checksum.diag_type = Full diag_checksum.format = openpmd -diag_checksum.openpmd_backend = bp +diag_checksum.openpmd_backend = h5 diag_checksum.fields_to_plot = Ex Ey Ez Bx By Bz diag_checksum.write_species = 1 diag_checksum.species = electron From c381d56a9932e85030a17376e144cfb3121b6ece Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Feb 2025 10:22:49 +0000 Subject: [PATCH 014/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Examples/Tests/EM_fields_on_particles/analysis_2d.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index a064721096c..c8299134136 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import numpy as np -from adios2 import Stream +from openpmd_viewer import OpenPMDTimeSeries from scipy.interpolate import interp1d from scipy.optimize import minimize from scipy.signal import hilbert -from openpmd_viewer import OpenPMDTimeSeries c = 3e8 lambda_laser = 800e-9 @@ -18,7 +17,9 @@ ts_particle = OpenPMDTimeSeries("diags/diag1/") -ex_t, ey_t, ez_t, bx_t, by_t, bz_t = ts_particle.iterate(ts_particle.get_particle, ['ex', 'ey', 'ez', 'bx', 'by', 'bz'], species='electron') +ex_t, ey_t, ez_t, bx_t, by_t, bz_t = ts_particle.iterate( + ts_particle.get_particle, ["ex", "ey", "ez", "bx", "by", "bz"], species="electron" +) ex_t = np.squeeze(ex_t) ey_t = np.squeeze(ey_t) @@ -50,7 +51,7 @@ def elec_d(x): # # This example should be updated in the future when OpenPMDTimeSeries # supports variable-based encoding -""" +""" with Stream("diags/diag1/openpmd.bp", "r") as s: for _ in s.steps(): i = s.current_step() From 800494ebdc5d0e1c9f69f044ac1550b8c248b580 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:26:40 +0100 Subject: [PATCH 015/123] Update Source/Diagnostics/ParticleIO.cpp Co-authored-by: Luca Fedeli --- Source/Diagnostics/ParticleIO.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 1ff1640a44e..f439b0450ab 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -381,7 +381,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, // Loop over the particles and update their position amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long ip) { - // !!!!!!!!!! pas fini amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); From 041e9a88230f0a096eae6dd6b749b4affc0939c1 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Wed, 5 Feb 2025 11:27:33 +0100 Subject: [PATCH 016/123] Update Source/Diagnostics/ParticleIO.cpp Co-authored-by: Luca Fedeli --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index f439b0450ab..edd012b5c28 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -378,7 +378,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev0, 0._rt); const Dim3 lo = lbound(box); - // Loop over the particles and update their position + // Loop over the particles and compute the EM field using the doGatherShapeN function amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long ip) { amrex::ParticleReal xp, yp, zp; From 4a7f71eed2724f96de9c7218ce0b1ae784039509 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Wed, 5 Feb 2025 15:37:15 +0100 Subject: [PATCH 017/123] Update Source/Diagnostics/WarpXOpenPMD.cpp Co-authored-by: Luca Fedeli --- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index c42552116a9..9d722c09ae9 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -591,7 +591,7 @@ for (const auto & particle_diag : particle_diags) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } if ( particle_diag.m_plot_EM ) { - storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); // !!!!!!!!!!!!! why use_pinned_pc here? and not full_diag ???? + storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); } // names of amrex::Real and int particle attributes in SoA data From 850006442c139a6994abe1671263d51f64f52bab Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 5 Feb 2025 17:36:11 +0100 Subject: [PATCH 018/123] Added postprocessing script and updated documentation --- Docs/source/usage/parameters.rst | 6 +- .../read_variable_based_adios2.py | 133 ++++++++++++++++++ 2 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 Tools/PostProcessing/read_variable_based_adios2.py diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index aaba7130b87..7772c9c0fad 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2782,7 +2782,7 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a * ``.openpmd_encoding`` (optional, ``v`` (variable based), ``f`` (file based) or ``g`` (group based) ) only read if ``.format = openpmd``. openPMD `file output encoding `__. File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). - ``variable based`` is an `experimental feature with ADIOS2 `__ and not supported for back-transformed diagnostics. + ``variable based`` is an `experimental feature with ADIOS2 `__ and not supported for back-transformed diagnostics. This format is also not supported by OpenPMDTimeSeries at the moment, the script :download:`read_variable_based_adios2.py <../../../Tools/PostProcessing/read_variable_based_adios2.py>` provides basic functions to read variable-based particle diagnostics directly with the ``adios2`` module. Default: ``f`` (full diagnostics) * ``.adios2_operator.type`` (``zfp``, ``blosc``) optional, @@ -2914,9 +2914,9 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a * ``..variables`` (list of `strings` separated by spaces, optional) List of particle quantities to write to output. Choices are ``x``, ``y``, ``z`` for the particle positions (3D and RZ), ``x`` & ``z`` in 2D, ``z`` in 1D, - ``w`` for the particle weight and ``ux``, ``uy``, ``uz`` for the particle momenta. + ``w`` for the particle weight, ``ux``, ``uy``, ``uz`` for the particle momenta, and ``EM`` for the electromagnetic fields. When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. - By default, all particle quantities (except ``phi``) are written. + By default, all particle quantities (except ``phi`` and ``EM``) are written. If ``..variables = none``, no particle data are written. * ``..random_fraction`` (`float`) optional diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py new file mode 100644 index 00000000000..e622741441e --- /dev/null +++ b/Tools/PostProcessing/read_variable_based_adios2.py @@ -0,0 +1,133 @@ +import numpy as np +from adios2 import Stream + +def species_path(name, field): + """ + variable based adios2 particles data is stored in /data/particles/species_name/field/__data__ + this function is only to format this path + + Note : momenta are stored as 'momentum/x' and positions as 'position/x', but EM fields are stored as 'ex' (and not 'e/x') + """ + return f'/data/particles/{name}/{field}/__data__' + +def display_avail_variables(diag_path): + """ + if you are not sure how the variable you are looking for is named, or if you + want to check which variables are stored, this function displays every variable + available + """ + with Stream(diag_path, 'r') as s: + for _ in s.steps(): + if s.current_step() == 0: + var_avail = s.available_variables() + for name, _ in var_avail.items(): + print(f'Found variable : {name}') + break + +def get_particle_data(diag_path, species_name, variables, n_iterations=-1, n_particles=-1): + """ + Retrieves the particle data for the given variables + + WARNING : depending on the case, RAM usage might be important + + INPUT: + - diag_path : str + - species names : str + - variables : array of str + optional: + - n_iterations : int, will be computed if not given + - n_particles : int, will be computed if not given + + OUTPUT: + - one array of shape (n_iterations, n_particles) per variable given + """ + if n_iterations == -1 or n_particles == -1: + if n_iterations == -1: + n_iterations = 0 + skip_for = False + with Stream(diag_path, 'r') as s: + for _ in s.steps(): + if s.current_step()==0 and n_particles == -1: + fieldPath = species_path(species_name, variables[0]) + n_particles = (s.read(fieldPath)).shape[0] + if skip_for: + break + n_iterations += 1 + + + data = np.zeros((len(variables), n_iterations, n_particles)) + # really need to check that it works before commit + + with Stream(diag_path, 'r') as s: + for _ in s.steps(): + iteration = s.current_step() + + for i, variable in enumerate(variables): + data[i, iteration, :] = s.read(species_path(species_name, variable)) + + # progress bar + if iteration % 100 == 0: + n_eg = int(20 * iteration / n_iterations) + print(f'[{n_eg * '='}{(20-n_eg) * ' '}] Iteration {iteration}', end='\r' if iteration!=n_iterations else '\n') + + return data + +def get_single_traj(x, ids, particle_id): + """ + Returns the trajectory of a single in the given space x + + INPUT : + x : numpy array + shape = (n_iterations, n_particles) + ids : numpy array + shape = (n_iterations, n_particles) + particle_id : int + id of the particle to plot + + OUTPUT : + (n_iterations,) numpy array + """ + + return x[ids == particle_id] + +def select_particles(ids, iteration, *argv): + """ + select particles by filtering values + + USAGE : + select_ids = select_particles(id_t, 8000, (ux_t, [60e-6, 90e-6])) + -> returns the ids off all particles with 60e-6 < ux < 90e-6 at iteration 8000 + + select parameters can be stacked but need to be in tuple form (array, [range]) + + INPUT : + ids : numpy array (n_iterations, n_particles) float64 + iteration : int + + *argv : tuple (numpy array (n_iterations, n_particles) , 2-numbers array-like) + + """ + id_it = np.copy(ids[iteration, :]) + selected_ids = np.copy(ids[iteration, :]) + + for arg in argv: + # check if arg is in the expected shape + if not isinstance(arg, tuple): + raise TypeError(f'expected tuple argument, got {type(arg)}') + if not isinstance(arg[0], np.ndarray): + raise TypeError(f'expected np.ndarray, got {type(arg[0])}') + if arg[0].shape != ids.shape: + raise ValueError(f'Dimensions not matching') + try: + if len(arg[1]) != 2: + raise ValueError(f'limits should contain two values, but has {len(arg[1])}') + except TypeError: + raise TypeError(f'Expected a 2 elements container, got {type(arg[1])}') + + x_it = (arg[0])[iteration, :] + selected_ids = id_it[ np.isin(id_it, selected_ids) & + (x_it >= (arg[1])[0]) & + (x_it <= (arg[1])[1]) + ] + + return selected_ids \ No newline at end of file From 3b11e01c78b45cb62346678b61e6e51a1b0ccd71 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 5 Feb 2025 16:36:23 +0000 Subject: [PATCH 019/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../read_variable_based_adios2.py | 62 +++++++++++-------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py index e622741441e..43a8f8c370e 100644 --- a/Tools/PostProcessing/read_variable_based_adios2.py +++ b/Tools/PostProcessing/read_variable_based_adios2.py @@ -1,6 +1,7 @@ import numpy as np from adios2 import Stream + def species_path(name, field): """ variable based adios2 particles data is stored in /data/particles/species_name/field/__data__ @@ -8,23 +9,27 @@ def species_path(name, field): Note : momenta are stored as 'momentum/x' and positions as 'position/x', but EM fields are stored as 'ex' (and not 'e/x') """ - return f'/data/particles/{name}/{field}/__data__' + return f"/data/particles/{name}/{field}/__data__" + def display_avail_variables(diag_path): """ if you are not sure how the variable you are looking for is named, or if you want to check which variables are stored, this function displays every variable - available + available """ - with Stream(diag_path, 'r') as s: + with Stream(diag_path, "r") as s: for _ in s.steps(): if s.current_step() == 0: var_avail = s.available_variables() for name, _ in var_avail.items(): - print(f'Found variable : {name}') + print(f"Found variable : {name}") break -def get_particle_data(diag_path, species_name, variables, n_iterations=-1, n_particles=-1): + +def get_particle_data( + diag_path, species_name, variables, n_iterations=-1, n_particles=-1 +): """ Retrieves the particle data for the given variables @@ -45,20 +50,19 @@ def get_particle_data(diag_path, species_name, variables, n_iterations=-1, n_par if n_iterations == -1: n_iterations = 0 skip_for = False - with Stream(diag_path, 'r') as s: + with Stream(diag_path, "r") as s: for _ in s.steps(): - if s.current_step()==0 and n_particles == -1: + if s.current_step() == 0 and n_particles == -1: fieldPath = species_path(species_name, variables[0]) n_particles = (s.read(fieldPath)).shape[0] if skip_for: break - n_iterations += 1 - + n_iterations += 1 data = np.zeros((len(variables), n_iterations, n_particles)) # really need to check that it works before commit - with Stream(diag_path, 'r') as s: + with Stream(diag_path, "r") as s: for _ in s.steps(): iteration = s.current_step() @@ -68,10 +72,14 @@ def get_particle_data(diag_path, species_name, variables, n_iterations=-1, n_par # progress bar if iteration % 100 == 0: n_eg = int(20 * iteration / n_iterations) - print(f'[{n_eg * '='}{(20-n_eg) * ' '}] Iteration {iteration}', end='\r' if iteration!=n_iterations else '\n') + print( + f"[{n_eg * '='}{(20 - n_eg) * ' '}] Iteration {iteration}", + end="\r" if iteration != n_iterations else "\n", + ) return data - + + def get_single_traj(x, ids, particle_id): """ Returns the trajectory of a single in the given space x @@ -79,22 +87,23 @@ def get_single_traj(x, ids, particle_id): INPUT : x : numpy array shape = (n_iterations, n_particles) - ids : numpy array + ids : numpy array shape = (n_iterations, n_particles) particle_id : int id of the particle to plot - OUTPUT : + OUTPUT : (n_iterations,) numpy array """ return x[ids == particle_id] + def select_particles(ids, iteration, *argv): """ select particles by filtering values - USAGE : + USAGE : select_ids = select_particles(id_t, 8000, (ux_t, [60e-6, 90e-6])) -> returns the ids off all particles with 60e-6 < ux < 90e-6 at iteration 8000 @@ -105,29 +114,30 @@ def select_particles(ids, iteration, *argv): iteration : int *argv : tuple (numpy array (n_iterations, n_particles) , 2-numbers array-like) - + """ id_it = np.copy(ids[iteration, :]) selected_ids = np.copy(ids[iteration, :]) - + for arg in argv: # check if arg is in the expected shape if not isinstance(arg, tuple): - raise TypeError(f'expected tuple argument, got {type(arg)}') + raise TypeError(f"expected tuple argument, got {type(arg)}") if not isinstance(arg[0], np.ndarray): - raise TypeError(f'expected np.ndarray, got {type(arg[0])}') + raise TypeError(f"expected np.ndarray, got {type(arg[0])}") if arg[0].shape != ids.shape: - raise ValueError(f'Dimensions not matching') + raise ValueError("Dimensions not matching") try: if len(arg[1]) != 2: - raise ValueError(f'limits should contain two values, but has {len(arg[1])}') + raise ValueError( + f"limits should contain two values, but has {len(arg[1])}" + ) except TypeError: - raise TypeError(f'Expected a 2 elements container, got {type(arg[1])}') + raise TypeError(f"Expected a 2 elements container, got {type(arg[1])}") x_it = (arg[0])[iteration, :] - selected_ids = id_it[ np.isin(id_it, selected_ids) & - (x_it >= (arg[1])[0]) & - (x_it <= (arg[1])[1]) + selected_ids = id_it[ + np.isin(id_it, selected_ids) & (x_it >= (arg[1])[0]) & (x_it <= (arg[1])[1]) ] - return selected_ids \ No newline at end of file + return selected_ids From a0cae433b5784dceffdb53e222537fc345e477d5 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Thu, 6 Feb 2025 10:49:18 +0100 Subject: [PATCH 020/123] removed comment --- Tools/PostProcessing/read_variable_based_adios2.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py index 43a8f8c370e..ff1bdce0ccf 100644 --- a/Tools/PostProcessing/read_variable_based_adios2.py +++ b/Tools/PostProcessing/read_variable_based_adios2.py @@ -60,7 +60,6 @@ def get_particle_data( n_iterations += 1 data = np.zeros((len(variables), n_iterations, n_particles)) - # really need to check that it works before commit with Stream(diag_path, "r") as s: for _ in s.steps(): From 1aea7823ceb2646ed661223a3a36b0ae09906a88 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:40:41 +0100 Subject: [PATCH 021/123] Update analysis_2d.py Removed unnecessary comments --- .../EM_fields_on_particles/analysis_2d.py | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index c8299134136..7e4407c653c 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -8,7 +8,7 @@ c = 3e8 lambda_laser = 800e-9 -T_laser = lambda_laser / c # utile ? +T_laser = lambda_laser / c E_max = 3.26e10 T_peak = 10e-15 @@ -29,41 +29,8 @@ bz_t = np.squeeze(bz_t) n_diags = 401 -""" -ex_t = np.zeros((n_diags,)) -ey_t = np.zeros((n_diags,)) -ez_t = np.zeros((n_diags,)) -bx_t = np.zeros((n_diags,)) -by_t = np.zeros((n_diags,)) -bz_t = np.zeros((n_diags,)) - - -def elec_d(x): - return f"/data/particles/electron/{x}/__data__" - """ - -# Here we use adios2.Stream instead of openpmd_viewer.OpenPMDTimeSeries -# This is because the variable based encoding is still experimental -# and OpenPMDTimeSeries does not support it at the time of writing -# If there are only a few diagnostics, using file-based encoding will -# work, but opening/closing files creates A LOT of overhead and -# with a lot of saved iterations the reading time grows very fast -# -# This example should be updated in the future when OpenPMDTimeSeries -# supports variable-based encoding -""" -with Stream("diags/diag1/openpmd.bp", "r") as s: - for _ in s.steps(): - i = s.current_step() - ex_t[i] = s.read(elec_d("ex")).item() - ey_t[i] = s.read(elec_d("ey")).item() - ez_t[i] = s.read(elec_d("ez")).item() - bx_t[i] = s.read(elec_d("bx")).item() - by_t[i] = s.read(elec_d("by")).item() - bz_t[i] = s.read(elec_d("bz")).item() """ DT = 6.324524234e-17 # @ CFL = 0.99 -# on pourrait juste lire l'input file.... iterations = np.linspace(0, n_diags - 1, n_diags) T = (iterations * DT) - DT / 2 From cab9f6c7511874d4d1808b9791086ab034c83fe0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:40:52 +0000 Subject: [PATCH 022/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Examples/Tests/EM_fields_on_particles/analysis_2d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 7e4407c653c..64a6b3b9b18 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -8,7 +8,7 @@ c = 3e8 lambda_laser = 800e-9 -T_laser = lambda_laser / c +T_laser = lambda_laser / c E_max = 3.26e10 T_peak = 10e-15 From 7644c3a932a24677dbea11b8d2bd47c55db76dbd Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 13 Feb 2025 14:08:24 +0100 Subject: [PATCH 023/123] added output docstring in script --- Tools/PostProcessing/read_variable_based_adios2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py index e622741441e..9aec4943c37 100644 --- a/Tools/PostProcessing/read_variable_based_adios2.py +++ b/Tools/PostProcessing/read_variable_based_adios2.py @@ -105,6 +105,9 @@ def select_particles(ids, iteration, *argv): iteration : int *argv : tuple (numpy array (n_iterations, n_particles) , 2-numbers array-like) + + OUTPUT: + array with the selected ids """ id_it = np.copy(ids[iteration, :]) From 86f86d89a08afb2c7d1e40ec373f90de96915d33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 13 Feb 2025 13:10:41 +0000 Subject: [PATCH 024/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Tools/PostProcessing/read_variable_based_adios2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py index 6e65438345b..98360ea165a 100644 --- a/Tools/PostProcessing/read_variable_based_adios2.py +++ b/Tools/PostProcessing/read_variable_based_adios2.py @@ -116,7 +116,7 @@ def select_particles(ids, iteration, *argv): OUTPUT: array with the selected ids - + """ id_it = np.copy(ids[iteration, :]) selected_ids = np.copy(ids[iteration, :]) From 028b1396b5ec1b8e96533630e44ec4a4cfee0292 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 13 Feb 2025 14:17:25 +0100 Subject: [PATCH 025/123] updated syntax for runtime components --- Source/Diagnostics/ParticleIO.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 8504d1d444e..8ce2c37c810 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -318,19 +318,19 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, "but this is only available with `diag_type = Full`."); - tmp.NewRealComp("Ex"); - tmp.NewRealComp("Ey"); - tmp.NewRealComp("Ez"); - tmp.NewRealComp("Bx"); - tmp.NewRealComp("By"); - tmp.NewRealComp("Bz"); - - int const Ex_index = tmp.getParticleComps().at("Ex"); - int const Ey_index = tmp.getParticleComps().at("Ey"); - int const Ez_index = tmp.getParticleComps().at("Ez"); - int const Bx_index = tmp.getParticleComps().at("Bx"); - int const By_index = tmp.getParticleComps().at("By"); - int const Bz_index = tmp.getParticleComps().at("Bz"); + tmp.AddRealComp("Ex"); + tmp.AddRealComp("Ey"); + tmp.AddRealComp("Ez"); + tmp.AddRealComp("Bx"); + tmp.AddRealComp("By"); + tmp.AddRealComp("Bz"); + + int const Ex_index = tmp.GetRealCompIndex().at("Ex"); + int const Ey_index = tmp.GetRealCompIndex().at("Ey"); + int const Ez_index = tmp.GetRealCompIndex().at("Ez"); + int const Bx_index = tmp.GetRealCompIndex().at("Bx"); + int const By_index = tmp.GetRealCompIndex().at("By"); + int const Bz_index = tmp.GetRealCompIndex().at("Bz"); auto& warpx = WarpX::GetInstance(); From dccd20c50bd412200e8dca78f6e40ed7074b69db Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 13 Feb 2025 14:23:27 +0100 Subject: [PATCH 026/123] fix args in GetRealCompIndex --- Source/Diagnostics/ParticleIO.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 8ce2c37c810..814fc63e9dd 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -325,12 +325,12 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, tmp.AddRealComp("By"); tmp.AddRealComp("Bz"); - int const Ex_index = tmp.GetRealCompIndex().at("Ex"); - int const Ey_index = tmp.GetRealCompIndex().at("Ey"); - int const Ez_index = tmp.GetRealCompIndex().at("Ez"); - int const Bx_index = tmp.GetRealCompIndex().at("Bx"); - int const By_index = tmp.GetRealCompIndex().at("By"); - int const Bz_index = tmp.GetRealCompIndex().at("Bz"); + int const Ex_index = tmp.GetRealCompIndex("Ex"); + int const Ey_index = tmp.GetRealCompIndex("Ey"); + int const Ez_index = tmp.GetRealCompIndex("Ez"); + int const Bx_index = tmp.GetRealCompIndex("Bx"); + int const By_index = tmp.GetRealCompIndex("By"); + int const Bz_index = tmp.GetRealCompIndex("Bz"); auto& warpx = WarpX::GetInstance(); From fe605a2f0676a4a1ccbf3a6bfe18aa49f8ec5907 Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:40:37 +0100 Subject: [PATCH 027/123] changed fields from fp to aux Co-authored-by: Remi Lehe --- Source/Diagnostics/ParticleIO.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 814fc63e9dd..a3274025115 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -341,12 +341,12 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; - amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_fp, Dir{0}, lev0); - amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_fp, Dir{1}, lev0); - amrex::MultiFab const& Ez = *warpx.m_fields.get(FieldType::Efield_fp, Dir{2}, lev0); - amrex::MultiFab const& Bx = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{0}, lev0); - amrex::MultiFab const& By = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{1}, lev0); - amrex::MultiFab const& Bz = *warpx.m_fields.get(FieldType::Bfield_fp, Dir{2}, lev0); + amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_aux, Dir{0}, lev0); + amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_aux, Dir{1}, lev0); + amrex::MultiFab const& Ez = *warpx.m_fields.get(FieldType::Efield_aux, Dir{2}, lev0); + amrex::MultiFab const& Bx = *warpx.m_fields.get(FieldType::Bfield_aux, Dir{0}, lev0); + amrex::MultiFab const& By = *warpx.m_fields.get(FieldType::Bfield_aux, Dir{1}, lev0); + amrex::MultiFab const& Bz = *warpx.m_fields.get(FieldType::Bfield_aux, Dir{2}, lev0); const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); const bool galerkin_interpolation = WarpX::galerkin_interpolation; From 6f49cb73023c809932e56be70ef855b4fa31801c Mon Sep 17 00:00:00 2001 From: "G. RD" <48356331+grobertdautun@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:42:22 +0100 Subject: [PATCH 028/123] clarified is_full_diagnostics Co-authored-by: Remi Lehe --- Source/Diagnostics/WarpXOpenPMD.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 79d937fc6c1..6713163f834 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -586,11 +586,14 @@ for (const auto & particle_diag : particle_diags) { } // Gather the electrostatic potential (phi) on the macroparticles + // Detect whether this is a FullDiagnostic (use_pinned_pc = 0) or + // a BoundaryScrapingDiagnostic/BackTransformedDiagnostic (use_pinned_pc=1) + bool const is_full_diagnostic = !use_pinned_pc; if ( particle_diag.m_plot_phi ) { - storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); + storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, is_full_diagnostic); } if ( particle_diag.m_plot_EM ) { - storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, !use_pinned_pc ); + storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, is_full_diagnostic); } // names of amrex::ParticleReal and int particle attributes in SoA data From f0070a761eb0d3c6e96a4c2ecc3b95379e21346a Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 26 Feb 2025 13:44:52 +0100 Subject: [PATCH 029/123] added external fields (testing) --- Source/Diagnostics/ParticleIO.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index a3274025115..862cb4672d1 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -373,6 +373,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const auto bz_type = Bz.ixType(); const auto getPosition = GetParticlePosition(pti); + const auto getExternalEB = GetExternalEBField(pti); amrex::ParticleReal* Ex_particle_arr = pti.GetStructOfArrays().GetRealData(Ex_index).dataPtr(); amrex::ParticleReal* Ey_particle_arr = pti.GetStructOfArrays().GetRealData(Ey_index).dataPtr(); amrex::ParticleReal* Ez_particle_arr = pti.GetStructOfArrays().GetRealData(Ez_index).dataPtr(); @@ -396,6 +397,16 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bx_particle_arr[ip] = 0._rt; By_particle_arr[ip] = 0._rt; Bz_particle_arr[ip] = 0._rt; + + amrex::ParticleReal Ex_external, Ey_external, Ez_external; + amrex::ParticleReal Bx_external, By_external, Bz_external; + getExternalEB(ip, Ex_external, Ey_external, Ez_external, Bx_external, By_external, Bz_external); + Ex_particle_arr[ip] += Ex_external; + Ey_particle_arr[ip] += Ey_external; + Ez_particle_arr[ip] += Ez_external; + Bx_particle_arr[ip] += Bx_external; + By_particle_arr[ip] += By_external; + Bz_particle_arr[ip] += Bz_external; doGatherShapeN( xp, yp, zp, From 46164dae96a4b03e8e81683f0d4ddf7941d6e4e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 12:45:54 +0000 Subject: [PATCH 030/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 862cb4672d1..9d90b8b96c3 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -397,7 +397,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bx_particle_arr[ip] = 0._rt; By_particle_arr[ip] = 0._rt; Bz_particle_arr[ip] = 0._rt; - + amrex::ParticleReal Ex_external, Ey_external, Ez_external; amrex::ParticleReal Bx_external, By_external, Bz_external; getExternalEB(ip, Ex_external, Ey_external, Ez_external, Bx_external, By_external, Bz_external); From e2fc011129714de5677a06ed8d53b120ebfecfab Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 26 Feb 2025 14:24:50 +0100 Subject: [PATCH 031/123] removed temporary variable --- Source/Diagnostics/ParticleIO.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9d90b8b96c3..5809f20061b 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -398,15 +398,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, By_particle_arr[ip] = 0._rt; Bz_particle_arr[ip] = 0._rt; - amrex::ParticleReal Ex_external, Ey_external, Ez_external; - amrex::ParticleReal Bx_external, By_external, Bz_external; - getExternalEB(ip, Ex_external, Ey_external, Ez_external, Bx_external, By_external, Bz_external); - Ex_particle_arr[ip] += Ex_external; - Ey_particle_arr[ip] += Ey_external; - Ez_particle_arr[ip] += Ez_external; - Bx_particle_arr[ip] += Bx_external; - By_particle_arr[ip] += By_external; - Bz_particle_arr[ip] += Bz_external; + getExternalEB(ip, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], + Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip]); doGatherShapeN( xp, yp, zp, From 52014a2d0d114d6853bc4ed82ce3158ac3ba30be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 13:25:52 +0000 Subject: [PATCH 032/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 5809f20061b..85551ac9fb3 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -398,7 +398,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, By_particle_arr[ip] = 0._rt; Bz_particle_arr[ip] = 0._rt; - getExternalEB(ip, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], + getExternalEB(ip, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip]); doGatherShapeN( From 92328fcd0d545a66ebb6dc579f731c23bfe0700d Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 26 Feb 2025 15:14:14 +0100 Subject: [PATCH 033/123] include getExternalFields.H --- Source/Diagnostics/ParticleIO.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 5809f20061b..5a93af41369 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -10,6 +10,7 @@ #include "Particles/ParticleIO.H" #include "Fields.H" +#include "Particles/Gather/GetExternalFields.H" #include "Particles/LaserParticleContainer.H" #include "Particles/MultiParticleContainer.H" #include "Particles/PhysicalParticleContainer.H" From 76661f6627be3efa2074a470120651ef74b22b6f Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 28 Mar 2025 16:32:50 +0100 Subject: [PATCH 034/123] removed variable based adios2 script --- .../read_variable_based_adios2.py | 145 ------------------ 1 file changed, 145 deletions(-) delete mode 100644 Tools/PostProcessing/read_variable_based_adios2.py diff --git a/Tools/PostProcessing/read_variable_based_adios2.py b/Tools/PostProcessing/read_variable_based_adios2.py deleted file mode 100644 index 98360ea165a..00000000000 --- a/Tools/PostProcessing/read_variable_based_adios2.py +++ /dev/null @@ -1,145 +0,0 @@ -import numpy as np -from adios2 import Stream - - -def species_path(name, field): - """ - variable based adios2 particles data is stored in /data/particles/species_name/field/__data__ - this function is only to format this path - - Note : momenta are stored as 'momentum/x' and positions as 'position/x', but EM fields are stored as 'ex' (and not 'e/x') - """ - return f"/data/particles/{name}/{field}/__data__" - - -def display_avail_variables(diag_path): - """ - if you are not sure how the variable you are looking for is named, or if you - want to check which variables are stored, this function displays every variable - available - """ - with Stream(diag_path, "r") as s: - for _ in s.steps(): - if s.current_step() == 0: - var_avail = s.available_variables() - for name, _ in var_avail.items(): - print(f"Found variable : {name}") - break - - -def get_particle_data( - diag_path, species_name, variables, n_iterations=-1, n_particles=-1 -): - """ - Retrieves the particle data for the given variables - - WARNING : depending on the case, RAM usage might be important - - INPUT: - - diag_path : str - - species names : str - - variables : array of str - optional: - - n_iterations : int, will be computed if not given - - n_particles : int, will be computed if not given - - OUTPUT: - - one array of shape (n_iterations, n_particles) per variable given - """ - if n_iterations == -1 or n_particles == -1: - if n_iterations == -1: - n_iterations = 0 - skip_for = False - with Stream(diag_path, "r") as s: - for _ in s.steps(): - if s.current_step() == 0 and n_particles == -1: - fieldPath = species_path(species_name, variables[0]) - n_particles = (s.read(fieldPath)).shape[0] - if skip_for: - break - n_iterations += 1 - - data = np.zeros((len(variables), n_iterations, n_particles)) - - with Stream(diag_path, "r") as s: - for _ in s.steps(): - iteration = s.current_step() - - for i, variable in enumerate(variables): - data[i, iteration, :] = s.read(species_path(species_name, variable)) - - # progress bar - if iteration % 100 == 0: - n_eg = int(20 * iteration / n_iterations) - print( - f"[{n_eg * '='}{(20 - n_eg) * ' '}] Iteration {iteration}", - end="\r" if iteration != n_iterations else "\n", - ) - - return data - - -def get_single_traj(x, ids, particle_id): - """ - Returns the trajectory of a single in the given space x - - INPUT : - x : numpy array - shape = (n_iterations, n_particles) - ids : numpy array - shape = (n_iterations, n_particles) - particle_id : int - id of the particle to plot - - OUTPUT : - (n_iterations,) numpy array - """ - - return x[ids == particle_id] - - -def select_particles(ids, iteration, *argv): - """ - select particles by filtering values - - USAGE : - select_ids = select_particles(id_t, 8000, (ux_t, [60e-6, 90e-6])) - -> returns the ids off all particles with 60e-6 < ux < 90e-6 at iteration 8000 - - select parameters can be stacked but need to be in tuple form (array, [range]) - - INPUT : - ids : numpy array (n_iterations, n_particles) float64 - iteration : int - - *argv : tuple (numpy array (n_iterations, n_particles) , 2-numbers array-like) - - OUTPUT: - array with the selected ids - - """ - id_it = np.copy(ids[iteration, :]) - selected_ids = np.copy(ids[iteration, :]) - - for arg in argv: - # check if arg is in the expected shape - if not isinstance(arg, tuple): - raise TypeError(f"expected tuple argument, got {type(arg)}") - if not isinstance(arg[0], np.ndarray): - raise TypeError(f"expected np.ndarray, got {type(arg[0])}") - if arg[0].shape != ids.shape: - raise ValueError("Dimensions not matching") - try: - if len(arg[1]) != 2: - raise ValueError( - f"limits should contain two values, but has {len(arg[1])}" - ) - except TypeError: - raise TypeError(f"Expected a 2 elements container, got {type(arg[1])}") - - x_it = (arg[0])[iteration, :] - selected_ids = id_it[ - np.isin(id_it, selected_ids) & (x_it >= (arg[1])[0]) & (x_it <= (arg[1])[1]) - ] - - return selected_ids From 1e75602904e5990e9da175e1410b1cd215b9398e Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 31 Mar 2025 11:47:01 +0200 Subject: [PATCH 035/123] [NOT WORKING] add runtime compile options --- Source/Diagnostics/ParticleIO.cpp | 53 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index aad659ccc2e..3647627f931 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,13 +304,13 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool is_full_diagnostic ) { + ElectromagneticSolverAlgo electromagnetic_solver_id, const bool (&fields_to_plot)[6], bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - electromagnetic_solver_id != ElectromagneticSolverAlgo::None , + electromagnetic_solver_id != ElectromagneticSolverAlgo::None, "output of the electromagnetic fields on the particles was requested, " "but this is only available with an electromagnetic solver."); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -318,21 +318,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, "Output of the electromagnetic fields on the particles was requested, " "but this is only available with `diag_type = Full`."); - - tmp.AddRealComp("Ex"); - tmp.AddRealComp("Ey"); - tmp.AddRealComp("Ez"); - tmp.AddRealComp("Bx"); - tmp.AddRealComp("By"); - tmp.AddRealComp("Bz"); - - int const Ex_index = tmp.GetRealCompIndex("Ex"); - int const Ey_index = tmp.GetRealCompIndex("Ey"); - int const Ez_index = tmp.GetRealCompIndex("Ez"); - int const Bx_index = tmp.GetRealCompIndex("Bx"); - int const By_index = tmp.GetRealCompIndex("By"); - int const Bz_index = tmp.GetRealCompIndex("Bz"); - auto& warpx = WarpX::GetInstance(); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( @@ -341,6 +326,23 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); constexpr auto lev0=0; + const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); + const bool galerkin_interpolation = WarpX::galerkin_interpolation; + const int nox = WarpX::nox; + const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; + + static constexpr const fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; + + int fields_Index[6]; + + for (int i = 0; i < 6; i++) + { + if (fields_to_plot[i]) + { + tmp.AddRealComp(fields_names[i]); + fields_Index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? + } + } amrex::MultiFab const& Ex = *warpx.m_fields.get(FieldType::Efield_aux, Dir{0}, lev0); amrex::MultiFab const& Ey = *warpx.m_fields.get(FieldType::Efield_aux, Dir{1}, lev0); @@ -349,11 +351,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, amrex::MultiFab const& By = *warpx.m_fields.get(FieldType::Bfield_aux, Dir{1}, lev0); amrex::MultiFab const& Bz = *warpx.m_fields.get(FieldType::Bfield_aux, Dir{2}, lev0); - const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); - const bool galerkin_interpolation = WarpX::galerkin_interpolation; - const int nox = WarpX::nox; - const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; - #ifdef AMREX_USE_OMP #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) #endif @@ -387,10 +384,14 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const Dim3 lo = lbound(box); // Loop over the particles and compute the EM field using the doGatherShapeN function - amrex::ParallelFor( pti.numParticles(), + amrex::ParallelFor( + TypeList, CompileTimeOptions, CompileTimeOptions, + CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, + {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, + pti.numParticles(), [=] AMREX_GPU_DEVICE (long ip) { - amrex::ParticleReal xp, yp, zp; - getPosition(ip, xp, yp, zp); + amrex::ParticleReal xp, yp, zp; + getPosition(ip, xp, yp, zp); Ex_particle_arr[ip] = 0._rt; Ey_particle_arr[ip] = 0._rt; @@ -402,7 +403,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip]); - doGatherShapeN( + doGatherShapeN( xp, yp, zp, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip], From a6f2615cdae19688ba2e177add068cf556f7b9d3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 31 Mar 2025 09:48:30 +0000 Subject: [PATCH 036/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 3647627f931..6e5d4004b9f 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -384,8 +384,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const Dim3 lo = lbound(box); // Loop over the particles and compute the EM field using the doGatherShapeN function - amrex::ParallelFor( - TypeList, CompileTimeOptions, CompileTimeOptions, + amrex::ParallelFor( + TypeList, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), From 4d9fc827cc4f0a05aecc06c6f8395e6839d0de40 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 31 Mar 2025 12:56:14 +0200 Subject: [PATCH 037/123] [NOT WORKING] tests --- Source/Diagnostics/ParticleIO.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 3647627f931..87af1ed32f9 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -337,8 +337,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, for (int i = 0; i < 6; i++) { - if (fields_to_plot[i]) - { + if (fields_to_plot[i]){ tmp.AddRealComp(fields_names[i]); fields_Index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? } From f70ca45c30b553c26bcfb509496a576d20319a5c Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 31 Mar 2025 12:57:05 +0200 Subject: [PATCH 038/123] [NOT WORKING] tests --- Source/Diagnostics/ParticleIO.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9637e73acbe..d29fe56903e 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -335,8 +335,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, int fields_Index[6]; - for (int i = 0; i < 6; i++) - { + for (int i = 0; i < 6; i++){ if (fields_to_plot[i]){ tmp.AddRealComp(fields_names[i]); fields_Index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? From 2f9740c5f2eac82423f3c1fdfb35f070d57ead92 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 10:15:20 +0200 Subject: [PATCH 039/123] [NW] added tmp arrays --- Source/Diagnostics/ParticleIO.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index d29fe56903e..e1ceac26306 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -388,9 +388,22 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), [=] AMREX_GPU_DEVICE (long ip) { - amrex::ParticleReal xp, yp, zp; + amrex::ParticleReal xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle; getPosition(ip, xp, yp, zp); + Ex_particle = 0._rt; + Ey_particle = 0._rt; + Ez_particle = 0._rt; + Bx_particle = 0._rt; + By_particle = 0._rt; + Bz_particle = 0._rt; + + getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, + Bx_particle, By_particle, Bz_particle); + + + + /* Ex_particle_arr[ip] = 0._rt; Ey_particle_arr[ip] = 0._rt; Ez_particle_arr[ip] = 0._rt; @@ -410,6 +423,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation); + */ }); } From 1c4801ab249f9e90eda89cd521af4d3139e6ab2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 08:15:50 +0000 Subject: [PATCH 040/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e1ceac26306..89a2573c56c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -401,8 +401,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); - - + + /* Ex_particle_arr[ip] = 0._rt; Ey_particle_arr[ip] = 0._rt; From ddef5213e35f81566bd0c69a998e1e70f75cea08 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 10:30:42 +0200 Subject: [PATCH 041/123] [NW] add runtime options --- Source/Diagnostics/ParticleIO.cpp | 62 ++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e1ceac26306..2861b037adc 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -401,29 +401,47 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); + if constexpr (Ex_runtime_flag == doEx || Ey_runtime_flag == doEy || Ez_runtime_flag == doEz) + { + doDirectGatherVectorField( + xp, yp, zp, + Ex_particle, Ey_particle, Ez_particle, + Ex_grid, Ey_grid, Ez_grid, + ex_type, ey_type, ez_type, + dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation + ); + + } + + if constexpr (Bx_runtime_flag == doBx || By_runtime_flag == doBy || Bz_runtime_flag == doBz) + { + doDirectGatherVectorField( + xp, yp, zp, + Bx_particle, By_particle, Bz_particle, + Bx_grid, By_grid, Bz_grid, + bx_type, by_type, bz_type, + dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation + ); + } - - /* - Ex_particle_arr[ip] = 0._rt; - Ey_particle_arr[ip] = 0._rt; - Ez_particle_arr[ip] = 0._rt; - Bx_particle_arr[ip] = 0._rt; - By_particle_arr[ip] = 0._rt; - Bz_particle_arr[ip] = 0._rt; - - getExternalEB(ip, Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], - Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip]); - - doGatherShapeN( - xp, yp, zp, - Ex_particle_arr[ip], Ey_particle_arr[ip], Ez_particle_arr[ip], - Bx_particle_arr[ip], By_particle_arr[ip], Bz_particle_arr[ip], - Ex_grid, Ey_grid, Ez_grid, - Bx_grid, By_grid, Bz_grid, - ex_type, ey_type, ez_type, - bx_type, by_type, bz_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation); - */ + if (Ex_runtime_flag == doEx) { + Ex_particle_arr[ip] = Ex_particle; + } + if (Ey_runtime_flag == doEy) { + Ey_particle_arr[ip] = Ey_particle; + } + if (Ez_runtime_flag == doEz) { + Ez_particle_arr[ip] = Ez_particle; + } + if (Bx_runtime_flag == doBx) { + Bx_particle_arr[ip] = Bx_particle; + } + if (By_runtime_flag == doBy) { + By_particle_arr[ip] = By_particle; + } + if (Bz_runtime_flag == doBz) { + Bz_particle_arr[ip] = Bz_particle; + } }); } From 910ad1eb9bb0843c3ce620bbabd8b707bf9a6040 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 08:34:58 +0000 Subject: [PATCH 042/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 65019c192e9..22b15c48044 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -402,7 +402,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bx_particle, By_particle, Bz_particle); <<<<<<< HEAD - if constexpr (Ex_runtime_flag == doEx || Ey_runtime_flag == doEy || Ez_runtime_flag == doEz) + if constexpr (Ex_runtime_flag == doEx || Ey_runtime_flag == doEy || Ez_runtime_flag == doEz) { doDirectGatherVectorField( xp, yp, zp, @@ -411,7 +411,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ex_type, ey_type, ez_type, dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation ); - + } ======= @@ -425,7 +425,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bz_particle_arr[ip] = 0._rt; >>>>>>> 1c4801ab249f9e90eda89cd521af4d3139e6ab2b - if constexpr (Bx_runtime_flag == doBx || By_runtime_flag == doBy || Bz_runtime_flag == doBz) + if constexpr (Bx_runtime_flag == doBx || By_runtime_flag == doBy || Bz_runtime_flag == doBz) { doDirectGatherVectorField( xp, yp, zp, @@ -435,7 +435,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation ); } - + if (Ex_runtime_flag == doEx) { Ex_particle_arr[ip] = Ex_particle; } From 29a334520ba28c65ae0bfb7760e5670e8234dc16 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 13:48:13 +0200 Subject: [PATCH 043/123] this should work --- .../Diagnostics/ParticleDiag/ParticleDiag.H | 1 + .../Diagnostics/ParticleDiag/ParticleDiag.cpp | 11 ++- Source/Diagnostics/ParticleIO.cpp | 78 ++++++++++--------- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- Source/Particles/ParticleIO.H | 2 +- 5 files changed, 54 insertions(+), 40 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index 33dc4dc1931..d3c37c32483 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -25,6 +25,7 @@ public: amrex::Vector m_plot_flags; bool m_plot_phi = false; // Whether to output the potential phi on the particles bool m_plot_EM = false; // Whether to output the E and B fields on the particles + bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; // E and B fields bool m_do_random_filter = false; bool m_do_uniform_filter = false; diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index a1310534701..69774d2b7b8 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -43,8 +43,17 @@ ParticleDiag::ParticleDiag ( #endif if (var == "phi") { m_plot_phi = true; - } else if (var=="EM") { + } else if (var == "Ex" || var == "Ey" || var == "Ez" || + var == "Bx" || var == "By" || var == "Bz") { m_plot_EM = true; + static bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; + if (var == "Ex") m_plot_EM_flags[0] = true; + if (var == "Ey") m_plot_EM_flags[1] = true; + if (var == "Ez") m_plot_EM_flags[2] = true; + if (var == "Bx") m_plot_EM_flags[3] = true; + if (var == "By") m_plot_EM_flags[4] = true; + if (var == "Bz") m_plot_EM_flags[5] = true; + } } else { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(pc->HasRealComp(var), "variables argument '" + var diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 22b15c48044..690dca395f6 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, const bool (&fields_to_plot)[6], bool is_full_diagnostic) { + ElectromagneticSolverAlgo electromagnetic_solver_id, bool (&fields_to_plot)[6], bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; @@ -327,18 +327,32 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); - const bool galerkin_interpolation = WarpX::galerkin_interpolation; - const int nox = WarpX::nox; + //const bool galerkin_interpolation = WarpX::galerkin_interpolation; + //const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; static constexpr const fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; - int fields_Index[6]; + int fields_index[6]; + + enum Ex_flags { doEx, noEx }; + enum Ey_flags { doEy, noEy }; + enum Ez_flags { doEz, noEz }; + enum Bx_flags { doBx, noBx }; + enum By_flags { doBy, noBy }; + enum Bz_flags { doBz, noBz }; + + const auto Ex_runtime_flag = (fields_to_plot[0]) ? doEx : noEx; + const auto Ey_runtime_flag = (fields_to_plot[1]) ? doEy : noEy; + const auto Ez_runtime_flag = (fields_to_plot[2]) ? doEz : noEz; + const auto Bx_runtime_flag = (fields_to_plot[3]) ? doBx : noBx; + const auto By_runtime_flag = (fields_to_plot[4]) ? doBy : noBy; + const auto Bz_runtime_flag = (fields_to_plot[5]) ? doBz : noBz; for (int i = 0; i < 6; i++){ if (fields_to_plot[i]){ tmp.AddRealComp(fields_names[i]); - fields_Index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? + fields_index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? } } @@ -370,12 +384,12 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const auto getPosition = GetParticlePosition(pti); const auto getExternalEB = GetExternalEBField(pti); - amrex::ParticleReal* Ex_particle_arr = pti.GetStructOfArrays().GetRealData(Ex_index).dataPtr(); - amrex::ParticleReal* Ey_particle_arr = pti.GetStructOfArrays().GetRealData(Ey_index).dataPtr(); - amrex::ParticleReal* Ez_particle_arr = pti.GetStructOfArrays().GetRealData(Ez_index).dataPtr(); - amrex::ParticleReal* Bx_particle_arr = pti.GetStructOfArrays().GetRealData(Bx_index).dataPtr(); - amrex::ParticleReal* By_particle_arr = pti.GetStructOfArrays().GetRealData(By_index).dataPtr(); - amrex::ParticleReal* Bz_particle_arr = pti.GetStructOfArrays().GetRealData(Bz_index).dataPtr(); + if (fields_to_plot[0]) amrex::ParticleReal* Ex_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr(); + if (fields_to_plot[1]) amrex::ParticleReal* Ey_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr(); + if (fields_to_plot[2]) amrex::ParticleReal* Ez_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[2]).dataPtr(); + if (fields_to_plot[3]) amrex::ParticleReal* Bx_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[3]).dataPtr(); + if (fields_to_plot[4]) amrex::ParticleReal* By_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[4]).dataPtr(); + if (fields_to_plot[5]) amrex::ParticleReal* Bz_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[5]).dataPtr(); const auto box = pti.tilebox(); const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev0, 0._rt); @@ -387,8 +401,11 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), - [=] AMREX_GPU_DEVICE (long ip) { - amrex::ParticleReal xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle; + [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, + auto bx_control, auto by_control, auto bz_control) + { + amrex::ParticleReal xp, yp, zp; + [[maybe_unused]] amrex::ParticleReal Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle; getPosition(ip, xp, yp, zp); Ex_particle = 0._rt; @@ -401,57 +418,44 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); -<<<<<<< HEAD - if constexpr (Ex_runtime_flag == doEx || Ey_runtime_flag == doEy || Ez_runtime_flag == doEz) + if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, ex_type, ey_type, ez_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation + dinv, xyzmin, lo, n_rz_azimuthal_modes //, nox, galerkin_interpolation ); - } -======= - - /* - Ex_particle_arr[ip] = 0._rt; - Ey_particle_arr[ip] = 0._rt; - Ez_particle_arr[ip] = 0._rt; - Bx_particle_arr[ip] = 0._rt; - By_particle_arr[ip] = 0._rt; - Bz_particle_arr[ip] = 0._rt; ->>>>>>> 1c4801ab249f9e90eda89cd521af4d3139e6ab2b - - if constexpr (Bx_runtime_flag == doBx || By_runtime_flag == doBy || Bz_runtime_flag == doBz) + if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, bx_type, by_type, bz_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes, nox, galerkin_interpolation + dinv, xyzmin, lo, n_rz_azimuthal_modes //, nox, galerkin_interpolation ); } - - if (Ex_runtime_flag == doEx) { + + if (ex_control == doEx) { Ex_particle_arr[ip] = Ex_particle; } - if (Ey_runtime_flag == doEy) { + if (ey_control == doEy) { Ey_particle_arr[ip] = Ey_particle; } - if (Ez_runtime_flag == doEz) { + if (ez_control == doEz) { Ez_particle_arr[ip] = Ez_particle; } - if (Bx_runtime_flag == doBx) { + if (bx_control == doBx) { Bx_particle_arr[ip] = Bx_particle; } - if (By_runtime_flag == doBy) { + if (by_control == doBy) { By_particle_arr[ip] = By_particle; } - if (Bz_runtime_flag == doBz) { + if (bz_control == doBz) { Bz_particle_arr[ip] = Bz_particle; } }); diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 65ee5dd2df6..6f55776d6fa 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -610,7 +610,7 @@ for (const auto & particle_diag : particle_diags) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, is_full_diagnostic); } if ( particle_diag.m_plot_EM ) { - storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, is_full_diagnostic); + storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, particle_diag.m_plot_EM_flags, is_full_diagnostic); } // names of amrex::ParticleReal and int particle attributes in SoA data diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 3b92cd12429..0101eed6d0d 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, bool (&fields_to_plot)[6], bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From fdc274e3b7d6d77710a50ab459329402ee2897af Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 11:49:43 +0000 Subject: [PATCH 044/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 2 +- Source/Diagnostics/ParticleIO.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 69774d2b7b8..4b3ca0fcaa7 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -43,7 +43,7 @@ ParticleDiag::ParticleDiag ( #endif if (var == "phi") { m_plot_phi = true; - } else if (var == "Ex" || var == "Ey" || var == "Ez" || + } else if (var == "Ex" || var == "Ey" || var == "Ez" || var == "Bx" || var == "By" || var == "Bz") { m_plot_EM = true; static bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 690dca395f6..f2f9a670e18 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -402,7 +402,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, - auto bx_control, auto by_control, auto bz_control) + auto bx_control, auto by_control, auto bz_control) { amrex::ParticleReal xp, yp, zp; [[maybe_unused]] amrex::ParticleReal Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle; @@ -418,7 +418,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); - if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) + if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { doDirectGatherVectorField( xp, yp, zp, @@ -429,7 +429,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } - if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) + if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { doDirectGatherVectorField( xp, yp, zp, @@ -439,7 +439,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, dinv, xyzmin, lo, n_rz_azimuthal_modes //, nox, galerkin_interpolation ); } - + if (ex_control == doEx) { Ex_particle_arr[ip] = Ex_particle; } From ae4900c9128c72ae5370579509c378bca894edaf Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 14:12:17 +0200 Subject: [PATCH 045/123] defined unused fields as nullptr --- Source/Diagnostics/ParticleIO.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index f2f9a670e18..e7c72e7246e 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -333,7 +333,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, static constexpr const fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; - int fields_index[6]; + auto fields_index = amrex::Array{0,0,0,0,0,0}; enum Ex_flags { doEx, noEx }; enum Ey_flags { doEy, noEy }; @@ -384,12 +384,13 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const auto getPosition = GetParticlePosition(pti); const auto getExternalEB = GetExternalEBField(pti); - if (fields_to_plot[0]) amrex::ParticleReal* Ex_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr(); - if (fields_to_plot[1]) amrex::ParticleReal* Ey_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr(); - if (fields_to_plot[2]) amrex::ParticleReal* Ez_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[2]).dataPtr(); - if (fields_to_plot[3]) amrex::ParticleReal* Bx_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[3]).dataPtr(); - if (fields_to_plot[4]) amrex::ParticleReal* By_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[4]).dataPtr(); - if (fields_to_plot[5]) amrex::ParticleReal* Bz_particle_arr = pti.GetStructOfArrays().GetRealData(fields_index[5]).dataPtr(); + + amrex::ParticleReal* Ex_particle_arr = (fields_to_plot[0]) ? pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr() : nullptr; + amrex::ParticleReal* Ey_particle_arr = (fields_to_plot[1]) ? pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr() : nullptr; + amrex::ParticleReal* Ez_particle_arr = (fields_to_plot[2]) ? pti.GetStructOfArrays().GetRealData(fields_index[2]).dataPtr() : nullptr; + amrex::ParticleReal* Bx_particle_arr = (fields_to_plot[3]) ? pti.GetStructOfArrays().GetRealData(fields_index[3]).dataPtr() : nullptr; + amrex::ParticleReal* By_particle_arr = (fields_to_plot[4]) ? pti.GetStructOfArrays().GetRealData(fields_index[4]).dataPtr() : nullptr; + amrex::ParticleReal* Bz_particle_arr = (fields_to_plot[5]) ? pti.GetStructOfArrays().GetRealData(fields_index[5]).dataPtr() : nullptr; const auto box = pti.tilebox(); const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev0, 0._rt); @@ -440,22 +441,22 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } - if (ex_control == doEx) { + if constexpr (ex_control == doEx) { Ex_particle_arr[ip] = Ex_particle; } - if (ey_control == doEy) { + if constexpr (ey_control == doEy) { Ey_particle_arr[ip] = Ey_particle; } - if (ez_control == doEz) { + if constexpr (ez_control == doEz) { Ez_particle_arr[ip] = Ez_particle; } - if (bx_control == doBx) { + if constexpr (bx_control == doBx) { Bx_particle_arr[ip] = Bx_particle; } - if (by_control == doBy) { + if constexpr (by_control == doBy) { By_particle_arr[ip] = By_particle; } - if (bz_control == doBz) { + if constexpr (bz_control == doBz) { Bz_particle_arr[ip] = Bz_particle; } }); From 454b7f7ea721941ba072feb25a0e6efd8b45bf7f Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 14:17:08 +0200 Subject: [PATCH 046/123] fixed undefined type --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e7c72e7246e..5cd43a891ee 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -331,7 +331,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, //const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; - static constexpr const fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; + static constexpr const char* fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; auto fields_index = amrex::Array{0,0,0,0,0,0}; From e3e74cdc8d1ea5c790d13da49c566b6dabd4ce86 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 14:30:32 +0200 Subject: [PATCH 047/123] storeEMFieldsOnParticles parameters consistency --- Source/Diagnostics/ParticleIO.cpp | 2 +- Source/Particles/ParticleIO.H | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 5cd43a891ee..a280107b39c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool (&fields_to_plot)[6], bool is_full_diagnostic) { + ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[6], bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 0101eed6d0d..00d4a0f72dd 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool (&fields_to_plot)[6], bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[], bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 7ace39bf1308a21e5d602e82e748ff7e97967786 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 14:35:32 +0200 Subject: [PATCH 048/123] array is const --- Source/Diagnostics/ParticleIO.cpp | 2 +- Source/Particles/ParticleIO.H | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index a280107b39c..fb520dae7b9 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[6], bool is_full_diagnostic) { + ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 00d4a0f72dd..f676b03c438 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[], bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 872858fee2a23b8e51c1af7bd013880c61a672cb Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 14:46:38 +0200 Subject: [PATCH 049/123] adapted template params --- Source/Diagnostics/ParticleIO.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index fb520dae7b9..cf2b83ba6c2 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -418,10 +418,13 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); + + const int depos_order_perp = 1; // who are you ? + const int depos_order_para = 1; if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - doDirectGatherVectorField( + doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -432,7 +435,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { - doDirectGatherVectorField( + doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, From 5557af7ca3ae9e2ef12da1d43683975323ef8a58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 12:46:51 +0000 Subject: [PATCH 050/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index cf2b83ba6c2..51a53b76049 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -418,7 +418,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle); - + const int depos_order_perp = 1; // who are you ? const int depos_order_para = 1; From cf4d694d535d9eed2fdb545ced021cf35b5c4d51 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 15:00:34 +0200 Subject: [PATCH 051/123] trying to fix WarpXParIter issue --- Source/Diagnostics/ParticleIO.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 51a53b76049..40f5d63c78a 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -383,7 +383,9 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const auto bz_type = Bz.ixType(); const auto getPosition = GetParticlePosition(pti); - const auto getExternalEB = GetExternalEBField(pti); + + WarpXParIter const& pti_const = static_cast(pti); + const auto getExternalEB = GetExternalEBField(pti_const, lev0); amrex::ParticleReal* Ex_particle_arr = (fields_to_plot[0]) ? pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr() : nullptr; amrex::ParticleReal* Ey_particle_arr = (fields_to_plot[1]) ? pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr() : nullptr; From 887a1177c6dddf4cada7abe34a34ab9e5fb9f9c4 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 15:33:13 +0200 Subject: [PATCH 052/123] removed external fields (temporary) --- Source/Diagnostics/ParticleIO.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 40f5d63c78a..95a45603495 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -384,8 +384,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const auto getPosition = GetParticlePosition(pti); - WarpXParIter const& pti_const = static_cast(pti); - const auto getExternalEB = GetExternalEBField(pti_const, lev0); + // const auto getExternalEB = GetExternalEBField(a_pti, lev0); + // a_pti is a WarpXParIter, currently undefined amrex::ParticleReal* Ex_particle_arr = (fields_to_plot[0]) ? pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr() : nullptr; amrex::ParticleReal* Ey_particle_arr = (fields_to_plot[1]) ? pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr() : nullptr; @@ -418,8 +418,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, By_particle = 0._rt; Bz_particle = 0._rt; - getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, - Bx_particle, By_particle, Bz_particle); + //getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, + // Bx_particle, By_particle, Bz_particle); const int depos_order_perp = 1; // who are you ? const int depos_order_para = 1; From 851dd6b4e2a44890aba8e2d5cd4ce4d0755de1d8 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 15:39:41 +0200 Subject: [PATCH 053/123] fixed { not matching and removed redefinition of flags --- Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 4b3ca0fcaa7..72573ca7654 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -46,14 +46,12 @@ ParticleDiag::ParticleDiag ( } else if (var == "Ex" || var == "Ey" || var == "Ez" || var == "Bx" || var == "By" || var == "Bz") { m_plot_EM = true; - static bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; if (var == "Ex") m_plot_EM_flags[0] = true; if (var == "Ey") m_plot_EM_flags[1] = true; if (var == "Ez") m_plot_EM_flags[2] = true; if (var == "Bx") m_plot_EM_flags[3] = true; if (var == "By") m_plot_EM_flags[4] = true; if (var == "Bz") m_plot_EM_flags[5] = true; - } } else { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(pc->HasRealComp(var), "variables argument '" + var From a7b7655948bea3c8c9425f87f7ba729be17c7084 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 16:10:01 +0200 Subject: [PATCH 054/123] ignore_unused and remove 1 constexpr --- Source/Diagnostics/ParticleIO.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 95a45603495..5578b5d453e 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -423,6 +423,14 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int depos_order_perp = 1; // who are you ? const int depos_order_para = 1; + if (ex_control == noEx && ey_control == noEy && ez_control == noEz && + bx_control == noBx && by_control == noBy && bz_control == noBz) { + // only for compiling the kernel where nothing is asked (but the function won't be called anyway) + amrex::ignore_unused(depos_order_para, depos_order_perp, Ex_grid, Ey_grid, Ez_grid, + Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, + bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); + } + if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { @@ -446,7 +454,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } - if constexpr (ex_control == doEx) { + if (ex_control == doEx) { Ex_particle_arr[ip] = Ex_particle; } if constexpr (ey_control == doEy) { From fa2686c77e6d6fa8d1c8978bc88897ae68242edb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 14:12:34 +0000 Subject: [PATCH 055/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 5578b5d453e..77f9674bd7c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -430,7 +430,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); } - + if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { From 3ab1d6efb9b961d65dbc45267784b6ae39812997 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 17:54:17 +0200 Subject: [PATCH 056/123] changed lambda function capture --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 77f9674bd7c..2b1a92800e3 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -404,7 +404,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), - [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, + [=, Ex_particle_arr, Ey_particle_arr, Ez_particle_arr, Bx_particle_arr, By_particle_arr, Bz_particle_arr] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, auto bx_control, auto by_control, auto bz_control) { amrex::ParticleReal xp, yp, zp; @@ -454,7 +454,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } - if (ex_control == doEx) { + if constexpr (ex_control == doEx) { Ex_particle_arr[ip] = Ex_particle; } if constexpr (ey_control == doEy) { From 9ac5c8f546cd30b3a54ef22f170bf0d33a0b0eea Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 1 Apr 2025 18:01:08 +0200 Subject: [PATCH 057/123] ref --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 2b1a92800e3..109803607af 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -404,7 +404,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), - [=, Ex_particle_arr, Ey_particle_arr, Ez_particle_arr, Bx_particle_arr, By_particle_arr, Bz_particle_arr] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, + [=, &Ex_particle_arr, &Ey_particle_arr, &Ez_particle_arr, &Bx_particle_arr, &By_particle_arr, &Bz_particle_arr] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, auto bx_control, auto by_control, auto bz_control) { amrex::ParticleReal xp, yp, zp; From 2c11d115874e2d5bef1742932c82a74c4cb4e4da Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 2 Apr 2025 10:31:14 +0200 Subject: [PATCH 058/123] try to capture before constexpr --- Source/Diagnostics/ParticleIO.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 109803607af..9e172ca982b 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -404,7 +404,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, {Ex_runtime_flag, Ey_runtime_flag, Ez_runtime_flag, Bx_runtime_flag, By_runtime_flag, Bz_runtime_flag}, pti.numParticles(), - [=, &Ex_particle_arr, &Ey_particle_arr, &Ez_particle_arr, &Bx_particle_arr, &By_particle_arr, &Bz_particle_arr] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, + [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, auto bx_control, auto by_control, auto bz_control) { amrex::ParticleReal xp, yp, zp; @@ -454,23 +454,30 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } + amrex::ParticleReal* Ex_particle_ptr = (ex_control == doEx) ? &Ex_particle_arr[ip] : nullptr; + amrex::ParticleReal* Ey_particle_ptr = (ey_control == doEy) ? &Ey_particle_arr[ip] : nullptr; + amrex::ParticleReal* Ez_particle_ptr = (ez_control == doEz) ? &Ez_particle_arr[ip] : nullptr; + amrex::ParticleReal* Bx_particle_ptr = (bx_control == doBx) ? &Bx_particle_arr[ip] : nullptr; + amrex::ParticleReal* By_particle_ptr = (by_control == doBy) ? &By_particle_arr[ip] : nullptr; + amrex::ParticleReal* Bz_particle_ptr = (bz_control == doBz) ? &Bz_particle_arr[ip] : nullptr; + if constexpr (ex_control == doEx) { - Ex_particle_arr[ip] = Ex_particle; + *Ex_particle_ptr = Ex_particle; } if constexpr (ey_control == doEy) { - Ey_particle_arr[ip] = Ey_particle; + *Ey_particle_ptr = Ey_particle; } if constexpr (ez_control == doEz) { - Ez_particle_arr[ip] = Ez_particle; + *Ez_particle_ptr = Ez_particle; } if constexpr (bx_control == doBx) { - Bx_particle_arr[ip] = Bx_particle; + *Bx_particle_ptr = Bx_particle; } if constexpr (by_control == doBy) { - By_particle_arr[ip] = By_particle; + *By_particle_ptr = By_particle; } if constexpr (bz_control == doBz) { - Bz_particle_arr[ip] = Bz_particle; + *Bz_particle_ptr = Bz_particle; } }); } From ba3645ac2c0e863b732ff3433c0ee0103711b503 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 2 Apr 2025 10:37:31 +0200 Subject: [PATCH 059/123] ignore unused --- Source/Diagnostics/ParticleIO.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9e172ca982b..e0b5a4fabba 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -461,6 +461,9 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, amrex::ParticleReal* By_particle_ptr = (by_control == doBy) ? &By_particle_arr[ip] : nullptr; amrex::ParticleReal* Bz_particle_ptr = (bz_control == doBz) ? &Bz_particle_arr[ip] : nullptr; + amrex::ignore_unused(Ex_particle_ptr, Ey_particle_ptr, Ez_particle_ptr, + Bx_particle_ptr, By_particle_ptr, Bz_particle_ptr); + if constexpr (ex_control == doEx) { *Ex_particle_ptr = Ex_particle; } From 57dd7051118e561f86e74f13fe7c15d091037dbe Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 2 Apr 2025 11:36:30 +0200 Subject: [PATCH 060/123] changed some def, adapted capture oustside constexpr --- Source/Diagnostics/ParticleIO.cpp | 45 ++++++++++++++++++------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e0b5a4fabba..e03277f91f2 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -331,7 +331,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, //const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; - static constexpr const char* fields_names[6] = {"Ex", "Ey", "Ez", "Bx", "By", "Bz"}; + auto fields_names = amrex::Array{ + "Ex", "Ey", "Ez", "Bx", "By", "Bz"}; auto fields_index = amrex::Array{0,0,0,0,0,0}; @@ -352,7 +353,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, for (int i = 0; i < 6; i++){ if (fields_to_plot[i]){ tmp.AddRealComp(fields_names[i]); - fields_index[i] = tmp.GetRealCompIndex(fields_names[i]); // To check -> /!\ accessing unset values ? + fields_index[i] = tmp.GetRealCompIndex(fields_names[i]); } } @@ -408,20 +409,19 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, auto bx_control, auto by_control, auto bz_control) { amrex::ParticleReal xp, yp, zp; - [[maybe_unused]] amrex::ParticleReal Ex_particle, Ey_particle, Ez_particle, Bx_particle, By_particle, Bz_particle; getPosition(ip, xp, yp, zp); - Ex_particle = 0._rt; - Ey_particle = 0._rt; - Ez_particle = 0._rt; - Bx_particle = 0._rt; - By_particle = 0._rt; - Bz_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Ex_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Ey_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Ez_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Bx_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; //getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, // Bx_particle, By_particle, Bz_particle); - const int depos_order_perp = 1; // who are you ? + const int depos_order_perp = 1; // adapt w/ shape function const int depos_order_para = 1; if (ex_control == noEx && ey_control == noEy && ez_control == noEz && bx_control == noBx && by_control == noBy && bz_control == noBz) { @@ -454,33 +454,42 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ); } + auto& rEx_particle = Ex_particle_arr; + auto& rEy_particle = Ey_particle_arr; + auto& rEz_particle = Ez_particle_arr; + auto& rBx_particle = Bx_particle_arr; + auto& rBy_particle = By_particle_arr; + auto& rBz_particle = Bz_particle_arr; + + /* amrex::ParticleReal* Ex_particle_ptr = (ex_control == doEx) ? &Ex_particle_arr[ip] : nullptr; amrex::ParticleReal* Ey_particle_ptr = (ey_control == doEy) ? &Ey_particle_arr[ip] : nullptr; amrex::ParticleReal* Ez_particle_ptr = (ez_control == doEz) ? &Ez_particle_arr[ip] : nullptr; amrex::ParticleReal* Bx_particle_ptr = (bx_control == doBx) ? &Bx_particle_arr[ip] : nullptr; amrex::ParticleReal* By_particle_ptr = (by_control == doBy) ? &By_particle_arr[ip] : nullptr; amrex::ParticleReal* Bz_particle_ptr = (bz_control == doBz) ? &Bz_particle_arr[ip] : nullptr; + */ - amrex::ignore_unused(Ex_particle_ptr, Ey_particle_ptr, Ez_particle_ptr, - Bx_particle_ptr, By_particle_ptr, Bz_particle_ptr); + amrex::ignore_unused(rEx_particle, rEy_particle, rEz_particle, + rBx_particle, rBy_particle, rBz_particle); if constexpr (ex_control == doEx) { - *Ex_particle_ptr = Ex_particle; + rEx_particle[ip] = Ex_particle; } if constexpr (ey_control == doEy) { - *Ey_particle_ptr = Ey_particle; + rEy_particle[ip] = Ey_particle; } if constexpr (ez_control == doEz) { - *Ez_particle_ptr = Ez_particle; + rEz_particle[ip] = Ez_particle; } if constexpr (bx_control == doBx) { - *Bx_particle_ptr = Bx_particle; + rBx_particle[ip] = Bx_particle; } if constexpr (by_control == doBy) { - *By_particle_ptr = By_particle; + rBy_particle[ip] = By_particle; } if constexpr (bz_control == doBz) { - *Bz_particle_ptr = Bz_particle; + rBz_particle[ip] = Bz_particle; } }); } From 74df3ebe1de9a164a7a291d8b58ba71499c47461 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 09:38:17 +0000 Subject: [PATCH 061/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index e03277f91f2..992cf71bce7 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -416,7 +416,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, [[maybe_unused]] amrex::ParticleReal Ez_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal Bx_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; - [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; + [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; //getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, // Bx_particle, By_particle, Bz_particle); From f76a16168aa585a49482c810ad8638ea5ebd90a6 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 2 Apr 2025 14:07:58 +0200 Subject: [PATCH 062/123] updated test --- .../inputs_test_2d_particle_EM_diagnostics | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics index 779abd3b377..40b50f349a0 100644 --- a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics +++ b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics @@ -72,7 +72,7 @@ diag1.openpmd_backend = h5 diag1.fields_to_plot = none diag1.write_species = 1 diag1.species = electron -diag1.electron.variables = EM # will emit a warning because no position +diag1.electron.variables = Ex Ey Ez Bx By Bz # will emit a warning because no position diag_checksum.intervals = 400:400 diag_checksum.diag_type = Full @@ -81,4 +81,4 @@ diag_checksum.openpmd_backend = h5 diag_checksum.fields_to_plot = Ex Ey Ez Bx By Bz diag_checksum.write_species = 1 diag_checksum.species = electron -diag_checksum.electron.variables = x z ux uy uz w EM # will emit a warning because no position +diag_checksum.electron.variables = x z ux uy uz w Ex Ey Ez Bx By Bz From a0192516af5be2244e4236d003608c8c832deb0c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 12:08:14 +0000 Subject: [PATCH 063/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../inputs_test_2d_particle_EM_diagnostics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics index 40b50f349a0..b6c2b603b2f 100644 --- a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics +++ b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics @@ -81,4 +81,4 @@ diag_checksum.openpmd_backend = h5 diag_checksum.fields_to_plot = Ex Ey Ez Bx By Bz diag_checksum.write_species = 1 diag_checksum.species = electron -diag_checksum.electron.variables = x z ux uy uz w Ex Ey Ez Bx By Bz +diag_checksum.electron.variables = x z ux uy uz w Ex Ey Ez Bx By Bz From 3b8f9bfa1e41a1ee0427ba435db866a12180fe00 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 2 Apr 2025 14:19:42 +0200 Subject: [PATCH 064/123] code cleanup --- Source/Diagnostics/ParticleIO.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 992cf71bce7..af474b1c656 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -327,8 +327,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); - //const bool galerkin_interpolation = WarpX::galerkin_interpolation; - //const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; auto fields_names = amrex::Array{ @@ -420,6 +418,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, //getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, // Bx_particle, By_particle, Bz_particle); + // need to implement externalEB const int depos_order_perp = 1; // adapt w/ shape function const int depos_order_para = 1; @@ -439,7 +438,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, ex_type, ey_type, ez_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes //, nox, galerkin_interpolation + dinv, xyzmin, lo, n_rz_azimuthal_modes ); } @@ -450,7 +449,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, bx_type, by_type, bz_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes //, nox, galerkin_interpolation + dinv, xyzmin, lo, n_rz_azimuthal_modes ); } @@ -461,15 +460,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, auto& rBy_particle = By_particle_arr; auto& rBz_particle = Bz_particle_arr; - /* - amrex::ParticleReal* Ex_particle_ptr = (ex_control == doEx) ? &Ex_particle_arr[ip] : nullptr; - amrex::ParticleReal* Ey_particle_ptr = (ey_control == doEy) ? &Ey_particle_arr[ip] : nullptr; - amrex::ParticleReal* Ez_particle_ptr = (ez_control == doEz) ? &Ez_particle_arr[ip] : nullptr; - amrex::ParticleReal* Bx_particle_ptr = (bx_control == doBx) ? &Bx_particle_arr[ip] : nullptr; - amrex::ParticleReal* By_particle_ptr = (by_control == doBy) ? &By_particle_arr[ip] : nullptr; - amrex::ParticleReal* Bz_particle_ptr = (bz_control == doBz) ? &Bz_particle_arr[ip] : nullptr; - */ - amrex::ignore_unused(rEx_particle, rEy_particle, rEz_particle, rBx_particle, rBy_particle, rBz_particle); From cf8aa6e93b30ab6fad9297409f6e8059dacd8357 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 2 Apr 2025 12:19:55 +0000 Subject: [PATCH 065/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index af474b1c656..ad48051474f 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -438,7 +438,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, ex_type, ey_type, ez_type, - dinv, xyzmin, lo, n_rz_azimuthal_modes + dinv, xyzmin, lo, n_rz_azimuthal_modes ); } From 493699b66516bd8cf7635a33fa41b4055546a72a Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 16:21:27 +0200 Subject: [PATCH 066/123] corrected with shape function --- Source/Diagnostics/ParticleIO.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index ad48051474f..f5dd6414ac7 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -327,6 +327,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); + const bool galerkin_interpolation = WarpX::galerkin_interpolation; + const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; auto fields_names = amrex::Array{ @@ -420,8 +422,6 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, // Bx_particle, By_particle, Bz_particle); // need to implement externalEB - const int depos_order_perp = 1; // adapt w/ shape function - const int depos_order_para = 1; if (ex_control == noEx && ey_control == noEy && ez_control == noEz && bx_control == noBx && by_control == noBy && bz_control == noBz) { // only for compiling the kernel where nothing is asked (but the function won't be called anyway) @@ -432,7 +432,9 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) - { + { + const int depos_order_perp = nox; + const int depos_order_para = nox - galerkin_interpolation; doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, @@ -444,6 +446,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { + const int depos_order_para = nox; + const int depos_order_perp = nox - galerkin_interpolation; doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, From 100bba222a4a721b9d2d4910fdc24edb7beb0256 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 14:23:00 +0000 Subject: [PATCH 067/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index f5dd6414ac7..20a474fe722 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -432,7 +432,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) - { + { const int depos_order_perp = nox; const int depos_order_para = nox - galerkin_interpolation; doDirectGatherVectorField( From c480bb72352ffa874024e7c6f3e6f1677c8559ba Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 16:25:36 +0200 Subject: [PATCH 068/123] constexpr --- Source/Diagnostics/ParticleIO.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 20a474fe722..f1c469e9b71 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -433,8 +433,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - const int depos_order_perp = nox; - const int depos_order_para = nox - galerkin_interpolation; + constexpr int depos_order_perp = nox; + constexpr int depos_order_para = nox - galerkin_interpolation; doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, @@ -446,8 +446,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { - const int depos_order_para = nox; - const int depos_order_perp = nox - galerkin_interpolation; + constexpr int depos_order_para = nox; + constexpr int depos_order_perp = nox - galerkin_interpolation; doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, From 8c83e766c999a906d77fadf5bbf6d0a46f0dd898 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 16:31:04 +0200 Subject: [PATCH 069/123] no constexpr --- Source/Diagnostics/ParticleIO.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index f1c469e9b71..627a37ede04 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -433,9 +433,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - constexpr int depos_order_perp = nox; - constexpr int depos_order_para = nox - galerkin_interpolation; - doDirectGatherVectorField( + doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -446,9 +444,9 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { - constexpr int depos_order_para = nox; - constexpr int depos_order_perp = nox - galerkin_interpolation; - doDirectGatherVectorField( + // constexpr int depos_order_para = nox; + // constexpr int depos_order_perp = nox - galerkin_interpolation; + doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, From 4e8d4131dd598df759e14978540a896d61c9bdb9 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 16:46:18 +0200 Subject: [PATCH 070/123] test workaround for constant expressions --- Source/Diagnostics/ParticleIO.cpp | 35 +++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 627a37ede04..9d587a9906d 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -331,6 +331,37 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; + // need to do that for constant expression for compilation + if (galerkin_interpolation) { + if (nox == 1) { + const int depos_order_E_perp_B_para = 1; + const int depos_order_E_para_B_perp = 0; + } else if (nox == 2) { + const int depos_order_E_perp_B_para = 2; + const int depos_order_E_para_B_perp = 1; + } else if (nox == 3) { + const int depos_order_E_perp_B_para = 3; + const int depos_order_E_para_B_perp = 2; + } else if (nox == 4) { + const int depos_order_E_perp_B_para = 4; + const int depos_order_E_para_B_perp = 3; + } + } else { + if (nox == 1) { + const int depos_order_E_perp_B_para = 1; + const int depos_order_E_para_B_perp = 1; + } else if (nox == 2) { + const int depos_order_E_perp_B_para = 2; + const int depos_order_E_para_B_perp = 2; + } else if (nox == 3) { + const int depos_order_E_perp_B_para = 3; + const int depos_order_E_para_B_perp = 3; + } else if (nox == 4) { + const int depos_order_E_perp_B_para = 4; + const int depos_order_E_para_B_perp = 4; + } + } + auto fields_names = amrex::Array{ "Ex", "Ey", "Ez", "Bx", "By", "Bz"}; @@ -433,7 +464,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - doDirectGatherVectorField( + doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -446,7 +477,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, { // constexpr int depos_order_para = nox; // constexpr int depos_order_perp = nox - galerkin_interpolation; - doDirectGatherVectorField( + doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, From d2100a6e335f4740d03669aa807edc0c29afeeed Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 14:47:57 +0000 Subject: [PATCH 071/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9d587a9906d..dc93c5174e6 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -331,7 +331,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; - // need to do that for constant expression for compilation + // need to do that for constant expression for compilation if (galerkin_interpolation) { if (nox == 1) { const int depos_order_E_perp_B_para = 1; From e48b7f7d5a143aa725e751c9dbc2ab36469a1732 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:12:30 +0200 Subject: [PATCH 072/123] please work --- Source/Diagnostics/ParticleIO.cpp | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index dc93c5174e6..a3a5e67f0ef 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -334,31 +334,31 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, // need to do that for constant expression for compilation if (galerkin_interpolation) { if (nox == 1) { - const int depos_order_E_perp_B_para = 1; - const int depos_order_E_para_B_perp = 0; + auto gatherE = doDirectGatherVectorField<1,0>; + auto gatherB = doDirectGatherVectorField<0,1>; } else if (nox == 2) { - const int depos_order_E_perp_B_para = 2; - const int depos_order_E_para_B_perp = 1; + auto gatherE = doDirectGatherVectorField<2,1>; + auto gatherB = doDirectGatherVectorField<1,2>; } else if (nox == 3) { - const int depos_order_E_perp_B_para = 3; - const int depos_order_E_para_B_perp = 2; + auto gatherE = doDirectGatherVectorField<3,2>; + auto gatherB = doDirectGatherVectorField<2,3>; } else if (nox == 4) { - const int depos_order_E_perp_B_para = 4; - const int depos_order_E_para_B_perp = 3; + auto gatherE = doDirectGatherVectorField<4,3>; + auto gatherB = doDirectGatherVectorField<3,4>; } } else { if (nox == 1) { - const int depos_order_E_perp_B_para = 1; - const int depos_order_E_para_B_perp = 1; + auto gatherE = doDirectGatherVectorField<1,1>; + auto gatherB = doDirectGatherVectorField<1,1>; } else if (nox == 2) { - const int depos_order_E_perp_B_para = 2; - const int depos_order_E_para_B_perp = 2; + auto gatherE = doDirectGatherVectorField<2,2>; + auto gatherB = doDirectGatherVectorField<2,2>; } else if (nox == 3) { - const int depos_order_E_perp_B_para = 3; - const int depos_order_E_para_B_perp = 3; + auto gatherE = doDirectGatherVectorField<3,3>; + auto gatherB = doDirectGatherVectorField<3,3>; } else if (nox == 4) { - const int depos_order_E_perp_B_para = 4; - const int depos_order_E_para_B_perp = 4; + auto gatherE = doDirectGatherVectorField<4,4>; + auto gatherB = doDirectGatherVectorField<4,4>; } } @@ -464,7 +464,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - doDirectGatherVectorField( + gatherE( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -477,7 +477,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, { // constexpr int depos_order_para = nox; // constexpr int depos_order_perp = nox - galerkin_interpolation; - doDirectGatherVectorField( + gatherB( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, From 93f003690c40aa8fdcd5374ff84ca42a941f57dc Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:17:29 +0200 Subject: [PATCH 073/123] def gatherE gatherB outside of if else scope --- Source/Diagnostics/ParticleIO.cpp | 44 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index a3a5e67f0ef..780ba8b7539 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -332,33 +332,45 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; // need to do that for constant expression for compilation + void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + const amrex::IndexType&, const amrex::IndexType&, const amrex::IndexType&, + const amrex::XDim3&, const amrex::XDim3&, const Dim3&, int); + + void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + const amrex::IndexType&, const amrex::IndexType&, const amrex::IndexType&, + const amrex::XDim3&, const amrex::XDim3&, const Dim3&, int); + if (galerkin_interpolation) { if (nox == 1) { - auto gatherE = doDirectGatherVectorField<1,0>; - auto gatherB = doDirectGatherVectorField<0,1>; + gatherE = doDirectGatherVectorField<1,0>; + gatherB = doDirectGatherVectorField<0,1>; } else if (nox == 2) { - auto gatherE = doDirectGatherVectorField<2,1>; - auto gatherB = doDirectGatherVectorField<1,2>; + gatherE = doDirectGatherVectorField<2,1>; + gatherB = doDirectGatherVectorField<1,2>; } else if (nox == 3) { - auto gatherE = doDirectGatherVectorField<3,2>; - auto gatherB = doDirectGatherVectorField<2,3>; + gatherE = doDirectGatherVectorField<3,2>; + gatherB = doDirectGatherVectorField<2,3>; } else if (nox == 4) { - auto gatherE = doDirectGatherVectorField<4,3>; - auto gatherB = doDirectGatherVectorField<3,4>; + gatherE = doDirectGatherVectorField<4,3>; + gatherB = doDirectGatherVectorField<3,4>; } } else { if (nox == 1) { - auto gatherE = doDirectGatherVectorField<1,1>; - auto gatherB = doDirectGatherVectorField<1,1>; + gatherE = doDirectGatherVectorField<1,1>; + gatherB = doDirectGatherVectorField<1,1>; } else if (nox == 2) { - auto gatherE = doDirectGatherVectorField<2,2>; - auto gatherB = doDirectGatherVectorField<2,2>; + gatherE = doDirectGatherVectorField<2,2>; + gatherB = doDirectGatherVectorField<2,2>; } else if (nox == 3) { - auto gatherE = doDirectGatherVectorField<3,3>; - auto gatherB = doDirectGatherVectorField<3,3>; + gatherE = doDirectGatherVectorField<3,3>; + gatherB = doDirectGatherVectorField<3,3>; } else if (nox == 4) { - auto gatherE = doDirectGatherVectorField<4,4>; - auto gatherB = doDirectGatherVectorField<4,4>; + gatherE = doDirectGatherVectorField<4,4>; + gatherB = doDirectGatherVectorField<4,4>; } } From ddd7da018f6ff957e8abc94e8db1e50c198b500a Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:22:01 +0200 Subject: [PATCH 074/123] corrected types --- Source/Diagnostics/ParticleIO.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 780ba8b7539..a2776130852 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -332,17 +332,17 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; // need to do that for constant expression for compilation - void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - const amrex::IndexType&, const amrex::IndexType&, const amrex::IndexType&, - const amrex::XDim3&, const amrex::XDim3&, const Dim3&, int); - - void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - const amrex::IndexType&, const amrex::IndexType&, const amrex::IndexType&, - const amrex::XDim3&, const amrex::XDim3&, const Dim3&, int); + void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + amrex::IndexType, amrex::IndexType, amrex::IndexType, + const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); + + void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + amrex::IndexType, amrex::IndexType, amrex::IndexType, + const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); if (galerkin_interpolation) { if (nox == 1) { From f548c45e5c00732f6f74ed945773913c5f8bf499 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:23:41 +0000 Subject: [PATCH 075/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index a2776130852..fea52731105 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -332,16 +332,16 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; // need to do that for constant expression for compilation - void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - amrex::IndexType, amrex::IndexType, amrex::IndexType, + void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + amrex::IndexType, amrex::IndexType, amrex::IndexType, const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); - void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - amrex::IndexType, amrex::IndexType, amrex::IndexType, + void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, + amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + amrex::IndexType, amrex::IndexType, amrex::IndexType, const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); if (galerkin_interpolation) { From 2e429ace1f5e60439da01e2a88bc5c40d6ebe7bf Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:24:54 +0200 Subject: [PATCH 076/123] removed old var from ignore unused --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index fea52731105..f03717800f8 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -468,7 +468,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if (ex_control == noEx && ey_control == noEy && ez_control == noEz && bx_control == noBx && by_control == noBy && bz_control == noBz) { // only for compiling the kernel where nothing is asked (but the function won't be called anyway) - amrex::ignore_unused(depos_order_para, depos_order_perp, Ex_grid, Ey_grid, Ez_grid, + amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); } From 265a5f6f1e7bac69c91399a960d412610a33adfb Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:30:35 +0200 Subject: [PATCH 077/123] always initialise funcs --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index f03717800f8..b781cff77d0 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -354,7 +354,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,2>; gatherB = doDirectGatherVectorField<2,3>; - } else if (nox == 4) { + } else { // if (nox == 4) { gatherE = doDirectGatherVectorField<4,3>; gatherB = doDirectGatherVectorField<3,4>; } @@ -368,7 +368,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,3>; gatherB = doDirectGatherVectorField<3,3>; - } else if (nox == 4) { + } else { // if (nox == 4) { gatherE = doDirectGatherVectorField<4,4>; gatherB = doDirectGatherVectorField<4,4>; } From f284f509852428ba80fd728ff92dfcf62906b7f0 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:37:42 +0200 Subject: [PATCH 078/123] wrong types --- Source/Diagnostics/ParticleIO.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index b781cff77d0..bb64b362968 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -334,15 +334,15 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, // need to do that for constant expression for compilation void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, amrex::IndexType, amrex::IndexType, amrex::IndexType, - const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); + const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, const int); void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, + const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, amrex::IndexType, amrex::IndexType, amrex::IndexType, - const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, int); + const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, const int); if (galerkin_interpolation) { if (nox == 1) { From ada5051b039a512e6d06ab30646fa0f476048b6b Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Thu, 3 Apr 2025 17:45:17 +0200 Subject: [PATCH 079/123] first capture of variable outside constexpr --- Source/Diagnostics/ParticleIO.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index bb64b362968..bec2af33e49 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -354,7 +354,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,2>; gatherB = doDirectGatherVectorField<2,3>; - } else { // if (nox == 4) { + } else { gatherE = doDirectGatherVectorField<4,3>; gatherB = doDirectGatherVectorField<3,4>; } @@ -368,7 +368,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,3>; gatherB = doDirectGatherVectorField<3,3>; - } else { // if (nox == 4) { + } else { gatherE = doDirectGatherVectorField<4,4>; gatherB = doDirectGatherVectorField<4,4>; } @@ -473,10 +473,13 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); } + auto& rGatherE = gatherE; + auto& rGatherB = gatherB; + amrex::ignore_unused(rGatherE, rGatherB); if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - gatherE( + rGatherE( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -487,9 +490,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { - // constexpr int depos_order_para = nox; - // constexpr int depos_order_perp = nox - galerkin_interpolation; - gatherB( + rGatherB( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, From c61947e14e13fa8aace90eec1d3b009962d06d33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:46:48 +0000 Subject: [PATCH 080/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index bec2af33e49..b80e07121f6 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -354,7 +354,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,2>; gatherB = doDirectGatherVectorField<2,3>; - } else { + } else { gatherE = doDirectGatherVectorField<4,3>; gatherB = doDirectGatherVectorField<3,4>; } @@ -368,7 +368,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } else if (nox == 3) { gatherE = doDirectGatherVectorField<3,3>; gatherB = doDirectGatherVectorField<3,3>; - } else { + } else { gatherE = doDirectGatherVectorField<4,4>; gatherB = doDirectGatherVectorField<4,4>; } From a252513e101805a0521fa5ccd9a6aed5446c41ff Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 4 Apr 2025 16:20:54 +0200 Subject: [PATCH 081/123] template function to fix SYCL compilation --- Source/Diagnostics/ParticleIO.cpp | 87 ++++++++++++----------------- Source/Diagnostics/WarpXOpenPMD.cpp | 2 +- Source/Particles/ParticleIO.H | 2 +- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index b80e07121f6..9cf3b7b9113 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -302,6 +302,9 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, } } +namespace +{ +template void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { @@ -327,53 +330,8 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, constexpr auto lev0=0; const amrex::XDim3 dinv = WarpX::InvCellSize(lev0); - const bool galerkin_interpolation = WarpX::galerkin_interpolation; - const int nox = WarpX::nox; const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; - // need to do that for constant expression for compilation - void (*gatherE)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - amrex::IndexType, amrex::IndexType, amrex::IndexType, - const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, const int); - - void (*gatherB)(amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal, - amrex::ParticleReal&, amrex::ParticleReal&, amrex::ParticleReal&, - const amrex::Array4&, const amrex::Array4&, const amrex::Array4&, - amrex::IndexType, amrex::IndexType, amrex::IndexType, - const amrex::XDim3&, const amrex::XDim3&, const amrex::Dim3&, const int); - - if (galerkin_interpolation) { - if (nox == 1) { - gatherE = doDirectGatherVectorField<1,0>; - gatherB = doDirectGatherVectorField<0,1>; - } else if (nox == 2) { - gatherE = doDirectGatherVectorField<2,1>; - gatherB = doDirectGatherVectorField<1,2>; - } else if (nox == 3) { - gatherE = doDirectGatherVectorField<3,2>; - gatherB = doDirectGatherVectorField<2,3>; - } else { - gatherE = doDirectGatherVectorField<4,3>; - gatherB = doDirectGatherVectorField<3,4>; - } - } else { - if (nox == 1) { - gatherE = doDirectGatherVectorField<1,1>; - gatherB = doDirectGatherVectorField<1,1>; - } else if (nox == 2) { - gatherE = doDirectGatherVectorField<2,2>; - gatherB = doDirectGatherVectorField<2,2>; - } else if (nox == 3) { - gatherE = doDirectGatherVectorField<3,3>; - gatherB = doDirectGatherVectorField<3,3>; - } else { - gatherE = doDirectGatherVectorField<4,4>; - gatherB = doDirectGatherVectorField<4,4>; - } - } - auto fields_names = amrex::Array{ "Ex", "Ey", "Ez", "Bx", "By", "Bz"}; @@ -473,13 +431,9 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); } - auto& rGatherE = gatherE; - auto& rGatherB = gatherB; - amrex::ignore_unused(rGatherE, rGatherB); - if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { - rGatherE( + doDirectGatherVectorField( xp, yp, zp, Ex_particle, Ey_particle, Ez_particle, Ex_grid, Ey_grid, Ez_grid, @@ -490,7 +444,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { - rGatherB( + doDirectGatherVectorField( xp, yp, zp, Bx_particle, By_particle, Bz_particle, Bx_grid, By_grid, Bz_grid, @@ -531,3 +485,34 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } } +} + +void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, + ElectromagneticSolverAlgo electromagnetic_solver_id, + const bool fields_to_plot[], + const int depos_order, + const bool galerkin_interpolation, + bool is_full_diagnostic) +{ + if (galerkin_interpolation) { + if (depos_order == 1) { + ::storeEMFieldsOnParticles<1, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 2) { + ::storeEMFieldsOnParticles<2, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 3) { + ::storeEMFieldsOnParticles<3, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 4) { + ::storeEMFieldsOnParticles<4, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } + } else { + if (depos_order == 1) { + ::storeEMFieldsOnParticles<1, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 2) { + ::storeEMFieldsOnParticles<2, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 3) { + ::storeEMFieldsOnParticles<3, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } else if (depos_order == 4) { + ::storeEMFieldsOnParticles<4, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + } + } +} diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 6f55776d6fa..c282362ee36 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -610,7 +610,7 @@ for (const auto & particle_diag : particle_diags) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, is_full_diagnostic); } if ( particle_diag.m_plot_EM ) { - storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, particle_diag.m_plot_EM_flags, is_full_diagnostic); + storeEMFieldsOnParticles( tmp, WarpX::electromagnetic_solver_id, particle_diag.m_plot_EM_flags, WarpX::nox, WarpX::galerkin_interpolation, is_full_diagnostic); } // names of amrex::ParticleReal and int particle attributes in SoA data diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index f676b03c438..a8d8ed79f62 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], const int depos_order, const bool galerkin_interpolation, bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 1f7f414d2253b9addc4a27dcae1ef79f6601293b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 14:22:29 +0000 Subject: [PATCH 082/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 9cf3b7b9113..3b3736ce837 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -488,10 +488,10 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, - const bool fields_to_plot[], + ElectromagneticSolverAlgo electromagnetic_solver_id, + const bool fields_to_plot[], const int depos_order, - const bool galerkin_interpolation, + const bool galerkin_interpolation, bool is_full_diagnostic) { if (galerkin_interpolation) { From 34fde581e1735ff059d8ee0231d24e9bcc41f663 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 4 Apr 2025 16:24:58 +0200 Subject: [PATCH 083/123] changed template typename --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 3b3736ce837..b665b980e3c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, namespace { -template +template void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { @@ -485,7 +485,7 @@ storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, } } -} +} // namespace void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, From 0a0b73f11311c22a086394ebb9ac79fe3ff031ce Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 4 Apr 2025 16:29:41 +0200 Subject: [PATCH 084/123] changed template name --- Source/Diagnostics/ParticleIO.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index b665b980e3c..a79e1796a96 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -306,7 +306,7 @@ namespace { template void -storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, +storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; @@ -496,23 +496,23 @@ void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, { if (galerkin_interpolation) { if (depos_order == 1) { - ::storeEMFieldsOnParticles<1, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<1, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 2) { - ::storeEMFieldsOnParticles<2, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<2, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 3) { - ::storeEMFieldsOnParticles<3, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<3, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 4) { - ::storeEMFieldsOnParticles<4, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<4, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } } else { if (depos_order == 1) { - ::storeEMFieldsOnParticles<1, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<1, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 2) { - ::storeEMFieldsOnParticles<2, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<2, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 3) { - ::storeEMFieldsOnParticles<3, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<3, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } else if (depos_order == 4) { - ::storeEMFieldsOnParticles<4, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); + ::storeEMFieldsOnParticles_t<4, 0>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); } } } From 3d7c9619d3afce8fc4a26f39db23aa14bcac11f4 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 4 Apr 2025 16:33:10 +0200 Subject: [PATCH 085/123] changed templates types --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index a79e1796a96..d4c5c7ed3b6 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, namespace { -template +template void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { From 20d5d4bb96d09e419827ab0991fb421e53931ede Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Fri, 4 Apr 2025 17:58:32 +0200 Subject: [PATCH 086/123] code cleanup + documentation --- Docs/source/usage/parameters.rst | 18 ++++++++++-------- Source/Diagnostics/ParticleIO.cpp | 17 ++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 511cd07334c..7088dd0a5bb 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2243,7 +2243,7 @@ Filtering .. warning:: - Known bug: filter currently not working with FDTD solver in RZ geometry (see https://github.com/ECP-WarpX/WarpX/issues/1943). + Known bug: filter currently not working with FDTD solver in RZ geometry (see https://github.com/BLAST-WarpX/warpx/issues/1943). * ``warpx.filter_npass_each_dir`` (`3 int`) optional (default `1 1 1`) Number of passes along each direction for the bilinear filter. @@ -2813,14 +2813,13 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a * ``.openpmd_backend`` (``bp5``, ``bp4``, ``h5`` or ``json``) optional, only used if ``.format = openpmd`` `I/O backend `_ for `openPMD `_ data dumps. - ``bp`` is the `ADIOS I/O library `_, ``h5`` is the `HDF5 format `_, and ``json`` is a `simple text format `_. - ``json`` only works with serial/single-rank jobs. - When WarpX is compiled with openPMD support, the first available backend in the order given above is taken. + ``bp5``/``bp4`` is the `ADIOS I/O library `_, ``h5`` is the `HDF5 format `_, and ``json`` is a `simple text format `_. + ``json`` is for debugging and only works with serial/single-rank jobs. * ``.openpmd_encoding`` (optional, ``v`` (variable based), ``f`` (file based) or ``g`` (group based) ) only read if ``.format = openpmd``. openPMD `file output encoding `__. File based: one file per timestep (slower), group/variable based: one file for all steps (faster)). - ``variable based`` is an `experimental feature with ADIOS2 `__ and not supported for back-transformed diagnostics. This format is also not supported by OpenPMDTimeSeries at the moment, the script :download:`read_variable_based_adios2.py <../../../Tools/PostProcessing/read_variable_based_adios2.py>` provides basic functions to read variable-based particle diagnostics directly with the ``adios2`` module. + ``variable based`` is an `experimental feature with ADIOS2 BP5 `__ that will replace ``g``. Default: ``f`` (full diagnostics) * ``.adios2_operator.type`` (``zfp``, ``blosc``) optional, @@ -2854,7 +2853,7 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a .openpmd_backend = bp5 .adios2_engine.parameters.FlattenSteps = on -* ``.adios2_engine.type`` (``bp4``, ``sst``, ``ssc``, ``dataman``) optional, +* ``.adios2_engine.type`` (``bp5``, ``bp4``, ``sst``, ``ssc``, ``dataman``) optional, `ADIOS2 Engine type `__ for `openPMD `_ data dumps. See full list of engines at `ADIOS2 readthedocs `__ @@ -2959,10 +2958,13 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a * ``..variables`` (list of `strings` separated by spaces, optional) List of particle quantities to write to output. Choices are ``x``, ``y``, ``z`` for the particle positions (3D and RZ), ``x`` & ``z`` in 2D, ``z`` in 1D, - ``w`` for the particle weight, ``ux``, ``uy``, ``uz`` for the particle momenta, and ``EM`` for the electromagnetic fields. + ``w`` for the particle weight, ``ux``, ``uy``, ``uz`` for the particle momenta, and ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz`` for the electromagnetic fields. When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. - By default, all particle quantities (except ``phi`` and ``EM``) are written. + By default, positions, momenta and particle weight are written. If ``..variables = none``, no particle data are written. + + .. note:: + The electromagnetic fields diagnostics will not display the external fields. * ``..random_fraction`` (`float`) optional If provided ``..random_fraction = a``, only `a` fraction of the particle data of this species will be dumped randomly in diag ````, i.e. if `rand() < a`, this particle will be dumped, where `rand()` denotes a random number generator. diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index d4c5c7ed3b6..34a2b3a4253 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,10 +304,15 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, namespace { +// This template is isolated in a separate namespace to simplify the usage of +// the doDirectGatherVectorField template and avoid branching template void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], bool is_full_diagnostic) { + ElectromagneticSolverAlgo electromagnetic_solver_id, + const bool fields_to_plot[], + bool is_full_diagnostic) +{ using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; @@ -386,9 +391,6 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, const auto getPosition = GetParticlePosition(pti); - // const auto getExternalEB = GetExternalEBField(a_pti, lev0); - // a_pti is a WarpXParIter, currently undefined - amrex::ParticleReal* Ex_particle_arr = (fields_to_plot[0]) ? pti.GetStructOfArrays().GetRealData(fields_index[0]).dataPtr() : nullptr; amrex::ParticleReal* Ey_particle_arr = (fields_to_plot[1]) ? pti.GetStructOfArrays().GetRealData(fields_index[1]).dataPtr() : nullptr; amrex::ParticleReal* Ez_particle_arr = (fields_to_plot[2]) ? pti.GetStructOfArrays().GetRealData(fields_index[2]).dataPtr() : nullptr; @@ -400,7 +402,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev0, 0._rt); const Dim3 lo = lbound(box); - // Loop over the particles and compute the EM field using the doGatherShapeN function + // Loop over the particles and compute the EM field using the doDirectGatherVectorField function amrex::ParallelFor( TypeList, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions, CompileTimeOptions>{}, @@ -419,10 +421,6 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; - //getExternalEB(ip, Ex_particle, Ey_particle, Ez_particle, - // Bx_particle, By_particle, Bz_particle); - // need to implement externalEB - if (ex_control == noEx && ey_control == noEy && ez_control == noEz && bx_control == noBx && by_control == noBy && bz_control == noBz) { // only for compiling the kernel where nothing is asked (but the function won't be called anyway) @@ -453,6 +451,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ); } + // first capture of the variables in constexpr is not supported auto& rEx_particle = Ex_particle_arr; auto& rEy_particle = Ey_particle_arr; auto& rEz_particle = Ez_particle_arr; From c926f9a31c1314d0fd06fe977e823a235ac5d29b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:00:35 +0000 Subject: [PATCH 087/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Docs/source/usage/parameters.rst | 2 +- Source/Diagnostics/ParticleIO.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 7088dd0a5bb..33f8323fbff 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2962,7 +2962,7 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. By default, positions, momenta and particle weight are written. If ``..variables = none``, no particle data are written. - + .. note:: The electromagnetic fields diagnostics will not display the external fields. diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 34a2b3a4253..94cb97d1fcb 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -309,9 +309,9 @@ namespace template void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, - const bool fields_to_plot[], - bool is_full_diagnostic) + ElectromagneticSolverAlgo electromagnetic_solver_id, + const bool fields_to_plot[], + bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; From b75e0d60ea28eea1fd784d2d74a0f3e40b8e2a00 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 10:42:52 +0200 Subject: [PATCH 088/123] check for illegal memory access --- Source/Diagnostics/ParticleIO.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 94cb97d1fcb..4854acfad5c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -411,6 +411,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, auto bx_control, auto by_control, auto bz_control) { + if (ip >= pti.numParticles()) return; // Ensure valid particle index amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); From 8158c05de3f952e976e1dd0cd03215dad409539c Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 10:48:37 +0200 Subject: [PATCH 089/123] removed deleted function --- Source/Diagnostics/ParticleIO.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 4854acfad5c..94cb97d1fcb 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -411,7 +411,6 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [=] AMREX_GPU_DEVICE (long ip, auto ex_control, auto ey_control, auto ez_control, auto bx_control, auto by_control, auto bz_control) { - if (ip >= pti.numParticles()) return; // Ensure valid particle index amrex::ParticleReal xp, yp, zp; getPosition(ip, xp, yp, zp); From d436f2d40da78a1372227b850491df40d5d14f81 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 15:12:08 +0200 Subject: [PATCH 090/123] changes in doc --- Docs/source/usage/parameters.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 33f8323fbff..0e26506dd22 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2088,6 +2088,13 @@ Details about the collision models can be found in the :ref:`theory section .use_global_debye_length`` (`bool`) optional + Only for ``pairwisecoulomb``. When set, the Debye length used in the Coulomb log + is calculated including all species in the simulation. The lengths are combined + using the square root of one over the sum of one over the squares of the Debye lengths + of each species. By default, this is turned off. Note that if ``.CoulombLog`` + is specified, this Debye length is not used. + * ``.fusion_multiplier`` (`float`) optional. Only for ``nuclearfusion``. Increasing ``fusion_multiplier`` creates more macroparticles of fusion @@ -2815,6 +2822,7 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a `I/O backend `_ for `openPMD `_ data dumps. ``bp5``/``bp4`` is the `ADIOS I/O library `_, ``h5`` is the `HDF5 format `_, and ``json`` is a `simple text format `_. ``json`` is for debugging and only works with serial/single-rank jobs. + When WarpX is compiled with openPMD support, the first available backend in the order given above is taken. * ``.openpmd_encoding`` (optional, ``v`` (variable based), ``f`` (file based) or ``g`` (group based) ) only read if ``.format = openpmd``. openPMD `file output encoding `__. From f9698043943934df4b2bc658389fb71dfa66c051 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun <48356331+grobertdautun@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:26:07 +0200 Subject: [PATCH 091/123] removed const Co-authored-by: Luca Fedeli --- Source/Particles/ParticleIO.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index a8d8ed79f62..7b87b12ec77 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], const int depos_order, const bool galerkin_interpolation, bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[], int depos_order, bool galerkin_interpolation, bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 645e35ec95a9a4f906992adad355d42b19563abb Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun <48356331+grobertdautun@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:26:42 +0200 Subject: [PATCH 092/123] changed template description Co-authored-by: Luca Fedeli --- Source/Diagnostics/ParticleIO.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 94cb97d1fcb..3f6e9b9f71b 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,8 +304,11 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, namespace { -// This template is isolated in a separate namespace to simplify the usage of -// the doDirectGatherVectorField template and avoid branching +// This template function is called with all the possible combinations +// of the template parameters by storeEMFieldsOnParticles. +// depos_order and galerkin_interpolation must be template parameters +// because they are template parameters of doDirectGatherVectorField, +// which is called by this function. template void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, From c6ddf579d7a7c5e663236c56411c7114641f4aa6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:26:51 +0000 Subject: [PATCH 093/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 3f6e9b9f71b..faa5f9bca54 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -304,7 +304,7 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, namespace { -// This template function is called with all the possible combinations +// This template function is called with all the possible combinations // of the template parameters by storeEMFieldsOnParticles. // depos_order and galerkin_interpolation must be template parameters // because they are template parameters of doDirectGatherVectorField, From d9a9cc7854d29d3d9247b333a91e2b352894af72 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun <48356331+grobertdautun@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:27:34 +0200 Subject: [PATCH 094/123] add const Co-authored-by: Luca Fedeli --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index faa5f9bca54..d2e42ea550f 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -314,7 +314,7 @@ void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], - bool is_full_diagnostic) + const bool is_full_diagnostic) { using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; From a1ac46b9ea2572ca449081d19b3c15010edc74da Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun <48356331+grobertdautun@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:29:26 +0200 Subject: [PATCH 095/123] add const Co-authored-by: Luca Fedeli --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index d2e42ea550f..8bb8fb2978b 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -494,7 +494,7 @@ void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, const bool fields_to_plot[], const int depos_order, const bool galerkin_interpolation, - bool is_full_diagnostic) + const bool is_full_diagnostic) { if (galerkin_interpolation) { if (depos_order == 1) { From c97d4e2068afcb34bf789445b0ab84e978264878 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun <48356331+grobertdautun@users.noreply.github.com> Date: Mon, 7 Apr 2025 16:30:55 +0200 Subject: [PATCH 096/123] clearer comment Co-authored-by: Luca Fedeli --- .../inputs_test_2d_particle_EM_diagnostics | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics index b6c2b603b2f..a13df22d624 100644 --- a/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics +++ b/Examples/Tests/EM_fields_on_particles/inputs_test_2d_particle_EM_diagnostics @@ -72,7 +72,7 @@ diag1.openpmd_backend = h5 diag1.fields_to_plot = none diag1.write_species = 1 diag1.species = electron -diag1.electron.variables = Ex Ey Ez Bx By Bz # will emit a warning because no position +diag1.electron.variables = Ex Ey Ez Bx By Bz # will emit a warning because no position is asked diag_checksum.intervals = 400:400 diag_checksum.diag_type = Full From befb305f7270e08fa634a03fb98885ecd92c38b1 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 16:43:30 +0200 Subject: [PATCH 097/123] changes requested --- Source/Diagnostics/ParticleDiag/ParticleDiag.cpp | 12 ++++++------ Source/Diagnostics/ParticleIO.cpp | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 72573ca7654..da6db56b148 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -46,12 +46,12 @@ ParticleDiag::ParticleDiag ( } else if (var == "Ex" || var == "Ey" || var == "Ez" || var == "Bx" || var == "By" || var == "Bz") { m_plot_EM = true; - if (var == "Ex") m_plot_EM_flags[0] = true; - if (var == "Ey") m_plot_EM_flags[1] = true; - if (var == "Ez") m_plot_EM_flags[2] = true; - if (var == "Bx") m_plot_EM_flags[3] = true; - if (var == "By") m_plot_EM_flags[4] = true; - if (var == "Bz") m_plot_EM_flags[5] = true; + if (var == "Ex") {m_plot_EM_flags[0] = true;} + if (var == "Ey") {m_plot_EM_flags[1] = true;} + if (var == "Ez") {m_plot_EM_flags[2] = true;} + if (var == "Bx") {m_plot_EM_flags[3] = true;} + if (var == "By") {m_plot_EM_flags[4] = true;} + if (var == "Bz") {m_plot_EM_flags[5] = true;} } else { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(pc->HasRealComp(var), "variables argument '" + var diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 94cb97d1fcb..317ddfca0df 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -340,7 +340,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, auto fields_names = amrex::Array{ "Ex", "Ey", "Ez", "Bx", "By", "Bz"}; - auto fields_index = amrex::Array{0,0,0,0,0,0}; + auto fields_index = amrex::Array{-1,-1,-1,-1,-1,-1}; enum Ex_flags { doEx, noEx }; enum Ey_flags { doEy, noEy }; @@ -421,7 +421,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; - if (ex_control == noEx && ey_control == noEy && ez_control == noEz && + if constexpr (ex_control == noEx && ey_control == noEy && ez_control == noEz && bx_control == noBx && by_control == noBy && bz_control == noBz) { // only for compiling the kernel where nothing is asked (but the function won't be called anyway) amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, @@ -451,7 +451,8 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ); } - // first capture of the variables in constexpr is not supported + // first capture of the variables in constexpr is not supported with NVCC + // so we have to define these references here auto& rEx_particle = Ex_particle_arr; auto& rEy_particle = Ey_particle_arr; auto& rEz_particle = Ez_particle_arr; From f04bca0c996104a0eb2fcc70d2f80a935017fa2c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 14:44:51 +0000 Subject: [PATCH 098/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index cc03e722dd3..ae75b2f0d00 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -454,7 +454,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ); } - // first capture of the variables in constexpr is not supported with NVCC + // first capture of the variables in constexpr is not supported with NVCC // so we have to define these references here auto& rEx_particle = Ex_particle_arr; auto& rEy_particle = Ey_particle_arr; From 9ee657579fdebbdebb0e83c913f4760e19514a1a Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 16:48:30 +0200 Subject: [PATCH 099/123] reverted const changes --- Source/Particles/ParticleIO.H | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 7b87b12ec77..4434b5d7604 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, bool fields_to_plot[], int depos_order, bool galerkin_interpolation, bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], const int depos_order, const bool galerkin_interpolation, const bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 7f0d1b5c58864d76a95877456102d905d1432a16 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 7 Apr 2025 17:00:17 +0200 Subject: [PATCH 100/123] change in constexpr --- Docs/source/usage/parameters.rst | 2 +- Source/Diagnostics/ParticleIO.cpp | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 0e26506dd22..dcad4acb473 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -2972,7 +2972,7 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a If ``..variables = none``, no particle data are written. .. note:: - The electromagnetic fields diagnostics will not display the external fields. + The electromagnetic fields diagnostics will not include the external fields. * ``..random_fraction`` (`float`) optional If provided ``..random_fraction = a``, only `a` fraction of the particle data of this species will be dumped randomly in diag ````, i.e. if `rand() < a`, this particle will be dumped, where `rand()` denotes a random number generator. diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index ae75b2f0d00..d60a84c6cb7 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -424,13 +424,10 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; - if constexpr (ex_control == noEx && ey_control == noEy && ez_control == noEz && - bx_control == noBx && by_control == noBy && bz_control == noBz) { - // only for compiling the kernel where nothing is asked (but the function won't be called anyway) - amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, - Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, - bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); - } + + amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, + Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, + bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { From 1068708a3701cf0d2970e499eee8c51454dc89cc Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 15:01:19 +0000 Subject: [PATCH 101/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index d60a84c6cb7..94631c03ddd 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -424,7 +424,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, [[maybe_unused]] amrex::ParticleReal By_particle = 0._rt; [[maybe_unused]] amrex::ParticleReal Bz_particle = 0._rt; - + amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); From 1624f30fcc6ac49e32d096691b6e445179ce1776 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 09:34:43 +0200 Subject: [PATCH 102/123] add comments in test case analysis --- Examples/Tests/EM_fields_on_particles/analysis_2d.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index 64a6b3b9b18..b8d41595b36 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -89,7 +89,7 @@ def align_cost(shift, sig1, sig2, time): By_aligned = interp_func_by(T + opt_shift) Bz_aligned = interp_func_bz(T + opt_shift) -# verif +# test cases # E.1 @@ -102,6 +102,10 @@ def align_cost(shift, sig1, sig2, time): ey_p += 1e11 Ey_p += 1e11 +# np.allclose will almost always be false when values are very close to zero +# unless we give a high absolute tolerance +# Here I offset the values by 1e11 to avoid this problem + ez_p = ez_t[T >= delta_t] Ez_p = Ez_aligned[T >= delta_t] ez_p += 1e11 @@ -135,6 +139,9 @@ def align_cost(shift, sig1, sig2, time): by_p += 1e3 By_p += 1e3 +# same as for E.2 +# np.allclose will almost always be false when values are very close to zero + bz_p = bz_t[T >= delta_t] Bz_p = Bz_aligned[T >= delta_t] bz_p += 1e3 From 39117347eefe8b1c10e669626705250638de1911 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 09:45:09 +0200 Subject: [PATCH 103/123] add docygen comment --- Source/Diagnostics/ParticleIO.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 94631c03ddd..db166f3ef85 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -316,7 +316,14 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, const bool fields_to_plot[], const bool is_full_diagnostic) { - +/** + * \brief stores the electromagnetic fields on the particles as additional outputs + * + * \param tmp Particle container to store the gathered fields + * \param electromagnetic_solver_id The type of electromagnetic solver used + * \param fields_to_plot Array of booleans indicating which fields to plot + * \param is_full_diagnostic Whether this diagnostic is a full diagnostic +*/ using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; using Dir = ablastr::fields::Direction; From 13b38a6c5cc2d848cac6616f3d3364845cc14b9a Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 10:20:42 +0200 Subject: [PATCH 104/123] changed C-style array to amrex::Array --- Source/Diagnostics/ParticleDiag/ParticleDiag.H | 3 ++- Source/Diagnostics/ParticleIO.cpp | 4 ++-- Source/Particles/ParticleIO.H | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index d3c37c32483..4fea84d5771 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -25,7 +25,8 @@ public: amrex::Vector m_plot_flags; bool m_plot_phi = false; // Whether to output the potential phi on the particles bool m_plot_EM = false; // Whether to output the E and B fields on the particles - bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; // E and B fields + // bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; // E and B fields + amrex::Array m_plot_EM_flags = {false, false, false, false, false, false}; // E and B fields bool m_do_random_filter = false; bool m_do_uniform_filter = false; diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index db166f3ef85..63a78ec1449 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -313,7 +313,7 @@ template void storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, - const bool fields_to_plot[], + const amrex::Array fields_to_plot, const bool is_full_diagnostic) { /** @@ -496,7 +496,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, ElectromagneticSolverAlgo electromagnetic_solver_id, - const bool fields_to_plot[], + const amrex::Array fields_to_plot, const int depos_order, const bool galerkin_interpolation, const bool is_full_diagnostic) diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 4434b5d7604..0b0d47dedd7 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -94,5 +94,5 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, void storeEMFieldsOnParticles (PinnedMemoryParticleContainer& tmp, - ElectromagneticSolverAlgo electromagnetic_solver_id, const bool fields_to_plot[], const int depos_order, const bool galerkin_interpolation, const bool is_full_diagnostic ); + ElectromagneticSolverAlgo electromagnetic_solver_id, const amrex::Array fields_to_plot, const int depos_order, const bool galerkin_interpolation, const bool is_full_diagnostic ); #endif /* WARPX_PARTICLEIO_H_ */ From 615d1989b1015f5b44445028b32a261daf7b8d32 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 16:35:14 +0200 Subject: [PATCH 105/123] added warning --- Source/Diagnostics/ParticleDiag/ParticleDiag.H | 1 - Source/Diagnostics/ParticleIO.cpp | 10 +++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index 4fea84d5771..1d0c36d1de9 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -25,7 +25,6 @@ public: amrex::Vector m_plot_flags; bool m_plot_phi = false; // Whether to output the potential phi on the particles bool m_plot_EM = false; // Whether to output the E and B fields on the particles - // bool m_plot_EM_flags[6] = {false, false, false, false, false, false}; // E and B fields amrex::Array m_plot_EM_flags = {false, false, false, false, false, false}; // E and B fields bool m_do_random_filter = false; diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 63a78ec1449..0a9ed36fbf0 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -23,6 +23,7 @@ #include "WarpX.H" #include +#include #include #include @@ -339,7 +340,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, auto& warpx = WarpX::GetInstance(); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - warpx.finestLevel() ==0, + finestLevel == 0, "output of the electromagnetic fields on particles only works without mesh refinement" ); @@ -501,6 +502,13 @@ void storeEMFieldsOnParticles(PinnedMemoryParticleContainer& tmp, const bool galerkin_interpolation, const bool is_full_diagnostic) { + if (depos_order < 1 || depos_order > 4) { + ablastr::warn_manager::WMRecordWarning( + "Diagnostics", + "Particle shape order must be 1, 2, 3 or 4", + ablastr::warn_manager::WarnPriority::medium + ); + } if (galerkin_interpolation) { if (depos_order == 1) { ::storeEMFieldsOnParticles_t<1, 1>(tmp, electromagnetic_solver_id, fields_to_plot, is_full_diagnostic); From 92f397d6dd1a7af0e1a3a93bff46ccf8e361e7f9 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 16:43:00 +0200 Subject: [PATCH 106/123] fixed broken finestLevel() --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 0a9ed36fbf0..78d63314ce1 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -340,7 +340,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, auto& warpx = WarpX::GetInstance(); WARPX_ALWAYS_ASSERT_WITH_MESSAGE( - finestLevel == 0, + warpx.finestLevel() == 0, "output of the electromagnetic fields on particles only works without mesh refinement" ); From 09f3183f333d16a34248128bfe295c0cb69e5c9b Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Tue, 8 Apr 2025 22:42:10 +0200 Subject: [PATCH 107/123] updated test and checksum --- .../EM_fields_on_particles/analysis_2d.py | 4 +-- .../test_2d_particle_EM_diagnostics.json | 36 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Examples/Tests/EM_fields_on_particles/analysis_2d.py b/Examples/Tests/EM_fields_on_particles/analysis_2d.py index b8d41595b36..9c1c5f8ee6e 100755 --- a/Examples/Tests/EM_fields_on_particles/analysis_2d.py +++ b/Examples/Tests/EM_fields_on_particles/analysis_2d.py @@ -93,7 +93,7 @@ def align_cost(shift, sig1, sig2, time): # E.1 -assert np.allclose(np.zeros(ex_t.shape), ex_t, rtol=0, atol=5e-4) +assert np.allclose(np.zeros(ex_t.shape), ex_t, rtol=0, atol=1e-2) # E.2 @@ -130,7 +130,7 @@ def align_cost(shift, sig1, sig2, time): # B.1 -assert np.allclose(np.zeros(bx_t.shape), bx_t, rtol=0, atol=5e-4) +assert np.allclose(np.zeros(bx_t.shape), bx_t, rtol=0, atol=1e-3) # B.2 diff --git a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json index 4568e2f84ef..2d289e533e7 100644 --- a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json +++ b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json @@ -1,25 +1,25 @@ { + "lev=0": { + "Bx": 3864.690332686643, + "By": 239757.3669709079, + "Bz": 119878.42982987354, + "Ex": 2396689176296.2397, + "Ey": 35934018061852.125, + "Ez": 71884648325009.89 + }, "electron": { - "particle_bx": 3.890980310565517e-07, - "particle_by": 0.34760630481899957, - "particle_bz": 0.1737192637399916, - "particle_ex": 0.00013839455641573295, - "particle_ey": 50608854.55959022, - "particle_ez": 111088826.0524848, - "particle_momentum_x": 0.0, - "particle_momentum_y": 0.0, - "particle_momentum_z": 0.0, + "particle_bx": 7.639494150087526e-14, + "particle_by": 0.3474714129854592, + "particle_bz": 0.17371926374001348, + "particle_ex": 0.0019113002254111196, + "particle_ey": 50608854.55961605, + "particle_ez": 111043659.45772709, "particle_position_x": 2.5e-06, "particle_position_y": 0.0, "particle_position_z": 1.25e-05, + "particle_momentum_x": 0.0, + "particle_momentum_y": 0.0, + "particle_momentum_z": 0.0, "particle_weight": 0.0 - }, - "lev=0": { - "Bx": 3864.690332686649, - "By": 239757.36697091258, - "Bz": 119878.42982987352, - "Ex": 2396689176285.191, - "Ey": 35934018061852.125, - "Ez": 71884648325008.73 } -} \ No newline at end of file +} From 7e8e9285a8fe1cd2b04f60c6e08d2b053de64071 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 9 Apr 2025 09:39:08 +0200 Subject: [PATCH 108/123] update checksum again? --- .../test_2d_particle_EM_diagnostics.json | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json index 2d289e533e7..535a4ea4de2 100644 --- a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json +++ b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json @@ -1,19 +1,19 @@ { "lev=0": { - "Bx": 3864.690332686643, - "By": 239757.3669709079, - "Bz": 119878.42982987354, - "Ex": 2396689176296.2397, - "Ey": 35934018061852.125, - "Ez": 71884648325009.89 + "Bx": 3864.6903326868182, + "By": 239757.36697092294, + "Bz": 119878.42982987872, + "Ex": 2396689176285.2944, + "Ey": 35934018061853.67, + "Ez": 71884648325011.86 }, "electron": { - "particle_bx": 7.639494150087526e-14, - "particle_by": 0.3474714129854592, - "particle_bz": 0.17371926374001348, - "particle_ex": 0.0019113002254111196, - "particle_ey": 50608854.55961605, - "particle_ez": 111043659.45772709, + "particle_bx": 3.8909803033142373e-07, + "particle_by": 0.34760630481904997, + "particle_bz": 0.17371926374000385, + "particle_ex": 0.0001349025551462546, + "particle_ey": 50608854.55959178, + "particle_ez": 111088826.05245684, "particle_position_x": 2.5e-06, "particle_position_y": 0.0, "particle_position_z": 1.25e-05, From d2d3cb2b33ee5485b15ad726bd23bc76111dfb90 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 9 Apr 2025 12:58:15 +0200 Subject: [PATCH 109/123] Update Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json Update checksum using result obtained by github runner (I get the same on my local machine) --- .../benchmarks_json/test_2d_particle_EM_diagnostics.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json index 535a4ea4de2..d4f1470f835 100644 --- a/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json +++ b/Regression/Checksum/benchmarks_json/test_2d_particle_EM_diagnostics.json @@ -8,7 +8,7 @@ "Ez": 71884648325011.86 }, "electron": { - "particle_bx": 3.8909803033142373e-07, + "particle_bx": 3.890980338189904e-07, "particle_by": 0.34760630481904997, "particle_bz": 0.17371926374000385, "particle_ex": 0.0001349025551462546, From e55ff6808a6d48f1e83c56a409d9a9d03473cfd2 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Mon, 14 Apr 2025 10:27:09 +0200 Subject: [PATCH 110/123] added a doGatherShapeN call instead of 2 doDirectGatherVectorField when both fields are requested --- Source/Diagnostics/ParticleIO.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 78d63314ce1..eb698d269c1 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -436,8 +436,22 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); - - if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) + + if constexpr ((ex_control == doEx || ey_control == doEy || ez_control == doEy) && (bx_control == doBx || by_control == doBy || bz_control == doBz)) + { + // if E and B are both requested, doGatherShapeN is faster than two calls to doDirectGatherVectorField + doGatherShapeN( + xp, yp, zp, + Ex_particle, Ey_particle, Ez_particle, + Bx_particle, By_particle, Bz_particle, + Ex_grid, Ey_grid, Ez_grid, + Bx_grid, By_grid, Bz_grid, + ex_type, ey_type, ez_type, + bx_type, by_type, bz_type, + dinv, xyzmin, lo, n_rz_azimuthal_modes, depos_order, galerkin_interpolation + ); + } + else if constexpr (ex_control == doEx || ey_control == doEy || ez_control == doEz) { doDirectGatherVectorField( xp, yp, zp, @@ -447,8 +461,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, dinv, xyzmin, lo, n_rz_azimuthal_modes ); } - - if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) + else if constexpr (bx_control == doBx || by_control == doBy || bz_control == doBz) { doDirectGatherVectorField( xp, yp, zp, From 07f517f54859d239fd535a4c752e9ee49b4f3ad8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Apr 2025 08:29:25 +0000 Subject: [PATCH 111/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index eb698d269c1..9318d77671f 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -436,7 +436,7 @@ storeEMFieldsOnParticles_t (PinnedMemoryParticleContainer& tmp, amrex::ignore_unused(Ex_grid, Ey_grid, Ez_grid, Bx_grid, By_grid, Bz_grid, ex_type, ey_type, ez_type, bx_type, by_type, bz_type, dinv, xyzmin, lo, n_rz_azimuthal_modes); - + if constexpr ((ex_control == doEx || ey_control == doEy || ez_control == doEy) && (bx_control == doBx || by_control == doBy || bz_control == doBz)) { // if E and B are both requested, doGatherShapeN is faster than two calls to doDirectGatherVectorField From 8724fbf90e57564d6a557bd8b1fb84ae0b08bf81 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 8 Oct 2025 15:45:08 +0200 Subject: [PATCH 112/123] test in array initialisation --- Source/Particles/Gather/FieldGather.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Particles/Gather/FieldGather.H b/Source/Particles/Gather/FieldGather.H index 5aece69ff01..8a5345ce7a2 100644 --- a/Source/Particles/Gather/FieldGather.H +++ b/Source/Particles/Gather/FieldGather.H @@ -481,8 +481,8 @@ void doGatherShapeN ([[maybe_unused]] const amrex::ParticleReal xp, const amrex::Real z = (zp-xyzmin.z)*dinv.z; amrex::Real sz_node[depos_order + 1]; amrex::Real sz_cell[depos_order + 1]; - amrex::Real sz_node_v[depos_order + 1 - galerkin_interpolation]; - amrex::Real sz_cell_v[depos_order + 1 - galerkin_interpolation]; + amrex::Real sz_node_v[depos_order + 1 - galerkin_interpolation] = {0._rt}; + amrex::Real sz_cell_v[depos_order + 1 - galerkin_interpolation] = {0._rt}; int l_node = 0; int l_cell = 0; int l_node_v = 0; From dad09452f627af75b46b0ccdc9b1968a2879feb9 Mon Sep 17 00:00:00 2001 From: Gabriel Robert-Dautun Date: Wed, 8 Oct 2025 16:23:13 +0200 Subject: [PATCH 113/123] fix moved to another PR --- Source/Particles/Gather/FieldGather.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Particles/Gather/FieldGather.H b/Source/Particles/Gather/FieldGather.H index 8a5345ce7a2..5aece69ff01 100644 --- a/Source/Particles/Gather/FieldGather.H +++ b/Source/Particles/Gather/FieldGather.H @@ -481,8 +481,8 @@ void doGatherShapeN ([[maybe_unused]] const amrex::ParticleReal xp, const amrex::Real z = (zp-xyzmin.z)*dinv.z; amrex::Real sz_node[depos_order + 1]; amrex::Real sz_cell[depos_order + 1]; - amrex::Real sz_node_v[depos_order + 1 - galerkin_interpolation] = {0._rt}; - amrex::Real sz_cell_v[depos_order + 1 - galerkin_interpolation] = {0._rt}; + amrex::Real sz_node_v[depos_order + 1 - galerkin_interpolation]; + amrex::Real sz_cell_v[depos_order + 1 - galerkin_interpolation]; int l_node = 0; int l_cell = 0; int l_node_v = 0; From 7634b3a02562627b8ea22043ec2c39f425858904 Mon Sep 17 00:00:00 2001 From: David Grote Date: Mon, 9 Feb 2026 17:01:04 -0800 Subject: [PATCH 114/123] Add particle field diagnostic --- .../Diagnostics/ParticleDiag/ParticleDiag.H | 6 + .../Diagnostics/ParticleDiag/ParticleDiag.cpp | 25 +++- Source/Diagnostics/ParticleIO.cpp | 118 ++++++++++++++++++ Source/Diagnostics/WarpXOpenPMD.cpp | 6 + Source/Particles/ParticleIO.H | 17 +++ 5 files changed, 171 insertions(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.H b/Source/Diagnostics/ParticleDiag/ParticleDiag.H index 45bc596a78e..8169e69edf9 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.H +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.H @@ -24,6 +24,12 @@ public: [[nodiscard]] std::string getSpeciesName() const { return m_name; } amrex::Vector m_plot_flags; bool m_plot_phi = false; // Whether to output the potential phi on the particles + bool m_plot_Ex = false; // Whether to output the Ex on the particles + bool m_plot_Ey = false; // Whether to output the Ey on the particles + bool m_plot_Ez = false; // Whether to output the Ez on the particles + bool m_plot_Bx = false; // Whether to output the Bx on the particles + bool m_plot_By = false; // Whether to output the By on the particles + bool m_plot_Bz = false; // Whether to output the Bz on the particles bool m_do_random_filter = false; bool m_do_uniform_filter = false; diff --git a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp index 6da6a4b5915..f61b2a61056 100644 --- a/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp +++ b/Source/Diagnostics/ParticleDiag/ParticleDiag.cpp @@ -50,7 +50,14 @@ ParticleDiag::ParticleDiag ( // the particle container carries, and is only added to particles during output. // Therefore, this case needs to be treated specifically. m_plot_phi = true; - } else { + } + else if (var == "Ex") { m_plot_Ex = true; } + else if (var == "Ey") { m_plot_Ey = true; } + else if (var == "Ez") { m_plot_Ez = true; } + else if (var == "Bx") { m_plot_Bx = true; } + else if (var == "By") { m_plot_By = true; } + else if (var == "Bz") { m_plot_Bz = true; } + else { WARPX_ALWAYS_ASSERT_WITH_MESSAGE(pc->HasRealComp(var), "variables argument '" + var +"' is not an existing attribute for this species"); @@ -72,6 +79,22 @@ ParticleDiag::ParticleDiag ( } } + amrex::Vector additional_variables; + pp_diag_name_species_name.queryarr("additional_variables", additional_variables); + for (auto& var : additional_variables) { + if (var == "phi") { m_plot_phi = true; } + else if (var == "Ex") { m_plot_Ex = true; } + else if (var == "Ey") { m_plot_Ey = true; } + else if (var == "Ez") { m_plot_Ez = true; } + else if (var == "Bx") { m_plot_Bx = true; } + else if (var == "By") { m_plot_By = true; } + else if (var == "Bz") { m_plot_Bz = true; } + else { + WARPX_ABORT_WITH_MESSAGE( + "additional_variables argument '" + var + "' is not a valid variable"); + } + } + #if defined(WARPX_DIM_RZ) || defined(WARPX_DIM_RCYLINDER) || defined(WARPX_DIM_RSPHERE) // Always write out theta, whether or not it's requested, // to be consistent with always writing out r and z. diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 4ac155b2258..16cce5624bc 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -303,3 +303,121 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, } } } + +void +storeFieldOnParticles ( PinnedMemoryParticleContainer& tmp, bool is_full_diagnostic, + bool save_Ex, bool save_Ey, bool save_Ez, + bool save_Bx, bool save_By, bool save_Bz) { + + using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; + using ablastr::fields::Direction; + + // When this is not a full diagnostic, the particles are not written at the same physical time (i.e. PIC iteration) + // that they were collected. This happens for diagnostics that use buffering (e.g. BackTransformed, BoundaryScraping). + // Here `phi` is gathered at the iteration when particles are written (not collected) and is thus mismatched. + // To avoid confusion, we raise an error in this case. + WARPX_ALWAYS_ASSERT_WITH_MESSAGE( + is_full_diagnostic, + "Output of the fields on the particles was requested, " + "but this is only available with `diag_type = Full`."); + + if (save_Ex) { tmp.AddRealComp("Ex"); } + if (save_Ey) { tmp.AddRealComp("Ey"); } + if (save_Ez) { tmp.AddRealComp("Ez"); } + if (save_Bx) { tmp.AddRealComp("Bx"); } + if (save_By) { tmp.AddRealComp("By"); } + if (save_Bz) { tmp.AddRealComp("Bz"); } + + int const Ex_index = save_Ex ? tmp.GetRealCompIndex("Ex") : -1; + int const Ey_index = save_Ey ? tmp.GetRealCompIndex("Ey") : -1; + int const Ez_index = save_Ez ? tmp.GetRealCompIndex("Ez") : -1; + int const Bx_index = save_Bx ? tmp.GetRealCompIndex("Bx") : -1; + int const By_index = save_By ? tmp.GetRealCompIndex("By") : -1; + int const Bz_index = save_Bz ? tmp.GetRealCompIndex("Bz") : -1; + + auto & warpx = WarpX::GetInstance(); + auto & fields = warpx.m_fields; + + const int n_rz_azimuthal_modes = WarpX::n_rz_azimuthal_modes; + const int nox = WarpX::nox; + const bool galerkin_interpolation = WarpX::galerkin_interpolation; + + for (int lev=0; lev<=warpx.finestLevel(); lev++) { + + const amrex::XDim3 dinv = WarpX::InvCellSize(lev); + + amrex::MultiFab & Ex = *fields.get(FieldType::Efield_aux, Direction{0}, lev); + amrex::MultiFab & Ey = *fields.get(FieldType::Efield_aux, Direction{1}, lev); + amrex::MultiFab & Ez = *fields.get(FieldType::Efield_aux, Direction{2}, lev); + amrex::MultiFab & Bx = *fields.get(FieldType::Bfield_aux, Direction{0}, lev); + amrex::MultiFab & By = *fields.get(FieldType::Bfield_aux, Direction{1}, lev); + amrex::MultiFab & Bz = *fields.get(FieldType::Bfield_aux, Direction{2}, lev); + +#ifdef AMREX_USE_OMP + #pragma omp parallel if (amrex::Gpu::notInLaunchRegion()) +#endif + for (PinnedParIter pti(tmp, lev); pti.isValid(); ++pti) { + + amrex::Box box = pti.tilebox(); + const amrex::XDim3 xyzmin = WarpX::LowerCorner(box, lev, 0._rt); + const Dim3 lo = lbound(box); + + FArrayBox const* exfab = &Ex[pti]; + FArrayBox const* eyfab = &Ey[pti]; + FArrayBox const* ezfab = &Ez[pti]; + FArrayBox const* bxfab = &Bx[pti]; + FArrayBox const* byfab = &By[pti]; + FArrayBox const* bzfab = &Bz[pti]; + + amrex::Array4 const& ex_arr = exfab->array(); + amrex::Array4 const& ey_arr = eyfab->array(); + amrex::Array4 const& ez_arr = ezfab->array(); + amrex::Array4 const& bx_arr = bxfab->array(); + amrex::Array4 const& by_arr = byfab->array(); + amrex::Array4 const& bz_arr = bzfab->array(); + + amrex::IndexType const ex_type = exfab->box().ixType(); + amrex::IndexType const ey_type = eyfab->box().ixType(); + amrex::IndexType const ez_type = ezfab->box().ixType(); + amrex::IndexType const bx_type = bxfab->box().ixType(); + amrex::IndexType const by_type = byfab->box().ixType(); + amrex::IndexType const bz_type = bzfab->box().ixType(); + + const auto getPosition = GetParticlePosition(pti); + + amrex::ParticleReal* Ex_particle_arr = save_Ex ? pti.GetStructOfArrays().GetRealData(Ex_index).dataPtr() : nullptr; + amrex::ParticleReal* Ey_particle_arr = save_Ey ? pti.GetStructOfArrays().GetRealData(Ey_index).dataPtr() : nullptr; + amrex::ParticleReal* Ez_particle_arr = save_Ez ? pti.GetStructOfArrays().GetRealData(Ez_index).dataPtr() : nullptr; + amrex::ParticleReal* Bx_particle_arr = save_Bx ? pti.GetStructOfArrays().GetRealData(Bx_index).dataPtr() : nullptr; + amrex::ParticleReal* By_particle_arr = save_By ? pti.GetStructOfArrays().GetRealData(By_index).dataPtr() : nullptr; + amrex::ParticleReal* Bz_particle_arr = save_Bz ? pti.GetStructOfArrays().GetRealData(Bz_index).dataPtr() : nullptr; + + // Loop over the particles and update their position + amrex::ParallelFor( pti.numParticles(), + [=] AMREX_GPU_DEVICE (long ip) { + + amrex::ParticleReal xp, yp, zp; + getPosition(ip, xp, yp, zp); + + amrex::ParticleReal Exp = 0., Eyp = 0., Ezp = 0.; + amrex::ParticleReal Bxp = 0., Byp = 0., Bzp = 0.; + + doGatherShapeN(xp, yp, zp, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + ex_arr, ey_arr, ez_arr, bx_arr, by_arr, bz_arr, + ex_type, ey_type, ez_type, bx_type, by_type, bz_type, + dinv, xyzmin, lo, n_rz_azimuthal_modes, + nox, galerkin_interpolation); + + + if (Ex_particle_arr) Ex_particle_arr[ip] = Exp; + if (Ey_particle_arr) Ey_particle_arr[ip] = Eyp; + if (Ez_particle_arr) Ez_particle_arr[ip] = Ezp; + if (Bx_particle_arr) Bx_particle_arr[ip] = Bxp; + if (By_particle_arr) By_particle_arr[ip] = Byp; + if (Bz_particle_arr) Bz_particle_arr[ip] = Bzp; + + } + ); + } + } +} diff --git a/Source/Diagnostics/WarpXOpenPMD.cpp b/Source/Diagnostics/WarpXOpenPMD.cpp index 88808603627..1590416f7af 100644 --- a/Source/Diagnostics/WarpXOpenPMD.cpp +++ b/Source/Diagnostics/WarpXOpenPMD.cpp @@ -607,6 +607,12 @@ for (const auto & particle_diag : particle_diags) { if ( particle_diag.m_plot_phi ) { storePhiOnParticles( tmp, WarpX::electrostatic_solver_id, !use_pinned_pc ); } + if (particle_diag.m_plot_Ex || particle_diag.m_plot_Ey || particle_diag.m_plot_Ez || + particle_diag.m_plot_Bx || particle_diag.m_plot_By || particle_diag.m_plot_Bz) { + storeFieldOnParticles(tmp, !use_pinned_pc, + particle_diag.m_plot_Ex, particle_diag.m_plot_Ey, particle_diag.m_plot_Ez, + particle_diag.m_plot_Bx, particle_diag.m_plot_By, particle_diag.m_plot_Bz); + } // names of amrex::ParticleReal and int particle attributes in SoA data auto const rn = tmp.GetRealSoANames(); diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 8d3516e6890..e6b50d8f880 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -92,4 +92,21 @@ void storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, ElectrostaticSolverAlgo electrostatic_solver_id, bool is_full_diagnostic ); +/** \brief Gathers fields from a MultiFab to the macroparticles. + * Adds a runtime component of the particle container to store it. + * + * \param tmp The particle container on which to store the gathered field + * \param is_full_diagnostic Whether this diagnostic is a full diagnostic + * \parame save_Ex Whether the Ex field is saved + * \parame save_Ey Whether the Ex field is saved + * \parame save_Ez Whether the Ex field is saved + * \parame save_Bx Whether the Ex field is saved + * \parame save_By Whether the Ex field is saved + * \parame save_Bz Whether the Ex field is saved + */ +void +storeFieldOnParticles (PinnedMemoryParticleContainer& tmp, bool is_full_diagnostic, + bool save_Ex, bool save_Ey, bool save_Ez, + bool save_Bx, bool save_By, bool save_Bz); + #endif /* WARPX_PARTICLEIO_H_ */ From 1fd6bd43c799d9fec341b3eada8ffec787e0de02 Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 10 Feb 2026 09:32:38 -0800 Subject: [PATCH 115/123] Add documentation --- Docs/source/usage/parameters.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index 5e98a39113b..f6627eed3ca 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -3181,10 +3181,19 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a List of particle quantities to write to output. Choices are ``x``, ``y``, ``z`` for the particle positions (3D, RZ, RSPHERE), ``x`` and ``z`` in 2D, ``z`` in 1D, ``x`` and ``y`` for RCYLINDER, ``w`` for the particle weight and ``ux``, ``uy``, ``uz`` for the particle momenta. + The fields can also be obtained, ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz``. + Note that the fields gathered in the same way as during the simulation, and do not include any applied fields. When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. - By default, all particle quantities (except ``phi``) are written. + By default, positions, momenta, and weights are written out. If ``..variables = none``, no particle data are written. +* ``..additional_variables`` (list of `strings` separated by spaces, optional) + List of additional particle quantities to write to output. + This allows specifying the additional particle quantities beyond the standard position, momentum, and weight. + The options are the fields, ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz``, + and when using the lab-frame electrostatic solver, the electrostatic potential ``phi``. + Note that the fields gathered in the same way as during the simulation, and do not include any applied fields. + * ``..random_fraction`` (`float`) optional If provided ``..random_fraction = a``, only `a` fraction of the particle data of this species will be dumped randomly in diag ````, i.e. if `rand() < a`, this particle will be dumped, where `rand()` denotes a random number generator. The value `a` provided should be between 0 and 1. From 7e0f1080c6f5485b89ac6fbc98caf7ee2eb40951 Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 10 Feb 2026 10:36:48 -0800 Subject: [PATCH 116/123] Add CI test --- Examples/Tests/langmuir/analysis_3d.py | 34 +++++++++++++++++++++++--- Examples/Tests/langmuir/inputs_base_3d | 7 +++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Examples/Tests/langmuir/analysis_3d.py b/Examples/Tests/langmuir/analysis_3d.py index 75b9c5ba71c..28c850f243a 100755 --- a/Examples/Tests/langmuir/analysis_3d.py +++ b/Examples/Tests/langmuir/analysis_3d.py @@ -24,6 +24,7 @@ yt.funcs.mylog.setLevel(50) import numpy as np +from openpmd_viewer import OpenPMDTimeSeries from scipy.constants import c, e, epsilon_0, m_e # test name @@ -62,15 +63,19 @@ cos = {"Ex": (0, 1, 1), "Ey": (1, 0, 1), "Ez": (1, 1, 0)} -def get_contribution(is_cos, k, idim): - du = (hi[idim] - lo[idim]) / Ncell[idim] - u = lo[idim] + du * (0.5 + np.arange(Ncell[idim])) +def get_contribution_at_positions(is_cos, k, idim, u): if is_cos[idim] == 1: return np.cos(k * u) else: return np.sin(k * u) +def get_contribution(is_cos, k, idim): + du = (hi[idim] - lo[idim]) / Ncell[idim] + u = lo[idim] + du * (0.5 + np.arange(Ncell[idim])) + return get_contribution_at_positions(is_cos, k, idim, u) + + def get_theoretical_field(field, t): amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) cos_flag = cos[field] @@ -88,6 +93,18 @@ def get_theoretical_field(field, t): return E +def get_theoretical_field_at_positions(field, t, x, y, z): + amplitude = epsilon * (m_e * c**2 * k[field]) / e * np.sin(wp * t) + cos_flag = cos[field] + x_contribution = get_contribution_at_positions(cos_flag, kx, 0, x) + y_contribution = get_contribution_at_positions(cos_flag, ky, 1, y) + z_contribution = get_contribution_at_positions(cos_flag, kz, 2, z) + + E = amplitude * x_contribution * y_contribution * z_contribution + + return E + + # Read the file ds = yt.load(fn) @@ -127,6 +144,17 @@ def get_theoretical_field(field, t): print("%s: Max error: %.2e" % (field, max_error)) error_rel = max(error_rel, max_error) +ts = OpenPMDTimeSeries("./diags/openpmd") +x, y, z = ts.get_particle(["x", "y", "z"], species="electrons", iteration=40) +for field in ["Ex", "Ey", "Ez"]: + E_sim_particles = ts.get_particle( + [field.lower()], species="electrons", iteration=40 + ) + E_th_particles = get_theoretical_field_at_positions(field, t0, x, y, z) + max_error = abs(E_sim_particles - E_th_particles).max() / abs(E_th_particles).max() + print("%s: Max error at particles: %.2e" % (field, max_error)) + error_rel = max(error_rel, max_error) + # Plot the last field from the loop (Ez at iteration 40) fig, (ax1, ax2) = plt.subplots(1, 2, dpi=100) # First plot (slice at y=0) diff --git a/Examples/Tests/langmuir/inputs_base_3d b/Examples/Tests/langmuir/inputs_base_3d index d85ab817660..dd619b774a6 100644 --- a/Examples/Tests/langmuir/inputs_base_3d +++ b/Examples/Tests/langmuir/inputs_base_3d @@ -90,9 +90,14 @@ positrons.momentum_function_uz(x,y,z) = "-epsilon * k/kp * cos(k*x) * cos(k*y) * # Diagnostics warpx.synchronize_velocity_for_diagnostics = 1 -diagnostics.diags_names = diag1 +diagnostics.diags_names = diag1 openpmd diag1.intervals = max_step diag1.diag_type = Full diag1.fields_to_plot = Ex Ey Ez Bx By Bz jx jy jz part_per_cell rho diag1.electrons.variables = x y z w ux diag1.positrons.variables = x y z uz + +openpmd.intervals = 40 +openpmd.diag_type = Full +openpmd.format = openpmd +openpmd.electrons.additional_variables = Ex Ey Ez From 192a3d106b875d64e4879b263edf192ada97fc31 Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 10 Feb 2026 10:37:11 -0800 Subject: [PATCH 117/123] Fix documentation, the fields can only be written out with OpenPMD format --- Docs/source/usage/parameters.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Docs/source/usage/parameters.rst b/Docs/source/usage/parameters.rst index f6627eed3ca..40a24692ff3 100644 --- a/Docs/source/usage/parameters.rst +++ b/Docs/source/usage/parameters.rst @@ -3181,14 +3181,14 @@ In-situ capabilities can be used by turning on Sensei or Ascent (provided they a List of particle quantities to write to output. Choices are ``x``, ``y``, ``z`` for the particle positions (3D, RZ, RSPHERE), ``x`` and ``z`` in 2D, ``z`` in 1D, ``x`` and ``y`` for RCYLINDER, ``w`` for the particle weight and ``ux``, ``uy``, ``uz`` for the particle momenta. - The fields can also be obtained, ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz``. + When writing to the OpenPMD format, the fields can also be obtained, ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz``. Note that the fields gathered in the same way as during the simulation, and do not include any applied fields. - When using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. + Also, when writing to the OpenPMD format and when using the lab-frame electrostatic solver, ``phi`` (electrostatic potential, on the macroparticles) is also available. By default, positions, momenta, and weights are written out. If ``..variables = none``, no particle data are written. * ``..additional_variables`` (list of `strings` separated by spaces, optional) - List of additional particle quantities to write to output. + List of additional particle quantities to write to output, when using the OpenPMD format. This allows specifying the additional particle quantities beyond the standard position, momentum, and weight. The options are the fields, ``Ex``, ``Ey``, ``Ez``, ``Bx``, ``By``, ``Bz``, and when using the lab-frame electrostatic solver, the electrostatic potential ``phi``. From 164f04ea5b49a8cf2f8056b33942e6916cc975f4 Mon Sep 17 00:00:00 2001 From: David Grote Date: Tue, 10 Feb 2026 11:00:33 -0800 Subject: [PATCH 118/123] Fix documentation typo --- Source/Particles/ParticleIO.H | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index e6b50d8f880..b265efa7e61 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -97,12 +97,12 @@ storePhiOnParticles ( PinnedMemoryParticleContainer& tmp, * * \param tmp The particle container on which to store the gathered field * \param is_full_diagnostic Whether this diagnostic is a full diagnostic - * \parame save_Ex Whether the Ex field is saved - * \parame save_Ey Whether the Ex field is saved - * \parame save_Ez Whether the Ex field is saved - * \parame save_Bx Whether the Ex field is saved - * \parame save_By Whether the Ex field is saved - * \parame save_Bz Whether the Ex field is saved + * \param save_Ex Whether the Ex field is saved + * \param save_Ey Whether the Ex field is saved + * \param save_Ez Whether the Ex field is saved + * \param save_Bx Whether the Ex field is saved + * \param save_By Whether the Ex field is saved + * \param save_Bz Whether the Ex field is saved */ void storeFieldOnParticles (PinnedMemoryParticleContainer& tmp, bool is_full_diagnostic, From 118eb55aa21f8419f76c0cd22d67bc05936e36d9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 Apr 2026 21:31:16 +0000 Subject: [PATCH 119/123] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- Examples/Tests/langmuir/analysis_3d.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/Tests/langmuir/analysis_3d.py b/Examples/Tests/langmuir/analysis_3d.py index 2ff198ef019..4f9e75e11d7 100755 --- a/Examples/Tests/langmuir/analysis_3d.py +++ b/Examples/Tests/langmuir/analysis_3d.py @@ -24,8 +24,8 @@ yt.funcs.mylog.setLevel(50) import numpy as np -from openpmd_viewer import OpenPMDTimeSeries from analysis_utils import check_charge_conservation +from openpmd_viewer import OpenPMDTimeSeries from scipy.constants import c, e, epsilon_0, m_e # test name From 07eb64d73ea6c12ee8cb1f88c6aaf709dc90c7b5 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Thu, 2 Apr 2026 14:39:18 -0700 Subject: [PATCH 120/123] Fix build errors: replace removed PinnedMemoryParticleContainer with WarpXParticleContainer::Base Co-Authored-By: Claude Sonnet 4.6 --- Source/Diagnostics/ParticleIO.cpp | 4 ++-- Source/Particles/ParticleIO.H | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index 5fc958af73f..b733b9fbcb4 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -305,11 +305,11 @@ storePhiOnParticles ( WarpXParticleContainer::Base& tmp, } void -storeFieldOnParticles ( PinnedMemoryParticleContainer& tmp, bool is_full_diagnostic, +storeFieldOnParticles ( WarpXParticleContainer::Base& tmp, bool is_full_diagnostic, bool save_Ex, bool save_Ey, bool save_Ez, bool save_Bx, bool save_By, bool save_Bz) { - using PinnedParIter = typename PinnedMemoryParticleContainer::ParIterType; + using PinnedParIter = typename WarpXParticleContainer::ParIterType; using ablastr::fields::Direction; // When this is not a full diagnostic, the particles are not written at the same physical time (i.e. PIC iteration) diff --git a/Source/Particles/ParticleIO.H b/Source/Particles/ParticleIO.H index 7d2c4a717be..95ab4d41439 100644 --- a/Source/Particles/ParticleIO.H +++ b/Source/Particles/ParticleIO.H @@ -104,7 +104,7 @@ storePhiOnParticles ( WarpXParticleContainer::Base& tmp, * \param save_Bz Whether the Ex field is saved */ void -storeFieldOnParticles (PinnedMemoryParticleContainer& tmp, bool is_full_diagnostic, +storeFieldOnParticles (WarpXParticleContainer::Base& tmp, bool is_full_diagnostic, bool save_Ex, bool save_Ey, bool save_Ez, bool save_Bx, bool save_By, bool save_Bz); From 1ccf39445657742bd568e96f4d4a662316d772cd Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 3 Apr 2026 07:47:21 -0700 Subject: [PATCH 121/123] Add field diagnostic in Python script --- .../inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py index 76caccf7d62..66f9051e59e 100755 --- a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py @@ -135,8 +135,14 @@ species=[positrons], data_list=["x", "y", "z", "uz"], ) +field_on_particle_diag = picmi.ParticleDiagnostic( + name="openpmd", + period=40, + data_list=["x", "y", "z", "Ex", "Ey", "Ez"], +) sim.add_diagnostic(particle_diag1_electrons) sim.add_diagnostic(particle_diag1_positrons) +sim.add_diagnostic(field_on_particle_diag) sim.write_input_file(file_name="inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi") From 2b4bc7c0d0a81376d60ca06ba4f064a7da05139f Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 3 Apr 2026 08:19:06 -0700 Subject: [PATCH 122/123] Update test --- .../inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py index 66f9051e59e..acdc47d04d8 100755 --- a/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py +++ b/Examples/Tests/langmuir/inputs_test_3d_langmuir_multi_psatd_JRhom_LL2_picmi.py @@ -139,6 +139,7 @@ name="openpmd", period=40, data_list=["x", "y", "z", "Ex", "Ey", "Ez"], + warpx_format="openpmd", ) sim.add_diagnostic(particle_diag1_electrons) sim.add_diagnostic(particle_diag1_positrons) From 85e1d7cf6e7ac37ddb6c3c8cbf75021f4929b9ef Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Tue, 14 Apr 2026 06:05:29 -0700 Subject: [PATCH 123/123] Update comment --- Source/Diagnostics/ParticleIO.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index b733b9fbcb4..e609652d6dc 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -314,7 +314,7 @@ storeFieldOnParticles ( WarpXParticleContainer::Base& tmp, bool is_full_diagnost // When this is not a full diagnostic, the particles are not written at the same physical time (i.e. PIC iteration) // that they were collected. This happens for diagnostics that use buffering (e.g. BackTransformed, BoundaryScraping). - // Here `phi` is gathered at the iteration when particles are written (not collected) and is thus mismatched. + // Here the field is gathered at the iteration when particles are written (not collected) and is thus mismatched. // To avoid confusion, we raise an error in this case. WARPX_ALWAYS_ASSERT_WITH_MESSAGE( is_full_diagnostic,