aboutsummaryrefslogtreecommitdiff
path: root/Source/Utils/WarpXAlgorithmSelection.cpp
diff options
context:
space:
mode:
authorGravatar Remi Lehe <remi.lehe@normalesup.org> 2019-05-27 22:26:07 -0700
committerGravatar Remi Lehe <remi.lehe@normalesup.org> 2019-05-28 21:16:36 -0700
commit616080ee5659803fedcce4e23a3caadaa1f69faf (patch)
treeaa90fc33d7f9a55876df74b80e36999ead52eba9 /Source/Utils/WarpXAlgorithmSelection.cpp
parent24147a2d9977426c8c3461b9f6459e0834d3ce7a (diff)
downloadWarpX-616080ee5659803fedcce4e23a3caadaa1f69faf.tar.gz
WarpX-616080ee5659803fedcce4e23a3caadaa1f69faf.tar.zst
WarpX-616080ee5659803fedcce4e23a3caadaa1f69faf.zip
Start algorithm selection
Diffstat (limited to 'Source/Utils/WarpXAlgorithmSelection.cpp')
-rw-r--r--Source/Utils/WarpXAlgorithmSelection.cpp85
1 files changed, 85 insertions, 0 deletions
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 <WarpXAlgorithmSelection.H>
+
+// Define dictionary with correspondance between user-input strings,
+// and corresponding integer for use inside the code (e.g. in PICSAR).
+
+const std::map<std::string, int> 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<std::string, int> particle_pusher_algo_to_int = {
+ {"boris", ParticlePusherAlgo::Boris },
+ {"vay", ParticlePusherAlgo::Vay },
+ {"default", ParticlePusherAlgo::Boris }
+};
+
+const std::map<std::string, int> 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<std::string, int> 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<std::string, int> 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<std::string, int> 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];
+}