From 10eb71343fbe101c2db5ea02605769946339c9e0 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Mon, 30 Sep 2019 09:51:36 -0700 Subject: first commit: move particle creation routine in a new file --- Source/Particles/MultiParticleContainer.cpp | 138 +--------------------------- 1 file changed, 1 insertion(+), 137 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 715c97b99..e3f0155e6 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -522,142 +522,6 @@ MultiParticleContainer::getSpeciesID (std::string product_str) namespace { - // For particle i in mfi, if is_ionized[i]=1, copy particle - // particle i from container pc_source into pc_product - void createIonizedParticles ( - int lev, const MFIter& mfi, - std::unique_ptr< WarpXParticleContainer>& pc_source, - std::unique_ptr< WarpXParticleContainer>& pc_product, - amrex::Gpu::ManagedDeviceVector& is_ionized) - { - BL_PROFILE("createIonizedParticles"); - - const int * const AMREX_RESTRICT p_is_ionized = is_ionized.dataPtr(); - - const int grid_id = mfi.index(); - const int tile_id = mfi.LocalTileIndex(); - - // Get source particle data - auto& ptile_source = pc_source->GetParticles(lev)[std::make_pair(grid_id,tile_id)]; - const int np_source = ptile_source.GetArrayOfStructs().size(); - if (np_source == 0) return; - // --- source AoS particle data - WarpXParticleContainer::ParticleType* particles_source = ptile_source.GetArrayOfStructs()().data(); - // --- source SoA particle data - auto& soa_source = ptile_source.GetStructOfArrays(); - GpuArray attribs_source; - for (int ia = 0; ia < PIdx::nattribs; ++ia) { - attribs_source[ia] = soa_source.GetRealData(ia).data(); - } - // --- source runtime attribs - GpuArray runtime_uold_source; - // Prepare arrays for boosted frame diagnostics. - runtime_uold_source[0] = soa_source.GetRealData(PIdx::ux).data(); - runtime_uold_source[1] = soa_source.GetRealData(PIdx::uy).data(); - runtime_uold_source[2] = soa_source.GetRealData(PIdx::uz).data(); - - // Indices of product particle for each ionized source particle. - // i_product[i]-1 is the location in product tile of product particle - // from source particle i. - amrex::Gpu::ManagedDeviceVector i_product; - i_product.resize(np_source); - // 0GetParticles(lev)[std::make_pair(grid_id,tile_id)]; - // old and new (i.e., including ionized particles) number of particles - // for product species - const int np_product_old = ptile_product.GetArrayOfStructs().size(); - const int np_product_new = np_product_old + np_ionized; - // Allocate extra space in product species for ionized particles. - ptile_product.resize(np_product_new); - // --- product AoS particle data - // First element is the first newly-created product particle - WarpXParticleContainer::ParticleType* particles_product = ptile_product.GetArrayOfStructs()().data() + np_product_old; - // --- product SoA particle data - auto& soa_product = ptile_product.GetStructOfArrays(); - GpuArray attribs_product; - for (int ia = 0; ia < PIdx::nattribs; ++ia) { - // First element is the first newly-created product particle - attribs_product[ia] = soa_product.GetRealData(ia).data() + np_product_old; - } - // --- product runtime attribs - GpuArray runtime_attribs_product; - bool do_boosted_product = WarpX::do_boosted_frame_diagnostic - && pc_product->DoBoostedFrameDiags(); - if (do_boosted_product) { - std::map comps_product = pc_product->getParticleComps(); - runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; - runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; - runtime_attribs_product[2] = soa_product.GetRealData(comps_product[ "zold"]).data() + np_product_old; - runtime_attribs_product[3] = soa_product.GetRealData(comps_product["uxold"]).data() + np_product_old; - runtime_attribs_product[4] = soa_product.GetRealData(comps_product["uyold"]).data() + np_product_old; - runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; - } - - int pid_product; -#pragma omp critical (doFieldIonization_nextid) - { - // ID of first newly-created product particle - pid_product = pc_product->NextID(); - // Update NextID to include particles created in this function - pc_product->setNextID(pid_product+np_ionized); - } - const int cpuid = ParallelDescriptor::MyProc(); - - // Loop over all source particles. If is_ionized, copy particle data - // to corresponding product particle. - amrex::For( - np_source, [=] AMREX_GPU_DEVICE (int is) noexcept - { - if(p_is_ionized[is]){ - // offset of 1 due to inclusive scan - int ip = p_i_product[is]-1; - // is: index of ionized particle in source species - // ip: index of corresponding new particle in product species - WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; - WarpXParticleContainer::ParticleType& p_source = particles_source[is]; - // Copy particle from source to product: AoS - p_product.id() = pid_product + ip; - p_product.cpu() = cpuid; - p_product.pos(0) = p_source.pos(0); - p_product.pos(1) = p_source.pos(1); -#if (AMREX_SPACEDIM == 3) - p_product.pos(2) = p_source.pos(2); -#endif - // Copy particle from source to product: SoA - for (int ia = 0; ia < PIdx::nattribs; ++ia) { - 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 - // current properties (xold = x etc.). - if (do_boosted_product) { - runtime_attribs_product[0][ip] = p_source.pos(0); - runtime_attribs_product[1][ip] = p_source.pos(1); - runtime_attribs_product[2][ip] = p_source.pos(2); - runtime_attribs_product[3][ip] = runtime_uold_source[0][ip]; - runtime_attribs_product[4][ip] = runtime_uold_source[1][ip]; - runtime_attribs_product[5][ip] = runtime_uold_source[2][ip]; - } - } - } - ); - } } void @@ -721,7 +585,7 @@ MultiParticleContainer::doFieldIonization () amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); // Create particles in pc_product - createIonizedParticles(lev, mfi, pc_source, pc_product, is_ionized); + createParticles(lev, mfi, pc_source, pc_product, is_ionized); } } // lev } // pc_source -- cgit v1.2.3 From ce06037bdfa6a13e11b54dd905d90a3a58d81e69 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Mon, 30 Sep 2019 14:31:25 -0700 Subject: pass functor to createParticles --- Source/Particles/MultiParticleContainer.H | 4 +++- Source/Particles/MultiParticleContainer.cpp | 3 ++- Source/Particles/ParticleCreation/CreateParticles.cpp | 14 +++++++++++++- Source/Particles/ParticleCreation/Make.package | 1 + 4 files changed, 19 insertions(+), 3 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index a4107b93f..c90a30950 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -1,6 +1,7 @@ #ifndef WARPX_ParticleContainer_H_ #define WARPX_ParticleContainer_H_ +#include "IonizationEvent.H" #include #include #include @@ -195,7 +196,8 @@ public: int lev, const amrex::MFIter& mfi, std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, - amrex::Gpu::ManagedDeviceVector& is_flagged); + amrex::Gpu::ManagedDeviceVector& is_flagged, + copyAndTransformParticle copy_and_transform_functor); protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index e3f0155e6..0969dba04 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -584,8 +584,9 @@ MultiParticleContainer::doFieldIonization () // 0 if not ionized, 1 if ionized. amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); + copyAndTransformParticle copy_and_transform_functor; // Create particles in pc_product - createParticles(lev, mfi, pc_source, pc_product, is_ionized); + createParticles(lev, mfi, pc_source, pc_product, is_ionized, copy_and_transform_functor); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/CreateParticles.cpp b/Source/Particles/ParticleCreation/CreateParticles.cpp index 2e90676e9..5f14b6103 100644 --- a/Source/Particles/ParticleCreation/CreateParticles.cpp +++ b/Source/Particles/ParticleCreation/CreateParticles.cpp @@ -1,3 +1,4 @@ +#include "IonizationEvent.H" #include "MultiParticleContainer.H" #include "WarpX.H" @@ -9,7 +10,9 @@ void MultiParticleContainer::createParticles ( int lev, const MFIter& mfi, std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, - amrex::Gpu::ManagedDeviceVector& is_flagged) + amrex::Gpu::ManagedDeviceVector& is_flagged, + copyAndTransformParticle copy_and_transform_functor + ) { BL_PROFILE("createIonizedParticles"); @@ -100,6 +103,8 @@ void MultiParticleContainer::createParticles ( } const int cpuid = ParallelDescriptor::MyProc(); + copy_and_transform_functor(112); + // Loop over all source particles. If is_flagged, copy particle data // to corresponding product particle. amrex::For( @@ -112,6 +117,13 @@ void MultiParticleContainer::createParticles ( // ip: index of corresponding new particle in product species WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; WarpXParticleContainer::ParticleType& p_source = particles_source[is]; + + copy_and_transform_functor( + p_source, + + p_product, + ); + // Copy particle from source to product: AoS p_product.id() = pid_product + ip; p_product.cpu() = cpuid; diff --git a/Source/Particles/ParticleCreation/Make.package b/Source/Particles/ParticleCreation/Make.package index 066771611..9f98cc20f 100644 --- a/Source/Particles/ParticleCreation/Make.package +++ b/Source/Particles/ParticleCreation/Make.package @@ -1,3 +1,4 @@ +CEXE_headers += IonizationEvent.H CEXE_sources += CreateParticles.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Particles/ParticleCreation/ -- cgit v1.2.3 From 956aa9c5a3d28ba2433af2789d7d7d0480e8d638 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Mon, 30 Sep 2019 16:59:59 -0700 Subject: added class particleCreationProcess. Ionization test passes --- Source/Particles/MultiParticleContainer.H | 2 +- Source/Particles/MultiParticleContainer.cpp | 4 +- .../Particles/ParticleCreation/CreateParticles.cpp | 19 ++--- .../Particles/ParticleCreation/IonizationEvent.H | 81 +++++++++++++++++----- 4 files changed, 77 insertions(+), 29 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index c90a30950..56e0a2970 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -197,7 +197,7 @@ public: std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - copyAndTransformParticle copy_and_transform_functor); + particleCreationProcess creation_process); protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 0969dba04..984b7cdc9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -584,9 +584,9 @@ MultiParticleContainer::doFieldIonization () // 0 if not ionized, 1 if ionized. amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); - copyAndTransformParticle copy_and_transform_functor; + particleCreationProcess ionization_process; // Create particles in pc_product - createParticles(lev, mfi, pc_source, pc_product, is_ionized, copy_and_transform_functor); + createParticles(lev, mfi, pc_source, pc_product, is_ionized, ionization_process); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/CreateParticles.cpp b/Source/Particles/ParticleCreation/CreateParticles.cpp index f447164e8..16bd1c261 100644 --- a/Source/Particles/ParticleCreation/CreateParticles.cpp +++ b/Source/Particles/ParticleCreation/CreateParticles.cpp @@ -11,8 +11,7 @@ void MultiParticleContainer::createParticles ( std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - copyAndTransformParticle copy_and_transform_functor - ) + particleCreationProcess creation_process) { BL_PROFILE("createIonizedParticles"); @@ -103,6 +102,13 @@ void MultiParticleContainer::createParticles ( } const int cpuid = ParallelDescriptor::MyProc(); + copyAndTransformParticle copy_and_transform_functor = creation_process.initialize_functor( + cpuid, do_boosted_product, + &runtime_uold_source, + &attribs_source, + &attribs_product, + &runtime_attribs_product); + // Loop over all source particles. If is_flagged, copy particle data // to corresponding product particle. amrex::For( @@ -117,14 +123,9 @@ void MultiParticleContainer::createParticles ( WarpXParticleContainer::ParticleType& p_source = particles_source[is]; copy_and_transform_functor( - is, ip, pid_product, cpuid, do_boosted_product, - runtime_uold_source, + is, ip, pid_product, p_source, - p_product, - attribs_source, - attribs_product, - runtime_attribs_product); - + p_product); } } ); diff --git a/Source/Particles/ParticleCreation/IonizationEvent.H b/Source/Particles/ParticleCreation/IonizationEvent.H index d4cc203ab..f04fe7c39 100644 --- a/Source/Particles/ParticleCreation/IonizationEvent.H +++ b/Source/Particles/ParticleCreation/IonizationEvent.H @@ -5,21 +5,52 @@ class copyAndTransformParticle { + public: - void operator () ( - int is, int ip, int pid_product, int cpuid, int do_boosted_product, - const amrex::GpuArray& runtime_uold_source, - WarpXParticleContainer::ParticleType& p_source, - WarpXParticleContainer::ParticleType& p_product, - const amrex::GpuArray& attribs_source, - const amrex::GpuArray& attribs_product, - const amrex::GpuArray& runtime_attribs_product) const + + int m_cpuid; + bool m_do_boosted_product; + const amrex::GpuArray* m_runtime_uold_source; + const amrex::GpuArray* m_attribs_source; + const amrex::GpuArray* m_attribs_product; + const amrex::GpuArray* m_runtime_attribs_product; + + copyAndTransformParticle( + int cpuid, int do_boosted_product, + const amrex::GpuArray* runtime_uold_source, + const amrex::GpuArray* attribs_source, + const amrex::GpuArray* attribs_product, + const amrex::GpuArray* runtime_attribs_product) + : + m_cpuid(cpuid), + m_do_boosted_product(do_boosted_product), + m_runtime_uold_source(runtime_uold_source), + m_attribs_source(attribs_source), + m_attribs_product(attribs_product), + m_runtime_attribs_product(runtime_attribs_product) + {} +/* + { + m_cpuid = cpuid; + m_do_boosted_product = do_boosted_product; + m_runtime_uold_source = runtime_uold_source; + m_attribs_source = attribs_source; + m_attribs_product = attribs_product; + m_runtime_attribs_product = runtime_attribs_product; + } +*/ + + void operator () (int is, int ip, int pid_product, + WarpXParticleContainer::ParticleType& p_source, + WarpXParticleContainer::ParticleType& p_product + ) const { amrex::Print()<<"is = "<* runtime_uold_source, + const amrex::GpuArray* attribs_source, + const amrex::GpuArray* attribs_product, + const amrex::GpuArray* runtime_attribs_product) const noexcept + { + return copyAndTransformParticle( + cpuid, do_boosted_product, runtime_uold_source, + attribs_source, attribs_product, runtime_attribs_product); + }; +}; + #endif // IONIZATIONEVENT_H_ -- cgit v1.2.3 From 59be563f929717911bdf683ac14509cb6d7ad8c3 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 1 Oct 2019 07:43:57 -0700 Subject: some renaming for clarity --- Source/Particles/MultiParticleContainer.H | 2 +- Source/Particles/MultiParticleContainer.cpp | 2 +- .../Particles/ParticleCreation/CreateParticles.cpp | 4 ++-- Source/Particles/ParticleCreation/IonizationEvent.H | 20 +++++++------------- 4 files changed, 11 insertions(+), 17 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 56e0a2970..b6241d814 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -197,7 +197,7 @@ public: std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - particleCreationProcess creation_process); + elementaryProcess elementary_process); protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 984b7cdc9..bb0af28d0 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -584,7 +584,7 @@ MultiParticleContainer::doFieldIonization () // 0 if not ionized, 1 if ionized. amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); - particleCreationProcess ionization_process; + elementaryProcess ionization_process; // Create particles in pc_product createParticles(lev, mfi, pc_source, pc_product, is_ionized, ionization_process); } diff --git a/Source/Particles/ParticleCreation/CreateParticles.cpp b/Source/Particles/ParticleCreation/CreateParticles.cpp index 16bd1c261..ab58b5331 100644 --- a/Source/Particles/ParticleCreation/CreateParticles.cpp +++ b/Source/Particles/ParticleCreation/CreateParticles.cpp @@ -11,7 +11,7 @@ void MultiParticleContainer::createParticles ( std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - particleCreationProcess creation_process) + elementaryProcess elementary_process) { BL_PROFILE("createIonizedParticles"); @@ -102,7 +102,7 @@ void MultiParticleContainer::createParticles ( } const int cpuid = ParallelDescriptor::MyProc(); - copyAndTransformParticle copy_and_transform_functor = creation_process.initialize_functor( + copyAndTransformParticle copy_and_transform_functor = elementary_process.initialize_functor( cpuid, do_boosted_product, &runtime_uold_source, &attribs_source, diff --git a/Source/Particles/ParticleCreation/IonizationEvent.H b/Source/Particles/ParticleCreation/IonizationEvent.H index f04fe7c39..dd65a9cb7 100644 --- a/Source/Particles/ParticleCreation/IonizationEvent.H +++ b/Source/Particles/ParticleCreation/IonizationEvent.H @@ -3,6 +3,11 @@ #include "WarpXParticleContainer.H" +namespace +{ + +} + class copyAndTransformParticle { @@ -27,18 +32,7 @@ public: m_runtime_uold_source(runtime_uold_source), m_attribs_source(attribs_source), m_attribs_product(attribs_product), - m_runtime_attribs_product(runtime_attribs_product) - {} -/* - { - m_cpuid = cpuid; - m_do_boosted_product = do_boosted_product; - m_runtime_uold_source = runtime_uold_source; - m_attribs_source = attribs_source; - m_attribs_product = attribs_product; - m_runtime_attribs_product = runtime_attribs_product; - } -*/ + m_runtime_attribs_product(runtime_attribs_product) {} void operator () (int is, int ip, int pid_product, WarpXParticleContainer::ParticleType& p_source, @@ -74,7 +68,7 @@ public: } }; -class particleCreationProcess +class elementaryProcess { public: copyAndTransformParticle initialize_functor( -- cgit v1.2.3 From 5be8c34a9569d4a4ca9c6a86a9b65c8494a3cc6e Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 1 Oct 2019 15:16:23 -0700 Subject: one instance of class elementaryProcess per process --- Source/Particles/MultiParticleContainer.H | 8 +- Source/Particles/MultiParticleContainer.cpp | 6 +- .../Particles/ParticleCreation/IonizationEvent.H | 109 --------------------- Source/Particles/ParticleCreation/Make.package | 4 +- 4 files changed, 12 insertions(+), 115 deletions(-) delete mode 100644 Source/Particles/ParticleCreation/IonizationEvent.H (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index b6241d814..ea18f148a 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -1,7 +1,8 @@ #ifndef WARPX_ParticleContainer_H_ #define WARPX_ParticleContainer_H_ -#include "IonizationEvent.H" +#include "ElementaryProcess.H" + #include #include #include @@ -192,13 +193,16 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } + elementaryProcess ionization_process; + +/* void createParticles ( int lev, const amrex::MFIter& mfi, std::unique_ptr< WarpXParticleContainer>& pc_source, std::unique_ptr< WarpXParticleContainer>& pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, elementaryProcess elementary_process); - +*/ protected: // Particle container types diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index bb0af28d0..58f6c5de9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -584,9 +584,11 @@ MultiParticleContainer::doFieldIonization () // 0 if not ionized, 1 if ionized. amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); - elementaryProcess ionization_process; + // elementaryProcess ionization_process; // Create particles in pc_product - createParticles(lev, mfi, pc_source, pc_product, is_ionized, ionization_process); + bool do_boosted_product = WarpX::do_boosted_frame_diagnostic + && pc_product->DoBoostedFrameDiags(); + ionization_process.createParticles(lev, mfi, pc_source, pc_product, is_ionized, do_boosted_product); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/IonizationEvent.H b/Source/Particles/ParticleCreation/IonizationEvent.H deleted file mode 100644 index 12abedcf2..000000000 --- a/Source/Particles/ParticleCreation/IonizationEvent.H +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef IONIZATIONEVENT_H_ -#define IONIZATIONEVENT_H_ - -#include "WarpXParticleContainer.H" - -class copyAndTransformParticle -{ - -public: - - int m_cpuid; - bool m_do_boosted_product; - const amrex::GpuArray m_runtime_uold_source; - const amrex::GpuArray m_attribs_source; - const amrex::GpuArray m_attribs_product; - const amrex::GpuArray m_runtime_attribs_product; - - //AMREX_GPU_HOST_DEVICE - //copyAndTransformParticle() {} - - AMREX_GPU_HOST_DEVICE - copyAndTransformParticle( - int cpuid, int do_boosted_product, - const amrex::GpuArray runtime_uold_source, - const amrex::GpuArray attribs_source, - const amrex::GpuArray attribs_product, - const amrex::GpuArray runtime_attribs_product) - : - m_cpuid(cpuid), - m_do_boosted_product(do_boosted_product), - m_runtime_uold_source(runtime_uold_source), - m_attribs_source(attribs_source), - m_attribs_product(attribs_product), - m_runtime_attribs_product(runtime_attribs_product) {} - - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void operator () (int is, int ip, int pid_product, - WarpXParticleContainer::ParticleType& p_source, - WarpXParticleContainer::ParticleType& p_product) const noexcept - { - this->copyParticle(is, ip, pid_product, p_source, p_product); - this->transformSourceParticle(is, p_source); - this->transformProductParticle(is, p_product); - } - - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void copyParticle(int is, int ip, int pid_product, - WarpXParticleContainer::ParticleType& p_source, - WarpXParticleContainer::ParticleType& p_product) const - { - // amrex::Print()<<"tata is = "< runtime_uold_source, - const amrex::GpuArray attribs_source, - const amrex::GpuArray attribs_product, - const amrex::GpuArray runtime_attribs_product) const noexcept - { - return copyAndTransformParticle( - cpuid, do_boosted_product, runtime_uold_source, - attribs_source, attribs_product, runtime_attribs_product); - }; -}; - -#endif // IONIZATIONEVENT_H_ diff --git a/Source/Particles/ParticleCreation/Make.package b/Source/Particles/ParticleCreation/Make.package index 9f98cc20f..d523a308c 100644 --- a/Source/Particles/ParticleCreation/Make.package +++ b/Source/Particles/ParticleCreation/Make.package @@ -1,5 +1,5 @@ -CEXE_headers += IonizationEvent.H -CEXE_sources += CreateParticles.cpp +CEXE_headers += ElementaryProcess.H +# CEXE_sources += CreateParticles.cpp INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/Particles/ParticleCreation/ VPATH_LOCATIONS += $(WARPX_HOME)/Source/Particles/ParticleCreation/ -- cgit v1.2.3 From 55e3e26344354b99be5aa10c51de3f3e856a30b8 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Thu, 10 Oct 2019 16:00:03 +0200 Subject: WIP to write tables on disk --- Source/Particles/MultiParticleContainer.H | 7 ++++++ Source/Particles/MultiParticleContainer.cpp | 25 ++++++++++++++++++++- Source/QED/BreitWheelerEngineWrapper.cpp | 34 +++++++++++++++++++++++++++++ Source/QED/BreitWheelerEngineWrapper.h | 12 ++++++++-- 4 files changed, 75 insertions(+), 3 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 6bf53d6ec..da2b90cef 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -3,6 +3,7 @@ #define WARPX_ParticleContainer_H_ #include +#include #include #include #include @@ -222,6 +223,12 @@ protected: //Initialize QED engines and provides smart pointers //to species who need QED processes void InitQED (); + + bool someone_has_quantum_sync = false; + bool someone_has_breit_wheeler = false; + + void InitQuantumSync (); + void InitBreitWheeler (); #endif private: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index a5632dede..93176e5e7 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include @@ -740,11 +739,35 @@ void MultiParticleContainer::InitQED () if(pc->has_quantum_sync()){ pc->set_quantum_sync_engine_ptr (std::make_shared(qs_engine)); + someone_has_quantum_sync = true; } if(pc->has_breit_wheeler()){ pc->set_breit_wheeler_engine_ptr (std::make_shared(bw_engine)); + someone_has_breit_wheeler = true; } } + + if(someone_has_quantum_sync) + InitQuantumSync(); + + if(someone_has_breit_wheeler) + InitBreitWheeler(); + +} + +void MultiParticleContainer::InitQuantumSync () +{ + if(ParallelDescriptor::IOProcessor()){ + qs_engine.computes_lookup_tables_default(); + } +} + +void MultiParticleContainer::InitBreitWheeler () +{ + if(ParallelDescriptor::IOProcessor()){ + bw_engine.computes_lookup_tables_default(); + bw_engine.write_lookup_tables("qed_bw_lookup.bin"); + } } #endif diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index 97934589a..36d19838c 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -82,6 +82,40 @@ bool BreitWheelerEngine::are_lookup_tables_initialized () const return lookup_tables_initialized; } + +// Writes lookup tables on disk in 'folder' +// return false if it fails. */ +bool BreitWheelerEngine::write_lookup_tables ( + std::string folder) const +{ + if(!lookup_tables_initialized) + return false; + + auto all_data = make_tuple( + std::ref(innards.ctrl.chi_phot_min), + std::ref(innards.ctrl.chi_phot_tdndt_min), + std::ref(innards.ctrl.chi_phot_tdndt_max), + std::ref(innards.ctrl.chi_phot_tdndt_how_many), + std::ref(innards.ctrl.chi_phot_tpair_min), + std::ref(innards.ctrl.chi_phot_tpair_max), + std::ref(innards.ctrl.chi_phot_tpair_how_many), + std::ref(innards.ctrl.chi_frac_tpair_how_many), + std::ref(innards.TTfunc_coords), + std::ref(innards.TTfunc_data)); + + + + + char* data_dump = new char(buf_size); + + size_t count = 0; + auto copy_and_advance = [&count] (char* source, char*dest, size_t size) { + count += size; + }; + + return true; +} + //Private function which actually computes the lookup tables void BreitWheelerEngine::computes_lookup_tables ( WarpXBreitWheelerWrapperCtrl ctrl) diff --git a/Source/QED/BreitWheelerEngineWrapper.h b/Source/QED/BreitWheelerEngineWrapper.h index aaa94c0ec..a841f48a5 100644 --- a/Source/QED/BreitWheelerEngineWrapper.h +++ b/Source/QED/BreitWheelerEngineWrapper.h @@ -3,6 +3,10 @@ #include "QedWrapperCommons.h" +#include +#include +#include + //BW ENGINE from PICSAR #include "breit_wheeler_engine.hpp" @@ -20,8 +24,8 @@ struct BreitWheelerEngineInnards WarpXBreitWheelerWrapperCtrl ctrl; //Lookup table data - amrex::Gpu::ManagedDeviceVector TTfunc_coords; - amrex::Gpu::ManagedDeviceVector TTfunc_data; + amrex::Gpu::ManagedVector TTfunc_coords; + amrex::Gpu::ManagedVector TTfunc_data; //______ }; @@ -84,6 +88,10 @@ public: /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; + /* \brief Writes lookup tables on disk in 'file' + * return false if it fails. */ + bool write_lookup_tables (std::string file) const; + private: bool lookup_tables_initialized = false; -- cgit v1.2.3 From 85aa9abe9860c018e5db5051a6e805f10ea3b7e4 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 10 Oct 2019 08:36:37 -0700 Subject: solution with derived classes without template --- Source/Particles/MultiParticleContainer.H | 2 +- Source/Particles/MultiParticleContainer.cpp | 2 + .../Particles/ParticleCreation/ElementaryProcess.H | 43 ++-------------- .../ParticleCreation/ElementaryProcess.cpp | 4 +- .../Particles/ParticleCreation/TransformParticle.H | 60 +++++++++++++++++++--- 5 files changed, 64 insertions(+), 47 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 36efed5bc..bf35ec603 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -193,7 +193,7 @@ public: PhysicalParticleContainer& GetPCtmp () { return *pc_tmp; } - elementaryProcess ionization_process; + IonizationProcess ionization_process; protected: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 58f6c5de9..0043a5e8a 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -47,6 +47,7 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) nspecies_boosted_frame_diags += 1; } } + ionization_process = IonizationProcess(); } void @@ -586,6 +587,7 @@ MultiParticleContainer::doFieldIonization () pc_source->buildIonizationMask(mfi, lev, is_ionized); // elementaryProcess ionization_process; // Create particles in pc_product + // ionization_process(IonizationProcess()); bool do_boosted_product = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); ionization_process.createParticles(lev, mfi, pc_source, pc_product, is_ionized, do_boosted_product); diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 966789d44..0bd4acdd2 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -5,48 +5,10 @@ #include "CopyParticle.H" #include "TransformParticle.H" -/* -enum struct elementaryProcessType { Ionization }; -enum struct PType {source, product}; - - namespace transform - { - template < elementaryProcessType ElemT, PType PartT > - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void transformParticle( - int i, - WarpXParticleContainer::ParticleType& particle) - { - amrex::Print()<<"primary template\n"; - } - - template <> - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void transformParticle( - int i, - WarpXParticleContainer::ParticleType& particle) - { - amrex::Print()<<"ionization source template\n"; - } - - template <> - AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - void transformParticle( - int i, - WarpXParticleContainer::ParticleType& particle) - { - amrex::Print()<<"ionization product template\n"; - } - } -*/ - class elementaryProcess { - public: - elementaryProcess() {}; - copyParticle initialize_copy( int cpuid, int do_boosted_product, const amrex::GpuArray runtime_uold_source, @@ -77,4 +39,9 @@ public: copyParticle copy_functor); }; +class IonizationProcess: public elementaryProcess +{ + +}; + #endif // ELEMENTARYPROCESS_H_ diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.cpp b/Source/Particles/ParticleCreation/ElementaryProcess.cpp index 98299d5c8..406911481 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.cpp +++ b/Source/Particles/ParticleCreation/ElementaryProcess.cpp @@ -130,8 +130,8 @@ elementaryProcess::copyAndTransformParticles( WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; WarpXParticleContainer::ParticleType& p_source = particles_source[is]; copy_functor(is, ip, pid_product, p_source, p_product); - transformParticle(is, p_source); - transformParticle(ip, p_product); + transformSourceParticle(is, p_source); + //transformProductParticle(ip, p_product); } } ); diff --git a/Source/Particles/ParticleCreation/TransformParticle.H b/Source/Particles/ParticleCreation/TransformParticle.H index 23ab5b9c5..5d2283b3c 100644 --- a/Source/Particles/ParticleCreation/TransformParticle.H +++ b/Source/Particles/ParticleCreation/TransformParticle.H @@ -3,11 +3,20 @@ #include "WarpXParticleContainer.H" -enum struct PType {source, product}; +enum struct elementaryProcessType { Ionization }; -template < PType PT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle( +void transformSourceParticle( + int i, + WarpXParticleContainer::ParticleType& particle) +{ + amrex::Print()<<"primary template\n"; +} + +/* +template < elementaryProcessType ProcessT > +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void transformProductParticle( int i, WarpXParticleContainer::ParticleType& particle) { @@ -16,7 +25,7 @@ void transformParticle( template <> AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle < PType::source > ( +void transformSourceParticle < elementaryProcessType:Ionization > ( int i, WarpXParticleContainer::ParticleType& particle) { @@ -25,11 +34,50 @@ void transformParticle < PType::source > ( template <> AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle < PType::product > ( +void transformProductParticle < elementaryProcessType:Ionization> ( int i, WarpXParticleContainer::ParticleType& particle) { - amrex::Print()<<"specialized product\n"; + amrex::Print()<<"specialized source\n"; +} +*/ + + + + + + + + + +/* +enum struct PType {source, product}; + +template < elementaryProcess ProcessT, PType PT > +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void transformParticle( + int i, + WarpXParticleContainer::ParticleType& particle) +{ + amrex::Print()<<"primary template\n"; } +template +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void transformParticle < ProcessT, PType::source > ( + int i, + WarpXParticleContainer::ParticleType& particle) +{ + amrex::Print()<<"specialized source\n"; +} + +template +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE +void transformParticle < ProcessT, PType::product > ( + int i, + WarpXParticleContainer::ParticleType& particle) +{ + amrex::Print()<<"specialized product\n"; +} +*/ #endif // TRANSFORMPARTICLE_H_ -- cgit v1.2.3 From decbe1cd6241c2d2b89af816bbd993851a31752a Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 10 Oct 2019 09:50:00 -0700 Subject: add comments --- Source/Particles/MultiParticleContainer.cpp | 4 +- .../Particles/ParticleCreation/ElementaryProcess.H | 54 ++++++++++- .../Particles/ParticleCreation/TransformParticle.H | 103 ++++----------------- 3 files changed, 68 insertions(+), 93 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 0043a5e8a..c9a365292 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -585,11 +585,11 @@ MultiParticleContainer::doFieldIonization () // 0 if not ionized, 1 if ionized. amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); - // elementaryProcess ionization_process; // Create particles in pc_product - // ionization_process(IonizationProcess()); bool do_boosted_product = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); + // Copy source to product particles, and increase ionization + // level of source particle ionization_process.createParticles(lev, mfi, pc_source, pc_product, is_ionized, do_boosted_product); } } // lev diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 9d12714f6..435e31db5 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -5,11 +5,37 @@ #include "CopyParticle.H" #include "TransformParticle.H" +/** + * \brief Base class for particle creation processes + * + * Particles in a source particle container are copied to a product particle + * container if they are flagged. Both source and product particles can be + * modified. + * + * initialize_copy initializes a general copy functor + * createParticles formats the data to prepare for the copy, then + * calls copyAndTransformParticles + * copyAndTransformParticles loops over particles, performs the copy and + * transform source and product particles if needed. + * + * The class is templated on the process type. This gives flexibility + * on source and product particle transformation. + */ template class elementaryProcess { public: - elementaryProcess() {}; + + /** + * \brief initialize and return functor for particle copy + * + * \param cpuid id of MPI rank + * \param do_boosted_product whether to copy old attribs + * \param runtime_uold_source momentum of source particles + * \param attribs_source attribs of source particles + * \param attribs_product attribs of product particles + * \param runtime_attribs_product runtime attribs for product, to store old attribs + */ copyParticle initialize_copy( int cpuid, int do_boosted_product, const amrex::GpuArray runtime_uold_source, @@ -22,8 +48,19 @@ public: attribs_source, attribs_product, runtime_attribs_product); }; - // For particle i in mfi, if is_flagged[i]=1, copy particle - // particle i from container pc_source into pc_product + /** + * \brief create particles in product particle containers + * + * For particle i in mfi, if is_flagged[i]=1, copy particle + * particle i from container pc_source into pc_product + * + * \param lev MR level + * \param mfi MFIter where source particles are located + * \param pc_source source particle container + * \param pc_product product particle container + * \param is_flagged particles for which is_flagged is 1 are copied + * \param do_boosted_product whether to copy old attribs + */ void createParticles ( int lev, const amrex::MFIter& mfi, std::unique_ptr< WarpXParticleContainer>& pc_source, @@ -55,6 +92,7 @@ public: runtime_uold_source[1] = soa_source.GetRealData(PIdx::uy).data(); runtime_uold_source[2] = soa_source.GetRealData(PIdx::uz).data(); + // --- source runtime integer attribs amrex::GpuArray runtime_iattribs_source; std::map icomps_source = pc_source->getParticleiComps(); runtime_iattribs_source[0] = soa_source.GetIntData(icomps_source["ionization_level"]).data(); @@ -109,6 +147,7 @@ public: runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; } + // --- product runtime integer attribs amrex::GpuArray runtime_iattribs_product; std::map icomps_product = pc_product->getParticleiComps(); runtime_iattribs_product[0] = soa_product.GetIntData(icomps_product["ionization_level"]).data() + np_product_old; @@ -123,6 +162,7 @@ public: } const int cpuid = amrex::ParallelDescriptor::MyProc(); + // Create instance of copy functor copyParticle copy_functor = initialize_copy( cpuid, do_boosted_product, runtime_uold_source, @@ -130,12 +170,17 @@ public: attribs_product, runtime_attribs_product); + // Loop over source particles and create product particles copyAndTransformParticles(is_flagged, i_product, np_source, pid_product, particles_product, particles_source, copy_functor, runtime_iattribs_source, runtime_iattribs_product); } - + /** + * \brief Loop over source particles and create product particles + * + * \param is_flagged particles for which is_flagged is 1 are copied + */ void copyAndTransformParticles( amrex::Gpu::ManagedDeviceVector& is_flagged, amrex::Gpu::ManagedDeviceVector& i_product, @@ -169,6 +214,7 @@ public: } }; +// Derived class for ionization process class IonizationProcess: public elementaryProcess {}; diff --git a/Source/Particles/ParticleCreation/TransformParticle.H b/Source/Particles/ParticleCreation/TransformParticle.H index 5d173599c..0601a5f63 100644 --- a/Source/Particles/ParticleCreation/TransformParticle.H +++ b/Source/Particles/ParticleCreation/TransformParticle.H @@ -5,26 +5,33 @@ enum struct elementaryProcessType { Ionization }; +/** + * \brief small modifications on source particle + * \param i index of particle + * \param particle particle struct + * \param runtime_iattribs integer attribs + */ template < elementaryProcessType ProcessT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformSourceParticle( int i, WarpXParticleContainer::ParticleType& particle, - amrex::GpuArray runtime_iattribs_source) -{ - amrex::Print()<<"primary template\n"; -} - + amrex::GpuArray runtime_iattribs) {} + +/** + * \brief small modifications on product particle + * \param i index of particle + * \param particle particle struct + * \param runtime_iattribs integer attribs + */ template < elementaryProcessType ProcessT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformProductParticle( int i, WarpXParticleContainer::ParticleType& particle, - amrex::GpuArray runtime_iattribs_product) -{ - amrex::Print()<<"primary template\n"; -} + amrex::GpuArray runtime_iattribs) {} +// For ionization, increase ionization level of source particle template <> AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformSourceParticle < elementaryProcessType::Ionization > ( @@ -34,84 +41,6 @@ void transformSourceParticle < elementaryProcessType::Ionization > ( { // increment particle's ionization level runtime_iattribs_source[0][i] += 1; - amrex::Print()<<"specialized source\n"; -} - -template <> -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformProductParticle < elementaryProcessType::Ionization > ( - int i, - WarpXParticleContainer::ParticleType& particle, - amrex::GpuArray runtime_iattribs_product) -{ - amrex::Print()<<"specialized source\n"; -} - -/* -template < elementaryProcessType ProcessT > -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformProductParticle( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"primary template\n"; -} - -template <> -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformSourceParticle < elementaryProcessType:Ionization > ( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"specialized source\n"; } -template <> -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformProductParticle < elementaryProcessType:Ionization> ( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"specialized source\n"; -} -*/ - - - - - - - - - -/* -enum struct PType {source, product}; - -template < elementaryProcess ProcessT, PType PT > -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"primary template\n"; -} - -template -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle < ProcessT, PType::source > ( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"specialized source\n"; -} - -template -AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE -void transformParticle < ProcessT, PType::product > ( - int i, - WarpXParticleContainer::ParticleType& particle) -{ - amrex::Print()<<"specialized product\n"; -} -*/ #endif // TRANSFORMPARTICLE_H_ -- cgit v1.2.3 From 8e989a7d1e1b7602ad12ffd30bc4cd2ef8306cd7 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 10 Oct 2019 12:43:13 -0700 Subject: add multiple product species. Does not compile --- Source/Particles/MultiParticleContainer.cpp | 12 +- Source/Particles/ParticleCreation/CopyParticle.H | 15 +- .../Particles/ParticleCreation/ElementaryProcess.H | 152 ++++++++++++--------- .../Particles/ParticleCreation/TransformParticle.H | 6 +- 4 files changed, 110 insertions(+), 75 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index c9a365292..36f16bd33 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -586,11 +586,19 @@ MultiParticleContainer::doFieldIonization () amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); // Create particles in pc_product - bool do_boosted_product = WarpX::do_boosted_frame_diagnostic + bool do_boost = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); + const amrex::Vector v_do_boosted_product{do_boost}; + //amrex::Vector> v_pc_product{pc_product}; + // amrex::Vector v_pc_product = GetVecOfPtrs(pc_product); + const amrex::Vector v_pc_product {pc_product.get()}; + // v_pc_Prpod; + //v_pc_product.resize(1); + //v_pc_product[0] = pc_product; // Copy source to product particles, and increase ionization // level of source particle - ionization_process.createParticles(lev, mfi, pc_source, pc_product, is_ionized, do_boosted_product); + ionization_process.createParticles(lev, mfi, pc_source, v_pc_product, + is_ionized, v_do_boosted_product); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/CopyParticle.H b/Source/Particles/ParticleCreation/CopyParticle.H index 78c1350fb..422d96921 100644 --- a/Source/Particles/ParticleCreation/CopyParticle.H +++ b/Source/Particles/ParticleCreation/CopyParticle.H @@ -10,14 +10,14 @@ public: int m_cpuid; bool m_do_boosted_product; - const amrex::GpuArray m_runtime_uold_source; - const amrex::GpuArray m_attribs_source; - const amrex::GpuArray m_attribs_product; - const amrex::GpuArray m_runtime_attribs_product; + amrex::GpuArray m_runtime_uold_source; + amrex::GpuArray m_attribs_source; + amrex::GpuArray m_attribs_product; + amrex::GpuArray m_runtime_attribs_product; AMREX_GPU_HOST_DEVICE copyParticle( - int cpuid, int do_boosted_product, + const int cpuid, const int do_boosted_product, const amrex::GpuArray runtime_uold_source, const amrex::GpuArray attribs_source, const amrex::GpuArray attribs_product, @@ -31,9 +31,12 @@ public: m_runtime_attribs_product(runtime_attribs_product){} AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE + //void operator () (int is, int ip, int pid_product, + // WarpXParticleContainer::ParticleType& p_source, + // WarpXParticleContainer::ParticleType& p_product) const noexcept void operator () (int is, int ip, int pid_product, WarpXParticleContainer::ParticleType& p_source, - WarpXParticleContainer::ParticleType& p_product) const noexcept + WarpXParticleContainer::ParticleType& p_product) { // Copy particle from source to product: AoS p_product.id() = pid_product + ip; diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 6af7ff933..37f8a0a6d 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -37,7 +37,7 @@ public: * \param runtime_attribs_product runtime attribs for product, to store old attribs */ copyParticle initialize_copy( - int cpuid, int do_boosted_product, + const int cpuid, const int do_boosted_product, const amrex::GpuArray runtime_uold_source, const amrex::GpuArray attribs_source, const amrex::GpuArray attribs_product, @@ -64,9 +64,9 @@ public: void createParticles ( int lev, const amrex::MFIter& mfi, std::unique_ptr< WarpXParticleContainer>& pc_source, - std::unique_ptr< WarpXParticleContainer>& pc_product, + amrex::Vector v_pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - bool do_boosted_product) + const amrex::Vector v_do_boosted_product) { BL_PROFILE("createIonizedParticles"); @@ -97,6 +97,12 @@ public: std::map icomps_source = pc_source->getParticleiComps(); runtime_iattribs_source[0] = soa_source.GetIntData(icomps_source["ionization_level"]).data(); + int nproducts = v_pc_product.size(); + AMREX_ALWAYS_ASSERT_WITH_MESSAGE( + v_do_boosted_product.size() == nproducts, + "v_pc_product and v_do_boosted_product must have the same size."); + + // Indices of product particle for each ionized source particle. // i_product[i]-1 is the location in product tile of product particle // from source particle i. @@ -117,63 +123,73 @@ public: int np_ionized = i_product[np_source-1]; if (np_ionized == 0) return; - // Get product particle data - auto& ptile_product = pc_product->GetParticles(lev)[std::make_pair(grid_id,tile_id)]; - // old and new (i.e., including ionized particles) number of particles - // for product species - const int np_product_old = ptile_product.GetArrayOfStructs().size(); - const int np_product_new = np_product_old + np_ionized; - // Allocate extra space in product species for ionized particles. - ptile_product.resize(np_product_new); - // --- product AoS particle data - // First element is the first newly-created product particle - WarpXParticleContainer::ParticleType* particles_product = ptile_product.GetArrayOfStructs()().data() + np_product_old; - // --- product SoA particle data - auto& soa_product = ptile_product.GetStructOfArrays(); - amrex::GpuArray attribs_product; - for (int ia = 0; ia < PIdx::nattribs; ++ia) { + amrex::Vector v_copy_functor(nproducts); + amrex::Vector v_pid_product(nproducts); + amrex::Vector v_particles_product(nproducts); + amrex::Vector> v_runtime_iattribs_product(nproducts); + for (int iproduct=0; iproductGetParticles(lev)[std::make_pair(grid_id,tile_id)]; + // old and new (i.e., including ionized particles) number of particles + // for product species + const int np_product_old = ptile_product.GetArrayOfStructs().size(); + const int np_product_new = np_product_old + np_ionized; + // Allocate extra space in product species for ionized particles. + ptile_product.resize(np_product_new); + // --- product AoS particle data // First element is the first newly-created product particle - attribs_product[ia] = soa_product.GetRealData(ia).data() + np_product_old; - } - // --- product runtime attribs - amrex::GpuArray runtime_attribs_product; - if (do_boosted_product) { - std::map comps_product = pc_product->getParticleComps(); - runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; - runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; - runtime_attribs_product[2] = soa_product.GetRealData(comps_product[ "zold"]).data() + np_product_old; - runtime_attribs_product[3] = soa_product.GetRealData(comps_product["uxold"]).data() + np_product_old; - runtime_attribs_product[4] = soa_product.GetRealData(comps_product["uyold"]).data() + np_product_old; - runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; - } - - // --- product runtime integer attribs - amrex::GpuArray runtime_iattribs_product; - std::map icomps_product = pc_product->getParticleiComps(); - runtime_iattribs_product[0] = soa_product.GetIntData(icomps_product["ionization_level"]).data() + np_product_old; - - int pid_product; + v_particles_product[iproduct] = ptile_product.GetArrayOfStructs()().data() + np_product_old; + // --- product SoA particle data + auto& soa_product = ptile_product.GetStructOfArrays(); + amrex::GpuArray attribs_product; + for (int ia = 0; ia < PIdx::nattribs; ++ia) { + // First element is the first newly-created product particle + attribs_product[ia] = soa_product.GetRealData(ia).data() + np_product_old; + } + // --- product runtime attribs + amrex::GpuArray runtime_attribs_product; + int do_boost = v_do_boosted_product[iproduct]; + if (do_boost) { + std::map comps_product = pc_product->getParticleComps(); + runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; + runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; + runtime_attribs_product[2] = soa_product.GetRealData(comps_product[ "zold"]).data() + np_product_old; + runtime_attribs_product[3] = soa_product.GetRealData(comps_product["uxold"]).data() + np_product_old; + runtime_attribs_product[4] = soa_product.GetRealData(comps_product["uyold"]).data() + np_product_old; + runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; + } + + // --- product runtime integer attribs + amrex::GpuArray& runtime_iattribs_product = v_runtime_iattribs_product[iproduct]; + std::map icomps_product = pc_product->getParticleiComps(); + runtime_iattribs_product[0] = soa_product.GetIntData(icomps_product["ionization_level"]).data() + np_product_old; + + int pid_product; #pragma omp critical (doFieldIonization_nextid) - { - // ID of first newly-created product particle - pid_product = pc_product->NextID(); - // Update NextID to include particles created in this function - pc_product->setNextID(pid_product+np_ionized); + { + // ID of first newly-created product particle + pid_product = pc_product->NextID(); + // Update NextID to include particles created in this function + pc_product->setNextID(pid_product+np_ionized); + } + const int cpuid = amrex::ParallelDescriptor::MyProc(); + + // Create instance of copy functor + copyParticle copy_functor = initialize_copy( + cpuid, v_do_boosted_product[iproduct], + runtime_uold_source, + attribs_source, + attribs_product, + runtime_attribs_product); + v_copy_functor[iproduct] = copy_functor; + v_pid_product[iproduct] = pid_product; } - const int cpuid = amrex::ParallelDescriptor::MyProc(); - - // Create instance of copy functor - copyParticle copy_functor = initialize_copy( - cpuid, do_boosted_product, - runtime_uold_source, - attribs_source, - attribs_product, - runtime_attribs_product); // Loop over source particles and create product particles - copyAndTransformParticles(is_flagged, i_product, np_source, pid_product, - particles_product, particles_source, copy_functor, - runtime_iattribs_source, runtime_iattribs_product); + copyAndTransformParticles(is_flagged, i_product, np_source, v_pid_product, + v_particles_product, particles_source, v_copy_functor, + runtime_iattribs_source, v_runtime_iattribs_product); } /** @@ -184,12 +200,13 @@ public: void copyAndTransformParticles( amrex::Gpu::ManagedDeviceVector& is_flagged, amrex::Gpu::ManagedDeviceVector& i_product, - int np_source, int pid_product, - WarpXParticleContainer::ParticleType* particles_product, + int np_source, + const amrex::Vector v_pid_product, + const amrex::Vector v_particles_product, WarpXParticleContainer::ParticleType* particles_source, - copyParticle copy_functor, + const amrex::Vector v_copy_functor, amrex::GpuArray runtime_iattribs_source, - amrex::GpuArray runtime_iattribs_product) + amrex::Vector> v_runtime_iattribs_product) { int const * const AMREX_RESTRICT p_is_flagged = is_flagged.dataPtr(); int const * const AMREX_RESTRICT p_i_product = i_product.dataPtr(); @@ -199,15 +216,22 @@ public: np_source, [=] AMREX_GPU_DEVICE (int is) noexcept { if(p_is_flagged[is]){ + int nproducts = v_particles_product.size(); // offset of 1 due to inclusive scan int ip = p_i_product[is]-1; - // is: index of ionized particle in source species - // ip: index of corresponding new particle in product species - WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; WarpXParticleContainer::ParticleType& p_source = particles_source[is]; - copy_functor(is, ip, pid_product, p_source, p_product); + for (int iproduct=0; iproduct(is, p_source, runtime_iattribs_source); - transformProductParticle(ip, p_product, runtime_iattribs_product); + transformProductParticle(ip, v_particles_product, v_runtime_iattribs_product); } } ); diff --git a/Source/Particles/ParticleCreation/TransformParticle.H b/Source/Particles/ParticleCreation/TransformParticle.H index e562ca07e..c414ca56f 100644 --- a/Source/Particles/ParticleCreation/TransformParticle.H +++ b/Source/Particles/ParticleCreation/TransformParticle.H @@ -16,7 +16,7 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformSourceParticle( int i, WarpXParticleContainer::ParticleType& particle, - amrex::GpuArray runtime_iattribs) {} + amrex::GpuArray runtime_iattribs){} /** * \brief small modifications on product particle @@ -28,8 +28,8 @@ template < elementaryProcessType ProcessT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformProductParticle( int i, - WarpXParticleContainer::ParticleType& particle, - amrex::GpuArray runtime_iattribs) {} + amrex::Vector v_particle, + amrex::Vector> v_runtime_iattribs){} // For ionization, increase ionization level of source particle template <> -- cgit v1.2.3 From 2bcf51e137efbd4950649370c474d239718d61b2 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Thu, 10 Oct 2019 14:28:30 -0700 Subject: compiles and gives correct result --- Source/Particles/MultiParticleContainer.cpp | 10 +++---- Source/Particles/ParticleCreation/CopyParticle.H | 13 ++++++--- .../Particles/ParticleCreation/ElementaryProcess.H | 31 ++++++++-------------- .../Particles/ParticleCreation/TransformParticle.H | 3 +-- 4 files changed, 25 insertions(+), 32 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 36f16bd33..5d898c11a 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -586,15 +586,11 @@ MultiParticleContainer::doFieldIonization () amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); // Create particles in pc_product - bool do_boost = WarpX::do_boosted_frame_diagnostic + int do_boost = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); - const amrex::Vector v_do_boosted_product{do_boost}; - //amrex::Vector> v_pc_product{pc_product}; - // amrex::Vector v_pc_product = GetVecOfPtrs(pc_product); + amrex::Vector v_do_boosted_product; + v_do_boosted_product.push_back(do_boost); const amrex::Vector v_pc_product {pc_product.get()}; - // v_pc_Prpod; - //v_pc_product.resize(1); - //v_pc_product[0] = pc_product; // Copy source to product particles, and increase ionization // level of source particle ionization_process.createParticles(lev, mfi, pc_source, v_pc_product, diff --git a/Source/Particles/ParticleCreation/CopyParticle.H b/Source/Particles/ParticleCreation/CopyParticle.H index 422d96921..c42dc5bf6 100644 --- a/Source/Particles/ParticleCreation/CopyParticle.H +++ b/Source/Particles/ParticleCreation/CopyParticle.H @@ -30,10 +30,17 @@ public: m_attribs_product(attribs_product), m_runtime_attribs_product(runtime_attribs_product){} + AMREX_GPU_HOST_DEVICE + copyParticle(const copyParticle& in){ + m_cpuid = in.m_cpuid; + m_do_boosted_product = in.m_do_boosted_product; + m_runtime_uold_source = in.m_runtime_uold_source; + m_attribs_source = in.m_attribs_source; + m_attribs_product = in.m_attribs_product; + m_runtime_attribs_product = in.m_runtime_attribs_product; + } + AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE - //void operator () (int is, int ip, int pid_product, - // WarpXParticleContainer::ParticleType& p_source, - // WarpXParticleContainer::ParticleType& p_product) const noexcept void operator () (int is, int ip, int pid_product, WarpXParticleContainer::ParticleType& p_source, WarpXParticleContainer::ParticleType& p_product) diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 37f8a0a6d..c7909b3a1 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -66,10 +66,9 @@ public: std::unique_ptr< WarpXParticleContainer>& pc_source, amrex::Vector v_pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - const amrex::Vector v_do_boosted_product) + const amrex::Vector v_do_boosted_product) { BL_PROFILE("createIonizedParticles"); - const int grid_id = mfi.index(); const int tile_id = mfi.LocalTileIndex(); @@ -96,7 +95,6 @@ public: amrex::GpuArray runtime_iattribs_source; std::map icomps_source = pc_source->getParticleiComps(); runtime_iattribs_source[0] = soa_source.GetIntData(icomps_source["ionization_level"]).data(); - int nproducts = v_pc_product.size(); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( v_do_boosted_product.size() == nproducts, @@ -123,10 +121,10 @@ public: int np_ionized = i_product[np_source-1]; if (np_ionized == 0) return; - amrex::Vector v_copy_functor(nproducts); + // amrex::Vector v_copy_functor(nproducts); + amrex::Vector v_copy_functor; amrex::Vector v_pid_product(nproducts); amrex::Vector v_particles_product(nproducts); - amrex::Vector> v_runtime_iattribs_product(nproducts); for (int iproduct=0; iproduct runtime_attribs_product; - int do_boost = v_do_boosted_product[iproduct]; + const int do_boost = v_do_boosted_product[iproduct]; if (do_boost) { std::map comps_product = pc_product->getParticleComps(); runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; @@ -161,10 +159,6 @@ public: } // --- product runtime integer attribs - amrex::GpuArray& runtime_iattribs_product = v_runtime_iattribs_product[iproduct]; - std::map icomps_product = pc_product->getParticleiComps(); - runtime_iattribs_product[0] = soa_product.GetIntData(icomps_product["ionization_level"]).data() + np_product_old; - int pid_product; #pragma omp critical (doFieldIonization_nextid) { @@ -176,20 +170,19 @@ public: const int cpuid = amrex::ParallelDescriptor::MyProc(); // Create instance of copy functor - copyParticle copy_functor = initialize_copy( + v_copy_functor.push_back (initialize_copy( cpuid, v_do_boosted_product[iproduct], runtime_uold_source, attribs_source, attribs_product, - runtime_attribs_product); - v_copy_functor[iproduct] = copy_functor; + runtime_attribs_product) ); v_pid_product[iproduct] = pid_product; } // Loop over source particles and create product particles copyAndTransformParticles(is_flagged, i_product, np_source, v_pid_product, v_particles_product, particles_source, v_copy_functor, - runtime_iattribs_source, v_runtime_iattribs_product); + runtime_iattribs_source); } /** @@ -204,9 +197,8 @@ public: const amrex::Vector v_pid_product, const amrex::Vector v_particles_product, WarpXParticleContainer::ParticleType* particles_source, - const amrex::Vector v_copy_functor, - amrex::GpuArray runtime_iattribs_source, - amrex::Vector> v_runtime_iattribs_product) + const amrex::Vector& v_copy_functor, + amrex::GpuArray runtime_iattribs_source) { int const * const AMREX_RESTRICT p_is_flagged = is_flagged.dataPtr(); int const * const AMREX_RESTRICT p_i_product = i_product.dataPtr(); @@ -223,15 +215,14 @@ public: for (int iproduct=0; iproduct(is, p_source, runtime_iattribs_source); - transformProductParticle(ip, v_particles_product, v_runtime_iattribs_product); + transformProductParticle(ip, v_particles_product); } } ); diff --git a/Source/Particles/ParticleCreation/TransformParticle.H b/Source/Particles/ParticleCreation/TransformParticle.H index c414ca56f..090be1f26 100644 --- a/Source/Particles/ParticleCreation/TransformParticle.H +++ b/Source/Particles/ParticleCreation/TransformParticle.H @@ -28,8 +28,7 @@ template < elementaryProcessType ProcessT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformProductParticle( int i, - amrex::Vector v_particle, - amrex::Vector> v_runtime_iattribs){} + amrex::Vector v_particle){} // For ionization, increase ionization level of source particle template <> -- cgit v1.2.3 From 65e76e8b475ab7ebb2f2763cdf9f4bae377314cb Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 11 Oct 2019 17:01:24 +0200 Subject: Style changes --- Source/Particles/MultiParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 93176e5e7..45f79105f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -749,7 +749,7 @@ void MultiParticleContainer::InitQED () } if(someone_has_quantum_sync) - InitQuantumSync(); + InitQuantumSync(); if(someone_has_breit_wheeler) InitBreitWheeler(); @@ -759,7 +759,7 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { if(ParallelDescriptor::IOProcessor()){ - qs_engine.computes_lookup_tables_default(); + qs_engine.computes_lookup_tables_default(); } } -- cgit v1.2.3 From 9528e74bcb855176b82ce3b435a97891f3bb49d4 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 15 Oct 2019 16:24:59 +0200 Subject: Added all the functors and some methods to read/write lookup tables --- Source/Particles/MultiParticleContainer.H | 7 +++ Source/Particles/MultiParticleContainer.cpp | 38 +++++++++++- Source/QED/BreitWheelerEngineWrapper.H | 78 ++++++++++++++++++++++-- Source/QED/BreitWheelerEngineWrapper.cpp | 92 +++++++++++++++++++++++++++- Source/QED/QedWrapperCommons.H | 2 - Source/QED/QuantumSyncEngineWrapper.H | 90 ++++++++++++++++++++++++--- Source/QED/QuantumSyncEngineWrapper.cpp | 94 ++++++++++++++++++++++++++++- 7 files changed, 380 insertions(+), 21 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index a09e0eeae..9e44afdd7 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -19,6 +19,8 @@ #include #include #include +#include +#include // // MultiParticleContainer holds multiple (nspecies or npsecies+1 when @@ -229,6 +231,11 @@ protected: void InitQuantumSync (); void InitBreitWheeler (); + + std::tuple + ParseQuantumSyncParams (); + std::tuple + ParseBreitWheelerParams (); #endif private: diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 7c7f0bfa1..bca2995e9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -758,16 +758,50 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { + bool is_custom; + WarpXQuantumSynchrotronWrapperCtrl ctrl; + std::string filename; + std::tie(is_custom, filename, ctrl) = ParseQuantumSyncParams(); + if(ParallelDescriptor::IOProcessor()){ - qs_engine.computes_lookup_tables_default(); + qs_engine.compute_lookup_tables_default(); + qs_engine.write_lookup_tables("qed_qs_lookup.bin"); } + amrex::ParallelDescriptor::Barrier(); + qs_engine.read_lookup_tables("qed_qs_lookup.bin"); } void MultiParticleContainer::InitBreitWheeler () { + bool is_custom; + WarpXBreitWheelerWrapperCtrl ctrl; + std::string filename; + std::tie(is_custom, filename, ctrl) = ParseBreitWheelerParams(); + if(ParallelDescriptor::IOProcessor()){ - bw_engine.computes_lookup_tables_default(); + bw_engine.compute_lookup_tables_default(); bw_engine.write_lookup_tables("qed_bw_lookup.bin"); } + amrex::ParallelDescriptor::Barrier(); + bw_engine.read_lookup_tables("qed_bw_lookup.bin"); + +} + +std::tuple +MultiParticleContainer::ParseQuantumSyncParams () +{ + WarpXQuantumSynchrotronWrapperCtrl ctrl; + bool is_custom{false}; + + return std::make_tuple(is_custom, std::string(""), ctrl); +} + +std::tuple +MultiParticleContainer::ParseBreitWheelerParams () +{ + WarpXBreitWheelerWrapperCtrl ctrl; + bool is_custom{false}; + + return std::make_tuple(is_custom, std::string(""), ctrl); } #endif diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index 570d359fc..05e70897d 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -3,6 +3,8 @@ #include "QedWrapperCommons.H" +#include + #include #include @@ -25,6 +27,10 @@ struct BreitWheelerEngineInnards //Lookup table data amrex::Gpu::ManagedVector TTfunc_coords; amrex::Gpu::ManagedVector TTfunc_data; + + amrex::Gpu::ManagedVector cum_distrib_coords_1; + amrex::Gpu::ManagedVector cum_distrib_coords_2; + amrex::Gpu::ManagedVector cum_distrib_data; //______ }; @@ -70,9 +76,9 @@ public: amrex::Real bx, amrex::Real by, amrex::Real bz, amrex::Real dt, amrex::Real& opt_depth) const { - bool has_event_happend = false; - amrex::Real dummy_lambda = 1.0; - amrex::Real unused_event_time = 0.0; + bool has_event_happend{false}; + amrex::Real dummy_lambda{1.0}; + amrex::Real unused_event_time{0.0}; const auto table = picsar::multi_physics::lookup_1d (innards->TTfunc_data.size(), @@ -97,6 +103,61 @@ private: BreitWheelerEngineInnards* innards; }; +// Generates an electron-positron pair via the Breit-Wheeler process +// (returns false if errors occur) +class BreitWheelerGeneratePairs +{ +public: + BreitWheelerGeneratePairs( + BreitWheelerEngineInnards* _innards): + innards{_innards}{}; + + template + AMREX_GPU_DEVICE + AMREX_FORCE_INLINE + bool operator()( + amrex::Real px, amrex::Real py, amrex::Real pz, + amrex::Real ex, amrex::Real ey, amrex::Real ez, + amrex::Real bx, amrex::Real by, amrex::Real bz, + amrex::Real weight, + amrex::Real* e_px, amrex::Real* e_py, amrex::Real* e_pz, + amrex::Real* p_px, amrex::Real* p_py, amrex::Real* p_pz, + amrex::Real* e_weight, amrex::Real* p_weight) const + { + amrex::Real dummy_lambda{1.0}; + picsar::multi_physics::picsar_array + rand_zero_one_minus_epsi; + for(auto& el : rand_zero_one_minus_epsi) + el = amrex::Random(); + + const auto table = picsar::multi_physics::lookup_2d + (innards->cum_distrib_coords_1.size(), + innards->cum_distrib_coords_1.data(), + innards->cum_distrib_coords_2.size(), + innards->cum_distrib_coords_2.data(), + innards->cum_distrib_data.data()); + + bool stat = WarpXBreitWheelerWrapper:: + internal_generate_breit_wheeler_pairs( + px, py, pz, + ex, ey, ez, + bx, by, bz, + weight, sampling, + e_px, e_py, e_pz, + p_px, p_py, p_pz, + e_weight, p_weight, + dummy_lambda, + table, + innards->ctrl, + rand_zero_one_minus_epsi.data()); + + return stat; + } + +private: + BreitWheelerEngineInnards* innards; +}; + // Factory class ============================= /** @@ -115,9 +176,15 @@ public: /* \brief Builds the functor to evolve the optical depth */ BreitWheelerEvolveOpticalDepth build_evolve_functor (); + /* \brief Builds the functor to generate the pairs */ + BreitWheelerGeneratePairs build_pair_functor (); + /* \brief Computes the Lookup tables using the default settings * provided by the PICSAR library */ - void computes_lookup_tables_default (); + void compute_lookup_tables_default (); + + /* \brief Computes the Lookup tables using user-defined settings */ + void compute_custom_lookup_tables (WarpXBreitWheelerWrapperCtrl ctrl); /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; @@ -126,6 +193,9 @@ public: * return false if it fails. */ bool write_lookup_tables (std::string file) const; + /* \brief Reads lookup tables from 'file' on disk */ + void read_lookup_tables (std::string file); + private: bool lookup_tables_initialized = false; diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index f5c3acb49..f6925fa9d 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -20,10 +20,17 @@ BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor () return BreitWheelerEvolveOpticalDepth(&innards); } +//Builds the functor to generate the pairs +BreitWheelerGeneratePairs BreitWheelerEngine::build_pair_functor () +{ + AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + + return BreitWheelerGeneratePairs(&innards); +} //Initializes the Lookup tables using the default settings //provided by the library -void BreitWheelerEngine::computes_lookup_tables_default () +void BreitWheelerEngine::compute_lookup_tables_default () { //A control parameters structure //with the default values provided by the library @@ -34,13 +41,20 @@ void BreitWheelerEngine::computes_lookup_tables_default () lookup_tables_initialized = true; } +// Computes the Lookup tables using user-defined settings +void BreitWheelerEngine::compute_custom_lookup_tables ( + WarpXBreitWheelerWrapperCtrl ctrl) +{ + computes_lookup_tables(ctrl); + + lookup_tables_initialized = true; +} + bool BreitWheelerEngine::are_lookup_tables_initialized () const { return lookup_tables_initialized; } - - /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ bool BreitWheelerEngine::write_lookup_tables ( @@ -49,9 +63,81 @@ bool BreitWheelerEngine::write_lookup_tables ( if(!lookup_tables_initialized) return false; + std::ofstream of(file, std::ios::out | std::ios::binary); + + //Header (control parameters) + of.write(reinterpret_cast(&innards.ctrl.chi_phot_min), + sizeof(innards.ctrl.chi_phot_min)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), + sizeof(innards.ctrl.chi_phot_tdndt_min)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), + sizeof(innards.ctrl.chi_phot_tdndt_max)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), + sizeof(innards.ctrl.chi_phot_tdndt_how_many)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), + sizeof(innards.ctrl.chi_phot_tpair_min)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), + sizeof(innards.ctrl.chi_phot_tpair_max)); + of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), + sizeof(innards.ctrl.chi_phot_tpair_how_many)); + of.write(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), + sizeof(innards.ctrl.chi_frac_tpair_how_many)); + //_______ + + //Data + of.write(reinterpret_cast(innards.TTfunc_coords.dataPtr()), + sizeof(amrex::Real)*innards.TTfunc_coords.size()); + of.write(reinterpret_cast(innards.TTfunc_data.dataPtr()), + sizeof(amrex::Real)*innards.TTfunc_data.size()); + // TODO: add other table + //_______ + + of.close(); + return true; } +/* \brief Reads lookup tables from 'file' on disk */ +void BreitWheelerEngine::read_lookup_tables (std::string file) +{ + std::ifstream ifile(file, std::ios::in | std::ios::binary); + + //Header (control parameters) + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_min), + sizeof(innards.ctrl.chi_phot_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), + sizeof(innards.ctrl.chi_phot_tdndt_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), + sizeof(innards.ctrl.chi_phot_tdndt_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), + sizeof(innards.ctrl.chi_phot_tdndt_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), + sizeof(innards.ctrl.chi_phot_tpair_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), + sizeof(innards.ctrl.chi_phot_tpair_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), + sizeof(innards.ctrl.chi_phot_tpair_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), + sizeof(innards.ctrl.chi_frac_tpair_how_many)); + //_______ + + //Data + size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_phot_tdndt_how_many; + char* data_buf = new char(size_buf); + ifile.read(data_buf, size_buf); + innards.TTfunc_coords.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + ifile.read(data_buf, size_buf); + innards.TTfunc_data.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + delete[] data_buf; + //_______ + + ifile.close(); + + lookup_tables_initialized = true; +} + //Private function which actually computes the lookup tables void BreitWheelerEngine::computes_lookup_tables ( WarpXBreitWheelerWrapperCtrl ctrl) diff --git a/Source/QED/QedWrapperCommons.H b/Source/QED/QedWrapperCommons.H index bfaf992bf..7e7b3df3d 100644 --- a/Source/QED/QedWrapperCommons.H +++ b/Source/QED/QedWrapperCommons.H @@ -6,8 +6,6 @@ #include #include -#include - //Sets the decorator for GPU #define PXRMP_GPU AMREX_GPU_DEVICE //Sets SI units in the library diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 2da6d312a..72a652d4d 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -3,6 +3,11 @@ #include "QedWrapperCommons.H" +#include + +#include +#include + //QS ENGINE from PICSAR #include "quantum_sync_engine.hpp" @@ -21,7 +26,11 @@ struct QuantumSynchrotronEngineInnards //Lookup table data amrex::Gpu::ManagedDeviceVector KKfunc_coords; - amrex::Gpu::ManagedDeviceVector KKfunc_data; + amrex::Gpu::ManagedDeviceVector KKfunc_data; + + amrex::Gpu::ManagedVector cum_distrib_coords_1; + amrex::Gpu::ManagedVector cum_distrib_coords_2; + amrex::Gpu::ManagedVector cum_distrib_data; //______ }; @@ -62,14 +71,14 @@ public: AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool operator()( - amrex::Real px, amrex::Real py, amrex::Real pz, + amrex::Real px, amrex::Real py, amrex::Real pz, amrex::Real ex, amrex::Real ey, amrex::Real ez, amrex::Real bx, amrex::Real by, amrex::Real bz, amrex::Real dt, amrex::Real& opt_depth) const { - bool has_event_happend = false; - amrex::Real dummy_lambda = 1.0; - amrex::Real unused_event_time = 0.0; + bool has_event_happend{false}; + amrex::Real dummy_lambda{1.0}; + amrex::Real unused_event_time{0.0}; const auto table = picsar::multi_physics ::lookup_1d( @@ -82,9 +91,9 @@ public: px, py, pz, ex, ey, ez, bx, by, bz, - dt, opt_depth, + dt, opt_depth, has_event_happend, unused_event_time, - dummy_lambda, + dummy_lambda, table, innards->ctrl); @@ -95,6 +104,59 @@ private: QuantumSynchrotronEngineInnards* innards; }; +// Generates a photon via the Quantum Synchrotron process +// and updates momentum accordingly (returns false if errors occur) +class QuantumSynchrotronGeneratePhotonAndUpdateMomentum +{ +public: + QuantumSynchrotronGeneratePhotonAndUpdateMomentum( + QuantumSynchrotronEngineInnards* _innards): + innards{_innards}{}; + + template + AMREX_GPU_DEVICE + AMREX_FORCE_INLINE + bool operator()( + amrex::Real* px, amrex::Real* py, amrex::Real* pz, + amrex::Real ex, amrex::Real ey, amrex::Real ez, + amrex::Real bx, amrex::Real by, amrex::Real bz, + amrex::Real weight, + amrex::Real* g_px, amrex::Real* g_py, amrex::Real* g_pz, + amrex::Real* g_weight) const + { + amrex::Real dummy_lambda{1.0}; + picsar::multi_physics::picsar_array + rand_zero_one_minus_epsi; + for(auto& el : rand_zero_one_minus_epsi) + el = amrex::Random(); + + const auto table = picsar::multi_physics::lookup_2d + (innards->cum_distrib_coords_1.size(), + innards->cum_distrib_coords_1.data(), + innards->cum_distrib_coords_2.size(), + innards->cum_distrib_coords_2.data(), + innards->cum_distrib_data.data()); + + bool stat = WarpXQuantumSynchrotronWrapper:: + internal_generate_photons_and_update_momentum( + *px, *py, *pz, + ex, ey, ez, + bx, by, bz, + weight, sampling, + *g_px, *g_py, *g_pz, + *g_weight, + dummy_lambda, + table, + innards->ctrl, + rand_zero_one_minus_epsi.data()); + + return stat; + } + +private: + QuantumSynchrotronEngineInnards* innards; +}; + // Factory class ============================= /** @@ -113,13 +175,23 @@ public: /* \brief Builds the functor to evolve the optical depth */ QuantumSynchrotronEvolveOpticalDepth build_evolve_functor (); - /* \brief Computes the Lookup tables using the default settings + /* \brief Computes the Lookup tables using the default settings * provided by the PICSAR library */ - void computes_lookup_tables_default (); + void compute_lookup_tables_default (); + + /* \brief Computes the Lookup tables using user-defined settings */ + void compute_custom_lookup_tables (WarpXQuantumSynchrotronWrapperCtrl ctrl); /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; + /* \brief Writes lookup tables on disk in 'file' + * return false if it fails. */ + bool write_lookup_tables (std::string file) const; + + /* \brief Reads lookup tables from 'file' on disk */ + void read_lookup_tables (std::string file); + private: bool lookup_tables_initialized = false; diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index 0fd22b53e..322b5cf82 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -23,7 +23,7 @@ QuantumSynchrotronEvolveOpticalDepth QuantumSynchrotronEngine::build_evolve_func //Initializes the Lookup tables using the default settings //provided by the library -void QuantumSynchrotronEngine::computes_lookup_tables_default () +void QuantumSynchrotronEngine::compute_lookup_tables_default () { //A control parameters structure //with the default values provided by the library @@ -34,11 +34,103 @@ void QuantumSynchrotronEngine::computes_lookup_tables_default () lookup_tables_initialized = true; } +// Computes the Lookup tables using user-defined settings +void QuantumSynchrotronEngine::compute_custom_lookup_tables ( + WarpXQuantumSynchrotronWrapperCtrl ctrl) +{ + computes_lookup_tables(ctrl); + + lookup_tables_initialized = true; +} + bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const { return lookup_tables_initialized; } +/* \brief Writes lookup tables on disk in 'file' + * return false if it fails. */ +bool QuantumSynchrotronEngine::write_lookup_tables ( + std::string file) const +{ + if(!lookup_tables_initialized) + return false; + + std::ofstream of(file, std::ios::out | std::ios::binary); + + //Header (control parameters) + of.write(reinterpret_cast(&innards.ctrl.chi_part_min), + sizeof(innards.ctrl.chi_part_min)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tdndt_min), + sizeof(innards.ctrl.chi_part_tdndt_min)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tdndt_max), + sizeof(innards.ctrl.chi_part_tdndt_max)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tdndt_how_many), + sizeof(innards.ctrl.chi_part_tdndt_how_many)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tem_min), + sizeof(innards.ctrl.chi_part_tem_max)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tem_max), + sizeof(innards.ctrl.chi_part_tem_max)); + of.write(reinterpret_cast(&innards.ctrl.chi_part_tem_how_many), + sizeof(innards.ctrl.chi_part_tem_how_many)); + of.write(reinterpret_cast(&innards.ctrl.prob_tem_how_many), + sizeof(innards.ctrl.prob_tem_how_many)); + //_______ + + //Data + of.write(reinterpret_cast(innards.KKfunc_coords.dataPtr()), + sizeof(amrex::Real)*innards.KKfunc_coords.size()); + of.write(reinterpret_cast(innards.KKfunc_data.dataPtr()), + sizeof(amrex::Real)*innards.KKfunc_data.size()); + // TODO: add other table + //_______ + + of.close(); + + return true; +} + +/* \brief Reads lookup tables from 'file' on disk */ +void QuantumSynchrotronEngine::read_lookup_tables (std::string file) +{ + std::ifstream ifile(file, std::ios::in | std::ios::binary); + + //Header (control parameters) + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_min), + sizeof(innards.ctrl.chi_part_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_min), + sizeof(innards.ctrl.chi_part_tdndt_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_max), + sizeof(innards.ctrl.chi_part_tdndt_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_how_many), + sizeof(innards.ctrl.chi_part_tdndt_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_min), + sizeof(innards.ctrl.chi_part_tem_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_max), + sizeof(innards.ctrl.chi_part_tem_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_how_many), + sizeof(innards.ctrl.chi_part_tem_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.prob_tem_how_many), + sizeof(innards.ctrl.prob_tem_how_many)); + //_______ + + //Data + size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_part_tdndt_how_many; + char* data_buf = new char(size_buf); + ifile.read(data_buf, size_buf); + innards.KKfunc_coords.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + ifile.read(data_buf, size_buf); + innards.KKfunc_data.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + delete[] data_buf; + //_______ + + ifile.close(); + + lookup_tables_initialized = true; +} + //Private function which actually computes the lookup tables void QuantumSynchrotronEngine::computes_lookup_tables ( WarpXQuantumSynchrotronWrapperCtrl ctrl) -- cgit v1.2.3 From cbc49ae2f246d7244de60abfc365bd76be9f1aca Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 18 Oct 2019 12:17:16 +0200 Subject: Code restructuring to isolate boost dependency --- GNUmakefile | 3 +- Source/Make.WarpX | 17 +++-- Source/Particles/MultiParticleContainer.cpp | 20 +++--- Source/QED/BreitWheelerEngineTableBuilder.H | 8 +++ Source/QED/BreitWheelerEngineTableBuilder.cpp | 4 ++ Source/QED/BreitWheelerEngineWrapper.H | 34 ++++++--- Source/QED/BreitWheelerEngineWrapper.cpp | 98 +++++++++++++------------- Source/QED/Make.package | 9 +++ Source/QED/QedWrapperCommons.H | 7 +- Source/QED/QuantumSyncEngineTableBuilder.H | 6 ++ Source/QED/QuantumSyncEngineTableBuilder.cpp | 4 ++ Source/QED/QuantumSyncEngineWrapper.H | 25 ++++--- Source/QED/QuantumSyncEngineWrapper.cpp | 99 ++++++++++++++------------- 13 files changed, 201 insertions(+), 133 deletions(-) create mode 100644 Source/QED/BreitWheelerEngineTableBuilder.H create mode 100644 Source/QED/BreitWheelerEngineTableBuilder.cpp create mode 100644 Source/QED/QuantumSyncEngineTableBuilder.H create mode 100644 Source/QED/QuantumSyncEngineTableBuilder.cpp (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/GNUmakefile b/GNUmakefile index 2fdd7f25b..ef86420f6 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,7 +8,8 @@ DEBUG = FALSE #DIM = 2 DIM = 3 -#QED = TRUE +#QED = TRUE +#QED_TABLE_GEN = TRUE COMP = gcc #COMP = intel diff --git a/Source/Make.WarpX b/Source/Make.WarpX index 54baecbf6..b9fe0a258 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -83,11 +83,6 @@ ifeq ($(USE_SENSEI_INSITU),TRUE) endif ifeq ($(QED),TRUE) - BOOST_ROOT ?= NOT_SET - ifneq ($(BOOST_ROOT),NOT_SET) - VPATH_LOCATIONS += $(BOOST_ROOT) - INCLUDE_LOCATIONS += $(BOOST_ROOT) - endif INCLUDE_LOCATIONS += $(PICSAR_HOME)/src/multi_physics/QED/src CXXFLAGS += -DWARPX_QED CFLAGS += -DWARPX_QED @@ -95,8 +90,20 @@ ifeq ($(QED),TRUE) F90FLAGS += -DWARPX_QED include $(WARPX_HOME)/Source/QED/Make.package USERSuffix := $(USERSuffix).QED + + ifeq ($(QED_TABLE_GEN),TRUE) + BOOST_ROOT ?= NOT_SET + ifneq ($(BOOST_ROOT),NOT_SET) + VPATH_LOCATIONS += $(BOOST_ROOT) + INCLUDE_LOCATIONS += $(BOOST_ROOT) + CXXFLAGS += -DWARPX_QED_TABLE_GEN + CFLAGS += -DWARPX_QED_TABLE_GEN + FFLAGS += -DWARPX_QED_TABLE_GEN + F90FLAGS += -DWARPX_QED_TABLE_GEN + endif endif +endif include $(PICSAR_HOME)/src/Make.package diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index bca2995e9..771943171 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -763,11 +763,11 @@ void MultiParticleContainer::InitQuantumSync () std::string filename; std::tie(is_custom, filename, ctrl) = ParseQuantumSyncParams(); - if(ParallelDescriptor::IOProcessor()){ - qs_engine.compute_lookup_tables_default(); - qs_engine.write_lookup_tables("qed_qs_lookup.bin"); - } - amrex::ParallelDescriptor::Barrier(); + // if(ParallelDescriptor::IOProcessor()){ + // qs_engine.compute_lookup_tables_default(); + // qs_engine.write_lookup_tables("qed_qs_lookup.bin"); + // } + // amrex::ParallelDescriptor::Barrier(); qs_engine.read_lookup_tables("qed_qs_lookup.bin"); } @@ -778,11 +778,11 @@ void MultiParticleContainer::InitBreitWheeler () std::string filename; std::tie(is_custom, filename, ctrl) = ParseBreitWheelerParams(); - if(ParallelDescriptor::IOProcessor()){ - bw_engine.compute_lookup_tables_default(); - bw_engine.write_lookup_tables("qed_bw_lookup.bin"); - } - amrex::ParallelDescriptor::Barrier(); + // if(ParallelDescriptor::IOProcessor()){ + // bw_engine.compute_lookup_tables_default(); + // bw_engine.write_lookup_tables("qed_bw_lookup.bin"); + // } + // amrex::ParallelDescriptor::Barrier(); bw_engine.read_lookup_tables("qed_bw_lookup.bin"); } diff --git a/Source/QED/BreitWheelerEngineTableBuilder.H b/Source/QED/BreitWheelerEngineTableBuilder.H new file mode 100644 index 000000000..bd53ab3cf --- /dev/null +++ b/Source/QED/BreitWheelerEngineTableBuilder.H @@ -0,0 +1,8 @@ +#ifndef WARPX_breit_wheeler_engine_table_builder_h_ +#define WARPX_breit_wheeler_engine_table_builder_h_ + +#include "QedWrapperCommons.H" + +class BreitWheelerEngineTableBuilder{}; + +#endif //WARPX_breit_wheeler_engine_table_builder_h_ diff --git a/Source/QED/BreitWheelerEngineTableBuilder.cpp b/Source/QED/BreitWheelerEngineTableBuilder.cpp new file mode 100644 index 000000000..128f7164d --- /dev/null +++ b/Source/QED/BreitWheelerEngineTableBuilder.cpp @@ -0,0 +1,4 @@ +#include "BreitWheelerEngineTableBuilder.H" + +//Include the full BW engine with table generation support +#include "breit_wheeler_engine.hpp" diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index 72460b52b..a25198741 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -4,16 +4,23 @@ #include "QedWrapperCommons.H" #include +#include +#include #include #include //BW ENGINE from PICSAR +//Include only essential parts of the library in this file #define PXRMP_CORE_ONLY #include "breit_wheeler_engine.hpp" -using WarpXBreitWheelerWrapper = - picsar::multi_physics::breit_wheeler_engine; +#ifdef WARPX_QED_TABLE_GEN + #include "BreitWheelerEngineTableBuilder.H" +#endif + +using WarpXBreitWheelerWrapper = picsar::multi_physics:: + breit_wheeler_engine; using WarpXBreitWheelerWrapperCtrl = picsar::multi_physics::breit_wheeler_engine_ctrl; @@ -180,6 +187,19 @@ public: /* \brief Builds the functor to generate the pairs */ BreitWheelerGeneratePairs build_pair_functor (); + /* \brief Reads lookup tables from 'file' on disk */ + void read_lookup_tables (std::string file); + + /* \brief Checks if lookup tables are properly initialized */ + bool are_lookup_tables_initialized () const; + +private: + bool lookup_tables_initialized = false; + + BreitWheelerEngineInnards innards; + +#ifdef WARPX_QED_TABLE_GEN +public: /* \brief Computes the Lookup tables using the default settings * provided by the PICSAR library */ void compute_lookup_tables_default (); @@ -187,24 +207,18 @@ public: /* \brief Computes the Lookup tables using user-defined settings */ void compute_custom_lookup_tables (WarpXBreitWheelerWrapperCtrl ctrl); - /* \brief Checks if lookup tables are properly initialized */ - bool are_lookup_tables_initialized () const; - /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ bool write_lookup_tables (std::string file) const; - /* \brief Reads lookup tables from 'file' on disk */ - void read_lookup_tables (std::string file); private: - bool lookup_tables_initialized = false; - - BreitWheelerEngineInnards innards; + BreitWheelerEngineTableBuilder table_builder; //Private function which actually computes the lookup tables void computes_lookup_tables ( WarpXBreitWheelerWrapperCtrl ctrl); +#endif }; //============================================ diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index f6925fa9d..13fd4b388 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -28,6 +28,54 @@ BreitWheelerGeneratePairs BreitWheelerEngine::build_pair_functor () return BreitWheelerGeneratePairs(&innards); } +bool BreitWheelerEngine::are_lookup_tables_initialized () const +{ + return lookup_tables_initialized; +} + +/* \brief Reads lookup tables from 'file' on disk */ +void BreitWheelerEngine::read_lookup_tables (std::string file) +{ + std::ifstream ifile(file, std::ios::in | std::ios::binary); + + //Header (control parameters) + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_min), + sizeof(innards.ctrl.chi_phot_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), + sizeof(innards.ctrl.chi_phot_tdndt_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), + sizeof(innards.ctrl.chi_phot_tdndt_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), + sizeof(innards.ctrl.chi_phot_tdndt_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), + sizeof(innards.ctrl.chi_phot_tpair_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), + sizeof(innards.ctrl.chi_phot_tpair_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), + sizeof(innards.ctrl.chi_phot_tpair_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), + sizeof(innards.ctrl.chi_frac_tpair_how_many)); + //_______ + + //Data + size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_phot_tdndt_how_many; + char* data_buf = new char(size_buf); + ifile.read(data_buf, size_buf); + innards.TTfunc_coords.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + ifile.read(data_buf, size_buf); + innards.TTfunc_data.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + delete[] data_buf; + //_______ + + ifile.close(); + + lookup_tables_initialized = true; +} + + +#ifdef WARPX_QED_TABLE_GEN //Initializes the Lookup tables using the default settings //provided by the library void BreitWheelerEngine::compute_lookup_tables_default () @@ -50,10 +98,6 @@ void BreitWheelerEngine::compute_custom_lookup_tables ( lookup_tables_initialized = true; } -bool BreitWheelerEngine::are_lookup_tables_initialized () const -{ - return lookup_tables_initialized; -} /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ @@ -97,53 +141,13 @@ bool BreitWheelerEngine::write_lookup_tables ( return true; } -/* \brief Reads lookup tables from 'file' on disk */ -void BreitWheelerEngine::read_lookup_tables (std::string file) -{ - std::ifstream ifile(file, std::ios::in | std::ios::binary); - - //Header (control parameters) - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_min), - sizeof(innards.ctrl.chi_phot_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), - sizeof(innards.ctrl.chi_phot_tdndt_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), - sizeof(innards.ctrl.chi_phot_tdndt_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), - sizeof(innards.ctrl.chi_phot_tdndt_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), - sizeof(innards.ctrl.chi_phot_tpair_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), - sizeof(innards.ctrl.chi_phot_tpair_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), - sizeof(innards.ctrl.chi_phot_tpair_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), - sizeof(innards.ctrl.chi_frac_tpair_how_many)); - //_______ - - //Data - size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_phot_tdndt_how_many; - char* data_buf = new char(size_buf); - ifile.read(data_buf, size_buf); - innards.TTfunc_coords.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - ifile.read(data_buf, size_buf); - innards.TTfunc_data.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - delete[] data_buf; - //_______ - - ifile.close(); - - lookup_tables_initialized = true; -} - //Private function which actually computes the lookup tables void BreitWheelerEngine::computes_lookup_tables ( WarpXBreitWheelerWrapperCtrl ctrl) { //Lambda is not actually used if S.I. units are enabled - WarpXBreitWheelerWrapper bw_engine(std::move(DummyStruct()), 1.0, ctrl); + WarpXBreitWheelerWrapper bw_engine( + std::move(__DummyStruct()), 1.0, ctrl); bw_engine.compute_dN_dt_lookup_table(); //bw_engine.compute_cumulative_pair_table(); @@ -161,4 +165,6 @@ void BreitWheelerEngine::computes_lookup_tables ( //____ } +#endif + //============================================ diff --git a/Source/QED/Make.package b/Source/QED/Make.package index d4bad3f18..58fc4047c 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -4,5 +4,14 @@ CEXE_headers += QuantumSyncsEngineWrapper.H CEXE_sources += BreitWheelerEngineWrapper.cpp CEXE_sources += QuantumSyncEngineWrapper.cpp +#Table generation is enabled only if QED_TABLE_GEN is +#set to true +ifeq ($(QED_TABLE_GEN),TRUE) + CEXE_headers += BreitWheelerEngineTableBuilder.H + CEXE_headers += QuantumSyncEngineTableBuilder.H + CEXE_sources += BreitWheelerEngineTableBuilder.cpp + CEXE_sources += QuantumSyncEngineTableBuilder.cpp +endif + INCLUDE_LOCATIONS += $(WARPX_HOME)/Source/QED VPATH_LOCATIONS += $(WARPX_HOME)/Source/QED diff --git a/Source/QED/QedWrapperCommons.H b/Source/QED/QedWrapperCommons.H index 7e7b3df3d..3197f271b 100644 --- a/Source/QED/QedWrapperCommons.H +++ b/Source/QED/QedWrapperCommons.H @@ -1,10 +1,9 @@ #ifndef WARPX_amrex_qed_wrapper_commons_h_ #define WARPX_amrex_qed_wrapper_commons_h_ -//Common definitions for the QED library wrappers +//Common definitions for the QED library wrappers and table builders -#include -#include +#include //Sets the decorator for GPU #define PXRMP_GPU AMREX_GPU_DEVICE @@ -12,6 +11,6 @@ #define PXRMP_WITH_SI_UNITS //An empty data type -struct DummyStruct{}; +struct __DummyStruct{}; #endif //WARPX_amrex_qed_wrapper_commons_h_ diff --git a/Source/QED/QuantumSyncEngineTableBuilder.H b/Source/QED/QuantumSyncEngineTableBuilder.H new file mode 100644 index 000000000..f555f9212 --- /dev/null +++ b/Source/QED/QuantumSyncEngineTableBuilder.H @@ -0,0 +1,6 @@ +#ifndef WARPX_quantum_sync_engine_table_builder_h_ +#define WARPX_quantum_sync_engine_table_builder_h_ + +class QuantumSynchrotronEngineTableBuilder{}; + +#endif //WARPX_quantum_sync_engine_table_builder_h_ diff --git a/Source/QED/QuantumSyncEngineTableBuilder.cpp b/Source/QED/QuantumSyncEngineTableBuilder.cpp new file mode 100644 index 000000000..4cd604f67 --- /dev/null +++ b/Source/QED/QuantumSyncEngineTableBuilder.cpp @@ -0,0 +1,4 @@ +#include "QuantumSyncEngineTableBuilder.H" + +//Include the full QS engine with table generation support +#include "quantum_sync_engine.hpp" diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 69870c9a9..2a5a91098 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -176,20 +176,10 @@ public: /* \brief Builds the functor to evolve the optical depth */ QuantumSynchrotronEvolveOpticalDepth build_evolve_functor (); - /* \brief Computes the Lookup tables using the default settings - * provided by the PICSAR library */ - void compute_lookup_tables_default (); - - /* \brief Computes the Lookup tables using user-defined settings */ - void compute_custom_lookup_tables (WarpXQuantumSynchrotronWrapperCtrl ctrl); /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; - /* \brief Writes lookup tables on disk in 'file' - * return false if it fails. */ - bool write_lookup_tables (std::string file) const; - /* \brief Reads lookup tables from 'file' on disk */ void read_lookup_tables (std::string file); @@ -198,9 +188,24 @@ private: QuantumSynchrotronEngineInnards innards; +#ifdef WARPX_QED_TABLE_GEN +public: + /* \brief Computes the Lookup tables using the default settings + * provided by the PICSAR library */ + void compute_lookup_tables_default (); + + /* \brief Computes the Lookup tables using user-defined settings */ + void compute_custom_lookup_tables (WarpXQuantumSynchrotronWrapperCtrl ctrl); + /* \brief Writes lookup tables on disk in 'file' + * return false if it fails. */ + bool write_lookup_tables (std::string file) const; + +private: //Private function which actually computes the lookup tables void computes_lookup_tables ( WarpXQuantumSynchrotronWrapperCtrl ctrl); + +#endif }; //============================================ diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index 322b5cf82..533007843 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -21,6 +21,54 @@ QuantumSynchrotronEvolveOpticalDepth QuantumSynchrotronEngine::build_evolve_func return QuantumSynchrotronEvolveOpticalDepth(&innards); } +bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const +{ + return lookup_tables_initialized; +} + +/* \brief Reads lookup tables from 'file' on disk */ +void QuantumSynchrotronEngine::read_lookup_tables (std::string file) +{ + std::ifstream ifile(file, std::ios::in | std::ios::binary); + + //Header (control parameters) + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_min), + sizeof(innards.ctrl.chi_part_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_min), + sizeof(innards.ctrl.chi_part_tdndt_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_max), + sizeof(innards.ctrl.chi_part_tdndt_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_how_many), + sizeof(innards.ctrl.chi_part_tdndt_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_min), + sizeof(innards.ctrl.chi_part_tem_min)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_max), + sizeof(innards.ctrl.chi_part_tem_max)); + ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_how_many), + sizeof(innards.ctrl.chi_part_tem_how_many)); + ifile.read(reinterpret_cast(&innards.ctrl.prob_tem_how_many), + sizeof(innards.ctrl.prob_tem_how_many)); + //_______ + + //Data + size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_part_tdndt_how_many; + char* data_buf = new char(size_buf); + ifile.read(data_buf, size_buf); + innards.KKfunc_coords.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + ifile.read(data_buf, size_buf); + innards.KKfunc_data.assign((amrex::Real*)data_buf, + (amrex::Real*)data_buf + size_buf); + delete[] data_buf; + //_______ + + ifile.close(); + + lookup_tables_initialized = true; +} + +#ifdef WARPX_QED_TABLE_GEN + //Initializes the Lookup tables using the default settings //provided by the library void QuantumSynchrotronEngine::compute_lookup_tables_default () @@ -43,10 +91,6 @@ void QuantumSynchrotronEngine::compute_custom_lookup_tables ( lookup_tables_initialized = true; } -bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const -{ - return lookup_tables_initialized; -} /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ @@ -90,53 +134,13 @@ bool QuantumSynchrotronEngine::write_lookup_tables ( return true; } -/* \brief Reads lookup tables from 'file' on disk */ -void QuantumSynchrotronEngine::read_lookup_tables (std::string file) -{ - std::ifstream ifile(file, std::ios::in | std::ios::binary); - - //Header (control parameters) - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_min), - sizeof(innards.ctrl.chi_part_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_min), - sizeof(innards.ctrl.chi_part_tdndt_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_max), - sizeof(innards.ctrl.chi_part_tdndt_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tdndt_how_many), - sizeof(innards.ctrl.chi_part_tdndt_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_min), - sizeof(innards.ctrl.chi_part_tem_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_max), - sizeof(innards.ctrl.chi_part_tem_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_part_tem_how_many), - sizeof(innards.ctrl.chi_part_tem_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.prob_tem_how_many), - sizeof(innards.ctrl.prob_tem_how_many)); - //_______ - - //Data - size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_part_tdndt_how_many; - char* data_buf = new char(size_buf); - ifile.read(data_buf, size_buf); - innards.KKfunc_coords.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - ifile.read(data_buf, size_buf); - innards.KKfunc_data.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - delete[] data_buf; - //_______ - - ifile.close(); - - lookup_tables_initialized = true; -} - -//Private function which actually computes the lookup tables + //Private function which actually computes the lookup tables void QuantumSynchrotronEngine::computes_lookup_tables ( WarpXQuantumSynchrotronWrapperCtrl ctrl) { //Lambda is not actually used if S.I. units are enabled - WarpXQuantumSynchrotronWrapper qs_engine(std::move(DummyStruct()), 1.0, ctrl); + WarpXQuantumSynchrotronWrapper qs_engine( + std::move(__DummyStruct()), 1.0, ctrl); qs_engine.compute_dN_dt_lookup_table(); //qs_engine.compute_cumulative_pair_table(); @@ -153,5 +157,6 @@ void QuantumSynchrotronEngine::computes_lookup_tables ( qs_innards_picsar.KKfunc_table_data_how_many); //____ } +#endif //============================================ -- cgit v1.2.3 From c4c5a80272be535b4968d78ff8ae97777f6193d9 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 18 Oct 2019 18:29:05 +0200 Subject: progress towards separation of the 'table building' function --- Source/Particles/MultiParticleContainer.H | 4 +- Source/Particles/MultiParticleContainer.cpp | 16 +-- Source/QED/BreitWheelerEngineTableBuilder.H | 5 +- Source/QED/BreitWheelerEngineWrapper.H | 27 ++-- Source/QED/BreitWheelerEngineWrapper.cpp | 185 +++++++++++++++++----------- Source/QED/Make.package | 1 + Source/QED/QedTableParserHelperFunctions.H | 44 +++++++ Source/QED/QedWrapperCommons.H | 23 ++++ 8 files changed, 207 insertions(+), 98 deletions(-) create mode 100644 Source/QED/QedTableParserHelperFunctions.H (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 9e44afdd7..9f52dd0a5 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -232,9 +232,9 @@ protected: void InitQuantumSync (); void InitBreitWheeler (); - std::tuple + std::tuple ParseQuantumSyncParams (); - std::tuple + std::tuple ParseBreitWheelerParams (); #endif diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 771943171..afeac1abd 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -759,7 +759,7 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { bool is_custom; - WarpXQuantumSynchrotronWrapperCtrl ctrl; + PicsarQuantumSynchrotronCtrl ctrl; std::string filename; std::tie(is_custom, filename, ctrl) = ParseQuantumSyncParams(); @@ -768,13 +768,13 @@ void MultiParticleContainer::InitQuantumSync () // qs_engine.write_lookup_tables("qed_qs_lookup.bin"); // } // amrex::ParallelDescriptor::Barrier(); - qs_engine.read_lookup_tables("qed_qs_lookup.bin"); + // qs_engine.read_lookup_tables("qed_qs_lookup.bin"); } void MultiParticleContainer::InitBreitWheeler () { bool is_custom; - WarpXBreitWheelerWrapperCtrl ctrl; + PicsarBreitWheelerCtrl ctrl; std::string filename; std::tie(is_custom, filename, ctrl) = ParseBreitWheelerParams(); @@ -783,23 +783,23 @@ void MultiParticleContainer::InitBreitWheeler () // bw_engine.write_lookup_tables("qed_bw_lookup.bin"); // } // amrex::ParallelDescriptor::Barrier(); - bw_engine.read_lookup_tables("qed_bw_lookup.bin"); + // bw_engine.read_lookup_tables("qed_bw_lookup.bin"); } -std::tuple +std::tuple MultiParticleContainer::ParseQuantumSyncParams () { - WarpXQuantumSynchrotronWrapperCtrl ctrl; + PicsarQuantumSynchrotronCtrl ctrl; bool is_custom{false}; return std::make_tuple(is_custom, std::string(""), ctrl); } -std::tuple +std::tuple MultiParticleContainer::ParseBreitWheelerParams () { - WarpXBreitWheelerWrapperCtrl ctrl; + PicsarBreitWheelerCtrl ctrl; bool is_custom{false}; return std::make_tuple(is_custom, std::string(""), ctrl); diff --git a/Source/QED/BreitWheelerEngineTableBuilder.H b/Source/QED/BreitWheelerEngineTableBuilder.H index bd53ab3cf..0e3e45064 100644 --- a/Source/QED/BreitWheelerEngineTableBuilder.H +++ b/Source/QED/BreitWheelerEngineTableBuilder.H @@ -3,6 +3,9 @@ #include "QedWrapperCommons.H" -class BreitWheelerEngineTableBuilder{}; +class BreitWheelerEngineTableBuilder{ + public: + +}; #endif //WARPX_breit_wheeler_engine_table_builder_h_ diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index c6d550732..d42150154 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -186,37 +186,36 @@ public: /* \brief Builds the functor to generate the pairs */ BreitWheelerGeneratePairs build_pair_functor (); - /* \brief Reads lookup tables from 'file' on disk */ - void read_lookup_tables (std::string file); - /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; -private: - bool lookup_tables_initialized = false; + /* \brief Reads lookup tables from 'file' on disk */ + bool init_lookup_tables_from_raw_data (const std::vector& raw_data); - BreitWheelerEngineInnards innards; + /* \brief Writes lookup tables on disk in 'file' + * return false if it fails. */ + std::vector export_lookup_tables_data () const; -#ifdef WARPX_QED_TABLE_GEN -public: /* \brief Computes the Lookup tables using the default settings * provided by the PICSAR library */ void compute_lookup_tables_default (); /* \brief Computes the Lookup tables using user-defined settings */ - void compute_custom_lookup_tables (WarpXBreitWheelerWrapperCtrl ctrl); + void compute_custom_lookup_tables (PicsarBreitWheelerCtrl ctrl); - /* \brief Writes lookup tables on disk in 'file' - * return false if it fails. */ - bool write_lookup_tables (std::string file) const; +private: + bool lookup_tables_initialized = false; + BreitWheelerEngineInnards innards; + +#ifdef WARPX_QED_TABLE_GEN -private: BreitWheelerEngineTableBuilder table_builder; //Private function which actually computes the lookup tables void computes_lookup_tables ( - WarpXBreitWheelerWrapperCtrl ctrl); + PicsarBreitWheelerCtrl ctrl); + #endif }; diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index c58c652e5..327b76411 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -1,4 +1,13 @@ #include "BreitWheelerEngineWrapper.H" + +#include "QedTableParserHelperFunctions.H" + +#include + +using namespace std; +using namespace QedUtils; +using namespace amrex; + //This file provides a wrapper aroud the breit_wheeler engine //provided by the PICSAR library @@ -7,13 +16,15 @@ BreitWheelerEngine::BreitWheelerEngine (){} //Builds the functor to initialize the optical depth -BreitWheelerGetOpticalDepth BreitWheelerEngine::build_optical_depth_functor () +BreitWheelerGetOpticalDepth +BreitWheelerEngine::build_optical_depth_functor () { return BreitWheelerGetOpticalDepth(); } //Builds the functor to evolve the optical depth -BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor () +BreitWheelerEvolveOpticalDepth +BreitWheelerEngine::build_evolve_functor () { AMREX_ALWAYS_ASSERT(lookup_tables_initialized); @@ -21,7 +32,8 @@ BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor () } //Builds the functor to generate the pairs -BreitWheelerGeneratePairs BreitWheelerEngine::build_pair_functor () +BreitWheelerGeneratePairs +BreitWheelerEngine::build_pair_functor () { AMREX_ALWAYS_ASSERT(lookup_tables_initialized); @@ -34,44 +46,102 @@ bool BreitWheelerEngine::are_lookup_tables_initialized () const } /* \brief Reads lookup tables from 'file' on disk */ -void BreitWheelerEngine::read_lookup_tables (std::string file) +bool +BreitWheelerEngine::init_lookup_tables_from_raw_data ( + const vector& raw_data) { - std::ifstream ifile(file, std::ios::in | std::ios::binary); + const char* p_data = raw_data.data(); + const char* const p_last = &raw_data.back(); + bool is_ok; //Header (control parameters) - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_min), - sizeof(innards.ctrl.chi_phot_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), - sizeof(innards.ctrl.chi_phot_tdndt_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), - sizeof(innards.ctrl.chi_phot_tdndt_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), - sizeof(innards.ctrl.chi_phot_tdndt_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), - sizeof(innards.ctrl.chi_phot_tpair_min)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), - sizeof(innards.ctrl.chi_phot_tpair_max)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), - sizeof(innards.ctrl.chi_phot_tpair_how_many)); - ifile.read(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), - sizeof(innards.ctrl.chi_frac_tpair_how_many)); - //_______ + tie(is_ok, innards.ctrl.chi_phot_min, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tdndt_min, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tdndt_max, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tdndt_how_many, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tpair_min, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tpair_max, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_phot_tpair_how_many, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, innards.ctrl.chi_frac_tpair_how_many, p_data) = + parse_raw_data( + p_data, p_last); + if(!is_ok) return false; + + //___________________________ //Data - size_t size_buf = sizeof(amrex::Real)*innards.ctrl.chi_phot_tdndt_how_many; - char* data_buf = new char(size_buf); - ifile.read(data_buf, size_buf); - innards.TTfunc_coords.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - ifile.read(data_buf, size_buf); - innards.TTfunc_data.assign((amrex::Real*)data_buf, - (amrex::Real*)data_buf + size_buf); - delete[] data_buf; - //_______ - - ifile.close(); - + vector tndt_coords(innards.ctrl.chi_phot_tdndt_how_many); + vector tndt_data(innards.ctrl.chi_phot_tdndt_how_many); + vector cum_tab_coords1(innards.ctrl.chi_phot_tpair_how_many); + vector cum_tab_coords2(innards.ctrl.chi_frac_tpair_how_many); + vector cum_tab_data(innards.ctrl.chi_phot_tpair_how_many* + innards.ctrl.chi_frac_tpair_how_many); + + tie(is_ok, tndt_coords, p_data) = + parse_raw_data_vec( + p_data, tndt_coords.size(), p_last); + if(!is_ok) return false; + innards.TTfunc_coords.assign(tndt_coords.begin(), tndt_coords.end()); + + tie(is_ok, tndt_data, p_data) = + parse_raw_data_vec( + p_data, tndt_data.size(), p_last); + if(!is_ok) return false; + innards.TTfunc_data.assign(tndt_data.begin(), tndt_data.end()); + + tie(is_ok, cum_tab_coords1, p_data) = + parse_raw_data_vec( + p_data, cum_tab_coords1.size(), p_last); + if(!is_ok) return false; + innards.cum_distrib_coords_1.assign( + cum_tab_coords1.begin(), cum_tab_coords1.end()); + + tie(is_ok, cum_tab_coords2, p_data) = + parse_raw_data_vec( + p_data, cum_tab_coords2.size(), p_last); + if(!is_ok) return false; + innards.cum_distrib_coords_2.assign( + cum_tab_coords2.begin(), cum_tab_coords2.end()); + + tie(is_ok, cum_tab_data, p_data) = + parse_raw_data_vec( + p_data, cum_tab_data.size(), p_last); + if(!is_ok) return false; + innards.cum_distrib_data.assign( + cum_tab_data.begin(), cum_tab_data.end()); + + //___________________________ lookup_tables_initialized = true; + + return true; } @@ -101,56 +171,25 @@ void BreitWheelerEngine::compute_custom_lookup_tables ( /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ -bool BreitWheelerEngine::write_lookup_tables ( - std::string file) const +std::vector export_lookup_tables_data () const { if(!lookup_tables_initialized) - return false; - - std::ofstream of(file, std::ios::out | std::ios::binary); + return std::vector; - //Header (control parameters) - of.write(reinterpret_cast(&innards.ctrl.chi_phot_min), - sizeof(innards.ctrl.chi_phot_min)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_min), - sizeof(innards.ctrl.chi_phot_tdndt_min)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_max), - sizeof(innards.ctrl.chi_phot_tdndt_max)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tdndt_how_many), - sizeof(innards.ctrl.chi_phot_tdndt_how_many)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_min), - sizeof(innards.ctrl.chi_phot_tpair_min)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_max), - sizeof(innards.ctrl.chi_phot_tpair_max)); - of.write(reinterpret_cast(&innards.ctrl.chi_phot_tpair_how_many), - sizeof(innards.ctrl.chi_phot_tpair_how_many)); - of.write(reinterpret_cast(&innards.ctrl.chi_frac_tpair_how_many), - sizeof(innards.ctrl.chi_frac_tpair_how_many)); - //_______ - - //Data - of.write(reinterpret_cast(innards.TTfunc_coords.dataPtr()), - sizeof(amrex::Real)*innards.TTfunc_coords.size()); - of.write(reinterpret_cast(innards.TTfunc_data.dataPtr()), - sizeof(amrex::Real)*innards.TTfunc_data.size()); - // TODO: add other table - //_______ - - of.close(); - - return true; + //TODO + return std::vector; } //Private function which actually computes the lookup tables void BreitWheelerEngine::computes_lookup_tables ( - WarpXBreitWheelerWrapperCtrl ctrl) + PicsarBreitWheelerCtrl ctrl) { //Lambda is not actually used if S.I. units are enabled - WarpXBreitWheelerWrapper bw_engine( + PicsarBreitWheelerEngine bw_engine( std::move(QedUtils::DummyStruct()), 1.0, ctrl); bw_engine.compute_dN_dt_lookup_table(); - //bw_engine.compute_cumulative_pair_table(); + bw_engine.compute_cumulative_pair_table(); auto bw_innards_picsar = bw_engine.export_innards(); diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 302e890c8..23e50b9d1 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,5 +1,6 @@ CEXE_headers += QedWrapperCommons.H CEXE_headers += QedChiFunctions.H +CEXE_headers += QedTableParserHelperFunctions.H CEXE_headers += BreitWheelerEngineWrapper.H CEXE_headers += QuantumSyncsEngineWrapper.H CEXE_sources += BreitWheelerEngineWrapper.cpp diff --git a/Source/QED/QedTableParserHelperFunctions.H b/Source/QED/QedTableParserHelperFunctions.H new file mode 100644 index 000000000..a4c73adc4 --- /dev/null +++ b/Source/QED/QedTableParserHelperFunctions.H @@ -0,0 +1,44 @@ +#ifndef WARPX_amrex_qed_table_parser_helper_functions_h_ +#define WARPX_amrex_qed_table_parser_helper_functions_h_ + +//This file contains helper functions to parse a char* array +//into a lookup table + +#include +#include + +namespace QedUtils{ + template + std::tuple, const char*>parse_raw_data_vec( + const char* p_data, size_t how_many, const char* const p_last) + { + std::vector res; + if(p_data + sizeof(T)*how_many > p_last) + return std::make_tuple(false, res, nullptr); + + auto r_data = reinterpret_cast(p_data); + + res.assign(r_data, r_data + how_many); + + p_data += sizeof(T)*how_many; + return std::make_tuple(true, res, p_data); + } + + template + std::tuple parse_raw_data( + const char* p_data, const char* const p_last) + { + T res; + if(p_data + sizeof(T) > p_last) + return std::make_tuple(false, res, nullptr); + + auto r_data = reinterpret_cast(p_data); + + res = *r_data; + + p_data += sizeof(T); + return std::make_tuple(true, res, p_data); + } +}; + +#endif //WARPX_amrex_qed_table_parser_helper_functions_h_ diff --git a/Source/QED/QedWrapperCommons.H b/Source/QED/QedWrapperCommons.H index 2d17d3b83..a972b8869 100644 --- a/Source/QED/QedWrapperCommons.H +++ b/Source/QED/QedWrapperCommons.H @@ -16,4 +16,27 @@ namespace QedUtils{ struct DummyStruct{}; }; +//Control structures used by the engines +struct PicsarBreitWheelerCtrl +{ + _REAL chi_phot_min = + static_cast<_REAL>(__breit_wheeler_min_chi_phot); + + _REAL chi_phot_tdndt_min = + static_cast<_REAL>(__breit_wheeler_min_tdndt_chi_phot); + _REAL chi_phot_tdndt_max = + static_cast<_REAL>(__breit_wheeler_max_tdndt_chi_phot); + size_t chi_phot_tdndt_how_many = + __breit_wheeler_how_many_tdndt_chi_phot; + + _REAL chi_phot_tpair_min = + static_cast<_REAL>(__breit_wheeler_min_tpair_chi_phot); + _REAL chi_phot_tpair_max = + static_cast<_REAL>(__breit_wheeler_max_tpair_chi_phot); + size_t chi_phot_tpair_how_many = + __breit_wheeler_how_many_tpair_chi_phot; + size_t chi_frac_tpair_how_many = + __breit_wheeler_chi_frac_tpair_how_many; +}; + #endif //WARPX_amrex_qed_wrapper_commons_h_ -- cgit v1.2.3 From 9f8c153619f12390dd616c8f28548055f2bcb6d6 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 21 Oct 2019 17:44:00 +0200 Subject: added parsing of inputfile for table generation --- .../qed/breit_wheeler/inputs.2d_test_table_gen | 82 ++++++++++++ Source/Make.WarpX | 1 + Source/Particles/MultiParticleContainer.cpp | 144 +++++++++++++++++---- Source/QED/BreitWheelerEngineWrapper.H | 17 +-- Source/QED/BreitWheelerEngineWrapper.cpp | 45 ++----- Source/QED/QedTableParserHelperFunctions.H | 6 +- Source/QED/QuantumSyncEngineWrapper.H | 16 +-- Source/QED/QuantumSyncEngineWrapper.cpp | 51 +++----- 8 files changed, 245 insertions(+), 117 deletions(-) create mode 100644 Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen new file mode 100644 index 000000000..e206c8e32 --- /dev/null +++ b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen @@ -0,0 +1,82 @@ +################################# +####### GENERAL PARAMETERS ###### +################################# +max_step = 1 +amr.n_cell = 128 128 +amr.max_grid_size = 128 # maximum size of each AMReX box, used to decompose the domain +amr.blocking_factor = 32 # minimum size of each AMReX box, used to decompose the domain +amr.plot_int = 1 +geometry.coord_sys = 0 # 0: Cartesian +geometry.is_periodic = 0 0 # Is periodic? +geometry.prob_lo = -32.e-6 -32.e-6 # physical domain +geometry.prob_hi = 32.e-6 32.e-6 +amr.max_level = 0 # Maximum level in hierarchy (1 might be unstable, >1 is not supported) +warpx.fine_tag_lo = -5.e-6 -35.e-6 +warpx.fine_tag_hi = 5.e-6 -25.e-6 + +################################# +############ NUMERICS ########### +################################# +algo.current_deposition = esirkepov +algo.charge_deposition = standard +algo.field_gathering = standard +algo.particle_pusher = boris +interpolation.nox = 3 # Particle interpolation order. Must be the same in x, y, and z +interpolation.noy = 3 +interpolation.noz = 3 +warpx.verbose = 1 +warpx.do_dive_cleaning = 0 +warpx.plot_raw_fields = 0 +warpx.plot_raw_fields_guards = 0 +warpx.plot_finepatch = 0 +warpx.plot_crsepatch = 0 +warpx.use_filter = 1 +warpx.cfl = 1. # if 1., the time step is set to its CFL limit +warpx.do_pml = 1 # use Perfectly Matched Layer as boundary condition +warpx.serialize_ics = 1 + +################################# +############ PLASMA ############# +################################# +particles.nspecies = 1 # number of species +particles.species_names = photons +particles.photon_species = photons +################################# + +photons.charge = -q_e +photons.mass = m_e +photons.injection_style = "NUniformPerCell" +photons.profile = "constant" +photons.xmin = -30e-6 +photons.ymin = -30e-6 +photons.zmin = -30e-6 +photons.xmax = 30e-6 +photons.ymax = 30e-6 +photons.zmax = 30e-6 +photons.num_particles_per_cell_each_dim = 2 2 +photons.density = 1e19 +photons.profile = "constant" +photons.momentum_distribution_type = "gaussian" +photons.ux_m = 0.0 +photons.uy_m = 0.0 +photons.uz_m = 0.0 +photons.ux_th = 100. +photons.uy_th = 100. +photons.uz_th = 100. +##########QED#################### +photons.do_qed = 1 +photons.do_qed_breit_wheeler = 1 +################################# + +##########QED TABLES#################### +qed_bw.chi_min = 0.01 +qed_bw.generate_table = 1 +qed_bw.tab_dndt_chi_min = 0.01 +qed_bw.tab_dndt_chi_max = 100 +qed_bw.tab_dndt_how_many = 100 +qed_bw.tab_pair_chi_min = 0.01 +qed_bw.tab_pair_chi_max = 100 +qed_bw.tab_pair_chi_how_many = 10 +qed_bw.tab_pair_prob_how_many = 10 +qed_bw.save_table_in = "bw_table" +################################# diff --git a/Source/Make.WarpX b/Source/Make.WarpX index 8e4e3b4f7..b81fed147 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -101,6 +101,7 @@ ifeq ($(QED),TRUE) CFLAGS += -DWARPX_QED_TABLE_GEN FFLAGS += -DWARPX_QED_TABLE_GEN F90FLAGS += -DWARPX_QED_TABLE_GEN + USERSuffix := $(USERSuffix).GENTABLES endif endif diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index afeac1abd..e825b0f35 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -1,4 +1,7 @@ #include + +#include + #include #include @@ -7,6 +10,7 @@ #include using namespace amrex; +using namespace std::literals; MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) { @@ -758,50 +762,146 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { - bool is_custom; + bool generate_table; PicsarQuantumSynchrotronCtrl ctrl; std::string filename; - std::tie(is_custom, filename, ctrl) = ParseQuantumSyncParams(); + std::tie(generate_table, filename, ctrl) = ParseQuantumSyncParams(); - // if(ParallelDescriptor::IOProcessor()){ - // qs_engine.compute_lookup_tables_default(); - // qs_engine.write_lookup_tables("qed_qs_lookup.bin"); - // } - // amrex::ParallelDescriptor::Barrier(); - // qs_engine.read_lookup_tables("qed_qs_lookup.bin"); + if(generate_table && ParallelDescriptor::IOProcessor()){ + qs_engine.compute_lookup_tables(ctrl); + Vector all_data = qs_engine.export_lookup_tables_data(); + //TODO: WRITE + } + ParallelDescriptor::Barrier(); + + Vector table_data; + ParallelDescriptor::ReadAndBcastFile(filename, table_data); + if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) + amrex::Error("Table initialization has failed!\n"); } void MultiParticleContainer::InitBreitWheeler () { - bool is_custom; + bool generate_table; PicsarBreitWheelerCtrl ctrl; std::string filename; - std::tie(is_custom, filename, ctrl) = ParseBreitWheelerParams(); + std::tie(generate_table, filename, ctrl) = ParseBreitWheelerParams(); - // if(ParallelDescriptor::IOProcessor()){ - // bw_engine.compute_lookup_tables_default(); - // bw_engine.write_lookup_tables("qed_bw_lookup.bin"); - // } - // amrex::ParallelDescriptor::Barrier(); - // bw_engine.read_lookup_tables("qed_bw_lookup.bin"); + if(generate_table && ParallelDescriptor::IOProcessor()){ + bw_engine.compute_lookup_tables(ctrl); + Vector all_data = bw_engine.export_lookup_tables_data(); + //TODO: WRITE + } + ParallelDescriptor::Barrier(); + Vector table_data; + ParallelDescriptor::ReadAndBcastFile(filename, table_data); + if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) + amrex::Error("Table initialization has failed!\n"); } std::tuple MultiParticleContainer::ParseQuantumSyncParams () { - PicsarQuantumSynchrotronCtrl ctrl; - bool is_custom{false}; + PicsarQuantumSynchrotronCtrl ctrl = + qs_engine.get_default_ctrl(); + bool generate_table{false}; + std::string table_name; + + ParmParse pp("qed_qs"); + + pp.query("chi_min", ctrl.chi_part_min); + + pp.query("generate_table", generate_table); + if(generate_table){ + int t_int; + pp.query("tab_dndt_chi_min", ctrl.chi_part_tdndt_min); + pp.query("tab_dndt_chi_max", ctrl.chi_part_tdndt_max); + pp.query("tab_dndt_how_many", t_int); + ctrl.chi_part_tdndt_max = t_int; + pp.query("tab_em_chi_min", ctrl.chi_part_tem_min); + pp.query("tab_em_chi_max", ctrl.chi_part_tem_max); + pp.query("tab_em_chi_how_many", t_int); + ctrl.chi_part_tem_how_many = t_int; + pp.query("tab_em_prob_how_many", t_int); + ctrl.prob_tem_how_many = t_int; + pp.query("save_table_in", table_name); + } + + std::string load_table_name; + pp.query("load_table_from", load_table_name); + if(load_table_name != ""s){ + if(ParallelDescriptor::IOProcessor()){ + amrex::Print() << "Warning, Quantum Synchrotron table will be loaded, not generated. \n"; + } + table_name = load_table_name; + generate_table = false; + } + +#ifndef WARPX_QED_TABLE_GEN + if(generate_table){ + amrex::Error("Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"); + } +#endif + + if(table_name==""s){ + amrex::Error("Error: Quantum Synchrotron table has either to be generated or to be loaded.\n"); + } - return std::make_tuple(is_custom, std::string(""), ctrl); + return std::make_tuple(generate_table, table_name, ctrl); } std::tuple MultiParticleContainer::ParseBreitWheelerParams () { - PicsarBreitWheelerCtrl ctrl; - bool is_custom{false}; + PicsarBreitWheelerCtrl ctrl = + bw_engine.get_default_ctrl(); + bool generate_table{false}; + std::string table_name; + + ParmParse pp("qed_bw"); + + pp.query("chi_min", ctrl.chi_phot_min); + + pp.query("generate_table", generate_table); + if(generate_table){ + int t_int; + pp.query("tab_dndt_chi_min", ctrl.chi_phot_tdndt_min); + pp.query("tab_dndt_chi_max", ctrl.chi_phot_tdndt_max); + pp.query("tab_dndt_how_many", t_int); + ctrl.chi_phot_tdndt_how_many = t_int; + pp.query("tab_pair_chi_min", ctrl.chi_phot_tpair_min); + pp.query("tab_pair_chi_max", ctrl.chi_phot_tpair_max); + pp.query("tab_pair_chi_how_many", t_int); + ctrl.chi_phot_tpair_how_many = t_int; + pp.query("tab_pair_prob_how_many", t_int); + ctrl.chi_frac_tpair_how_many = t_int; + pp.query("save_table_in", table_name); + } + + std::string load_table_name; + pp.query("load_table_from", load_table_name); + if(load_table_name != ""s){ + if(ParallelDescriptor::IOProcessor()){ + amrex::Print() << "Warning, Breit Wheeler table will be loaded, not generated. \n"; + } + table_name = load_table_name; + generate_table = false; + } + +#ifndef WARPX_QED_TABLE_GEN + if(generate_table){ + if(ParallelDescriptor::IOProcessor()){ + amrex::Error("Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"); + } + } +#endif + + if(table_name==""s){ + amrex::Error("Error: Breit Wheeler table has either to be generated or to be loaded.\n"); + } + - return std::make_tuple(is_custom, std::string(""), ctrl); + return std::make_tuple(generate_table, table_name, ctrl); } #endif diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index fa27b79e7..dde70637d 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -5,6 +5,7 @@ #include "BreitWheelerEngineInnards.H" #include +#include #include //BW ENGINE from PICSAR @@ -17,7 +18,6 @@ #endif #include -#include using PicsarBreitWheelerEngine = picsar::multi_physics:: breit_wheeler_engine; @@ -174,18 +174,16 @@ public: bool are_lookup_tables_initialized () const; /* \brief Reads lookup tables from 'file' on disk */ - bool init_lookup_tables_from_raw_data (const std::vector& raw_data); + bool init_lookup_tables_from_raw_data (const amrex::Vector& raw_data); /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ - std::vector export_lookup_tables_data () const; - - /* \brief Computes the Lookup tables using the default settings - * provided by the PICSAR library */ - void compute_lookup_tables_default (); + amrex::Vector export_lookup_tables_data () const; /* \brief Computes the Lookup tables using user-defined settings */ - void compute_custom_lookup_tables (PicsarBreitWheelerCtrl ctrl); + void compute_lookup_tables (PicsarBreitWheelerCtrl ctrl); + + PicsarBreitWheelerCtrl get_default_ctrl() const; private: bool lookup_tables_initialized = false; @@ -196,9 +194,6 @@ private: BreitWheelerEngineTableBuilder table_builder; #endif - //Private function which actually computes the lookup tables - void compute_lookup_tables (PicsarBreitWheelerCtrl ctrl); - }; //============================================ diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index 7efa5aa79..011da6ee1 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -2,10 +2,7 @@ #include "QedTableParserHelperFunctions.H" -#include - #include -#include using namespace std; using namespace QedUtils; @@ -51,7 +48,7 @@ bool BreitWheelerEngine::are_lookup_tables_initialized () const /* \brief Reads lookup tables from 'file' on disk */ bool BreitWheelerEngine::init_lookup_tables_from_raw_data ( - const vector& raw_data) + const Vector& raw_data) { const char* p_data = raw_data.data(); const char* const p_last = &raw_data.back(); @@ -101,11 +98,11 @@ BreitWheelerEngine::init_lookup_tables_from_raw_data ( //___________________________ //Data - vector tndt_coords(innards.ctrl.chi_phot_tdndt_how_many); - vector tndt_data(innards.ctrl.chi_phot_tdndt_how_many); - vector cum_tab_coords1(innards.ctrl.chi_phot_tpair_how_many); - vector cum_tab_coords2(innards.ctrl.chi_frac_tpair_how_many); - vector cum_tab_data(innards.ctrl.chi_phot_tpair_how_many* + Vector tndt_coords(innards.ctrl.chi_phot_tdndt_how_many); + Vector tndt_data(innards.ctrl.chi_phot_tdndt_how_many); + Vector cum_tab_coords1(innards.ctrl.chi_phot_tpair_how_many); + Vector cum_tab_coords2(innards.ctrl.chi_frac_tpair_how_many); + Vector cum_tab_data(innards.ctrl.chi_phot_tpair_how_many* innards.ctrl.chi_frac_tpair_how_many); tie(is_ok, tndt_coords, p_data) = @@ -147,34 +144,17 @@ BreitWheelerEngine::init_lookup_tables_from_raw_data ( return true; } -//Initializes the Lookup tables using the default settings -//provided by the library -void BreitWheelerEngine::compute_lookup_tables_default () +PicsarBreitWheelerCtrl +BreitWheelerEngine::get_default_ctrl() const { - //A control parameters structure - //with the default values provided by the library - PicsarBreitWheelerCtrl ctrl_default; - - compute_lookup_tables(ctrl_default); - - lookup_tables_initialized = true; + return PicsarBreitWheelerCtrl(); } -// Computes the Lookup tables using user-defined settings -void BreitWheelerEngine::compute_custom_lookup_tables ( - PicsarBreitWheelerCtrl ctrl) -{ - compute_lookup_tables(ctrl); - - lookup_tables_initialized = true; -} - - /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ -std::vector BreitWheelerEngine::export_lookup_tables_data () const +Vector BreitWheelerEngine::export_lookup_tables_data () const { - std::vector res{}; + Vector res{}; if(!lookup_tables_initialized) return res; @@ -217,9 +197,6 @@ void BreitWheelerEngine::compute_lookup_tables ( { #ifdef WARPX_QED_TABLE_GEN table_builder.compute_table(ctrl, innards); -#else - amrex::Print() << - "Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"; #endif } diff --git a/Source/QED/QedTableParserHelperFunctions.H b/Source/QED/QedTableParserHelperFunctions.H index a4c73adc4..e63947ef7 100644 --- a/Source/QED/QedTableParserHelperFunctions.H +++ b/Source/QED/QedTableParserHelperFunctions.H @@ -4,15 +4,15 @@ //This file contains helper functions to parse a char* array //into a lookup table -#include +#include #include namespace QedUtils{ template - std::tuple, const char*>parse_raw_data_vec( + std::tuple, const char*>parse_raw_data_vec( const char* p_data, size_t how_many, const char* const p_last) { - std::vector res; + amrex::Vector res; if(p_data + sizeof(T)*how_many > p_last) return std::make_tuple(false, res, nullptr); diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index c769ed549..da4a0c40a 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -5,6 +5,7 @@ #include "QuantumSyncEngineInnards.H" #include +#include #include //QS ENGINE from PICSAR @@ -17,7 +18,6 @@ #endif #include -#include using PicsarQuantumSynchrotronEngine = picsar::multi_physics:: quantum_synchrotron_engine; @@ -171,19 +171,16 @@ public: bool are_lookup_tables_initialized () const; /* \brief Reads lookup tables from 'file' on disk */ - bool init_lookup_tables_from_raw_data (const std::vector& raw_data); + bool init_lookup_tables_from_raw_data (const amrex::Vector& raw_data); /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ - std::vector export_lookup_tables_data () const; - - /* \brief Computes the Lookup tables using the default settings - * provided by the PICSAR library */ - void compute_lookup_tables_default (); + amrex::Vector export_lookup_tables_data () const; /* \brief Computes the Lookup tables using user-defined settings */ - void compute_custom_lookup_tables (PicsarQuantumSynchrotronCtrl ctrl); + void compute_lookup_tables (PicsarQuantumSynchrotronCtrl ctrl); + PicsarQuantumSynchrotronCtrl get_default_ctrl() const; private: bool lookup_tables_initialized = false; @@ -194,9 +191,6 @@ private: QuantumSynchrotronEngineTableBuilder table_builder; #endif - //Private function which actually computes the lookup tables - void compute_lookup_tables (PicsarQuantumSynchrotronCtrl ctrl); - }; //============================================ diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index 299f08f47..c1202ad21 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -2,10 +2,7 @@ #include "QedTableParserHelperFunctions.H" -#include - #include -#include using namespace std; using namespace QedUtils; @@ -41,7 +38,7 @@ bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const /* \brief Reads lookup tables from 'file' on disk */ bool QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( - const vector& raw_data) + const Vector& raw_data) { const char* p_data = raw_data.data(); const char* const p_last = &raw_data.back(); @@ -91,11 +88,11 @@ QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( //___________________________ //Data - vector tndt_coords(innards.ctrl.chi_part_tdndt_min); - vector tndt_data(innards.ctrl.chi_part_tdndt_min); - vector cum_tab_coords1(innards.ctrl.chi_part_tem_how_many); - vector cum_tab_coords2(innards.ctrl.prob_tem_how_many); - vector cum_tab_data(innards.ctrl.chi_part_tem_how_many* + Vector tndt_coords(innards.ctrl.chi_part_tdndt_min); + Vector tndt_data(innards.ctrl.chi_part_tdndt_min); + Vector cum_tab_coords1(innards.ctrl.chi_part_tem_how_many); + Vector cum_tab_coords2(innards.ctrl.prob_tem_how_many); + Vector cum_tab_data(innards.ctrl.chi_part_tem_how_many* innards.ctrl.prob_tem_how_many); tie(is_ok, tndt_coords, p_data) = @@ -137,33 +134,11 @@ QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( return true; } -//Initializes the Lookup tables using the default settings -//provided by the library -void QuantumSynchrotronEngine::compute_lookup_tables_default () -{ - //A control parameters structure - //with the default values provided by the library - PicsarQuantumSynchrotronCtrl ctrl_default; - - compute_lookup_tables(ctrl_default); - - lookup_tables_initialized = true; -} - -// Computes the Lookup tables using user-defined settings -void QuantumSynchrotronEngine::compute_custom_lookup_tables ( - PicsarQuantumSynchrotronCtrl ctrl) -{ - compute_lookup_tables(ctrl); - - lookup_tables_initialized = true; -} - /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ -std::vector QuantumSynchrotronEngine::export_lookup_tables_data () const +Vector QuantumSynchrotronEngine::export_lookup_tables_data () const { - std::vector res{}; + Vector res{}; if(!lookup_tables_initialized) return res; @@ -181,6 +156,7 @@ std::vector QuantumSynchrotronEngine::export_lookup_tables_data () const add_data_to_buf(innards.ctrl.chi_part_tdndt_how_many); add_data_to_buf(innards.ctrl.chi_part_tem_min); add_data_to_buf(innards.ctrl.chi_part_tem_max); + add_data_to_buf(innards.ctrl.chi_part_tem_how_many); add_data_to_buf(innards.ctrl.prob_tem_how_many); auto add_data_to_buf_vv = [&res](const auto* data, size_t how_many){ @@ -199,15 +175,18 @@ std::vector QuantumSynchrotronEngine::export_lookup_tables_data () const return res; } +PicsarQuantumSynchrotronCtrl +QuantumSynchrotronEngine::get_default_ctrl() const +{ + return PicsarQuantumSynchrotronCtrl(); +} + //Private function which actually computes the lookup tables void QuantumSynchrotronEngine::compute_lookup_tables ( PicsarQuantumSynchrotronCtrl ctrl) { #ifdef WARPX_QED_TABLE_GEN table_builder.compute_table(ctrl, innards); -#else - amrex::Print() << - "Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"; #endif } -- cgit v1.2.3 From df10673fdfbf3fa9a293a8b01911350fd873bc41 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 21 Oct 2019 18:11:20 +0200 Subject: added I) methods --- .../Modules/qed/breit_wheeler/inputs.2d_test_table_gen | 6 +++--- Source/Particles/MultiParticleContainer.cpp | 5 +++-- Source/Utils/WarpXUtil.H | 6 ++++++ Source/Utils/WarpXUtil.cpp | 17 +++++++++++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen index e206c8e32..ec8ca4051 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen +++ b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen @@ -73,10 +73,10 @@ qed_bw.chi_min = 0.01 qed_bw.generate_table = 1 qed_bw.tab_dndt_chi_min = 0.01 qed_bw.tab_dndt_chi_max = 100 -qed_bw.tab_dndt_how_many = 100 +qed_bw.tab_dndt_how_many = 200 qed_bw.tab_pair_chi_min = 0.01 qed_bw.tab_pair_chi_max = 100 -qed_bw.tab_pair_chi_how_many = 10 -qed_bw.tab_pair_prob_how_many = 10 +qed_bw.tab_pair_chi_how_many = 30 +qed_bw.tab_pair_prob_how_many = 30 qed_bw.save_table_in = "bw_table" ################################# diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index e825b0f35..462ec36a3 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -770,7 +771,7 @@ void MultiParticleContainer::InitQuantumSync () if(generate_table && ParallelDescriptor::IOProcessor()){ qs_engine.compute_lookup_tables(ctrl); Vector all_data = qs_engine.export_lookup_tables_data(); - //TODO: WRITE + WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); } ParallelDescriptor::Barrier(); @@ -790,7 +791,7 @@ void MultiParticleContainer::InitBreitWheeler () if(generate_table && ParallelDescriptor::IOProcessor()){ bw_engine.compute_lookup_tables(ctrl); Vector all_data = bw_engine.export_lookup_tables_data(); - //TODO: WRITE + WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); } ParallelDescriptor::Barrier(); diff --git a/Source/Utils/WarpXUtil.H b/Source/Utils/WarpXUtil.H index fd6e72dc6..85e6de911 100644 --- a/Source/Utils/WarpXUtil.H +++ b/Source/Utils/WarpXUtil.H @@ -2,6 +2,8 @@ #include #include +#include + void ReadBoostedFrameParameters(amrex::Real& gamma_boost, amrex::Real& beta_boost, amrex::Vector& boost_direction); @@ -9,3 +11,7 @@ void ConvertLabParamsToBoost(); void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax); + +namespace WarpXUtilIO{ + bool WriteBinaryDataOnFile(std::string filename, const amrex::Vector& data); +} diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index 4b11eb69d..0f2c75a15 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -1,10 +1,11 @@ -#include - #include #include #include #include +#include +#include + using namespace amrex; void ReadBoostedFrameParameters(Real& gamma_boost, Real& beta_boost, @@ -152,3 +153,15 @@ void NullifyMF(amrex::MultiFab& mf, int lev, amrex::Real zmin, amrex::Real zmax) } } } + + +namespace WarpXUtilIO{ + bool WriteBinaryDataOnFile(std::string filename, const amrex::Vector& data) + { + std::ofstream of{filename, std::ios::binary}; + of.write(data.data(), data.size()); + of.close(); + return of.good(); + } +} + -- cgit v1.2.3 From e880bf78f0014481d1d681eb88c7f8caf062add3 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 21 Oct 2019 18:32:08 +0200 Subject: bugfixing --- 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 462ec36a3..885a46546 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -819,7 +819,7 @@ MultiParticleContainer::ParseQuantumSyncParams () pp.query("tab_dndt_chi_min", ctrl.chi_part_tdndt_min); pp.query("tab_dndt_chi_max", ctrl.chi_part_tdndt_max); pp.query("tab_dndt_how_many", t_int); - ctrl.chi_part_tdndt_max = t_int; + ctrl.chi_part_tdndt_how_many= t_int; pp.query("tab_em_chi_min", ctrl.chi_part_tem_min); pp.query("tab_em_chi_max", ctrl.chi_part_tem_max); pp.query("tab_em_chi_how_many", t_int); -- cgit v1.2.3 From 9eee660cf049a7817ea164fd6d0b4ff711537361 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 21 Oct 2019 19:11:56 +0200 Subject: bugfixing --- .../qed/quantum_synchrotron/inputs.2d_test_table_gen | 16 ++++++++-------- Source/Particles/MultiParticleContainer.cpp | 2 +- Source/QED/QuantumSyncEngineWrapper.cpp | 1 - 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen index 9bb3bdcbd..3fa536ecc 100644 --- a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen +++ b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen @@ -94,14 +94,14 @@ positrons.do_qed_quantum_sync = 1 ################################# ##########QED TABLES#################### -qed_qs.chi_part_min = 0.01 +qed_qs.chi_min = 0.01 qed_qs.generate_table = 1 -qed_qs.chi_part_tdndt_min = 0.01 -qed_qs.chi_part_tdndt_max = 100 -qed_qs.chi_part_tdndt_how_many = 200 -qed_qs.chi_part_tem_min = 0.01 -qed_qs.chi_part_tem_max = 100 -qed_qs.chi_part_tem_how_many = 15 -qed_qs.prob_tem_how_many = 15 +qed_qs.tab_dndt_chi_min = 0.01 +qed_qs.tab_dndt_chi_max = 100 +qed_qs.tab_dndt_how_many = 200 +qed_qs.tab_em_chi_min = 0.01 +qed_qs.tab_em_chi_max = 100 +qed_qs.tab_em_chi_how_many = 5 +qed_qs.tab_em_prob_how_many = 5 qed_qs.save_table_in = "qs_table" ################################# \ No newline at end of file diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 885a46546..09f819c22 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -815,7 +815,7 @@ MultiParticleContainer::ParseQuantumSyncParams () pp.query("generate_table", generate_table); if(generate_table){ - int t_int; + int t_int = 0; pp.query("tab_dndt_chi_min", ctrl.chi_part_tdndt_min); pp.query("tab_dndt_chi_max", ctrl.chi_part_tdndt_max); pp.query("tab_dndt_how_many", t_int); diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index 5d54405a1..c29881fc2 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -191,5 +191,4 @@ void QuantumSynchrotronEngine::compute_lookup_tables ( #endif } - //============================================ -- cgit v1.2.3 From 40a05a827bc553e99157ac5cab3fb343ea832004 Mon Sep 17 00:00:00 2001 From: Maxence Thevenet Date: Mon, 21 Oct 2019 13:55:18 -0400 Subject: use RedistributeCPU to avoid issue with runtime components on GPU --- Source/Particles/MultiParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 5d898c11a..7d4081def 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -310,7 +310,7 @@ void MultiParticleContainer::Redistribute () { for (auto& pc : allcontainers) { - pc->Redistribute(); + pc->RedistributeCPU(); } } @@ -318,7 +318,7 @@ void MultiParticleContainer::RedistributeLocal (const int num_ghost) { for (auto& pc : allcontainers) { - pc->Redistribute(0, 0, 0, num_ghost); + pc->RedistributeCPU(0, 0, 0, num_ghost); } } -- cgit v1.2.3 From 805eaad896dc3a15bd4cccb39eba79f146a6f9ae Mon Sep 17 00:00:00 2001 From: Maxence Thevenet Date: Mon, 21 Oct 2019 20:09:38 -0400 Subject: fix ionization on GPU. Compiles and ionization test passes --- Source/Particles/MultiParticleContainer.cpp | 2 +- Source/Particles/ParticleCreation/CopyParticle.H | 6 +- .../Particles/ParticleCreation/ElementaryProcess.H | 108 ++++++++++++--------- .../Particles/ParticleCreation/TransformParticle.H | 3 +- 4 files changed, 72 insertions(+), 47 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index bd680af99..6bf153a01 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -594,7 +594,7 @@ MultiParticleContainer::doFieldIonization () // Create particles in pc_product int do_boost = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); - amrex::Vector v_do_boosted_product; + amrex::Gpu::ManagedDeviceVector v_do_boosted_product; v_do_boosted_product.push_back(do_boost); const amrex::Vector v_pc_product {pc_product.get()}; // Copy source to product particles, and increase ionization diff --git a/Source/Particles/ParticleCreation/CopyParticle.H b/Source/Particles/ParticleCreation/CopyParticle.H index eb0f72bde..228b25546 100644 --- a/Source/Particles/ParticleCreation/CopyParticle.H +++ b/Source/Particles/ParticleCreation/CopyParticle.H @@ -48,6 +48,7 @@ public: m_runtime_attribs_product(runtime_attribs_product){} // Copy constructor. +/* AMREX_GPU_HOST_DEVICE copyParticle(const copyParticle& in){ m_cpuid = in.m_cpuid; @@ -57,6 +58,7 @@ public: m_attribs_product = in.m_attribs_product; m_runtime_attribs_product = in.m_runtime_attribs_product; } +*/ /** * \brief Overload operator () to do the copy of 1 particle @@ -70,7 +72,7 @@ public: AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator () (int is, int ip, int pid_product, WarpXParticleContainer::ParticleType& p_source, - WarpXParticleContainer::ParticleType& p_product) + WarpXParticleContainer::ParticleType& p_product) const noexcept { // Copy particle from source to product: AoS p_product.id() = pid_product + ip; @@ -87,6 +89,7 @@ public: // Update xold etc. if boosted frame diagnostics required // for product species. Fill runtime attribs with a copy of // current properties (xold = x etc.). + /* if (m_do_boosted_product) { m_runtime_attribs_product[0][ip] = p_source.pos(0); m_runtime_attribs_product[1][ip] = p_source.pos(1); @@ -95,6 +98,7 @@ public: m_runtime_attribs_product[4][ip] = m_runtime_uold_source[1][ip]; m_runtime_attribs_product[5][ip] = m_runtime_uold_source[2][ip]; } + */ } }; diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 4c47b7f52..27505ed0c 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -67,8 +67,9 @@ public: std::unique_ptr< WarpXParticleContainer>& pc_source, amrex::Vector v_pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - const amrex::Vector v_do_boosted_product) + amrex::Gpu::ManagedDeviceVector v_do_boosted_product) { + BL_PROFILE("createIonizedParticles"); const int grid_id = mfi.index(); const int tile_id = mfi.LocalTileIndex(); @@ -96,12 +97,12 @@ public: amrex::GpuArray runtime_iattribs_source; std::map icomps_source = pc_source->getParticleiComps(); runtime_iattribs_source[0] = soa_source.GetIntData(icomps_source["ionization_level"]).data(); + int nproducts = v_pc_product.size(); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( v_do_boosted_product.size() == nproducts, "v_pc_product and v_do_boosted_product must have the same size."); - // Indices of product particle for each ionized source particle. // i_product[i]-1 is the location in product tile of product particle // from source particle i. @@ -122,9 +123,8 @@ public: int np_ionized = i_product[np_source-1]; if (np_ionized == 0) return; - // amrex::Vector v_copy_functor(nproducts); - amrex::Vector v_copy_functor; - amrex::Vector v_pid_product(nproducts); + amrex::Gpu::ManagedDeviceVector v_copy_functor; + amrex::Gpu::ManagedDeviceVector v_pid_product(nproducts); amrex::Gpu::ManagedDeviceVector v_particles_product(nproducts); for (int iproduct=0; iproduct attribs_product; @@ -149,41 +150,53 @@ public: // --- product runtime attribs amrex::GpuArray runtime_attribs_product; const int do_boost = v_do_boosted_product[iproduct]; - if (do_boost) { - std::map comps_product = pc_product->getParticleComps(); - runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; - runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; - runtime_attribs_product[2] = soa_product.GetRealData(comps_product[ "zold"]).data() + np_product_old; - runtime_attribs_product[3] = soa_product.GetRealData(comps_product["uxold"]).data() + np_product_old; - runtime_attribs_product[4] = soa_product.GetRealData(comps_product["uyold"]).data() + np_product_old; - runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; - } - - // --- product runtime integer attribs - int pid_product; + if (do_boost) { + std::map comps_product = pc_product->getParticleComps(); + runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; + runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; + runtime_attribs_product[2] = soa_product.GetRealData(comps_product[ "zold"]).data() + np_product_old; + runtime_attribs_product[3] = soa_product.GetRealData(comps_product["uxold"]).data() + np_product_old; + runtime_attribs_product[4] = soa_product.GetRealData(comps_product["uyold"]).data() + np_product_old; + runtime_attribs_product[5] = soa_product.GetRealData(comps_product["uzold"]).data() + np_product_old; + } + + // --- product runtime integer attribs + int pid_product; #pragma omp critical (doFieldIonization_nextid) - { - // ID of first newly-created product particle - pid_product = pc_product->NextID(); - // Update NextID to include particles created in this function - pc_product->setNextID(pid_product+np_ionized); - } - const int cpuid = amrex::ParallelDescriptor::MyProc(); - - // Create instance of copy functor - v_copy_functor.push_back (initialize_copy( - cpuid, v_do_boosted_product[iproduct], - runtime_uold_source, - attribs_source, - attribs_product, - runtime_attribs_product) ); - v_pid_product[iproduct] = pid_product; - } + { + // ID of first newly-created product particle + pid_product = pc_product->NextID(); + // Update NextID to include particles created in this function + pc_product->setNextID(pid_product+np_ionized); + } + const int cpuid = amrex::ParallelDescriptor::MyProc(); + // Create instance of copy functor +/* + const copyParticle copy_functor = initialize_copy( + cpuid, do_boosted_product, + runtime_uold_source, + attribs_source, + attribs_product, + runtime_attribs_product); +*/ + v_copy_functor.push_back (initialize_copy( + cpuid, v_do_boosted_product[iproduct], + runtime_uold_source, + attribs_source, + attribs_product, + runtime_attribs_product) ); + v_pid_product[iproduct] = pid_product; + + } // Loop over source particles and create product particles copyAndTransformParticles(is_flagged, i_product, np_source, v_pid_product, v_particles_product, particles_source, v_copy_functor, runtime_iattribs_source); + + //copyAndTransformParticles(is_flagged, i_product, np_source, pid_product, + // particles_product, particles_source, copy_functor, + // runtime_iattribs_source); } /** @@ -205,15 +218,22 @@ public: amrex::Gpu::ManagedDeviceVector& is_flagged, amrex::Gpu::ManagedDeviceVector& i_product, int np_source, - const amrex::Vector v_pid_product, - const amrex::Gpu::ManagedDeviceVector v_particles_product, + amrex::Gpu::ManagedDeviceVector v_pid_product, + amrex::Gpu::ManagedDeviceVector v_particles_product, WarpXParticleContainer::ParticleType* particles_source, - const amrex::Vector& v_copy_functor, + const amrex::Gpu::ManagedDeviceVector& v_copy_functor, amrex::GpuArray runtime_iattribs_source) { + + // WarpXParticleContainer::ParticleType* particles_product, + // const copyParticle& copy_functor, + int const * const AMREX_RESTRICT p_is_flagged = is_flagged.dataPtr(); int const * const AMREX_RESTRICT p_i_product = i_product.dataPtr(); - WarpXParticleContainer::ParticleType* const * const AMREX_RESTRICT p_particles_product = v_particles_product.dataPtr(); + copyParticle const * const p_copy_functor = v_copy_functor.data(); + WarpXParticleContainer::ParticleType * * p_particles_product = v_particles_product.data(); + int const * const p_pid_product = v_pid_product.data(); + // Loop over all source particles. If is_flagged, copy particle data // to corresponding product particle. amrex::For( @@ -224,14 +244,14 @@ public: // offset of 1 due to inclusive scan int ip = p_i_product[is]-1; WarpXParticleContainer::ParticleType& p_source = particles_source[is]; + // WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; for (int iproduct=0; iproduct(is, p_source, runtime_iattribs_source); diff --git a/Source/Particles/ParticleCreation/TransformParticle.H b/Source/Particles/ParticleCreation/TransformParticle.H index c202cb6d7..e16b0a4b7 100644 --- a/Source/Particles/ParticleCreation/TransformParticle.H +++ b/Source/Particles/ParticleCreation/TransformParticle.H @@ -27,7 +27,8 @@ template < elementaryProcessType ProcessT > AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void transformProductParticle( int i, - WarpXParticleContainer::ParticleType* const * const v_particle){} + WarpXParticleContainer::ParticleType* * v_particle){} +// WarpXParticleContainer::ParticleType& particle){} // For ionization, increase ionization level of source particle template <> -- cgit v1.2.3 From 67812c4d2164042f56a3451c57a5517517b26ef4 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 22 Oct 2019 16:31:32 +0200 Subject: Added comments --- .../qed/breit_wheeler/inputs.2d_test_table_gen | 2 ++ .../quantum_synchrotron/inputs.2d_test_table_gen | 2 ++ Source/Particles/MultiParticleContainer.H | 28 ++++++++++++++++++++-- Source/Particles/MultiParticleContainer.cpp | 4 ++++ 4 files changed, 34 insertions(+), 2 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen index ec8ca4051..e89c42d92 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen +++ b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_table_gen @@ -1,3 +1,5 @@ +#An inputfile to demonstrate lookup table generation for the Breit Wheeler engine + ################################# ####### GENERAL PARAMETERS ###### ################################# diff --git a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen index f3da6298d..dfef55139 100644 --- a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen +++ b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_table_gen @@ -1,3 +1,5 @@ +#An inputfile to demonstrate lookup table generation for the Quantum Synchrotron engine + ################################# ####### GENERAL PARAMETERS ###### ################################# diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 9f52dd0a5..c19e166b0 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -222,18 +222,42 @@ protected: QuantumSynchrotronEngine qs_engine; //_______________________________ - //Initialize QED engines and provides smart pointers - //to species who need QED processes + /** + * Initialize QED engines and provides smart pointers + * to species who need QED processes + */ void InitQED (); + //Flags to store if at least one species needs a QED process bool someone_has_quantum_sync = false; bool someone_has_breit_wheeler = false; + //________ + /** + * Initializes the Quantum Synchrotron engine + */ void InitQuantumSync (); + + /** + * Initializes the Quantum Synchrotron engine + */ void InitBreitWheeler (); + /** + * Parses inputfile parameters for Quantum Synchrotron engine + * @return {a tuple containing a flag which is true if tables + * have to be generate, a filename (where tables should be stored + * or read from) and control parameters.} + */ std::tuple ParseQuantumSyncParams (); + + /** + * Parses inputfile parameters for Breit Wheeler engine + * @return {a tuple containing a flag which is true if tables + * have to be generate, a filename (where tables should be stored + * or read from) and control parameters.} + */ std::tuple ParseBreitWheelerParams (); #endif diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 09f819c22..928ba2ab7 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -4,6 +4,8 @@ #include #include + +//This is now needed for writing a binary file on disk. #include #include @@ -11,6 +13,8 @@ #include using namespace amrex; + +//literals allow to write "aa"s, which means that "aa" is an std::string (C++14) using namespace std::literals; MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) -- cgit v1.2.3 From 42550405dbbffce12e967c73099799e54e0abb9a Mon Sep 17 00:00:00 2001 From: Maxence Thevenet Date: Tue, 22 Oct 2019 10:32:15 -0400 Subject: call RedistributeCPU if runtime components are present, even on GPU --- Source/Particles/MultiParticleContainer.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 6bf153a01..2b6b95827 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -316,18 +316,25 @@ void MultiParticleContainer::Redistribute () { for (auto& pc : allcontainers) { - pc->RedistributeCPU(); + if ( (pc->NumRuntimeRealComps()>0) || (pc->NumRuntimeIntComps()>0) ) { + pc->RedistributeCPU(); + } else { + pc->Redistribute(); + } } -} -void -MultiParticleContainer::RedistributeLocal (const int num_ghost) -{ - for (auto& pc : allcontainers) { - pc->RedistributeCPU(0, 0, 0, num_ghost); + void + MultiParticleContainer::RedistributeLocal (const int num_ghost) + { + for (auto& pc : allcontainers) { + if ( (pc->NumRuntimeRealComps()>0) || (pc->NumRuntimeIntComps()>0) ) { + pc->RedistributeCPU(0, 0, 0, num_ghost); + } else { + pc->Redistribute(0, 0, 0, num_ghost); + } + } } } - Vector MultiParticleContainer::NumberOfParticlesInGrid (int lev) const { -- cgit v1.2.3 From 2b77afdaa9ca95b0e29f5ccaf98d29c94e5206a9 Mon Sep 17 00:00:00 2001 From: Maxence Thevenet Date: Tue, 22 Oct 2019 10:42:10 -0400 Subject: comments and remove typo --- Source/Particles/MultiParticleContainer.cpp | 19 ++++++++++--------- Source/Particles/ParticleCreation/ElementaryProcess.H | 18 +++++++++--------- 2 files changed, 19 insertions(+), 18 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 2b6b95827..cc48f38db 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -322,19 +322,20 @@ MultiParticleContainer::Redistribute () pc->Redistribute(); } } +} - void - MultiParticleContainer::RedistributeLocal (const int num_ghost) - { - for (auto& pc : allcontainers) { - if ( (pc->NumRuntimeRealComps()>0) || (pc->NumRuntimeIntComps()>0) ) { - pc->RedistributeCPU(0, 0, 0, num_ghost); - } else { - pc->Redistribute(0, 0, 0, num_ghost); - } +void +MultiParticleContainer::RedistributeLocal (const int num_ghost) +{ + for (auto& pc : allcontainers) { + if ( (pc->NumRuntimeRealComps()>0) || (pc->NumRuntimeIntComps()>0) ) { + pc->RedistributeCPU(0, 0, 0, num_ghost); + } else { + pc->Redistribute(0, 0, 0, num_ghost); } } } + Vector MultiParticleContainer::NumberOfParticlesInGrid (int lev) const { diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index 34e13638e..d00a81175 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -8,18 +8,18 @@ /** * \brief Base class for particle creation processes * - * Particles in a source particle container are copied to a product particle - * container if they are flagged. Both source and product particles can be + * Particles in a source particle container are copied to product particle + * containers if they are flagged. Both source and product particles can be * modified. * - * initialize_copy initializes a general copy functor - * createParticles formats the data to prepare for the copy, then - * calls copyAndTransformParticles - * copyAndTransformParticles loops over particles, performs the copy and - * transform source and product particles if needed. + * - initialize_copy initializes a general copy functor + * - createParticles formats the data to prepare for the copy, then + * calls copyAndTransformParticles + * - copyAndTransformParticles loops over particles, performs the copy and + * transform source and product particles if needed. * * The class is templated on the process type. This gives flexibility - * on source and product particle transformation. + * on source and product particle transformations. */ template class elementaryProcess @@ -52,7 +52,7 @@ public: * \brief create particles in product particle containers * * For particle i in mfi, if is_flagged[i]=1, copy particle - * particle i from container pc_source into pc_product + * particle i from container pc_source into each container in v_pc_product * * \param lev MR level * \param mfi MFIter where source particles are located -- cgit v1.2.3 From 9dbdaa27a22d3020b26ab8271682bbccdbb66c8d Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 22 Oct 2019 16:55:24 +0200 Subject: Added temporary option to override table loading --- .../qed/breit_wheeler/inputs.2d_test_tau_init | 4 ++++ .../quantum_synchrotron/inputs.2d_test_tau_init | 4 ++++ Source/Particles/MultiParticleContainer.cpp | 28 ++++++++++++++++++++++ 3 files changed, 36 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init index 06f87f92b..78b9c198b 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init +++ b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init @@ -67,3 +67,7 @@ photons.uz_th = 100. photons.do_qed = 1 photons.do_qed_breit_wheeler = 1 ################################# + +##########QED TABLES############# +qed_bw.ignore_tables_for_test = 1 +################################# \ No newline at end of file diff --git a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_tau_init b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_tau_init index cdc5be585..4844245e9 100644 --- a/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_tau_init +++ b/Examples/Modules/qed/quantum_synchrotron/inputs.2d_test_tau_init @@ -92,3 +92,7 @@ positrons.uz_th = 100. positrons.do_qed = 1 positrons.do_qed_quantum_sync = 1 ################################# + +##########QED TABLES############# +qed_qs.ignore_tables_for_test = 1 +################################# \ No newline at end of file diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 928ba2ab7..74409a57f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -779,6 +779,13 @@ void MultiParticleContainer::InitQuantumSync () } ParallelDescriptor::Barrier(); + //Only temporary for test purposes, will be removed + ParmParse pp("qed_qs"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) @@ -799,6 +806,13 @@ void MultiParticleContainer::InitBreitWheeler () } ParallelDescriptor::Barrier(); + //Only temporary for test purposes, will be removed + ParmParse pp("qed_bw"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) @@ -817,6 +831,13 @@ MultiParticleContainer::ParseQuantumSyncParams () pp.query("chi_min", ctrl.chi_part_min); + //Only temporary for test purposes, will be removed + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) + return std::make_tuple(false, "__DUMMY__", ctrl); + //_________________________________________________ + pp.query("generate_table", generate_table); if(generate_table){ int t_int = 0; @@ -868,6 +889,13 @@ MultiParticleContainer::ParseBreitWheelerParams () pp.query("chi_min", ctrl.chi_phot_min); + //Only temporary for test purposes, will be removed + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) + return std::make_tuple(false, "__DUMMY__", ctrl); + //_________________________________________________ + pp.query("generate_table", generate_table); if(generate_table){ int t_int; -- cgit v1.2.3 From eb7564be98a2005036ed90e4cdf1b94c26fbc4c6 Mon Sep 17 00:00:00 2001 From: Maxence Thevenet Date: Tue, 22 Oct 2019 11:24:29 -0400 Subject: minor cleaning --- Source/Particles/MultiParticleContainer.cpp | 3 +-- Source/Particles/ParticleCreation/ElementaryProcess.H | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index cc48f38db..c54408b64 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -602,8 +602,7 @@ MultiParticleContainer::doFieldIonization () // Create particles in pc_product int do_boost = WarpX::do_boosted_frame_diagnostic && pc_product->DoBoostedFrameDiags(); - amrex::Gpu::ManagedDeviceVector v_do_boosted_product; - v_do_boosted_product.push_back(do_boost); + amrex::Gpu::ManagedDeviceVector v_do_boosted_product{do_boost}; const amrex::Vector v_pc_product {pc_product.get()}; // Copy source to product particles, and increase ionization // level of source particle diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index d00a81175..215574cda 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -228,13 +228,11 @@ public: // offset of 1 due to inclusive scan int ip = p_i_product[is]-1; WarpXParticleContainer::ParticleType& p_source = particles_source[is]; - // WarpXParticleContainer::ParticleType& p_product = particles_product[ip]; for (int iproduct=0; iproduct Date: Wed, 23 Oct 2019 17:42:22 +0200 Subject: moved ignore_table_test block at the beginning of InitBW and InitQS methods --- Source/Particles/MultiParticleContainer.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 74409a57f..f56a34525 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -767,6 +767,13 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { + //Only temporary for test purposes, will be removed + ParmParse pp("qed_qs"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + bool generate_table; PicsarQuantumSynchrotronCtrl ctrl; std::string filename; @@ -779,13 +786,6 @@ void MultiParticleContainer::InitQuantumSync () } ParallelDescriptor::Barrier(); - //Only temporary for test purposes, will be removed - ParmParse pp("qed_qs"); - bool ignore_tables = false; - pp.query("ignore_tables_for_test", ignore_tables); - if(ignore_tables) return; - //_________________________________________________ - Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) @@ -794,6 +794,14 @@ void MultiParticleContainer::InitQuantumSync () void MultiParticleContainer::InitBreitWheeler () { + + //Only temporary for test purposes, will be removed + ParmParse pp("qed_bw"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + bool generate_table; PicsarBreitWheelerCtrl ctrl; std::string filename; @@ -806,13 +814,6 @@ void MultiParticleContainer::InitBreitWheeler () } ParallelDescriptor::Barrier(); - //Only temporary for test purposes, will be removed - ParmParse pp("qed_bw"); - bool ignore_tables = false; - pp.query("ignore_tables_for_test", ignore_tables); - if(ignore_tables) return; - //_________________________________________________ - Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) -- cgit v1.2.3 From e10894084b934b0d973ef44c6c1dde84002d9acf Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 23 Oct 2019 18:02:48 +0200 Subject: Revert "moved ignore_table_test block at the beginning of InitBW and InitQS methods" This reverts commit e74d1f6c7326dfceac938d504af66fd58b946ce2. --- Source/Particles/MultiParticleContainer.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index f56a34525..74409a57f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -767,13 +767,6 @@ void MultiParticleContainer::InitQED () void MultiParticleContainer::InitQuantumSync () { - //Only temporary for test purposes, will be removed - ParmParse pp("qed_qs"); - bool ignore_tables = false; - pp.query("ignore_tables_for_test", ignore_tables); - if(ignore_tables) return; - //_________________________________________________ - bool generate_table; PicsarQuantumSynchrotronCtrl ctrl; std::string filename; @@ -786,6 +779,13 @@ void MultiParticleContainer::InitQuantumSync () } ParallelDescriptor::Barrier(); + //Only temporary for test purposes, will be removed + ParmParse pp("qed_qs"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) @@ -794,14 +794,6 @@ void MultiParticleContainer::InitQuantumSync () void MultiParticleContainer::InitBreitWheeler () { - - //Only temporary for test purposes, will be removed - ParmParse pp("qed_bw"); - bool ignore_tables = false; - pp.query("ignore_tables_for_test", ignore_tables); - if(ignore_tables) return; - //_________________________________________________ - bool generate_table; PicsarBreitWheelerCtrl ctrl; std::string filename; @@ -814,6 +806,13 @@ void MultiParticleContainer::InitBreitWheeler () } ParallelDescriptor::Barrier(); + //Only temporary for test purposes, will be removed + ParmParse pp("qed_bw"); + bool ignore_tables = false; + pp.query("ignore_tables_for_test", ignore_tables); + if(ignore_tables) return; + //_________________________________________________ + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) -- cgit v1.2.3 From 98467d93f8d2dda5f9e361797b5d88df16cef04b Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 23 Oct 2019 18:03:28 +0200 Subject: added barriers --- Source/Particles/MultiParticleContainer.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 74409a57f..95b9089fb 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -788,6 +788,7 @@ void MultiParticleContainer::InitQuantumSync () Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); + ParallelDescriptor::Barrier(); if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) amrex::Error("Table initialization has failed!\n"); } @@ -815,6 +816,7 @@ void MultiParticleContainer::InitBreitWheeler () Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); + ParallelDescriptor::Barrier(); if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) amrex::Error("Table initialization has failed!\n"); } -- cgit v1.2.3 From 7ce6fa3e8c4e1050ae5511350cdc4095631a6272 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 23 Oct 2019 18:18:56 +0200 Subject: Improved parsing of inputfile --- Source/Particles/MultiParticleContainer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 95b9089fb..1c240bed1 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -859,7 +859,7 @@ MultiParticleContainer::ParseQuantumSyncParams () std::string load_table_name; pp.query("load_table_from", load_table_name); if(load_table_name != ""s){ - if(ParallelDescriptor::IOProcessor()){ + if(generate_table && ParallelDescriptor::IOProcessor()){ amrex::Print() << "Warning, Quantum Synchrotron table will be loaded, not generated. \n"; } table_name = load_table_name; @@ -917,7 +917,7 @@ MultiParticleContainer::ParseBreitWheelerParams () std::string load_table_name; pp.query("load_table_from", load_table_name); if(load_table_name != ""s){ - if(ParallelDescriptor::IOProcessor()){ + if(generate_table && ParallelDescriptor::IOProcessor()){ amrex::Print() << "Warning, Breit Wheeler table will be loaded, not generated. \n"; } table_name = load_table_name; @@ -936,7 +936,6 @@ MultiParticleContainer::ParseBreitWheelerParams () amrex::Error("Error: Breit Wheeler table has either to be generated or to be loaded.\n"); } - return std::make_tuple(generate_table, table_name, ctrl); } #endif -- cgit v1.2.3 From a0337151fd6b715a2f8e3a2a160c8317c1bf27f5 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 23 Oct 2019 18:44:26 +0200 Subject: Improved parsing of the inputfile --- Source/Particles/MultiParticleContainer.cpp | 47 +++++++++++++++++++---------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 1c240bed1..566422a7a 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -772,13 +772,6 @@ void MultiParticleContainer::InitQuantumSync () std::string filename; std::tie(generate_table, filename, ctrl) = ParseQuantumSyncParams(); - if(generate_table && ParallelDescriptor::IOProcessor()){ - qs_engine.compute_lookup_tables(ctrl); - Vector all_data = qs_engine.export_lookup_tables_data(); - WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); - } - ParallelDescriptor::Barrier(); - //Only temporary for test purposes, will be removed ParmParse pp("qed_qs"); bool ignore_tables = false; @@ -786,10 +779,25 @@ void MultiParticleContainer::InitQuantumSync () if(ignore_tables) return; //_________________________________________________ + + if(generate_table && ParallelDescriptor::IOProcessor()){ + qs_engine.compute_lookup_tables(ctrl); + Vector all_data = qs_engine.export_lookup_tables_data(); + WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); + } + ParallelDescriptor::Barrier(); + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); ParallelDescriptor::Barrier(); - if(!qs_engine.init_lookup_tables_from_raw_data(table_data)) + + //No need to initialize from raw data for the processor that + //has just generated the table + if(!generate_table || !ParallelDescriptor::IOProcessor()){ + qs_engine.init_lookup_tables_from_raw_data(table_data); + } + + if(!qs_engine.are_lookup_tables_initialized()) amrex::Error("Table initialization has failed!\n"); } @@ -800,13 +808,6 @@ void MultiParticleContainer::InitBreitWheeler () std::string filename; std::tie(generate_table, filename, ctrl) = ParseBreitWheelerParams(); - if(generate_table && ParallelDescriptor::IOProcessor()){ - bw_engine.compute_lookup_tables(ctrl); - Vector all_data = bw_engine.export_lookup_tables_data(); - WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); - } - ParallelDescriptor::Barrier(); - //Only temporary for test purposes, will be removed ParmParse pp("qed_bw"); bool ignore_tables = false; @@ -814,10 +815,24 @@ void MultiParticleContainer::InitBreitWheeler () if(ignore_tables) return; //_________________________________________________ + if(generate_table && ParallelDescriptor::IOProcessor()){ + bw_engine.compute_lookup_tables(ctrl); + Vector all_data = bw_engine.export_lookup_tables_data(); + WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); + } + ParallelDescriptor::Barrier(); + Vector table_data; ParallelDescriptor::ReadAndBcastFile(filename, table_data); ParallelDescriptor::Barrier(); - if(!bw_engine.init_lookup_tables_from_raw_data(table_data)) + + //No need to initialize from raw data for the processor that + //has just generated the table + if(!generate_table || !ParallelDescriptor::IOProcessor()){ + bw_engine.init_lookup_tables_from_raw_data(table_data); + } + + if(!bw_engine.are_lookup_tables_initialized()) amrex::Error("Table initialization has failed!\n"); } -- cgit v1.2.3 From 9920e58195ad4b75c14ee8fdf09dc6404c0f312c Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 25 Oct 2019 10:57:42 +0200 Subject: fixed use of shared pointers --- Source/Particles/MultiParticleContainer.H | 4 ++-- Source/Particles/MultiParticleContainer.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 58546a106..949173052 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -215,8 +215,8 @@ protected: #ifdef WARPX_QED // The QED engines - BreitWheelerEngine bw_engine; - QuantumSynchrotronEngine qs_engine; + std::shared_ptr shr_p_bw_engine; + std::shared_ptr shr_p_qs_engine; //_______________________________ //Initialize QED engines and provides smart pointers diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index c860d21f5..f4c00404b 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -736,14 +736,17 @@ MultiParticleContainer::doFieldIonization () #ifdef WARPX_QED void MultiParticleContainer::InitQED () { + shr_p_qs_engine = std::make_shared(); + shr_p_bw_engine = std::make_shared(); + for (auto& pc : allcontainers) { if(pc->has_quantum_sync()){ pc->set_quantum_sync_engine_ptr - (std::make_shared(qs_engine)); + (shr_p_qs_engine); } if(pc->has_breit_wheeler()){ pc->set_breit_wheeler_engine_ptr - (std::make_shared(bw_engine)); + (shr_p_bw_engine); } } } -- cgit v1.2.3 From a6298fed05c3dd1134be85d8823c54339e570163 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 25 Oct 2019 13:40:51 +0200 Subject: fixed bug --- Source/Particles/MultiParticleContainer.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 54a4396c1..a55fa722d 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -751,10 +751,12 @@ void MultiParticleContainer::InitQED () if(pc->has_quantum_sync()){ pc->set_quantum_sync_engine_ptr (shr_p_qs_engine); + someone_has_quantum_sync = true; } if(pc->has_breit_wheeler()){ pc->set_breit_wheeler_engine_ptr (shr_p_bw_engine); + someone_has_breit_wheeler = true; } } -- cgit v1.2.3 From e133d2202685d6e478b42f9b554b00d5fa722801 Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Fri, 25 Oct 2019 11:56:10 -0700 Subject: replace 'boosted frame diags' with 'back-transformed diags' --- Docs/source/running_cpp/parameters.rst | 18 ++--- .../Modules/RigidInjection/inputs.BoostedFrame | 2 +- Examples/Modules/boosted_diags/inputs.2d | 2 +- Examples/Modules/boosted_diags/inputs.3d | 2 +- Examples/Modules/boosted_diags/inputs.3d.slice | 6 +- .../laser_acceleration/inputs.2d.boost | 2 +- .../plasma_acceleration/inputs.2d.boost | 2 +- .../plasma_acceleration/inputs.3d.boost | 2 +- Python/pywarpx/picmi.py | 8 +-- Source/Diagnostics/BoostedFrameDiagnostic.H | 12 ++-- Source/Diagnostics/BoostedFrameDiagnostic.cpp | 76 +++++++++++----------- Source/Diagnostics/Make.package | 4 +- Source/Evolve/WarpXEvolveEM.cpp | 6 +- Source/Initialization/WarpXInitData.cpp | 4 +- Source/Laser/LaserParticleContainer.cpp | 2 +- Source/Particles/MultiParticleContainer.H | 18 ++--- Source/Particles/MultiParticleContainer.cpp | 24 +++---- Source/Particles/PhotonParticleContainer.cpp | 2 +- Source/Particles/PhysicalParticleContainer.cpp | 10 +-- Source/Particles/WarpXParticleContainer.H | 4 +- Source/WarpX.H | 10 +-- Source/WarpX.cpp | 16 ++--- .../automated_test_4_labdiags_2ppc | 2 +- 23 files changed, 117 insertions(+), 117 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 59bfbb14e..a2de46b03 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -349,8 +349,8 @@ Particle initialization ``.plot_vars = none`` to plot no particle data, except particle position. -* ``.do_boosted_frame_diags`` (`0` or `1` optional, default `1`) - Only used when ``warpx.do_boosted_frame_diagnostic=1``. When running in a +* ``.do_back_transformed_diagnostics`` (`0` or `1` optional, default `1`) + Only used when ``warpx.do_back_transformed_diagnostics=1``. When running in a boosted frame, whether or not to plot back-transformed diagnostics for this species. @@ -765,7 +765,7 @@ Diagnostics and output When WarpX is compiled with openPMD support, this is ``h5`` by default. ``json`` only works with serial/single-rank jobs. -* ``warpx.do_boosted_frame_diagnostic`` (`0` or `1`) +* ``warpx.do_back_transformed_diagnostics`` (`0` or `1`) Whether to use the **back-transformed diagnostics** (i.e. diagnostics that perform on-the-fly conversion to the laboratory frame, when running boosted-frame simulations) @@ -776,22 +776,22 @@ Diagnostics and output is `lab_frame_data`. * ``warpx.num_snapshots_lab`` (`integer`) - Only used when ``warpx.do_boosted_frame_diagnostic`` is ``1``. + Only used when ``warpx.do_back_transformed_diagnostics`` is ``1``. The number of lab-frame snapshots that will be written. * ``warpx.dt_snapshots_lab`` (`float`, in seconds) - Only used when ``warpx.do_boosted_frame_diagnostic`` is ``1``. + Only used when ``warpx.do_back_transformed_diagnostics`` is ``1``. The time interval inbetween the lab-frame snapshots (where this time interval is expressed in the laboratory frame). * ``warpx.dz_snapshots_lab`` (`float`, in meters) - Only used when ``warpx.do_boosted_frame_diagnostic`` is ``1``. + Only used when ``warpx.do_back_transformed_diagnostics`` is ``1``. Distance between the lab-frame snapshots (expressed in the laboratory frame). ``dt_snapshots_lab`` is then computed by ``dt_snapshots_lab = dz_snapshots_lab/c``. Either `dt_snapshots_lab` or `dz_snapshot_lab` is required. -* ``warpx.do_boosted_frame_fields`` (`0 or 1`) +* ``warpx.do_back_transformed_fields`` (`0 or 1`) Whether to use the **back-transformed diagnostics** for the fields. * ``warpx.boosted_frame_diag_fields`` (space-separated list of `string`) @@ -850,7 +850,7 @@ Diagnostics and output negative number to disable slice generation and slice data dumping. * ``slice.num_slice_snapshots_lab`` (`integer`) - Only used when ``warpx.do_boosted_frame_diagnostic`` is ``1``. + Only used when ``warpx.do_back_transformed_diagnostics`` is ``1``. The number of back-transformed field and particle data that will be written for the reduced domain defined by ``slice.dom_lo`` and ``slice.dom_hi``. Note that the 'slice' is a reduced @@ -860,7 +860,7 @@ Diagnostics and output for further details. * ``slice.dt_slice_snapshots_lab`` (`float`, in seconds) - Only used when ``warpx.do_boosted_frame_diagnostic`` is ``1``. + Only used when ``warpx.do_back_transformed_diagnostics`` is ``1``. The time interval between the back-transformed reduced diagnostics (where this time interval is expressed in the laboratory frame). diff --git a/Examples/Modules/RigidInjection/inputs.BoostedFrame b/Examples/Modules/RigidInjection/inputs.BoostedFrame index c7a60f14f..456df363d 100644 --- a/Examples/Modules/RigidInjection/inputs.BoostedFrame +++ b/Examples/Modules/RigidInjection/inputs.BoostedFrame @@ -3,7 +3,7 @@ warpx.zmax_plasma_to_compute_max_step = 50.e-6 warpx.gamma_boost = 5. warpx.boost_direction = z -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 2 warpx.dt_snapshots_lab = 1.8679589331096515e-13 diff --git a/Examples/Modules/boosted_diags/inputs.2d b/Examples/Modules/boosted_diags/inputs.2d index 6afe6977d..7b2270f90 100644 --- a/Examples/Modules/boosted_diags/inputs.2d +++ b/Examples/Modules/boosted_diags/inputs.2d @@ -44,7 +44,7 @@ warpx.gamma_boost = 15. warpx.boost_direction = z # Diagnostics -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 20 warpx.dt_snapshots_lab = 7.0e-14 diff --git a/Examples/Modules/boosted_diags/inputs.3d b/Examples/Modules/boosted_diags/inputs.3d index 528eb6cd9..b700a52fb 100644 --- a/Examples/Modules/boosted_diags/inputs.3d +++ b/Examples/Modules/boosted_diags/inputs.3d @@ -44,7 +44,7 @@ warpx.gamma_boost = 15. warpx.boost_direction = z # Diagnostics -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 20; warpx.dt_snapshots_lab = 7.0e-14; diff --git a/Examples/Modules/boosted_diags/inputs.3d.slice b/Examples/Modules/boosted_diags/inputs.3d.slice index ca745f347..08f2310cd 100644 --- a/Examples/Modules/boosted_diags/inputs.3d.slice +++ b/Examples/Modules/boosted_diags/inputs.3d.slice @@ -30,7 +30,7 @@ warpx.serialize_ics = 1 warpx.gamma_boost = 10. warpx.boost_direction = z -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 4 warpx.dz_snapshots_lab = 0.001 warpx.boosted_frame_diag_fields= Ex Ey Ez By rho @@ -53,7 +53,7 @@ electrons.zmax = .003 electrons.profile = constant electrons.density = 3.5e24 electrons.do_continuous_injection = 1 -electrons.do_boosted_frame_diags = 1 +electrons.do_back_transformed_diagnostics = 1 ions.charge = q_e ions.mass = m_p @@ -69,7 +69,7 @@ ions.zmax = .003 ions.profile = constant ions.density = 3.5e24 ions.do_continuous_injection = 1 -ions.do_boosted_frame_diags = 1 +ions.do_back_transformed_diagnostics = 1 beam.charge = -q_e beam.mass = m_e diff --git a/Examples/Physics_applications/laser_acceleration/inputs.2d.boost b/Examples/Physics_applications/laser_acceleration/inputs.2d.boost index 89bded6c0..a50b5164a 100644 --- a/Examples/Physics_applications/laser_acceleration/inputs.2d.boost +++ b/Examples/Physics_applications/laser_acceleration/inputs.2d.boost @@ -41,7 +41,7 @@ warpx.serialize_ics = 1 ################################# warpx.gamma_boost = 10. warpx.boost_direction = z -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 7 warpx.dt_snapshots_lab = 1.6678204759907604e-12 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs.2d.boost b/Examples/Physics_applications/plasma_acceleration/inputs.2d.boost index d711815eb..af4556e25 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs.2d.boost +++ b/Examples/Physics_applications/plasma_acceleration/inputs.2d.boost @@ -39,7 +39,7 @@ interpolation.noz = 3 ################################# warpx.gamma_boost = 10.0 warpx.boost_direction = z -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 22 warpx.dt_snapshots_lab = 3.335640951981521e-11 diff --git a/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost b/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost index 42446a9ac..79480c97f 100644 --- a/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost +++ b/Examples/Physics_applications/plasma_acceleration/inputs.3d.boost @@ -38,7 +38,7 @@ interpolation.noz = 3 ################################# warpx.gamma_boost = 10.0 warpx.boost_direction = z -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 22 warpx.dt_snapshots_lab = 3.335640951981521e-11 diff --git a/Python/pywarpx/picmi.py b/Python/pywarpx/picmi.py index c33700278..c4e6803d5 100644 --- a/Python/pywarpx/picmi.py +++ b/Python/pywarpx/picmi.py @@ -671,10 +671,10 @@ class LabFrameFieldDiagnostic(picmistandard.PICMI_LabFrameFieldDiagnostic): pywarpx.warpx.check_consistency('dt_snapshots_lab', self.dt_snapshots, 'The time between snapshots must be the same in all lab frame diagnostics') pywarpx.warpx.check_consistency('lab_data_directory', self.write_dir, 'The write directory must be the same in all lab frame diagnostics') - pywarpx.warpx.do_boosted_frame_diagnostic = 1 + pywarpx.warpx.do_back_transformed_diagnostics = 1 pywarpx.warpx.num_snapshots_lab = self.num_snapshots pywarpx.warpx.dt_snapshots_lab = self.dt_snapshots - pywarpx.warpx.do_boosted_frame_fields = 1 + pywarpx.warpx.do_back_transformed_fields = 1 pywarpx.warpx.lab_data_directory = self.write_dir @@ -685,8 +685,8 @@ class LabFrameParticleDiagnostic(picmistandard.PICMI_LabFrameParticleDiagnostic) pywarpx.warpx.check_consistency('dt_snapshots_lab', self.dt_snapshots, 'The time between snapshots must be the same in all lab frame diagnostics') pywarpx.warpx.check_consistency('lab_data_directory', self.write_dir, 'The write directory must be the same in all lab frame diagnostics') - pywarpx.warpx.do_boosted_frame_diagnostic = 1 + pywarpx.warpx.do_back_transformed_diagnostics = 1 pywarpx.warpx.num_snapshots_lab = self.num_snapshots pywarpx.warpx.dt_snapshots_lab = self.dt_snapshots - pywarpx.warpx.do_boosted_frame_particles = 1 + pywarpx.warpx.do_back_transformed_particles = 1 pywarpx.warpx.lab_data_directory = self.write_dir diff --git a/Source/Diagnostics/BoostedFrameDiagnostic.H b/Source/Diagnostics/BoostedFrameDiagnostic.H index 5d95aaf7d..9e24caa1b 100644 --- a/Source/Diagnostics/BoostedFrameDiagnostic.H +++ b/Source/Diagnostics/BoostedFrameDiagnostic.H @@ -1,5 +1,5 @@ -#ifndef WARPX_BoostedFrameDiagnostic_H_ -#define WARPX_BoostedFrameDiagnostic_H_ +#ifndef WARPX_BackTransformedDiagnostic_H_ +#define WARPX_BackTransformedDiagnostic_H_ #include #include @@ -150,7 +150,7 @@ class LabFrameSlice : public LabFrameDiag { }; /** \brief - * BoostedFrameDiagnostic class handles the back-transformation of data when + * BackTransformedDiagnostic class handles the back-transformation of data when * running simulations in a boosted frame of reference to the lab-frame. * Because of the relativity of simultaneity, events that are synchronized * in the simulation boosted frame are not @@ -163,13 +163,13 @@ class LabFrameSlice : public LabFrameDiag { * to the output directory. The functions Flush() and writeLabFrameData() * are called at the end of the simulation and when the * the buffer for data storage is full, respectively. The particle data - * is collected and written only if particle.do_boosted_frame_diagnostic = 1. + * is collected and written only if particle.do_back_transformed_diagnostics = 1. */ -class BoostedFrameDiagnostic { +class BackTransformedDiagnostic { public: - BoostedFrameDiagnostic(amrex::Real zmin_lab, amrex::Real zmax_lab, + BackTransformedDiagnostic(amrex::Real zmin_lab, amrex::Real zmax_lab, amrex::Real v_window_lab, amrex::Real dt_snapshots_lab, int N_snapshots, amrex::Real dt_slice_snapshots_lab, int N_slice_snapshots, amrex::Real gamma_boost, diff --git a/Source/Diagnostics/BoostedFrameDiagnostic.cpp b/Source/Diagnostics/BoostedFrameDiagnostic.cpp index 297b4f5be..2880b37b1 100644 --- a/Source/Diagnostics/BoostedFrameDiagnostic.cpp +++ b/Source/Diagnostics/BoostedFrameDiagnostic.cpp @@ -1,7 +1,7 @@ #include #include -#include "BoostedFrameDiagnostic.H" +#include "BackTransformedDiagnostic.H" #include "SliceDiagnostic.H" #include "WarpX_f.H" #include "WarpX.H" @@ -514,8 +514,8 @@ LorentzTransformZ(MultiFab& data, Real gamma_boost, Real beta_boost, int ncomp) } } -BoostedFrameDiagnostic:: -BoostedFrameDiagnostic(Real zmin_lab, Real zmax_lab, Real v_window_lab, +BackTransformedDiagnostic:: +BackTransformedDiagnostic(Real zmin_lab, Real zmax_lab, Real v_window_lab, Real dt_snapshots_lab, int N_snapshots, Real dt_slice_snapshots_lab, int N_slice_snapshots, Real gamma_boost, Real t_boost, Real dt_boost, @@ -531,10 +531,10 @@ BoostedFrameDiagnostic(Real zmin_lab, Real zmax_lab, Real v_window_lab, { - BL_PROFILE("BoostedFrameDiagnostic::BoostedFrameDiagnostic"); + BL_PROFILE("BackTransformedDiagnostic::BackTransformedDiagnostic"); - AMREX_ALWAYS_ASSERT(WarpX::do_boosted_frame_fields or - WarpX::do_boosted_frame_particles); + AMREX_ALWAYS_ASSERT(WarpX::do_back_transformed_fields or + WarpX::do_back_transformed_particles); inv_gamma_boost_ = 1.0 / gamma_boost_; beta_boost_ = std::sqrt(1.0 - inv_gamma_boost_*inv_gamma_boost_); @@ -679,9 +679,9 @@ BoostedFrameDiagnostic(Real zmin_lab, Real zmax_lab, Real v_window_lab, AMREX_ALWAYS_ASSERT(max_box_size_ >= num_buffer_); } -void BoostedFrameDiagnostic::Flush(const Geometry& geom) +void BackTransformedDiagnostic::Flush(const Geometry& geom) { - BL_PROFILE("BoostedFrameDiagnostic::Flush"); + BL_PROFILE("BackTransformedDiagnostic::Flush"); VisMF::Header::Version current_version = VisMF::GetHeaderVersion(); VisMF::SetHeaderVersion(amrex::VisMF::Header::NoFabHeader_v1); @@ -696,7 +696,7 @@ void BoostedFrameDiagnostic::Flush(const Geometry& geom) int i_lab = (LabFrameDiags_[i]->current_z_lab - zmin_lab) / dz_lab_; if (LabFrameDiags_[i]->buff_counter_ != 0) { - if (WarpX::do_boosted_frame_fields) { + if (WarpX::do_back_transformed_fields) { const BoxArray& ba = LabFrameDiags_[i]->data_buffer_->boxArray(); const int hi = ba[0].bigEnd(boost_direction_); const int lo = hi - LabFrameDiags_[i]->buff_counter_ + 1; @@ -731,12 +731,12 @@ void BoostedFrameDiagnostic::Flush(const Geometry& geom) #endif } - if (WarpX::do_boosted_frame_particles) { + if (WarpX::do_back_transformed_particles) { // Loop over species to be dumped to BFD - for (int j = 0; j < mypc.nSpeciesBoostedFrameDiags(); ++j) { + for (int j = 0; j < mypc.nSpeciesBackTransformedDiagnostics(); ++j) { // Get species name std::string species_name = - species_names[mypc.mapSpeciesBoostedFrameDiags(j)]; + species_names[mypc.mapSpeciesBackTransformedDiagnostics(j)]; #ifdef WARPX_USE_HDF5 // Dump species data writeParticleDataHDF5(LabFrameDiags_[i]->particles_buffer_[j], @@ -765,12 +765,12 @@ void BoostedFrameDiagnostic::Flush(const Geometry& geom) void -BoostedFrameDiagnostic:: +BackTransformedDiagnostic:: writeLabFrameData(const MultiFab* cell_centered_data, const MultiParticleContainer& mypc, const Geometry& geom, const Real t_boost, const Real dt) { - BL_PROFILE("BoostedFrameDiagnostic::writeLabFrameData"); + BL_PROFILE("BackTransformedDiagnostic::writeLabFrameData"); VisMF::Header::Version current_version = VisMF::GetHeaderVersion(); VisMF::SetHeaderVersion(amrex::VisMF::Header::NoFabHeader_v1); @@ -808,7 +808,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, // If buffer of snapshot i is empty... if ( LabFrameDiags_[i]->buff_counter_ == 0) { // ... reset fields buffer data_buffer_ - if (WarpX::do_boosted_frame_fields) { + if (WarpX::do_back_transformed_fields) { LabFrameDiags_[i]->buff_box_.setSmall(boost_direction_, i_lab - num_buffer_ + 1); LabFrameDiags_[i]->buff_box_.setBig(boost_direction_, i_lab); @@ -820,12 +820,12 @@ writeLabFrameData(const MultiFab* cell_centered_data, buff_dm, ncomp_to_dump, 0) ); } // ... reset particle buffer particles_buffer_[i] - if (WarpX::do_boosted_frame_particles) + if (WarpX::do_back_transformed_particles) LabFrameDiags_[i]->particles_buffer_.resize( - mypc.nSpeciesBoostedFrameDiags()); + mypc.nSpeciesBackTransformedDiagnostics()); } - if (WarpX::do_boosted_frame_fields) { + if (WarpX::do_back_transformed_fields) { const int ncomp = cell_centered_data->nComp(); const int start_comp = 0; const bool interpolate = true; @@ -873,7 +873,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, tmp_slice_ptr.reset(nullptr); } - if (WarpX::do_boosted_frame_particles) { + if (WarpX::do_back_transformed_particles) { if (LabFrameDiags_[i]->t_lab != prev_t_lab ) { if (tmp_particle_buffer.size()>0) @@ -881,7 +881,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, tmp_particle_buffer.clear(); tmp_particle_buffer.shrink_to_fit(); } - tmp_particle_buffer.resize(mypc.nSpeciesBoostedFrameDiags()); + tmp_particle_buffer.resize(mypc.nSpeciesBackTransformedDiagnostics()); mypc.GetLabFrameData( LabFrameDiags_[i]->file_name, i_lab, boost_direction_, old_z_boost, LabFrameDiags_[i]->current_z_boost, @@ -889,7 +889,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, tmp_particle_buffer); } LabFrameDiags_[i]->AddPartDataToParticleBuffer(tmp_particle_buffer, - mypc.nSpeciesBoostedFrameDiags()); + mypc.nSpeciesBackTransformedDiagnostics()); } ++LabFrameDiags_[i]->buff_counter_; @@ -898,7 +898,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, // If buffer full, write to disk. if ( LabFrameDiags_[i]->buff_counter_ == num_buffer_) { - if (WarpX::do_boosted_frame_fields) { + if (WarpX::do_back_transformed_fields) { #ifdef WARPX_USE_HDF5 Box buff_box = LabFrameDiags_[i]->buff_box_; @@ -916,12 +916,12 @@ writeLabFrameData(const MultiFab* cell_centered_data, #endif } - if (WarpX::do_boosted_frame_particles) { + if (WarpX::do_back_transformed_particles) { // Loop over species to be dumped to BFD - for (int j = 0; j < mypc.nSpeciesBoostedFrameDiags(); ++j) { + for (int j = 0; j < mypc.nSpeciesBackTransformedDiagnostics(); ++j) { // Get species name const std::string species_name = species_names[ - mypc.mapSpeciesBoostedFrameDiags(j)]; + mypc.mapSpeciesBackTransformedDiagnostics(j)]; #ifdef WARPX_USE_HDF5 // Write data to disk (HDF5) writeParticleDataHDF5(LabFrameDiags_[i]->particles_buffer_[j], @@ -949,7 +949,7 @@ writeLabFrameData(const MultiFab* cell_centered_data, #ifdef WARPX_USE_HDF5 void -BoostedFrameDiagnostic:: +BackTransformedDiagnostic:: writeParticleDataHDF5(const WarpXParticleContainer::DiagnosticParticleData& pdata, const std::string& name, const std::string& species_name) { @@ -997,11 +997,11 @@ writeParticleDataHDF5(const WarpXParticleContainer::DiagnosticParticleData& pdat #endif void -BoostedFrameDiagnostic:: +BackTransformedDiagnostic:: writeParticleData(const WarpXParticleContainer::DiagnosticParticleData& pdata, const std::string& name, const int i_lab) { - BL_PROFILE("BoostedFrameDiagnostic::writeParticleData"); + BL_PROFILE("BackTransformedDiagnostic::writeParticleData"); std::string field_name; std::ofstream ofs; @@ -1047,10 +1047,10 @@ writeParticleData(const WarpXParticleContainer::DiagnosticParticleData& pdata, } void -BoostedFrameDiagnostic:: +BackTransformedDiagnostic:: writeMetaData () { - BL_PROFILE("BoostedFrameDiagnostic::writeMetaData"); + BL_PROFILE("BackTransformedDiagnostic::writeMetaData"); if (ParallelDescriptor::IOProcessor()) { const std::string fullpath = WarpX::lab_data_directory + "/snapshots"; @@ -1134,7 +1134,7 @@ LabFrameSnapShot(Real t_lab_in, Real t_boost, Real inv_gamma_boost_in, file_num, 5); createLabFrameDirectories(); buff_counter_ = 0; - if (WarpX::do_boosted_frame_fields) data_buffer_.reset(nullptr); + if (WarpX::do_back_transformed_fields) data_buffer_.reset(nullptr); } void @@ -1158,7 +1158,7 @@ createLabFrameDirectories() { if (ParallelDescriptor::IOProcessor()) { - if (WarpX::do_boosted_frame_fields) + if (WarpX::do_back_transformed_fields) { const auto lo = lbound(buff_box_); for (int comp = 0; comp < ncomp_to_dump_; ++comp) { @@ -1176,15 +1176,15 @@ createLabFrameDirectories() { ParallelDescriptor::Barrier(); - if (WarpX::do_boosted_frame_particles){ + if (WarpX::do_back_transformed_particles){ auto & mypc = WarpX::GetInstance().GetPartContainer(); const std::vector species_names = mypc.GetSpeciesNames(); // Loop over species to be dumped to BFD - for (int j = 0; j < mypc.nSpeciesBoostedFrameDiags(); ++j) + for (int j = 0; j < mypc.nSpeciesBackTransformedDiagnostics(); ++j) { // Loop over species to be dumped to BFD std::string species_name = - species_names[mypc.mapSpeciesBoostedFrameDiags(j)]; + species_names[mypc.mapSpeciesBackTransformedDiagnostics(j)]; output_create_species_group(file_name, species_name); for (int k = 0; k < static_cast(particle_field_names.size()); ++k) { @@ -1211,10 +1211,10 @@ createLabFrameDirectories() { const std::string particles_prefix = "particle"; // Loop over species to be dumped to BFD - for(int i = 0; i < mypc.nSpeciesBoostedFrameDiags(); ++i) { + for(int i = 0; i < mypc.nSpeciesBackTransformedDiagnostics(); ++i) { // Get species name std::string species_name = - species_names[mypc.mapSpeciesBoostedFrameDiags(i)]; + species_names[mypc.mapSpeciesBackTransformedDiagnostics(i)]; const std::string fullpath = file_name + "/" + species_name; if (!UtilCreateDirectory(fullpath, 0755)) CreateDirectoryFailed(fullpath); @@ -1302,7 +1302,7 @@ LabFrameSlice(Real t_lab_in, Real t_boost, Real inv_gamma_boost_in, dx_ = cell_dx; dy_ = cell_dy; - if (WarpX::do_boosted_frame_fields) data_buffer_.reset(nullptr); + if (WarpX::do_back_transformed_fields) data_buffer_.reset(nullptr); } void diff --git a/Source/Diagnostics/Make.package b/Source/Diagnostics/Make.package index dfd947d53..b624d6ebe 100644 --- a/Source/Diagnostics/Make.package +++ b/Source/Diagnostics/Make.package @@ -1,9 +1,9 @@ CEXE_sources += WarpXIO.cpp -CEXE_sources += BoostedFrameDiagnostic.cpp +CEXE_sources += BackTransformedDiagnostic.cpp CEXE_sources += ParticleIO.cpp CEXE_sources += FieldIO.cpp CEXE_headers += FieldIO.H -CEXE_headers += BoostedFrameDiagnostic.H +CEXE_headers += BackTransformedDiagnostic.H CEXE_headers += ElectrostaticIO.cpp CEXE_headers += SliceDiagnostic.H CEXE_sources += SliceDiagnostic.cpp diff --git a/Source/Evolve/WarpXEvolveEM.cpp b/Source/Evolve/WarpXEvolveEM.cpp index 7a3262703..b5fd52bdc 100644 --- a/Source/Evolve/WarpXEvolveEM.cpp +++ b/Source/Evolve/WarpXEvolveEM.cpp @@ -141,9 +141,9 @@ WarpX::EvolveEM (int numsteps) bool do_insitu = ((step+1) >= insitu_start) && (insitu_int > 0) && ((step+1) % insitu_int == 0); - if (do_boosted_frame_diagnostic) { + if (do_back_transformed_diagnostics) { std::unique_ptr cell_centered_data = nullptr; - if (WarpX::do_boosted_frame_fields) { + if (WarpX::do_back_transformed_fields) { cell_centered_data = GetCellCenteredData(); } myBFD->writeLabFrameData(cell_centered_data.get(), *mypc, geom[0], cur_time, dt[0]); @@ -261,7 +261,7 @@ WarpX::EvolveEM (int numsteps) WriteCheckPointFile(); } - if (do_boosted_frame_diagnostic) { + if (do_back_transformed_diagnostics) { myBFD->Flush(geom[0]); } diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index 78eaebfc5..6224d5348 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -82,14 +82,14 @@ WarpX::InitData () void WarpX::InitDiagnostics () { - if (do_boosted_frame_diagnostic) { + if (do_back_transformed_diagnostics) { const Real* current_lo = geom[0].ProbLo(); const Real* current_hi = geom[0].ProbHi(); Real dt_boost = dt[0]; // Find the positions of the lab-frame box that corresponds to the boosted-frame box at t=0 Real zmin_lab = current_lo[moving_window_dir]/( (1.+beta_boost)*gamma_boost ); Real zmax_lab = current_hi[moving_window_dir]/( (1.+beta_boost)*gamma_boost ); - myBFD.reset(new BoostedFrameDiagnostic(zmin_lab, + myBFD.reset(new BackTransformedDiagnostic(zmin_lab, zmax_lab, moving_window_v, dt_snapshots_lab, num_snapshots_lab, diff --git a/Source/Laser/LaserParticleContainer.cpp b/Source/Laser/LaserParticleContainer.cpp index 8571c74ad..b9ab20197 100644 --- a/Source/Laser/LaserParticleContainer.cpp +++ b/Source/Laser/LaserParticleContainer.cpp @@ -26,7 +26,7 @@ LaserParticleContainer::LaserParticleContainer (AmrCore* amr_core, int ispecies, { charge = 1.0; mass = std::numeric_limits::max(); - do_boosted_frame_diags = 0; + do_back_transformed_diagnostics = 0; ParmParse pp(laser_name); diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 949173052..30f7354d0 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -162,9 +162,9 @@ public: int nSpecies() const {return nspecies;} - int nSpeciesBoostedFrameDiags() const {return nspecies_boosted_frame_diags;} - int mapSpeciesBoostedFrameDiags(int i) const {return map_species_boosted_frame_diags[i];} - int doBoostedFrameDiags() const {return do_boosted_frame_diags;} + int nSpeciesBackTransformedDiagnostics() const {return nspecies_back_transformed_diagnostics;} + int mapSpeciesBackTransformedDiagnostics(int i) const {return map_species_back_transformed_diagnostics[i];} + int doBackTransformedDiagnostics() const {return do_back_transformed_diagnostics;} int nSpeciesDepositOnMainGrid () const { bool const onMainGrid = true; @@ -236,12 +236,12 @@ 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 - // MultiParticleContainer for 0 map_species_boosted_frame_diags; - int do_boosted_frame_diags = 0; + // Number of species dumped in BackTransformedDiagnostics + int nspecies_back_transformed_diagnostics = 0; + // map_species_back_transformed_diagnostics[i] is the species ID in + // MultiParticleContainer for 0 map_species_back_transformed_diagnostics; + int do_back_transformed_diagnostics = 0; // runtime parameters int nlasers = 0; diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index f4c00404b..63aa500e9 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -38,14 +38,14 @@ MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) // Compute the number of species for which lab-frame data is dumped // nspecies_lab_frame_diags, and map their ID to MultiParticleContainer // particle IDs in map_species_lab_diags. - map_species_boosted_frame_diags.resize(nspecies); - nspecies_boosted_frame_diags = 0; + map_species_back_transformed_diagnostics.resize(nspecies); + nspecies_back_transformed_diagnostics = 0; for (int i=0; ido_boosted_frame_diags){ - map_species_boosted_frame_diags[nspecies_boosted_frame_diags] = i; - do_boosted_frame_diags = 1; - nspecies_boosted_frame_diags += 1; + if (pc->do_back_transformed_diagnostics){ + map_species_back_transformed_diagnostics[nspecies_back_transformed_diagnostics] = i; + do_back_transformed_diagnostics = 1; + nspecies_back_transformed_diagnostics += 1; } } } @@ -387,8 +387,8 @@ MultiParticleContainer BL_PROFILE("MultiParticleContainer::GetLabFrameData"); // Loop over particle species - for (int i = 0; i < nspecies_boosted_frame_diags; ++i){ - int isp = map_species_boosted_frame_diags[i]; + for (int i = 0; i < nspecies_back_transformed_diagnostics; ++i){ + int isp = map_species_back_transformed_diagnostics[i]; WarpXParticleContainer* pc = allcontainers[isp].get(); WarpXParticleContainer::DiagnosticParticles diagnostic_particles; pc->GetParticleSlice(direction, z_old, z_new, t_boost, t_lab, dt, diagnostic_particles); @@ -603,9 +603,9 @@ namespace } // --- product runtime attribs GpuArray runtime_attribs_product; - bool do_boosted_product = WarpX::do_boosted_frame_diagnostic - && pc_product->DoBoostedFrameDiags(); - if (do_boosted_product) { + bool do_back_transformed_product = WarpX::do_back_transformed_diagnostics + && pc_product->doBackTransformedDiagnostics(); + if (do_back_transformed_product) { std::map comps_product = pc_product->getParticleComps(); runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; runtime_attribs_product[1] = soa_product.GetRealData(comps_product[ "yold"]).data() + np_product_old; @@ -652,7 +652,7 @@ namespace // Update xold etc. if boosted frame diagnostics required // for product species. Fill runtime attribs with a copy of // current properties (xold = x etc.). - if (do_boosted_product) { + if (do_back_transformed_product) { runtime_attribs_product[0][ip] = p_source.pos(0); runtime_attribs_product[1][ip] = p_source.pos(1); runtime_attribs_product[2][ip] = p_source.pos(2); diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index cf2ffbec4..612da01ca 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -73,7 +73,7 @@ PhotonParticleContainer::PushPX(WarpXParIter& pti, const ParticleReal* const AMREX_RESTRICT By = attribs[PIdx::By].dataPtr(); const ParticleReal* const AMREX_RESTRICT Bz = attribs[PIdx::Bz].dataPtr(); - if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags) + if (WarpX::do_back_transformed_diagnostics && do_back_transformed_diagnostics) { copy_attribs(pti, x, y, z); } diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d12a4dbff..d451ed32b 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -43,7 +43,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_continuous_injection", do_continuous_injection); // Whether to plot back-transformed (lab-frame) diagnostics // for this species. - pp.query("do_boosted_frame_diags", do_boosted_frame_diags); + pp.query("do_back_transformed_diagnostics", do_back_transformed_diagnostics); pp.query("do_field_ionization", do_field_ionization); @@ -86,7 +86,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp //variable to set plot_flags size int plot_flag_size = PIdx::nattribs; - if(WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags) + if(WarpX::do_back_transformed_diagnostics && do_back_transformed_diagnostics) plot_flag_size += 6; #ifdef WARPX_QED @@ -1078,7 +1078,7 @@ PhysicalParticleContainer::Evolve (int lev, bool has_buffer = cEx || cjx; - if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags) + if (WarpX::do_back_transformed_diagnostics && do_back_transformed_diagnostics) { for (WarpXParIter pti(*this, lev); pti.isValid(); ++pti) { @@ -1585,7 +1585,7 @@ PhysicalParticleContainer::PushPX(WarpXParIter& pti, const ParticleReal* const AMREX_RESTRICT By = attribs[PIdx::By].dataPtr(); const ParticleReal* const AMREX_RESTRICT Bz = attribs[PIdx::Bz].dataPtr(); - if (WarpX::do_boosted_frame_diagnostic && do_boosted_frame_diags && (a_dt_type!=DtType::SecondHalf)) + if (WarpX::do_back_transformed_diagnostics && do_back_transformed_diagnostics && (a_dt_type!=DtType::SecondHalf)) { copy_attribs(pti, x, y, z); } @@ -1842,7 +1842,7 @@ void PhysicalParticleContainer::GetParticleSlice(const int direction, const Real // Note the the slice should always move in the negative boost direction. AMREX_ALWAYS_ASSERT(z_new < z_old); - AMREX_ALWAYS_ASSERT(do_boosted_frame_diags == 1); + AMREX_ALWAYS_ASSERT(do_back_transformed_diagnostics == 1); const int nlevs = std::max(0, finestLevel()+1); diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 879f4782e..8930cb176 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -273,7 +273,7 @@ public: AddIntComp(comm); } - int DoBoostedFrameDiags () const { return do_boosted_frame_diags; } + int doBackTransformedDiagnostics () const { return do_back_transformed_diagnostics; } virtual void buildIonizationMask (const amrex::MFIter& mfi, const int lev, amrex::Gpu::ManagedDeviceVector& ionization_mask) @@ -316,7 +316,7 @@ protected: amrex::Gpu::ManagedVector adk_exp_prefactor; std::string physical_element; - int do_boosted_frame_diags = 1; + int do_back_transformed_diagnostics = 1; #ifdef WARPX_QED bool do_qed = false; diff --git a/Source/WarpX.H b/Source/WarpX.H index 6ecc584a2..0084ba64c 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -4,7 +4,7 @@ #include "WarpXDtType.H" #include #include -#include +#include #include #include @@ -100,12 +100,12 @@ public: static bool serialize_ics; // Back transformation diagnostic - static bool do_boosted_frame_diagnostic; + static bool do_back_transformed_diagnostics; static std::string lab_data_directory; static int num_snapshots_lab; static amrex::Real dt_snapshots_lab; - static bool do_boosted_frame_fields; - static bool do_boosted_frame_particles; + static bool do_back_transformed_fields; + static bool do_back_transformed_particles; // Boosted frame parameters static amrex::Real gamma_boost; @@ -478,7 +478,7 @@ private: std::unique_ptr mypc; // Boosted Frame Diagnostics - std::unique_ptr myBFD; + std::unique_ptr myBFD; // // Fields: First array for level, second for direction diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 9ba0741bb..b329f5252 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -61,12 +61,12 @@ int WarpX::num_mirrors = 0; int WarpX::sort_int = -1; -bool WarpX::do_boosted_frame_diagnostic = false; +bool WarpX::do_back_transformed_diagnostics = false; std::string WarpX::lab_data_directory = "lab_frame_data"; int WarpX::num_snapshots_lab = std::numeric_limits::lowest(); Real WarpX::dt_snapshots_lab = std::numeric_limits::lowest(); -bool WarpX::do_boosted_frame_fields = true; -bool WarpX::do_boosted_frame_particles = true; +bool WarpX::do_back_transformed_fields = true; +bool WarpX::do_back_transformed_particles = true; int WarpX::num_slice_snapshots_lab = 0; Real WarpX::dt_slice_snapshots_lab; @@ -168,7 +168,7 @@ WarpX::WarpX () current_injection_position = geom[0].ProbLo(moving_window_dir); } } - do_boosted_frame_particles = mypc->doBoostedFrameDiags(); + do_back_transformed_particles = mypc->doBackTransformedDiagnostics(); Efield_aux.resize(nlevs_max); Bfield_aux.resize(nlevs_max); @@ -324,8 +324,8 @@ WarpX::ReadParameters () moving_window_v *= PhysConst::c; } - pp.query("do_boosted_frame_diagnostic", do_boosted_frame_diagnostic); - if (do_boosted_frame_diagnostic) { + pp.query("do_back_transformed_diagnostics", do_back_transformed_diagnostics); + if (do_back_transformed_diagnostics) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(gamma_boost > 1.0, "gamma_boost must be > 1 to use the boosted frame diagnostic."); @@ -353,7 +353,7 @@ WarpX::ReadParameters () pp.get("gamma_boost", gamma_boost); - pp.query("do_boosted_frame_fields", do_boosted_frame_fields); + pp.query("do_back_transformed_fields", do_back_transformed_fields); AMREX_ALWAYS_ASSERT_WITH_MESSAGE(do_moving_window, "The moving window should be on if using the boosted frame diagnostic."); @@ -600,7 +600,7 @@ WarpX::ReadParameters () } } - if (do_boosted_frame_diagnostic) { + if (do_back_transformed_diagnostics) { AMREX_ALWAYS_ASSERT_WITH_MESSAGE(gamma_boost > 1.0, "gamma_boost must be > 1 to use the boost frame diagnostic"); pp.query("num_slice_snapshots_lab", num_slice_snapshots_lab); diff --git a/Tools/performance_tests/automated_test_4_labdiags_2ppc b/Tools/performance_tests/automated_test_4_labdiags_2ppc index 282c93331..bac071f63 100644 --- a/Tools/performance_tests/automated_test_4_labdiags_2ppc +++ b/Tools/performance_tests/automated_test_4_labdiags_2ppc @@ -35,7 +35,7 @@ warpx.gamma_boost = 15. warpx.boost_direction = z # Diagnostics -warpx.do_boosted_frame_diagnostic = 1 +warpx.do_back_transformed_diagnostics = 1 warpx.num_snapshots_lab = 20 warpx.dt_snapshots_lab = 7.0e-14 -- cgit v1.2.3 From edaca2ba13564df6227dd399851c1f26b47d69bf Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Mon, 28 Oct 2019 16:47:25 -0700 Subject: replace 'boosted frame' with 'back-transformed' diags --- Source/Particles/MultiParticleContainer.cpp | 8 ++++---- Source/Particles/ParticleCreation/CopyParticle.H | 8 ++++---- Source/Particles/ParticleCreation/ElementaryProcess.H | 18 +++++++++--------- 3 files changed, 17 insertions(+), 17 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 4e5f12420..9cf535131 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -596,14 +596,14 @@ MultiParticleContainer::doFieldIonization () amrex::Gpu::ManagedDeviceVector is_ionized; pc_source->buildIonizationMask(mfi, lev, is_ionized); // Create particles in pc_product - int do_boost = WarpX::do_boosted_frame_diagnostic - && pc_product->DoBoostedFrameDiags(); - amrex::Gpu::ManagedDeviceVector v_do_boosted_product{do_boost}; + int do_boost = WarpX::do_back_transformed_diagnostics + && pc_product->doBackTransformedDiagnostics(); + amrex::Gpu::ManagedDeviceVector v_do_back_transformed_product{do_boost}; const amrex::Vector v_pc_product {pc_product.get()}; // Copy source to product particles, and increase ionization // level of source particle ionization_process.createParticles(lev, mfi, pc_source, v_pc_product, - is_ionized, v_do_boosted_product); + is_ionized, v_do_back_transformed_product); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/CopyParticle.H b/Source/Particles/ParticleCreation/CopyParticle.H index fb3eca86b..bd2d530fb 100644 --- a/Source/Particles/ParticleCreation/CopyParticle.H +++ b/Source/Particles/ParticleCreation/CopyParticle.H @@ -21,7 +21,7 @@ public: // ID of MPI rank int m_cpuid; // If true, will copy old attribs for back-transforme diagnostics - bool m_do_boosted_product; + bool m_do_back_transformed_product; // Source old (runtime) attribs for back-transformed diagnostics amrex::GpuArray m_runtime_uold_source; // Source attribs @@ -34,14 +34,14 @@ public: // Simple constructor AMREX_GPU_HOST_DEVICE copyParticle( - const int cpuid, const int do_boosted_product, + const int cpuid, const int do_back_transformed_product, const amrex::GpuArray runtime_uold_source, const amrex::GpuArray attribs_source, const amrex::GpuArray attribs_product, const amrex::GpuArray runtime_attribs_product) : m_cpuid(cpuid), - m_do_boosted_product(do_boosted_product), + m_do_back_transformed_product(do_back_transformed_product), m_runtime_uold_source(runtime_uold_source), m_attribs_source(attribs_source), m_attribs_product(attribs_product), @@ -76,7 +76,7 @@ public: // Update xold etc. if boosted frame diagnostics required // for product species. Fill runtime attribs with a copy of // current properties (xold = x etc.). - if (m_do_boosted_product) { + if (m_do_back_transformed_product) { m_runtime_attribs_product[0][ip] = p_source.pos(0); m_runtime_attribs_product[1][ip] = p_source.pos(1); m_runtime_attribs_product[2][ip] = p_source.pos(2); diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index e9143ed5a..bca3f3679 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -30,21 +30,21 @@ public: * \brief initialize and return functor for particle copy * * \param cpuid id of MPI rank - * \param do_boosted_product whether to copy old attribs + * \param do_back_transformed_product whether to copy old attribs * \param runtime_uold_source momentum of source particles * \param attribs_source attribs of source particles * \param attribs_product attribs of product particles * \param runtime_attribs_product runtime attribs for product, to store old attribs */ copyParticle initialize_copy( - const int cpuid, const int do_boosted_product, + const int cpuid, const int do_back_transformed_product, const amrex::GpuArray runtime_uold_source, const amrex::GpuArray attribs_source, const amrex::GpuArray attribs_product, const amrex::GpuArray runtime_attribs_product) const noexcept { return copyParticle ( - cpuid, do_boosted_product, runtime_uold_source, + cpuid, do_back_transformed_product, runtime_uold_source, attribs_source, attribs_product, runtime_attribs_product); }; @@ -59,7 +59,7 @@ public: * \param pc_source source particle container * \param v_pc_product vector of product particle containers * \param is_flagged particles for which is_flagged is 1 are copied - * \param v_do_boosted_product vector: whether to copy old attribs for + * \param v_do_back_transformed_product vector: whether to copy old attribs for * each product container */ void createParticles ( @@ -67,7 +67,7 @@ public: std::unique_ptr< WarpXParticleContainer>& pc_source, amrex::Vector v_pc_product, amrex::Gpu::ManagedDeviceVector& is_flagged, - amrex::Gpu::ManagedDeviceVector v_do_boosted_product) + amrex::Gpu::ManagedDeviceVector v_do_back_transformed_product) { BL_PROFILE("createParticles"); @@ -100,8 +100,8 @@ public: int nproducts = v_pc_product.size(); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( - v_do_boosted_product.size() == nproducts, - "v_pc_product and v_do_boosted_product must have the same size."); + v_do_back_transformed_product.size() == nproducts, + "v_pc_product and v_do_back_transformed_product must have the same size."); // Indices of product particle for each source particle. // i_product[i]-1 is the location in product tile of product particle @@ -149,7 +149,7 @@ public: } // --- product runtime attribs amrex::GpuArray runtime_attribs_product; - const int do_boost = v_do_boosted_product[iproduct]; + const int do_boost = v_do_back_transformed_product[iproduct]; if (do_boost) { std::map comps_product = pc_product->getParticleComps(); runtime_attribs_product[0] = soa_product.GetRealData(comps_product[ "xold"]).data() + np_product_old; @@ -173,7 +173,7 @@ public: // Create instance of copy functor, and add it to the vector v_copy_functor.push_back (initialize_copy( - cpuid, v_do_boosted_product[iproduct], + cpuid, v_do_back_transformed_product[iproduct], runtime_uold_source, attribs_source, attribs_product, -- cgit v1.2.3 From 02a5a2f105d612508df817d98781a5d628624aea Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 29 Oct 2019 10:50:30 -0700 Subject: call StreamSynchronize at the end of functions where arrays are allocated on GPU --- Source/Particles/MultiParticleContainer.cpp | 1 + Source/Particles/ParticleCreation/ElementaryProcess.H | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 9cf535131..0dbc55676 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -604,6 +604,7 @@ MultiParticleContainer::doFieldIonization () // level of source particle ionization_process.createParticles(lev, mfi, pc_source, v_pc_product, is_ionized, v_do_back_transformed_product); + Gpu::streamSynchronize(); } } // lev } // pc_source diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index bca3f3679..cfd9d1d62 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -185,6 +185,7 @@ public: copyAndTransformParticles(is_flagged, i_product, np_source, v_pid_product, v_particles_product, particles_source, v_copy_functor, runtime_iattribs_source); + amrex::Gpu::streamSynchronize(); } /** @@ -244,7 +245,7 @@ public: } } ); - amrex::Gpu::streamSynchronize(); + } }; -- cgit v1.2.3 From 102a6a070ab0c068b8cb9a4704b421772edcbe9e Mon Sep 17 00:00:00 2001 From: MaxThevenet Date: Tue, 29 Oct 2019 12:05:07 -0700 Subject: add comments to explain cudaSynchroniwe --- Source/Particles/MultiParticleContainer.cpp | 2 ++ Source/Particles/ParticleCreation/ElementaryProcess.H | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 0dbc55676..de2b4583d 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -604,6 +604,8 @@ MultiParticleContainer::doFieldIonization () // level of source particle ionization_process.createParticles(lev, mfi, pc_source, v_pc_product, is_ionized, v_do_back_transformed_product); + // Synchronize to prevent the destruction of temporary arrays (at the + // end of the function call) before the kernel executes. Gpu::streamSynchronize(); } } // lev diff --git a/Source/Particles/ParticleCreation/ElementaryProcess.H b/Source/Particles/ParticleCreation/ElementaryProcess.H index cfd9d1d62..fa791c244 100644 --- a/Source/Particles/ParticleCreation/ElementaryProcess.H +++ b/Source/Particles/ParticleCreation/ElementaryProcess.H @@ -185,6 +185,8 @@ public: copyAndTransformParticles(is_flagged, i_product, np_source, v_pid_product, v_particles_product, particles_source, v_copy_functor, runtime_iattribs_source); + // Synchronize to prevent the destruction of temporary arrays (at the + // end of the function call) before the kernel executes. amrex::Gpu::streamSynchronize(); } @@ -245,7 +247,6 @@ public: } } ); - } }; -- cgit v1.2.3 From e291b723665b72be079a5026e25dd1ce2a7c70dd Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 30 Oct 2019 10:37:27 +0100 Subject: now using nspecies_quantum_sync and nspecies_breit_wheeler --- Source/Particles/MultiParticleContainer.H | 21 +++++++++++++-------- Source/Particles/MultiParticleContainer.cpp | 11 +++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 4616005eb..7df0fbdf8 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -1,13 +1,8 @@ #ifndef WARPX_ParticleContainer_H_ #define WARPX_ParticleContainer_H_ -<<<<<<< HEAD -#include -#include -======= #include "ElementaryProcess.H" ->>>>>>> upstream/dev #include #include #include @@ -235,11 +230,21 @@ protected: */ void InitQED (); - //Flags to store if at least one species needs a QED process - bool someone_has_quantum_sync = false; - bool someone_has_breit_wheeler = false; + //Variables to store how many species need a QED process + int nspecies_quantum_sync = 0; + int nspecies_breit_wheeler = 0; //________ + /** + * Returns the number of species having Quantum Synchrotron process enabled + */ + int NSpeciesQuantumSync() const { return nspecies_quantum_sync;} + + /** + * Returns the number of species having Breit Wheeler process enabled + */ + int NSpeciesBreitWheeler() const { return nspecies_breit_wheeler;} + /** * Initializes the Quantum Synchrotron engine */ diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 02ba4fa87..a30d0699c 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -626,23 +626,26 @@ void MultiParticleContainer::InitQED () shr_p_qs_engine = std::make_shared(); shr_p_bw_engine = std::make_shared(); + nspecies_quantum_sync = 0; + nspecies_breit_wheeler = 0; + for (auto& pc : allcontainers) { if(pc->has_quantum_sync()){ pc->set_quantum_sync_engine_ptr (shr_p_qs_engine); - someone_has_quantum_sync = true; + nspecies_quantum_sync++; } if(pc->has_breit_wheeler()){ pc->set_breit_wheeler_engine_ptr (shr_p_bw_engine); - someone_has_breit_wheeler = true; + nspecies_breit_wheeler++; } } - if(someone_has_quantum_sync) + if(nspecies_quantum_sync != 0) InitQuantumSync(); - if(someone_has_breit_wheeler) + if(nspecies_breit_wheeler !=0) InitBreitWheeler(); } -- cgit v1.2.3 From fa33c9e67a23ca0cfc48a7a54fea5ec8fd0da015 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 30 Oct 2019 11:38:16 +0100 Subject: refactoring to comply with new style guidelines --- Source/Diagnostics/ParticleIO.cpp | 2 +- Source/Particles/MultiParticleContainer.H | 12 +-- Source/Particles/MultiParticleContainer.cpp | 36 ++++---- Source/Particles/PhotonParticleContainer.cpp | 6 +- Source/Particles/PhysicalParticleContainer.H | 8 +- Source/Particles/PhysicalParticleContainer.cpp | 24 +++--- Source/Particles/WarpXParticleContainer.H | 2 +- Source/QED/BreitWheelerEngineWrapper.H | 44 +++++----- Source/QED/BreitWheelerEngineWrapper.cpp | 114 ++++++++++++------------- Source/QED/QuantumSyncEngineWrapper.H | 44 +++++----- Source/QED/QuantumSyncEngineWrapper.cpp | 108 +++++++++++------------ 11 files changed, 200 insertions(+), 200 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Diagnostics/ParticleIO.cpp b/Source/Diagnostics/ParticleIO.cpp index d55660b39..3b7481b8c 100644 --- a/Source/Diagnostics/ParticleIO.cpp +++ b/Source/Diagnostics/ParticleIO.cpp @@ -113,7 +113,7 @@ MultiParticleContainer::WritePlotFile (const std::string& dir) const } #ifdef WARPX_QED - if(pc->do_qed){ + if(pc->m_do_qed){ real_names.push_back("tau"); } #endif diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 7df0fbdf8..f9a0e51d7 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -220,8 +220,8 @@ protected: #ifdef WARPX_QED // The QED engines - std::shared_ptr shr_p_bw_engine; - std::shared_ptr shr_p_qs_engine; + std::shared_ptr m_shr_p_bw_engine; + std::shared_ptr m_shr_p_qs_engine; //_______________________________ /** @@ -231,19 +231,19 @@ protected: void InitQED (); //Variables to store how many species need a QED process - int nspecies_quantum_sync = 0; - int nspecies_breit_wheeler = 0; + int m_nspecies_quantum_sync = 0; + int m_nspecies_breit_wheeler = 0; //________ /** * Returns the number of species having Quantum Synchrotron process enabled */ - int NSpeciesQuantumSync() const { return nspecies_quantum_sync;} + int NSpeciesQuantumSync() const { return m_nspecies_quantum_sync;} /** * Returns the number of species having Breit Wheeler process enabled */ - int NSpeciesBreitWheeler() const { return nspecies_breit_wheeler;} + int NSpeciesBreitWheeler() const { return m_nspecies_breit_wheeler;} /** * Initializes the Quantum Synchrotron engine diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index a30d0699c..8dc969e8f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -623,22 +623,22 @@ MultiParticleContainer::doFieldIonization () #ifdef WARPX_QED void MultiParticleContainer::InitQED () { - shr_p_qs_engine = std::make_shared(); - shr_p_bw_engine = std::make_shared(); + m_shr_p_qs_engine = std::make_shared(); + m_shr_p_bw_engine = std::make_shared(); - nspecies_quantum_sync = 0; - nspecies_breit_wheeler = 0; + m_nspecies_quantum_sync = 0; + m_nspecies_breit_wheeler = 0; for (auto& pc : allcontainers) { if(pc->has_quantum_sync()){ pc->set_quantum_sync_engine_ptr - (shr_p_qs_engine); - nspecies_quantum_sync++; + (m_shr_p_qs_engine); + m_nspecies_quantum_sync++; } if(pc->has_breit_wheeler()){ pc->set_breit_wheeler_engine_ptr - (shr_p_bw_engine); - nspecies_breit_wheeler++; + (m_shr_p_bw_engine); + m_nspecies_breit_wheeler++; } } @@ -666,8 +666,8 @@ void MultiParticleContainer::InitQuantumSync () if(generate_table && ParallelDescriptor::IOProcessor()){ - shr_p_qs_engine->compute_lookup_tables(ctrl); - Vector all_data = shr_p_qs_engine->export_lookup_tables_data(); + m_shr_p_qs_engine->compute_lookup_tables(ctrl); + Vector all_data = m_shr_p_qs_engine->export_lookup_tables_data(); WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); } ParallelDescriptor::Barrier(); @@ -679,10 +679,10 @@ void MultiParticleContainer::InitQuantumSync () //No need to initialize from raw data for the processor that //has just generated the table if(!generate_table || !ParallelDescriptor::IOProcessor()){ - shr_p_qs_engine->init_lookup_tables_from_raw_data(table_data); + m_shr_p_qs_engine->init_lookup_tables_from_raw_data(table_data); } - if(!shr_p_qs_engine->are_lookup_tables_initialized()) + if(!m_shr_p_qs_engine->are_lookup_tables_initialized()) amrex::Error("Table initialization has failed!\n"); } @@ -701,8 +701,8 @@ void MultiParticleContainer::InitBreitWheeler () //_________________________________________________ if(generate_table && ParallelDescriptor::IOProcessor()){ - shr_p_bw_engine->compute_lookup_tables(ctrl); - Vector all_data =shr_p_bw_engine->export_lookup_tables_data(); + m_shr_p_bw_engine->compute_lookup_tables(ctrl); + Vector all_data = m_shr_p_bw_engine->export_lookup_tables_data(); WarpXUtilIO::WriteBinaryDataOnFile(filename, all_data); } ParallelDescriptor::Barrier(); @@ -714,10 +714,10 @@ void MultiParticleContainer::InitBreitWheeler () //No need to initialize from raw data for the processor that //has just generated the table if(!generate_table || !ParallelDescriptor::IOProcessor()){ - shr_p_bw_engine->init_lookup_tables_from_raw_data(table_data); + m_shr_p_bw_engine->init_lookup_tables_from_raw_data(table_data); } - if(!shr_p_bw_engine->are_lookup_tables_initialized()) + if(!m_shr_p_bw_engine->are_lookup_tables_initialized()) amrex::Error("Table initialization has failed!\n"); } @@ -725,7 +725,7 @@ std::tuple MultiParticleContainer::ParseQuantumSyncParams () { PicsarQuantumSynchrotronCtrl ctrl = - shr_p_qs_engine->get_default_ctrl(); + m_shr_p_qs_engine->get_default_ctrl(); bool generate_table{false}; std::string table_name; @@ -783,7 +783,7 @@ std::tuple MultiParticleContainer::ParseBreitWheelerParams () { PicsarBreitWheelerCtrl ctrl = - shr_p_bw_engine->get_default_ctrl(); + m_shr_p_bw_engine->get_default_ctrl(); bool generate_table{false}; std::string table_name; diff --git a/Source/Particles/PhotonParticleContainer.cpp b/Source/Particles/PhotonParticleContainer.cpp index 612da01ca..7e52b52e1 100644 --- a/Source/Particles/PhotonParticleContainer.cpp +++ b/Source/Particles/PhotonParticleContainer.cpp @@ -26,9 +26,9 @@ PhotonParticleContainer::PhotonParticleContainer (AmrCore* amr_core, int ispecie ParmParse pp(species_name); #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); + //IF m_do_qed is enabled, find out if Breit Wheeler process is enabled + if(m_do_qed) + pp.query("do_qed_breit_wheeler", m_do_qed_breit_wheeler); //Check for processes which do not make sense for photons bool test_quantum_sync = false; diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index ed3a698e2..17a504719 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -220,16 +220,16 @@ protected: #ifdef WARPX_QED // A flag to enable quantum_synchrotron process for leptons - bool do_qed_quantum_sync = false; + bool m_do_qed_quantum_sync = false; // A flag to enable breit_wheeler process [photons only!!] - bool do_qed_breit_wheeler = false; + bool m_do_qed_breit_wheeler = false; // A smart pointer to an instance of a Quantum Synchrotron engine - std::shared_ptr shr_ptr_qs_engine; + std::shared_ptr m_shr_p_qs_engine; // A smart pointer to an instance of a Breit Wheeler engine [photons only!] - std::shared_ptr shr_ptr_bw_engine; + std::shared_ptr m_shr_p_bw_engine; #endif }; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index fed7266e1..51690d659 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -74,13 +74,13 @@ 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) + pp.query("do_qed", m_do_qed); + if(m_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); + if(m_do_qed) + pp.query("do_qed_quantum_sync", m_do_qed_quantum_sync); //TODO: SHOULD CHECK IF SPECIES IS EITHER ELECTRONS OR POSITRONS!! #endif @@ -91,7 +91,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp plot_flag_size += 6; #ifdef WARPX_QED - if(do_qed){ + if(m_do_qed){ // plot_flag will have an entry for the optical depth plot_flag_size++; } @@ -123,7 +123,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp } #ifdef WARPX_QED - if(do_qed){ + if(m_do_qed){ //Optical depths is always plotted if QED is on plot_flags[plot_flag_size-1] = 1; } @@ -544,11 +544,11 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) BreitWheelerGetOpticalDepth breit_wheeler_get_opt; if(loc_has_quantum_sync){ quantum_sync_get_opt = - shr_ptr_qs_engine->build_optical_depth_functor(); + m_shr_p_qs_engine->build_optical_depth_functor(); } if(loc_has_breit_wheeler){ breit_wheeler_get_opt = - shr_ptr_bw_engine->build_optical_depth_functor(); + m_shr_p_bw_engine->build_optical_depth_functor(); } #endif @@ -2238,25 +2238,25 @@ PhysicalParticleContainer::AmIALepton(){ bool PhysicalParticleContainer::has_quantum_sync() { - return do_qed_quantum_sync; + return m_do_qed_quantum_sync; } bool PhysicalParticleContainer::has_breit_wheeler() { - return do_qed_breit_wheeler; + return m_do_qed_breit_wheeler; } void PhysicalParticleContainer:: set_breit_wheeler_engine_ptr(std::shared_ptr ptr) { - shr_ptr_bw_engine = ptr; + m_shr_p_bw_engine = ptr; } void PhysicalParticleContainer:: set_quantum_sync_engine_ptr(std::shared_ptr ptr) { - shr_ptr_qs_engine = ptr; + m_shr_p_qs_engine = ptr; } #endif diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index b41dcede3..dbd913c5b 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -320,7 +320,7 @@ protected: int do_back_transformed_diagnostics = 1; #ifdef WARPX_QED - bool do_qed = false; + bool m_do_qed = false; virtual bool has_quantum_sync(){return false;}; virtual bool has_breit_wheeler(){return false;}; diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index 3badf78c3..86fdbb1b4 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -79,8 +79,8 @@ public: size_t TTfunc_size, amrex::Real* TTfunc_coords, amrex::Real* TTfunc_data): - ctrl{t_ctrl}, - lookup_table{ + m_ctrl{t_ctrl}, + m_lookup_table{ TTfunc_size, TTfunc_coords, TTfunc_data @@ -103,7 +103,7 @@ public: amrex::Real bx, amrex::Real by, amrex::Real bz, amrex::Real dt, amrex::Real& opt_depth) const { - bool has_event_happend{false}; + bool has_event_happened{false}; //the library provides the time (< dt) at which the event occurs, but this //feature won't be used in WarpX for now. @@ -115,20 +115,20 @@ public: ex, ey, ez, bx, by, bz, dt, opt_depth, - has_event_happend, unused_event_time, - dummy_lambda, - lookup_table, - ctrl); + has_event_happened, unused_event_time, + m_dummy_lambda, + m_lookup_table, + m_ctrl); - return has_event_happend; + return has_event_happened; } private: //laser wavelenght is not used with SI units - const amrex::Real dummy_lambda{1.0}; + const amrex::Real m_dummy_lambda{1.0}; - const PicsarBreitWheelerCtrl ctrl; - const picsar::multi_physics::lookup_1d lookup_table; + const PicsarBreitWheelerCtrl m_ctrl; + const picsar::multi_physics::lookup_1d m_lookup_table; }; /** @@ -146,8 +146,8 @@ public: */ BreitWheelerGeneratePairs( BreitWheelerEngineInnards& r_innards): - ctrl{r_innards.ctrl}, - lookup_table{ + m_ctrl{r_innards.ctrl}, + m_lookup_table{ r_innards.cum_distrib_coords_1.size(), r_innards.cum_distrib_coords_1.data(), r_innards.cum_distrib_coords_2.size(), @@ -192,18 +192,18 @@ public: e_px, e_py, e_pz, p_px, p_py, p_pz, e_weight, p_weight, - dummy_lambda, - lookup_table, - ctrl, + m_dummy_lambda, + m_lookup_table, + m_ctrl, rand_zero_one_minus_epsi.data()); } private: //laser wavelenght is not used with SI units - const amrex::Real dummy_lambda{1.0}; + const amrex::Real m_dummy_lambda{1.0}; - const PicsarBreitWheelerCtrl ctrl; - const picsar::multi_physics::lookup_2d lookup_table; + const PicsarBreitWheelerCtrl m_ctrl; + const picsar::multi_physics::lookup_2d m_lookup_table; }; // Factory class ============================= @@ -266,13 +266,13 @@ public: PicsarBreitWheelerCtrl get_default_ctrl() const; private: - bool lookup_tables_initialized = false; + bool m_lookup_tables_initialized = false; - BreitWheelerEngineInnards innards; + BreitWheelerEngineInnards m_innards; //Table builing is available only if WarpX is compiled with QED_TABLE_GEN=TRUE #ifdef WARPX_QED_TABLE_GEN - BreitWheelerEngineTableBuilder table_builder; + BreitWheelerEngineTableBuilder m_table_builder; #endif }; diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index f84754462..76d28d66a 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -24,25 +24,25 @@ BreitWheelerEngine::build_optical_depth_functor () BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor () { - AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return BreitWheelerEvolveOpticalDepth(innards.ctrl, - innards.TTfunc_coords.size(), - innards.TTfunc_coords.dataPtr(), - innards.TTfunc_data.dataPtr() ); + return BreitWheelerEvolveOpticalDepth(m_innards.ctrl, + m_innards.TTfunc_coords.size(), + m_innards.TTfunc_coords.dataPtr(), + m_innards.TTfunc_data.dataPtr() ); } BreitWheelerGeneratePairs BreitWheelerEngine::build_pair_functor () { - AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return BreitWheelerGeneratePairs(innards); + return BreitWheelerGeneratePairs(m_innards); } bool BreitWheelerEngine::are_lookup_tables_initialized () const { - return lookup_tables_initialized; + return m_lookup_tables_initialized; } bool @@ -54,91 +54,91 @@ BreitWheelerEngine::init_lookup_tables_from_raw_data ( bool is_ok; //Header (control parameters) - tie(is_ok, innards.ctrl.chi_phot_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tdndt_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tdndt_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tdndt_max, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tdndt_max, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tdndt_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tdndt_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tpair_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tpair_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tpair_max, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tpair_max, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_phot_tpair_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_phot_tpair_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_frac_tpair_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_frac_tpair_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; //___________________________ //Data - Vector tndt_coords(innards.ctrl.chi_phot_tdndt_how_many); - Vector tndt_data(innards.ctrl.chi_phot_tdndt_how_many); - Vector cum_tab_coords1(innards.ctrl.chi_phot_tpair_how_many); - Vector cum_tab_coords2(innards.ctrl.chi_frac_tpair_how_many); - Vector cum_tab_data(innards.ctrl.chi_phot_tpair_how_many* - innards.ctrl.chi_frac_tpair_how_many); + Vector tndt_coords(m_innards.ctrl.chi_phot_tdndt_how_many); + Vector tndt_data(m_innards.ctrl.chi_phot_tdndt_how_many); + Vector cum_tab_coords1(m_innards.ctrl.chi_phot_tpair_how_many); + Vector cum_tab_coords2(m_innards.ctrl.chi_frac_tpair_how_many); + Vector cum_tab_data(m_innards.ctrl.chi_phot_tpair_how_many* + m_innards.ctrl.chi_frac_tpair_how_many); tie(is_ok, tndt_coords, p_data) = parse_raw_data_vec( p_data, tndt_coords.size(), p_last); if(!is_ok) return false; - innards.TTfunc_coords.assign(tndt_coords.begin(), tndt_coords.end()); + m_innards.TTfunc_coords.assign(tndt_coords.begin(), tndt_coords.end()); tie(is_ok, tndt_data, p_data) = parse_raw_data_vec( p_data, tndt_data.size(), p_last); if(!is_ok) return false; - innards.TTfunc_data.assign(tndt_data.begin(), tndt_data.end()); + m_innards.TTfunc_data.assign(tndt_data.begin(), tndt_data.end()); tie(is_ok, cum_tab_coords1, p_data) = parse_raw_data_vec( p_data, cum_tab_coords1.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_coords_1.assign( + m_innards.cum_distrib_coords_1.assign( cum_tab_coords1.begin(), cum_tab_coords1.end()); tie(is_ok, cum_tab_coords2, p_data) = parse_raw_data_vec( p_data, cum_tab_coords2.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_coords_2.assign( + m_innards.cum_distrib_coords_2.assign( cum_tab_coords2.begin(), cum_tab_coords2.end()); tie(is_ok, cum_tab_data, p_data) = parse_raw_data_vec( p_data, cum_tab_data.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_data.assign( + m_innards.cum_distrib_data.assign( cum_tab_data.begin(), cum_tab_data.end()); //___________________________ - lookup_tables_initialized = true; + m_lookup_tables_initialized = true; return true; } @@ -147,7 +147,7 @@ Vector BreitWheelerEngine::export_lookup_tables_data () const { Vector res{}; - if(!lookup_tables_initialized) + if(!m_lookup_tables_initialized) return res; auto add_data_to_buf = [&res](auto data){ @@ -157,14 +157,14 @@ Vector BreitWheelerEngine::export_lookup_tables_data () const sizeof(data)); }; - add_data_to_buf(innards.ctrl.chi_phot_min); - add_data_to_buf(innards.ctrl.chi_phot_tdndt_min); - add_data_to_buf(innards.ctrl.chi_phot_tdndt_max); - add_data_to_buf(innards.ctrl.chi_phot_tdndt_how_many); - add_data_to_buf(innards.ctrl.chi_phot_tpair_min); - add_data_to_buf(innards.ctrl.chi_phot_tpair_max); - add_data_to_buf(innards.ctrl.chi_phot_tpair_how_many); - add_data_to_buf(innards.ctrl.chi_frac_tpair_how_many); + add_data_to_buf(m_innards.ctrl.chi_phot_min); + add_data_to_buf(m_innards.ctrl.chi_phot_tdndt_min); + add_data_to_buf(m_innards.ctrl.chi_phot_tdndt_max); + add_data_to_buf(m_innards.ctrl.chi_phot_tdndt_how_many); + add_data_to_buf(m_innards.ctrl.chi_phot_tpair_min); + add_data_to_buf(m_innards.ctrl.chi_phot_tpair_max); + add_data_to_buf(m_innards.ctrl.chi_phot_tpair_how_many); + add_data_to_buf(m_innards.ctrl.chi_frac_tpair_how_many); auto add_data_to_buf_vv = [&res](const auto* data, size_t how_many){ res.insert(res.end(), @@ -173,16 +173,16 @@ Vector BreitWheelerEngine::export_lookup_tables_data () const sizeof(*data)*how_many); }; - add_data_to_buf_vv(innards.TTfunc_coords.data(), - innards.TTfunc_coords.size()); - add_data_to_buf_vv(innards.TTfunc_data.data(), - innards.TTfunc_data.size()); - add_data_to_buf_vv(innards.cum_distrib_coords_1.data(), - innards.cum_distrib_coords_1.size()); - add_data_to_buf_vv(innards.cum_distrib_coords_2.data(), - innards.cum_distrib_coords_2.size()); - add_data_to_buf_vv(innards.cum_distrib_data.data(), - innards.cum_distrib_data.size()); + add_data_to_buf_vv(m_innards.TTfunc_coords.data(), + m_innards.TTfunc_coords.size()); + add_data_to_buf_vv(m_innards.TTfunc_data.data(), + m_innards.TTfunc_data.size()); + add_data_to_buf_vv(m_innards.cum_distrib_coords_1.data(), + m_innards.cum_distrib_coords_1.size()); + add_data_to_buf_vv(m_innards.cum_distrib_coords_2.data(), + m_innards.cum_distrib_coords_2.size()); + add_data_to_buf_vv(m_innards.cum_distrib_data.data(), + m_innards.cum_distrib_data.size()); return res; } @@ -197,8 +197,8 @@ void BreitWheelerEngine::compute_lookup_tables ( PicsarBreitWheelerCtrl ctrl) { #ifdef WARPX_QED_TABLE_GEN - table_builder.compute_table(ctrl, innards); - lookup_tables_initialized = true; + m_table_builder.compute_table(ctrl, m_innards); + m_lookup_tables_initialized = true; #endif } diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 1d74e9bbb..7d7fe5b6b 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -79,8 +79,8 @@ public: */ QuantumSynchrotronEvolveOpticalDepth( QuantumSynchrotronEngineInnards& r_innards): - ctrl{r_innards.ctrl}, - lookup_table{ + m_ctrl{r_innards.ctrl}, + m_lookup_table{ r_innards.KKfunc_data.size(), r_innards.KKfunc_coords.data(), r_innards.KKfunc_data.data() @@ -103,7 +103,7 @@ public: amrex::Real bx, amrex::Real by, amrex::Real bz, amrex::Real dt, amrex::Real& opt_depth) const { - bool has_event_happend{false}; + bool has_event_happened{false}; //the library provides the time (< dt) at which the event occurs, but this //feature won't be used in WarpX for now. @@ -115,20 +115,20 @@ public: ex, ey, ez, bx, by, bz, dt, opt_depth, - has_event_happend, unused_event_time, - dummy_lambda, - lookup_table, - ctrl); + has_event_happened, unused_event_time, + m_dummy_lambda, + m_lookup_table, + m_ctrl); - return has_event_happend; + return has_event_happened; } private: //laser wavelenght is not used with SI units - const amrex::Real dummy_lambda{1.0}; + const amrex::Real m_dummy_lambda{1.0}; - const PicsarQuantumSynchrotronCtrl ctrl; - const picsar::multi_physics::lookup_1d lookup_table; + const PicsarQuantumSynchrotronCtrl m_ctrl; + const picsar::multi_physics::lookup_1d m_lookup_table; }; /** @@ -146,8 +146,8 @@ public: */ QuantumSynchrotronGeneratePhotonAndUpdateMomentum( QuantumSynchrotronEngineInnards& r_innards): - ctrl{r_innards.ctrl}, - lookup_table{ + m_ctrl{r_innards.ctrl}, + m_lookup_table{ r_innards.cum_distrib_coords_1.size(), r_innards.cum_distrib_coords_1.data(), r_innards.cum_distrib_coords_2.size(), @@ -189,18 +189,18 @@ public: weight, sampling, g_px, g_py, g_pz, g_weight, - dummy_lambda, - lookup_table, - ctrl, + m_dummy_lambda, + m_lookup_table, + m_ctrl, rand_zero_one_minus_epsi.data()); } private: //laser wavelenght is not used with SI units - const amrex::Real dummy_lambda{1.0}; + const amrex::Real m_dummy_lambda{1.0}; - const PicsarQuantumSynchrotronCtrl ctrl; - const picsar::multi_physics::lookup_2d lookup_table; + const PicsarQuantumSynchrotronCtrl m_ctrl; + const picsar::multi_physics::lookup_2d m_lookup_table; }; // Factory class ============================= @@ -263,13 +263,13 @@ public: PicsarQuantumSynchrotronCtrl get_default_ctrl() const; private: - bool lookup_tables_initialized = false; + bool m_lookup_tables_initialized = false; - QuantumSynchrotronEngineInnards innards; + QuantumSynchrotronEngineInnards m_innards; //Table builing is available only if the libray is compiled with QED_TABLE_GEN=TRUE #ifdef WARPX_QED_TABLE_GEN - QuantumSynchrotronEngineTableBuilder table_builder; + QuantumSynchrotronEngineTableBuilder m_table_builder; #endif }; diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index 13bc178d3..8606d19ae 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -23,22 +23,22 @@ QuantumSynchrotronEngine::build_optical_depth_functor () QuantumSynchrotronEvolveOpticalDepth QuantumSynchrotronEngine::build_evolve_functor () { - AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return QuantumSynchrotronEvolveOpticalDepth(innards); + return QuantumSynchrotronEvolveOpticalDepth(m_innards); } QuantumSynchrotronGeneratePhotonAndUpdateMomentum QuantumSynchrotronEngine::build_phot_em_functor () { - AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return QuantumSynchrotronGeneratePhotonAndUpdateMomentum(innards); + return QuantumSynchrotronGeneratePhotonAndUpdateMomentum(m_innards); } bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const { - return lookup_tables_initialized; + return m_lookup_tables_initialized; } bool @@ -50,91 +50,91 @@ QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( bool is_ok; //Header (control parameters) - tie(is_ok, innards.ctrl.chi_part_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tdndt_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tdndt_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tdndt_max, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tdndt_max, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tdndt_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tdndt_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tem_min, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tem_min, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tem_max, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tem_max, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.chi_part_tem_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.chi_part_tem_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; - tie(is_ok, innards.ctrl.prob_tem_how_many, p_data) = - parse_raw_data( + tie(is_ok, m_innards.ctrl.prob_tem_how_many, p_data) = + parse_raw_data( p_data, p_last); if(!is_ok) return false; //___________________________ //Data - Vector tndt_coords(innards.ctrl.chi_part_tdndt_how_many); - Vector tndt_data(innards.ctrl.chi_part_tdndt_how_many); - Vector cum_tab_coords1(innards.ctrl.chi_part_tem_how_many); - Vector cum_tab_coords2(innards.ctrl.prob_tem_how_many); - Vector cum_tab_data(innards.ctrl.chi_part_tem_how_many* - innards.ctrl.prob_tem_how_many); + Vector tndt_coords(m_innards.ctrl.chi_part_tdndt_how_many); + Vector tndt_data(m_innards.ctrl.chi_part_tdndt_how_many); + Vector cum_tab_coords1(m_innards.ctrl.chi_part_tem_how_many); + Vector cum_tab_coords2(m_innards.ctrl.prob_tem_how_many); + Vector cum_tab_data(m_innards.ctrl.chi_part_tem_how_many* + m_innards.ctrl.prob_tem_how_many); tie(is_ok, tndt_coords, p_data) = parse_raw_data_vec( p_data, tndt_coords.size(), p_last); if(!is_ok) return false; - innards.KKfunc_coords.assign(tndt_coords.begin(), tndt_coords.end()); + m_innards.KKfunc_coords.assign(tndt_coords.begin(), tndt_coords.end()); tie(is_ok, tndt_data, p_data) = parse_raw_data_vec( p_data, tndt_data.size(), p_last); if(!is_ok) return false; - innards.KKfunc_data.assign(tndt_data.begin(), tndt_data.end()); + m_innards.KKfunc_data.assign(tndt_data.begin(), tndt_data.end()); tie(is_ok, cum_tab_coords1, p_data) = parse_raw_data_vec( p_data, cum_tab_coords1.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_coords_1.assign( + m_innards.cum_distrib_coords_1.assign( cum_tab_coords1.begin(), cum_tab_coords1.end()); tie(is_ok, cum_tab_coords2, p_data) = parse_raw_data_vec( p_data, cum_tab_coords2.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_coords_2.assign( + m_innards.cum_distrib_coords_2.assign( cum_tab_coords2.begin(), cum_tab_coords2.end()); tie(is_ok, cum_tab_data, p_data) = parse_raw_data_vec( p_data, cum_tab_data.size(), p_last); if(!is_ok) return false; - innards.cum_distrib_data.assign( + m_innards.cum_distrib_data.assign( cum_tab_data.begin(), cum_tab_data.end()); //___________________________ - lookup_tables_initialized = true; + m_lookup_tables_initialized = true; return true; } @@ -143,7 +143,7 @@ Vector QuantumSynchrotronEngine::export_lookup_tables_data () const { Vector res{}; - if(!lookup_tables_initialized) + if(!m_lookup_tables_initialized) return res; auto add_data_to_buf = [&res](auto data){ @@ -153,14 +153,14 @@ Vector QuantumSynchrotronEngine::export_lookup_tables_data () const sizeof(data)); }; - add_data_to_buf(innards.ctrl.chi_part_min); - add_data_to_buf(innards.ctrl.chi_part_tdndt_min); - add_data_to_buf(innards.ctrl.chi_part_tdndt_max); - add_data_to_buf(innards.ctrl.chi_part_tdndt_how_many); - add_data_to_buf(innards.ctrl.chi_part_tem_min); - add_data_to_buf(innards.ctrl.chi_part_tem_max); - add_data_to_buf(innards.ctrl.chi_part_tem_how_many); - add_data_to_buf(innards.ctrl.prob_tem_how_many); + add_data_to_buf(m_innards.ctrl.chi_part_min); + add_data_to_buf(m_innards.ctrl.chi_part_tdndt_min); + add_data_to_buf(m_innards.ctrl.chi_part_tdndt_max); + add_data_to_buf(m_innards.ctrl.chi_part_tdndt_how_many); + add_data_to_buf(m_innards.ctrl.chi_part_tem_min); + add_data_to_buf(m_innards.ctrl.chi_part_tem_max); + add_data_to_buf(m_innards.ctrl.chi_part_tem_how_many); + add_data_to_buf(m_innards.ctrl.prob_tem_how_many); auto add_data_to_buf_vv = [&res](const auto* data, size_t how_many){ res.insert(res.end(), @@ -169,16 +169,16 @@ Vector QuantumSynchrotronEngine::export_lookup_tables_data () const sizeof(*data)*how_many); }; - add_data_to_buf_vv(innards.KKfunc_coords.data(), - innards.KKfunc_coords.size()); - add_data_to_buf_vv(innards.KKfunc_data.data(), - innards.KKfunc_data.size()); - add_data_to_buf_vv(innards.cum_distrib_coords_1.data(), - innards.cum_distrib_coords_1.size()); - add_data_to_buf_vv(innards.cum_distrib_coords_2.data(), - innards.cum_distrib_coords_2.size()); - add_data_to_buf_vv(innards.cum_distrib_data.data(), - innards.cum_distrib_data.size()); + add_data_to_buf_vv(m_innards.KKfunc_coords.data(), + m_innards.KKfunc_coords.size()); + add_data_to_buf_vv(m_innards.KKfunc_data.data(), + m_innards.KKfunc_data.size()); + add_data_to_buf_vv(m_innards.cum_distrib_coords_1.data(), + m_innards.cum_distrib_coords_1.size()); + add_data_to_buf_vv(m_innards.cum_distrib_coords_2.data(), + m_innards.cum_distrib_coords_2.size()); + add_data_to_buf_vv(m_innards.cum_distrib_data.data(), + m_innards.cum_distrib_data.size()); return res; } @@ -193,8 +193,8 @@ void QuantumSynchrotronEngine::compute_lookup_tables ( PicsarQuantumSynchrotronCtrl ctrl) { #ifdef WARPX_QED_TABLE_GEN - table_builder.compute_table(ctrl, innards); - lookup_tables_initialized = true; + m_table_builder.compute_table(ctrl, m_innards); + m_lookup_tables_initialized = true; #endif } -- cgit v1.2.3 From 72d55c39b28552a711b4be3cdd7f91e06366624b Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 30 Oct 2019 11:40:12 +0100 Subject: clearer error message --- Source/Particles/MultiParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 8dc969e8f..837f70275 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -768,7 +768,7 @@ MultiParticleContainer::ParseQuantumSyncParams () #ifndef WARPX_QED_TABLE_GEN if(generate_table){ - amrex::Error("Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"); + amrex::Error("Error: Compile with QED_TABLE_GEN=TRUE to enable table generation!\n"); } #endif @@ -827,7 +827,7 @@ MultiParticleContainer::ParseBreitWheelerParams () #ifndef WARPX_QED_TABLE_GEN if(generate_table){ if(ParallelDescriptor::IOProcessor()){ - amrex::Error("Error: use QED_TABLE_GEN=TRUE to enable table generation!\n"); + amrex::Error("Error: Compile with QED_TABLE_GEN=TRUE to enable table generation!\n"); } } #endif -- cgit v1.2.3 From af5d5d427ea58c5fc1dad0397ffbd3297788c743 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 30 Oct 2019 11:48:28 +0100 Subject: correct bug and changed strategy to check if a string is empty --- Source/Particles/MultiParticleContainer.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 837f70275..8d64c9d6f 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -14,9 +14,6 @@ using namespace amrex; -//literals allow to write "aa"s, which means that "aa" is an std::string (C++14) -using namespace std::literals; - MultiParticleContainer::MultiParticleContainer (AmrCore* amr_core) { @@ -642,10 +639,10 @@ void MultiParticleContainer::InitQED () } } - if(nspecies_quantum_sync != 0) + if(m_nspecies_quantum_sync != 0) InitQuantumSync(); - if(nspecies_breit_wheeler !=0) + if(m_nspecies_breit_wheeler !=0) InitBreitWheeler(); } @@ -758,7 +755,7 @@ MultiParticleContainer::ParseQuantumSyncParams () std::string load_table_name; pp.query("load_table_from", load_table_name); - if(load_table_name != ""s){ + if(!load_table_name.empty()){ if(generate_table && ParallelDescriptor::IOProcessor()){ amrex::Print() << "Warning, Quantum Synchrotron table will be loaded, not generated. \n"; } @@ -772,7 +769,7 @@ MultiParticleContainer::ParseQuantumSyncParams () } #endif - if(table_name==""s){ + if(table_name.empty()){ amrex::Error("Error: Quantum Synchrotron table has either to be generated or to be loaded.\n"); } @@ -816,7 +813,7 @@ MultiParticleContainer::ParseBreitWheelerParams () std::string load_table_name; pp.query("load_table_from", load_table_name); - if(load_table_name != ""s){ + if(!load_table_name.empty()){ if(generate_table && ParallelDescriptor::IOProcessor()){ amrex::Print() << "Warning, Breit Wheeler table will be loaded, not generated. \n"; } @@ -832,7 +829,7 @@ MultiParticleContainer::ParseBreitWheelerParams () } #endif - if(table_name==""s){ + if(table_name.empty()){ amrex::Error("Error: Breit Wheeler table has either to be generated or to be loaded.\n"); } -- cgit v1.2.3 From cd9ca5d0753d15adad6b7b35fc8a539e5bd4f3f9 Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Wed, 30 Oct 2019 15:27:19 +0100 Subject: added comments and corrected error in inputfile --- .../qed/breit_wheeler/inputs.2d_test_tau_init | 2 +- Source/Particles/MultiParticleContainer.cpp | 78 +++++++++++++++++++++- Source/QED/BreitWheelerEngineInnards.H | 2 +- Source/QED/BreitWheelerEngineWrapper.H | 55 +++++++++------ Source/QED/BreitWheelerEngineWrapper.cpp | 5 +- Source/QED/QuantumSyncEngineWrapper.H | 48 ++++++++----- 6 files changed, 146 insertions(+), 44 deletions(-) (limited to 'Source/Particles/MultiParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init index ac85bafe8..afa0675a8 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init +++ b/Examples/Modules/qed/breit_wheeler/inputs.2d_test_tau_init @@ -75,7 +75,7 @@ qed_bw.ignore_tables_for_test = 1 #qed_bw.tab_pair_chi_min = 0.01 #qed_bw.tab_pair_chi_max = 100 #qed_bw.tab_pair_chi_how_many = 30 -#qed_bw.tab_pair_prob_how_many = 30 +#qed_bw.chi_frac_tpair_how_many = 30 #qed_bw.save_table_in = "bw_table" #qed_bw.load_table_from = "bw_table" ################################# diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 8d64c9d6f..fca22daa2 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -728,6 +728,9 @@ MultiParticleContainer::ParseQuantumSyncParams () ParmParse pp("qed_qs"); + // Engine paramenter: chi_part_min is the minium chi parameter to be + // considered by the engine. If a lepton has chi < chi_part_min, + // the optical depth is not evolved and photon generation is ignored pp.query("chi_min", ctrl.chi_part_min); //Only temporary for test purposes, will be removed @@ -740,17 +743,52 @@ MultiParticleContainer::ParseQuantumSyncParams () pp.query("generate_table", generate_table); if(generate_table){ int t_int = 0; + + //==Table parameters== + + //--- sub-table 1 (1D) + //These parameters are used to pre-compute a function + //which appears in the evolution of the optical depth + + //Minimun chi for the table. If a lepton has chi < chi_part_tdndt_min, + ///chi is considered as it were equal to chi_part_tdndt_min pp.query("tab_dndt_chi_min", ctrl.chi_part_tdndt_min); + + //Maximum chi for the table. If a lepton has chi > chi_part_tdndt_max, + ///chi is considered as it were equal to chi_part_tdndt_max pp.query("tab_dndt_chi_max", ctrl.chi_part_tdndt_max); + + //How many points should be used for chi in the table pp.query("tab_dndt_how_many", t_int); ctrl.chi_part_tdndt_how_many= t_int; + //------ + + //--- sub-table 2 (2D) + //These parameters are used to pre-compute a function + //which is used to extract the properties of the generated + //photons. + + //Minimun chi for the table. If a lepton has chi < chi_part_tem_min, + ///chi is considered as it were equal to chi_part_tem_min pp.query("tab_em_chi_min", ctrl.chi_part_tem_min); + + //Maximum chi for the table. If a lepton has chi > chi_part_tem_max, + ///chi is considered as it were equal to chi_part_tem_max pp.query("tab_em_chi_max", ctrl.chi_part_tem_max); + + //How many points should be used for chi in the table pp.query("tab_em_chi_how_many", t_int); ctrl.chi_part_tem_how_many = t_int; + + //The other axis of the table is a cumulative probability distribution + //(corresponding to different energies of the generated particles) + //This parameter is the number of different points to consider pp.query("tab_em_prob_how_many", t_int); ctrl.prob_tem_how_many = t_int; + //==================== + pp.query("save_table_in", table_name); + } std::string load_table_name; @@ -786,6 +824,9 @@ MultiParticleContainer::ParseBreitWheelerParams () ParmParse pp("qed_bw"); + // Engine paramenter: chi_phot_min is the minium chi parameter to be + // considered by the engine. If a photon has chi < chi_phot_min, + // the optical depth is not evolved and pair generation is ignored pp.query("chi_min", ctrl.chi_phot_min); //Only temporary for test purposes, will be removed @@ -797,17 +838,52 @@ MultiParticleContainer::ParseBreitWheelerParams () pp.query("generate_table", generate_table); if(generate_table){ + int t_int; + + //==Table parameters== + + //--- sub-table 1 (1D) + //These parameters are used to pre-compute a function + //which appears in the evolution of the optical depth + + //Minimun chi for the table. If a photon has chi < chi_phot_tdndt_min, + //an analytical approximation is used. pp.query("tab_dndt_chi_min", ctrl.chi_phot_tdndt_min); + + //Maximum chi for the table. If a photon has chi > chi_phot_tdndt_min, + //an analytical approximation is used. pp.query("tab_dndt_chi_max", ctrl.chi_phot_tdndt_max); + + //How many points should be used for chi in the table pp.query("tab_dndt_how_many", t_int); ctrl.chi_phot_tdndt_how_many = t_int; + //------ + + //--- sub-table 2 (2D) + //These parameters are used to pre-compute a function + //which is used to extract the properties of the generated + //particles. + + //Minimun chi for the table. If a photon has chi < chi_phot_tpair_min + //chi is considered as it were equal to chi_phot_tpair_min pp.query("tab_pair_chi_min", ctrl.chi_phot_tpair_min); + + //Maximum chi for the table. If a photon has chi > chi_phot_tpair_max + //chi is considered as it were equal to chi_phot_tpair_max pp.query("tab_pair_chi_max", ctrl.chi_phot_tpair_max); + + //How many points should be used for chi in the table pp.query("tab_pair_chi_how_many", t_int); ctrl.chi_phot_tpair_how_many = t_int; - pp.query("tab_pair_prob_how_many", t_int); + + //The other axis of the table is the fraction of the initial energy + //'taken away' by the most energetic particle of the pair. + //This parameter is the number of different fractions to consider + pp.query("tab_pair_frac_how_many", t_int); ctrl.chi_frac_tpair_how_many = t_int; + //==================== + pp.query("save_table_in", table_name); } diff --git a/Source/QED/BreitWheelerEngineInnards.H b/Source/QED/BreitWheelerEngineInnards.H index 6c5edcff6..2a7026989 100644 --- a/Source/QED/BreitWheelerEngineInnards.H +++ b/Source/QED/BreitWheelerEngineInnards.H @@ -19,7 +19,7 @@ struct BreitWheelerEngineInnards // Control parameters (a POD struct) picsar::multi_physics::breit_wheeler_engine_ctrl ctrl; - //Lookup table data (should stay on GPU) + //Lookup table data amrex::Gpu::ManagedVector TTfunc_coords; amrex::Gpu::ManagedVector TTfunc_data; diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index d2cb12ff1..1033ff7c9 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -84,17 +84,12 @@ public: * lookup_table uses non-owning vectors under the hood. So no new data * allocations should be triggered on GPU */ - BreitWheelerEvolveOpticalDepth( - const PicsarBreitWheelerCtrl t_ctrl, - size_t TTfunc_size, - amrex::Real* TTfunc_coords, - amrex::Real* TTfunc_data): - m_ctrl{t_ctrl}, - m_lookup_table{ - TTfunc_size, - TTfunc_coords, - TTfunc_data - }{}; + BreitWheelerEvolveOpticalDepth(BreitWheelerEngineInnards& r_innards): + m_ctrl{r_innards.ctrl}, + m_TTfunc_size{r_innards.TTfunc_coords.size()}, + m_p_TTfunc_coords{r_innards.TTfunc_coords.dataPtr()}, + m_p_TTfunc_data{r_innards.TTfunc_data.dataPtr()} + {}; /** * Evolves the optical depth. It can be used on GPU. @@ -127,7 +122,10 @@ public: dt, opt_depth, has_event_happened, unused_event_time, m_dummy_lambda, - m_lookup_table, + picsar::multi_physics::lookup_1d{ + m_TTfunc_size, + m_p_TTfunc_coords, + m_p_TTfunc_data}, m_ctrl); return has_event_happened; @@ -138,7 +136,11 @@ private: const amrex::Real m_dummy_lambda{1.0}; const PicsarBreitWheelerCtrl m_ctrl; - const picsar::multi_physics::lookup_1d m_lookup_table; + + //lookup table data + size_t m_TTfunc_size; + amrex::Real* m_p_TTfunc_coords; + amrex::Real* m_p_TTfunc_data; }; /** @@ -157,12 +159,11 @@ public: BreitWheelerGeneratePairs( BreitWheelerEngineInnards& r_innards): m_ctrl{r_innards.ctrl}, - m_lookup_table{ - r_innards.cum_distrib_coords_1.size(), - r_innards.cum_distrib_coords_1.data(), - r_innards.cum_distrib_coords_2.size(), - r_innards.cum_distrib_coords_2.data(), - r_innards.cum_distrib_data.data() + m_cum_distrib_coords_1_size{r_innards.cum_distrib_coords_1.size()}, + m_cum_distrib_coords_2_size{r_innards.cum_distrib_coords_2.size()}, + m_p_distrib_coords_1{r_innards.cum_distrib_coords_1.data()}, + m_p_distrib_coords_2{r_innards.cum_distrib_coords_2.data()}, + m_p_cum_distrib_data{r_innards.cum_distrib_data.data() }{}; /** @@ -203,7 +204,13 @@ public: p_px, p_py, p_pz, e_weight, p_weight, m_dummy_lambda, - m_lookup_table, + picsar::multi_physics::lookup_2d{ + m_cum_distrib_coords_1_size, + m_p_distrib_coords_1, + m_cum_distrib_coords_2_size, + m_p_distrib_coords_2, + m_p_cum_distrib_data + }, m_ctrl, rand_zero_one_minus_epsi.data()); } @@ -213,7 +220,13 @@ private: const amrex::Real m_dummy_lambda{1.0}; const PicsarBreitWheelerCtrl m_ctrl; - const picsar::multi_physics::lookup_2d m_lookup_table; + + //lookup table data + size_t m_cum_distrib_coords_1_size; + size_t m_cum_distrib_coords_2_size; + amrex::Real* m_p_distrib_coords_1; + amrex::Real* m_p_distrib_coords_2; + amrex::Real* m_p_cum_distrib_data; }; // Factory class ============================= diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index a6d3d0108..42953c97f 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -26,10 +26,7 @@ BreitWheelerEngine::build_evolve_functor () { AMREX_ALWAYS_ASSERT(m_lookup_tables_initialized); - return BreitWheelerEvolveOpticalDepth(m_innards.ctrl, - m_innards.TTfunc_coords.size(), - m_innards.TTfunc_coords.dataPtr(), - m_innards.TTfunc_data.dataPtr() ); + return BreitWheelerEvolveOpticalDepth(m_innards); } BreitWheelerGeneratePairs diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 1201dec32..1a6ffe4f3 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -87,11 +87,10 @@ public: QuantumSynchrotronEvolveOpticalDepth( QuantumSynchrotronEngineInnards& r_innards): m_ctrl{r_innards.ctrl}, - m_lookup_table{ - r_innards.KKfunc_data.size(), - r_innards.KKfunc_coords.data(), - r_innards.KKfunc_data.data() - }{}; + m_KKfunc_size{r_innards.KKfunc_coords.size()}, + m_p_KKfunc_coords{r_innards.KKfunc_coords.dataPtr()}, + m_p_KKfunc_data{r_innards.KKfunc_data.dataPtr()} + {}; /** * Evolves the optical depth. It can be used on GPU. @@ -124,7 +123,10 @@ public: dt, opt_depth, has_event_happened, unused_event_time, m_dummy_lambda, - m_lookup_table, + picsar::multi_physics::lookup_1d{ + m_KKfunc_size, + m_p_KKfunc_coords, + m_p_KKfunc_data}, m_ctrl); return has_event_happened; @@ -135,7 +137,11 @@ private: const amrex::Real m_dummy_lambda{1.0}; const PicsarQuantumSynchrotronCtrl m_ctrl; - const picsar::multi_physics::lookup_1d m_lookup_table; + + //lookup table data + size_t m_KKfunc_size; + amrex::Real* m_p_KKfunc_coords; + amrex::Real* m_p_KKfunc_data; }; /** @@ -154,13 +160,12 @@ public: QuantumSynchrotronGeneratePhotonAndUpdateMomentum( QuantumSynchrotronEngineInnards& r_innards): m_ctrl{r_innards.ctrl}, - m_lookup_table{ - r_innards.cum_distrib_coords_1.size(), - r_innards.cum_distrib_coords_1.data(), - r_innards.cum_distrib_coords_2.size(), - r_innards.cum_distrib_coords_2.data(), - r_innards.cum_distrib_data.data() - }{}; + m_cum_distrib_coords_1_size{r_innards.cum_distrib_coords_1.size()}, + m_cum_distrib_coords_2_size{r_innards.cum_distrib_coords_2.size()}, + m_p_distrib_coords_1{r_innards.cum_distrib_coords_1.data()}, + m_p_distrib_coords_2{r_innards.cum_distrib_coords_2.data()}, + m_p_cum_distrib_data{r_innards.cum_distrib_data.data()} + {}; /** * Generates sampling (template parameter) photons according to Quantum Synchrotron process. @@ -197,7 +202,12 @@ public: g_px, g_py, g_pz, g_weight, m_dummy_lambda, - m_lookup_table, + picsar::multi_physics::lookup_2d{ + m_cum_distrib_coords_1_size, + m_p_distrib_coords_1, + m_cum_distrib_coords_2_size, + m_p_distrib_coords_2, + m_p_cum_distrib_data}, m_ctrl, rand_zero_one_minus_epsi.data()); } @@ -207,7 +217,13 @@ private: const amrex::Real m_dummy_lambda{1.0}; const PicsarQuantumSynchrotronCtrl m_ctrl; - const picsar::multi_physics::lookup_2d m_lookup_table; + + //lookup table data + size_t m_cum_distrib_coords_1_size; + size_t m_cum_distrib_coords_2_size; + amrex::Real* m_p_distrib_coords_1; + amrex::Real* m_p_distrib_coords_2; + amrex::Real* m_p_cum_distrib_data; }; // Factory class ============================= -- cgit v1.2.3