Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion atintegrators/AperturePass.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ MODULE_DEF(AperturePass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double *r_in;
const mxArray *ElemData = prhs[0];
int num_particles = mxGetN(prhs[1]);
Expand Down
25 changes: 14 additions & 11 deletions atintegrators/BeamLoadingCavityPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void write_buffer(double *data, double *buffer, int datasize, int buffersize){

void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
double *bunch_spos,double *bunch_currents,
double circumference,int nturn,struct elem *Elem) {
double circumference,int nturn,double energy,
struct elem *Elem) {
/*
* r_in - 6-by-N matrix of initial conditions reshaped into
* 1-d array of 6*N elements
Expand All @@ -63,7 +64,6 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
long buffersize = Elem->buffersize;
double normfact = Elem->normfact;
double le = Elem->Length;
double energy = Elem->Energy;
double rffreq = Elem->Frequency;
double harmn = Elem->HarmNumber;
double tlag = Elem->TimeLag;
Expand Down Expand Up @@ -156,6 +156,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
double *r_in, int num_particles, struct parameters *Param)
{
double rl = Param->RingLength;
double energy;
int nturn=Param->nturn;
if (!Elem) {
long nslice,nturns,blmode,cavitymode, buffersize;
Expand All @@ -176,7 +177,6 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,

/*attributes for RF cavity*/
Length=atGetDouble(ElemData,"Length"); check_error();
Energy=atGetDouble(ElemData,"Energy"); check_error();
Frequency=atGetDouble(ElemData,"Frequency"); check_error();
TimeLag=atGetOptionalDouble(ElemData,"TimeLag",0); check_error();
/*attributes for resonator*/
Expand All @@ -202,7 +202,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
vbeam_buffer=atGetDoubleArray(ElemData,"_vbeam_buffer"); check_error();
vbunch_buffer=atGetDoubleArray(ElemData,"_vbunch_buffer"); check_error();
/*optional attributes*/

Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
z_cuts=atGetOptionalDoubleArray(ElemData,"ZCuts"); check_error();

int dimsth[] = {Param->nbunch*nslice*nturns, 4};
Expand Down Expand Up @@ -239,6 +239,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->vbeam_buffer = vbeam_buffer;
Elem->vbunch_buffer = vbunch_buffer;
}
energy = atEnergy(Param->energy, Elem->Energy);

if(num_particles<Param->nbunch){
atError("Number of particles has to be greater or equal to the number of bunches.");
}else if (num_particles%Param->nbunch!=0){
Expand All @@ -257,7 +259,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
}
#endif
BeamLoadingCavityPass(r_in,num_particles,Param->nbunch,Param->bunch_spos,
Param->bunch_currents,rl,nturn,Elem);
Param->bunch_currents,rl,nturn,energy,Elem);
return Elem;
}

Expand All @@ -267,10 +269,10 @@ MODULE_DEF(BeamLoadingCavityPass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if(nrhs == 2)
{

{
if(nrhs >= 2) {
double rest_energy = 0.0;
double charge = -1.0;
double *r_in;
const mxArray *ElemData = prhs[0];
int num_particles = mxGetN(prhs[1]);
Expand All @@ -293,7 +295,6 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
double *vbunch_buffer;
/*attributes for RF cavity*/
Length=atGetDouble(ElemData,"Length"); check_error();
Energy=atGetDouble(ElemData,"Energy"); check_error();
Frequency=atGetDouble(ElemData,"Frequency"); check_error();
TimeLag=atGetOptionalDouble(ElemData,"TimeLag",0); check_error();
/*attributes for resonator*/
Expand All @@ -319,6 +320,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
vbeam_buffer=atGetDoubleArray(ElemData,"_vbeam_buffer"); check_error();
vbunch_buffer=atGetDoubleArray(ElemData,"_vbunch_buffer"); check_error();
/*optional attributes*/
Energy=atGetOptionalDouble(ElemData,"Energy",0.0); check_error();
z_cuts=atGetOptionalDoubleArray(ElemData,"ZCuts"); check_error();

Elem = (struct elem*)atMalloc(sizeof(struct elem));
Expand Down Expand Up @@ -348,6 +350,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Elem->vgen_buffer = vgen_buffer;
Elem->vbeam_buffer = vbeam_buffer;
Elem->vbunch_buffer = vbunch_buffer;
if (nrhs > 2) atProperties(prhs[2], &Energy, &rest_energy, &charge);

if (mxGetM(prhs[1]) != 6) mexErrMsgIdAndTxt("AT:WrongArg","Second argument must be a 6 x N matrix");
/* ALLOCATE memory for the output array of the same size as the input */
Expand All @@ -356,7 +359,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])

double bspos = 0.0;
double bcurr = 0.0;
BeamLoadingCavityPass(r_in,num_particles,1,&bspos,&bcurr,1,0,Elem);
BeamLoadingCavityPass(r_in,num_particles,1,&bspos,&bcurr,1,0,Energy,Elem);
}
else if (nrhs == 0)
{ /* return list of required fields */
Expand Down
2 changes: 1 addition & 1 deletion atintegrators/BeamMomentsPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ MODULE_DEF(BeamMomentsPass) /* Dummy module initialisation */

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {

double *r_in;
const mxArray *ElemData = prhs[0];
Expand Down
2 changes: 1 addition & 1 deletion atintegrators/BendLinearPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ MODULE_DEF(BendLinearPass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2 ) {
if (nrhs >= 2) {
double Length, BendingAngle, EntranceAngle, ExitAngle, K, ByError, FringeInt1, FringeInt2, FullGap;
double *R1, *R2, *T1, *T2;
double *r_in;
Expand Down
2 changes: 1 addition & 1 deletion atintegrators/BndMPoleSymplectic4E2Pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ MODULE_DEF(BndMPoleSymplectic4E2Pass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double irho;
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling, FringeInt1, FringeInt2;
int MaxOrder, NumIntSteps;
Expand Down
15 changes: 10 additions & 5 deletions atintegrators/BndMPoleSymplectic4E2RadPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void BndMPoleSymplectic4E2RadPass(double *r, double le, double irho, double *A,
ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
double *r_in, int num_particles, struct parameters *Param)
{
double irho;
double irho, energy;
if (!Elem) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling, Energy,
FringeInt1, FringeInt2;
Expand All @@ -216,8 +216,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap",0); check_error();
Scaling=atGetOptionalDouble(ElemData,"FieldScaling",1.0); check_error();
FringeInt1=atGetOptionalDouble(ElemData,"FringeInt1",0); check_error();
Expand Down Expand Up @@ -258,13 +258,15 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->KickAngle=KickAngle;
}
irho = Elem->BendingAngle/Elem->Length;
energy = atEnergy(Param->energy, Elem->Energy);

BndMPoleSymplectic4E2RadPass(r_in, Elem->Length, irho, Elem->PolynomA, Elem->PolynomB,
Elem->MaxOrder, Elem->NumIntSteps, Elem->EntranceAngle, Elem->ExitAngle,
Elem->FringeInt1, Elem->FringeInt2, Elem->FullGap,
Elem->h1, Elem->h2,
Elem->T1, Elem->T2, Elem->R1, Elem->R2,
Elem->RApertures, Elem->EApertures,
Elem->KickAngle, Elem->Scaling, Elem->Energy, num_particles);
Elem->KickAngle, Elem->Scaling, energy, num_particles);
return Elem;
}

Expand All @@ -275,7 +277,9 @@ MODULE_DEF(BndMPoleSymplectic4E2RadPass) /* Dummy module initialisation *
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double rest_energy = 0.0;
double charge = -1.0;
double irho;
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling, FringeInt1, FringeInt2, Energy;
int MaxOrder, NumIntSteps;
Expand All @@ -293,8 +297,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetDouble(ElemData,"Energy"); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",0.0); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap", 0); check_error();
Scaling=atGetOptionalDouble(ElemData,"FieldScaling",1.0); check_error();
FringeInt1=atGetOptionalDouble(ElemData,"FringeInt1", 0); check_error();
Expand All @@ -309,6 +313,7 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
RApertures=atGetOptionalDoubleArray(ElemData,"RApertures"); check_error();
KickAngle=atGetOptionalDoubleArray(ElemData,"KickAngle"); check_error();
irho = BendingAngle/Length;
if (nrhs > 2) atProperties(prhs[2], &Energy, &rest_energy, &charge);

/* ALLOCATE memory for the output array of the same size as the input */
plhs[0] = mxDuplicateArray(prhs[1]);
Expand Down
2 changes: 1 addition & 1 deletion atintegrators/BndMPoleSymplectic4Pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ MODULE_DEF(BndMPoleSymplectic4Pass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2;
int MaxOrder, NumIntSteps, FringeBendEntrance, FringeBendExit,
Expand Down
16 changes: 11 additions & 5 deletions atintegrators/BndMPoleSymplectic4QuantPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void BndMPoleSymplectic4QuantPass(double *r, double le, double irho, double *A,
ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
double *r_in, int num_particles, struct parameters *Param)
{
double irho;
double irho, energy;
if (!Elem) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2, Energy;
Expand All @@ -195,8 +195,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
FringeBendEntrance=atGetOptionalLong(ElemData,"FringeBendEntrance",1); check_error();
FringeBendExit=atGetOptionalLong(ElemData,"FringeBendExit",1); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap",0); check_error();
Expand Down Expand Up @@ -245,6 +245,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->KickAngle=KickAngle;
}
irho = Elem->BendingAngle/Elem->Length;
energy = atEnergy(Param->energy, Elem->Energy);

BndMPoleSymplectic4QuantPass(r_in, Elem->Length, irho, Elem->PolynomA, Elem->PolynomB,
Elem->MaxOrder, Elem->NumIntSteps, Elem->EntranceAngle, Elem->ExitAngle,
Elem->FringeBendEntrance,Elem->FringeBendExit,
Expand All @@ -253,7 +255,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->fringeIntM0, Elem->fringeIntP0,
Elem->T1, Elem->T2, Elem->R1, Elem->R2,
Elem->RApertures, Elem->EApertures,
Elem->KickAngle, Elem->Scaling, Elem->Energy,
Elem->KickAngle, Elem->Scaling, energy,
Param->thread_rng, num_particles);
return Elem;
}
Expand All @@ -265,12 +267,14 @@ MODULE_DEF(BndMPoleSymplectic4QuantPass) /* Dummy module initialisation *
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2, Energy;
int MaxOrder, NumIntSteps, FringeBendEntrance, FringeBendExit,
FringeQuadEntrance, FringeQuadExit;
double *PolynomA, *PolynomB, *R1, *R2, *T1, *T2, *EApertures, *RApertures, *fringeIntM0, *fringeIntP0, *KickAngle;
double rest_energy = 0.0;
double charge = -1.0;
double irho;
double *r_in;
const mxArray *ElemData = prhs[0];
Expand All @@ -285,8 +289,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetDouble(ElemData,"Energy"); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",0.0); check_error();
FringeBendEntrance=atGetOptionalLong(ElemData,"FringeBendEntrance",1); check_error();
FringeBendExit=atGetOptionalLong(ElemData,"FringeBendExit",1); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap",0); check_error();
Expand All @@ -305,10 +309,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
RApertures=atGetOptionalDoubleArray(ElemData,"RApertures"); check_error();
KickAngle=atGetOptionalDoubleArray(ElemData,"KickAngle"); check_error();
irho = BendingAngle/Length;
if (nrhs > 2) atProperties(prhs[2], &Energy, &rest_energy, &charge);

/* ALLOCATE memory for the output array of the same size as the input */
plhs[0] = mxDuplicateArray(prhs[1]);
r_in = mxGetDoubles(plhs[0]);

BndMPoleSymplectic4QuantPass(r_in, Length, irho, PolynomA, PolynomB,
MaxOrder, NumIntSteps, EntranceAngle, ExitAngle,
FringeBendEntrance, FringeBendExit,
Expand Down
16 changes: 11 additions & 5 deletions atintegrators/BndMPoleSymplectic4RadPass.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void BndMPoleSymplectic4RadPass(double *r, double le, double irho, double *A, do
ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
double *r_in, int num_particles, struct parameters *Param)
{
double irho;
double irho, energy;
if (!Elem) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2, Energy;
Expand All @@ -143,8 +143,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",Param->energy); check_error();
FringeBendEntrance=atGetOptionalLong(ElemData,"FringeBendEntrance",1); check_error();
FringeBendExit=atGetOptionalLong(ElemData,"FringeBendExit",1); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap",0); check_error();
Expand Down Expand Up @@ -193,6 +193,8 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->KickAngle=KickAngle;
}
irho = Elem->BendingAngle/Elem->Length;
energy = atEnergy(Param->energy, Elem->Energy);

BndMPoleSymplectic4RadPass(r_in, Elem->Length, irho, Elem->PolynomA, Elem->PolynomB,
Elem->MaxOrder, Elem->NumIntSteps, Elem->EntranceAngle, Elem->ExitAngle,
Elem->FringeBendEntrance,Elem->FringeBendExit,
Expand All @@ -201,7 +203,7 @@ ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem,
Elem->fringeIntM0, Elem->fringeIntP0,
Elem->T1, Elem->T2, Elem->R1, Elem->R2,
Elem->RApertures, Elem->EApertures,
Elem->KickAngle, Elem->Scaling, Elem->Energy, num_particles);
Elem->KickAngle, Elem->Scaling, energy, num_particles);
return Elem;
}

Expand All @@ -212,7 +214,9 @@ MODULE_DEF(BndMPoleSymplectic4RadPass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double rest_energy = 0.0;
double charge = -1.0;
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2, Energy;
int MaxOrder, NumIntSteps, FringeBendEntrance, FringeBendExit,
Expand All @@ -232,8 +236,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
BendingAngle=atGetDouble(ElemData,"BendingAngle"); check_error();
EntranceAngle=atGetDouble(ElemData,"EntranceAngle"); check_error();
ExitAngle=atGetDouble(ElemData,"ExitAngle"); check_error();
Energy=atGetDouble(ElemData,"Energy"); check_error();
/*optional fields*/
Energy=atGetOptionalDouble(ElemData,"Energy",0.0); check_error();
FringeBendEntrance=atGetOptionalLong(ElemData,"FringeBendEntrance",1); check_error();
FringeBendExit=atGetOptionalLong(ElemData,"FringeBendExit",1); check_error();
FullGap=atGetOptionalDouble(ElemData,"FullGap",0); check_error();
Expand All @@ -252,10 +256,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
RApertures=atGetOptionalDoubleArray(ElemData,"RApertures"); check_error();
KickAngle=atGetOptionalDoubleArray(ElemData,"KickAngle"); check_error();
irho = BendingAngle/Length;
if (nrhs > 2) atProperties(prhs[2], &Energy, &rest_energy, &charge);

/* ALLOCATE memory for the output array of the same size as the input */
plhs[0] = mxDuplicateArray(prhs[1]);
r_in = mxGetDoubles(plhs[0]);

BndMPoleSymplectic4RadPass(r_in, Length, irho, PolynomA, PolynomB,
MaxOrder, NumIntSteps, EntranceAngle, ExitAngle,
FringeBendEntrance, FringeBendExit,
Expand Down
2 changes: 1 addition & 1 deletion atintegrators/BndStrMPoleSymplectic4Pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ MODULE_DEF(BndStrMPoleSymplectic4Pass) /* Dummy module initialisation */
#if defined(MATLAB_MEX_FILE)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if (nrhs == 2) {
if (nrhs >= 2) {
double Length, BendingAngle, EntranceAngle, ExitAngle, FullGap, Scaling,
FringeInt1, FringeInt2, X0ref, ByError, RefDZ;
int MaxOrder, NumIntSteps;
Expand Down
Loading