Skip to content

Commit 3116b13

Browse files
committed
Add continuousLinear function to teapot_base
1 parent fe0aa5e commit 3116b13

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

src/teapot/teapotbase.cc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,4 +1566,99 @@ void RingRF(Bunch* bunch, double ring_length, int harmonic_numb,
15661566
}
15671567
}
15681568

1569+
1570+
////////////////////////////
1571+
// NAME
1572+
// continuousLinear
1573+
//
1574+
// DESCRIPTION
1575+
// Continuous axisymmetric focusing element: linear transport matrix. This
1576+
// is equivalent to quad1, but is focusing in both planes. This element
1577+
// assumes there is no energy offset from the synchronous particle.
1578+
//
1579+
// PARAMETERS
1580+
// bunch = reference to the macro-particle bunch
1581+
// length = length of transport
1582+
// kq = quadrupole field strength [m^(-2)]
1583+
// kq already has information about the charge of particle.
1584+
//
1585+
// RETURNS
1586+
// Nothing
1587+
//
1588+
///////////////////////////////////////////////////////////////////////////
1589+
1590+
void continuousLinear(Bunch* bunch, double length, double kq, int useCharge) {
1591+
if (kq == 0.0 || bunch->getCharge() == 0.0) {
1592+
drift(bunch, length);
1593+
return;
1594+
}
1595+
1596+
double kqc = abs(kq);
1597+
double sqrt_kq;
1598+
double kqlength;
1599+
1600+
double x_init;
1601+
double y_init;
1602+
double xp_init;
1603+
double yp_init;
1604+
1605+
double cx;
1606+
double sx;
1607+
double cy;
1608+
double sy;
1609+
1610+
double m11 = 0.0;
1611+
double m12 = 0.0;
1612+
double m21 = 0.0;
1613+
double m22 = 0.0;
1614+
double m33 = 0.0;
1615+
double m34 = 0.0;
1616+
double m43 = 0.0;
1617+
double m44 = 0.0;
1618+
1619+
SyncPart* syncPart = bunch->getSyncPart();
1620+
1621+
double v = OrbitConst::c * syncPart->getBeta();
1622+
if (length > 0.0) {
1623+
syncPart->setTime(syncPart->getTime() + length / v);
1624+
}
1625+
1626+
double gamma2i = 1.0 / (syncPart->getGamma() * syncPart->getGamma());
1627+
double dp_p_coeff = 1.0 /(syncPart->getMomentum() * syncPart->getBeta());
1628+
1629+
sqrt_kq = pow(kqc, 0.5);
1630+
kqlength = sqrt_kq * length;
1631+
cx = cos(kqlength);
1632+
sx = sin(kqlength);
1633+
cy = cos(kqlength);
1634+
sy = sin(kqlength);
1635+
m11 = +cx;
1636+
m12 = +sx / sqrt_kq;
1637+
m21 = -sx * sqrt_kq;
1638+
m22 = +cx;
1639+
m33 = +cy;
1640+
m34 = +sy / sqrt_kq;
1641+
m43 = -sy * sqrt_kq;
1642+
m44 = +cy;
1643+
1644+
double dp_p;
1645+
1646+
double** arr = bunch->coordArr();
1647+
1648+
for(int i = 0; i < bunch->getSize(); i++) {
1649+
dp_p = arr[i][5] * dp_p_coeff;
1650+
x_init = arr[i][0];
1651+
xp_init = arr[i][1];
1652+
y_init = arr[i][2];
1653+
yp_init = arr[i][3];
1654+
1655+
arr[i][0] = x_init * m11 + xp_init * m12;
1656+
arr[i][1] = x_init * m21 + xp_init * m22;
1657+
arr[i][2] = y_init * m33 + yp_init * m34;
1658+
arr[i][3] = y_init * m43 + yp_init * m44;
1659+
arr[i][4] += dp_p * gamma2i * length;
1660+
}
1661+
}
1662+
1663+
15691664
} //end of namespace teapot_base

src/teapot/teapotbase.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ namespace teapot_base
7575
int nsteps, int useCharge);
7676

7777
void RingRF(Bunch* bunch, double ring_length, int harmonic_numb, double voltage, double phase_s, int useCharge);
78+
79+
void continuousLinear(Bunch* bunch, double length, double kq, int useCharge);
7880
}
7981

8082
#endif //TEAPOT_BASE_H

src/teapot/wrap_teapotbase.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,23 @@ extern "C"
483483
return Py_None;
484484
}
485485

486+
// Continuous axisymmetric focusing element.
487+
static PyObject* wrap_continuousLinear(PyObject *self, PyObject *args)
488+
{
489+
PyObject* pyBunch;
490+
double length, kq;
491+
int useCharge = 1;
492+
if(!PyArg_ParseTuple(args, "Odd|i:continuousLinear",
493+
&pyBunch, &length, &kq, &useCharge))
494+
{
495+
error("teapotbase - continuousLinear - cannot parse arguments!");
496+
}
497+
Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) pyBunch)->cpp_obj;
498+
teapot_base::continuousLinear(cpp_bunch, length, kq, useCharge);
499+
Py_INCREF(Py_None);
500+
return Py_None;
501+
}
502+
486503
static PyMethodDef teapotbaseMethods[] =
487504
{
488505
{"rotatexy", wrap_rotatexy, METH_VARARGS, "Rotates bunch around z axis "},
@@ -510,6 +527,7 @@ extern "C"
510527
{"soln", wrap_soln, METH_VARARGS, "Integration through a solenoid "},
511528
{"wedgebendCF", wrap_wedgebendCF, METH_VARARGS, "Straight bends particles through wedge for Combined Function non-SBEND "},
512529
{"RingRF", wrap_RingRF, METH_VARARGS, "Tracking particles through a simple ring RF cavity."},
530+
{"continuousLinear", wrap_continuousLinear, METH_VARARGS, "Continuous axisymmetric linear focusing element."},
513531
{ NULL, NULL }
514532
};
515533

0 commit comments

Comments
 (0)