-
Notifications
You must be signed in to change notification settings - Fork 42
Add feedback passmethod #983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lcarver
wants to merge
24
commits into
master
Choose a base branch
from
add_feedback_passmethod
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
78bbfa0
Add unmodified passmethod from simon
33133ba
Add MPI, add mex function
5376147
Check build
08586f0
build
86d58db
build
a64c751
rebuild
1afef0f
Wrong Dummy mode
198df6a
Add orbit to simple_ring
e93858d
Add Feedback element
087f2f1
Fix all pointers
0316aac
Stash
6a95be2
remove comments
6e1ec0e
Better pointers
c6b320a
Add optionals
9b1def8
Merge branch 'master' into add_feedback_passmethod
lcarver 85d1e88
Change capitals, add Sequence, remove kwaargs, modify help
9e51f09
black
f025786
put back kwargs as it is needed for passmethod
680072d
Change case in C too
fb5b6df
merge master
052d1a5
add buffer to feedback pass
c14d7c5
Merge branch 'master' into add_feedback_passmethod
9d3057c
Checkpoint, but ultimately this is not a good implementation
5612a56
pass test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| /* IdentityPass.c | ||
| Accelerator Toolbox | ||
| Revision 7/16/03 | ||
| A.Terebilo | ||
| */ | ||
|
|
||
| #include "atelem.c" | ||
| #include "atlalib.c" | ||
| #ifdef MPI | ||
| #include <mpi.h> | ||
| #include <mpi4py/mpi4py.h> | ||
| #endif | ||
|
|
||
| struct elem | ||
| { | ||
| double GX; | ||
| double GY; | ||
| double GZ; | ||
| double *closed_orbit; | ||
| }; | ||
|
|
||
| void FeedbackPass(double *r_in, int num_particles, struct elem *Elem) | ||
| { | ||
| int c; | ||
| double mx = 0.0; | ||
| double my = 0.0; | ||
| double mz = 0.0; | ||
| long npart = 0.0; | ||
|
|
||
| double *closed_orbit; | ||
| closed_orbit = Elem->closed_orbit; | ||
|
|
||
| double gx = Elem->GX; | ||
| double gy = Elem->GY; | ||
| double gz = Elem->GZ; | ||
|
|
||
| for (c = 0; c<num_particles; c++) { /*Loop over particles */ | ||
| double *r6 = r_in+c*6; | ||
|
|
||
| if (!atIsNaN(r6[0])) { | ||
| npart += 1; | ||
| mx += r6[0]; | ||
| my += r6[2]; | ||
| mz += r6[5]; | ||
| } | ||
| } | ||
|
|
||
| #ifdef MPI | ||
| MPI_Allreduce(MPI_IN_PLACE, &npart, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); | ||
| MPI_Allreduce(MPI_IN_PLACE, &mx, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); | ||
| MPI_Allreduce(MPI_IN_PLACE, &my, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); | ||
| MPI_Allreduce(MPI_IN_PLACE, &mz, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); | ||
| MPI_Barrier(MPI_COMM_WORLD); | ||
| #endif | ||
|
|
||
|
|
||
| if (npart>0.0){ | ||
| mx /= npart; | ||
| my /= npart; | ||
| mz /= npart; | ||
| for (c = 0; c<num_particles; c++) { /*Loop over particles */ | ||
| double *r6 = r_in+c*6; | ||
| if (!atIsNaN(r6[0])) { | ||
| r6[0] -= (mx-closed_orbit[0])*gx; | ||
| r6[2] -= (my-closed_orbit[2])*gy; | ||
| r6[5] -= (mz-closed_orbit[5])*gz; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #if defined(MATLAB_MEX_FILE) || defined(PYAT) | ||
| ExportMode struct elem *trackFunction(const atElem *ElemData,struct elem *Elem, | ||
| double *r_in, int num_particles, struct parameters *Param) | ||
| { | ||
| if (!Elem) { | ||
| double GX, GY, GZ, *closed_orbit; | ||
| GX=atGetOptionalDouble(ElemData,"GX",0.0); check_error(); | ||
| GY=atGetOptionalDouble(ElemData,"GY",0.0); check_error(); | ||
| GZ=atGetOptionalDouble(ElemData,"GZ",0.0); check_error(); | ||
| closed_orbit = atGetDoubleArray(ElemData,"closed_orbit"); check_error(); | ||
|
|
||
| Elem = (struct elem*)atMalloc(sizeof(struct elem)); | ||
| Elem->GX=GX; | ||
| Elem->GY=GY; | ||
| Elem->GZ=GZ; | ||
| Elem->closed_orbit = closed_orbit; | ||
| } | ||
| FeedbackPass(r_in,num_particles,Elem); | ||
| return Elem; | ||
| } | ||
|
|
||
| MODULE_DEF(FeedbackPass) /* Dummy module initialisation */ | ||
|
|
||
| #endif /*defined(MATLAB_MEX_FILE) || defined(PYAT)*/ | ||
|
|
||
|
|
||
| #ifdef MATLAB_MEX_FILE | ||
|
|
||
| void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) | ||
| { | ||
| if (nrhs >= 2) { | ||
|
|
||
| double *r_in; | ||
| const mxArray *ElemData = prhs[0]; | ||
| int num_particles = mxGetN(prhs[1]); | ||
| struct elem El, *Elem=&El; | ||
|
|
||
| double GX,GY,GZ,*closed_orbit; | ||
|
|
||
| GX=atGetOptionalDouble(ElemData,"GX",0.0); check_error(); | ||
| GY=atGetOptionalDouble(ElemData,"GY",0.0); check_error(); | ||
| GZ=atGetOptionalDouble(ElemData,"GZ",0.0); check_error(); | ||
| closed_orbit = atGetDoubleArray(ElemData,"closed_orbit");check_error(); | ||
|
|
||
|
|
||
| Elem = (struct elem*)atMalloc(sizeof(struct elem)); | ||
| Elem->GX=GX; | ||
| Elem->GY=GY; | ||
| Elem->GZ=GZ; | ||
| Elem->closed_orbit = closed_orbit; | ||
|
|
||
| if (mxGetM(prhs[1]) != 6) mexErrMsgIdAndTxt("AT:WrongArg","Second argument must be a 6 x N matrix: particle array"); | ||
|
|
||
| /* ALLOCATE memory for the output array of the same size as the input */ | ||
| plhs[0] = mxDuplicateArray(prhs[1]); | ||
| r_in = mxGetDoubles(plhs[0]); | ||
| FeedbackPass(r_in,num_particles,Elem); | ||
| } | ||
| else if (nrhs == 0) { | ||
| /* list of required fields */ | ||
| plhs[0] = mxCreateCellMatrix(1,1); | ||
| mxSetCell(plhs[0],0,mxCreateString("closed_orbit")); | ||
| if(nlhs>1) /* optional fields */ | ||
| { | ||
| plhs[1] = mxCreateCellMatrix(3,1); | ||
| mxSetCell(plhs[1],0,mxCreateString("GX")); | ||
| mxSetCell(plhs[1],1,mxCreateString("GY")); | ||
| mxSetCell(plhs[1],2,mxCreateString("GZ")); | ||
| } | ||
| } | ||
| else { | ||
| mexErrMsgIdAndTxt("AT:WrongArg","Needs 2 or 0 arguments"); | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,7 +141,9 @@ def simple_ring( | |
| U0: float = 0.0, | ||
| name: str = "", | ||
| particle: str | Particle = "relativistic", | ||
| TimeLag: float | Sequence[float] = 0.0 | ||
| TimeLag: float | Sequence[float] = 0.0, | ||
|
swhite2401 marked this conversation as resolved.
|
||
| orb6: Sequence[float] = np.zeros(6), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed for feedback? |
||
|
|
||
| ) -> Lattice: | ||
| """Generates a "simple ring" based on a given dictionary | ||
| of global parameters | ||
|
|
@@ -201,7 +203,8 @@ def simple_ring( | |
| or a Particle object | ||
| TimeLag: Set the timelag of the cavities, Default=0. Can be scalar | ||
| or sequence of scalars (as with harmonic_number and Vrf). | ||
|
|
||
| orb6: 6d closed orbit. Needed for inclusion of feedbacks. | ||
|
|
||
| If the given emitx, emity or espread is 0, then no equlibrium emittance | ||
| is applied in this plane. | ||
| If the given tau is 0, then no radiation damping is applied for this plane. | ||
|
|
@@ -265,7 +268,8 @@ def simple_ring( | |
| # generate the linear tracking element, we set a length | ||
| # which is needed to give the lattice object the correct length | ||
| # (although it is not used for anything else) | ||
| lin_elem = M66("Linear", m66=Mat66, Length=circumference) | ||
|
|
||
| lin_elem = M66("Linear", m66=Mat66, Length=circumference, T1=-orb6, T2=orb6) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you had to change this |
||
|
|
||
| # Generate the simple radiation element | ||
| simplerad = SimpleRadiation( | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.