From 8943396e2775221899a628ed876066f776651e22 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 12:13:51 +0200 Subject: Fixed issue with tau output --- Source/Particles/MultiParticleContainer.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index e8125588d..74e59867e 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -17,7 +17,6 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) { - ReadParameters(); allcontainers.resize(nspecies + nlasers); -- 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/MultiParticleContainer.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 864a36568ae872d10133cbc6735452bdcc493fe6 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 14:39:59 +0200 Subject: Reverted style change --- Source/Particles/MultiParticleContainer.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index e65c0d600..84a05d5ed 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -490,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 @@ -498,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); @@ -610,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(); @@ -657,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); @@ -680,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; } @@ -694,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(); @@ -716,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); -- cgit v1.2.3 From 46c213ff20dbb777da79bea6553cd0419b4b3284 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 12 Sep 2019 17:35:00 +0200 Subject: Removed old code --- Source/Particles/MultiParticleContainer.H | 8 +++--- Source/Particles/MultiParticleContainer.cpp | 41 ++++++----------------------- 2 files changed, 12 insertions(+), 37 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index acf1be4c3..e377351bd 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -93,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 @@ -130,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 (); @@ -138,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 (); @@ -221,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/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 84a05d5ed..83c7dc127 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -137,31 +137,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 } @@ -490,7 +465,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 @@ -498,8 +473,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); @@ -610,7 +585,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(); @@ -657,7 +632,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); @@ -680,7 +655,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; } @@ -694,7 +669,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(); @@ -716,7 +691,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); -- cgit v1.2.3 From bfbb36bae052eac7b47d4a002ab67358539ba422 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 13 Sep 2019 10:05:44 +0200 Subject: Applied style changes --- Source/Particles/MultiParticleContainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 9c9bdcec4..53ce0fbbc 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -106,7 +106,7 @@ MultiParticleContainer::ReadParameters () 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(), + 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; -- 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/MultiParticleContainer.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 9e871a93cb18c3080751cf2982ed12b361022f05 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 11 Oct 2019 09:20:45 -0700 Subject: Fix order of includes in MultiParticleContainer.cpp --- Source/Particles/MultiParticleContainer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index a5632dede..c860d21f5 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -1,12 +1,12 @@ +#include +#include +#include + #include #include #include #include -#include -#include -#include - using namespace amrex; MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) -- cgit v1.2.3