From c238eab6e20f732facdef32909f368b9436fb964 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 16 May 2019 17:46:58 -0700 Subject: Photons are derived class from PhysicalParticleContainer --- Source/Particles/MultiParticleContainer.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 6d618c096..b4abe8b76 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -22,6 +22,9 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) else if (species_types[i] == PCTypes::RigidInjected) { allcontainers[i].reset(new RigidInjectedParticleContainer(amr_core, i, species_names[i])); } + else if (species_types[i] == PCTypes::Photon) { + allcontainers[i].reset(new PhotonParticleContainer(amr_core, i, species_names[i])); + } allcontainers[i]->deposit_on_main_grid = deposit_on_main_grid[i]; } @@ -78,9 +81,11 @@ MultiParticleContainer::ReadParameters () BL_ASSERT(nspecies >= 0); if (nspecies > 0) { + // Get species names pp.getarr("species_names", species_names); BL_ASSERT(species_names.size() == nspecies); + // Get species to deposit on main grid deposit_on_main_grid.resize(nspecies, 0); std::vector tmp; pp.queryarr("deposit_on_main_grid", tmp); @@ -93,9 +98,9 @@ MultiParticleContainer::ReadParameters () species_types.resize(nspecies, PCTypes::Physical); + // Get rigid-injected species std::vector rigid_injected_species; pp.queryarr("rigid_injected_species", rigid_injected_species); - if (!rigid_injected_species.empty()) { for (auto const& name : rigid_injected_species) { auto it = std::find(species_names.begin(), species_names.end(), name); @@ -104,6 +109,18 @@ MultiParticleContainer::ReadParameters () species_types[i] = PCTypes::RigidInjected; } } + // Get photon species + std::vector photon_species; + pp.queryarr("photon_species", photon_species); + if (!photon_species.empty()) { + for (auto const& name : photon_species) { + auto it = std::find(species_names.begin(), species_names.end(), name); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.rigid_injected_species must be part of particles.species_names"); + int i = std::distance(species_names.begin(), it); + species_types[i] = PCTypes::Photon; + } + } + } pp.query("use_fdtd_nci_corr", WarpX::use_fdtd_nci_corr); -- cgit v1.2.3 From fb9684efe88a98ade20072bc566dc4adaa817b18 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 10:10:06 +0200 Subject: added bw_engine object as a public member of MultiParticleContainer --- Source/Particles/MultiParticleContainer.H | 43 ++++++++++++++++------------- Source/Particles/MultiParticleContainer.cpp | 39 ++++++++++++++------------ 2 files changed, 46 insertions(+), 36 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index d1df20f39..a76fd89e3 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -52,24 +52,24 @@ public: const amrex::Vector > > >& masks); /// - /// This evolves all the particles by one PIC time step, including charge deposition, the + /// This evolves all the particles by one PIC time step, including charge deposition, the /// field solve, and pushing the particles, for all the species in the MultiParticleContainer. /// This is the electrostatic version. /// - void EvolveES (const amrex::Vector, 3> >& E, - amrex::Vector >& rho, + void EvolveES (const amrex::Vector, 3> >& E, + amrex::Vector >& rho, amrex::Real t, amrex::Real dt); /// - /// This pushes the particle positions by one half time step for all the species in the + /// This pushes the particle positions by one half time step for all the species in the /// MultiParticleContainer. It is used to desynchronize the particles after initializaton /// or when restarting from a checkpoint. This is the electrostatic version. - /// + /// void PushXES (amrex::Real dt); /// /// This deposits the particle charge onto rho, accumulating the value for all the species - /// in the MultiParticleContainer. rho is assumed to contain node-centered multifabs. + /// in the MultiParticleContainer. rho is assumed to contain node-centered multifabs. /// This version is hard-coded for CIC deposition. /// void DepositCharge(amrex::Vector >& rho, bool local = false); @@ -80,14 +80,14 @@ public: /// amrex::Real sumParticleCharge(bool local = false); #endif // WARPX_DO_ELECTROSTATIC - + /// /// Performs the field gather operation using the input fields E and B, for all the species /// in the MultiParticleContainer. This is the electromagnetic version of the field gather. /// void FieldGather (int lev, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, - const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); + const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); /// /// This evolves all the particles by one PIC time step, including current deposition, the @@ -97,8 +97,8 @@ public: void Evolve (int lev, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz, - amrex::MultiFab& jx, amrex::MultiFab& jy, amrex::MultiFab& jz, - amrex::MultiFab* cjx, amrex::MultiFab* cjy, amrex::MultiFab* cjz, + amrex::MultiFab& jx, amrex::MultiFab& jy, amrex::MultiFab& jz, + amrex::MultiFab* cjx, amrex::MultiFab* cjy, amrex::MultiFab* cjz, amrex::MultiFab* rho, amrex::MultiFab* crho, const amrex::MultiFab* cEx, const amrex::MultiFab* cEy, const amrex::MultiFab* cEz, const amrex::MultiFab* cBx, const amrex::MultiFab* cBy, const amrex::MultiFab* cBz, @@ -108,7 +108,7 @@ public: /// This pushes the particle positions by one half time step for all the species in the /// MultiParticleContainer. It is used to desynchronize the particles after initializaton /// or when restarting from a checkpoint. This is the electromagnetic version. - /// + /// void PushX (amrex::Real dt); /// @@ -116,7 +116,7 @@ public: /// MultiParticleContainer. It is used to desynchronize the particles after initializaton /// or when restarting from a checkpoint. It is also used to synchronize particles at the /// the end of the run. This is the electromagnetic version. - /// + /// void PushP (int lev, amrex::Real dt, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, const amrex::MultiFab& Ez, const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz); @@ -125,14 +125,14 @@ public: /// This deposits the particle charge onto a node-centered MultiFab and returns a unique ptr /// to it. The charge density is accumulated over all the particles in the MultiParticleContainer /// This version uses PICSAR routines to perform the deposition. - /// + /// std::unique_ptr GetChargeDensity(int lev, bool local = false); void Checkpoint (const std::string& dir) const; void WritePlotFile( const std::string& dir, const amrex::Vector& real_names) const; - + void Restart (const std::string& dir); void PostRestart (); @@ -174,7 +174,7 @@ public: const amrex::Real t_boost, const amrex::Real t_lab, const amrex::Real dt, amrex::Vector& parts) const; - // Inject particles during the simulation (for particles entering the + // Inject particles during the simulation (for particles entering the // simulation domain after some iterations, due to flowing plasma and/or // moving window). void ContinuousInjection(const amrex::RealBox& injection_box) const; @@ -182,10 +182,10 @@ public: void UpdateContinuousInjectionPosition(amrex::Real dt) const; int doContinuousInjection() const; - // + // // Parameters for the Cherenkov corrector in the FDTD solver. // Both stencils are calculated ar runtime. - // + // // Number of coefficients for the stencil of the NCI corrector. // The stencil is applied in the z direction only. static constexpr int nstencilz_fdtd_nci_corr=5; @@ -196,7 +196,12 @@ public: std::vector GetSpeciesNames() const { return species_names; } PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } - + + //bw_engine is a public member of the MultiParticleContainer object +#ifdef WARPX_QED + pxrmp::breit_wheeler_engine bw_engine; +#endif + protected: // Particle container types @@ -221,7 +226,7 @@ private: // Number of species dumped in BoostedFrameDiagnostics int nspecies_boosted_frame_diags = 0; - // map_species_boosted_frame_diags[i] is the species ID in + // map_species_boosted_frame_diags[i] is the species ID in // MultiParticleContainer for 0 map_species_boosted_frame_diags; int do_boosted_frame_diags = 0; diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index b4abe8b76..d1e28fd1f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -11,6 +11,11 @@ using namespace amrex; constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) +#ifdef WARPX_QED + : + bw_engine{std::move(amrex_rng_wrapper{})}//, default_lambda};//, bw_ctrl}; +#endif + { ReadParameters(); @@ -27,7 +32,7 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) } allcontainers[i]->deposit_on_main_grid = deposit_on_main_grid[i]; } - + for (int i = nspecies; i < nspecies+nlasers; ++i) { allcontainers[i].reset(new LaserParticleContainer(amr_core,i, lasers_names[i-nspecies])); } @@ -195,7 +200,7 @@ MultiParticleContainer::Evolve (int lev, const MultiFab& Ex, const MultiFab& Ey, const MultiFab& Ez, const MultiFab& Bx, const MultiFab& By, const MultiFab& Bz, MultiFab& jx, MultiFab& jy, MultiFab& jz, - MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, + MultiFab* cjx, MultiFab* cjy, MultiFab* cjz, MultiFab* rho, const MultiFab* cEx, const MultiFab* cEy, const MultiFab* cEz, const MultiFab* cBx, const MultiFab* cBy, const MultiFab* cBz, @@ -211,7 +216,7 @@ MultiParticleContainer::Evolve (int lev, for (auto& pc : allcontainers) { pc->Evolve(lev, Ex, Ey, Ez, Bx, By, Bz, jx, jy, jz, cjx, cjy, cjz, rho, cEx, cEy, cEz, cBx, cBy, cBz, t, dt); - } + } } void @@ -407,7 +412,7 @@ MultiParticleContainer { BL_PROFILE("MultiParticleContainer::GetLabFrameData"); - + // Loop over particle species for (int i = 0; i < nspecies_boosted_frame_diags; ++i){ int isp = map_species_boosted_frame_diags[i]; @@ -416,41 +421,41 @@ MultiParticleContainer pc->GetParticleSlice(direction, z_old, z_new, t_boost, t_lab, dt, diagnostic_particles); // Here, diagnostic_particles[lev][index] is a WarpXParticleContainer::DiagnosticParticleData // where "lev" is the AMR level and "index" is a [grid index][tile index] pair. - + // Loop over AMR levels for (int lev = 0; lev <= pc->finestLevel(); ++lev){ - // Loop over [grid index][tile index] pairs - // and Fills parts[species number i] with particle data from all grids and - // tiles in diagnostic_particles. parts contains particles from all + // Loop over [grid index][tile index] pairs + // and Fills parts[species number i] with particle data from all grids and + // tiles in diagnostic_particles. parts contains particles from all // AMR levels indistinctly. for (auto it = diagnostic_particles[lev].begin(); it != diagnostic_particles[lev].end(); ++it){ // it->first is the [grid index][tile index] key - // it->second is the corresponding + // it->second is the corresponding // WarpXParticleContainer::DiagnosticParticleData value parts[i].GetRealData(DiagIdx::w).insert( parts[i].GetRealData(DiagIdx::w ).end(), it->second.GetRealData(DiagIdx::w ).begin(), it->second.GetRealData(DiagIdx::w ).end()); - + parts[i].GetRealData(DiagIdx::x).insert( parts[i].GetRealData(DiagIdx::x ).end(), it->second.GetRealData(DiagIdx::x ).begin(), it->second.GetRealData(DiagIdx::x ).end()); - + parts[i].GetRealData(DiagIdx::y).insert( parts[i].GetRealData(DiagIdx::y ).end(), it->second.GetRealData(DiagIdx::y ).begin(), it->second.GetRealData(DiagIdx::y ).end()); - + parts[i].GetRealData(DiagIdx::z).insert( parts[i].GetRealData(DiagIdx::z ).end(), it->second.GetRealData(DiagIdx::z ).begin(), it->second.GetRealData(DiagIdx::z ).end()); - + parts[i].GetRealData(DiagIdx::ux).insert( parts[i].GetRealData(DiagIdx::ux).end(), it->second.GetRealData(DiagIdx::ux).begin(), it->second.GetRealData(DiagIdx::ux).end()); - + parts[i].GetRealData(DiagIdx::uy).insert( parts[i].GetRealData(DiagIdx::uy).end(), it->second.GetRealData(DiagIdx::uy).begin(), it->second.GetRealData(DiagIdx::uy).end()); - + parts[i].GetRealData(DiagIdx::uz).insert( parts[i].GetRealData(DiagIdx::uz).end(), it->second.GetRealData(DiagIdx::uz).begin(), it->second.GetRealData(DiagIdx::uz).end()); @@ -461,7 +466,7 @@ MultiParticleContainer /* \brief Continuous injection for particles initially outside of the domain. * \param injection_box: Domain where new particles should be injected. - * Loop over all WarpXParticleContainer in MultiParticleContainer and + * Loop over all WarpXParticleContainer in MultiParticleContainer and * calls virtual function ContinuousInjection. */ void @@ -477,7 +482,7 @@ MultiParticleContainer::ContinuousInjection(const RealBox& injection_box) const /* \brief Update position of continuous injection parameters. * \param dt: simulation time step (level 0) - * All classes inherited from WarpXParticleContainer do not have + * All classes inherited from WarpXParticleContainer do not have * a position to update (PhysicalParticleContainer does not do anything). */ void -- cgit v1.2.3 From 623c962eff3c57f7b3e413f3dda02eeccc4bdf4e Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 10:16:32 +0200 Subject: bw engine is now initialized in the MultiParticleContainer object --- Source/Particles/MultiParticleContainer.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index d1e28fd1f..30b60a391 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -159,6 +159,27 @@ MultiParticleContainer::InitData () pc->InitData(); } pc_tmp->InitData(); + +#ifdef WARPX_QED + //Initialize the lookup tables + //Generates tables if they do not exist + if(!does_file_exist("bw_engine_dndt.bin")){ + bw_engine.compute_dN_dt_lookup_table(&std::cout); + bw_engine.write_dN_dt_table("bw_engine_dndt.bin"); + } + else{ + bw_engine.read_dN_dt_table("bw_engine_dndt.bin"); + } + + if(!does_file_exist("bw_engine_pair.bin")){ + bw_engine.compute_cumulative_pair_table(&std::cout); + bw_engine.write_cumulative_pair_table("bw_engine_pair.bin"); + } + else{ + bw_engine.read_cumulative_pair_table("bw_engine_pair.bin"); + } +#endif + } -- cgit v1.2.3 From 6a9acaeaa3c625d7885d85c44bd68e2bf432df4f Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 10:44:52 +0200 Subject: corrected bug & moved bw_engine completely in MultiParticleContaine --- Source/Particles/MultiParticleContainer.H | 35 +++++++++++++++++++++++++++-- Source/Particles/MultiParticleContainer.cpp | 5 +++++ Source/WarpX.H | 31 ------------------------- 3 files changed, 38 insertions(+), 33 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index a76fd89e3..acb14aa8c 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -22,6 +22,37 @@ // concrete class dervied from WarpXParticlContainer. // +//Enable QED effects +#define WARPX_QED + +#ifdef WARPX_QED +//BW ENGINE +//#define PXRMP_GPU __host__ __device__ +#define PXRMP_WITH_SI_UNITS +#include "breit_wheeler_engine.hpp" +//Alias for the picsar::multi_physics namespace +namespace pxrmp = picsar::multi_physics; + +//RNG wrapper BW engine +class amrex_rng_wrapper +{ +public: + //Get rnd number uniformly distributed in [a,b) + amrex::Real unf(amrex::Real a, amrex::Real b) + { + return (b-a)*amrex::Random() + a; + } + + //Get rnd number with exponential distribution + amrex::Real exp(amrex::Real l) + { + amrex::Real zero_plus_to_one = 1.0 - unf(0.0, 1.0); + return -log(zero_plus_to_one)/l; + } +}; +//___________________________________________ +#endif + class MultiParticleContainer { @@ -198,9 +229,9 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } //bw_engine is a public member of the MultiParticleContainer object -#ifdef WARPX_QED +//#ifdef WARPX_QED pxrmp::breit_wheeler_engine bw_engine; -#endif +//#endif protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 30b60a391..993817e03 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -161,6 +161,11 @@ MultiParticleContainer::InitData () pc_tmp->InitData(); #ifdef WARPX_QED + + //Helper function + auto does_file_exist = [](const char *fileName) + {return (std::ifstream{fileName}).good(); }; + //Initialize the lookup tables //Generates tables if they do not exist if(!does_file_exist("bw_engine_dndt.bin")){ diff --git a/Source/WarpX.H b/Source/WarpX.H index 3c5ab05dd..787d45035 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -35,37 +35,6 @@ class AmrMeshInSituBridge; } #endif -//Enable QED effects -#define WARPX_QED - -#ifdef WARPX_QED -//BW ENGINE -//#define PXRMP_GPU __host__ __device__ -#define PXRMP_WITH_SI_UNITS -#include "breit_wheeler_engine.hpp" -//Alias for the picsar::multi_physics namespace -namespace pxrmp = picsar::multi_physics; - -//RNG wrapper BW engine -class amrex_rng_wrapper -{ -public: - //Get rnd number uniformly distributed in [a,b) - amrex::Real unf(amrex::Real a, amrex::Real b) - { - return (b-a)*amrex::Random() + a; - } - - //Get rnd number with exponential distribution - amrex::Real exp(amrex::Real l) - { - amrex::Real zero_plus_to_one = 1.0 - unf(0.0, 1.0); - return -log(zero_plus_to_one)/l; - } -}; -//___________________________________________ -#endif - enum struct DtType : int { Full = 0, -- cgit v1.2.3 From 1ebc8d24940889699bfc477fe84bed04fd885dcd Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 10:45:13 +0200 Subject: corrected bugs --- Source/Particles/MultiParticleContainer.H | 4 ++-- Source/Particles/MultiParticleContainer.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index acb14aa8c..2754607fd 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -229,9 +229,9 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } //bw_engine is a public member of the MultiParticleContainer object -//#ifdef WARPX_QED +#ifdef WARPX_QED pxrmp::breit_wheeler_engine bw_engine; -//#endif +#endif protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 993817e03..d8ccb36c6 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -10,12 +10,12 @@ using namespace amrex; constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; -MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) #ifdef WARPX_QED - : - bw_engine{std::move(amrex_rng_wrapper{})}//, default_lambda};//, bw_ctrl}; +MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core): + bw_engine{std::move(amrex_rng_wrapper{})}//, default_lambda};//, bw_ctrl}; +#else +MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) #endif - { ReadParameters(); -- cgit v1.2.3 From e52a1bb390e665dcf3f8a7f6e2790fa8200672a3 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 10:55:56 +0200 Subject: can't add a tau component to photons (it crashes :-( ) --- Source/Particles/MultiParticleContainer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index d8ccb36c6..c53ddceac 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -72,6 +72,13 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) pc_tmp->AddRealComp("uyold"); pc_tmp->AddRealComp("uzold"); } + +#ifdef WARPX_QED + //Add a tau field (optical depth) for all photon species + //for (int i = 0; i < nspecies; ++i) + //allcontainers[i]->AddRealComp("tau"); +#endif + } void -- cgit v1.2.3 From 81b53da1c52294a642f0d7919a25fa704a6172b7 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 11:20:26 +0200 Subject: now WARPX_QED is defined via makefile --- GNUmakefile | 2 ++ Source/Make.WarpX | 17 ++++++++++++----- Source/Particles/MultiParticleContainer.H | 2 -- Source/Particles/MultiParticleContainer.cpp | 4 ++-- Source/Particles/PhotonParticleContainer.cpp | 7 ++++++- 5 files changed, 22 insertions(+), 10 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/GNUmakefile b/GNUmakefile index 9d7b1c65f..5e4c46628 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,6 +8,8 @@ DEBUG = FALSE DIM = 2 #DIM = 3 +QED = TRUE + COMP = gcc #COMP = intel #COMP = pgi diff --git a/Source/Make.WarpX b/Source/Make.WarpX index c1ef54c33..280955665 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -45,6 +45,13 @@ endif DEFINES += -DWARPX_USE_PY endif +ifeq ($(QED),TRUE) + CXXFLAGS += -DWARPX_QED + CFLAGS += -DWARPX_QED + FFLAGS += -DWARPX_QED + F90FLAGS += -DWARPX_QED +endif + -include Make.package include $(WARPX_HOME)/Source/Make.package include $(WARPX_HOME)/Source/BoundaryConditions/Make.package @@ -98,7 +105,7 @@ ifeq ($(USE_OPENPMD), TRUE) DEFINES += -DWARPX_USE_OPENPMD -DopenPMD_HAVE_MPI=1 LIBRARIES += -lopenPMD -lhdf5 endif - + ifeq ($(USE_PSATD),TRUE) FFTW_HOME ?= NOT_SET @@ -139,7 +146,7 @@ ifeq ($(USE_HDF5),TRUE) endif DEFINES += -DWARPX_USE_HDF5 LIBRARIES += -lhdf5 -lz -endif +endif # job_info support CEXE_sources += AMReX_buildInfo.cpp @@ -186,7 +193,7 @@ else ifdef WarpxBinDir -all: $(executable) +all: $(executable) $(SILENT) $(RM) AMReX_buildInfo.cpp @if [ ! -d $(WarpxBinDir) ]; then mkdir -p $(WarpxBinDir); fi $(SILENT) mv -f $(executable) $(WarpxBinDir)/ @@ -195,7 +202,7 @@ all: $(executable) else -all: $(executable) +all: $(executable) $(SILENT) $(RM) AMReX_buildInfo.cpp @echo SUCCESS @@ -203,7 +210,7 @@ endif endif -AMReX_buildInfo.cpp: +AMReX_buildInfo.cpp: $(AMREX_HOME)/Tools/C_scripts/makebuildinfo_C.py \ --amrex_home "$(AMREX_HOME)" \ --COMP "$(COMP)" --COMP_VERSION "$(COMP_VERSION)" \ diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 2754607fd..44e325b84 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -22,8 +22,6 @@ // concrete class dervied from WarpXParticlContainer. // -//Enable QED effects -#define WARPX_QED #ifdef WARPX_QED //BW ENGINE diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index c53ddceac..c22e87345 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -75,8 +75,8 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) #ifdef WARPX_QED //Add a tau field (optical depth) for all photon species - //for (int i = 0; i < nspecies; ++i) - //allcontainers[i]->AddRealComp("tau"); + for (int i = 0; i < nspecies; ++i) + allcontainers[i]->AddRealComp("tau"); #endif } diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 0e1adc13b..8c8008627 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -26,6 +26,11 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie // store it into member data. pp.query("size_in_inches", size_in_inches); +#define WARPX_QED +#ifdef WARPX_QED + plot_flags.resize(PIdx::nattribs + 6, 1); +#endif + } void PhotonParticleContainer::InitData() @@ -57,7 +62,7 @@ PhotonParticleContainer::PushPX(WarpXParIter& pti, auto& Bzp = attribs[PIdx::Bz]; const long np = pti.numParticles(); - // Using new pusher for positions + // Using new pusher for positions const amrex_real zero_mass = 0.0; const amrex_real zero_charge = 0.0; warpx_particle_pusher_positions(&np, -- cgit v1.2.3 From cf3b3e52e484eca8c5640f65863186ba47137cad Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 11:39:26 +0200 Subject: Moved addition of tau component into PhotonParticleContainer --- Source/Particles/MultiParticleContainer.cpp | 7 ------- Source/Particles/PhotonParticleContainer.cpp | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index c22e87345..d8ccb36c6 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -72,13 +72,6 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) pc_tmp->AddRealComp("uyold"); pc_tmp->AddRealComp("uzold"); } - -#ifdef WARPX_QED - //Add a tau field (optical depth) for all photon species - for (int i = 0; i < nspecies; ++i) - allcontainers[i]->AddRealComp("tau"); -#endif - } void diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 8c8008627..b0bbf406a 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -26,8 +26,8 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie // store it into member data. pp.query("size_in_inches", size_in_inches); -#define WARPX_QED #ifdef WARPX_QED + AddRealComp("tau"); plot_flags.resize(PIdx::nattribs + 6, 1); #endif -- cgit v1.2.3 From e1067378f5d43c11850f4e6518cbfe3a96250889 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 14:37:08 +0200 Subject: Added a wrapper for BW engine --- Source/Particles/MultiParticleContainer.H | 30 +++------------------------- Source/Particles/MultiParticleContainer.cpp | 12 ++++++----- Source/Particles/PhotonParticleContainer.cpp | 4 ++++ Source/QED/Make.package | 5 +++-- Source/QED/amrex_rng_wrapper.cpp | 18 +++++++++++++++++ Source/QED/amrex_rng_wrapper.h | 20 +++++++++++++++++++ Source/QED/amrex_rng_wrapper.hpp | 27 ------------------------- Source/QED/breit_wheeler_engine_wrapper.h | 7 +++---- 8 files changed, 58 insertions(+), 65 deletions(-) create mode 100644 Source/QED/amrex_rng_wrapper.cpp create mode 100644 Source/QED/amrex_rng_wrapper.h delete mode 100644 Source/QED/amrex_rng_wrapper.hpp (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 44e325b84..eb1d2ba75 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -22,33 +22,9 @@ // concrete class dervied from WarpXParticlContainer. // - +// #ifdef WARPX_QED -//BW ENGINE -//#define PXRMP_GPU __host__ __device__ -#define PXRMP_WITH_SI_UNITS -#include "breit_wheeler_engine.hpp" -//Alias for the picsar::multi_physics namespace -namespace pxrmp = picsar::multi_physics; - -//RNG wrapper BW engine -class amrex_rng_wrapper -{ -public: - //Get rnd number uniformly distributed in [a,b) - amrex::Real unf(amrex::Real a, amrex::Real b) - { - return (b-a)*amrex::Random() + a; - } - - //Get rnd number with exponential distribution - amrex::Real exp(amrex::Real l) - { - amrex::Real zero_plus_to_one = 1.0 - unf(0.0, 1.0); - return -log(zero_plus_to_one)/l; - } -}; -//___________________________________________ + #include "breit_wheeler_engine_wrapper.h" #endif class MultiParticleContainer @@ -228,7 +204,7 @@ public: //bw_engine is a public member of the MultiParticleContainer object #ifdef WARPX_QED - pxrmp::breit_wheeler_engine bw_engine; + warpx_breit_wheeler_engine bw_engine; #endif protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index d8ccb36c6..92f66c705 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -10,13 +10,15 @@ using namespace amrex; constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; -#ifdef WARPX_QED + MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core): - bw_engine{std::move(amrex_rng_wrapper{})}//, default_lambda};//, bw_ctrl}; -#else -MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) -#endif + bw_engine{std::move(init_warpx_breit_wheeler_engine())} { + +#ifdef WARPX_QED + +#endif + ReadParameters(); allcontainers.resize(nspecies + nlasers); diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 41ad13fc2..9ea448ec8 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -37,6 +37,10 @@ void PhotonParticleContainer::InitData() { AddParticles(0); // Note - add on level 0 +#ifdef WARPX_QED + InitOpticalDepth(); +#endif + if (maxLevel() > 0) { Redistribute(); // We then redistribute } diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 12b007e73..6e38efb9e 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,5 +1,6 @@ -CEXE_headers += WarpXConst.H -CEXE_headers += WarpXUtil.H +CEXE_headers += amrex_rng_wrapper.h +CEXE_headers += breit_wheeler_engine_wrapper.h +CEXE_sources += amrex_rng_wrapper.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/QED VPATH_LOCATIONS += $(WARPX_HOME)/Source/QED diff --git a/Source/QED/amrex_rng_wrapper.cpp b/Source/QED/amrex_rng_wrapper.cpp new file mode 100644 index 000000000..955144c4c --- /dev/null +++ b/Source/QED/amrex_rng_wrapper.cpp @@ -0,0 +1,18 @@ +//This file provides a wrapper aroud the RNG +//provided by the amrex library + +#include "amrex_rng_wrapper.h" + +//RNG wrapper BW engine +//Get rnd number uniformly distributed in [a,b) +amrex::Real amrex_rng_wrapper::unf(amrex::Real a, amrex::Real b) +{ + return (b-a)*amrex::Random() + a; +} + +//Get rnd number with exponential distribution +amrex::Real amrex_rng_wrapper::exp(amrex::Real l) +{ + amrex::Real zero_plus_to_one = 1.0 - unf(0.0, 1.0); + return -log(zero_plus_to_one)/l; +} diff --git a/Source/QED/amrex_rng_wrapper.h b/Source/QED/amrex_rng_wrapper.h new file mode 100644 index 000000000..f9818c589 --- /dev/null +++ b/Source/QED/amrex_rng_wrapper.h @@ -0,0 +1,20 @@ +#ifndef WARPX_amrex_rng_wrapper_h_ +#define WARPX_rng_wrapper_h_ + +//This file provides a wrapper aroud the RNG +//provided by the amrex library + +#include + +//RNG wrapper BW engine +class amrex_rng_wrapper +{ +public: + //Get rnd number uniformly distributed in [a,b) + amrex::Real unf(amrex::Real a, amrex::Real b); + + //Get rnd number with exponential distribution + amrex::Real exp(amrex::Real l); +}; + +#endif //amrex_rng_wrapper_hpp_ diff --git a/Source/QED/amrex_rng_wrapper.hpp b/Source/QED/amrex_rng_wrapper.hpp deleted file mode 100644 index 25d667df7..000000000 --- a/Source/QED/amrex_rng_wrapper.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WARPX_amrex_rng_wrapper_hpp_ -#define WARPX_rng_wrapper_hpp_ - -//This file provides a wrapper aroud the RNG -//provided by the amrex library - -#include - -//RNG wrapper BW engine -inline class amrex_rng_wrapper -{ -public: - //Get rnd number uniformly distributed in [a,b) - amrex::Real unf(amrex::Real a, amrex::Real b) - { - return (b-a)*amrex::Random() + a; - } - - //Get rnd number with exponential distribution - amrex::Real exp(amrex::Real l) - { - amrex::Real zero_plus_to_one = 1.0 - unf(0.0, 1.0); - return -log(zero_plus_to_one)/l; - } -}; - -#endif //amrex_rng_wrapper_hpp_ diff --git a/Source/QED/breit_wheeler_engine_wrapper.h b/Source/QED/breit_wheeler_engine_wrapper.h index 17bf4ef69..3bb3ea740 100644 --- a/Source/QED/breit_wheeler_engine_wrapper.h +++ b/Source/QED/breit_wheeler_engine_wrapper.h @@ -9,17 +9,16 @@ #define PXRMP_WITH_SI_UNITS #include "breit_wheeler_engine.hpp" -#include "amrex_rng_wrapper.hpp" +#include "amrex_rng_wrapper.h" using warpx_breit_wheeler_engine = picsar::multi_physics::breit_wheeler_engine; //Helper function to initialize the engine -inline warpx_breit_wheeler_engine&& init_warpx_breit_wheeler_engine(){ - return std::move(warpx_breit_wheeler_engine{std::move{amrex_rng_wrapper{}}}); +inline warpx_breit_wheeler_engine init_warpx_breit_wheeler_engine(){ + return warpx_breit_wheeler_engine{std::move(amrex_rng_wrapper{})}; } //___________________________________________ -#endif #endif //WARPX_breit_wheeler_engine_wrapper_H_ -- cgit v1.2.3 From ffb2c6a10bcfcf8c2b7a617f0d1ddb9fd8666aec Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 3 Jun 2019 15:24:54 +0200 Subject: Added function to initialize the optical depth (still crashing) --- Source/Particles/MultiParticleContainer.cpp | 9 +++++---- Source/Particles/PhotonParticleContainer.H | 8 ++++++-- Source/Particles/PhotonParticleContainer.cpp | 17 ++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 92f66c705..a56651f50 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -10,14 +10,15 @@ using namespace amrex; constexpr int MultiParticleContainer::nstencilz_fdtd_nci_corr; - +#ifdef WARPX_QED MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core): bw_engine{std::move(init_warpx_breit_wheeler_engine())} +#else +MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) +#endif { -#ifdef WARPX_QED - -#endif + ReadParameters(); diff --git a/Source/Particles/PhotonParticleContainer.H b/Source/Particles/PhotonParticleContainer.H index 4c72fe47e..616231ef6 100644 --- a/Source/Particles/PhotonParticleContainer.H +++ b/Source/Particles/PhotonParticleContainer.H @@ -4,6 +4,8 @@ #include #include +#include "breit_wheeler_engine_wrapper.h" + class PhotonParticleContainer : public PhysicalParticleContainer { @@ -63,9 +65,11 @@ public: int lev, amrex::Real dt ) override {}; - +//This function initialises the optical depth of the photons #ifdef WARPX_QED - virtual void InitOpticalDepth(); + virtual void InitOpticalDepth( + WarpXParIter& pti, + warpx_breit_wheeler_engine& engine); #endif private: diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 9ea448ec8..6e6300bd1 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -11,6 +11,8 @@ #include #include +#include "breit_wheeler_engine_wrapper.h" + using namespace amrex; PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecies, @@ -37,10 +39,6 @@ void PhotonParticleContainer::InitData() { AddParticles(0); // Note - add on level 0 -#ifdef WARPX_QED - InitOpticalDepth(); -#endif - if (maxLevel() > 0) { Redistribute(); // We then redistribute } @@ -110,7 +108,12 @@ PhotonParticleContainer::Evolve (int lev, #ifdef WARPX_QED - void PhotonParticleContainer::InitOpticalDepth(){ - - } +void PhotonParticleContainer::InitOpticalDepth( + WarpXParIter& pti, + warpx_breit_wheeler_engine& engine) +{ + auto& taus = pti.GetAttribs(particle_comps["tau"]); + for(auto& tau: taus) + tau = engine.get_optical_depth(); +} #endif -- cgit v1.2.3 From e90fc75dee20853fd2c3fa8ed08c2cf349e3e7d4 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 12 Sep 2019 08:28:31 -0700 Subject: remove QED specifics, they will be included in later PRs --- Source/Particles/MultiParticleContainer.H | 5 ---- Source/Particles/MultiParticleContainer.cpp | 36 +++-------------------------- 2 files changed, 3 insertions(+), 38 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index db00f4209..1aad4b2cb 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -22,11 +22,6 @@ // concrete class derived from WarpXParticlContainer. // -// -#ifdef WARPX_QED - #include "breit_wheeler_engine_wrapper.h" -#endif - class MultiParticleContainer { diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 8a4d1cf18..9c9bdcec4 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -8,16 +8,9 @@ using namespace amrex; -#ifdef WARPX_QED -MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core): - bw_engine{std::move(init_warpx_breit_wheeler_engine())} -#else MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) -#endif { - - ReadParameters(); allcontainers.resize(nspecies + nlasers); @@ -112,7 +105,9 @@ MultiParticleContainer::ReadParameters () if (!photon_species.empty()) { for (auto const& name : photon_species) { auto it = std::find(species_names.begin(), species_names.end(), name); - AMREX_ALWAYS_ASSERT_WITH_MESSAGE(it != species_names.end(), "ERROR: species in particles.rigid_injected_species must be part of particles.species_names"); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + it != species_names.end(), + "ERROR: species in particles.rigid_injected_species must be part of particles.species_names"); int i = std::distance(species_names.begin(), it); species_types[i] = PCTypes::Photon; } @@ -154,31 +149,6 @@ MultiParticleContainer::InitData () // For each species, get the ID of its product species. // This is used for ionization and pair creation processes. mapSpeciesProduct(); - -#ifdef WARPX_QED - - //Helper function - auto does_file_exist = [](const char *fileName) - {return (std::ifstream{fileName}).good(); }; - - //Initialize the lookup tables - //Generates tables if they do not exist - if(!does_file_exist("bw_engine_dndt.bin")){ - bw_engine.compute_dN_dt_lookup_table(&std::cout); - bw_engine.write_dN_dt_table("bw_engine_dndt.bin"); - } - else{ - bw_engine.read_dN_dt_table("bw_engine_dndt.bin"); - } - - if(!does_file_exist("bw_engine_pair.bin")){ - bw_engine.compute_cumulative_pair_table(&std::cout); - bw_engine.write_cumulative_pair_table("bw_engine_pair.bin"); - } - else{ - bw_engine.read_cumulative_pair_table("bw_engine_pair.bin"); - } -#endif } -- cgit v1.2.3