-
Notifications
You must be signed in to change notification settings - Fork 40
Forbid negative lattice or element energies #1066
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,26 +76,17 @@ typedef mxArray atElem; | |
|
|
||
| double atEnergy(double ringenergy, double elemenergy) | ||
| { | ||
| if (ringenergy!=0.0) | ||
| if (ringenergy > 0.0) | ||
| return ringenergy; | ||
| else | ||
| if (elemenergy!=0.0) | ||
| if (elemenergy > 0.0) | ||
| return elemenergy; | ||
| else { | ||
| atError("Energy not defined."); | ||
| atError("Energy must be positive. Check lattice or passmethod parameters."); | ||
| return 0.0; /* Never reached but makes the compiler happy */ | ||
| } | ||
| } | ||
|
|
||
| double atGamma(double ringenergy, double elemenergy, double rest_energy) | ||
| { | ||
| double energy = atEnergy(ringenergy, elemenergy); | ||
| if (rest_energy == 0.0) | ||
| return 1.0E-9 * energy / __E0; | ||
| else | ||
| return energy / rest_energy; | ||
| } | ||
|
|
||
| static mxArray *get_field(const mxArray *pm, const char *fieldname) | ||
| { | ||
| mxArray *field; | ||
|
|
@@ -206,11 +197,19 @@ typedef PyObject atElem; | |
| #define atError(...) PyErr_Format(PyExc_ValueError, __VA_ARGS__) | ||
| #define atWarning(...) PyErr_WarnFormat(PyExc_RuntimeWarning, 0, __VA_ARGS__) | ||
| #define atPrintf(...) PySys_WriteStdout(__VA_ARGS__) | ||
| #define atEnergy(ringenergy,elemenergy) (ringenergy) | ||
| #define atGamma(ringenergy,elemenergy,rest_energy) ((rest_energy) == 0.0 ? 1.0E-9*(ringenergy)/__E0 : (ringenergy)/(rest_energy)) | ||
|
|
||
| static int array_imported = 0; | ||
|
|
||
| double atEnergy(double ringenergy, double elemenergy) | ||
| { | ||
| if (ringenergy > 0.0) | ||
| return ringenergy; | ||
| else { | ||
| atError("Energy must be positive. Check lattice or set the track() keyword argument."); | ||
| return 0.0; /* Never reached but makes the compiler happy */ | ||
| } | ||
| } | ||
|
|
||
| static NUMPY_IMPORT_ARRAY_TYPE init_numpy(void) | ||
| { | ||
| import_array(); | ||
|
|
@@ -362,6 +361,15 @@ static double *atGetOptionalDoubleArray(const PyObject *element, char *name) | |
| #define C_LINK | ||
| #endif | ||
|
|
||
| double atGamma(double ringenergy, double elemenergy, double rest_energy) | ||
| { | ||
| double energy = atEnergy(ringenergy, elemenergy); | ||
| if (rest_energy == 0.0) | ||
| return 1.0E-9 * energy / __E0; | ||
| else | ||
| return energy / rest_energy; | ||
| } | ||
|
|
||
|
Comment on lines
+364
to
+372
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. For python, the macro as it is is enough (and more efficient).
Contributor
Author
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 am not so sure about this, how about a simulation of energy ramp where the energy is set to negative during the ramp? I think we still need the energy check in atGamma() |
||
| C_LINK ExportMode struct elem *trackFunction(const atElem *ElemData, struct elem *Elem, double *r_in, | ||
| int num_particles, struct parameters *Param); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test as it is was implemented by @oscarxblanco in #1016 to solve the same issue as you do.
What you write here is exactly what I suggested in #1016 (comment) but was not implemented. So it's ok for me