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 --- Source/QED/QuantumSyncEngineTableBuilder.cpp | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Source/QED/QuantumSyncEngineTableBuilder.cpp (limited to 'Source/QED/QuantumSyncEngineTableBuilder.cpp') 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" -- cgit v1.2.3 From 2e34335e7b43599ac7685d611e6dedb6f1ac7efa Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Fri, 18 Oct 2019 14:47:34 +0200 Subject: Cleaning and adding wrappers for chi function calculations --- Source/Particles/PhysicalParticleContainer.H | 1 + Source/QED/BreitWheelerEngineTableBuilder.cpp | 10 ++++++ Source/QED/BreitWheelerEngineWrapper.H | 11 +++---- Source/QED/BreitWheelerEngineWrapper.cpp | 2 +- Source/QED/Make.package | 1 + Source/QED/QedChiFunctions.H | 38 ++++++++++++++++++++++ Source/QED/QedWrapperCommons.H | 7 ++-- Source/QED/QuantumSyncEngineTableBuilder.cpp | 9 +++++ Source/QED/QuantumSyncEngineWrapper.H | 47 ++++++++++++++------------- Source/QED/QuantumSyncEngineWrapper.cpp | 2 +- 10 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 Source/QED/QedChiFunctions.H (limited to 'Source/QED/QuantumSyncEngineTableBuilder.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index c953aa2d7..08493edcd 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -10,6 +10,7 @@ #ifdef WARPX_QED #include #include + #include #endif #include diff --git a/Source/QED/BreitWheelerEngineTableBuilder.cpp b/Source/QED/BreitWheelerEngineTableBuilder.cpp index 128f7164d..e85bfd523 100644 --- a/Source/QED/BreitWheelerEngineTableBuilder.cpp +++ b/Source/QED/BreitWheelerEngineTableBuilder.cpp @@ -1,4 +1,14 @@ #include "BreitWheelerEngineTableBuilder.H" + //Include the full BW engine with table generation support +//(after some consistency tests) +#ifdef PXRMP_CORE_ONLY + #error The Table Builder is incompatible with PXRMP_CORE_ONLY +#endif + +#ifdef __PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE__ + #warning breit_wheeler_engine.hpp should not have been included before reaching this point. +#endif #include "breit_wheeler_engine.hpp" +//_______________________________________________ diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index 66bddbbf1..c4185b6fc 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -4,23 +4,22 @@ #include "QedWrapperCommons.H" #include -#include -#include +#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" +#include #ifdef WARPX_QED_TABLE_GEN #include "BreitWheelerEngineTableBuilder.H" #endif using WarpXBreitWheelerWrapper = picsar::multi_physics:: - breit_wheeler_engine; + breit_wheeler_engine; using WarpXBreitWheelerWrapperCtrl = picsar::multi_physics::breit_wheeler_engine_ctrl; diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index 959dc8328..c58c652e5 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -147,7 +147,7 @@ void BreitWheelerEngine::computes_lookup_tables ( { //Lambda is not actually used if S.I. units are enabled WarpXBreitWheelerWrapper bw_engine( - std::move(QedDummyStruct()), 1.0, ctrl); + std::move(QedUtils::DummyStruct()), 1.0, ctrl); bw_engine.compute_dN_dt_lookup_table(); //bw_engine.compute_cumulative_pair_table(); diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 58fc4047c..302e890c8 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -1,4 +1,5 @@ CEXE_headers += QedWrapperCommons.H +CEXE_headers += QedChiFunctions.H CEXE_headers += BreitWheelerEngineWrapper.H CEXE_headers += QuantumSyncsEngineWrapper.H CEXE_sources += BreitWheelerEngineWrapper.cpp diff --git a/Source/QED/QedChiFunctions.H b/Source/QED/QedChiFunctions.H new file mode 100644 index 000000000..b150aae6b --- /dev/null +++ b/Source/QED/QedChiFunctions.H @@ -0,0 +1,38 @@ +#ifndef WARPX_amrex_qed_chi_functions_h_ +#define WARPX_amrex_qed_chi_functions_h_ + +#include "QedWrapperCommons.H" + +#define PXRMP_CORE_ONLY +#include + +namespace QedUtils{ + //Thin wrappers around functions used to calculate chi parameters + + AMREX_GPU_DEVICE + AMREX_FORCE_INLINE + amrex::Real chi_photon( + 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) + { + const amrex::Real dummy_lambda = 1.0; + return picsar::multi_physics::chi_photon( + px, py, pz, ex, ey, ez, bx, by, bz, dummy_lambda); + } + + AMREX_GPU_DEVICE + AMREX_FORCE_INLINE + amrex::Real chi_lepton( + 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) + { + const amrex::Real dummy_lambda = 1.0; + return picsar::multi_physics::chi_lepton( + px, py, pz, ex, ey, ez, bx, by, bz, dummy_lambda); + } + //_________ +}; + +#endif //WARPX_amrex_qed_chi_functions_h_ \ No newline at end of file diff --git a/Source/QED/QedWrapperCommons.H b/Source/QED/QedWrapperCommons.H index fe93f69ec..2d17d3b83 100644 --- a/Source/QED/QedWrapperCommons.H +++ b/Source/QED/QedWrapperCommons.H @@ -3,6 +3,7 @@ //Common definitions for the QED library wrappers and table builders +#include #include //Sets the decorator for GPU @@ -10,7 +11,9 @@ //Sets SI units in the library #define PXRMP_WITH_SI_UNITS -//An empty data type -struct QedDummyStruct{}; +namespace QedUtils{ + //An empty data type + struct DummyStruct{}; +}; #endif //WARPX_amrex_qed_wrapper_commons_h_ diff --git a/Source/QED/QuantumSyncEngineTableBuilder.cpp b/Source/QED/QuantumSyncEngineTableBuilder.cpp index 4cd604f67..68dbe5a36 100644 --- a/Source/QED/QuantumSyncEngineTableBuilder.cpp +++ b/Source/QED/QuantumSyncEngineTableBuilder.cpp @@ -1,4 +1,13 @@ #include "QuantumSyncEngineTableBuilder.H" //Include the full QS engine with table generation support +//(after some consistency tests) +#ifdef PXRMP_CORE_ONLY + #error The Table Builder is incompatible with PXRMP_CORE_ONLY +#endif + +#ifdef __PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE__ + #warning quantum_sync_engine.hpp should not have been included before reaching this point. +#endif #include "quantum_sync_engine.hpp" +//_______________________________________________ diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 2a5a91098..fcfd53321 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -4,16 +4,19 @@ #include "QedWrapperCommons.H" #include +#include -#include -#include + +#include +#include //QS ENGINE from PICSAR +//Include only essential parts of the library in this file #define PXRMP_CORE_ONLY -#include "quantum_sync_engine.hpp" +#include -using WarpXQuantumSynchrotronWrapper = - picsar::multi_physics::quantum_synchrotron_engine; +using WarpXQuantumSynchrotronWrapper = picsar::multi_physics:: + quantum_synchrotron_engine; using WarpXQuantumSynchrotronWrapperCtrl = picsar::multi_physics::quantum_synchrotron_engine_ctrl; @@ -66,8 +69,8 @@ class QuantumSynchrotronEvolveOpticalDepth { public: QuantumSynchrotronEvolveOpticalDepth( - QuantumSynchrotronEngineInnards* _innards): - innards{_innards}{}; + QuantumSynchrotronEngineInnards* t_innards): + p_innards{t_innards}{}; AMREX_GPU_DEVICE AMREX_FORCE_INLINE @@ -83,9 +86,9 @@ public: const auto table = picsar::multi_physics ::lookup_1d( - innards->KKfunc_data.size(), - innards->KKfunc_coords.data(), - innards->KKfunc_data.data()); + p_innards->KKfunc_data.size(), + p_innards->KKfunc_coords.data(), + p_innards->KKfunc_data.data()); WarpXQuantumSynchrotronWrapper:: internal_evolve_opt_depth_and_determine_event( @@ -96,13 +99,13 @@ public: has_event_happend, unused_event_time, dummy_lambda, table, - innards->ctrl); + p_innards->ctrl); return has_event_happend; } private: - QuantumSynchrotronEngineInnards* innards; + QuantumSynchrotronEngineInnards* p_innards; }; // Generates a photon via the Quantum Synchrotron process @@ -111,8 +114,8 @@ class QuantumSynchrotronGeneratePhotonAndUpdateMomentum { public: QuantumSynchrotronGeneratePhotonAndUpdateMomentum( - QuantumSynchrotronEngineInnards* _innards): - innards{_innards}{}; + QuantumSynchrotronEngineInnards* t_innards): + p_innards{t_innards}{}; template AMREX_GPU_DEVICE @@ -126,17 +129,17 @@ public: amrex::Real* g_weight) const { amrex::Real dummy_lambda{1.0}; - picsar::multi_physics::picsar_array + amrex::GpuArray 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()); + (p_innards->cum_distrib_coords_1.size(), + p_innards->cum_distrib_coords_1.data(), + p_innards->cum_distrib_coords_2.size(), + p_innards->cum_distrib_coords_2.data(), + p_innards->cum_distrib_data.data()); bool stat = WarpXQuantumSynchrotronWrapper:: internal_generate_photons_and_update_momentum( @@ -148,14 +151,14 @@ public: *g_weight, dummy_lambda, table, - innards->ctrl, + p_innards->ctrl, rand_zero_one_minus_epsi.data()); return stat; } private: - QuantumSynchrotronEngineInnards* innards; + QuantumSynchrotronEngineInnards* p_innards; }; // Factory class ============================= diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index a3c55359b..c362bded3 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -140,7 +140,7 @@ void QuantumSynchrotronEngine::computes_lookup_tables ( { //Lambda is not actually used if S.I. units are enabled WarpXQuantumSynchrotronWrapper qs_engine( - std::move(QedDummyStruct()), 1.0, ctrl); + std::move(QedUtils::DummyStruct()), 1.0, ctrl); qs_engine.compute_dN_dt_lookup_table(); //qs_engine.compute_cumulative_pair_table(); -- cgit v1.2.3 From 82c12f66fc69d249deb3103865f36192ab1e1e3a Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Mon, 21 Oct 2019 14:26:29 +0200 Subject: Created TableBuilder for QS engine + bugfixing --- Source/Make.WarpX | 11 +- Source/QED/BreitWheelerEngineTableBuilder.cpp | 15 +- Source/QED/BreitWheelerEngineWrapper.H | 6 +- Source/QED/BreitWheelerEngineWrapper.cpp | 30 ++-- Source/QED/Make.package | 3 +- Source/QED/QuantumSyncEngineInnards.H | 28 ++++ Source/QED/QuantumSyncEngineTableBuilder.H | 12 +- Source/QED/QuantumSyncEngineTableBuilder.cpp | 44 +++++- Source/QED/QuantumSyncEngineWrapper.H | 60 +++---- Source/QED/QuantumSyncEngineWrapper.cpp | 216 ++++++++++++++------------ 10 files changed, 266 insertions(+), 159 deletions(-) create mode 100644 Source/QED/QuantumSyncEngineInnards.H (limited to 'Source/QED/QuantumSyncEngineTableBuilder.cpp') diff --git a/Source/Make.WarpX b/Source/Make.WarpX index b9fe0a258..8e4e3b4f7 100644 --- a/Source/Make.WarpX +++ b/Source/Make.WarpX @@ -92,10 +92,11 @@ ifeq ($(QED),TRUE) 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) + BOOST_ROOT ?= NOT_SET + ifneq ($(BOOST_ROOT),NOT_SET) + VPATH_LOCATIONS += $(BOOST_ROOT) + INCLUDE_LOCATIONS += $(BOOST_ROOT) + endif CXXFLAGS += -DWARPX_QED_TABLE_GEN CFLAGS += -DWARPX_QED_TABLE_GEN FFLAGS += -DWARPX_QED_TABLE_GEN @@ -103,8 +104,6 @@ ifeq ($(QED),TRUE) endif endif -endif - include $(PICSAR_HOME)/src/Make.package WARPX_GIT_VERSION := $(shell cd $(WARPX_HOME); git describe --abbrev=12 --dirty --always --tags) diff --git a/Source/QED/BreitWheelerEngineTableBuilder.cpp b/Source/QED/BreitWheelerEngineTableBuilder.cpp index 8d7914976..39deef893 100644 --- a/Source/QED/BreitWheelerEngineTableBuilder.cpp +++ b/Source/QED/BreitWheelerEngineTableBuilder.cpp @@ -9,10 +9,9 @@ #ifdef __PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE__ #warning breit_wheeler_engine.hpp should not have been included before reaching this point. #endif -#include "breit_wheeler_engine.hpp" +#include //_______________________________________________ - using PicsarBreitWheelerEngine = picsar::multi_physics:: breit_wheeler_engine; @@ -41,5 +40,17 @@ BreitWheelerEngineTableBuilder::compute_table innards.TTfunc_data.assign(bw_innards_picsar.TTfunc_table_data_ptr, bw_innards_picsar.TTfunc_table_data_ptr + bw_innards_picsar.TTfunc_table_data_how_many); + innards.cum_distrib_coords_1.assign( + bw_innards_picsar.cum_distrib_table_coords_1_ptr, + bw_innards_picsar.cum_distrib_table_coords_1_ptr + + bw_innards_picsar.cum_distrib_table_coords_1_how_many); + innards.cum_distrib_coords_2.assign( + bw_innards_picsar.cum_distrib_table_coords_2_ptr, + bw_innards_picsar.cum_distrib_table_coords_2_ptr + + bw_innards_picsar.cum_distrib_table_coords_2_how_many); + innards.cum_distrib_data.assign( + bw_innards_picsar.cum_distrib_table_data_ptr, + bw_innards_picsar.cum_distrib_table_data_ptr + + bw_innards_picsar.cum_distrib_table_data_how_many); //____ } \ No newline at end of file diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index 895e8a8f6..fa27b79e7 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -193,14 +193,12 @@ private: BreitWheelerEngineInnards innards; #ifdef WARPX_QED_TABLE_GEN - BreitWheelerEngineTableBuilder table_builder; +#endif //Private function which actually computes the lookup tables - BreitWheelerEngineInnards computes_lookup_tables ( - PicsarBreitWheelerCtrl ctrl); + void compute_lookup_tables (PicsarBreitWheelerCtrl ctrl); -#endif }; //============================================ diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index 457f98752..90c136b8d 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -2,7 +2,10 @@ #include "QedTableParserHelperFunctions.H" +#include + #include +#include using namespace std; using namespace QedUtils; @@ -144,26 +147,24 @@ BreitWheelerEngine::init_lookup_tables_from_raw_data ( return true; } - -#ifdef WARPX_QED_TABLE_GEN //Initializes the Lookup tables using the default settings //provided by the library void BreitWheelerEngine::compute_lookup_tables_default () { //A control parameters structure //with the default values provided by the library - WarpXBreitWheelerWrapperCtrl ctrl_default; + PicsarBreitWheelerCtrl ctrl_default; - computes_lookup_tables(ctrl_default); + compute_lookup_tables(ctrl_default); lookup_tables_initialized = true; } // Computes the Lookup tables using user-defined settings void BreitWheelerEngine::compute_custom_lookup_tables ( - WarpXBreitWheelerWrapperCtrl ctrl) + PicsarBreitWheelerCtrl ctrl) { - computes_lookup_tables(ctrl); + compute_lookup_tables(ctrl); lookup_tables_initialized = true; } @@ -171,22 +172,27 @@ void BreitWheelerEngine::compute_custom_lookup_tables ( /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ -std::vector export_lookup_tables_data () const +std::vector BreitWheelerEngine::export_lookup_tables_data () const { if(!lookup_tables_initialized) - return std::vector; + return std::vector{}; //TODO - return std::vector; + return std::vector{}; } + + //Private function which actually computes the lookup tables -void BreitWheelerEngine::computes_lookup_tables ( +void BreitWheelerEngine::compute_lookup_tables ( PicsarBreitWheelerCtrl 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 +} //============================================ diff --git a/Source/QED/Make.package b/Source/QED/Make.package index 214eff351..c9cd73cc2 100644 --- a/Source/QED/Make.package +++ b/Source/QED/Make.package @@ -2,8 +2,9 @@ CEXE_headers += QedWrapperCommons.H CEXE_headers += QedChiFunctions.H CEXE_headers += QedTableParserHelperFunctions.H CEXE_headers += BreitWheelerEngineInnards.H +CEXE_headers += QuantumSyncEngineInnards.H CEXE_headers += BreitWheelerEngineWrapper.H -CEXE_headers += QuantumSyncsEngineWrapper.H +CEXE_headers += QuantumSyncEngineWrapper.H CEXE_sources += BreitWheelerEngineWrapper.cpp CEXE_sources += QuantumSyncEngineWrapper.cpp diff --git a/Source/QED/QuantumSyncEngineInnards.H b/Source/QED/QuantumSyncEngineInnards.H new file mode 100644 index 000000000..8fcd24bba --- /dev/null +++ b/Source/QED/QuantumSyncEngineInnards.H @@ -0,0 +1,28 @@ +#ifndef WARPX_quantum_sync_engine_innards_h_ +#define WARPX_quantum_sync_engine_innards_h_ + +#include "QedWrapperCommons.H" + +#include + +#include + +// Struct to hold Quantum Synchrotron engine data ================ + +struct QuantumSynchrotronEngineInnards +{ + // Control parameters + picsar::multi_physics::quantum_synchrotron_engine_ctrl ctrl; + + //Lookup table data + amrex::Gpu::ManagedDeviceVector KKfunc_coords; + 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; + //______ +}; + + +#endif //WARPX_quantum_sync_engine_innards_h_ \ No newline at end of file diff --git a/Source/QED/QuantumSyncEngineTableBuilder.H b/Source/QED/QuantumSyncEngineTableBuilder.H index f555f9212..cdb948f0f 100644 --- a/Source/QED/QuantumSyncEngineTableBuilder.H +++ b/Source/QED/QuantumSyncEngineTableBuilder.H @@ -1,6 +1,16 @@ #ifndef WARPX_quantum_sync_engine_table_builder_h_ #define WARPX_quantum_sync_engine_table_builder_h_ -class QuantumSynchrotronEngineTableBuilder{}; +#include "QedWrapperCommons.H" +#include "QuantumSyncEngineInnards.H" + +#include + +class QuantumSynchrotronEngineTableBuilder{ +public: + void compute_table + (picsar::multi_physics::quantum_synchrotron_engine_ctrl ctrl, + QuantumSynchrotronEngineInnards& innards) const; +}; #endif //WARPX_quantum_sync_engine_table_builder_h_ diff --git a/Source/QED/QuantumSyncEngineTableBuilder.cpp b/Source/QED/QuantumSyncEngineTableBuilder.cpp index 68dbe5a36..371977497 100644 --- a/Source/QED/QuantumSyncEngineTableBuilder.cpp +++ b/Source/QED/QuantumSyncEngineTableBuilder.cpp @@ -9,5 +9,47 @@ #ifdef __PICSAR_MULTIPHYSICS_BREIT_WHEELER_ENGINE__ #warning quantum_sync_engine.hpp should not have been included before reaching this point. #endif -#include "quantum_sync_engine.hpp" +#include //_______________________________________________ + +using PicsarQuantumSynchrotronEngine = picsar::multi_physics:: + quantum_synchrotron_engine; + +using PicsarQuantumSynchrotronCtrl = + picsar::multi_physics::quantum_synchrotron_engine_ctrl; + + void +QuantumSynchrotronEngineTableBuilder::compute_table + (PicsarQuantumSynchrotronCtrl ctrl, + QuantumSynchrotronEngineInnards& innards) const +{ + PicsarQuantumSynchrotronEngine qs_engine( + std::move(QedUtils::DummyStruct()), 1.0, ctrl); + + qs_engine.compute_dN_dt_lookup_table(); + qs_engine.compute_cumulative_phot_em_table(); + + auto qs_innards_picsar = qs_engine.export_innards(); + + //Copy data in a GPU-friendly data-structure + innards.ctrl = qs_innards_picsar.qs_ctrl; + innards.KKfunc_coords.assign(qs_innards_picsar.KKfunc_table_coords_ptr, + qs_innards_picsar.KKfunc_table_coords_ptr + + qs_innards_picsar.KKfunc_table_coords_how_many); + innards.KKfunc_data.assign(qs_innards_picsar.KKfunc_table_data_ptr, + qs_innards_picsar.KKfunc_table_data_ptr + + qs_innards_picsar.KKfunc_table_data_how_many); + innards.cum_distrib_coords_1.assign( + qs_innards_picsar.cum_distrib_table_coords_1_ptr, + qs_innards_picsar.cum_distrib_table_coords_1_ptr + + qs_innards_picsar.cum_distrib_table_coords_1_how_many); + innards.cum_distrib_coords_2.assign( + qs_innards_picsar.cum_distrib_table_coords_2_ptr, + qs_innards_picsar.cum_distrib_table_coords_2_ptr + + qs_innards_picsar.cum_distrib_table_coords_2_how_many); + innards.cum_distrib_data.assign( + qs_innards_picsar.cum_distrib_table_data_ptr, + qs_innards_picsar.cum_distrib_table_data_ptr + + qs_innards_picsar.cum_distrib_table_data_how_many); + //____ +} \ No newline at end of file diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index 5c61894a6..c769ed549 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -2,41 +2,29 @@ #define WARPX_quantum_sync_engine_wrapper_h_ #include "QedWrapperCommons.H" +#include "QuantumSyncEngineInnards.H" #include #include - -#include -#include - //QS ENGINE from PICSAR //Include only essential parts of the library in this file #define PXRMP_CORE_ONLY #include +#ifdef WARPX_QED_TABLE_GEN + #include "QuantumSyncEngineTableBuilder.H" +#endif + +#include +#include + using PicsarQuantumSynchrotronEngine = picsar::multi_physics:: quantum_synchrotron_engine; using PicsarQuantumSynchrotronCtrl = picsar::multi_physics::quantum_synchrotron_engine_ctrl; -// Struct to hold engine data ================ - -struct QuantumSynchrotronEngineInnards -{ - // Control parameters - PicsarQuantumSynchrotronCtrl ctrl; - - //Lookup table data - amrex::Gpu::ManagedDeviceVector KKfunc_coords; - 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; - //______ -}; // Functors ================================== @@ -179,36 +167,36 @@ public: /* \brief Builds the functor to evolve the optical depth */ QuantumSynchrotronEvolveOpticalDepth build_evolve_functor (); - /* \brief Checks if lookup tables are properly initialized */ bool are_lookup_tables_initialized () const; - /* \brief Reads lookup tables from 'file' on disk */ - void read_lookup_tables (std::string file); + /* \brief Reads lookup tables from 'file' on disk */ + bool init_lookup_tables_from_raw_data (const std::vector& raw_data); -private: - bool lookup_tables_initialized = false; - - QuantumSynchrotronEngineInnards 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 (WarpXQuantumSynchrotronWrapperCtrl ctrl); - /* \brief Writes lookup tables on disk in 'file' - * return false if it fails. */ - bool write_lookup_tables (std::string file) const; + void compute_custom_lookup_tables (PicsarQuantumSynchrotronCtrl ctrl); + private: - //Private function which actually computes the lookup tables - void computes_lookup_tables ( - WarpXQuantumSynchrotronWrapperCtrl ctrl); + bool lookup_tables_initialized = false; + + QuantumSynchrotronEngineInnards innards; +#ifdef WARPX_QED_TABLE_GEN + 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 c362bded3..d50e786ee 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -1,4 +1,16 @@ #include "QuantumSyncEngineWrapper.H" + +#include "QedTableParserHelperFunctions.H" + +#include + +#include +#include + +using namespace std; +using namespace QedUtils; +using namespace amrex; + //This file provides a wrapper aroud the quantum_sync engine //provided by the PICSAR library @@ -27,47 +39,103 @@ bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const } /* \brief Reads lookup tables from 'file' on disk */ -void QuantumSynchrotronEngine::read_lookup_tables (std::string file) +bool +QuantumSynchrotronEngine::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_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)); - //_______ + tie(is_ok, 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( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, 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( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, 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( + p_data, p_last); + if(!is_ok) return false; + + tie(is_ok, 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( + p_data, p_last); + if(!is_ok) return false; + + //___________________________ //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(); - + 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) = + 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()); + + 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()); + + 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; -} -#ifdef WARPX_QED_TABLE_GEN + return true; +} //Initializes the Lookup tables using the default settings //provided by the library @@ -75,88 +143,44 @@ void QuantumSynchrotronEngine::compute_lookup_tables_default () { //A control parameters structure //with the default values provided by the library - WarpXQuantumSynchrotronWrapperCtrl ctrl_default; + PicsarQuantumSynchrotronCtrl ctrl_default; - computes_lookup_tables(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 ( - WarpXQuantumSynchrotronWrapperCtrl ctrl) + PicsarQuantumSynchrotronCtrl ctrl) { - computes_lookup_tables(ctrl); + compute_lookup_tables(ctrl); lookup_tables_initialized = true; } - /* \brief Writes lookup tables on disk in 'file' * return false if it fails. */ -bool QuantumSynchrotronEngine::write_lookup_tables ( - std::string file) const +std::vector QuantumSynchrotronEngine::export_lookup_tables_data () const { if(!lookup_tables_initialized) - return false; + return std::vector{}; - 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; + //TODO + return std::vector{}; } - //Private function which actually computes the lookup tables -void QuantumSynchrotronEngine::computes_lookup_tables ( - WarpXQuantumSynchrotronWrapperCtrl ctrl) +//Private function which actually computes the lookup tables +void QuantumSynchrotronEngine::compute_lookup_tables ( + PicsarQuantumSynchrotronCtrl ctrl) { - //Lambda is not actually used if S.I. units are enabled - WarpXQuantumSynchrotronWrapper qs_engine( - std::move(QedUtils::DummyStruct()), 1.0, ctrl); - - qs_engine.compute_dN_dt_lookup_table(); - //qs_engine.compute_cumulative_pair_table(); - - auto qs_innards_picsar = qs_engine.export_innards(); - - //Copy data in a GPU-friendly data-structure - innards.ctrl = qs_innards_picsar.qs_ctrl; - innards.KKfunc_coords.assign(qs_innards_picsar.KKfunc_table_coords_ptr, - qs_innards_picsar.KKfunc_table_coords_ptr + - qs_innards_picsar.KKfunc_table_coords_how_many); - innards.KKfunc_data.assign(qs_innards_picsar.KKfunc_table_data_ptr, - qs_innards_picsar.KKfunc_table_data_ptr + - qs_innards_picsar.KKfunc_table_data_how_many); - //____ -} +#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 a09e6a6a8e2a3211535506ff6bed875cab22fead Mon Sep 17 00:00:00 2001 From: Luca Fedeli Date: Tue, 22 Oct 2019 14:51:47 +0200 Subject: added comments to code under Source/QED, marginally improved code quality --- Source/QED/BreitWheelerEngineInnards.H | 15 ++- Source/QED/BreitWheelerEngineTableBuilder.H | 11 +- Source/QED/BreitWheelerEngineTableBuilder.cpp | 10 +- Source/QED/BreitWheelerEngineWrapper.H | 177 +++++++++++++++++++------- Source/QED/BreitWheelerEngineWrapper.cpp | 38 +++--- Source/QED/QedChiFunctions.H | 30 ++++- Source/QED/QedTableParserHelperFunctions.H | 30 ++++- Source/QED/QedWrapperCommons.H | 25 +++- Source/QED/QuantumSyncEngineInnards.H | 17 ++- Source/QED/QuantumSyncEngineTableBuilder.H | 10 ++ Source/QED/QuantumSyncEngineTableBuilder.cpp | 11 +- Source/QED/QuantumSyncEngineWrapper.H | 177 +++++++++++++++++++------- Source/QED/QuantumSyncEngineWrapper.cpp | 31 +++-- 13 files changed, 426 insertions(+), 156 deletions(-) (limited to 'Source/QED/QuantumSyncEngineTableBuilder.cpp') diff --git a/Source/QED/BreitWheelerEngineInnards.H b/Source/QED/BreitWheelerEngineInnards.H index 8b7a2330e..6c5edcff6 100644 --- a/Source/QED/BreitWheelerEngineInnards.H +++ b/Source/QED/BreitWheelerEngineInnards.H @@ -5,15 +5,21 @@ #include +//This includes only the definition of a simple datastructure +//used to control the Breit Wheeler engine. #include -// Struct to hold Breit Wheeler engine data ================ +/** + * This structure holds all the parameters required to use the + * Breit Wheeler engine: a POD control structure and lookup + * tables data. + */ struct BreitWheelerEngineInnards { - // Control parameters + // Control parameters (a POD struct) picsar::multi_physics::breit_wheeler_engine_ctrl ctrl; - //Lookup table data + //Lookup table data (should stay on GPU) amrex::Gpu::ManagedVector TTfunc_coords; amrex::Gpu::ManagedVector TTfunc_data; @@ -22,5 +28,6 @@ struct BreitWheelerEngineInnards amrex::Gpu::ManagedVector cum_distrib_data; //______ }; +//========================================================== -#endif //WARPX_breit_wheeler_engine_innards_h_ \ No newline at end of file +#endif //WARPX_breit_wheeler_engine_innards_h_ diff --git a/Source/QED/BreitWheelerEngineTableBuilder.H b/Source/QED/BreitWheelerEngineTableBuilder.H index 90ecf84e0..e30b82208 100644 --- a/Source/QED/BreitWheelerEngineTableBuilder.H +++ b/Source/QED/BreitWheelerEngineTableBuilder.H @@ -4,14 +4,23 @@ #include "QedWrapperCommons.H" #include "BreitWheelerEngineInnards.H" +//This includes only the definition of a simple datastructure +//used to control the Breit Wheeler engine. #include +/** + * A class which computes the lookup tables for the Breit Wheeler engine. + */ class BreitWheelerEngineTableBuilder{ public: + /** + * Computes the tables. + * @param[in] ctrl control parameters to generate the tables + * @param[out] innards structure holding both a copy of ctrl and lookup tables data + */ void compute_table (picsar::multi_physics::breit_wheeler_engine_ctrl ctrl, BreitWheelerEngineInnards& innards) const; }; #endif //WARPX_breit_wheeler_engine_table_builder_h_ - diff --git a/Source/QED/BreitWheelerEngineTableBuilder.cpp b/Source/QED/BreitWheelerEngineTableBuilder.cpp index 39deef893..3326d5b59 100644 --- a/Source/QED/BreitWheelerEngineTableBuilder.cpp +++ b/Source/QED/BreitWheelerEngineTableBuilder.cpp @@ -1,7 +1,8 @@ #include "BreitWheelerEngineTableBuilder.H" -//Include the full BW engine with table generation support -//(after some consistency tests) +//Include the full Breit Wheeler engine with table generation support +//(after some consistency tests). This requires to have a recent version +// of the Boost library. #ifdef PXRMP_CORE_ONLY #error The Table Builder is incompatible with PXRMP_CORE_ONLY #endif @@ -12,12 +13,13 @@ #include //_______________________________________________ +//Some handy aliases using PicsarBreitWheelerEngine = picsar::multi_physics:: breit_wheeler_engine; using PicsarBreitWheelerCtrl = picsar::multi_physics::breit_wheeler_engine_ctrl; - +//_______________________________________________ void BreitWheelerEngineTableBuilder::compute_table @@ -53,4 +55,4 @@ BreitWheelerEngineTableBuilder::compute_table bw_innards_picsar.cum_distrib_table_data_ptr + bw_innards_picsar.cum_distrib_table_data_how_many); //____ -} \ No newline at end of file +} diff --git a/Source/QED/BreitWheelerEngineWrapper.H b/Source/QED/BreitWheelerEngineWrapper.H index dde70637d..15592c5ee 100644 --- a/Source/QED/BreitWheelerEngineWrapper.H +++ b/Source/QED/BreitWheelerEngineWrapper.H @@ -8,57 +8,93 @@ #include #include -//BW ENGINE from PICSAR -//Include only essential parts of the library in this file +//#define PXRMP_CORE_ONLY allows importing only the 'core functions' of the +//Breit Wheeler engine of the QED PICSAR library. #define PXRMP_CORE_ONLY #include +//Lookup table building function is in a dedicated (optional) class to +//avoid including heavy dependencies if they are not needed. #ifdef WARPX_QED_TABLE_GEN #include "BreitWheelerEngineTableBuilder.H" #endif #include +//Some handy aliases using PicsarBreitWheelerEngine = picsar::multi_physics:: breit_wheeler_engine; using PicsarBreitWheelerCtrl = picsar::multi_physics::breit_wheeler_engine_ctrl; +//__________ // Functors ================================== -// These functors provide the core elementary functions of the library -// Can be included in GPU kernels +// These functors allow using the core elementary functions of the library. +// They are generated by a factory class (BreitWheelerEngine, see below). +// They can be included in GPU kernels. /** - * \brief Functor to initialize the optical depth of photons for the + * Functor to initialize the optical depth of photons for the * Breit-Wheeler process */ class BreitWheelerGetOpticalDepth { public: + /** + * Constructor does nothing because optical depth initialization + * does not require control parameters or lookup tables. + */ BreitWheelerGetOpticalDepth () {}; + /** + * () operator is just a thin wrapper around a very simple function to + * generate the optical depth. It can be used on GPU. + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real operator() () const { + //A random number in [0,1) should be provided as an argument. return PicsarBreitWheelerEngine:: internal_get_optical_depth(amrex::Random()); } }; //____________________________________________ -// Evolution of the optical depth (returns true if -// an event occurs) +/** + * Functor to evolve the optical depth of photons due to the + * Breit-Wheeler process + */ class BreitWheelerEvolveOpticalDepth { public: + /** + * Constructor acquires a reference to control parameters and + * lookup tables data. + * lookup_table uses non-owning vectors under the hood. So no new data + * allocations should be triggered on GPU + */ BreitWheelerEvolveOpticalDepth( - BreitWheelerEngineInnards* t_innards): - p_innards{t_innards}{}; + BreitWheelerEngineInnards& r_innards): + ctrl{r_innards.ctrl}, + lookup_table{ + r_innards.TTfunc_data.size(), + r_innards.TTfunc_coords.data(), + r_innards.TTfunc_data.data() + }{}; + /** + * Evolves the optical depth. It can be used on GPU. + * @param[in] px,py,pz momentum components of the photon (SI units) + * @param[in] ex,ey,ez electric field components (SI units) + * @param[in] bx,by,bz magnetic field components (SI units) + * @param[in] dt timestep (SI units) + * @param[in,out] opt_depth optical depth of the photon. It is modified by the method. + * @return a flag which is true if optical depth becomes negative (i.e. a pair has to be generated). + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool operator()( @@ -68,13 +104,10 @@ public: 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}; - const auto table = picsar::multi_physics::lookup_1d - (p_innards->TTfunc_data.size(), - p_innards->TTfunc_coords.data(), - p_innards->TTfunc_data.data()); + //the library provides the time (< dt) at which the event occurs, but this + //feature won't be used in WarpX for now. + amrex::Real unused_event_time{0.0}; PicsarBreitWheelerEngine:: internal_evolve_opt_depth_and_determine_event( @@ -84,29 +117,59 @@ public: dt, opt_depth, has_event_happend, unused_event_time, dummy_lambda, - table, - p_innards->ctrl); + lookup_table, + ctrl); return has_event_happend; } private: - BreitWheelerEngineInnards* p_innards; + //laser wavelenght is not used with SI units + const amrex::Real dummy_lambda{1.0}; + + const PicsarBreitWheelerCtrl ctrl; + const picsar::multi_physics::lookup_1d lookup_table; }; -// Generates an electron-positron pair via the Breit-Wheeler process -// (returns false if errors occur) +/** + * Functor to generate a pair via the + * Breit-Wheeler process + */ class BreitWheelerGeneratePairs { public: + /** + * Constructor acquires a reference to control parameters and + * lookup tables data. + * lookup_table uses non-owning vectors under the hood. So no new data + * allocations should be triggered on GPU + */ BreitWheelerGeneratePairs( - BreitWheelerEngineInnards* t_innards): - p_innards{t_innards}{}; + BreitWheelerEngineInnards& r_innards): + ctrl{r_innards.ctrl}, + 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() + }{}; + /** + * Generates sampling (template parameter) pairs according to Breit Wheeler process. + * It can be used on GPU. + * @param[in] px,py,pz momentum components of the photon (SI units) + * @param[in] ex,ey,ez electric field components (SI units) + * @param[in] bx,by,bz magnetic field components (SI units) + * @param[in] weight of the photon (code units) + * @param[out] e_px,e_py,e_pz momenta of generated electrons. Each array should have size=sampling (SI units) + * @param[out] p_px,p_py,p_pz momenta of generated positrons. Each array should have size=sampling (SI units) + * @param[out] e_weight,p_weight weight of the generated particles Each array should have size=sampling (code units). + */ template AMREX_GPU_DEVICE AMREX_FORCE_INLINE - bool operator()( + void 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, @@ -115,20 +178,12 @@ public: 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}; + //[sampling] random numbers are needed 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 - (p_innards->cum_distrib_coords_1.size(), - p_innards->cum_distrib_coords_1.data(), - p_innards->cum_distrib_coords_2.size(), - p_innards->cum_distrib_coords_2.data(), - p_innards->cum_distrib_data.data()); + for(auto& el : rand_zero_one_minus_epsi) el = amrex::Random(); - bool stat = PicsarBreitWheelerEngine:: + PicsarBreitWheelerEngine:: internal_generate_breit_wheeler_pairs( px, py, pz, ex, ey, ez, @@ -138,51 +193,76 @@ public: p_px, p_py, p_pz, e_weight, p_weight, dummy_lambda, - table, - p_innards->ctrl, + lookup_table, + ctrl, rand_zero_one_minus_epsi.data()); - - return stat; } private: - BreitWheelerEngineInnards* p_innards; + //laser wavelenght is not used with SI units + const amrex::Real dummy_lambda{1.0}; + + const PicsarBreitWheelerCtrl ctrl; + const picsar::multi_physics::lookup_2d lookup_table; }; // Factory class ============================= /** - * \brief Wrapper for the Breit Wheeler engine of the PICSAR library + * Wrapper for the Breit Wheeler engine of the PICSAR library */ class BreitWheelerEngine { public: + /** + * Constructor requires no arguments. + */ BreitWheelerEngine (); /** - * \brief Builds the functor to initialize the optical depth + * Builds the functor to initialize the optical depth */ BreitWheelerGetOpticalDepth build_optical_depth_functor (); - /* \brief Builds the functor to evolve the optical depth */ + /** + * Builds the functor to evolve the optical depth + */ BreitWheelerEvolveOpticalDepth build_evolve_functor (); - /* \brief Builds the functor to generate the pairs */ + /** + * Builds the functor to generate the pairs + */ BreitWheelerGeneratePairs build_pair_functor (); - /* \brief Checks if lookup tables are properly initialized */ + /** + * Checks if the optical tables are properly initialized + */ bool are_lookup_tables_initialized () const; - /* \brief Reads lookup tables from 'file' on disk */ + /** + * Init lookup tables from raw binary data. + * @param raw_data a Vector of char + * @return true if it succeeds, false if it cannot parse 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. */ + /** + * Export lookup tables data into a raw binary Vector + * @return the data in binary format. The Vector is empty if tables were + * not previously initialized. + */ amrex::Vector export_lookup_tables_data () const; - /* \brief Computes the Lookup tables using user-defined settings */ + /** + * Computes the lookup tables. It does nothing unless WarpX is compiled with QED_TABLE_GEN=TRUE + * @param ctrl control params to generate the tables + */ void compute_lookup_tables (PicsarBreitWheelerCtrl ctrl); + /** + * gets default (reasonable) values for the control parameters + * @return default control params to generate the tables + */ PicsarBreitWheelerCtrl get_default_ctrl() const; private: @@ -190,6 +270,7 @@ private: BreitWheelerEngineInnards innards; +//Table builing is available only if WarpX is compiled with QED_TABLE_GEN=TRUE #ifdef WARPX_QED_TABLE_GEN BreitWheelerEngineTableBuilder table_builder; #endif diff --git a/Source/QED/BreitWheelerEngineWrapper.cpp b/Source/QED/BreitWheelerEngineWrapper.cpp index 4b5bed98f..e37673509 100644 --- a/Source/QED/BreitWheelerEngineWrapper.cpp +++ b/Source/QED/BreitWheelerEngineWrapper.cpp @@ -15,29 +15,26 @@ using namespace amrex; BreitWheelerEngine::BreitWheelerEngine (){} -//Builds the functor to initialize the optical depth BreitWheelerGetOpticalDepth BreitWheelerEngine::build_optical_depth_functor () { return BreitWheelerGetOpticalDepth(); } -//Builds the functor to evolve the optical depth BreitWheelerEvolveOpticalDepth BreitWheelerEngine::build_evolve_functor () { AMREX_ALWAYS_ASSERT(lookup_tables_initialized); - return BreitWheelerEvolveOpticalDepth(&innards); + return BreitWheelerEvolveOpticalDepth(innards); } -//Builds the functor to generate the pairs BreitWheelerGeneratePairs BreitWheelerEngine::build_pair_functor () { AMREX_ALWAYS_ASSERT(lookup_tables_initialized); - return BreitWheelerGeneratePairs(&innards); + return BreitWheelerGeneratePairs(innards); } bool BreitWheelerEngine::are_lookup_tables_initialized () const @@ -45,7 +42,6 @@ bool BreitWheelerEngine::are_lookup_tables_initialized () const return lookup_tables_initialized; } -/* \brief Reads lookup tables from 'file' on disk */ bool BreitWheelerEngine::init_lookup_tables_from_raw_data ( const Vector& raw_data) @@ -144,14 +140,6 @@ BreitWheelerEngine::init_lookup_tables_from_raw_data ( return true; } -PicsarBreitWheelerCtrl -BreitWheelerEngine::get_default_ctrl() const -{ - return PicsarBreitWheelerCtrl(); -} - -/* \brief Writes lookup tables on disk in 'file' - * return false if it fails. */ Vector BreitWheelerEngine::export_lookup_tables_data () const { Vector res{}; @@ -182,16 +170,26 @@ 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(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()); return res; } -//Private function which actually computes the lookup tables +PicsarBreitWheelerCtrl +BreitWheelerEngine::get_default_ctrl() const +{ + return PicsarBreitWheelerCtrl(); +} + void BreitWheelerEngine::compute_lookup_tables ( PicsarBreitWheelerCtrl ctrl) { diff --git a/Source/QED/QedChiFunctions.H b/Source/QED/QedChiFunctions.H index b150aae6b..dd8ffac0e 100644 --- a/Source/QED/QedChiFunctions.H +++ b/Source/QED/QedChiFunctions.H @@ -1,14 +1,28 @@ #ifndef WARPX_amrex_qed_chi_functions_h_ #define WARPX_amrex_qed_chi_functions_h_ +/** + * This header contains wrappers around functions provided by + * the PICSAR QED library to calculate the 'chi' parameter + * for photons or electrons and positrons. + */ + #include "QedWrapperCommons.H" +//#define PXRMP_CORE_ONLY allows importing only the 'core functions' of the +//QED library. #define PXRMP_CORE_ONLY #include namespace QedUtils{ - //Thin wrappers around functions used to calculate chi parameters - + /** + * Function to calculate the 'chi' parameter for photons. + * Suitable for GPU kernels. + * @param[in] px,py,pz components of momentum (SI units) + * @param[in] ex,ey,ez components of electric field (SI units) + * @param[in] bx,by,bz components of magnetic field (SI units) + * @return chi parameter + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real chi_photon( @@ -16,11 +30,20 @@ namespace QedUtils{ amrex::Real ex, amrex::Real ey, amrex::Real ez, amrex::Real bx, amrex::Real by, amrex::Real bz) { + //laser wavelength is unused if SI units are set const amrex::Real dummy_lambda = 1.0; return picsar::multi_physics::chi_photon( px, py, pz, ex, ey, ez, bx, by, bz, dummy_lambda); } + /** + * Function to calculate the 'chi' parameter for electrons or positrons. + * Suitable for GPU kernels. + * @param[in] px,py,pz components of momentum (SI units) + * @param[in] ex,ey,ez components of electric field (SI units) + * @param[in] bx,by,bz components of magnetic field (SI units) + * @return chi parameter + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real chi_lepton( @@ -28,6 +51,7 @@ namespace QedUtils{ amrex::Real ex, amrex::Real ey, amrex::Real ez, amrex::Real bx, amrex::Real by, amrex::Real bz) { + //laser wavelength is unused if SI units are set const amrex::Real dummy_lambda = 1.0; return picsar::multi_physics::chi_lepton( px, py, pz, ex, ey, ez, bx, by, bz, dummy_lambda); @@ -35,4 +59,4 @@ namespace QedUtils{ //_________ }; -#endif //WARPX_amrex_qed_chi_functions_h_ \ No newline at end of file +#endif //WARPX_amrex_qed_chi_functions_h_ diff --git a/Source/QED/QedTableParserHelperFunctions.H b/Source/QED/QedTableParserHelperFunctions.H index e63947ef7..e5124ea48 100644 --- a/Source/QED/QedTableParserHelperFunctions.H +++ b/Source/QED/QedTableParserHelperFunctions.H @@ -1,13 +1,28 @@ #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 +/** + * This header contains helper functions to safely extract data + * (e.g. integers, floating point numbers) from raw binary data + * (i.e. a char*). + */ #include #include namespace QedUtils{ + /** + * This function safely extracts an amrex::Vector from raw binary data. + * T must be a simple datatype (e.g. an int, a float, a double...). + * + * @param[in] p_char a pointer to the binary stream + * @param[in] how_many how many T should be read from stream + * @param[in] p_last a pointer to the last element of the char* array + * @return {a tuple containing + * 1) flag (which is false if p_last is exceeded) + * 2) a Vector of T + * 3) a pointer to a new location of the binary data (after having read how_many T)} + */ template std::tuple, const char*>parse_raw_data_vec( const char* p_data, size_t how_many, const char* const p_last) @@ -24,6 +39,17 @@ namespace QedUtils{ return std::make_tuple(true, res, p_data); } + /** + * This function safely extracts a T from raw binary data. + * T must be a simple datatype (e.g. an int, a float, a double...). + * + * @param[in] p_char a pointer to the binary stream + * @param[in] p_last a pointer to the last element of the char* array + * @return {a tuple containing + * 1) flag (which is false if p_last is exceeded) + * 2) a T + * 3) a pointer to a new location of the binary data (after having read 1 T)} + */ template std::tuple parse_raw_data( const char* p_data, const char* const p_last) diff --git a/Source/QED/QedWrapperCommons.H b/Source/QED/QedWrapperCommons.H index 2d17d3b83..536f03806 100644 --- a/Source/QED/QedWrapperCommons.H +++ b/Source/QED/QedWrapperCommons.H @@ -1,19 +1,36 @@ #ifndef WARPX_amrex_qed_wrapper_commons_h_ #define WARPX_amrex_qed_wrapper_commons_h_ -//Common definitions for the QED library wrappers and table builders +/** + * This header contains some common #define directives and a + * 'dummy' class used by the QED library wrappers and related + * components. + */ #include #include -//Sets the decorator for GPU +/** + * PICSAR uses PXRMP_GPU to decorate methods which should be + * compiled for GPU. The user has to set it to the right value + * (AMREX_GPU_DEVICE in this case). + * PXRMP_WITH_SI_UNITS sets the library to use International + * System units. + */ #define PXRMP_GPU AMREX_GPU_DEVICE -//Sets SI units in the library #define PXRMP_WITH_SI_UNITS +//_________________________ +/** + * A namespace called 'QedUtils' is used to encapsulate + * free functions (defined elsewhere) and an + * empty datastructure (DummyStruct), which is re-used by several + * components. + */ namespace QedUtils{ - //An empty data type struct DummyStruct{}; }; +//_________________________ + #endif //WARPX_amrex_qed_wrapper_commons_h_ diff --git a/Source/QED/QuantumSyncEngineInnards.H b/Source/QED/QuantumSyncEngineInnards.H index 8fcd24bba..7ba84a095 100644 --- a/Source/QED/QuantumSyncEngineInnards.H +++ b/Source/QED/QuantumSyncEngineInnards.H @@ -5,16 +5,21 @@ #include +//This includes only the definition of a simple datastructure +//used to control the Quantum Synchrotron engine. #include -// Struct to hold Quantum Synchrotron engine data ================ - +/** + * This structure holds all the parameters required to use the + * Quantum Synchrotron engine: a POD control structure and lookup + * tables data. + */ struct QuantumSynchrotronEngineInnards { - // Control parameters + // Control parameters (a POD struct) picsar::multi_physics::quantum_synchrotron_engine_ctrl ctrl; - //Lookup table data + //Lookup table data (should stay on GPU) amrex::Gpu::ManagedDeviceVector KKfunc_coords; amrex::Gpu::ManagedDeviceVector KKfunc_data; @@ -23,6 +28,6 @@ struct QuantumSynchrotronEngineInnards amrex::Gpu::ManagedVector cum_distrib_data; //______ }; +//========================================================== - -#endif //WARPX_quantum_sync_engine_innards_h_ \ No newline at end of file +#endif //WARPX_quantum_sync_engine_innards_h_ diff --git a/Source/QED/QuantumSyncEngineTableBuilder.H b/Source/QED/QuantumSyncEngineTableBuilder.H index cdb948f0f..e70f5d02f 100644 --- a/Source/QED/QuantumSyncEngineTableBuilder.H +++ b/Source/QED/QuantumSyncEngineTableBuilder.H @@ -4,10 +4,20 @@ #include "QedWrapperCommons.H" #include "QuantumSyncEngineInnards.H" +//This includes only the definition of a simple datastructure +//used to control the Quantum Synchrotron engine. #include +/** + * A class which computes the lookup tables for the Quantum Synchrotron engine. + */ class QuantumSynchrotronEngineTableBuilder{ public: + /** + * Computes the tables. + * @param[in] ctrl control parameters to generate the tables + * @param[out] innards structure holding both a copy of ctrl and lookup tables data + */ void compute_table (picsar::multi_physics::quantum_synchrotron_engine_ctrl ctrl, QuantumSynchrotronEngineInnards& innards) const; diff --git a/Source/QED/QuantumSyncEngineTableBuilder.cpp b/Source/QED/QuantumSyncEngineTableBuilder.cpp index 371977497..51c3720f2 100644 --- a/Source/QED/QuantumSyncEngineTableBuilder.cpp +++ b/Source/QED/QuantumSyncEngineTableBuilder.cpp @@ -1,7 +1,8 @@ #include "QuantumSyncEngineTableBuilder.H" -//Include the full QS engine with table generation support -//(after some consistency tests) +//Include the full Quantum Synchrotron engine with table generation support +//(after some consistency tests). This requires to have a recent version +// of the Boost library. #ifdef PXRMP_CORE_ONLY #error The Table Builder is incompatible with PXRMP_CORE_ONLY #endif @@ -12,13 +13,15 @@ #include //_______________________________________________ +//Some handy aliases using PicsarQuantumSynchrotronEngine = picsar::multi_physics:: quantum_synchrotron_engine; using PicsarQuantumSynchrotronCtrl = picsar::multi_physics::quantum_synchrotron_engine_ctrl; +//_______________________________________________ - void +void QuantumSynchrotronEngineTableBuilder::compute_table (PicsarQuantumSynchrotronCtrl ctrl, QuantumSynchrotronEngineInnards& innards) const @@ -52,4 +55,4 @@ QuantumSynchrotronEngineTableBuilder::compute_table qs_innards_picsar.cum_distrib_table_data_ptr + qs_innards_picsar.cum_distrib_table_data_how_many); //____ -} \ No newline at end of file +} diff --git a/Source/QED/QuantumSyncEngineWrapper.H b/Source/QED/QuantumSyncEngineWrapper.H index da4a0c40a..f968f4182 100644 --- a/Source/QED/QuantumSyncEngineWrapper.H +++ b/Source/QED/QuantumSyncEngineWrapper.H @@ -8,28 +8,32 @@ #include #include -//QS ENGINE from PICSAR -//Include only essential parts of the library in this file +//#define PXRMP_CORE_ONLY allows importing only the 'core functions' of the +//Quantum Synchrotron engine of the QED PICSAR library. #define PXRMP_CORE_ONLY #include +//Lookup table building function is in a dedicated (optional) class to +//avoid including heavy dependencies if they are not needed. #ifdef WARPX_QED_TABLE_GEN #include "QuantumSyncEngineTableBuilder.H" #endif #include +//Some handy aliases using PicsarQuantumSynchrotronEngine = picsar::multi_physics:: quantum_synchrotron_engine; using PicsarQuantumSynchrotronCtrl = picsar::multi_physics::quantum_synchrotron_engine_ctrl; - +//__________ // Functors ================================== -// These functors provide the core elementary functions of the library -// Can be included in GPU kernels +// These functors allow using the core elementary functions of the library. +// They are generated by a factory class (QuantumSynchrotronEngine, see below). +// They can be included in GPU kernels. /** * Functor to initialize the optical depth of leptons for the @@ -38,28 +42,59 @@ using PicsarQuantumSynchrotronCtrl = class QuantumSynchrotronGetOpticalDepth { public: + /** + * Constructor does nothing because optical depth initialization + * does not require control parameters or lookup tables. + */ QuantumSynchrotronGetOpticalDepth () {}; + /** + * () operator is just a thin wrapper around a very simple function to + * generate the optical depth. It can be used on GPU. + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real operator() () const { + //A random number in [0,1) should be provided as an argument. return PicsarQuantumSynchrotronEngine:: internal_get_optical_depth(amrex::Random()); } }; //____________________________________________ -// Evolution of the optical depth (returns true if -// an event occurs) +/** + * Functor to evolve the optical depth of leptons due to the + * Quantum Synchrotron process + */ class QuantumSynchrotronEvolveOpticalDepth { public: + /** + * Constructor acquires a reference to control parameters and + * lookup tables data. + * lookup_table uses non-owning vectors under the hood. So no new data + * allocations should be triggered on GPU + */ QuantumSynchrotronEvolveOpticalDepth( - QuantumSynchrotronEngineInnards* t_innards): - p_innards{t_innards}{}; + QuantumSynchrotronEngineInnards& r_innards): + ctrl{r_innards.ctrl}, + lookup_table{ + r_innards.KKfunc_data.size(), + r_innards.KKfunc_coords.data(), + r_innards.KKfunc_data.data() + }{}; + /** + * Evolves the optical depth. It can be used on GPU. + * @param[in] px,py,pz momentum components of the lepton (SI units) + * @param[in] ex,ey,ez electric field components (SI units) + * @param[in] bx,by,bz magnetic field components (SI units) + * @param[in] dt timestep (SI units) + * @param[in,out] opt_depth optical depth of the lepton. It is modified by the method. + * @return a flag which is true if optical depth becomes negative (i.e. a photon has to be generated). + */ AMREX_GPU_DEVICE AMREX_FORCE_INLINE bool operator()( @@ -69,14 +104,10 @@ public: 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}; - const auto table = picsar::multi_physics - ::lookup_1d( - p_innards->KKfunc_data.size(), - p_innards->KKfunc_coords.data(), - p_innards->KKfunc_data.data()); + //the library provides the time (< dt) at which the event occurs, but this + //feature won't be used in WarpX for now. + amrex::Real unused_event_time{0.0}; PicsarQuantumSynchrotronEngine:: internal_evolve_opt_depth_and_determine_event( @@ -86,29 +117,58 @@ public: dt, opt_depth, has_event_happend, unused_event_time, dummy_lambda, - table, - p_innards->ctrl); + lookup_table, + ctrl); return has_event_happend; } private: - QuantumSynchrotronEngineInnards* p_innards; + //laser wavelenght is not used with SI units + const amrex::Real dummy_lambda{1.0}; + + const PicsarQuantumSynchrotronCtrl ctrl; + const picsar::multi_physics::lookup_1d lookup_table; }; -// Generates a photon via the Quantum Synchrotron process -// and updates momentum accordingly (returns false if errors occur) +/** + * Functor to generate a photon via the Quantum Synchrotron process + * and to update momentum accordingly + */ class QuantumSynchrotronGeneratePhotonAndUpdateMomentum { public: + /** + * Constructor acquires a reference to control parameters and + * lookup tables data. + * lookup_table uses non-owning vectors under the hood. So no new data + * allocations should be triggered on GPU + */ QuantumSynchrotronGeneratePhotonAndUpdateMomentum( - QuantumSynchrotronEngineInnards* t_innards): - p_innards{t_innards}{}; + QuantumSynchrotronEngineInnards& r_innards): + ctrl{r_innards.ctrl}, + 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() + }{}; + /** + * Generates sampling (template parameter) photons according to Quantum Synchrotron process. + * It can be used on GPU. + * @param[in,out] px,py,pz momentum components of the lepton. They are modified (SI units) + * @param[in] ex,ey,ez electric field components (SI units) + * @param[in] bx,by,bz magnetic field components (SI units) + * @param[in] weight of the lepton (code units) + * @param[out] g_px,g_py,g_pz momenta of generated photons. Each array should have size=sampling (SI units) + * @param[out] g_weight weight of the generated photons. Array should have size=sampling (code units) + */ template AMREX_GPU_DEVICE AMREX_FORCE_INLINE - bool operator()( + void 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, @@ -116,20 +176,12 @@ public: amrex::Real* g_px, amrex::Real* g_py, amrex::Real* g_pz, amrex::Real* g_weight) const { - amrex::Real dummy_lambda{1.0}; + //[sampling] random numbers are needed amrex::GpuArray rand_zero_one_minus_epsi; - for(auto& el : rand_zero_one_minus_epsi) - el = amrex::Random(); + for(auto& el : rand_zero_one_minus_epsi) el = amrex::Random(); - const auto table = picsar::multi_physics::lookup_2d - (p_innards->cum_distrib_coords_1.size(), - p_innards->cum_distrib_coords_1.data(), - p_innards->cum_distrib_coords_2.size(), - p_innards->cum_distrib_coords_2.data(), - p_innards->cum_distrib_data.data()); - - bool stat = PicsarQuantumSynchrotronEngine:: + PicsarQuantumSynchrotronEngine:: internal_generate_photons_and_update_momentum( *px, *py, *pz, ex, ey, ez, @@ -138,48 +190,76 @@ public: *g_px, *g_py, *g_pz, *g_weight, dummy_lambda, - table, - p_innards->ctrl, + lookup_table, + ctrl, rand_zero_one_minus_epsi.data()); - - return stat; } private: - QuantumSynchrotronEngineInnards* p_innards; + //laser wavelenght is not used with SI units + const amrex::Real dummy_lambda{1.0}; + + const PicsarQuantumSynchrotronCtrl ctrl; + const picsar::multi_physics::lookup_2d lookup_table; }; // Factory class ============================= /** - * \brief Wrapper for the Quantum Synchrotron engine of the PICSAR library + * Wrapper for the Quantum Synchrotron engine of the PICSAR library */ class QuantumSynchrotronEngine { public: + /** + * Constructor requires no arguments. + */ QuantumSynchrotronEngine (); /** - * \brief Builds the functor to initialize the optical depth + * Builds the functor to initialize the optical depth */ QuantumSynchrotronGetOpticalDepth build_optical_depth_functor (); - /* \brief Builds the functor to evolve the optical depth */ + /** + * Builds the functor to evolve the optical depth + */ QuantumSynchrotronEvolveOpticalDepth build_evolve_functor (); - /* \brief Checks if lookup tables are properly initialized */ + /** + * Builds the functor to generate photons + */ + QuantumSynchrotronGeneratePhotonAndUpdateMomentum build_phot_em_functor (); + + /** + * Checks if the optical tables are properly initialized + */ bool are_lookup_tables_initialized () const; - /* \brief Reads lookup tables from 'file' on disk */ + /** + * Init lookup tables from raw binary data. + * @param raw_data a Vector of char + * @return true if it succeeds, false if it cannot parse 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. */ + /** + * Export lookup tables data into a raw binary Vector + * @return the data in binary format. The Vector is empty if tables were + * not previously initialized. + */ amrex::Vector export_lookup_tables_data () const; - /* \brief Computes the Lookup tables using user-defined settings */ + /** + * Computes the lookup tables. It does nothing unless WarpX is compiled with QED_TABLE_GEN=TRUE + * @param ctrl control params to generate the tables + */ void compute_lookup_tables (PicsarQuantumSynchrotronCtrl ctrl); + /** + * gets default (reasonable) values for the control parameters + * @return default control params to generate the tables + */ PicsarQuantumSynchrotronCtrl get_default_ctrl() const; private: @@ -187,6 +267,7 @@ private: QuantumSynchrotronEngineInnards innards; +//Table builing is available only if the libray is compiled with QED_TABLE_GEN=TRUE #ifdef WARPX_QED_TABLE_GEN QuantumSynchrotronEngineTableBuilder table_builder; #endif diff --git a/Source/QED/QuantumSyncEngineWrapper.cpp b/Source/QED/QuantumSyncEngineWrapper.cpp index c29881fc2..ec53e3e8c 100644 --- a/Source/QED/QuantumSyncEngineWrapper.cpp +++ b/Source/QED/QuantumSyncEngineWrapper.cpp @@ -15,19 +15,25 @@ using namespace amrex; QuantumSynchrotronEngine::QuantumSynchrotronEngine (){} -//Builds the functor to evolve the optical depth QuantumSynchrotronGetOpticalDepth QuantumSynchrotronEngine::build_optical_depth_functor () { return QuantumSynchrotronGetOpticalDepth(); } -//Builds the functor to evolve the optical depth QuantumSynchrotronEvolveOpticalDepth QuantumSynchrotronEngine::build_evolve_functor () { AMREX_ALWAYS_ASSERT(lookup_tables_initialized); - return QuantumSynchrotronEvolveOpticalDepth(&innards); + return QuantumSynchrotronEvolveOpticalDepth(innards); +} + +QuantumSynchrotronGeneratePhotonAndUpdateMomentum QuantumSynchrotronEngine::build_phot_em_functor () +{ + AMREX_ALWAYS_ASSERT(lookup_tables_initialized); + + return QuantumSynchrotronGeneratePhotonAndUpdateMomentum(innards); + } bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const @@ -35,7 +41,6 @@ bool QuantumSynchrotronEngine::are_lookup_tables_initialized () const return lookup_tables_initialized; } -/* \brief Reads lookup tables from 'file' on disk */ bool QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( const Vector& raw_data) @@ -134,8 +139,6 @@ QuantumSynchrotronEngine::init_lookup_tables_from_raw_data ( return true; } -/* \brief Writes lookup tables on disk in 'file' - * return false if it fails. */ Vector QuantumSynchrotronEngine::export_lookup_tables_data () const { Vector res{}; @@ -166,11 +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(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()); return res; } @@ -181,7 +189,6 @@ QuantumSynchrotronEngine::get_default_ctrl() const return PicsarQuantumSynchrotronCtrl(); } -//Private function which actually computes the lookup tables void QuantumSynchrotronEngine::compute_lookup_tables ( PicsarQuantumSynchrotronCtrl ctrl) { -- cgit v1.2.3