From 616080ee5659803fedcce4e23a3caadaa1f69faf Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Mon, 27 May 2019 22:26:07 -0700 Subject: Start algorithm selection --- Source/Utils/WarpXAlgorithmSelection.cpp | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Source/Utils/WarpXAlgorithmSelection.cpp (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp new file mode 100644 index 000000000..7e868b745 --- /dev/null +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -0,0 +1,85 @@ +#include + +// Define dictionary with correspondance between user-input strings, +// and corresponding integer for use inside the code (e.g. in PICSAR). + +const std::map maxwell_solver_algo_to_int = { + {"yee", MaxwellSolverAlgo::Yee }, +#if (defined AMREX_USE_GPU) // Only available on CPU + {"ckc", MaxwellSolverAlgo::CKC }, +#endif + {"default", MaxwellSolverAlgo::Yee } +}; + +const std::map particle_pusher_algo_to_int = { + {"boris", ParticlePusherAlgo::Boris }, + {"vay", ParticlePusherAlgo::Vay }, + {"default", ParticlePusherAlgo::Boris } +}; + +const std::map current_deposition_algo_to_int = { + {"esirkepov", CurrentDepositionAlgo::Esirkepov }, + {"direct", CurrentDepositionAlgo::Direct }, +#if (defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D + {"direct-vectorized", CurrentDepositionAlgo::DirectVectorized }, +#endif + {"default", CurrentDepositionAlgo::Esirkepov } +}; + +const std::map charge_deposition_algo_to_int = { + {"standard", ChargeDepositionAlgo::Standard }, +#if (defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D + {"vectorized", ChargeDepositionAlgo::Vectorized }, + {"default", ChargeDepositionAlgo::Vectorized } +#else + {"default", ChargeDepositionAlgo::Standard } +#endif +}; + +const std::map gathering_algo_to_int = { + {"standard", GatheringAlgo::Standard }, +#ifndef AMREX_USE_GPU // Only available on CPU + {"vectorized", GatheringAlgo::Vectorized }, +#endif +}; + + +int +GetAlgorithmInteger( amrex::ParmParse& pp, const char* pp_search_key ){ + + // Read user input ; use "default" if it is not found + std::string algo = "default"; + pp.query( pp_search_key, algo ); + + // Pick the right dictionary + std::map algo_to_int; + if (pp_search_key == "maxwell_fdtd_solver") { + algo_to_int = maxwell_solver_algo_to_int; + } else if (pp_search_key == "particle_pusher") { + algo_to_int = particle_pusher_algo_to_int; + } else if (pp_search_key == "current_deposition") { + algo_to_int = current_deposition_algo_to_int; + } else if (pp_search_key == "charge_deposition") { + algo_to_int = charge_deposition_algo_to_int; + } else { + std::string pp_search_string = pp_search_key; + amrex::Abort("Unknown algorithm type: " + pp_search_string); + } + + // Check if the user-input is a valid key for the dictionary + if (algo_to_int.count(algo) == 0){ + // Not a valid key ; print error message + std::string pp_search_string = pp_search_key; + std::string error_message = "Invalid string for algo." + + pp_search_string + ": " + algo + ". The valid values are: "; + for ( const auto &valid_pair : algo_to_int ) { + if (valid_pair.first != "default"){ + error_message += valid_pair.first + " "; + } + } + amrex::Abort(error_message); + } + + // If the input is a valid key, return the value + return algo_to_int[algo]; +} -- cgit v1.2.3 From 31f0aadd209fe4bb227380b31eb264b5ab79cb5f Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Wed, 29 May 2019 08:13:21 -0700 Subject: Fix bugs --- Source/FortranInterface/WarpX_picsar.F90 | 4 +--- Source/Utils/WarpXAlgorithmSelection.H | 2 +- Source/Utils/WarpXAlgorithmSelection.cpp | 15 +++++++++------ Source/WarpX.cpp | 13 +++++++------ 4 files changed, 18 insertions(+), 16 deletions(-) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/FortranInterface/WarpX_picsar.F90 b/Source/FortranInterface/WarpX_picsar.F90 index ddffc61ea..12d541b08 100644 --- a/Source/FortranInterface/WarpX_picsar.F90 +++ b/Source/FortranInterface/WarpX_picsar.F90 @@ -218,12 +218,10 @@ subroutine warpx_charge_deposition(rho,np,xp,yp,zp,w,q,xmin,ymin,zmin,dx,dy,dz,n IF ((nox.eq.1).and.(noy.eq.1).and.(noz.eq.1)) THEN CALL depose_rho_vecHVv2_1_1_1(rho,np,xp,yp,zp,w,q,xmin,ymin,zmin,dx,dy,dz,nx,ny,nz,& nxguard,nyguard,nzguard,lvect) + ELSE IF ((nox.eq.2).and.(noy.eq.2).and.(noz.eq.2)) THEN CALL depose_rho_vecHVv2_2_2_2(rho,np,xp,yp,zp,w,q,xmin,ymin,zmin,dx,dy,dz,nx,ny,nz,& nxguard,nyguard,nzguard,lvect) - ELSE IF ((nox.eq.3).and.(noy.eq.3).and.(noz.eq.3)) THEN - CALL depose_rho_vecHVv2_3_3_3(rho,np,xp,yp,zp,w,q,xmin,ymin,zmin,dx,dy,dz,nx,ny,nz,& - nxguard,nyguard,nzguard,lvect) ELSE CALL pxr_depose_rho_n(rho,np,xp,yp,zp,w,q,xmin,ymin,zmin,dx,dy,dz,nx,ny,nz,& diff --git a/Source/Utils/WarpXAlgorithmSelection.H b/Source/Utils/WarpXAlgorithmSelection.H index 3a892b92c..3fb23698a 100644 --- a/Source/Utils/WarpXAlgorithmSelection.H +++ b/Source/Utils/WarpXAlgorithmSelection.H @@ -52,6 +52,6 @@ struct GatheringAlgo { }; int -GetAlgorithmInteger( amrex::ParmParse& pp, std::string pp_search_key ); +GetAlgorithmInteger( amrex::ParmParse& pp, const char* pp_search_key ); #endif // UTILS_WARPXALGORITHMSELECTION_H_ diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 7e868b745..a8081cdcb 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -5,7 +5,7 @@ const std::map maxwell_solver_algo_to_int = { {"yee", MaxwellSolverAlgo::Yee }, -#if (defined AMREX_USE_GPU) // Only available on CPU +#ifndef AMREX_USE_GPU // Only available on CPU {"ckc", MaxwellSolverAlgo::CKC }, #endif {"default", MaxwellSolverAlgo::Yee } @@ -20,7 +20,7 @@ const std::map particle_pusher_algo_to_int = { const std::map current_deposition_algo_to_int = { {"esirkepov", CurrentDepositionAlgo::Esirkepov }, {"direct", CurrentDepositionAlgo::Direct }, -#if (defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D +#if (!defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D {"direct-vectorized", CurrentDepositionAlgo::DirectVectorized }, #endif {"default", CurrentDepositionAlgo::Esirkepov } @@ -28,7 +28,7 @@ const std::map current_deposition_algo_to_int = { const std::map charge_deposition_algo_to_int = { {"standard", ChargeDepositionAlgo::Standard }, -#if (defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D +#if (!defined AMREX_USE_GPU)&&(AMREX_SPACEDIM == 3) // Only available on CPU and 3D {"vectorized", ChargeDepositionAlgo::Vectorized }, {"default", ChargeDepositionAlgo::Vectorized } #else @@ -40,6 +40,9 @@ const std::map gathering_algo_to_int = { {"standard", GatheringAlgo::Standard }, #ifndef AMREX_USE_GPU // Only available on CPU {"vectorized", GatheringAlgo::Vectorized }, + {"default", GatheringAlgo::Vectorized } +#else + {"default", GatheringAlgo::Standard } #endif }; @@ -70,11 +73,11 @@ GetAlgorithmInteger( amrex::ParmParse& pp, const char* pp_search_key ){ if (algo_to_int.count(algo) == 0){ // Not a valid key ; print error message std::string pp_search_string = pp_search_key; - std::string error_message = "Invalid string for algo." - + pp_search_string + ": " + algo + ". The valid values are: "; + std::string error_message = "Invalid string for algo." + pp_search_string + + ": " + algo + ".\nThe valid values are:\n"; for ( const auto &valid_pair : algo_to_int ) { if (valid_pair.first != "default"){ - error_message += valid_pair.first + " "; + error_message += " - " + valid_pair.first + "\n"; } } amrex::Abort(error_message); diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 3d7f7dcc5..c51df1d74 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #ifdef BL_USE_SENSEI_INSITU #include @@ -118,7 +119,7 @@ WarpX::ResetInstance () { delete m_instance; m_instance = nullptr; -} +} WarpX::WarpX () { @@ -276,10 +277,10 @@ WarpX::ReadParameters () ReadBoostedFrameParameters(gamma_boost, beta_boost, boost_direction); - // pp.query returns 1 if argument zmax_plasma_to_compute_max_step is + // pp.query returns 1 if argument zmax_plasma_to_compute_max_step is // specified by the user, 0 otherwise. - do_compute_max_step_from_zmax = - pp.query("zmax_plasma_to_compute_max_step", + do_compute_max_step_from_zmax = + pp.query("zmax_plasma_to_compute_max_step", zmax_plasma_to_compute_max_step); pp.queryarr("B_external", B_external); @@ -318,7 +319,7 @@ WarpX::ReadParameters () "gamma_boost must be > 1 to use the boosted frame diagnostic."); pp.query("lab_data_directory", lab_data_directory); - + std::string s; pp.get("boost_direction", s); AMREX_ALWAYS_ASSERT_WITH_MESSAGE( (s == "z" || s == "Z"), @@ -477,7 +478,7 @@ WarpX::ReadParameters () { ParmParse pp("algo"); - pp.query("current_deposition", current_deposition_algo); + current_deposition_algo = GetAlgorithmInteger(pp, "current_deposition"); pp.query("charge_deposition", charge_deposition_algo); pp.query("field_gathering", field_gathering_algo); pp.query("particle_pusher", particle_pusher_algo); -- cgit v1.2.3 From 8b27266c55e5d4560a410c772902284da6eac7de Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 31 May 2019 08:51:46 -0700 Subject: Address review comments --- Source/Utils/WarpXAlgorithmSelection.cpp | 4 ++++ Source/WarpX.cpp | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index a8081cdcb..21d3ef7f0 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -1,4 +1,6 @@ #include +#include +#include // Define dictionary with correspondance between user-input strings, // and corresponding integer for use inside the code (e.g. in PICSAR). @@ -53,6 +55,8 @@ GetAlgorithmInteger( amrex::ParmParse& pp, const char* pp_search_key ){ // Read user input ; use "default" if it is not found std::string algo = "default"; pp.query( pp_search_key, algo ); + // Convert to lower case + std::transform(algo.begin(), algo.end(), algo.begin(), ::tolower); // Pick the right dictionary std::map algo_to_int; diff --git a/Source/WarpX.cpp b/Source/WarpX.cpp index 66b553c20..c2cf97f30 100644 --- a/Source/WarpX.cpp +++ b/Source/WarpX.cpp @@ -485,7 +485,7 @@ WarpX::ReadParameters () ParmParse pp("algo"); current_deposition_algo = GetAlgorithmInteger(pp, "current_deposition"); charge_deposition_algo = GetAlgorithmInteger(pp, "charge_deposition"); - field_gathering_algo = GetAlgorithmInteger(pp, "charge_deposition"); + field_gathering_algo = GetAlgorithmInteger(pp, "field_gathering"); particle_pusher_algo = GetAlgorithmInteger(pp, "particle_pusher"); maxwell_fdtd_solver_id = GetAlgorithmInteger(pp, "maxwell_fdtd_solver"); } @@ -524,7 +524,7 @@ WarpX::ReadParameters () amrex::Vector slice_hi(AMREX_SPACEDIM); Vector slice_crse_ratio(AMREX_SPACEDIM); // set default slice_crse_ratio // - for (int idim=0; idim < AMREX_SPACEDIM; ++idim ) + for (int idim=0; idim < AMREX_SPACEDIM; ++idim ) { slice_crse_ratio[idim] = 1; } @@ -543,7 +543,7 @@ WarpX::ReadParameters () } } - + } // This is a virtual function. -- cgit v1.2.3 From 73ef945e0754789bde20b8add94bd2ec58e29f4a Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 31 May 2019 08:53:58 -0700 Subject: Allow the use of the CKC solver on GPU --- Docs/source/running_cpp/parameters.rst | 8 ++++---- Source/Utils/WarpXAlgorithmSelection.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Docs/source/running_cpp/parameters.rst b/Docs/source/running_cpp/parameters.rst index 350e730c7..ba64c1fcd 100644 --- a/Docs/source/running_cpp/parameters.rst +++ b/Docs/source/running_cpp/parameters.rst @@ -562,7 +562,7 @@ Numerics and algorithms The algorithm for the FDTD Maxwell field solver. Available options are: - ``yee``: Yee FDTD solver. - - ``ckc``: Cole-Karkkainen solver with Cowan + - ``ckc``: (not available in ``RZ`` geometry) Cole-Karkkainen solver with Cowan coefficients (see `Cowan, PRSTAB 16 (2013) `__) If ``algo.maxwell_fdtd_solver`` is not specified, ``yee`` is the default. @@ -722,13 +722,13 @@ Diagnostics and output The extent of the slice are defined by the co-ordinates of the lower corner (``slice.dom_lo``) and upper corner (``slice.dom_hi``). The slice could be 1D, 2D, or 3D, aligned with the co-ordinate axes and the first axis of the coordinates is x. For example: if for a 3D simulation, an x-z slice is to be extracted at y = 0.0, then the y-value of slice.dom_lo and slice.dom_hi must be equal to 0.0 * ``slice.coarsening_ratio`` (`2 integers in 2D`, `3 integers in 3D`; default `1`) - The coarsening ratio input must be greater than 0. Default is 1 in all directions. - In the directions that is reduced, i.e., for an x-z slice in 3D, the reduced y-dimension has a default coarsening ratio equal to 1. + The coarsening ratio input must be greater than 0. Default is 1 in all directions. + In the directions that is reduced, i.e., for an x-z slice in 3D, the reduced y-dimension has a default coarsening ratio equal to 1. * ``slice.plot_int`` (`integer`) The number of PIC cycles inbetween two consecutive data dumps for the slice. Use a negative number to disable slice generation and slice data dumping. - + Checkpoints and restart diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 21d3ef7f0..44e032a0b 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -7,7 +7,7 @@ const std::map maxwell_solver_algo_to_int = { {"yee", MaxwellSolverAlgo::Yee }, -#ifndef AMREX_USE_GPU // Only available on CPU +#ifndef WARPX_RZ // Not available in RZ {"ckc", MaxwellSolverAlgo::CKC }, #endif {"default", MaxwellSolverAlgo::Yee } -- cgit v1.2.3 From ca771c7fe1a614a5487f054d6612fa6642695081 Mon Sep 17 00:00:00 2001 From: Remi Lehe Date: Fri, 31 May 2019 20:07:55 -0700 Subject: Fix parsing of gathering string --- Source/Utils/WarpXAlgorithmSelection.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp') diff --git a/Source/Utils/WarpXAlgorithmSelection.cpp b/Source/Utils/WarpXAlgorithmSelection.cpp index 44e032a0b..89802e064 100644 --- a/Source/Utils/WarpXAlgorithmSelection.cpp +++ b/Source/Utils/WarpXAlgorithmSelection.cpp @@ -68,6 +68,8 @@ GetAlgorithmInteger( amrex::ParmParse& pp, const char* pp_search_key ){ algo_to_int = current_deposition_algo_to_int; } else if (pp_search_key == "charge_deposition") { algo_to_int = charge_deposition_algo_to_int; + } else if (pp_search_key == "field_gathering") { + algo_to_int = gathering_algo_to_int; } else { std::string pp_search_string = pp_search_key; amrex::Abort("Unknown algorithm type: " + pp_search_string); -- cgit v1.2.3