From d4406ac0dfd0e650bc85cbd8b3255f906d5452dd Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 9 Jan 2020 21:27:29 -0800 Subject: parser for particles in PhysicalParticleContainer --- Source/Particles/PhysicalParticleContainer.cpp | 213 ++++++++++++++++++++++--- 1 file changed, 192 insertions(+), 21 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 94d9bc363..b11a8e82b 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1010,18 +1010,74 @@ PhysicalParticleContainer::FieldGather (int lev, const FArrayBox& byfab = By[pti]; const FArrayBox& bzfab = Bz[pti]; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - + if (WarpX::E_ext_particle_s=="constant" || + WarpX::E_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::E_external_particle[0]; + amrex::Print() << " " << WarpX::E_external_particle[1]; + amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; + Exp.assign(np,WarpX::E_external_particle[0]); + Eyp.assign(np,WarpX::E_external_particle[1]); + Ezp.assign(np,WarpX::E_external_particle[2]); + } + if (WarpX::B_ext_particle_s=="constant" || + WarpX::B_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::B_external_particle[0]; + amrex::Print() << " " << WarpX::B_external_particle[1]; + amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; + Bxp.assign(np,WarpX::B_external_particle[0]); + Byp.assign(np,WarpX::B_external_particle[1]); + Bzp.assign(np,WarpX::B_external_particle[2]); + } // // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); + // to delete comment + if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); + Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); + Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); + ParserWrapper *xfield_partparser = Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Exp_data[i] = xfield_partparser->getField(x,y,z); + Eyp_data[i] = yfield_partparser->getField(x,y,z); + Ezp_data[i] = zfield_partparser->getField(x,y,z); + }); + } + if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); + Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); + Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); + ParserWrapper *xfield_partparser = Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = By_particle_parser.get(); + ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Bxp_data[i] = xfield_partparser->getField(x,y,z); + Byp_data[i] = yfield_partparser->getField(x,y,z); + Bzp_data[i] = zfield_partparser->getField(x,y,z); + }); + } + + // // Field Gather // @@ -1147,13 +1203,72 @@ PhysicalParticleContainer::Evolve (int lev, exfab, eyfab, ezfab, bxfab, byfab, bzfab); } - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); + if (WarpX::E_ext_particle_s=="constant" || + WarpX::E_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::E_external_particle[0]; + amrex::Print() << " " << WarpX::E_external_particle[1]; + amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; + Exp.assign(np,WarpX::E_external_particle[0]); + Eyp.assign(np,WarpX::E_external_particle[1]); + Ezp.assign(np,WarpX::E_external_particle[2]); + } + if (WarpX::B_ext_particle_s=="constant" || + WarpX::B_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::B_external_particle[0]; + amrex::Print() << " " << WarpX::B_external_particle[1]; + amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; + Bxp.assign(np,WarpX::B_external_particle[0]); + Byp.assign(np,WarpX::B_external_particle[1]); + Bzp.assign(np,WarpX::B_external_particle[2]); + } + // + // copy data from particle container to temp arrays + // + pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); + // to delete comment + if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); + Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); + Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); + ParserWrapper *xfield_partparser = Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Exp_data[i] = xfield_partparser->getField(x,y,z); + Eyp_data[i] = yfield_partparser->getField(x,y,z); + Ezp_data[i] = zfield_partparser->getField(x,y,z); + }); + } + if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); + Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); + Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); + ParserWrapper *xfield_partparser = Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = By_particle_parser.get(); + ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Bxp_data[i] = xfield_partparser->getField(x,y,z); + Byp_data[i] = yfield_partparser->getField(x,y,z); + Bzp_data[i] = zfield_partparser->getField(x,y,z); + }); + } - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); // Determine which particles deposit/gather in the buffer, and // which particles deposit/gather in the fine patch @@ -1795,19 +1910,75 @@ PhysicalParticleContainer::PushP (int lev, Real dt, const FArrayBox& byfab = By[pti]; const FArrayBox& bzfab = Bz[pti]; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - + if (WarpX::E_ext_particle_s=="constant" || + WarpX::E_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::E_external_particle[0]; + amrex::Print() << " " << WarpX::E_external_particle[1]; + amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; + Exp.assign(np,WarpX::E_external_particle[0]); + Eyp.assign(np,WarpX::E_external_particle[1]); + Ezp.assign(np,WarpX::E_external_particle[2]); + } + if (WarpX::B_ext_particle_s=="constant" || + WarpX::B_ext_particle_s=="default") { + amrex::Print() << " const " << WarpX::B_external_particle[0]; + amrex::Print() << " " << WarpX::B_external_particle[1]; + amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; + Bxp.assign(np,WarpX::B_external_particle[0]); + Byp.assign(np,WarpX::B_external_particle[1]); + Bzp.assign(np,WarpX::B_external_particle[2]); + } // // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); + // to delete comment + if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); + Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); + Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); + ParserWrapper *xfield_partparser = Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Exp_data[i] = xfield_partparser->getField(x,y,z); + Eyp_data[i] = yfield_partparser->getField(x,y,z); + Ezp_data[i] = zfield_partparser->getField(x,y,z); + }); + } + if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { + // Points to particle position + Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); + Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); + Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); + Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); + ParserWrapper *xfield_partparser = Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = By_particle_parser.get(); + ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Real x = xp_data[i]; + Real y = yp_data[i]; + Real z = zp_data[i]; + Bxp_data[i] = xfield_partparser->getField(x,y,z); + Byp_data[i] = yfield_partparser->getField(x,y,z); + Bzp_data[i] = zfield_partparser->getField(x,y,z); + }); + } + + + int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, -- cgit v1.2.3 From acb42c129e67e716e6b0dd917105c5b3dc31da3f Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Thu, 9 Jan 2020 21:34:58 -0800 Subject: cleaning --- Source/Particles/PhysicalParticleContainer.cpp | 18 ++++++++---------- Source/Particles/WarpXParticleContainer.H | 3 +-- Source/Particles/WarpXParticleContainer.cpp | 2 -- Source/WarpX.H | 12 ------------ Source/WarpX.cpp | 3 --- 5 files changed, 9 insertions(+), 29 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index b11a8e82b..34b8d6cb4 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1033,7 +1033,6 @@ PhysicalParticleContainer::FieldGather (int lev, // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - // to delete comment if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { // Points to particle position Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); @@ -1042,9 +1041,9 @@ PhysicalParticleContainer::FieldGather (int lev, Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); - ParserWrapper *xfield_partparser = Ex_particle_parser.get(); - ParserWrapper *yfield_partparser = Ey_particle_parser.get(); - ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + ParserWrapper *xfield_partparser = Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = Ez_particle_parser.get(); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { Real x = xp_data[i]; @@ -1063,9 +1062,9 @@ PhysicalParticleContainer::FieldGather (int lev, Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); - ParserWrapper *xfield_partparser = Bx_particle_parser.get(); - ParserWrapper *yfield_partparser = By_particle_parser.get(); - ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + ParserWrapper *xfield_partparser = Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = By_particle_parser.get(); + ParserWrapper *zfield_partparser = Bz_particle_parser.get(); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { Real x = xp_data[i]; @@ -1076,7 +1075,7 @@ PhysicalParticleContainer::FieldGather (int lev, Bzp_data[i] = zfield_partparser->getField(x,y,z); }); } - + // // Field Gather @@ -1225,7 +1224,7 @@ PhysicalParticleContainer::Evolve (int lev, // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - // to delete comment + if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { // Points to particle position Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); @@ -1933,7 +1932,6 @@ PhysicalParticleContainer::PushP (int lev, Real dt, // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - // to delete comment if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { // Points to particle position Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index b80dfb056..14eb1a96f 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -323,7 +323,6 @@ public: //amrex::Real getMass () {return mass;} amrex::ParticleReal getMass () const {return mass;} - // to delete comment // ParserWrapper for B_external on the particle std::unique_ptr Bx_particle_parser; std::unique_ptr By_particle_parser; @@ -332,7 +331,7 @@ public: std::unique_ptr Ex_particle_parser; std::unique_ptr Ey_particle_parser; std::unique_ptr Ez_particle_parser; - + protected: diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 9d5f4bcf4..465539d1a 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -115,8 +115,6 @@ WarpXParticleContainer::WarpXParticleContainer (AmrCore* amr_core, int ispecies) m_yp.resize(num_threads); m_zp.resize(num_threads); - - // to delete comment if (WarpX::B_ext_particle_s == "parse_b_ext_particle_function") { Bx_particle_parser.reset(new ParserWrapper( makeParser(WarpX::str_Bx_ext_particle_function))); diff --git a/Source/WarpX.H b/Source/WarpX.H index 91a815f7c..5818df394 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -92,7 +92,6 @@ public: // Initialization Type for External E and B on grid and particles static std::string B_ext_grid_s; static std::string E_ext_grid_s; - // EB parser for particles -- to delete comment static std::string B_ext_particle_s; static std::string E_ext_particle_s; @@ -114,7 +113,6 @@ public: std::unique_ptr Eyfield_parser; std::unique_ptr Ezfield_parser; - // EV parser for particles -- to delete comment // Parser for B_external on the particle static std::string str_Bx_ext_particle_function; static std::string str_By_ext_particle_function; @@ -124,16 +122,6 @@ public: static std::string str_Ey_ext_particle_function; static std::string str_Ez_ext_particle_function; - // -- to delete comment - // ParserWrapper for B_external on the particle - static std::unique_ptr Bx_particle_parser; - static std::unique_ptr By_particle_parser; - static std::unique_ptr Bz_particle_parser; - // ParserWrapper for E_external on the particle - static std::unique_ptr Ex_particle_parser; - static std::unique_ptr Ey_particle_parser; - static std::unique_ptr Ez_particle_parser; - // Algorithms static long current_deposition_algo; static long charge_deposition_algo; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index bc0edf979..d9be00df8 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -32,7 +32,6 @@ Vector WarpX::B_external_grid(3, 0.0); std::string WarpX::B_ext_grid_s = "default"; std::string WarpX::E_ext_grid_s = "default"; -//to delete comment std::string WarpX::B_ext_particle_s = "default"; std::string WarpX::E_ext_particle_s = "default"; @@ -45,7 +44,6 @@ std::string WarpX::str_Ex_ext_grid_function; std::string WarpX::str_Ey_ext_grid_function; std::string WarpX::str_Ez_ext_grid_function; -// EV parser for particles -- to delete comment // Parser for B_external on the particle std::string WarpX::str_Bx_ext_particle_function; std::string WarpX::str_By_ext_particle_function; @@ -331,7 +329,6 @@ WarpX::ReadParameters () pp.query("zmax_plasma_to_compute_max_step", zmax_plasma_to_compute_max_step); - // -- to delete comment // default values of E_external_particle and B_external_particle // are used to set the E and B field when "constant" or "parser" // is not explicitly used in the input -- cgit v1.2.3 From 7a13ea7dd1670c2c474016f15246b9e4c29062bf Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Fri, 10 Jan 2020 10:53:22 -0800 Subject: modifying input files in test cases and adding comments --- .../inputs.3d_test_optical_depth_evolution | 2 + Examples/Tests/Larmor/inputs.mr | 1 + Examples/Tests/particle_pusher/inputs | 2 + .../test_const_B_analytical/inputs | 1 + Source/Particles/PhysicalParticleContainer.H | 20 ++ Source/Particles/PhysicalParticleContainer.cpp | 257 ++++++--------------- 6 files changed, 97 insertions(+), 186 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution b/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution index 0d4cad2b1..8e4bcc3d7 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution +++ b/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution @@ -158,9 +158,11 @@ qed_bw.lookup_table_mode = "dummy_builtin" ################################# ### EXTERNAL E FIELD ### (3e15 * [-0.811107105653813 0.324442842261525 0.486664263392288] ) +warpx.E_ext_particle_init_style = "constant" warpx.E_external_particle = -2433321316961438 973328526784575 1459992790176863 #### ### EXTERNAL B FIELD ### (1e7 * [0.28571429 0.42857143 0.85714286] ) +warpx.B_ext_particle_init_style = "constant" warpx.B_external_particle = 2857142.85714286 4285714.28571428 8571428.57142857 #### diff --git a/Examples/Tests/Larmor/inputs.mr b/Examples/Tests/Larmor/inputs.mr index f933aa77a..cef5e0735 100644 --- a/Examples/Tests/Larmor/inputs.mr +++ b/Examples/Tests/Larmor/inputs.mr @@ -34,6 +34,7 @@ geometry.prob_hi = 2.0 2.0 warpx.do_pml = 1 warpx.pml_ncell = 10 +warpx.B_ext_particle_init_style = "constant" warpx.B_external_particle = 0.0 0.00078110417851950768 0.0 # Verbosity diff --git a/Examples/Tests/particle_pusher/inputs b/Examples/Tests/particle_pusher/inputs index 45ba7fa70..53376bb21 100755 --- a/Examples/Tests/particle_pusher/inputs +++ b/Examples/Tests/particle_pusher/inputs @@ -40,5 +40,7 @@ warpx.plot_raw_fields = 0 # External fields # Ex is set to be Ex = -vy*Bz +warpx.B_ext_particle_init_style = "constant" warpx.B_external_particle = 0.0 0.0 1.0 +warpx.E_ext_particle_init_style = "constant" warpx.E_external_particle = -2.994174829214179e+08 0.0 0.0 diff --git a/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs b/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs index e8fdbe984..03aa89b51 100644 --- a/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs +++ b/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs @@ -64,4 +64,5 @@ pos_perp2.single_particle_vel = -958.3148474999095 127.77531299998823 255.550625 pos_perp2.single_particle_weight = 1e-08 pos_perp2.do_classical_radiation_reaction = 1 +warpx.B_ext_particle_init_style = "constant" warpx.B_external_particle = 917978.2333474257 1376967.350021139 2753934.700042278 diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 0192ffb37..4e817750c 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -47,6 +47,25 @@ public: amrex::Real t, amrex::Real dt) override; #endif // WARPX_DO_ELECTROSTATIC + /** + * \brief Apply external E and B fields on the particles. The E and B + * fields could be defined as a constant or using a parser for reading + * in a mathematical expression. The default value for the E- and B-fields + * is (0.0,0.0,0.0). + * + * \param Exp-Bzp: fields on particles modified based on external E and B + * \param xp,yp,zp: arrays of particle positions required to compute + * mathematical expression for the external fields + * using parser. + */ + void ApplyExternalFieldOnParticles ( WarpXParIter& pti, + RealVector& Exp, RealVector& Eyp, + RealVector& Ezp, RealVector& Bxp, + RealVector& Byp, RealVector& Bzp, + amrex::Gpu::ManagedDeviceVector xp, + amrex::Gpu::ManagedDeviceVector yp, + amrex::Gpu::ManagedDeviceVector zp); + virtual void FieldGather (int lev, const amrex::MultiFab& Ex, const amrex::MultiFab& Ey, @@ -318,6 +337,7 @@ protected: //radiation reaction bool do_classical_radiation_reaction = false; + #ifdef WARPX_QED // A flag to enable quantum_synchrotron process for leptons bool m_do_qed_quantum_sync = false; diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 34b8d6cb4..ebb2b4082 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -961,6 +961,67 @@ PhysicalParticleContainer::EvolveES (const Vector xp, + Gpu::ManagedDeviceVector yp, + Gpu::ManagedDeviceVector zp) +{ + const long np = pti.numParticles(); + + if (WarpX::E_ext_particle_s=="constant" || + WarpX::E_ext_particle_s=="default") { + Exp.assign(np,WarpX::E_external_particle[0]); + Eyp.assign(np,WarpX::E_external_particle[1]); + Ezp.assign(np,WarpX::E_external_particle[2]); + } + if (WarpX::B_ext_particle_s=="constant" || + WarpX::B_ext_particle_s=="default") { + Bxp.assign(np,WarpX::B_external_particle[0]); + Byp.assign(np,WarpX::B_external_particle[1]); + Bzp.assign(np,WarpX::B_external_particle[2]); + } + if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { + Real* const AMREX_RESTRICT xp_data = xp.dataPtr(); + Real* const AMREX_RESTRICT yp_data = yp.dataPtr(); + Real* const AMREX_RESTRICT zp_data = zp.dataPtr(); + Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); + Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); + Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); + ParserWrapper *xfield_partparser = Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Eyp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + }); + } + if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { + Real* const AMREX_RESTRICT xp_data = xp.dataPtr(); + Real* const AMREX_RESTRICT yp_data = yp.dataPtr(); + Real* const AMREX_RESTRICT zp_data = zp.dataPtr(); + Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); + Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); + Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); + ParserWrapper *xfield_partparser = Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = By_particle_parser.get(); + ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + amrex::ParallelFor(pti.numParticles(), + [=] AMREX_GPU_DEVICE (long i) { + Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Byp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Bzp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + }); + } + +} + + + void PhysicalParticleContainer::FieldGather (int lev, const amrex::MultiFab& Ex, @@ -1010,72 +1071,13 @@ PhysicalParticleContainer::FieldGather (int lev, const FArrayBox& byfab = By[pti]; const FArrayBox& bzfab = Bz[pti]; - if (WarpX::E_ext_particle_s=="constant" || - WarpX::E_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::E_external_particle[0]; - amrex::Print() << " " << WarpX::E_external_particle[1]; - amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - } - if (WarpX::B_ext_particle_s=="constant" || - WarpX::B_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::B_external_particle[0]; - amrex::Print() << " " << WarpX::B_external_particle[1]; - amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - } // // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - - if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); - Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); - Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); - ParserWrapper *xfield_partparser = Ex_particle_parser.get(); - ParserWrapper *yfield_partparser = Ey_particle_parser.get(); - ParserWrapper *zfield_partparser = Ez_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Exp_data[i] = xfield_partparser->getField(x,y,z); - Eyp_data[i] = yfield_partparser->getField(x,y,z); - Ezp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); - Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); - Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); - ParserWrapper *xfield_partparser = Bx_particle_parser.get(); - ParserWrapper *yfield_partparser = By_particle_parser.get(); - ParserWrapper *zfield_partparser = Bz_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Bxp_data[i] = xfield_partparser->getField(x,y,z); - Byp_data[i] = yfield_partparser->getField(x,y,z); - Bzp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - + ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + m_xp[thread_num], m_yp[thread_num], + m_zp[thread_num]); // // Field Gather @@ -1202,72 +1204,13 @@ PhysicalParticleContainer::Evolve (int lev, exfab, eyfab, ezfab, bxfab, byfab, bzfab); } - if (WarpX::E_ext_particle_s=="constant" || - WarpX::E_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::E_external_particle[0]; - amrex::Print() << " " << WarpX::E_external_particle[1]; - amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - } - if (WarpX::B_ext_particle_s=="constant" || - WarpX::B_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::B_external_particle[0]; - amrex::Print() << " " << WarpX::B_external_particle[1]; - amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - } // // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - - if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); - Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); - Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); - ParserWrapper *xfield_partparser = Ex_particle_parser.get(); - ParserWrapper *yfield_partparser = Ey_particle_parser.get(); - ParserWrapper *zfield_partparser = Ez_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Exp_data[i] = xfield_partparser->getField(x,y,z); - Eyp_data[i] = yfield_partparser->getField(x,y,z); - Ezp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); - Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); - Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); - ParserWrapper *xfield_partparser = Bx_particle_parser.get(); - ParserWrapper *yfield_partparser = By_particle_parser.get(); - ParserWrapper *zfield_partparser = Bz_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Bxp_data[i] = xfield_partparser->getField(x,y,z); - Byp_data[i] = yfield_partparser->getField(x,y,z); - Bzp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - + ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + m_xp[thread_num], m_yp[thread_num], + m_zp[thread_num]); // Determine which particles deposit/gather in the buffer, and // which particles deposit/gather in the fine patch @@ -1909,73 +1852,14 @@ PhysicalParticleContainer::PushP (int lev, Real dt, const FArrayBox& byfab = By[pti]; const FArrayBox& bzfab = Bz[pti]; - if (WarpX::E_ext_particle_s=="constant" || - WarpX::E_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::E_external_particle[0]; - amrex::Print() << " " << WarpX::E_external_particle[1]; - amrex::Print() << " " << WarpX::E_external_particle[2] << "\n"; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - } - if (WarpX::B_ext_particle_s=="constant" || - WarpX::B_ext_particle_s=="default") { - amrex::Print() << " const " << WarpX::B_external_particle[0]; - amrex::Print() << " " << WarpX::B_external_particle[1]; - amrex::Print() << " " << WarpX::B_external_particle[2] << "\n"; - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - } // // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); - Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); - Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); - ParserWrapper *xfield_partparser = Ex_particle_parser.get(); - ParserWrapper *yfield_partparser = Ey_particle_parser.get(); - ParserWrapper *zfield_partparser = Ez_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Exp_data[i] = xfield_partparser->getField(x,y,z); - Eyp_data[i] = yfield_partparser->getField(x,y,z); - Ezp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { - // Points to particle position - Real* const AMREX_RESTRICT xp_data = m_xp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT yp_data = m_yp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT zp_data = m_zp[thread_num].dataPtr(); - Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); - Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); - Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); - ParserWrapper *xfield_partparser = Bx_particle_parser.get(); - ParserWrapper *yfield_partparser = By_particle_parser.get(); - ParserWrapper *zfield_partparser = Bz_particle_parser.get(); - amrex::ParallelFor(pti.numParticles(), - [=] AMREX_GPU_DEVICE (long i) { - Real x = xp_data[i]; - Real y = yp_data[i]; - Real z = zp_data[i]; - Bxp_data[i] = xfield_partparser->getField(x,y,z); - Byp_data[i] = yfield_partparser->getField(x,y,z); - Bzp_data[i] = zfield_partparser->getField(x,y,z); - }); - } - - + ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + m_xp[thread_num], m_yp[thread_num], + m_zp[thread_num]); int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, @@ -2589,4 +2473,5 @@ set_quantum_sync_engine_ptr(std::shared_ptr ptr) { m_shr_p_qs_engine = ptr; } + #endif -- cgit v1.2.3 From 4e1b36d2b7adc7fad187212aa8bac43278e9f307 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Sat, 11 Jan 2020 00:36:38 -0800 Subject: moving external field on particle function to FieldGather (pti,...) --- Source/Particles/PhysicalParticleContainer.H | 2 +- Source/Particles/PhysicalParticleContainer.cpp | 27 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index dcbbfc1f2..147b632eb 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -58,7 +58,7 @@ public: * mathematical expression for the external fields * using parser. */ - void ApplyExternalFieldOnParticles ( WarpXParIter& pti, + void AssignExternalFieldOnParticles ( WarpXParIter& pti, RealVector& Exp, RealVector& Eyp, RealVector& Ezp, RealVector& Bxp, RealVector& Byp, RealVector& Bzp, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index eae1b2964..a4a9dbcfc 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -964,7 +964,7 @@ PhysicalParticleContainer::EvolveES (const Vector xp, @@ -1077,9 +1077,9 @@ PhysicalParticleContainer::FieldGather (int lev, // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - m_xp[thread_num], m_yp[thread_num], - m_zp[thread_num]); + //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + // m_xp[thread_num], m_yp[thread_num], + // m_zp[thread_num]); // // Field Gather @@ -1210,9 +1210,9 @@ PhysicalParticleContainer::Evolve (int lev, // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - m_xp[thread_num], m_yp[thread_num], - m_zp[thread_num]); + //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + // m_xp[thread_num], m_yp[thread_num], + // m_zp[thread_num]); // Determine which particles deposit/gather in the buffer, and // which particles deposit/gather in the fine patch @@ -1858,9 +1858,9 @@ PhysicalParticleContainer::PushP (int lev, Real dt, // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - m_xp[thread_num], m_yp[thread_num], - m_zp[thread_num]); + //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + // m_xp[thread_num], m_yp[thread_num], + // m_zp[thread_num]); int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, @@ -2229,6 +2229,13 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, // If no particles, do not do anything if (np_to_gather == 0) return; + + // initializing the field value to the externally applied field before + // gathering fields from the grid to the particles. + AssignExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, + m_xp[thread_num], m_yp[thread_num], + m_zp[thread_num]); + // Get cell size on gather_lev const std::array& dx = WarpX::CellSize(std::max(gather_lev,0)); -- cgit v1.2.3 From cbcdf651d51af5446a6c2f8a1c1f308d35c14f1c Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Mon, 13 Jan 2020 10:21:44 -0800 Subject: wrap openmp pragma in #ifdef _OPENMP --- Source/Particles/PhysicalParticleContainer.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index f22f94e9b..2fea9133a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -493,7 +493,9 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) // Update NextID to include particles created in this function int pid; +#ifdef _OPENMP #pragma omp critical (add_plasma_nextid) +#endif { pid = ParticleType::NextID(); ParticleType::NextID(pid+max_new_particles); -- cgit v1.2.3 From fc98645e5fe7e1bb6a01ea925d87018e4f518419 Mon Sep 17 00:00:00 2001 From: Andrew Myers Date: Mon, 13 Jan 2020 10:28:24 -0800 Subject: fix EOL whitespace --- Source/Particles/PhysicalParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 2fea9133a..0d9d4fc1a 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -493,9 +493,9 @@ PhysicalParticleContainer::AddPlasma (int lev, RealBox part_realbox) // Update NextID to include particles created in this function int pid; -#ifdef _OPENMP +#ifdef _OPENMP #pragma omp critical (add_plasma_nextid) -#endif +#endif { pid = ParticleType::NextID(); ParticleType::NextID(pid+max_new_particles); -- cgit v1.2.3 From 5f9b4aa7d04ab3b945b180ba079b6482db2e9c24 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 13 Jan 2020 11:14:17 -0800 Subject: moving E/B parser variables to MultiParticleContainer class. changing input files appropriately. --- .../inputs.3d_test_optical_depth_evolution | 8 +-- Examples/Tests/Larmor/inputs.mr | 4 +- Examples/Tests/particle_pusher/inputs | 8 +-- .../test_const_B_analytical/inputs | 4 +- Source/Particles/MultiParticleContainer.H | 24 +++++++ Source/Particles/MultiParticleContainer.cpp | 79 ++++++++++++++++++++++ Source/Particles/PhysicalParticleContainer.cpp | 53 +++++++-------- .../Particles/RigidInjectedParticleContainer.cpp | 7 -- Source/Particles/WarpXParticleContainer.H | 16 ++--- Source/Particles/WarpXParticleContainer.cpp | 18 ----- Source/WarpX.H | 15 ---- Source/WarpX.cpp | 67 ------------------ 12 files changed, 146 insertions(+), 157 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution b/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution index 8e4bcc3d7..0e1b37a00 100644 --- a/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution +++ b/Examples/Modules/qed/breit_wheeler/inputs.3d_test_optical_depth_evolution @@ -158,11 +158,11 @@ qed_bw.lookup_table_mode = "dummy_builtin" ################################# ### EXTERNAL E FIELD ### (3e15 * [-0.811107105653813 0.324442842261525 0.486664263392288] ) -warpx.E_ext_particle_init_style = "constant" -warpx.E_external_particle = -2433321316961438 973328526784575 1459992790176863 +particles.E_ext_particle_init_style = "constant" +particles.E_external_particle = -2433321316961438 973328526784575 1459992790176863 #### ### EXTERNAL B FIELD ### (1e7 * [0.28571429 0.42857143 0.85714286] ) -warpx.B_ext_particle_init_style = "constant" -warpx.B_external_particle = 2857142.85714286 4285714.28571428 8571428.57142857 +particles.B_ext_particle_init_style = "constant" +particles.B_external_particle = 2857142.85714286 4285714.28571428 8571428.57142857 #### diff --git a/Examples/Tests/Larmor/inputs.mr b/Examples/Tests/Larmor/inputs.mr index cef5e0735..8b197543c 100644 --- a/Examples/Tests/Larmor/inputs.mr +++ b/Examples/Tests/Larmor/inputs.mr @@ -34,8 +34,8 @@ geometry.prob_hi = 2.0 2.0 warpx.do_pml = 1 warpx.pml_ncell = 10 -warpx.B_ext_particle_init_style = "constant" -warpx.B_external_particle = 0.0 0.00078110417851950768 0.0 +particles.B_ext_particle_init_style = "constant" +particles.B_external_particle = 0.0 0.00078110417851950768 0.0 # Verbosity warpx.verbose = 1 diff --git a/Examples/Tests/particle_pusher/inputs b/Examples/Tests/particle_pusher/inputs index 53376bb21..c61ac72c2 100755 --- a/Examples/Tests/particle_pusher/inputs +++ b/Examples/Tests/particle_pusher/inputs @@ -40,7 +40,7 @@ warpx.plot_raw_fields = 0 # External fields # Ex is set to be Ex = -vy*Bz -warpx.B_ext_particle_init_style = "constant" -warpx.B_external_particle = 0.0 0.0 1.0 -warpx.E_ext_particle_init_style = "constant" -warpx.E_external_particle = -2.994174829214179e+08 0.0 0.0 +particles.B_ext_particle_init_style = "constant" +particles.B_external_particle = 0.0 0.0 1.0 +particles.E_ext_particle_init_style = "constant" +particles.E_external_particle = -2.994174829214179e+08 0.0 0.0 diff --git a/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs b/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs index 03aa89b51..07ae2f17f 100644 --- a/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs +++ b/Examples/Tests/radiation_reaction/test_const_B_analytical/inputs @@ -64,5 +64,5 @@ pos_perp2.single_particle_vel = -958.3148474999095 127.77531299998823 255.550625 pos_perp2.single_particle_weight = 1e-08 pos_perp2.do_classical_radiation_reaction = 1 -warpx.B_ext_particle_init_style = "constant" -warpx.B_external_particle = 917978.2333474257 1376967.350021139 2753934.700042278 +particles.B_ext_particle_init_style = "constant" +particles.B_external_particle = 917978.2333474257 1376967.350021139 2753934.700042278 diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index 9db129b05..f3ea1825c 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -8,6 +8,7 @@ #include #include #include +#include #include #ifdef WARPX_QED @@ -215,6 +216,29 @@ public: IonizationProcess ionization_process; + std::string m_B_ext_particle_s = "default"; + std::string m_E_ext_particle_s = "default"; + // External fields added to particle fields. + amrex::Vector m_B_external_particle; + amrex::Vector m_E_external_particle; + // Parser for B_external on the particle + std::string m_str_Bx_ext_particle_function; + std::string m_str_By_ext_particle_function; + std::string m_str_Bz_ext_particle_function; + // Parser for E_external on the particle + std::string m_str_Ex_ext_particle_function; + std::string m_str_Ey_ext_particle_function; + std::string m_str_Ez_ext_particle_function; + // ParserWrapper for B_external on the particle + std::unique_ptr m_Bx_particle_parser; + std::unique_ptr m_By_particle_parser; + std::unique_ptr m_Bz_particle_parser; + // ParserWrapper for E_external on the particle + std::unique_ptr m_Ex_particle_parser; + std::unique_ptr m_Ey_particle_parser; + std::unique_ptr m_Ez_particle_parser; + + protected: // Particle container types diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index d84bc1afa..78b976209 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -72,6 +72,85 @@ MultiParticleContainer::ReadParameters () { ParmParse pp("particles"); + // allocating and initializing default values of external fields for particles + m_E_external_particle.resize(3); + m_B_external_particle.resize(3); + // initialize E and B fields to 0.0 + for (int idim = 0; idim < 3; ++idim) { + m_E_external_particle[idim] = 0.0; + m_B_external_particle[idim] = 0.0; + } + // default values of E_external_particle and B_external_particle + // are used to set the E and B field when "constant" or "parser" + // is not explicitly used in the input + pp.query("B_ext_particle_init_style", m_B_ext_particle_s); + std::transform(m_B_ext_particle_s.begin(), + m_B_ext_particle_s.end(), + m_B_ext_particle_s.begin(), + ::tolower); + pp.query("E_ext_particle_init_style", m_E_ext_particle_s); + std::transform(m_E_ext_particle_s.begin(), + m_E_ext_particle_s.end(), + m_E_ext_particle_s.begin(), + ::tolower); + // if the input string for B_external on particles is "constant" + // then the values for the external B on particles must + // be provided in the input file. + if (m_B_ext_particle_s == "constant") + pp.getarr("B_external_particle", m_B_external_particle); + + // if the input string for E_external on particles is "constant" + // then the values for the external E on particles must + // be provided in the input file. + if (m_E_ext_particle_s == "constant") + pp.getarr("E_external_particle", m_E_external_particle); + + // if the input string for B_ext_particle_s is + // "parse_b_ext_particle_function" then the mathematical expression + // for the Bx_, By_, Bz_external_particle_function(x,y,z) + // must be provided in the input file. + if (m_B_ext_particle_s == "parse_b_ext_particle_function") { + // store the mathematical expression as string + Store_parserString(pp, "Bx_external_particle_function(x,y,z)", + m_str_Bx_ext_particle_function); + Store_parserString(pp, "By_external_particle_function(x,y,z)", + m_str_By_ext_particle_function); + Store_parserString(pp, "Bz_external_particle_function(x,y,z)", + m_str_Bz_ext_particle_function); + + m_Bx_particle_parser.reset(new ParserWrapper( + makeParser(m_str_Bx_ext_particle_function))); + m_By_particle_parser.reset(new ParserWrapper( + makeParser(m_str_By_ext_particle_function))); + m_Bz_particle_parser.reset(new ParserWrapper( + makeParser(m_str_Bz_ext_particle_function))); + + } + + // if the input string for E_ext_particle_s is + // "parse_e_ext_particle_function" then the mathematical expression + // for the Ex_, Ey_, Ez_external_particle_function(x,y,z) + // must be provided in the input file. + if (m_E_ext_particle_s == "parse_e_ext_particle_function") { + // store the mathematical expression as string + Store_parserString(pp, "Ex_external_particle_function(x,y,z)", + m_str_Ex_ext_particle_function); + Store_parserString(pp, "Ey_external_particle_function(x,y,z)", + m_str_Ey_ext_particle_function); + Store_parserString(pp, "Ez_external_particle_function(x,y,z)", + m_str_Ez_ext_particle_function); + m_Ex_particle_parser.reset(new ParserWrapper( + makeParser(m_str_Ex_ext_particle_function))); + m_Ey_particle_parser.reset(new ParserWrapper( + makeParser(m_str_Ey_ext_particle_function))); + m_Ez_particle_parser.reset(new ParserWrapper( + makeParser(m_str_Ez_ext_particle_function))); + + } + + + + pp.query("nspecies", nspecies); BL_ASSERT(nspecies >= 0); diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index a4a9dbcfc..51448c747 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -972,29 +972,32 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Gpu::ManagedDeviceVector zp) { const long np = pti.numParticles(); - - if (WarpX::E_ext_particle_s=="constant" || - WarpX::E_ext_particle_s=="default") { - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); + /// get WarpX class object + auto & warpx = WarpX::GetInstance(); + /// get MultiParticleContainer class object + auto & mypc = warpx.GetPartContainer(); + if (mypc.m_E_ext_particle_s=="constant" || + mypc.m_E_ext_particle_s=="default") { + Exp.assign(np,mypc.m_E_external_particle[0]); + Eyp.assign(np,mypc.m_E_external_particle[1]); + Ezp.assign(np,mypc.m_E_external_particle[2]); } - if (WarpX::B_ext_particle_s=="constant" || - WarpX::B_ext_particle_s=="default") { - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); + if (mypc.m_B_ext_particle_s=="constant" || + mypc.m_B_ext_particle_s=="default") { + Bxp.assign(np,mypc.m_B_external_particle[0]); + Byp.assign(np,mypc.m_B_external_particle[1]); + Bzp.assign(np,mypc.m_B_external_particle[2]); } - if (WarpX::E_ext_particle_s=="parse_e_ext_particle_function") { + if (mypc.m_E_ext_particle_s=="parse_e_ext_particle_function") { Real* const AMREX_RESTRICT xp_data = xp.dataPtr(); Real* const AMREX_RESTRICT yp_data = yp.dataPtr(); Real* const AMREX_RESTRICT zp_data = zp.dataPtr(); Real* const AMREX_RESTRICT Exp_data = Exp.dataPtr(); Real* const AMREX_RESTRICT Eyp_data = Eyp.dataPtr(); Real* const AMREX_RESTRICT Ezp_data = Ezp.dataPtr(); - ParserWrapper *xfield_partparser = Ex_particle_parser.get(); - ParserWrapper *yfield_partparser = Ey_particle_parser.get(); - ParserWrapper *zfield_partparser = Ez_particle_parser.get(); + ParserWrapper *xfield_partparser = mypc.m_Ex_particle_parser.get(); + ParserWrapper *yfield_partparser = mypc.m_Ey_particle_parser.get(); + ParserWrapper *zfield_partparser = mypc.m_Ez_particle_parser.get(); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); @@ -1002,16 +1005,16 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); }); } - if (WarpX::B_ext_particle_s=="parse_b_ext_particle_function") { + if (mypc.m_B_ext_particle_s=="parse_b_ext_particle_function") { Real* const AMREX_RESTRICT xp_data = xp.dataPtr(); Real* const AMREX_RESTRICT yp_data = yp.dataPtr(); Real* const AMREX_RESTRICT zp_data = zp.dataPtr(); Real* const AMREX_RESTRICT Bxp_data = Bxp.dataPtr(); Real* const AMREX_RESTRICT Byp_data = Byp.dataPtr(); Real* const AMREX_RESTRICT Bzp_data = Bzp.dataPtr(); - ParserWrapper *xfield_partparser = Bx_particle_parser.get(); - ParserWrapper *yfield_partparser = By_particle_parser.get(); - ParserWrapper *zfield_partparser = Bz_particle_parser.get(); + ParserWrapper *xfield_partparser = mypc.m_Bx_particle_parser.get(); + ParserWrapper *yfield_partparser = mypc.m_By_particle_parser.get(); + ParserWrapper *zfield_partparser = mypc.m_Bz_particle_parser.get(); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); @@ -1077,9 +1080,6 @@ PhysicalParticleContainer::FieldGather (int lev, // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - // m_xp[thread_num], m_yp[thread_num], - // m_zp[thread_num]); // // Field Gather @@ -1210,9 +1210,6 @@ PhysicalParticleContainer::Evolve (int lev, // copy data from particle container to temp arrays // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - // m_xp[thread_num], m_yp[thread_num], - // m_zp[thread_num]); // Determine which particles deposit/gather in the buffer, and // which particles deposit/gather in the fine patch @@ -1858,10 +1855,6 @@ PhysicalParticleContainer::PushP (int lev, Real dt, // pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - //ApplyExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, - // m_xp[thread_num], m_yp[thread_num], - // m_zp[thread_num]); - int e_is_nodal = Ex.is_nodal() and Ey.is_nodal() and Ez.is_nodal(); FieldGather(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, &exfab, &eyfab, &ezfab, &bxfab, &byfab, &bzfab, @@ -2226,7 +2219,6 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, AMREX_ALWAYS_ASSERT_WITH_MESSAGE((gather_lev==(lev-1)) || (gather_lev==(lev )), "Gather buffers only work for lev-1"); - // If no particles, do not do anything if (np_to_gather == 0) return; @@ -2236,6 +2228,7 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); + // Get cell size on gather_lev const std::array& dx = WarpX::CellSize(std::max(gather_lev,0)); diff --git a/Source/Particles/RigidInjectedParticleContainer.cpp b/Source/Particles/RigidInjectedParticleContainer.cpp index bee71fba1..f3b502a0a 100644 --- a/Source/Particles/RigidInjectedParticleContainer.cpp +++ b/Source/Particles/RigidInjectedParticleContainer.cpp @@ -392,13 +392,6 @@ RigidInjectedParticleContainer::PushP (int lev, Real dt, const FArrayBox& byfab = By[pti]; const FArrayBox& bzfab = Bz[pti]; - Exp.assign(np,WarpX::E_external_particle[0]); - Eyp.assign(np,WarpX::E_external_particle[1]); - Ezp.assign(np,WarpX::E_external_particle[2]); - Bxp.assign(np,WarpX::B_external_particle[0]); - Byp.assign(np,WarpX::B_external_particle[1]); - Bzp.assign(np,WarpX::B_external_particle[2]); - // // copy data from particle container to temp arrays // diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 14eb1a96f..39ce1dcda 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -323,14 +323,14 @@ public: //amrex::Real getMass () {return mass;} amrex::ParticleReal getMass () const {return mass;} - // ParserWrapper for B_external on the particle - std::unique_ptr Bx_particle_parser; - std::unique_ptr By_particle_parser; - std::unique_ptr Bz_particle_parser; - // ParserWrapper for E_external on the particle - std::unique_ptr Ex_particle_parser; - std::unique_ptr Ey_particle_parser; - std::unique_ptr Ez_particle_parser; +// // ParserWrapper for B_external on the particle +// std::unique_ptr Bx_particle_parser; +// std::unique_ptr By_particle_parser; +// std::unique_ptr Bz_particle_parser; +// // ParserWrapper for E_external on the particle +// std::unique_ptr Ex_particle_parser; +// std::unique_ptr Ey_particle_parser; +// std::unique_ptr Ez_particle_parser; protected: diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 465539d1a..9fe331f13 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -115,24 +115,6 @@ WarpXParticleContainer::WarpXParticleContainer (AmrCore* amr_core, int ispecies) m_yp.resize(num_threads); m_zp.resize(num_threads); - if (WarpX::B_ext_particle_s == "parse_b_ext_particle_function") { - Bx_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_Bx_ext_particle_function))); - By_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_By_ext_particle_function))); - Bz_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_Bz_ext_particle_function))); - } - - if (WarpX::E_ext_particle_s == "parse_e_ext_particle_function") { - Ex_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_Ex_ext_particle_function))); - Ey_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_Ey_ext_particle_function))); - Ez_particle_parser.reset(new ParserWrapper( - makeParser(WarpX::str_Ez_ext_particle_function))); - } - } void diff --git a/Source/WarpX.H b/Source/WarpX.H index 5818df394..9b0110ea8 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -81,10 +81,6 @@ public: static void GotoNextLine (std::istream& is); - // External fields added to particle fields. - static amrex::Vector B_external_particle; - static amrex::Vector E_external_particle; - // Initial field on the grid. static amrex::Vector E_external_grid; static amrex::Vector B_external_grid; @@ -92,8 +88,6 @@ public: // Initialization Type for External E and B on grid and particles static std::string B_ext_grid_s; static std::string E_ext_grid_s; - static std::string B_ext_particle_s; - static std::string E_ext_particle_s; // Parser for B_external on the grid static std::string str_Bx_ext_grid_function; @@ -113,15 +107,6 @@ public: std::unique_ptr Eyfield_parser; std::unique_ptr Ezfield_parser; - // Parser for B_external on the particle - static std::string str_Bx_ext_particle_function; - static std::string str_By_ext_particle_function; - static std::string str_Bz_ext_particle_function; - // Parser for E_external on the particle - static std::string str_Ex_ext_particle_function; - static std::string str_Ey_ext_particle_function; - static std::string str_Ez_ext_particle_function; - // Algorithms static long current_deposition_algo; static long charge_deposition_algo; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 45ad16b58..07ea8c1af 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -24,16 +24,11 @@ using namespace amrex; -Vector WarpX::B_external_particle(3, 0.0); -Vector WarpX::E_external_particle(3, 0.0); - Vector WarpX::E_external_grid(3, 0.0); Vector WarpX::B_external_grid(3, 0.0); std::string WarpX::B_ext_grid_s = "default"; std::string WarpX::E_ext_grid_s = "default"; -std::string WarpX::B_ext_particle_s = "default"; -std::string WarpX::E_ext_particle_s = "default"; // Parser for B_external on the grid std::string WarpX::str_Bx_ext_grid_function; @@ -44,15 +39,6 @@ std::string WarpX::str_Ex_ext_grid_function; std::string WarpX::str_Ey_ext_grid_function; std::string WarpX::str_Ez_ext_grid_function; -// Parser for B_external on the particle -std::string WarpX::str_Bx_ext_particle_function; -std::string WarpX::str_By_ext_particle_function; -std::string WarpX::str_Bz_ext_particle_function; -// Parser for E_external on the particle -std::string WarpX::str_Ex_ext_particle_function; -std::string WarpX::str_Ey_ext_particle_function; -std::string WarpX::str_Ez_ext_particle_function; - int WarpX::do_moving_window = 0; int WarpX::moving_window_dir = -1; Real WarpX::moving_window_v = std::numeric_limits::max(); @@ -329,59 +315,6 @@ WarpX::ReadParameters () pp.query("zmax_plasma_to_compute_max_step", zmax_plasma_to_compute_max_step); - // default values of E_external_particle and B_external_particle - // are used to set the E and B field when "constant" or "parser" - // is not explicitly used in the input - pp.query("B_ext_particle_init_style", B_ext_particle_s); - std::transform(B_ext_particle_s.begin(), - B_ext_particle_s.end(), - B_ext_particle_s.begin(), - ::tolower); - pp.query("E_ext_particle_init_style", E_ext_particle_s); - std::transform(E_ext_particle_s.begin(), - E_ext_particle_s.end(), - E_ext_particle_s.begin(), - ::tolower); - // if the input string for B_external on particles is "constant" - // then the values for the external B on particles must - // be provided in the input file. - if (B_ext_particle_s == "constant") - pp.getarr("B_external_particle", B_external_particle); - - // if the input string for E_external on particles is "constant" - // then the values for the external E on particles must - // be provided in the input file. - if (E_ext_particle_s == "constant") - pp.getarr("E_external_particle", E_external_particle); - - // if the input string for B_ext_particle_s is - // "parse_b_ext_particle_function" then the mathematical expression - // for the Bx_, By_, Bz_external_particle_function(x,y,z) - // must be provided in the input file. - if (B_ext_particle_s == "parse_b_ext_particle_function") { - // store the mathematical expression as string - Store_parserString(pp, "Bx_external_particle_function(x,y,z)", - str_Bx_ext_particle_function); - Store_parserString(pp, "By_external_particle_function(x,y,z)", - str_By_ext_particle_function); - Store_parserString(pp, "Bz_external_particle_function(x,y,z)", - str_Bz_ext_particle_function); - } - - // if the input string for E_ext_particle_s is - // "parse_e_ext_particle_function" then the mathematical expression - // for the Ex_, Ey_, Ez_external_particle_function(x,y,z) - // must be provided in the input file. - if (E_ext_particle_s == "parse_e_ext_particle_function") { - // store the mathematical expression as string - Store_parserString(pp, "Ex_external_particle_function(x,y,z)", - str_Ex_ext_particle_function); - Store_parserString(pp, "Ey_external_particle_function(x,y,z)", - str_Ey_ext_particle_function); - Store_parserString(pp, "Ez_external_particle_function(x,y,z)", - str_Ez_ext_particle_function); - } - pp.query("do_moving_window", do_moving_window); if (do_moving_window) { -- cgit v1.2.3 From eae5b5934107d1f044c9f869e53b8c41678ea2ea Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 13 Jan 2020 11:41:22 -0800 Subject: shared memory for parser on gpu --- Source/Particles/PhysicalParticleContainer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 51448c747..dc6b5f6c1 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1003,7 +1003,11 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Eyp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - }); + } + /* To allocate shared memory for the GPU threads. */ + /* But, for now only 3 doubles (x,y,z) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + ); } if (mypc.m_B_ext_particle_s=="parse_b_ext_particle_function") { Real* const AMREX_RESTRICT xp_data = xp.dataPtr(); @@ -1020,7 +1024,11 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Byp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Bzp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - }); + } + /* To allocate shared memory for the GPU threads. */ + /* But, for now only 3 doubles (x,y,z) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + ); } } -- cgit v1.2.3 From 728214c866b53620aaae1d47e2f8cfb604f7e2fa Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Mon, 13 Jan 2020 12:10:05 -0800 Subject: missing comma --- Source/Particles/PhysicalParticleContainer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index dc6b5f6c1..d4de7bb53 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1003,7 +1003,7 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Eyp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - } + }, /* To allocate shared memory for the GPU threads. */ /* But, for now only 3 doubles (x,y,z) are allocated. */ amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 @@ -1024,7 +1024,7 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Byp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); Bzp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - } + }, /* To allocate shared memory for the GPU threads. */ /* But, for now only 3 doubles (x,y,z) are allocated. */ amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 -- cgit v1.2.3 From eb6089d8ad31c0fa34acc9592f4fc0f9fe7099fb Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Tue, 14 Jan 2020 11:37:49 -0800 Subject: adding time as an independent variable for parser function (x,y,z,t) --- Source/Initialization/InjectorDensity.cpp | 4 ++-- Source/Initialization/InjectorMomentum.cpp | 4 ++-- Source/Initialization/WarpXInitData.cpp | 4 ++-- Source/Parser/GpuParser.H | 14 ++++++++++---- Source/Parser/GpuParser.cpp | 4 ++++ Source/Parser/WarpXParserWrapper.H | 2 +- Source/Parser/wp_parser_c.h | 2 +- Source/Particles/MultiParticleContainer.cpp | 12 ++++++------ Source/Particles/PhysicalParticleContainer.H | 2 +- Source/Particles/PhysicalParticleContainer.cpp | 26 ++++++++++++++------------ Source/Utils/WarpXMovingWindow.cpp | 2 +- Source/Utils/WarpXUtil.cpp | 3 ++- 12 files changed, 46 insertions(+), 33 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Initialization/InjectorDensity.cpp b/Source/Initialization/InjectorDensity.cpp index 9f711a7af..fa54b342c 100644 --- a/Source/Initialization/InjectorDensity.cpp +++ b/Source/Initialization/InjectorDensity.cpp @@ -36,8 +36,8 @@ InjectorDensity::sharedMemoryNeeded () const noexcept case Type::parser: { // For parser injector, the 3D position of each particle - // is stored in shared memory. - return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3; + // and time, t, is stored in shared memory. + return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4; } default: return 0; diff --git a/Source/Initialization/InjectorMomentum.cpp b/Source/Initialization/InjectorMomentum.cpp index 8fadf0c4b..255883a34 100644 --- a/Source/Initialization/InjectorMomentum.cpp +++ b/Source/Initialization/InjectorMomentum.cpp @@ -30,9 +30,9 @@ InjectorMomentum::sharedMemoryNeeded () const noexcept { case Type::parser: { - // For parser injector, the 3D position of each particle + // For parser injector, the 3D position of each particle and time, t, // is stored in shared memory. - return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3; + return amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4; } default: return 0; diff --git a/Source/Initialization/WarpXInitData.cpp b/Source/Initialization/WarpXInitData.cpp index be29a1cbc..48c30ae93 100644 --- a/Source/Initialization/WarpXInitData.cpp +++ b/Source/Initialization/WarpXInitData.cpp @@ -535,8 +535,8 @@ WarpX::InitializeExternalFieldsOnGridUsingParser ( mfzfab(i,j,k) = zfield_parser->getField(x,y,z); }, /* To allocate shared memory for the GPU threads. */ - /* But, for now only 3 doubles (x,y,z) are allocated. */ - amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + /* But, for now only 4 doubles (x,y,z,t) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4 ); } diff --git a/Source/Parser/GpuParser.H b/Source/Parser/GpuParser.H index c158ee314..ff855d275 100644 --- a/Source/Parser/GpuParser.H +++ b/Source/Parser/GpuParser.H @@ -17,7 +17,7 @@ public: AMREX_GPU_HOST_DEVICE amrex::Real - operator() (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + operator() (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real t=0.0) const noexcept { #ifdef AMREX_USE_GPU @@ -27,15 +27,17 @@ public: amrex::Gpu::SharedMemory gsm; amrex::Real* p = gsm.dataPtr(); int tid = threadIdx.x + threadIdx.y*blockDim.x + threadIdx.z*(blockDim.x*blockDim.y); - p[tid*3] = x; - p[tid*3+1] = y; - p[tid*3+2] = z; + p[tid*4] = x; + p[tid*4+1] = y; + p[tid*4+2] = z; + p[tid*4+3] = t; return wp_ast_eval(m_gpu_parser.ast); #else // WarpX compiled for GPU, function compiled for __host__ m_var.x = x; m_var.y = y; m_var.z = z; + m_t = t; return wp_ast_eval(m_cpu_parser.ast); #endif @@ -49,10 +51,12 @@ public: m_var[tid].x = x; m_var[tid].y = y; m_var[tid].z = z; + m_t[tid] = t; return wp_ast_eval(m_parser[tid]->ast); #endif } + private: #ifdef AMREX_USE_GPU @@ -61,10 +65,12 @@ private: // Copy of the parser running on __host__ struct wp_parser m_cpu_parser; mutable amrex::XDim3 m_var; + mutable amrex::Real m_t; #else // Only one parser struct wp_parser** m_parser; mutable amrex::XDim3* m_var; + mutable amrex::Real* m_t; int nthreads; #endif }; diff --git a/Source/Parser/GpuParser.cpp b/Source/Parser/GpuParser.cpp index 5078b498b..ba904666b 100644 --- a/Source/Parser/GpuParser.cpp +++ b/Source/Parser/GpuParser.cpp @@ -16,6 +16,7 @@ GpuParser::GpuParser (WarpXParser const& wp) wp_parser_regvar_gpu(&m_gpu_parser, "x", 0); wp_parser_regvar_gpu(&m_gpu_parser, "y", 1); wp_parser_regvar_gpu(&m_gpu_parser, "z", 2); + wp_parser_regvar_gpu(&m_gpu_parser, "t", 3); // Initialize CPU parser: allocate memory in CUDA managed memory, // copy all data needed on CPU to m_cpu_parser @@ -28,6 +29,7 @@ GpuParser::GpuParser (WarpXParser const& wp) wp_parser_regvar(&m_cpu_parser, "x", &(m_var.x)); wp_parser_regvar(&m_cpu_parser, "y", &(m_var.y)); wp_parser_regvar(&m_cpu_parser, "z", &(m_var.z)); + wp_parser_regvar(&m_cpu_parser, "t", &(m_t)); #else // not defined AMREX_USE_GPU @@ -39,6 +41,7 @@ GpuParser::GpuParser (WarpXParser const& wp) m_parser = ::new struct wp_parser*[nthreads]; m_var = ::new amrex::XDim3[nthreads]; + m_t = ::new amrex::Real[nthreads]; for (int tid = 0; tid < nthreads; ++tid) { @@ -50,6 +53,7 @@ GpuParser::GpuParser (WarpXParser const& wp) wp_parser_regvar(m_parser[tid], "x", &(m_var[tid].x)); wp_parser_regvar(m_parser[tid], "y", &(m_var[tid].y)); wp_parser_regvar(m_parser[tid], "z", &(m_var[tid].z)); + wp_parser_regvar(m_parser[tid], "t", &(m_t[tid])); } #endif // AMREX_USE_GPU diff --git a/Source/Parser/WarpXParserWrapper.H b/Source/Parser/WarpXParserWrapper.H index 2dd7f72c7..2a355e749 100644 --- a/Source/Parser/WarpXParserWrapper.H +++ b/Source/Parser/WarpXParserWrapper.H @@ -24,7 +24,7 @@ struct ParserWrapper AMREX_GPU_HOST_DEVICE amrex::Real - getField (amrex::Real x, amrex::Real y, amrex::Real z) const noexcept + getField (amrex::Real x, amrex::Real y, amrex::Real z, amrex::Real t=0.0) const noexcept { return m_parser(x,y,z); } diff --git a/Source/Parser/wp_parser_c.h b/Source/Parser/wp_parser_c.h index 970d6b355..2cf0e2c00 100644 --- a/Source/Parser/wp_parser_c.h +++ b/Source/Parser/wp_parser_c.h @@ -30,7 +30,7 @@ wp_ast_eval (struct wp_node* node) #ifdef AMREX_DEVICE_COMPILE extern __shared__ amrex_real extern_xyz[]; int tid = threadIdx.x + threadIdx.y*blockDim.x + threadIdx.z*(blockDim.x*blockDim.y); - amrex_real* x = extern_xyz + tid*3; + amrex_real* x = extern_xyz + tid*4; // parser assumes 4 independent variables (x,y,z,t) #endif switch (node->type) diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index 0fd81e698..c99bd3c5b 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -111,11 +111,11 @@ MultiParticleContainer::ReadParameters () // must be provided in the input file. if (m_B_ext_particle_s == "parse_b_ext_particle_function") { // store the mathematical expression as string - Store_parserString(pp, "Bx_external_particle_function(x,y,z)", + Store_parserString(pp, "Bx_external_particle_function(x,y,z,t)", m_str_Bx_ext_particle_function); - Store_parserString(pp, "By_external_particle_function(x,y,z)", + Store_parserString(pp, "By_external_particle_function(x,y,z,t)", m_str_By_ext_particle_function); - Store_parserString(pp, "Bz_external_particle_function(x,y,z)", + Store_parserString(pp, "Bz_external_particle_function(x,y,z,t)", m_str_Bz_ext_particle_function); m_Bx_particle_parser.reset(new ParserWrapper( @@ -133,11 +133,11 @@ MultiParticleContainer::ReadParameters () // must be provided in the input file. if (m_E_ext_particle_s == "parse_e_ext_particle_function") { // store the mathematical expression as string - Store_parserString(pp, "Ex_external_particle_function(x,y,z)", + Store_parserString(pp, "Ex_external_particle_function(x,y,z,t)", m_str_Ex_ext_particle_function); - Store_parserString(pp, "Ey_external_particle_function(x,y,z)", + Store_parserString(pp, "Ey_external_particle_function(x,y,z,t)", m_str_Ey_ext_particle_function); - Store_parserString(pp, "Ez_external_particle_function(x,y,z)", + Store_parserString(pp, "Ez_external_particle_function(x,y,z,t)", m_str_Ez_ext_particle_function); m_Ex_particle_parser.reset(new ParserWrapper( makeParser(m_str_Ex_ext_particle_function))); diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 147b632eb..8867778f7 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -64,7 +64,7 @@ public: RealVector& Byp, RealVector& Bzp, amrex::Gpu::ManagedDeviceVector xp, amrex::Gpu::ManagedDeviceVector yp, - amrex::Gpu::ManagedDeviceVector zp); + amrex::Gpu::ManagedDeviceVector zp, int lev); virtual void FieldGather (int lev, const amrex::MultiFab& Ex, diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index d4de7bb53..5b80ed2d9 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -969,7 +969,7 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, RealVector& Bxp, RealVector& Byp, RealVector& Bzp, Gpu::ManagedDeviceVector xp, Gpu::ManagedDeviceVector yp, - Gpu::ManagedDeviceVector zp) + Gpu::ManagedDeviceVector zp, int lev) { const long np = pti.numParticles(); /// get WarpX class object @@ -998,15 +998,16 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, ParserWrapper *xfield_partparser = mypc.m_Ex_particle_parser.get(); ParserWrapper *yfield_partparser = mypc.m_Ey_particle_parser.get(); ParserWrapper *zfield_partparser = mypc.m_Ez_particle_parser.get(); + Real time = warpx.gett_new(lev); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { - Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - Eyp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Exp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); + Eyp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); + Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); }, /* To allocate shared memory for the GPU threads. */ - /* But, for now only 3 doubles (x,y,z) are allocated. */ - amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + /* But, for now only 3 doubles (x,y,z,t) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4 ); } if (mypc.m_B_ext_particle_s=="parse_b_ext_particle_function") { @@ -1019,15 +1020,16 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, ParserWrapper *xfield_partparser = mypc.m_Bx_particle_parser.get(); ParserWrapper *yfield_partparser = mypc.m_By_particle_parser.get(); ParserWrapper *zfield_partparser = mypc.m_Bz_particle_parser.get(); + Real time = warpx.gett_new(lev); amrex::ParallelFor(pti.numParticles(), [=] AMREX_GPU_DEVICE (long i) { - Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - Byp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); - Bzp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i]); + Bxp_data[i] = xfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); + Byp_data[i] = yfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); + Bzp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); }, /* To allocate shared memory for the GPU threads. */ - /* But, for now only 3 doubles (x,y,z) are allocated. */ - amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 3 + /* But, for now only 4 doubles (x,y,z,t) are allocated. */ + amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4 ); } @@ -2234,7 +2236,7 @@ PhysicalParticleContainer::FieldGather (WarpXParIter& pti, // gathering fields from the grid to the particles. AssignExternalFieldOnParticles(pti, Exp, Eyp, Ezp, Bxp, Byp, Bzp, m_xp[thread_num], m_yp[thread_num], - m_zp[thread_num]); + m_zp[thread_num], lev); // Get cell size on gather_lev diff --git a/Source/Utils/WarpXMovingWindow.cpp b/Source/Utils/WarpXMovingWindow.cpp index e05a64bfe..91dd4e2ca 100644 --- a/Source/Utils/WarpXMovingWindow.cpp +++ b/Source/Utils/WarpXMovingWindow.cpp @@ -309,7 +309,7 @@ WarpX::shiftMF (MultiFab& mf, const Geometry& geom, int num_shift, int dir, #endif srcfab(i,j,k,n) = field_parser->getField(x,y,z); } - , amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double)*3 + , amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double)*4 ); } diff --git a/Source/Utils/WarpXUtil.cpp b/Source/Utils/WarpXUtil.cpp index e9fb958fd..a154e93df 100644 --- a/Source/Utils/WarpXUtil.cpp +++ b/Source/Utils/WarpXUtil.cpp @@ -185,12 +185,13 @@ void Store_parserString(amrex::ParmParse& pp, std::string query_string, WarpXParser makeParser (std::string const& parse_function) { WarpXParser parser(parse_function); - parser.registerVariables({"x","y","z"}); + parser.registerVariables({"x","y","z","t"}); ParmParse pp("my_constants"); std::set symbols = parser.symbols(); symbols.erase("x"); symbols.erase("y"); symbols.erase("z"); + symbols.erase("t"); for (auto it = symbols.begin(); it != symbols.end(); ) { Real v; if (pp.query(it->c_str(), v)) { -- cgit v1.2.3 From 262de3a369647eac5820c79b010e94865b280db8 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Wed, 15 Jan 2020 12:15:34 -0800 Subject: changes as suggested in review. --- Source/Particles/MultiParticleContainer.H | 8 ------- Source/Particles/MultiParticleContainer.cpp | 32 ++++++++++++++++---------- Source/Particles/PhysicalParticleContainer.H | 5 ++-- Source/Particles/PhysicalParticleContainer.cpp | 5 ---- Source/Particles/WarpXParticleContainer.H | 10 -------- Source/WarpX.H | 2 +- 6 files changed, 24 insertions(+), 38 deletions(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/MultiParticleContainer.H b/Source/Particles/MultiParticleContainer.H index f3ea1825c..ed1c2f371 100644 --- a/Source/Particles/MultiParticleContainer.H +++ b/Source/Particles/MultiParticleContainer.H @@ -221,14 +221,6 @@ public: // External fields added to particle fields. amrex::Vector m_B_external_particle; amrex::Vector m_E_external_particle; - // Parser for B_external on the particle - std::string m_str_Bx_ext_particle_function; - std::string m_str_By_ext_particle_function; - std::string m_str_Bz_ext_particle_function; - // Parser for E_external on the particle - std::string m_str_Ex_ext_particle_function; - std::string m_str_Ey_ext_particle_function; - std::string m_str_Ez_ext_particle_function; // ParserWrapper for B_external on the particle std::unique_ptr m_Bx_particle_parser; std::unique_ptr m_By_particle_parser; diff --git a/Source/Particles/MultiParticleContainer.cpp b/Source/Particles/MultiParticleContainer.cpp index c99bd3c5b..ab836ce9d 100644 --- a/Source/Particles/MultiParticleContainer.cpp +++ b/Source/Particles/MultiParticleContainer.cpp @@ -111,19 +111,23 @@ MultiParticleContainer::ReadParameters () // must be provided in the input file. if (m_B_ext_particle_s == "parse_b_ext_particle_function") { // store the mathematical expression as string + std::string str_Bx_ext_particle_function; + std::string str_By_ext_particle_function; + std::string str_Bz_ext_particle_function; Store_parserString(pp, "Bx_external_particle_function(x,y,z,t)", - m_str_Bx_ext_particle_function); + str_Bx_ext_particle_function); Store_parserString(pp, "By_external_particle_function(x,y,z,t)", - m_str_By_ext_particle_function); + str_By_ext_particle_function); Store_parserString(pp, "Bz_external_particle_function(x,y,z,t)", - m_str_Bz_ext_particle_function); + str_Bz_ext_particle_function); + // Parser for B_external on the particle m_Bx_particle_parser.reset(new ParserWrapper( - makeParser(m_str_Bx_ext_particle_function))); + makeParser(str_Bx_ext_particle_function))); m_By_particle_parser.reset(new ParserWrapper( - makeParser(m_str_By_ext_particle_function))); + makeParser(str_By_ext_particle_function))); m_Bz_particle_parser.reset(new ParserWrapper( - makeParser(m_str_Bz_ext_particle_function))); + makeParser(str_Bz_ext_particle_function))); } @@ -133,18 +137,22 @@ MultiParticleContainer::ReadParameters () // must be provided in the input file. if (m_E_ext_particle_s == "parse_e_ext_particle_function") { // store the mathematical expression as string + std::string str_Ex_ext_particle_function; + std::string str_Ey_ext_particle_function; + std::string str_Ez_ext_particle_function; Store_parserString(pp, "Ex_external_particle_function(x,y,z,t)", - m_str_Ex_ext_particle_function); + str_Ex_ext_particle_function); Store_parserString(pp, "Ey_external_particle_function(x,y,z,t)", - m_str_Ey_ext_particle_function); + str_Ey_ext_particle_function); Store_parserString(pp, "Ez_external_particle_function(x,y,z,t)", - m_str_Ez_ext_particle_function); + str_Ez_ext_particle_function); + // Parser for E_external on the particle m_Ex_particle_parser.reset(new ParserWrapper( - makeParser(m_str_Ex_ext_particle_function))); + makeParser(str_Ex_ext_particle_function))); m_Ey_particle_parser.reset(new ParserWrapper( - makeParser(m_str_Ey_ext_particle_function))); + makeParser(str_Ey_ext_particle_function))); m_Ez_particle_parser.reset(new ParserWrapper( - makeParser(m_str_Ez_ext_particle_function))); + makeParser(str_Ez_ext_particle_function))); } diff --git a/Source/Particles/PhysicalParticleContainer.H b/Source/Particles/PhysicalParticleContainer.H index 8867778f7..74d1a0f62 100644 --- a/Source/Particles/PhysicalParticleContainer.H +++ b/Source/Particles/PhysicalParticleContainer.H @@ -53,8 +53,9 @@ public: * in a mathematical expression. The default value for the E- and B-fields * is (0.0,0.0,0.0). * - * \param Exp-Bzp: fields on particles modified based on external E and B - * \param xp,yp,zp: arrays of particle positions required to compute + * \param[in,out] Exp-Bzp pointer to fields on particles modified based + * on external E and B + * \param[in] xp,yp,zp arrays of particle positions required to compute * mathematical expression for the external fields * using parser. */ diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index c04b3d32a..91cc5fb12 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1218,11 +1218,6 @@ PhysicalParticleContainer::Evolve (int lev, exfab, eyfab, ezfab, bxfab, byfab, bzfab); } - // - // copy data from particle container to temp arrays - // - pti.GetPosition(m_xp[thread_num], m_yp[thread_num], m_zp[thread_num]); - // Determine which particles deposit/gather in the buffer, and // which particles deposit/gather in the fine patch long nfine_current = np; diff --git a/Source/Particles/WarpXParticleContainer.H b/Source/Particles/WarpXParticleContainer.H index 39ce1dcda..398334d93 100644 --- a/Source/Particles/WarpXParticleContainer.H +++ b/Source/Particles/WarpXParticleContainer.H @@ -323,16 +323,6 @@ public: //amrex::Real getMass () {return mass;} amrex::ParticleReal getMass () const {return mass;} -// // ParserWrapper for B_external on the particle -// std::unique_ptr Bx_particle_parser; -// std::unique_ptr By_particle_parser; -// std::unique_ptr Bz_particle_parser; -// // ParserWrapper for E_external on the particle -// std::unique_ptr Ex_particle_parser; -// std::unique_ptr Ey_particle_parser; -// std::unique_ptr Ez_particle_parser; - - protected: std::map particle_comps; diff --git a/Source/WarpX.H b/Source/WarpX.H index ad4fa29b1..ed6233743 100644 --- a/Source/WarpX.H +++ b/Source/WarpX.H @@ -87,7 +87,7 @@ public: static amrex::Vector E_external_grid; static amrex::Vector B_external_grid; - // Initialization Type for External E and B on grid and particles + // Initialization Type for External E and B on grid static std::string B_ext_grid_s; static std::string E_ext_grid_s; -- cgit v1.2.3 From 2762b9acd8a9e3cb64185c49c8ad19a016a05182 Mon Sep 17 00:00:00 2001 From: RevathiJambunathan Date: Wed, 15 Jan 2020 12:23:53 -0800 Subject: fixing typo in comment --- Source/Particles/PhysicalParticleContainer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 91cc5fb12..5d56a5c42 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -1008,7 +1008,7 @@ PhysicalParticleContainer::AssignExternalFieldOnParticles(WarpXParIter& pti, Ezp_data[i] = zfield_partparser->getField(xp_data[i],yp_data[i],zp_data[i],time); }, /* To allocate shared memory for the GPU threads. */ - /* But, for now only 3 doubles (x,y,z,t) are allocated. */ + /* But, for now only 4 doubles (x,y,z,t) are allocated. */ amrex::Gpu::numThreadsPerBlockParallelFor() * sizeof(double) * 4 ); } -- cgit v1.2.3 From d06b6f698729ffca37ddeefa79e3a9407d9f8d81 Mon Sep 17 00:00:00 2001 From: Yinjian Zhao Date: Thu, 23 Jan 2020 14:43:35 -0800 Subject: Change do_not_push to be species specific and add corresponding documentation. --- Docs/source/running_cpp/parameters.rst | 4 ++++ Source/Particles/PhysicalParticleContainer.cpp | 1 + Source/Particles/WarpXParticleContainer.cpp | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'Source/Particles/PhysicalParticleContainer.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index cba041e6d..fe01815a2 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -386,6 +386,10 @@ Particle initialization If `1` is given, both charge deposition and current deposition will not be done, thus that species does not contribute to the fields. +* ``.do_not_push`` (`0` or `1` optional; default `0`) + If `1` is given, this species will not be pushed + by any pusher during the simulation. + * ``.plot_species`` (`0` or `1` optional; default `1`) Whether to plot particle quantities for this species. diff --git a/Source/Particles/PhysicalParticleContainer.cpp b/Source/Particles/PhysicalParticleContainer.cpp index 0d9d4fc1a..936a64c9c 100644 --- a/Source/Particles/PhysicalParticleContainer.cpp +++ b/Source/Particles/PhysicalParticleContainer.cpp @@ -40,6 +40,7 @@ PhysicalParticleContainer::PhysicalParticleContainer (AmrCore* amr_core, int isp pp.query("do_splitting", do_splitting); pp.query("split_type", split_type); pp.query("do_not_deposit", do_not_deposit); + pp.query("do_not_push", do_not_push); pp.query("do_continuous_injection", do_continuous_injection); pp.query("initialize_self_fields", initialize_self_fields); diff --git a/Source/Particles/WarpXParticleContainer.cpp b/Source/Particles/WarpXParticleContainer.cpp index 15a6cff9b..6abc02139 100644 --- a/Source/Particles/WarpXParticleContainer.cpp +++ b/Source/Particles/WarpXParticleContainer.cpp @@ -129,7 +129,6 @@ WarpXParticleContainer::ReadParameters () do_tiling = true; #endif pp.query("do_tiling", do_tiling); - pp.query("do_not_push", do_not_push); initialized = true; } -- cgit v1.2.3