From 9446ea37a95b79116ab78836b7a6a6f60ff4dbb2 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 12:37:01 +0200 Subject: Added do_qed_breit_wheeler flag for photons --- Source/Particles/PhotonParticleContainer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 61e602ffb..399892959 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -31,6 +31,12 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie // store it into member data. pp.query("size_in_inches", size_in_inches); +#ifdef WARPX_QED + //IF do_qed is enabled, find out if Breit Wheeler process is enabled + if(do_qed) + pp.query("do_qed_breit_wheeler", do_qed_breit_wheeler); +#endif + } void PhotonParticleContainer::InitData() -- cgit v1.2.3 From d48db8b433b165a7822e914b8fda7636924f1c32 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 13:52:36 +0200 Subject: Added initialization of tau for photons via BW engine --- Source/Particles/PhotonParticleContainer.H | 3 +++ Source/Particles/PhotonParticleContainer.cpp | 25 +++++++++++++++++++++++++ Source/QED/breit_wheeler_engine_wrapper.h | 9 +++++++++ 3 files changed, 37 insertions(+) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.H b/Source/Particles/PhotonParticleContainer.H index 9d7cc641f..85c18dcf6 100644 --- a/Source/Particles/PhotonParticleContainer.H +++ b/Source/Particles/PhotonParticleContainer.H @@ -72,6 +72,9 @@ private: #ifdef WARPX_QED // A flag to enable breit_wheeler process for photons bool do_qed_breit_wheeler = false; + + // A function to initialize the Tau component according to the BW engine + void InitTauBreitWheeler(); #endif diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 399892959..e6712657a 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -43,6 +43,11 @@ void PhotonParticleContainer::InitData() { AddParticles(0); // Note - add on level 0 +#ifdef WARPX_QED + if(do_qed_breit_wheeler) + InitTauBreitWheeler(); +#endif + if (maxLevel() > 0) { Redistribute(); // We then redistribute } @@ -118,3 +123,23 @@ PhotonParticleContainer::Evolve (int lev, t, dt); } + +#ifdef WARPX_QED +// A function to initialize the Tau component according to the BW engine +void PhotonParticleContainer::InitTauBreitWheeler() +{ + BL_PROFILE("PhotonParticleContainer::InitOpticalDepth"); +//Looping over all the particles +int num_levels = finestLevel() + 1; +for (int lev=0; lev < num_levels; ++lev) + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ + auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); + amrex::ParallelFor( + pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + taus[i] = warpx_breit_wheeler_get_optical_depth(); + } + ); + } +} +#endif diff --git a/Source/QED/breit_wheeler_engine_wrapper.h b/Source/QED/breit_wheeler_engine_wrapper.h index 3bb3ea740..0e4164423 100644 --- a/Source/QED/breit_wheeler_engine_wrapper.h +++ b/Source/QED/breit_wheeler_engine_wrapper.h @@ -19,6 +19,15 @@ inline warpx_breit_wheeler_engine init_warpx_breit_wheeler_engine(){ return warpx_breit_wheeler_engine{std::move(amrex_rng_wrapper{})}; } +//Interface for the get_optical_depth method of the BW engine +inline +AMREX_GPU_HOST_DEVICE +amrex::Real warpx_breit_wheeler_get_optical_depth(){ + return warpx_breit_wheeler_engine:: + internal_get_optical_depth(amrex::Random()); +} + + //___________________________________________ #endif //WARPX_breit_wheeler_engine_wrapper_H_ -- cgit v1.2.3 From a0d4cb42266e8e3c6140138e718e11a10f8f58d4 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 14:33:31 +0200 Subject: Optical depth correctly initialized. Now BW engine wrapper is a class --- Source/Particles/MultiParticleContainer.cpp | 21 ++++++++----------- Source/Particles/PhotonParticleContainer.cpp | 2 +- Source/QED/Make.package | 2 ++ Source/QED/breit_wheeler_engine_wrapper.h | 30 +++++++++++----------------- Source/QED/qed_wrapper_commons.h | 13 ++++++++++++ 5 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 Source/QED/qed_wrapper_commons.h (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 74e59867e..e65c0d600 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -8,12 +8,7 @@ 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 { @@ -495,7 +490,7 @@ MultiParticleContainer::doContinuousInjection () const } /* \brief Get ID of product species of each species. - * The users specifies the name of the product species, + * The users specifies the name of the product species, * this routine get its ID. */ void @@ -503,8 +498,8 @@ MultiParticleContainer::mapSpeciesProduct () { for (int i=0; iionization_product_name and store its ID into + // If species pc has ionization on, find species with name + // pc->ionization_product_name and store its ID into // pc->ionization_product. if (pc->do_field_ionization){ int i_product = getSpeciesID(pc->ionization_product_name); @@ -615,7 +610,7 @@ namespace } // --- product runtime attribs GpuArray runtime_attribs_product; - bool do_boosted_product = WarpX::do_boosted_frame_diagnostic + bool do_boosted_product = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); if (do_boosted_product) { std::map comps_product = pc_product->getParticleComps(); @@ -662,7 +657,7 @@ namespace attribs_product[ia][ip] = attribs_source[ia][is]; } // Update xold etc. if boosted frame diagnostics required - // for product species. Fill runtime attribs with a copy of + // for product species. Fill runtime attribs with a copy of // current properties (xold = x etc.). if (do_boosted_product) { runtime_attribs_product[0][ip] = p_source.pos(0); @@ -685,7 +680,7 @@ MultiParticleContainer::doFieldIonization () // Loop over all species. // Ionized particles in pc_source create particles in pc_product for (auto& pc_source : allcontainers){ - + // Skip if not ionizable if (!pc_source->do_field_ionization){ continue; } @@ -699,7 +694,7 @@ MultiParticleContainer::doFieldIonization () // they do not exist (or if they were defined by default, i.e., // without runtime component). #ifdef _OPENMP - // Touch all tiles of source species in serial if runtime attribs + // Touch all tiles of source species in serial if runtime attribs for (MFIter mfi = pc_source->MakeMFIter(lev); mfi.isValid(); ++mfi) { const int grid_id = mfi.index(); const int tile_id = mfi.LocalTileIndex(); @@ -721,7 +716,7 @@ MultiParticleContainer::doFieldIonization () MFItInfo info; if (pc_source->do_tiling && Gpu::notInLaunchRegion()) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - pc_product->do_tiling, + pc_product->do_tiling, "For ionization, either all or none of the " "particle species must use tiling."); info.EnableTiling(pc_source->tile_size); diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index e6712657a..5fecaf525 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -137,7 +137,7 @@ for (int lev=0; lev < num_levels; ++lev) amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { - taus[i] = warpx_breit_wheeler_get_optical_depth(); + taus[i] = warpx_breit_wheeler_engine::get_optical_depth(); } ); } diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 6e38efb9e..73ac89228 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,6 +1,8 @@ +CEXE_headers += qed_wrapper_commons.h CEXE_headers += amrex_rng_wrapper.h CEXE_headers += breit_wheeler_engine_wrapper.h CEXE_sources += amrex_rng_wrapper.cpp +CEXE_sources += breit_wheeler_engine_wrapper.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/QED VPATH_LOCATIONS += $(WARPX_HOME)/Source/QED diff --git a/Source/QED/breit_wheeler_engine_wrapper.h b/Source/QED/breit_wheeler_engine_wrapper.h index 0e4164423..e4649f3cb 100644 --- a/Source/QED/breit_wheeler_engine_wrapper.h +++ b/Source/QED/breit_wheeler_engine_wrapper.h @@ -5,28 +5,22 @@ //provided by the standard template library //BW ENGINE -//#define PXRMP_GPU __host__ __device__ -#define PXRMP_WITH_SI_UNITS +#include "qed_wrapper_commons.h" #include "breit_wheeler_engine.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 warpx_breit_wheeler_engine{std::move(amrex_rng_wrapper{})}; -} - -//Interface for the get_optical_depth method of the BW engine -inline -AMREX_GPU_HOST_DEVICE -amrex::Real warpx_breit_wheeler_get_optical_depth(){ - return warpx_breit_wheeler_engine:: - internal_get_optical_depth(amrex::Random()); -} - +class warpx_breit_wheeler_engine : + public picsar::multi_physics:: + breit_wheeler_engine +{ +public: + warpx_breit_wheeler_engine(); + + //Interface for the get_optical_depth method of the BW engine + static AMREX_GPU_HOST_DEVICE + amrex::Real get_optical_depth(); +}; //___________________________________________ diff --git a/Source/QED/qed_wrapper_commons.h b/Source/QED/qed_wrapper_commons.h new file mode 100644 index 000000000..4a7eab7fa --- /dev/null +++ b/Source/QED/qed_wrapper_commons.h @@ -0,0 +1,13 @@ +#ifndef WARPX_amrex_qed_wrapper_commons_h_ +#define WARPX_amrex_qed_wrapper_commons_h_ + +//Common definitions for the QED library wrappers + +#include + +//Sets the decorator for GPU +#define PXRMP_GPU AMREX_GPU_HOST_DEVICE +//Sets SI units in the library +#define PXRMP_WITH_SI_UNITS + +#endif -- cgit v1.2.3 From 85ca7fb2a3786956af222af095f500c9a05a4b9d Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 15:34:44 +0200 Subject: Now physical particles have Tau initialization via QS engine --- Examples/Physics_applications/QED/inputs.2d | 4 + Source/Particles/MultiParticleContainer.H | 11 +- Source/Particles/PhotonParticleContainer.cpp | 22 ++-- Source/Particles/PhysicalParticleContainer.H | 19 +++- Source/Particles/PhysicalParticleContainer.cpp | 152 +++++++++++++++---------- Source/QED/Make.package | 2 + Source/QED/amrex_rng_wrapper.h | 4 +- Source/QED/breit_wheeler_engine_wrapper.cpp | 16 +++ 8 files changed, 147 insertions(+), 83 deletions(-) create mode 100644 Source/QED/breit_wheeler_engine_wrapper.cpp (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Examples/Physics_applications/QED/inputs.2d b/Examples/Physics_applications/QED/inputs.2d index f08670736..cb7b41703 100644 --- a/Examples/Physics_applications/QED/inputs.2d +++ b/Examples/Physics_applications/QED/inputs.2d @@ -61,6 +61,10 @@ electrons.uz_m = 500. electrons.ux_th = 2. electrons.uy_th = 2. electrons.uz_th = 50. +##########QED#################### +electrons.do_qed = 1 +electrons.do_qed_quantum_sync = 1 +################################# photons.charge = -q_e photons.mass = m_e diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 67392c449..e377351bd 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -24,6 +24,7 @@ // #ifdef WARPX_QED #include "breit_wheeler_engine_wrapper.h" + #include "quantum_sync_engine_wrapper.h" #endif class MultiParticleContainer @@ -92,7 +93,7 @@ public: 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& By, const amrex::MultiFab& Bz); /// /// This evolves all the particles by one PIC time step, including current deposition, the @@ -129,7 +130,7 @@ 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 - /// + /// std::unique_ptr GetChargeDensity(int lev, bool local = false); void doFieldIonization (); @@ -137,7 +138,7 @@ public: void Checkpoint (const std::string& dir) const; void WritePlotFile (const std::string& dir) const; - + void Restart (const std::string& dir); void PostRestart (); @@ -191,9 +192,9 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } - //bw_engine is a public member of the MultiParticleContainer object #ifdef WARPX_QED warpx_breit_wheeler_engine bw_engine; + warpx_quantum_sync_engine qs_engine; #endif protected: @@ -220,7 +221,7 @@ private: void mapSpeciesProduct (); int getSpeciesID (std::string product_str); - + // Number of species dumped in BoostedFrameDiagnostics int nspecies_boosted_frame_diags = 0; // map_species_boosted_frame_diags[i] is the species ID in diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 5fecaf525..1da8cace2 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -129,17 +129,17 @@ PhotonParticleContainer::Evolve (int lev, void PhotonParticleContainer::InitTauBreitWheeler() { BL_PROFILE("PhotonParticleContainer::InitOpticalDepth"); -//Looping over all the particles -int num_levels = finestLevel() + 1; -for (int lev=0; lev < num_levels; ++lev) - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ - auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); - amrex::ParallelFor( - pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - taus[i] = warpx_breit_wheeler_engine::get_optical_depth(); - } - ); + //Looping over all the particles + int num_levels = finestLevel() + 1; + for (int lev=0; lev < num_levels; ++lev) + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ + auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); + amrex::ParallelFor( + pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + taus[i] = warpx_breit_wheeler_engine::get_optical_depth(); + } + ); } } #endif diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index c7494fbdf..578668fdb 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -24,7 +24,7 @@ public: void InitIonizationModule (); -#ifdef WARPX_DO_ELECTROSTATIC +#ifdef WARPX_DO_ELECTROSTATIC virtual void FieldGatherES(const amrex::Vector, 3> >& E, const amrex::Vector > > >& masks) override; @@ -32,7 +32,7 @@ public: amrex::Vector >& rho, amrex::Real t, amrex::Real dt) override; #endif // WARPX_DO_ELECTROSTATIC - + virtual void FieldGather (int lev, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, @@ -99,14 +99,14 @@ public: const amrex::MultiFab& Bx, const amrex::MultiFab& By, const amrex::MultiFab& Bz) override; - + void copy_attribs(WarpXParIter& pti,const amrex::Real* xp, const amrex::Real* yp, const amrex::Real* zp); virtual void PostRestart () final {} void SplitParticles(int lev); - + virtual void buildIonizationMask (const amrex::MFIter& mfi, const int lev, amrex::Gpu::ManagedDeviceVector& ionization_mask) override; @@ -125,7 +125,7 @@ public: std::array u, amrex::Real weight); virtual void GetParticleSlice(const int direction, const amrex::Real z_old, - const amrex::Real z_new, const amrex::Real t_boost, + const amrex::Real z_new, const amrex::Real t_boost, const amrex::Real t_lab, const amrex::Real dt, DiagnosticParticles& diagnostic_particles) final; @@ -145,6 +145,15 @@ protected: // Inject particles during the whole simulation void ContinuousInjection (const amrex::RealBox& injection_box) override; +private: +#ifdef WARPX_QED + // A flag to enable quantum_synchrotron process for leptons + bool do_qed_quantum_sync = false; + + // A function to initialize the Tau component according to the QS engine + void InitTauQuantumSync(); +#endif + }; #endif diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index da4e3afc2..ae226015d 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -34,7 +34,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); pp.query("do_continuous_injection", do_continuous_injection); - // Whether to plot back-transformed (lab-frame) diagnostics + // Whether to plot back-transformed (lab-frame) diagnostics // for this species. pp.query("do_boosted_frame_diags", do_boosted_frame_diags); @@ -50,9 +50,14 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp #ifdef WARPX_QED //Add real component if QED is enabled pp.query("do_qed", do_qed); - if(do_qed){ + if(do_qed) AddRealComp("tau"); - } + + //IF do_qed is enabled, find out if Quantum Synchrotron process is enabled + if(do_qed) + pp.query("do_qed_quantum_sync", do_qed_quantum_sync); + + //TODO: SHOULD CHECK IF SPECIES IS EITHER ELECTRONS OR POSITRONS!! #endif //variable to set plot_flags size @@ -63,7 +68,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp #ifdef WARPX_QED if(do_qed){ // plot_flag will have an entry for the optical depth - plot_flag_size ++; + plot_flag_size++; } #endif //_______________________________ @@ -104,7 +109,14 @@ void PhysicalParticleContainer::InitData() // Init ionization module here instead of in the PhysicalParticleContainer // constructor because dt is required if (do_field_ionization) {InitIonizationModule();} + AddParticles(0); // Note - add on level 0 + +#ifdef WARPX_QED + if(do_qed_quantum_sync) + InitTauQuantumSync(); +#endif + Redistribute(); // We then redistribute } @@ -157,7 +169,7 @@ void PhysicalParticleContainer::MapParticletoBoostedFrame(Real& x, Real& y, Real void PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, Real x_rms, Real y_rms, Real z_rms, - Real q_tot, long npart, + Real q_tot, long npart, int do_symmetrize) { const Geometry& geom = m_gdb->Geom(0); @@ -169,7 +181,7 @@ PhysicalParticleContainer::AddGaussianBeam(Real x_m, Real y_m, Real z_m, std::normal_distribution distz(z_m, z_rms); if (ParallelDescriptor::IOProcessor()) { - // If do_symmetrize, create 4x fewer particles, and + // If do_symmetrize, create 4x fewer particles, and // Replicate each particle 4 times (x,y) (-x,y) (x,-y) (-x,-y) if (do_symmetrize){ npart /= 4; @@ -402,11 +414,11 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) const int tile_id = mfi.LocalTileIndex(); // Max number of new particles, if particles are created in the whole - // overlap_box. All of them are created, and invalid ones are then + // overlap_box. All of them are created, and invalid ones are then // discaded int max_new_particles = overlap_box.numPts() * num_ppc; - // If refine injection, build pointer dp_cellid that holds pointer to + // If refine injection, build pointer dp_cellid that holds pointer to // array of refined cell IDs. Vector cellid_v; if (refine_injection and lev == 0) @@ -461,7 +473,7 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) if (do_field_ionization) { pi = soa.GetIntData(particle_icomps["ionization_level"]).data() + old_size; } - + const GpuArray overlap_corner {AMREX_D_DECL(overlap_realbox.lo(0), overlap_realbox.lo(1), @@ -473,9 +485,9 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) bool loc_do_field_ionization = do_field_ionization; int loc_ionization_initial_level = ionization_initial_level; - // Loop over all new particles and inject them (creates too many + // Loop over all new particles and inject them (creates too many // particles, in particular does not consider xmin, xmax etc.). - // The invalid ones are given negative ID and are deleted during the + // The invalid ones are given negative ID and are deleted during the // next redistribute. amrex::For(max_new_particles, [=] AMREX_GPU_DEVICE (int ip) noexcept { @@ -642,7 +654,7 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) p.pos(1) = z; #endif }, shared_mem_bytes); - + if (cost) { wt = (amrex::second() - wt) / tile_box.d_numPts(); Array4 const& costarr = cost->array(mfi); @@ -880,7 +892,7 @@ PhysicalParticleContainer::FieldGather (int lev, MultiFab* cost = WarpX::getCosts(lev); #ifdef _OPENMP -#pragma omp parallel +#pragma omp parallel #endif { #ifdef _OPENMP @@ -930,7 +942,7 @@ PhysicalParticleContainer::FieldGather (int lev, // int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, + &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, Ex.nGrow(), e_is_nodal, 0, np, thread_num, lev, lev); @@ -964,11 +976,11 @@ PhysicalParticleContainer::Evolve (int lev, BL_PROFILE_VAR_NS("PPC::FieldGather", blp_fg); BL_PROFILE_VAR_NS("PPC::ParticlePush", blp_ppc_pp); BL_PROFILE_VAR_NS("PPC::Evolve::partition", blp_partition); - + const std::array& dx = WarpX::CellSize(lev); const std::array& cdx = WarpX::CellSize(std::max(lev-1,0)); - // Get instances of NCI Godfrey filters + // Get instances of NCI Godfrey filters const auto& nci_godfrey_filter_exeybz = WarpX::GetInstance().nci_godfrey_filter_exeybz; const auto& nci_godfrey_filter_bxbyez = WarpX::GetInstance().nci_godfrey_filter_bxbyez; @@ -993,9 +1005,9 @@ PhysicalParticleContainer::Evolve (int lev, tmp_particle_data[lev][index][i].resize(np); } } - + #ifdef _OPENMP -#pragma omp parallel +#pragma omp parallel #endif { #ifdef _OPENMP @@ -1194,7 +1206,7 @@ PhysicalParticleContainer::Evolve (int lev, } const long np_current = (cjx) ? nfine_current : np; - + // // copy data from particle container to temp arrays // @@ -1210,14 +1222,14 @@ PhysicalParticleContainer::Evolve (int lev, } else { ion_lev = nullptr; } - DepositCharge(pti, wp, ion_lev, rho, 0, 0, + DepositCharge(pti, wp, ion_lev, rho, 0, 0, np_current, thread_num, lev, lev); if (has_buffer){ DepositCharge(pti, wp, ion_lev, crho, 0, np_current, np-np_current, thread_num, lev, lev-1); } } - + if (! do_not_push) { const long np_gather = (cEx) ? nfine_gather : np; @@ -1229,7 +1241,7 @@ PhysicalParticleContainer::Evolve (int lev, // BL_PROFILE_VAR_START(blp_fg); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - exfab, eyfab, ezfab, bxfab, byfab, bzfab, + exfab, eyfab, ezfab, bxfab, byfab, bzfab, Ex.nGrow(), e_is_nodal, 0, np_gather, thread_num, lev, lev); @@ -1245,7 +1257,7 @@ PhysicalParticleContainer::Evolve (int lev, FArrayBox const* cbxfab = &(*cBx)[pti]; FArrayBox const* cbyfab = &(*cBy)[pti]; FArrayBox const* cbzfab = &(*cBz)[pti]; - + if (WarpX::use_fdtd_nci_corr) { #if (AMREX_SPACEDIM == 2) @@ -1283,13 +1295,13 @@ PhysicalParticleContainer::Evolve (int lev, eyeli = filtered_Ey.elixir(); nci_godfrey_filter_exeybz[lev-1]->ApplyStencil(filtered_Ey, (*cEy)[pti], filtered_Ey.box()); ceyfab = &filtered_Ey; - + // Filter Bx filtered_Bx.resize(amrex::convert(tbox,WarpX::Bx_nodal_flag)); bxeli = filtered_Bx.elixir(); nci_godfrey_filter_bxbyez[lev-1]->ApplyStencil(filtered_Bx, (*cBx)[pti], filtered_Bx.box()); cbxfab = &filtered_Bx; - + // Filter Bz filtered_Bz.resize(amrex::convert(tbox,WarpX::Bz_nodal_flag)); bzeli = filtered_Bz.elixir(); @@ -1297,14 +1309,14 @@ PhysicalParticleContainer::Evolve (int lev, cbzfab = &filtered_Bz; #endif } - + // Field gather for particles in gather buffers e_is_nodal = cEx->is_nodal() and cEy->is_nodal() and cEz->is_nodal(); - FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, cexfab, ceyfab, cezfab, cbxfab, cbyfab, cbzfab, - cEx->nGrow(), e_is_nodal, - nfine_gather, np-nfine_gather, + cEx->nGrow(), e_is_nodal, + nfine_gather, np-nfine_gather, thread_num, lev, lev-1); } @@ -1314,7 +1326,7 @@ PhysicalParticleContainer::Evolve (int lev, // Particle Push // BL_PROFILE_VAR_START(blp_ppc_pp); - PushPX(pti, m_xp[thread_num], m_yp[thread_num], m_zp[thread_num], + PushPX(pti, m_xp[thread_num], m_yp[thread_num], m_zp[thread_num], m_giv[thread_num], dt); BL_PROFILE_VAR_STOP(blp_ppc_pp); @@ -1328,7 +1340,7 @@ PhysicalParticleContainer::Evolve (int lev, } else { ion_lev = nullptr; } - + // Deposit inside domains DepositCurrent(pti, wp, uxp, uyp, uzp, ion_lev, &jx, &jy, &jz, 0, np_current, thread_num, @@ -1348,7 +1360,7 @@ PhysicalParticleContainer::Evolve (int lev, pti.SetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); BL_PROFILE_VAR_STOP(blp_copy); } - + if (rho) { // Deposit charge after particle push, in component 1 of MultiFab rho. int* AMREX_RESTRICT ion_lev; @@ -1417,7 +1429,7 @@ PhysicalParticleContainer::SplitParticles(int lev) for(int i=0; icharge; const Real m = this-> mass; if (WarpX::particle_pusher_algo == ParticlePusherAlgo::Boris){ - amrex::ParallelFor( + amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { Real qp = q; @@ -1624,7 +1636,7 @@ PhysicalParticleContainer::PushP (int lev, Real dt, int thread_num = omp_get_thread_num(); #else int thread_num = 0; -#endif +#endif for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { const Box& box = pti.validbox(); @@ -1664,7 +1676,7 @@ PhysicalParticleContainer::PushP (int lev, Real dt, int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, + &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, Ex.nGrow(), e_is_nodal, 0, np, thread_num, lev, lev); @@ -1712,7 +1724,7 @@ void PhysicalParticleContainer::copy_attribs(WarpXParIter& pti,const Real* xp, Real* AMREX_RESTRICT uxp = attribs[PIdx::ux].dataPtr(); Real* AMREX_RESTRICT uyp = attribs[PIdx::uy].dataPtr(); Real* AMREX_RESTRICT uzp = attribs[PIdx::uz].dataPtr(); - + const auto np = pti.numParticles(); const auto lev = pti.GetLevel(); const auto index = pti.GetPairIndex(); @@ -1728,7 +1740,7 @@ void PhysicalParticleContainer::copy_attribs(WarpXParIter& pti,const Real* xp, xpold[i]=xp[i]; ypold[i]=yp[i]; zpold[i]=zp[i]; - + uxpold[i]=uxp[i]; uypold[i]=uyp[i]; uzpold[i]=uzp[i]; @@ -1768,7 +1780,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real slice_box.setHi(direction, z_max); diagnostic_particles.resize(finestLevel()+1); - + for (int lev = 0; lev < nlevs; ++lev) { const Real* dx = Geom(lev).CellSize(); @@ -1815,7 +1827,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real auto& uzp_old = tmp_particle_data[lev][index][TmpIdx::uzold]; const long np = pti.numParticles(); - + Real uzfrm = -WarpX::gamma_boost*WarpX::beta_boost*PhysConst::c; Real inv_c2 = 1.0/PhysConst::c/PhysConst::c; @@ -1850,7 +1862,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real Real uzp = uz_old_p *weight_old + uz_new_p *weight_new; diagnostic_particles[lev][index].GetRealData(DiagIdx::w).push_back(wp[i]); - + diagnostic_particles[lev][index].GetRealData(DiagIdx::x).push_back(xp); diagnostic_particles[lev][index].GetRealData(DiagIdx::y).push_back(yp); diagnostic_particles[lev][index].GetRealData(DiagIdx::z).push_back(zp); @@ -1875,7 +1887,7 @@ PhysicalParticleContainer::ContinuousInjection(const RealBox& injection_box) AddPlasma(lev, injection_box); } -/* \brief Gather fields from FArrayBox exfab, eyfab, ezfab, bxfab, byfab, +/* \brief Gather fields from FArrayBox exfab, eyfab, ezfab, bxfab, byfab, * bzfab into arrays of fields on particles Exp, Eyp, Ezp, Bxp, Byp, Bzp. * \param Exp-Bzp: fields on particles. * \param exfab-bzfab: FAB of electric and magnetic fields for particles in pti @@ -1885,7 +1897,7 @@ PhysicalParticleContainer::ContinuousInjection(const RealBox& injection_box) * \param np_to_gather: number of particles onto which fields are gathered * \param thread_num: if using OpenMP, thread number * \param lev: level on which particles are located - * \param gather_lev: level from which particles gather fields (lev-1) for + * \param gather_lev: level from which particles gather fields (lev-1) for particles in buffers. */ void @@ -1912,14 +1924,14 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, AMREX_ALWAYS_ASSERT_WITH_MESSAGE((gather_lev==(lev-1)) || (gather_lev==(lev )), "Gather buffers only work for lev-1"); - + // If no particles, do not do anything if (np_to_gather == 0) return; // Get cell size on gather_lev const std::array& dx = WarpX::CellSize(std::max(gather_lev,0)); // Set staggering shift depending on e_is_nodal const Real stagger_shift = e_is_nodal ? 0.0 : 0.5; - + // Get box from which field is gathered. // If not gathering from the finest level, the box is coarsened. Box box; @@ -1929,26 +1941,26 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, const IntVect& ref_ratio = WarpX::RefRatio(gather_lev); box = amrex::coarsen(pti.tilebox(),ref_ratio); } - + // Add guard cells to the box. box.grow(ngE); - + const Array4& ex_arr = exfab->array(); const Array4& ey_arr = eyfab->array(); const Array4& ez_arr = ezfab->array(); const Array4& bx_arr = bxfab->array(); const Array4& by_arr = byfab->array(); const Array4& bz_arr = bzfab->array(); - + const Real * const AMREX_RESTRICT xp = m_xp[thread_num].dataPtr() + offset; const Real * const AMREX_RESTRICT zp = m_zp[thread_num].dataPtr() + offset; const Real * const AMREX_RESTRICT yp = m_yp[thread_num].dataPtr() + offset; - + // Lower corner of tile box physical domain const std::array& xyzmin = WarpX::LowerCorner(box, gather_lev); - + const Dim3 lo = lbound(box); - + // Depending on l_lower_in_v and WarpX::nox, call // different versions of template function doGatherShapeN if (WarpX::l_lower_order_in_v){ @@ -2031,10 +2043,10 @@ void PhysicalParticleContainer::InitIonizationModule () } // Compute ADK prefactors (See Chen, JCP 236 (2013), equation (2)) // For now, we assume l=0 and m=0. - // The approximate expressions are used, + // The approximate expressions are used, // without Gamma function Real wa = std::pow(PhysConst::alpha,3) * PhysConst::c / PhysConst::r_e; - Real Ea = PhysConst::m_e * PhysConst::c*PhysConst::c /PhysConst::q_e * + Real Ea = PhysConst::m_e * PhysConst::c*PhysConst::c /PhysConst::q_e * std::pow(PhysConst::alpha,4)/PhysConst::r_e; Real UH = table_ionization_energies[0]; Real l_eff = std::sqrt(UH/ionization_energies[0]) - 1.; @@ -2049,18 +2061,18 @@ void PhysicalParticleContainer::InitIonizationModule () Real C2 = std::pow(2,2*n_eff)/(n_eff*tgamma(n_eff+l_eff+1)*tgamma(n_eff-l_eff)); adk_power[i] = -(2*n_eff - 1); Real Uion = ionization_energies[i]; - adk_prefactor[i] = dt * wa * C2 * ( Uion/(2*UH) ) + adk_prefactor[i] = dt * wa * C2 * ( Uion/(2*UH) ) * std::pow(2*std::pow((Uion/UH),3./2)*Ea,2*n_eff - 1); adk_exp_prefactor[i] = -2./3 * std::pow( Uion/UH,3./2) * Ea; } } /* \brief create mask of ionized particles (1 if ionized, 0 otherwise) - * + * * \param mfi: tile or grid * \param lev: MR level * \param ionization_mask: Array with as many elements as particles in mfi. - * This function initialized the array, and set each element to 1 or 0 + * This function initialized the array, and set each element to 1 or 0 * depending on whether the particle is ionized or not. */ void @@ -2106,7 +2118,7 @@ PhysicalParticleContainer::buildIonizationMask (const amrex::MFIter& mfi, const // Loop over all particles in grid/tile. If ionized, set mask to 1 // and increment ionization level. - ParallelFor( + ParallelFor( np, [=] AMREX_GPU_DEVICE (long i) { // Get index of ionization_level @@ -2138,3 +2150,23 @@ PhysicalParticleContainer::buildIonizationMask (const amrex::MFIter& mfi, const } ); } + +#ifdef WARPX_QED +// A function to initialize the Tau component according to the QS engine +void PhysicalParticleContainer::InitTauQuantumSync() +{ + BL_PROFILE("PhysicalParticleContainer::InitTauQuantumSync"); +//Looping over all the particles + int num_levels = finestLevel() + 1; + for (int lev=0; lev < num_levels; ++lev) + for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ + auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); + amrex::ParallelFor( + pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + taus[i] = warpx_quantum_sync_engine::get_optical_depth(); + } + ); + } +} +#endif diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 73ac89228..5c71d44a2 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,8 +1,10 @@ CEXE_headers += qed_wrapper_commons.h CEXE_headers += amrex_rng_wrapper.h CEXE_headers += breit_wheeler_engine_wrapper.h +CEXE_headers += quantum_syncs_engine_wrapper.h CEXE_sources += amrex_rng_wrapper.cpp CEXE_sources += breit_wheeler_engine_wrapper.cpp +CEXE_sources += quantum_sync_engine_wrapper.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/QED VPATH_LOCATIONS += $(WARPX_HOME)/Source/QED diff --git a/Source/QED/amrex_rng_wrapper.h b/Source/QED/amrex_rng_wrapper.h index f9818c589..1e6b7c259 100644 --- a/Source/QED/amrex_rng_wrapper.h +++ b/Source/QED/amrex_rng_wrapper.h @@ -1,5 +1,5 @@ #ifndef WARPX_amrex_rng_wrapper_h_ -#define WARPX_rng_wrapper_h_ +#define WARPX_amrex_rng_wrapper_h_ //This file provides a wrapper aroud the RNG //provided by the amrex library @@ -17,4 +17,4 @@ public: amrex::Real exp(amrex::Real l); }; -#endif //amrex_rng_wrapper_hpp_ +#endif //WARPX_amrex_rng_wrapper_h_ diff --git a/Source/QED/breit_wheeler_engine_wrapper.cpp b/Source/QED/breit_wheeler_engine_wrapper.cpp new file mode 100644 index 000000000..acef9026d --- /dev/null +++ b/Source/QED/breit_wheeler_engine_wrapper.cpp @@ -0,0 +1,16 @@ +#include "breit_wheeler_engine_wrapper.h" +//This file provides a wrapper aroud the breit_wheeler engine +//provided by the standard template library + +using namespace picsar::multi_physics; + +warpx_breit_wheeler_engine::warpx_breit_wheeler_engine(): + breit_wheeler_engine(std::move(amrex_rng_wrapper{})) +{}; + +//Interface for the get_optical_depth method of the BW engine +amrex::Real +AMREX_GPU_HOST_DEVICE +warpx_breit_wheeler_engine::get_optical_depth(){ + return internal_get_optical_depth(amrex::Random()); +} -- cgit v1.2.3 From 50f84adbb5d4a9ecbb004f8d19f4741aec979fe5 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 18:00:11 +0200 Subject: Added decorators and removed old unused code --- Source/Particles/PhotonParticleContainer.H | 2 -- Source/Particles/PhotonParticleContainer.cpp | 3 --- Source/QED/amrex_rng_wrapper.cpp | 6 ++++-- Source/QED/amrex_rng_wrapper.h | 6 ++++-- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.H b/Source/Particles/PhotonParticleContainer.H index 85c18dcf6..697f286d7 100644 --- a/Source/Particles/PhotonParticleContainer.H +++ b/Source/Particles/PhotonParticleContainer.H @@ -67,8 +67,6 @@ public: private: - amrex::Real size_in_inches = 1.; - #ifdef WARPX_QED // A flag to enable breit_wheeler process for photons bool do_qed_breit_wheeler = false; diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 1da8cace2..7025d658c 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -27,9 +27,6 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie // where is the name of your species ParmParse pp(species_name); - // read .size_in_inches in the input file, and - // store it into member data. - pp.query("size_in_inches", size_in_inches); #ifdef WARPX_QED //IF do_qed is enabled, find out if Breit Wheeler process is enabled diff --git a/Source/QED/amrex_rng_wrapper.cpp b/Source/QED/amrex_rng_wrapper.cpp index 955144c4c..936e82e80 100644 --- a/Source/QED/amrex_rng_wrapper.cpp +++ b/Source/QED/amrex_rng_wrapper.cpp @@ -5,13 +5,15 @@ //RNG wrapper BW engine //Get rnd number uniformly distributed in [a,b) -amrex::Real amrex_rng_wrapper::unf(amrex::Real a, amrex::Real b) +amrex::Real AMREX_GPU_HOST_DEVICE +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 AMREX_GPU_HOST_DEVICE +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 index 1e6b7c259..fbaf27d68 100644 --- a/Source/QED/amrex_rng_wrapper.h +++ b/Source/QED/amrex_rng_wrapper.h @@ -11,10 +11,12 @@ class amrex_rng_wrapper { public: //Get rnd number uniformly distributed in [a,b) - amrex::Real unf(amrex::Real a, amrex::Real b); + amrex::Real AMREX_GPU_HOST_DEVICE + unf(amrex::Real a, amrex::Real b); //Get rnd number with exponential distribution - amrex::Real exp(amrex::Real l); + amrex::Real AMREX_GPU_HOST_DEVICE + exp(amrex::Real l); }; #endif //WARPX_amrex_rng_wrapper_h_ -- cgit v1.2.3 From 2e29e6b2f791f56898cd3ba3f4c351913f9db3c0 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 12 Sep 2019 13:24:19 -0700 Subject: remove outdated comment --- Source/Particles/PhotonParticleContainer.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 4d11b9bae..f2eb147de 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -23,8 +23,6 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie : PhysicalParticleContainer(amr_core, ispecies, name) { - // This will read .[...] from the inputs file - // where is the name of your species ParmParse pp(species_name); #ifdef WARPX_QED -- cgit v1.2.3 From aa7a4b1f456e6c3a960791a75ac4731b74e41b18 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 16 Sep 2019 10:52:34 +0200 Subject: Added test for unphysical QED processes in PhotonParticleContainer.cpp --- Source/Particles/PhotonParticleContainer.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 71202c7fd..fb6064349 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -29,6 +29,14 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie //IF do_qed is enabled, find out if Breit Wheeler process is enabled if(do_qed) pp.query("do_qed_breit_wheeler", do_qed_breit_wheeler); + + //Check for processes which do not make sense for photons + bool test_quantum_sync; + pp.query("do_qed_quantum_sync", test_quantum_sync); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + test_quantum_sync == 0, + "ERROR: do_qed_quantum_sync can be 1 for species NOT listed in particles.photon_species only!"); + //_________________________________________________________ #endif } -- cgit v1.2.3 From 7f178a55df4d0973f6788d9c27fd10b128ad4571 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 8 Oct 2019 18:25:10 +0200 Subject: Heavy refactoring --- Source/Particles/MultiParticleContainer.H | 21 +++++++----- Source/Particles/MultiParticleContainer.cpp | 22 +++++++++++++ Source/Particles/PhotonParticleContainer.H | 4 --- Source/Particles/PhotonParticleContainer.cpp | 5 ++- Source/Particles/PhysicalParticleContainer.H | 25 ++++++++++++++- Source/Particles/PhysicalParticleContainer.cpp | 34 ++++++++++++++++++-- Source/Particles/WarpXParticleContainer.H | 15 ++++++++- Source/QED/BreitWheelerEngineWrapper.cpp | 28 ++++++++++++++++ Source/QED/BreitWheelerEngineWrapper.h | 44 ++++++++++++++++++++++++++ Source/QED/Make.package | 12 +++---- Source/QED/QedWrapperCommons.h | 16 ++++++++++ Source/QED/QuantumSyncEngineWrapper.cpp | 29 +++++++++++++++++ Source/QED/QuantumSyncEngineWrapper.h | 44 ++++++++++++++++++++++++++ Source/QED/amrex_rng_wrapper.cpp | 20 ------------ Source/QED/amrex_rng_wrapper.h | 22 ------------- Source/QED/breit_wheeler_engine_wrapper.cpp | 16 ---------- Source/QED/breit_wheeler_engine_wrapper.h | 27 ---------------- Source/QED/qed_wrapper_commons.h | 13 -------- Source/QED/quantum_sync_engine_wrapper.cpp | 16 ---------- Source/QED/quantum_sync_engine_wrapper.h | 27 ---------------- 20 files changed, 275 insertions(+), 165 deletions(-) create mode 100644 Source/QED/BreitWheelerEngineWrapper.cpp create mode 100644 Source/QED/BreitWheelerEngineWrapper.h create mode 100644 Source/QED/QedWrapperCommons.h create mode 100644 Source/QED/QuantumSyncEngineWrapper.cpp create mode 100644 Source/QED/QuantumSyncEngineWrapper.h delete mode 100644 Source/QED/amrex_rng_wrapper.cpp delete mode 100644 Source/QED/amrex_rng_wrapper.h delete mode 100644 Source/QED/breit_wheeler_engine_wrapper.cpp delete mode 100644 Source/QED/breit_wheeler_engine_wrapper.h delete mode 100644 Source/QED/qed_wrapper_commons.h delete mode 100644 Source/QED/quantum_sync_engine_wrapper.cpp delete mode 100644 Source/QED/quantum_sync_engine_wrapper.h (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 8869e4d4a..6bf53d6ec 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -23,8 +23,8 @@ // #ifdef WARPX_QED - #include "breit_wheeler_engine_wrapper.h" - #include "quantum_sync_engine_wrapper.h" + #include "BreitWheelerEngineWrapper.h" + #include "QuantumSyncEngineWrapper.h" #endif class MultiParticleContainer @@ -196,12 +196,6 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } - -#ifdef WARPX_QED - warpx_breit_wheeler_engine bw_engine; - warpx_quantum_sync_engine qs_engine; -#endif - protected: // Particle container types @@ -219,6 +213,17 @@ protected: std::vector species_types; +#ifdef WARPX_QED + // The QED engines + BreitWheelerEngine bw_engine; + QuantumSynchrotronEngine qs_engine; + //_______________________________ + + //Initialize QED engines and provides smart pointers + //to species who need QED processes + void InitQED (); +#endif + private: // physical particles (+ laser) diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 715c97b99..a5632dede 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -149,6 +150,11 @@ 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 + InitQED(); +#endif + } @@ -726,3 +732,19 @@ MultiParticleContainer::doFieldIonization () } // lev } // pc_source } + +#ifdef WARPX_QED +void MultiParticleContainer::InitQED () +{ + for (auto& pc : allcontainers) { + if(pc->has_quantum_sync()){ + pc->set_quantum_sync_engine_ptr + (std::make_shared(qs_engine)); + } + if(pc->has_breit_wheeler()){ + pc->set_breit_wheeler_engine_ptr + (std::make_shared(bw_engine)); + } + } +} +#endif diff --git a/Source/Particles/PhotonParticleContainer.H b/Source/Particles/PhotonParticleContainer.H index 98e8e0aab..bda539419 100644 --- a/Source/Particles/PhotonParticleContainer.H +++ b/Source/Particles/PhotonParticleContainer.H @@ -68,13 +68,9 @@ public: private: #ifdef WARPX_QED - // A flag to enable breit_wheeler process for photons - bool do_qed_breit_wheeler = false; - // A function to initialize the Tau component according to the BW engine void InitTauBreitWheeler(); #endif - }; #endif // #ifndef WARPX_PhotonParticleContainer_H_ diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index a8a51723e..9ed2e10e6 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -128,6 +128,9 @@ PhotonParticleContainer::Evolve (int lev, void PhotonParticleContainer::InitTauBreitWheeler() { BL_PROFILE("PhotonParticleContainer::InitOpticalDepth"); + //Get functor + auto get_opt = shr_ptr_bw_engine->build_optical_depth_functor(); + //Looping over all the particles int num_levels = finestLevel() + 1; for (int lev=0; lev < num_levels; ++lev) @@ -136,7 +139,7 @@ void PhotonParticleContainer::InitTauBreitWheeler() amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { - taus[i] = warpx_breit_wheeler_engine::get_optical_depth(); + taus[i] = get_opt(); } ); } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 79685c08b..4fa621514 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -9,6 +9,11 @@ #include +#ifdef WARPX_QED +#include +#include +#endif + class PhysicalParticleContainer : public WarpXParticleContainer { @@ -180,6 +185,16 @@ public: amrex::FArrayBox const * & ezfab, amrex::FArrayBox const * & bxfab, amrex::FArrayBox const * & byfab, amrex::FArrayBox const * & bzfab); +#ifdef WARPX_QED + bool has_quantum_sync() override; + bool has_breit_wheeler() override; + + void set_breit_wheeler_engine_ptr + (std::shared_ptr) override; + void set_quantum_sync_engine_ptr + (std::shared_ptr) override; +#endif + protected: std::string species_name; @@ -194,13 +209,21 @@ protected: // Inject particles during the whole simulation void ContinuousInjection (const amrex::RealBox& injection_box) override; -private: #ifdef WARPX_QED // A flag to enable quantum_synchrotron process for leptons bool do_qed_quantum_sync = false; + // A flag to enable breit_wheeler process [photons only!!] + bool do_qed_breit_wheeler = false; + // A function to initialize the Tau component according to the QS engine void InitTauQuantumSync(); + + // A smart pointer to an instance of a Quantum Synchrotron engine + std::shared_ptr shr_ptr_qs_engine; + + // A smart pointer to an instance of a Breit Wheeler engine [photons only!] + std::shared_ptr shr_ptr_bw_engine; #endif }; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 9e12eb26e..ac5b98dae 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1,6 +1,8 @@ #include #include +#include + #include #include #include @@ -2110,11 +2112,39 @@ PhysicalParticleContainer::buildIonizationMask (const amrex::MFIter& mfi, const } #ifdef WARPX_QED + +bool PhysicalParticleContainer::has_quantum_sync() +{ + return do_qed_quantum_sync; +} + +bool PhysicalParticleContainer::has_breit_wheeler() +{ + return do_qed_breit_wheeler; +} + +void +PhysicalParticleContainer:: +set_breit_wheeler_engine_ptr(std::shared_ptr ptr) +{ + shr_ptr_bw_engine = ptr; +} + +void +PhysicalParticleContainer:: +set_quantum_sync_engine_ptr(std::shared_ptr ptr) +{ + shr_ptr_qs_engine = ptr; +} + // A function to initialize the Tau component according to the QS engine void PhysicalParticleContainer::InitTauQuantumSync() { BL_PROFILE("PhysicalParticleContainer::InitTauQuantumSync"); -//Looping over all the particles + //Get functor + auto get_opt = shr_ptr_qs_engine->build_optical_depth_functor(); + + //Looping over all the particles int num_levels = finestLevel() + 1; for (int lev=0; lev < num_levels; ++lev) for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ @@ -2122,7 +2152,7 @@ void PhysicalParticleContainer::InitTauQuantumSync() amrex::ParallelFor( pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { - taus[i] = warpx_quantum_sync_engine::get_optical_depth(); + taus[i] = get_opt(); } ); } diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 4b36b12f6..3f327c969 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -1,12 +1,17 @@ #ifndef WARPX_WarpXParticleContainer_H_ #define WARPX_WarpXParticleContainer_H_ +#include + #include "WarpXDtType.H" #include #include -#include +#ifdef WARPX_QED +#include +#include +#endif enum struct ConvertDirection{WarpX_to_SI, SI_to_WarpX}; @@ -315,6 +320,14 @@ protected: #ifdef WARPX_QED bool do_qed = false; + + virtual bool has_quantum_sync(){return false;}; + virtual bool has_breit_wheeler(){return false;}; + + virtual void + set_breit_wheeler_engine_ptr(std::shared_ptr){}; + virtual void + set_quantum_sync_engine_ptr(std::shared_ptr){}; #endif amrex::Vector local_rho; diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp new file mode 100644 index 000000000..b654cc9b0 --- /dev/null +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -0,0 +1,28 @@ +#include "BreitWheelerEngineWrapper.h" +//This file provides a wrapper aroud the breit_wheeler engine +//provided by the PICSAR library + +using namespace picsar::multi_physics; + +// Functors ================================== + +// Initialization of the optical depth +AMREX_GPU_DEVICE +amrex::Real +BreitWheelerGetOpticalDepth::operator() () const +{ + return WarpXBreitWheelerWrapper:: + internal_get_optical_depth(amrex::Random()); +} +//____________________________________________ + +// Factory class ============================= + +BreitWheelerEngine::BreitWheelerEngine(){} + +BreitWheelerGetOpticalDepth BreitWheelerEngine::build_optical_depth_functor() +{ + return BreitWheelerGetOpticalDepth(); +} + +//============================================ diff --git a/Source/QED/BreitWheelerEngineWrapper.h b/Source/QED/BreitWheelerEngineWrapper.h new file mode 100644 index 000000000..6aacf4f4e --- /dev/null +++ b/Source/QED/BreitWheelerEngineWrapper.h @@ -0,0 +1,44 @@ +#ifndef WARPX_breit_wheeler_engine_wrapper_h_ +#define WARPX_breit_wheeler_engine_wrapper_h_ + +//This file provides a wrapper aroud the breit_wheeler engine +//provided by the QED modules of the PICSAR library + +#include "QedWrapperCommons.h" + +//BW ENGINE from PICSAR +#include "breit_wheeler_engine.hpp" + +using WarpXBreitWheelerWrapper = + picsar::multi_physics::breit_wheeler_engine; + +// Functors ================================== + +// These functors provide the core elementary functions of the library +// Can be included in GPU kernels + +// Initialization of the optical depth +class BreitWheelerGetOpticalDepth +{ +public: + BreitWheelerGetOpticalDepth() + {}; + + AMREX_GPU_DEVICE + amrex::Real operator() () const; +}; +//____________________________________________ + +// Factory class ============================= +class BreitWheelerEngine +{ +public: + BreitWheelerEngine(); + + //Builds the functor to initialize the optical depth + BreitWheelerGetOpticalDepth build_optical_depth_functor(); +}; + +//============================================ + +#endif //WARPX_breit_wheeler_engine_wrapper_H_ diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 5c71d44a2..7af5860ee 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,10 +1,8 @@ -CEXE_headers += qed_wrapper_commons.h -CEXE_headers += amrex_rng_wrapper.h -CEXE_headers += breit_wheeler_engine_wrapper.h -CEXE_headers += quantum_syncs_engine_wrapper.h -CEXE_sources += amrex_rng_wrapper.cpp -CEXE_sources += breit_wheeler_engine_wrapper.cpp -CEXE_sources += quantum_sync_engine_wrapper.cpp +CEXE_headers += QedWrapperCommons.h +CEXE_headers += BreitWheelerEngineWrapper.h +CEXE_headers += QuantumSyncsEngineWrapper.h +CEXE_sources += BreitWheelerEngineWrapper.cpp +CEXE_sources += QuantumSyncEngineWrapper.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/QED VPATH_LOCATIONS += $(WARPX_HOME)/Source/QED diff --git a/Source/QED/QedWrapperCommons.h b/Source/QED/QedWrapperCommons.h new file mode 100644 index 000000000..821034c06 --- /dev/null +++ b/Source/QED/QedWrapperCommons.h @@ -0,0 +1,16 @@ +#ifndef WARPX_amrex_qed_wrapper_commons_h_ +#define WARPX_amrex_qed_wrapper_commons_h_ + +//Common definitions for the QED library wrappers + +#include + +//Sets the decorator for GPU +#define PXRMP_GPU AMREX_GPU_DEVICE +//Sets SI units in the library +#define PXRMP_WITH_SI_UNITS + +//An empty data type +struct DummyStruct{}; + +#endif //WARPX_amrex_qed_wrapper_commons_h_ diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp new file mode 100644 index 000000000..ce130bb62 --- /dev/null +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -0,0 +1,29 @@ +#include "QuantumSyncEngineWrapper.h" +//This file provides a wrapper aroud the quantum_sync engine +//provided by the PICSAR library + +using namespace picsar::multi_physics; + +// Functors ================================== + +// Initialization of the optical depth + +AMREX_GPU_DEVICE +amrex::Real +QuantumSynchrotronGetOpticalDepth::operator() () const +{ + return WarpXQuantumSynchrotronWrapper:: + internal_get_optical_depth(amrex::Random()); +} +//____________________________________________ + +// Factory class ============================= + +QuantumSynchrotronEngine::QuantumSynchrotronEngine(){} + +QuantumSynchrotronGetOpticalDepth QuantumSynchrotronEngine::build_optical_depth_functor() +{ + return QuantumSynchrotronGetOpticalDepth(); +} + +//============================================ diff --git a/Source/QED/QuantumSyncEngineWrapper.h b/Source/QED/QuantumSyncEngineWrapper.h new file mode 100644 index 000000000..0cb444c07 --- /dev/null +++ b/Source/QED/QuantumSyncEngineWrapper.h @@ -0,0 +1,44 @@ +#ifndef WARPX_quantum_sync_engine_wrapper_h_ +#define WARPX_quantum_sync_engine_wrapper_h_ + +//This file provides a wrapper aroud the breit_wheeler engine +//provided by the QED modules of the PICSAR library + +#include "QedWrapperCommons.h" + +//QS ENGINE from PICSAR +#include "quantum_sync_engine.hpp" + +using WarpXQuantumSynchrotronWrapper = + picsar::multi_physics::quantum_synchrotron_engine; + +// Functors ================================== + +// These functors provide the core elementary functions of the library +// Can be included in GPU kernels + +// Initialization of the optical depth +class QuantumSynchrotronGetOpticalDepth +{ +public: + QuantumSynchrotronGetOpticalDepth() + {}; + + AMREX_GPU_DEVICE + amrex::Real operator() () const; +}; +//____________________________________________ + +// Factory class ============================= +class QuantumSynchrotronEngine +{ +public: + QuantumSynchrotronEngine(); + + //Builds the functor to initialize the optical depth + QuantumSynchrotronGetOpticalDepth build_optical_depth_functor(); +}; + +//============================================ + +#endif //WARPX_quantum_sync_engine_wrapper_h_ diff --git a/Source/QED/amrex_rng_wrapper.cpp b/Source/QED/amrex_rng_wrapper.cpp deleted file mode 100644 index 10fe02c1d..000000000 --- a/Source/QED/amrex_rng_wrapper.cpp +++ /dev/null @@ -1,20 +0,0 @@ -//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_GPU_DEVICE -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_GPU_DEVICE -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 deleted file mode 100644 index e846cb44f..000000000 --- a/Source/QED/amrex_rng_wrapper.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef WARPX_amrex_rng_wrapper_h_ -#define WARPX_amrex_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 AMREX_GPU_DEVICE - unf(amrex::Real a, amrex::Real b); - - //Get rnd number with exponential distribution - amrex::Real AMREX_GPU_DEVICE - exp(amrex::Real l); -}; - -#endif //WARPX_amrex_rng_wrapper_h_ diff --git a/Source/QED/breit_wheeler_engine_wrapper.cpp b/Source/QED/breit_wheeler_engine_wrapper.cpp deleted file mode 100644 index 846c76099..000000000 --- a/Source/QED/breit_wheeler_engine_wrapper.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "breit_wheeler_engine_wrapper.h" -//This file provides a wrapper aroud the breit_wheeler engine -//provided by the standard template library - -using namespace picsar::multi_physics; - -warpx_breit_wheeler_engine::warpx_breit_wheeler_engine(): - breit_wheeler_engine(std::move(amrex_rng_wrapper{})) -{}; - -//Interface for the get_optical_depth method of the BW engine -amrex::Real -AMREX_GPU_DEVICE -warpx_breit_wheeler_engine::get_optical_depth(){ - return internal_get_optical_depth(amrex::Random()); -} diff --git a/Source/QED/breit_wheeler_engine_wrapper.h b/Source/QED/breit_wheeler_engine_wrapper.h deleted file mode 100644 index 390717b09..000000000 --- a/Source/QED/breit_wheeler_engine_wrapper.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WARPX_breit_wheeler_engine_wrapper_h_ -#define WARPX_breit_wheeler_engine_wrapper_h_ - -//This file provides a wrapper aroud the breit_wheeler engine -//provided by the QED modules of the PICSAR library - -//BW ENGINE -#include "qed_wrapper_commons.h" -#include "breit_wheeler_engine.hpp" - -#include "amrex_rng_wrapper.h" - -class warpx_breit_wheeler_engine : - public picsar::multi_physics:: - breit_wheeler_engine -{ -public: - warpx_breit_wheeler_engine(); - - //Interface for the get_optical_depth method of the BW engine - static AMREX_GPU_DEVICE - amrex::Real get_optical_depth(); -}; - -//___________________________________________ - -#endif //WARPX_breit_wheeler_engine_wrapper_H_ diff --git a/Source/QED/qed_wrapper_commons.h b/Source/QED/qed_wrapper_commons.h deleted file mode 100644 index 49f82ad5b..000000000 --- a/Source/QED/qed_wrapper_commons.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef WARPX_amrex_qed_wrapper_commons_h_ -#define WARPX_amrex_qed_wrapper_commons_h_ - -//Common definitions for the QED library wrappers - -#include - -//Sets the decorator for GPU -#define PXRMP_GPU AMREX_GPU_DEVICE -//Sets SI units in the library -#define PXRMP_WITH_SI_UNITS - -#endif diff --git a/Source/QED/quantum_sync_engine_wrapper.cpp b/Source/QED/quantum_sync_engine_wrapper.cpp deleted file mode 100644 index c41cd4b61..000000000 --- a/Source/QED/quantum_sync_engine_wrapper.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "quantum_sync_engine_wrapper.h" -//This file provides a wrapper aroud the quantum_sync engine -//provided by the standard template library - -using namespace picsar::multi_physics; - -warpx_quantum_sync_engine::warpx_quantum_sync_engine(): - quantum_synchrotron_engine(std::move(amrex_rng_wrapper{})) -{}; - -//Interface for the get_optical_depth method of the QS engine -amrex::Real -AMREX_GPU_DEVICE -warpx_quantum_sync_engine::get_optical_depth(){ - return internal_get_optical_depth(amrex::Random()); -} diff --git a/Source/QED/quantum_sync_engine_wrapper.h b/Source/QED/quantum_sync_engine_wrapper.h deleted file mode 100644 index 0af2c2189..000000000 --- a/Source/QED/quantum_sync_engine_wrapper.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef WARPX_quantum_sync_engine_wrapper_h_ -#define WARPX_quantum_sync_engine_wrapper_h_ - -//This file provides a wrapper aroud the breit_wheeler engine -//provided by the QED modules of the PICSAR library - -//BW ENGINE -#include "qed_wrapper_commons.h" -#include "quantum_sync_engine.hpp" - -#include "amrex_rng_wrapper.h" - -class warpx_quantum_sync_engine : - public picsar::multi_physics:: - quantum_synchrotron_engine -{ -public: - warpx_quantum_sync_engine(); - - //Interface for the get_optical_depth method of the BW engine - static AMREX_GPU_DEVICE - amrex::Real get_optical_depth(); -}; - -//___________________________________________ - -#endif //WARPX_quantum_sync_engine_wrapper_h_ -- cgit v1.2.3 From 7df331a7c81899600240aab5954b8950d01ba4f5 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 11 Oct 2019 15:00:57 +0200 Subject: Moved tau initialization in AddPlasma for both photons and physical particles --- Source/Particles/PhotonParticleContainer.H | 7 --- Source/Particles/PhotonParticleContainer.cpp | 28 ------------ Source/Particles/PhysicalParticleContainer.H | 3 -- Source/Particles/PhysicalParticleContainer.cpp | 59 +++++++++++++++----------- 4 files changed, 34 insertions(+), 63 deletions(-) (limited to 'Source/Particles/PhotonParticleContainer.cpp') diff --git a/Source/Particles/PhotonParticleContainer.H b/Source/Particles/PhotonParticleContainer.H index 7c0da9331..407cf26f3 100644 --- a/Source/Particles/PhotonParticleContainer.H +++ b/Source/Particles/PhotonParticleContainer.H @@ -73,13 +73,6 @@ public: int lev, int depos_lev, amrex::Real dt) override {}; - -private: - -#ifdef WARPX_QED - // A function to initialize the Tau component according to the BW engine - void InitTauBreitWheeler(); -#endif }; #endif // #ifndef WARPX_PhotonParticleContainer_H_ diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 9ed2e10e6..3c70a957f 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -45,11 +45,6 @@ void PhotonParticleContainer::InitData() { AddParticles(0); // Note - add on level 0 -#ifdef WARPX_QED - if(do_qed_breit_wheeler) - InitTauBreitWheeler(); -#endif - if (maxLevel() > 0) { Redistribute(); // We then redistribute } @@ -122,26 +117,3 @@ PhotonParticleContainer::Evolve (int lev, t, dt); } - -#ifdef WARPX_QED -// A function to initialize the Tau component according to the BW engine -void PhotonParticleContainer::InitTauBreitWheeler() -{ - BL_PROFILE("PhotonParticleContainer::InitOpticalDepth"); - //Get functor - auto get_opt = shr_ptr_bw_engine->build_optical_depth_functor(); - - //Looping over all the particles - int num_levels = finestLevel() + 1; - for (int lev=0; lev < num_levels; ++lev) - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ - auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); - amrex::ParallelFor( - pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - taus[i] = get_opt(); - } - ); - } -} -#endif diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index ff98d1de9..84f46de5c 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -216,9 +216,6 @@ protected: // A flag to enable breit_wheeler process [photons only!!] bool do_qed_breit_wheeler = false; - // A function to initialize the Tau component according to the QS engine - void InitTauQuantumSync(); - // A smart pointer to an instance of a Quantum Synchrotron engine std::shared_ptr shr_ptr_qs_engine; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 3d3d3ff74..357fb1f68 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -124,11 +124,6 @@ void PhysicalParticleContainer::InitData() AddParticles(0); // Note - add on level 0 -#ifdef WARPX_QED - if(do_qed_quantum_sync) - InitTauQuantumSync(); -#endif - Redistribute(); // We then redistribute } @@ -513,6 +508,30 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) pi = soa.GetIntData(particle_icomps["ionization_level"]).data() + old_size; } +#ifdef WARPX_QED + //Pointer to the optical depth component + amrex::Real* p_tau; + + //If a QED effect is enabled, tau has to be initialized + bool loc_has_quantum_sync = has_quantum_sync(); + bool loc_has_breit_wheeler = has_breit_wheeler(); + if(loc_has_quantum_sync || loc_has_breit_wheeler){ + p_tau = soa.GetRealData(particle_comps["tau"]).data() + old_size; + } + + //If needed, get the appropriate functors from the engines + QuantumSynchrotronGetOpticalDepth quantum_sync_get_opt; + BreitWheelerGetOpticalDepth breit_wheeler_get_opt; + if(loc_has_quantum_sync){ + quantum_sync_get_opt = + shr_ptr_qs_engine->build_optical_depth_functor(); + } + if(loc_has_breit_wheeler){ + breit_wheeler_get_opt = + shr_ptr_bw_engine->build_optical_depth_functor(); + } +#endif + const GpuArray overlap_corner {AMREX_D_DECL(overlap_realbox.lo(0), overlap_realbox.lo(1), @@ -660,6 +679,16 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) pi[ip] = loc_ionization_initial_level; } +#ifdef WARPX_QED + if(loc_has_quantum_sync){ + p_tau[ip] = quantum_sync_get_opt(); + } + + if(loc_has_breit_wheeler){ + p_tau[ip] = breit_wheeler_get_opt(); + } +#endif + u.x *= PhysConst::c; u.y *= PhysConst::c; u.z *= PhysConst::c; @@ -2136,24 +2165,4 @@ set_quantum_sync_engine_ptr(std::shared_ptr ptr) { shr_ptr_qs_engine = ptr; } - -// A function to initialize the Tau component according to the QS engine -void PhysicalParticleContainer::InitTauQuantumSync() -{ - BL_PROFILE("PhysicalParticleContainer::InitTauQuantumSync"); - //Get functor - auto get_opt = shr_ptr_qs_engine->build_optical_depth_functor(); - //Looping over all the particles - int num_levels = finestLevel() + 1; - for (int lev=0; lev < num_levels; ++lev) - for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti){ - auto taus = pti.GetAttribs(particle_comps["tau"]).dataPtr(); - amrex::ParallelFor( - pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - taus[i] = get_opt(); - } - ); - } -} #endif -- cgit v1.2.3