-
Notifications
You must be signed in to change notification settings - Fork 36
Simple ring model #643
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
Merged
Merged
Simple ring model #643
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1455f9c
New PassMethod for simple quantum diffusion. Added element to element…
ac8132d
Wrong function name in __all__
4b1f5bf
Merge branch 'master' into simple_ring_model
ac6dd11
fix matlab test
d8b9a89
matlab test
2ebd2ca
matlab tests
8821e97
Add radiation damping and U0 to SimpleQuantDiffPass.
72746a3
Update arguments for SimpleQuantDiff Element
6f1ff88
Remove energyloss element. Remove analytical tau.
8b09580
Add rad on/off switching. Modify input types. Set defaults
0033931
pep
3f9281f
change default passmethod of simplequantdiff
c51a4e4
Add periodicity=1 to avoid at warning about no bends
6da14e3
Change type hint for harmonic_number to int instead of float
3f17e46
expanded help
d40dfd3
wrong text
cb3479d
Modified text
f212be9
Added multiple cavity inputs
7b630cd
Remved sincos
bf759f9
Add test. Modified help of simple_ring. Added broadcasting and option…
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
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,169 @@ | ||
|
||
#include "atelem.c" | ||
#include "atrandom.c" | ||
|
||
struct elem | ||
{ | ||
double emit_x; | ||
double emit_y; | ||
double sigma_dp; | ||
double tau_x; | ||
double tau_y; | ||
double tau_z; | ||
double beta_x; | ||
double beta_y; | ||
double sigma_xp; | ||
double sigma_yp; | ||
double U0; | ||
double EnergyLossFactor; | ||
}; | ||
|
||
void SimpleQuantDiffPass(double *r_in, | ||
double sigma_xp, double sigma_yp, double sigma_dp, | ||
double tau_x, double tau_y, double tau_z, double EnergyLossFactor, | ||
pcg32_random_t* rng, int num_particles) | ||
|
||
{ | ||
double *r6; | ||
int c, i; | ||
|
||
#pragma omp parallel for if (num_particles > OMP_PARTICLE_THRESHOLD*10) default(shared) shared(r_in,num_particles) private(c,r6) | ||
for (c = 0; c<num_particles; c++) { /*Loop over particles */ | ||
r6 = r_in+c*6; | ||
double randnorm[3]; | ||
for (i = 0; i < 3; i++) { | ||
randnorm[i] = atrandn_r(rng, 0.0, 1.0); | ||
} | ||
|
||
if(!atIsNaN(r6[0])) { | ||
if(tau_x!=0.0) { | ||
r6[1] -= 2*r6[1]/tau_x; | ||
} | ||
if(sigma_xp!=0.0) { | ||
r6[1] += 2*sigma_xp*sqrt(1/tau_x)*randnorm[0]; | ||
} | ||
if(sigma_yp!=0.0) { | ||
r6[3] += 2*sigma_yp*sqrt(1/tau_y)*randnorm[1]; | ||
} | ||
if(tau_y!=0.0) { | ||
r6[3] -= 2*r6[3]/tau_y; | ||
} | ||
if(sigma_dp!=0.0) { | ||
r6[4] += 2*sigma_dp*sqrt(1/tau_z)*randnorm[2]; | ||
} | ||
if(tau_z!=0.0) { | ||
r6[4] -= 2*r6[4]/tau_z; | ||
} | ||
|
||
if(EnergyLossFactor>0.0) { | ||
r6[4] -= EnergyLossFactor; | ||
} | ||
} | ||
} | ||
} | ||
|
||
#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 (ElemData) {*/ | ||
if (!Elem) { | ||
double emit_x, emit_y, sigma_dp, tau_x, tau_y, tau_z, beta_x, beta_y, U0, EnergyLossFactor; | ||
emit_x=atGetDouble(ElemData,"emit_x"); check_error(); | ||
emit_y=atGetDouble(ElemData,"emit_y"); check_error(); | ||
sigma_dp=atGetDouble(ElemData,"sigma_dp"); check_error(); | ||
tau_x=atGetDouble(ElemData,"tau_x"); check_error(); | ||
tau_y=atGetDouble(ElemData,"tau_y"); check_error(); | ||
tau_z=atGetDouble(ElemData,"tau_z"); check_error(); | ||
beta_x=atGetDouble(ElemData,"beta_x"); check_error(); | ||
beta_y=atGetDouble(ElemData,"beta_y"); check_error(); | ||
U0=atGetDouble(ElemData,"U0"); check_error(); | ||
|
||
Elem = (struct elem*)atMalloc(sizeof(struct elem)); | ||
Elem->emit_x=emit_x; | ||
Elem->emit_y=emit_y; | ||
Elem->sigma_dp=sigma_dp; | ||
Elem->tau_x=tau_x; | ||
Elem->tau_y=tau_y; | ||
Elem->tau_z=tau_z; | ||
Elem->beta_x=beta_x; | ||
Elem->beta_y=beta_y; | ||
Elem->sigma_xp=sqrt(emit_x/beta_x); | ||
Elem->sigma_yp=sqrt(emit_y/beta_y); | ||
Elem->U0=U0; | ||
Elem->EnergyLossFactor=U0/Param->energy; | ||
} | ||
SimpleQuantDiffPass(r_in, Elem->sigma_xp, Elem->sigma_yp, Elem->sigma_dp, Elem->tau_x, Elem->tau_y, Elem->tau_z, Elem->EnergyLossFactor, Param->thread_rng, num_particles); | ||
/* } | ||
else { | ||
atFree(Elem->T1); | ||
atFree(Elem->T2); | ||
atFree(Elem->R1); | ||
atFree(Elem->R2); | ||
atFree(Elem->EApertures); | ||
atFree(Elem->RApertures); | ||
}*/ | ||
return Elem; | ||
} | ||
|
||
MODULE_DEF(SimpleQuantDiffPass) /* Dummy module initialisation */ | ||
|
||
#endif /*defined(MATLAB_MEX_FILE) || defined(PYAT)*/ | ||
|
||
#if defined(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]); | ||
double emit_x, emit_y, sigma_dp, tau_x, tau_y, tau_z, beta_x, beta_y, sigma_xp, sigma_yp, U0, EnergyLossFactor; | ||
|
||
emit_x=atGetDouble(ElemData,"emit_x"); check_error(); | ||
emit_y=atGetDouble(ElemData,"emit_y"); check_error(); | ||
sigma_dp=atGetDouble(ElemData,"sigma_dp"); check_error(); | ||
tau_x=atGetDouble(ElemData,"tau_x"); check_error(); | ||
tau_y=atGetDouble(ElemData,"tau_y"); check_error(); | ||
tau_z=atGetDouble(ElemData,"tau_z"); check_error(); | ||
beta_x=atGetDouble(ElemData,"beta_x"); check_error(); | ||
beta_y=atGetDouble(ElemData,"beta_y"); check_error(); | ||
U0=atGetDouble(ElemData,"U0"); check_error(); | ||
sigma_xp=sqrt(emit_x/beta_x); | ||
sigma_yp=sqrt(emit_y/beta_y); | ||
EnergyLossFactor=U0/6e9; | ||
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 */ | ||
plhs[0] = mxDuplicateArray(prhs[1]); | ||
r_in = mxGetDoubles(plhs[0]); | ||
SimpleQuantDiffPass(r_in, sigma_xp, sigma_yp, sigma_dp, tau_x, tau_y, tau_z, EnergyLossFactor, &pcg32_global, num_particles); | ||
} | ||
else if (nrhs == 0) { | ||
/* list of required fields */ | ||
plhs[0] = mxCreateCellMatrix(9,1); | ||
mxSetCell(plhs[0],0,mxCreateString("emit_x")); | ||
mxSetCell(plhs[0],1,mxCreateString("emit_y")); | ||
mxSetCell(plhs[0],2,mxCreateString("sigma_dp")); | ||
mxSetCell(plhs[0],3,mxCreateString("tau_x")); | ||
mxSetCell(plhs[0],4,mxCreateString("tau_y")); | ||
mxSetCell(plhs[0],5,mxCreateString("tau_z")); | ||
mxSetCell(plhs[0],6,mxCreateString("beta_x")); | ||
mxSetCell(plhs[0],7,mxCreateString("beta_y")); | ||
mxSetCell(plhs[0],8,mxCreateString("U0")); | ||
|
||
|
||
/* | ||
if (nlhs>1) { | ||
plhs[1] = mxCreateCellMatrix(6,1); | ||
mxSetCell(plhs[1],0,mxCreateString("T1")); | ||
mxSetCell(plhs[1],1,mxCreateString("T2")); | ||
mxSetCell(plhs[1],2,mxCreateString("R1")); | ||
mxSetCell(plhs[1],3,mxCreateString("R2")); | ||
mxSetCell(plhs[1],4,mxCreateString("RApertures")); | ||
mxSetCell(plhs[1],5,mxCreateString("EApertures")); | ||
}*/ | ||
} | ||
else { | ||
mexErrMsgIdAndTxt("AT:WrongArg","Needs 0 or 2 arguments"); | ||
} | ||
} | ||
#endif /*defined(MATLAB_MEX_FILE)*/ |
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
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.