Skip to content

Commit 0e28dbb

Browse files
committed
compile FDW and integrate wiggler diffusion matrix
1 parent d783e71 commit 0e28dbb

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

atintegrators/atelem.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ double atEnergy(double ringenergy, double elemenergy)
8080
else
8181
if (elemenergy!=0.0)
8282
return elemenergy;
83-
else
83+
else {
8484
atError("Energy not defined.");
85+
return 0.0; /* Never reached but makes the compiler happy */
86+
}
8587
}
8688

8789
static mxArray *get_field(const mxArray *pm, const char *fieldname)

atintegrators/gwigR.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ static void GWigPass_4th(struct gwigR *pWig, double *X)
124124
double dl, dl1, dl0;
125125
double B[3];
126126
double ax, ay, axpy, aypx;
127-
double factorvect;
128127

129128
Nstep = pWig->PN*(pWig->Nw);
130129
dl = pWig->Lw/(pWig->PN);
@@ -450,7 +449,7 @@ static void GWigB(struct gwigR *pWig, double *Xvec, double *B)
450449
{
451450
int i;
452451
double x, y, z;
453-
double kx, ky, kz, tz, kw;
452+
double kx, ky, kz, tz;
454453
double cx, sx, chx, shx;
455454
double cy, sy, chy, shy;
456455
double cz, sz;
@@ -461,8 +460,6 @@ static void GWigB(struct gwigR *pWig, double *Xvec, double *B)
461460
y = Xvec[2];
462461
z = pWig->Zw;
463462

464-
kw = 2e0*PI/(pWig->Lw);
465-
466463
B[0] = 0;
467464
B[1] = 0;
468465
B[2] = 0;
@@ -596,9 +593,9 @@ static void GWigRadiationKicks(struct gwigR *pWig, double *X, double *Bxy, doubl
596593
static void Hessian(struct gwigR *pWig, double *Xvec, double *H2)
597594
{
598595
int i,j,k;
599-
double x,px,y,py,D;
600-
double ax,axx,axxx,axy,axyy,axxy;
601-
double ay, ayx, ayxx, ayy, ayyy, ayxy;
596+
double px, py,D;
597+
double ax,axx,axxx,axy,axxy;
598+
double ay, ayx, ayxx, ayy, ayxy;
602599
double Pax[6];
603600
double Pay[6];
604601
double H[6][6];
@@ -610,19 +607,15 @@ static void Hessian(struct gwigR *pWig, double *Xvec, double *H2)
610607
axx =Pax[1];
611608
axxx=Pax[2];
612609
axy =Pax[3];
613-
axyy=Pax[4];
614610
axxy=Pax[5];
615611

616612
ay =Pay[0];
617613
ayx =Pay[1];
618614
ayxx=Pay[2];
619615
ayy =Pay[3];
620-
ayyy=Pay[4];
621616
ayxy=Pay[5];
622617

623-
x =Xvec[0];
624618
px=Xvec[1];
625-
y =Xvec[2];
626619
py=Xvec[3];
627620
D =Xvec[4];
628621

atmat/atmexall.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ function atmexall(varargin)
101101
% Diffusion matrices
102102
cdir=fullfile(atroot,'atphysics','Radiation');
103103
compile([alloptions, {passinclude}], fullfile(cdir,'findmpoleraddiffmatrix.c'));
104+
compile([alloptions, {passinclude}], fullfile(cdir,'FDW.c'));
104105

105106
% RDTs
106107
cdir=fullfile(atroot,'atphysics','NonLinearDynamics');

atmat/atphysics/Radiation/FDW.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
* Journal of Instrumentation, May 2021.
2424
*/
2525

26-
#include "atlalib.c"
2726
#include "atelem.c"
27+
#include "atlalib.c"
2828
#include "gwigR.c"
2929
#include <math.h>
30-
#include "mex.h"
31-
#include "matrix.h"
3230
#include "gwig.h"
3331

3432
/* Fourth order-symplectic integrator constants */
@@ -121,13 +119,11 @@ static void wigglerB(struct gwigR *pWig, double* orbit_in, double L, double *B66
121119
double Bxyz[3];
122120
double p_norm = 1/(1+orbit_in[4]);
123121
double p_norm2 = SQR(p_norm);
124-
double x,px,y,py,D;
122+
double px,py,D;
125123
double DLDS;
126124
int i;
127125

128-
x = orbit_in[0];
129126
px= orbit_in[1];
130-
y = orbit_in[2];
131127
py= orbit_in[3];
132128
D = orbit_in[4];
133129
GWigAx(pWig, orbit_in, &ax, &axpy);
@@ -204,7 +200,6 @@ static void FindElemB(double *orbit_in, double le, double Lw, double Bmax,
204200
double ax,ay,axpy,aypx;
205201
double B[3];
206202
double E0G;
207-
double factorvect;
208203
struct gwigR pWig;
209204
int flag;
210205

@@ -327,7 +322,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
327322
const mxArray *mxElem, *mxOrbit;
328323
double *bdiff;
329324
double orb[6];
330-
double energy;
325+
double energy = mxGetNaN(); /* Default energy value */
331326
int i, m, n;
332327

333328
if (nrhs < 2)
@@ -349,11 +344,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
349344
if (!(mxIsDouble(mxEnergy) && mxIsScalar(mxEnergy)))
350345
mexErrMsgIdAndTxt("AT:WrongArg", "Energy must be a double scalar");
351346
energy=mxGetScalar(mxEnergy);
352-
}
347+
}
353348

354-
else {
355-
energy=mxGetNaN();
356-
}
357349
/* ALLOCATE memory for the output array */
358350
plhs[0] = mxCreateDoubleMatrix(6,6,mxREAL);
359351
bdiff = mxGetDoubles(plhs[0]);
@@ -374,7 +366,7 @@ static PyObject *compute_wiggdiffmatrix(PyObject *self, PyObject *args) {
374366
PyArrayObject *pyOrbit;
375367
double *orb0, *bdiff, *retval;
376368
double orb[6];
377-
double energy;
369+
double energy = NAN; /* Default energy value */
378370
npy_intp outdims[2] = {6, 6};
379371
int i;
380372

0 commit comments

Comments
 (0)