-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathWarpXAlgorithmSelection.cpp
260 lines (229 loc) · 10.1 KB
/
WarpXAlgorithmSelection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* Copyright 2019-2020 Axel Huebl, David Grote, Luca Fedeli
* Remi Lehe, Weiqun Zhang, Yinjian Zhao
*
*
* This file is part of WarpX.
*
* License: BSD-3-Clause-LBNL
*/
#include "WarpX.H"
#include "WarpXAlgorithmSelection.H"
#include "Utils/TextMsg.H"
#include <AMReX.H>
#include <AMReX_ParmParse.H>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <map>
#include <utility>
// Define dictionary with correspondence between user-input strings,
// and corresponding integer for use inside the code
const std::map<std::string, int> evolve_scheme_to_int = {
{"explicit", EvolveScheme::Explicit },
{"implicit_picard", EvolveScheme::ImplicitPicard },
{"semi_implicit_picard", EvolveScheme::SemiImplicitPicard },
{"default", EvolveScheme::Explicit }
};
const std::map<std::string, int> grid_to_int = {
{"collocated", GridType::Collocated},
{"staggered", GridType::Staggered},
{"hybrid", GridType::Hybrid},
{"default", GridType::Staggered}
};
const std::map<std::string, int> electromagnetic_solver_algo_to_int = {
{"none", ElectromagneticSolverAlgo::None },
{"yee", ElectromagneticSolverAlgo::Yee },
{"ckc", ElectromagneticSolverAlgo::CKC },
{"psatd", ElectromagneticSolverAlgo::PSATD },
{"ect", ElectromagneticSolverAlgo::ECT },
{"hybrid", ElectromagneticSolverAlgo::HybridPIC },
{"default", ElectromagneticSolverAlgo::Yee }
};
const std::map<std::string, int> electrostatic_solver_algo_to_int = {
{"none", ElectrostaticSolverAlgo::None },
{"relativistic", ElectrostaticSolverAlgo::Relativistic},
{"labframe-electromagnetostatic", ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic},
{"labframe", ElectrostaticSolverAlgo::LabFrame},
{"default", ElectrostaticSolverAlgo::None }
};
const std::map<std::string, int> particle_pusher_algo_to_int = {
{"boris", ParticlePusherAlgo::Boris },
{"vay", ParticlePusherAlgo::Vay },
{"higuera", ParticlePusherAlgo::HigueraCary },
{"default", ParticlePusherAlgo::Boris }
};
const std::map<std::string, int> current_deposition_algo_to_int = {
{"esirkepov", CurrentDepositionAlgo::Esirkepov },
{"direct", CurrentDepositionAlgo::Direct },
{"vay", CurrentDepositionAlgo::Vay },
{"villasenor", CurrentDepositionAlgo::Villasenor },
{"default", CurrentDepositionAlgo::Esirkepov } // NOTE: overwritten for PSATD and Hybrid-PIC below
};
const std::map<std::string, int> charge_deposition_algo_to_int = {
{"standard", ChargeDepositionAlgo::Standard },
{"default", ChargeDepositionAlgo::Standard }
};
const std::map<std::string, int> gathering_algo_to_int = {
{"energy-conserving", GatheringAlgo::EnergyConserving },
{"momentum-conserving", GatheringAlgo::MomentumConserving },
{"default", GatheringAlgo::EnergyConserving }
};
const std::map<std::string, int> psatd_solution_type_to_int = {
{"first-order", PSATDSolutionType::FirstOrder},
{"second-order", PSATDSolutionType::SecondOrder},
{"default", PSATDSolutionType::SecondOrder}
};
const std::map<std::string, int> J_in_time_to_int = {
{"constant", JInTime::Constant},
{"linear", JInTime::Linear},
{"default", JInTime::Constant}
};
const std::map<std::string, int> rho_in_time_to_int = {
{"constant", RhoInTime::Constant},
{"linear", RhoInTime::Linear},
{"default", RhoInTime::Linear}
};
const std::map<std::string, int> load_balance_costs_update_algo_to_int = {
{"timers", LoadBalanceCostsUpdateAlgo::Timers },
{"gpuclock", LoadBalanceCostsUpdateAlgo::GpuClock },
{"heuristic", LoadBalanceCostsUpdateAlgo::Heuristic },
{"default", LoadBalanceCostsUpdateAlgo::Timers }
};
const std::map<std::string, int> MaxwellSolver_medium_algo_to_int = {
{"vacuum", MediumForEM::Vacuum},
{"macroscopic", MediumForEM::Macroscopic},
{"default", MediumForEM::Vacuum}
};
const std::map<std::string, int> MacroscopicSolver_algo_to_int = {
{"backwardeuler", MacroscopicSolverAlgo::BackwardEuler},
{"laxwendroff", MacroscopicSolverAlgo::LaxWendroff},
{"default", MacroscopicSolverAlgo::BackwardEuler}
};
const std::map<std::string, int> FieldBCType_algo_to_int = {
{"pml", FieldBoundaryType::PML},
{"periodic", FieldBoundaryType::Periodic},
{"pec", FieldBoundaryType::PEC},
{"pmc", FieldBoundaryType::PMC},
{"damped", FieldBoundaryType::Damped},
{"absorbing_silver_mueller", FieldBoundaryType::Absorbing_SilverMueller},
{"neumann", FieldBoundaryType::Neumann},
{"none", FieldBoundaryType::None},
{"default", FieldBoundaryType::PML}
};
const std::map<std::string, ParticleBoundaryType> ParticleBCType_algo_to_enum = {
{"absorbing", ParticleBoundaryType::Absorbing},
{"open", ParticleBoundaryType::Open},
{"reflecting", ParticleBoundaryType::Reflecting},
{"periodic", ParticleBoundaryType::Periodic},
{"default", ParticleBoundaryType::Absorbing}
};
const std::map<std::string, int> ReductionType_algo_to_int = {
{"maximum", ReductionType::Maximum},
{"minimum", ReductionType::Minimum},
{"integral", ReductionType::Sum}
};
int
GetAlgorithmInteger(const 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<std::string, int> algo_to_int;
if (0 == std::strcmp(pp_search_key, "evolve_scheme")) {
algo_to_int = evolve_scheme_to_int;
} else if (0 == std::strcmp(pp_search_key, "maxwell_solver")) {
algo_to_int = electromagnetic_solver_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "grid_type")) {
algo_to_int = grid_to_int;
} else if (0 == std::strcmp(pp_search_key, "do_electrostatic")) {
algo_to_int = electrostatic_solver_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "particle_pusher")) {
algo_to_int = particle_pusher_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "current_deposition")) {
algo_to_int = current_deposition_algo_to_int;
if (WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::PSATD ||
WarpX::electromagnetic_solver_id == ElectromagneticSolverAlgo::HybridPIC ||
WarpX::electrostatic_solver_id != ElectrostaticSolverAlgo::None) {
algo_to_int["default"] = CurrentDepositionAlgo::Direct;
}
} else if (0 == std::strcmp(pp_search_key, "charge_deposition")) {
algo_to_int = charge_deposition_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "field_gathering")) {
algo_to_int = gathering_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "solution_type")) {
algo_to_int = psatd_solution_type_to_int;
} else if (0 == std::strcmp(pp_search_key, "J_in_time")) {
algo_to_int = J_in_time_to_int;
} else if (0 == std::strcmp(pp_search_key, "rho_in_time")) {
algo_to_int = rho_in_time_to_int;
} else if (0 == std::strcmp(pp_search_key, "load_balance_costs_update")) {
algo_to_int = load_balance_costs_update_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "em_solver_medium")) {
algo_to_int = MaxwellSolver_medium_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "macroscopic_sigma_method")) {
algo_to_int = MacroscopicSolver_algo_to_int;
} else if (0 == std::strcmp(pp_search_key, "reduction_type")) {
algo_to_int = ReductionType_algo_to_int;
} else {
std::string const pp_search_string = pp_search_key;
WARPX_ABORT_WITH_MESSAGE("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
const std::string pp_search_string = pp_search_key;
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 + "\n";
}
}
WARPX_ABORT_WITH_MESSAGE(error_message);
}
// If the input is a valid key, return the value
return algo_to_int[algo];
}
int
GetFieldBCTypeInteger( std::string BCType ){
std::transform(BCType.begin(), BCType.end(), BCType.begin(), ::tolower);
if (FieldBCType_algo_to_int.count(BCType) == 0) {
std::string error_message = "Invalid string for field/particle BC. : " + BCType + "\nThe valid values are : \n";
for (const auto &valid_pair : FieldBCType_algo_to_int) {
if (valid_pair.first != "default"){
error_message += " - " + valid_pair.first + "\n";
}
}
WARPX_ABORT_WITH_MESSAGE(error_message);
}
// return FieldBCType_algo_to_int[BCType]; // This operator cannot be used for a const map
return FieldBCType_algo_to_int.at(BCType);
}
ParticleBoundaryType
GetParticleBCTypeInteger( std::string BCType ){
std::transform(BCType.begin(), BCType.end(), BCType.begin(), ::tolower);
if (ParticleBCType_algo_to_enum.count(BCType) == 0) {
std::string error_message = "Invalid string for particle BC. : " + BCType + "\nThe valid values are : \n";
for (const auto &valid_pair : ParticleBCType_algo_to_enum) {
if (valid_pair.first != "default"){
error_message += " - " + valid_pair.first + "\n";
}
}
WARPX_ABORT_WITH_MESSAGE(error_message);
}
// return ParticleBCType_algo_to_enum[BCType]; // This operator cannot be used for a const map
return ParticleBCType_algo_to_enum.at(BCType);
}
std::string
GetFieldBCTypeString( int fb_type ) {
std::string boundary_name;
for (const auto &valid_pair : FieldBCType_algo_to_int) {
if ((valid_pair.second == fb_type)&&(valid_pair.first != "default")){
boundary_name = valid_pair.first;
break;
}
}
return boundary_name;
}