-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAlgorithms.cpp
More file actions
103 lines (91 loc) · 3.29 KB
/
Algorithms.cpp
File metadata and controls
103 lines (91 loc) · 3.29 KB
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
/* Copyright 2022-2025 The Regents of the University of California, through Lawrence
* Berkeley National Laboratory (subject to receipt of any required
* approvals from the U.S. Dept. of Energy). All rights reserved.
*
* This file is part of ImpactX.
*
* Authors: Axel Huebl, Chad Mitchell
* License: BSD-3-Clause-LBNL
*/
#include "initialization/Algorithms.H"
#include <ablastr/warn_manager/WarnManager.H>
#include <AMReX_ParmParse.H>
#include <algorithm> // for std::transform
#include <stdexcept>
#include <string>
namespace impactx
{
SpaceChargeAlgo
get_space_charge_algo ()
{
amrex::ParmParse const pp_algo("algo");
std::string space_charge;
bool has_space_charge = pp_algo.query("space_charge", space_charge);
if (!has_space_charge) { return SpaceChargeAlgo::False; }
// TODO: at some point, remove backwards compatibility to pre 25.03
std::string space_charge_lower = space_charge;
std::transform(space_charge.begin(), space_charge.end(), space_charge_lower.begin(),
[](unsigned char c){ return std::tolower(c); });
if (space_charge == "1" || space_charge_lower == "true" || space_charge_lower == "on")
{
ablastr::warn_manager::WMRecordWarning(
"algo.space_charge",
"The option algo.space_charge = true is deprecated and will be removed in a future version of ImpactX. "
"Please use algo.space_charge = 3D instead.",
ablastr::warn_manager::WarnPriority::high
);
return SpaceChargeAlgo::True_3D;
}
if (space_charge == "0")
{
ablastr::warn_manager::WMRecordWarning(
"algo.space_charge",
"The option algo.space_charge = 0 is deprecated and will be removed in a future version of ImpactX. "
"Please use algo.space_charge = false instead.",
ablastr::warn_manager::WarnPriority::high
);
return SpaceChargeAlgo::False;
}
if (space_charge_lower == "false" || space_charge_lower == "off")
{
return SpaceChargeAlgo::False;
}
else if (space_charge == "3D")
{
return SpaceChargeAlgo::True_3D;
}
else if (space_charge == "Gauss3D")
{
return SpaceChargeAlgo::Gauss3D;
}
else if (space_charge == "Gauss2p5D")
{
return SpaceChargeAlgo::Gauss2p5D;
}
else if (space_charge == "2D")
{
return SpaceChargeAlgo::True_2D;
}
else if (space_charge == "2p5D")
{
return SpaceChargeAlgo::True_2p5D;
}
else
{
throw std::runtime_error("algo.space_charge = " + space_charge + " is not a valid option");
}
}
std::string
to_string (SpaceChargeAlgo sca)
{
std::string const str = amrex::getEnumNameString(sca);
// strip True_ prefix, which we only added because var names / enum member names
// cannot start with a number
std::string const true_prefix = "True_";
if (str.find(true_prefix) == 0)
{
return str.substr(true_prefix.length());
}
return str;
}
} // namespace impactx