Skip to content

Commit

Permalink
Bug Fix: Wiggler diffusion matrix (#759)
Browse files Browse the repository at this point in the history
* Adding wiggler matrix diffusion code and modifying wiggler integrators to initialize z position for every particle

* Silencing warnings for .mexw64 and .pyd extensions

* Defining energy in mex file from Param instead of ElemData

* Wiggler difussion matrices added to ohmienvelope

* Matlab/Python mex function update

* update matlab & python runners

* Merged gwigrad2 to gwigR

* GwigInit function update

* Adding rotation and translation to integrators

* Spelling typos

* Wiggler index deletion enhanced

* File modification log update

* Updated radiation kicks computation and documentation

* Minor changes to documentation

* Updating rotation and translation diffusion

* Minor changes to integrator file

* Translation diffusion deleted

* radiation kicks back to original formula

---------

Co-authored-by: ZeusMarti <[email protected]>
Co-authored-by: oscarxblanco <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent f34f189 commit a409dd6
Show file tree
Hide file tree
Showing 8 changed files with 995 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.mex
*.mexa64
*.mexmaci64
*.mexw64

# Compiled python
*.pyc
*.pyd

# pytest cache
.cache
Expand Down
16 changes: 13 additions & 3 deletions atintegrators/GWigSymplecticPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*---------------------------------------------------------------------------
* Modification Log:
* -----------------
* .03 2024-05-06 J. Arenillas, ALBA, [email protected]
* Adding rotations and translations to wiggler.
* Bug fix in wiggler initialisation.
* Energy parameter bug fix.
*
* .02 2003-06-18 J. Li
* Cleanup the code
*
Expand Down Expand Up @@ -123,11 +128,13 @@ void GWigSymplecticPass(double *r, double Energy, double Ltot, double Lw,
/* Energy is defined in the lattice in eV but GeV is used by the gwig code. */
Energy = Energy / 1e9;

GWigInit(&Wig, Energy, Ltot, Lw, Bmax, Nstep, Nmeth, NHharm, NVharm, By, Bx, T1, T2, R1, R2);

for (c = 0;c<num_particles;c++) {
GWigInit(&Wig, Energy, Ltot, Lw, Bmax, Nstep, Nmeth, NHharm, NVharm, By, Bx, T1, T2, R1, R2);
r6 = r+c*6;
if (!atIsNaN(r6[0])) {
/* Misalignment at entrance */
if (T1) ATaddvv(r6,T1);
if (R1) ATmultmv(r6,R1);
switch (Nmeth) {
case second:
GWigPass_2nd(&Wig, r6);
Expand All @@ -139,6 +146,9 @@ void GWigSymplecticPass(double *r, double Energy, double Ltot, double Lw,
printf("Invalid wiggler integration method %d.\n", Nmeth);
break;
}
/* Misalignment at exit */
if (R2) ATmultmv(r6,R2);
if (T2) ATaddvv(r6,T2);
}
}
}
Expand All @@ -158,7 +168,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
int Nstep, Nmeth;
int NHharm, NVharm;

Energy = atGetDouble(ElemData, "Energy"); check_error();
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
Ltot = atGetDouble(ElemData, "Length"); check_error();
Lw = atGetDouble(ElemData, "Lw"); check_error();
Bmax = atGetDouble(ElemData, "Bmax"); check_error();
Expand Down
17 changes: 13 additions & 4 deletions atintegrators/GWigSymplecticRadPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*---------------------------------------------------------------------------
* Modification Log:
* -----------------
* .03 2024-05-06 J. Arenillas, ALBA, [email protected]
* Adding rotations and translations to wiggler.
* Bug fix in wiggler initialisation.
* Energy parameter bug fix.
* .02 2003-06-18 J. Li
* Cleanup the code
*
Expand Down Expand Up @@ -123,7 +127,7 @@ void GWigInit(struct gwigR *Wig,double design_energy, double Ltot, double Lw,

#define second 2
#define fourth 4
void GWigSymplecticRadPass(double *r,double Energy, double Ltot, double Lw,
void GWigSymplecticRadPass(double *r, double Energy, double Ltot, double Lw,
double Bmax, int Nstep, int Nmeth, int NHharm, int NVharm,
double *By, double *Bx, double *T1, double *T2,
double *R1, double *R2, int num_particles)
Expand All @@ -141,11 +145,13 @@ void GWigSymplecticRadPass(double *r,double Energy, double Ltot, double Lw,
zEndPointV[0] = 0;
zEndPointV[1] = Ltot;

GWigInit(&Wig, Energy, Ltot, Lw, Bmax, Nstep, Nmeth, NHharm, NVharm,0, 0, zEndPointH, zEndPointV, By, Bx, T1, T2, R1, R2);

for(c = 0;c<num_particles;c++) {
GWigInit(&Wig, Energy, Ltot, Lw, Bmax, Nstep, Nmeth, NHharm, NVharm,0, 0, zEndPointH, zEndPointV, By, Bx, T1, T2, R1, R2);
r6 = r+c*6;
if(!atIsNaN(r6[0])) {
/* Misalignment at entrance */
if (T1) ATaddvv(r6,T1);
if (R1) ATmultmv(r6,R1);
switch (Nmeth) {
case second:
GWigPass_2nd(&Wig, r6);
Expand All @@ -157,6 +163,9 @@ void GWigSymplecticRadPass(double *r,double Energy, double Ltot, double Lw,
printf("Invalid wiggler integration method %d.\n", Nmeth);
break;
}
/* Misalignment at exit */
if (R2) ATmultmv(r6,R2);
if (T2) ATaddvv(r6,T2);
}
}
}
Expand All @@ -176,7 +185,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
int Nstep, Nmeth;
int NHharm, NVharm;

Energy = atGetDouble(ElemData, "Energy"); check_error();
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
Ltot = atGetDouble(ElemData, "Length"); check_error();
Lw = atGetDouble(ElemData, "Lw"); check_error();
Bmax = atGetDouble(ElemData, "Bmax"); check_error();
Expand Down
Loading

0 comments on commit a409dd6

Please sign in to comment.