Skip to content

Commit 560de9c

Browse files
authored
Make powi<N>(...) Readable (#1034)
Make pow readable again.
1 parent f0d9c6c commit 560de9c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+285
-195
lines changed

src/diagnostics/CovarianceMatrixMath.H

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,17 @@ namespace impactx::diagnostics
4848
)
4949
{
5050
using namespace amrex::literals;
51+
using amrex::Math::powi;
5152
using ablastr::constant::math::pi;
5253

5354
std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> roots;
5455
amrex::ParticleReal x1 = 0.0_prt;
5556
amrex::ParticleReal x2 = 0.0_prt;
5657
amrex::ParticleReal x3 = 0.0_prt;
5758

58-
amrex::ParticleReal Q = (3.0_prt*a*c - amrex::Math::powi<2>(b))/(9.0_prt * amrex::Math::powi<2>(a));
59-
amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*amrex::Math::powi<2>(a)*d - 2.0_prt*amrex::Math::powi<3>(b))/(54.0_prt*amrex::Math::powi<3>(a));
60-
amrex::ParticleReal discriminant = amrex::Math::powi<3>(Q) + amrex::Math::powi<2>(R);
59+
amrex::ParticleReal Q = (3.0_prt*a*c - powi<2>(b))/(9.0_prt * powi<2>(a));
60+
amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*powi<2>(a)*d - 2.0_prt*powi<3>(b))/(54.0_prt*powi<3>(a));
61+
amrex::ParticleReal discriminant = powi<3>(Q) + powi<2>(R);
6162

6263
// Discriminant should be < 0. Otherwise, keep theta at default and throw an error.
6364
amrex::ParticleReal tol = 1.0e-12; //allow for roundoff error
@@ -83,7 +84,7 @@ namespace impactx::diagnostics
8384
} else {
8485

8586
//Three real roots in trigonometric form.
86-
amrex::ParticleReal theta = std::acos(R/std::sqrt(-amrex::Math::powi<3>(Q)));
87+
amrex::ParticleReal theta = std::acos(R/std::sqrt(-powi<3>(Q)));
8788
x1 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt) - b/(3.0_prt*a);
8889
x2 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt + 2.0_prt*pi/3.0_prt) - b/(3.0_prt*a);
8990
x3 = 2.0_prt*std::sqrt(-Q)*std::cos(theta/3.0_prt + 4.0_prt*pi/3.0_prt) - b/(3.0_prt*a);
@@ -119,16 +120,17 @@ namespace impactx::diagnostics
119120
)
120121
{
121122
using namespace amrex::literals;
123+
using amrex::Math::powi;
122124
using Complex = amrex::GpuComplex<amrex::ParticleReal>;
123125

124126
std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> roots;
125127
amrex::ParticleReal x1 = 0.0_prt;
126128
amrex::ParticleReal x2 = 0.0_prt;
127129
amrex::ParticleReal x3 = 0.0_prt;
128130

129-
amrex::ParticleReal Q = (3.0_prt*a*c - amrex::Math::powi<2>(b))/(9.0_prt * amrex::Math::powi<2>(a));
130-
amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*amrex::Math::powi<2>(a)*d - 2.0_prt*amrex::Math::powi<3>(b))/(54.0_prt*amrex::Math::powi<3>(a));
131-
amrex::ParticleReal discriminant = amrex::Math::powi<3>(Q) + amrex::Math::powi<2>(R);
131+
amrex::ParticleReal Q = (3.0_prt*a*c - powi<2>(b))/(9.0_prt * powi<2>(a));
132+
amrex::ParticleReal R = (9.0_prt*a*b*c - 27_prt*powi<2>(a)*d - 2.0_prt*powi<3>(b))/(54.0_prt*powi<3>(a));
133+
amrex::ParticleReal discriminant = powi<3>(Q) + powi<2>(R);
132134

133135
// Define complex variable C
134136
Complex Qc(Q,0.0_prt);
@@ -153,7 +155,7 @@ namespace impactx::diagnostics
153155

154156
Complex z1 = Qc/C - C;
155157
Complex z2 = Qc/(xi*C) - xi*C;
156-
Complex z3 = Qc/(amrex::Math::powi<2>(xi)*C) - amrex::Math::powi<2>(xi)*C;
158+
Complex z3 = Qc/(powi<2>(xi)*C) - powi<2>(xi)*C;
157159
x1 = z2.m_real - b/(3.0*a);
158160
x2 = z1.m_real - b/(3.0*a);
159161
x3 = z3.m_real - b/(3.0*a);

src/diagnostics/EmittanceInvariants.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ namespace impactx::diagnostics
9999
BL_PROFILE("impactx::diagnostics::Eigenemittances");
100100

101101
using namespace amrex::literals;
102+
using amrex::Math::powi;
102103

103104
std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> invariants;
104105
std::tuple<amrex::ParticleReal, amrex::ParticleReal, amrex::ParticleReal> roots;
@@ -117,8 +118,8 @@ namespace impactx::diagnostics
117118
// doi:10.48550/arXiv.1305.1532.
118119
amrex::ParticleReal a = 1.0_prt;
119120
amrex::ParticleReal b = -I2;
120-
amrex::ParticleReal c = (amrex::Math::powi<2>(I2) - I4) / 2.0_prt;
121-
amrex::ParticleReal d = -amrex::Math::powi<3>(I2) / 6.0_prt + I2 * I4 / 2.0_prt - I6 / 3.0_prt;
121+
amrex::ParticleReal c = (powi<2>(I2) - I4) / 2.0_prt;
122+
amrex::ParticleReal d = -powi<3>(I2) / 6.0_prt + I2 * I4 / 2.0_prt - I6 / 3.0_prt;
122123

123124
// Return the cubic coefficients
124125
//std::cout << "Return a,b,c,d " << a << " " << b << " " << c << " " << d << "\n";

src/diagnostics/NonlinearLensInvariants.H

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace impactx::diagnostics
7777
) const
7878
{
7979
using namespace amrex::literals; // for _rt and _prt
80+
using amrex::Math::powi;
8081

8182
// a complex type with two amrex::ParticleReal
8283
using Complex = amrex::GpuComplex<amrex::ParticleReal>;
@@ -94,7 +95,7 @@ namespace impactx::diagnostics
9495
Complex const im1(0.0_prt, 1.0_prt);
9596

9697
// compute croot = sqrt(1-zeta**2)
97-
Complex croot = amrex::Math::powi<2>(zeta);
98+
Complex croot = powi<2>(zeta);
9899
croot = re1 - croot;
99100
croot = amrex::sqrt(croot);
100101

@@ -116,9 +117,9 @@ namespace impactx::diagnostics
116117

117118
// compute invariants H and I
118119
amrex::ParticleReal const Jz = xn*pyn - yn*pxn;
119-
Hinv = (amrex::Math::powi<2>(xn) + amrex::Math::powi<2>(yn) + amrex::Math::powi<2>(pxn) + amrex::Math::powi<2>(pyn))/2
120+
Hinv = (powi<2>(xn) + powi<2>(yn) + powi<2>(pxn) + powi<2>(pyn))/2
120121
+ m_tn*Hinv;
121-
Iinv = amrex::Math::powi<2>(Jz) + amrex::Math::powi<2>(pxn) + amrex::Math::powi<2>(xn) + m_tn*Iinv;
122+
Iinv = powi<2>(Jz) + powi<2>(pxn) + powi<2>(xn) + m_tn*Iinv;
122123

123124
return {Hinv, Iinv};
124125

src/elements/Aperture.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ namespace impactx::elements
143143
) const
144144
{
145145
using namespace amrex::literals; // for _rt and _prt
146+
using amrex::Math::powi;
146147

147148
// shift due to alignment errors of the element
148149
shift_in(x, y, px, py);
@@ -170,11 +171,11 @@ namespace impactx::elements
170171
switch (m_shape)
171172
{
172173
case Shape::rectangular: // default
173-
inside_aperture = (amrex::Math::powi<2>(u) <= 1_prt && amrex::Math::powi<2>(v) <= 1_prt);
174+
inside_aperture = (powi<2>(u) <= 1_prt && powi<2>(v) <= 1_prt);
174175
break;
175176

176177
case Shape::elliptical:
177-
inside_aperture = (amrex::Math::powi<2>(u) + amrex::Math::powi<2>(v) <= 1_prt);
178+
inside_aperture = (powi<2>(u) + powi<2>(v) <= 1_prt);
178179
break;
179180
}
180181

src/elements/Buncher.H

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ namespace impactx::elements
7575
void compute_constants (RefPart const & refpart)
7676
{
7777
using namespace amrex::literals; // for _rt and _prt
78+
using amrex::Math::powi;
7879

7980
Alignment::compute_constants(refpart);
8081

8182
// find beta*gamma^2
82-
amrex::ParticleReal const betgam2 = amrex::Math::powi<2>(refpart.pt) - 1.0_prt;
83+
amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1.0_prt;
8384

8485
m_neg_kV = -m_k * m_V;
8586
m_kV_r2bg2 = -m_neg_kV / (2.0_prt * betgam2);
@@ -151,9 +152,10 @@ namespace impactx::elements
151152
transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
152153
{
153154
using namespace amrex::literals; // for _rt and _prt
155+
using amrex::Math::powi;
154156

155157
// find beta*gamma^2
156-
amrex::ParticleReal const betgam2 = amrex::Math::powi<2>(refpart.pt) - 1.0_prt;
158+
amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1.0_prt;
157159

158160
amrex::ParticleReal const neg_kV = -m_k * m_V;
159161
amrex::ParticleReal const kV_r2bg2 = -neg_kV / (2.0_prt * betgam2);

src/elements/CFbend.H

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,21 @@ namespace impactx::elements
9191
void compute_constants (RefPart const & refpart)
9292
{
9393
using namespace amrex::literals; // for _rt and _prt
94+
using amrex::Math::powi;
9495

9596
Alignment::compute_constants(refpart);
9697

9798
// length of the current slice
9899
amrex::ParticleReal const slice_ds = m_ds / nslice();
99100

100101
// find beta*gamma^2, beta
101-
amrex::ParticleReal const betgam2 = amrex::Math::powi<2>(refpart.pt) - 1_prt;
102+
amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1_prt;
102103
amrex::ParticleReal const bet = refpart.beta();
103104
amrex::ParticleReal const ibetgam2 = 1_prt / betgam2;
104-
amrex::ParticleReal const b2rc2 = amrex::Math::powi<2>(bet) * amrex::Math::powi<2>(m_rc);
105+
amrex::ParticleReal const b2rc2 = powi<2>(bet) * powi<2>(m_rc);
105106

106107
// update horizontal and longitudinal phase space variables
107-
amrex::ParticleReal const gx = m_k + amrex::Math::powi<-2>(m_rc);
108+
amrex::ParticleReal const gx = m_k + powi<-2>(m_rc);
108109
amrex::ParticleReal const omega_x = std::sqrt(std::abs(gx));
109110

110111
// update vertical phase space variables
@@ -212,6 +213,7 @@ namespace impactx::elements
212213
void operator() (RefPart & AMREX_RESTRICT refpart) const
213214
{
214215
using namespace amrex::literals; // for _rt and _prt
216+
using amrex::Math::powi;
215217

216218
// assign input reference particle values
217219
amrex::ParticleReal const x = refpart.x;
@@ -229,7 +231,7 @@ namespace impactx::elements
229231

230232
// assign intermediate parameter
231233
amrex::ParticleReal const theta = slice_ds/m_rc;
232-
amrex::ParticleReal const B = std::sqrt(amrex::Math::powi<2>(pt)-1.0_prt)/m_rc;
234+
amrex::ParticleReal const B = std::sqrt(powi<2>(pt)-1.0_prt)/m_rc;
233235

234236
// calculate expensive terms once
235237
auto const [sin_theta, cos_theta] = amrex::Math::sincos(theta);
@@ -262,18 +264,19 @@ namespace impactx::elements
262264
transport_map ([[maybe_unused]] RefPart const & AMREX_RESTRICT refpart) const
263265
{
264266
using namespace amrex::literals; // for _rt and _prt
267+
using amrex::Math::powi;
265268

266269
// length of the current slice
267270
amrex::ParticleReal const slice_ds = m_ds / nslice();
268271

269272
// find beta*gamma^2, beta
270-
amrex::ParticleReal const betgam2 = amrex::Math::powi<2>(refpart.pt) - 1_prt;
273+
amrex::ParticleReal const betgam2 = powi<2>(refpart.pt) - 1_prt;
271274
amrex::ParticleReal const bet = refpart.beta();
272275
amrex::ParticleReal const ibetgam2 = 1_prt / betgam2;
273-
amrex::ParticleReal const b2rc2 = amrex::Math::powi<2>(bet) * amrex::Math::powi<2>(m_rc);
276+
amrex::ParticleReal const b2rc2 = powi<2>(bet) * powi<2>(m_rc);
274277

275278
// update horizontal and longitudinal phase space variables
276-
amrex::ParticleReal const gx = m_k + amrex::Math::powi<-2>(m_rc);
279+
amrex::ParticleReal const gx = m_k + powi<-2>(m_rc);
277280
amrex::ParticleReal const omega_x = std::sqrt(std::abs(gx));
278281

279282
// update vertical phase space variables

src/elements/ChrDrift.H

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ namespace impactx::elements
8585
void compute_constants (RefPart const & refpart)
8686
{
8787
using namespace amrex::literals; // for _rt and _prt
88+
using amrex::Math::powi;
8889

8990
Alignment::compute_constants(refpart);
9091

@@ -95,7 +96,7 @@ namespace impactx::elements
9596
m_beta = refpart.beta();
9697
m_gamma = refpart.gamma();
9798

98-
m_const1 = 1_prt / (2_prt * amrex::Math::powi<3>(m_beta) * amrex::Math::powi<2>(m_gamma));
99+
m_const1 = 1_prt / (2_prt * powi<3>(m_beta) * powi<2>(m_gamma));
99100
}
100101

101102
/** This is a chrdrift functor, so that a variable of this type can be used like a chrdrift function.
@@ -122,6 +123,7 @@ namespace impactx::elements
122123
) const
123124
{
124125
using namespace amrex::literals; // for _rt and _prt
126+
using amrex::Math::powi;
125127

126128
// shift due to alignment errors of the element
127129
shift_in(x, y, px, py);
@@ -137,7 +139,7 @@ namespace impactx::elements
137139
amrex::ParticleReal const ptout = pt;
138140

139141
// compute particle momentum deviation delta + 1
140-
amrex::ParticleReal const idelta1 = 1_prt / std::sqrt(1_prt - 2_prt*pt/m_beta + amrex::Math::powi<2>(pt));
142+
amrex::ParticleReal const idelta1 = 1_prt / std::sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
141143

142144
// advance transverse position and momentum (drift)
143145
x = xout + m_slice_ds * px * idelta1;
@@ -146,12 +148,12 @@ namespace impactx::elements
146148
// pyout = py;
147149

148150
// the corresponding symplectic update to t
149-
amrex::ParticleReal term = 2_prt * amrex::Math::powi<2>(pt) + amrex::Math::powi<2>(px) + amrex::Math::powi<2>(py);
150-
term = 2_prt - 4_prt*m_beta*pt + amrex::Math::powi<2>(m_beta)*term;
151-
term = -2_prt + amrex::Math::powi<2>(m_gamma)*term;
151+
amrex::ParticleReal term = 2_prt * powi<2>(pt) + powi<2>(px) + powi<2>(py);
152+
term = 2_prt - 4_prt*m_beta*pt + powi<2>(m_beta)*term;
153+
term = -2_prt + powi<2>(m_gamma)*term;
152154
term = (-1_prt+m_beta*pt)*term;
153155
term = term * m_const1;
154-
t = tout - m_slice_ds * (1_prt / m_beta + term * amrex::Math::powi<3>(idelta1));
156+
t = tout - m_slice_ds * (1_prt / m_beta + term * powi<3>(idelta1));
155157
// ptout = pt;
156158

157159
// assign updated momenta
@@ -174,6 +176,7 @@ namespace impactx::elements
174176
void operator() (RefPart & AMREX_RESTRICT refpart) const
175177
{
176178
using namespace amrex::literals; // for _rt and _prt
179+
using amrex::Math::powi;
177180

178181
// assign input reference particle values
179182
amrex::ParticleReal const x = refpart.x;
@@ -190,7 +193,7 @@ namespace impactx::elements
190193
amrex::ParticleReal const slice_ds = m_ds / nslice();
191194

192195
// assign intermediate parameter
193-
amrex::ParticleReal const step = slice_ds /std::sqrt(amrex::Math::powi<2>(pt)-1.0_prt);
196+
amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
194197

195198
// advance position and momentum (drift)
196199
refpart.x = x + step*px;

src/elements/ChrPlasmaLens.H

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,13 @@ namespace impactx::elements
131131
) const
132132
{
133133
using namespace amrex::literals; // for _rt and _prt
134+
using amrex::Math::powi;
134135

135136
// shift due to alignment errors of the element
136137
shift_in(x, y, px, py);
137138

138139
// compute particle momentum deviation delta + 1
139-
amrex::ParticleReal const delta1 = std::sqrt(1_prt - 2_prt*pt/m_beta + amrex::Math::powi<2>(pt));
140+
amrex::ParticleReal const delta1 = std::sqrt(1_prt - 2_prt*pt/m_beta + powi<2>(pt));
140141
amrex::ParticleReal const delta = delta1 - 1_prt;
141142

142143
// compute phase advance per unit length in s (in rad/m)
@@ -174,13 +175,13 @@ namespace impactx::elements
174175
amrex::ParticleReal const t0 = t - term*m_slice_ds/delta1;
175176

176177
amrex::ParticleReal const w = omega*delta1;
177-
amrex::ParticleReal const term1 = -(amrex::Math::powi<2>(p2)-amrex::Math::powi<2>(q2) * amrex::Math::powi<2>(w)) * std::sin(2_prt*m_slice_ds*omega);
178-
amrex::ParticleReal const term2 = -(amrex::Math::powi<2>(p1)-amrex::Math::powi<2>(q1) * amrex::Math::powi<2>(w)) * std::sin(2_prt*m_slice_ds*omega);
178+
amrex::ParticleReal const term1 = -(powi<2>(p2)-powi<2>(q2) * powi<2>(w)) * std::sin(2_prt*m_slice_ds*omega);
179+
amrex::ParticleReal const term2 = -(powi<2>(p1)-powi<2>(q1) * powi<2>(w)) * std::sin(2_prt*m_slice_ds*omega);
179180
amrex::ParticleReal const term3 = -2_prt*q2*p2*w * std::cos(2_prt*m_slice_ds*omega);
180181
amrex::ParticleReal const term4 = -2_prt*q1*p1*w * std::cos(2_prt*m_slice_ds*omega);
181182
amrex::ParticleReal const term5 = 2_prt*omega*(q1*p1*delta1 + q2*p2*delta1
182-
-(amrex::Math::powi<2>(p1) + amrex::Math::powi<2>(p2))*m_slice_ds - (amrex::Math::powi<2>(q1) + amrex::Math::powi<2>(q2)) * amrex::Math::powi<2>(w)*m_slice_ds);
183-
t = t0 + (-1_prt+m_beta*pt)/(8_prt*m_beta * amrex::Math::powi<3>(delta1)*omega)
183+
-(powi<2>(p1) + powi<2>(p2))*m_slice_ds - (powi<2>(q1) + powi<2>(q2)) * powi<2>(w)*m_slice_ds);
184+
t = t0 + (-1_prt+m_beta*pt)/(8_prt*m_beta * powi<3>(delta1)*omega)
184185
*(term1+term2+term3+term4+term5);
185186

186187
// ptout = pt;
@@ -207,6 +208,7 @@ namespace impactx::elements
207208
void operator() (RefPart & AMREX_RESTRICT refpart) const
208209
{
209210
using namespace amrex::literals; // for _rt and _prt
211+
using amrex::Math::powi;
210212

211213
// assign input reference particle values
212214
amrex::ParticleReal const x = refpart.x;
@@ -223,7 +225,7 @@ namespace impactx::elements
223225
amrex::ParticleReal const slice_ds = m_ds / nslice();
224226

225227
// assign intermediate parameter
226-
amrex::ParticleReal const step = slice_ds /std::sqrt(amrex::Math::powi<2>(pt)-1.0_prt);
228+
amrex::ParticleReal const step = slice_ds /std::sqrt(powi<2>(pt)-1.0_prt);
227229

228230
// advance position and momentum (straight element)
229231
refpart.x = x + step*px;

0 commit comments

Comments
 (0)