Skip to content

Commit 93153d4

Browse files
committed
Modify flag -> location and add model string.
1 parent a5aed30 commit 93153d4

File tree

4 files changed

+46
-33
lines changed

4 files changed

+46
-33
lines changed

examples/edge_effects/run_dipedge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@
8585
ns = 1 # number of slices per ds in the element
8686
edge_angle = math.pi / 8.0
8787
dipedge0 = elements.DipEdge(
88-
name="dipedge0", psi=edge_angle, rc=10.0, g=1.0e-3, model=0, flag="entry"
88+
name="dipedge0", psi=edge_angle, rc=10.0, g=1.0e-3, model="linear", location="entry"
8989
)
9090
dipedge1 = elements.DipEdge(
91-
name="dipedge1", psi=edge_angle, rc=10.0, g=1.0e-3, model=1, flag="entry"
91+
name="dipedge1", psi=edge_angle, rc=10.0, g=1.0e-3, model="nonlinear", location="entry"
9292
)
9393

9494
line = [

src/elements/DipEdge.H

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace impactx::elements
5050
exit = -1 //! for trailing (exit) fringe field
5151
};
5252

53+
enum Model
54+
{
55+
linear = 0, //! to use a linearized fringe field map
56+
nonlinear = 1 //! to use a nonlinear fringe field map
57+
};
58+
5359
/** Edge focusing associated with bend entry or exit
5460
*
5561
* This model assumes a first-order effect of nonzero gap.
@@ -70,8 +76,8 @@ namespace impactx::elements
7076
* @param K4 Fringe field integral (unitless).
7177
* @param K5 Fringe field integral (unitless).
7278
* @param K6 Fringe field integral (unitless).
73-
* @param model Model (0 linear, 1 nonlinear).
74-
* @param flag Flag specifying entry or exit location
79+
* @param model Fringe field model (linear or nonlinear).
80+
* @param location Fringe field location (entry or exit)
7581
* @param dx horizontal translation error in m
7682
* @param dy vertical translation error in m
7783
* @param rotation_degree rotation error in the transverse plane [degrees]
@@ -89,16 +95,16 @@ namespace impactx::elements
8995
amrex::ParticleReal K4,
9096
amrex::ParticleReal K5,
9197
amrex::ParticleReal K6,
92-
int model,
93-
Location flag,
98+
Model model,
99+
Location location,
94100
amrex::ParticleReal dx = 0,
95101
amrex::ParticleReal dy = 0,
96102
amrex::ParticleReal rotation_degree = 0,
97103
std::optional<std::string> name = std::nullopt
98104
)
99105
: Named(std::move(name)),
100106
Alignment(dx, dy, rotation_degree),
101-
m_psi(psi), m_rc(rc), m_g(g), m_R(R), m_K0(K0), m_K1(K1), m_K2(K2), m_K3(K3), m_K4(K4), m_K5(K5), m_K6(K6), m_model(model), m_flag(flag)
107+
m_psi(psi), m_rc(rc), m_g(g), m_R(R), m_K0(K0), m_K1(K1), m_K2(K2), m_K3(K3), m_K4(K4), m_K5(K5), m_K6(K6), m_model(model), m_location(location)
102108
{
103109
}
104110

@@ -142,7 +148,7 @@ namespace impactx::elements
142148
amrex::ParticleReal const sec_psi = 1_prt/cos_psi;
143149

144150
// the scale constant specifying entry or exit
145-
amrex::ParticleReal const flg = static_cast<amrex::ParticleReal>(m_flag);
151+
amrex::ParticleReal const flg = static_cast<amrex::ParticleReal>(m_location);
146152

147153
m_c1 = (m_g / m_rc) * m_K1 / cos_psi;
148154
m_c2_times_1plusdelta = powi<2>(m_g/m_rc) * m_K0 * sin_psi * powi<3>(sec_psi)/2_prt;
@@ -308,7 +314,7 @@ namespace impactx::elements
308314
amrex::ParticleReal m_K5; //! fringe field integral
309315
amrex::ParticleReal m_K6; //! fringe field integral
310316
int m_model; //! model specification
311-
Location m_flag; //! +1 for entry, or -1 for exit
317+
Location m_location; //! +1 for entry, or -1 for exit
312318

313319
private:
314320
// constants that are independent of the individually tracked particle,

src/initialization/InitElement.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ namespace detail
186186

187187
amrex::ParticleReal psi, rc, g;
188188
amrex::ParticleReal R = 1;
189-
std::string flag_str = "entry";
189+
std::string location_str = "entry";
190+
std::string model_str = "linear";
190191

191192
// The default values below are from eq (52) of K. Hwang and S. Y. Lee (2015)
192193
amrex::ParticleReal pi = ablastr::constant::math::pi;
@@ -197,7 +198,6 @@ namespace detail
197198
amrex::ParticleReal K4 = 0;
198199
amrex::ParticleReal K5 = 0;
199200
amrex::ParticleReal K6 = 0;
200-
int model = 0; //default to linear model
201201
pp_element.getWithParser("psi", psi);
202202
pp_element.getWithParser("rc", rc);
203203
pp_element.getWithParser("g", g);
@@ -209,15 +209,20 @@ namespace detail
209209
pp_element.queryAddWithParser("K4", K4);
210210
pp_element.queryAddWithParser("K5", K5);
211211
pp_element.queryAddWithParser("K6", K6);
212-
pp_element.queryAddWithParser("model", model);
213-
pp_element.queryAdd("flag", flag_str);
214-
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(flag_str == "entry" || flag_str == "exit",
215-
element_name + ".flag must be \"entry\" or \"exit\"");
216-
DipEdge::Location const flag = flag_str == "entry" ?
212+
pp_element.queryAdd("model", model_str);
213+
pp_element.queryAdd("location", location_str);
214+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(location_str == "entry" || location_str == "exit",
215+
element_name + ".location must be \"entry\" or \"exit\"");
216+
DipEdge::Location const location = location_str == "entry" ?
217217
DipEdge::Location::entry :
218218
DipEdge::Location::exit;
219+
AMREX_ALWAYS_ASSERT_WITH_MESSAGE(model_str == "linear" || model_str == "nonlinear",
220+
element_name + ".model must be \"linear\" or \"nonlinear\"");
221+
DipEdge::Model const model = model_str == "linear" ?
222+
DipEdge::Model::linear :
223+
DipEdge::Model::nonlinear;
219224

220-
m_lattice.emplace_back( DipEdge(psi, rc, g, R, K0, K1, K2, K3, K4, K5, K6, model, flag, a["dx"], a["dy"], a["rotation_degree"], element_name) );
225+
m_lattice.emplace_back( DipEdge(psi, rc, g, R, K0, K1, K2, K3, K4, K5, K6, model, location, a["dx"], a["dy"], a["rotation_degree"], element_name) );
221226
} else if (element_type == "quadedge")
222227
{
223228
auto a = detail::query_alignment(pp_element);

src/python/elements.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,7 @@ void init_elements(py::module& m)
817817
std::make_pair("K3", dip_edge.m_K3),
818818
std::make_pair("K4", dip_edge.m_K4),
819819
std::make_pair("K5", dip_edge.m_K5),
820-
std::make_pair("K6", dip_edge.m_K6),
821-
std::make_pair("model", dip_edge.m_model)
820+
std::make_pair("K6", dip_edge.m_K6)
822821
);
823822
}
824823
)
@@ -838,7 +837,7 @@ void init_elements(py::module& m)
838837
std::make_pair("K5", dip_edge.m_K5),
839838
std::make_pair("K6", dip_edge.m_K6),
840839
std::make_pair("model", dip_edge.m_model),
841-
std::make_pair("flag", dip_edge.m_flag)
840+
std::make_pair("location", dip_edge.m_location)
842841
);
843842
}
844843
)
@@ -854,21 +853,29 @@ void init_elements(py::module& m)
854853
amrex::ParticleReal K4,
855854
amrex::ParticleReal K5,
856855
amrex::ParticleReal K6,
857-
int model,
858-
std::string const & flag,
856+
std::string const & model,
857+
std::string const & location,
859858
amrex::ParticleReal dx,
860859
amrex::ParticleReal dy,
861860
amrex::ParticleReal rotation_degree,
862861
std::optional<std::string> name
863862
)
864863
{
865-
if (flag != "entry" && flag != "exit")
866-
throw std::runtime_error(R"(flag must be "entry" or "exit")");
864+
if (location != "entry" && location != "exit")
865+
throw std::runtime_error(R"(location must be "entry" or "exit")");
867866

868-
DipEdge::Location const fl = flag == "entry" ?
867+
DipEdge::Location const loc_fl = location == "entry" ?
869868
DipEdge::Location::entry :
870869
DipEdge::Location::exit;
871-
return new DipEdge(psi, rc, g, R, K0, K1, K2, K3, K4, K5, K6, model, fl, dx, dy, rotation_degree, name);
870+
871+
if (model != "linear" && model != "nonlinear")
872+
throw std::runtime_error(R"(model must be "linear" or "nonlinear")");
873+
874+
DipEdge::Model const model_fl = model == "linear" ?
875+
DipEdge::Model::linear :
876+
DipEdge::Model::nonlinear;
877+
878+
return new DipEdge(psi, rc, g, R, K0, K1, K2, K3, K4, K5, K6, model_fl, loc_fl, dx, dy, rotation_degree, name);
872879
}),
873880
py::arg("psi"),
874881
py::arg("rc"),
@@ -881,8 +888,8 @@ void init_elements(py::module& m)
881888
py::arg("K4") = 0,
882889
py::arg("K5") = 0,
883890
py::arg("K6") = 0,
884-
py::arg("model") = 0,
885-
py::arg("flag") = "entry",
891+
py::arg("model") = "linear",
892+
py::arg("location") = "entry",
886893
py::arg("dx") = 0,
887894
py::arg("dy") = 0,
888895
py::arg("rotation") = 0,
@@ -944,11 +951,6 @@ void init_elements(py::module& m)
944951
[](DipEdge & dip_edge, amrex::ParticleReal K6) { dip_edge.m_K6 = K6; },
945952
"Fringe field integral (unitless)"
946953
)
947-
.def_property("model",
948-
[](DipEdge & dip_edge) { return dip_edge.m_model; },
949-
[](DipEdge & dip_edge, int model) { dip_edge.m_model = model; },
950-
"Specification of model (0 - linear, 1 - nonlinear)"
951-
)
952954

953955
;
954956
register_push(py_DipEdge);

0 commit comments

Comments
 (0)