Hard coded momentum tolerance
Summary
In Opal-Cycl, there is a hardcoded parameter which requires the mean beam momentum to be within 1e-2 of the reference particle momentum. This is completely inappropriate for many simulations.
Steps to reproduce
Run a lattice with PC != mean momentum of the beam
What is the current bug behavior?
Opal throws an exception. This comes from line 2411 of ParallelCyclotronTracker.cpp
What is the expected correct behavior?
Really, opal should not throw an exception at all. There are many use cases where the reference momentum does not want to be the same as the actual distribution. At the very least the tolerance should be soft coded.
Relevant logs and/or screenshots
Line 2414 of src/Algorithms/ParallelCyclotronTracker.cpp
if (std::abs(pTotalMean - referencePtot) / pTotalMean > 1e-2) { // ROGERS BUG; 1e-2 should be user parameter
throw OpalException("ParallelCyclotronTracker::checkFileMomentum",
"The total momentum of the particle distribution\n"
"in the global reference frame: " +
std::to_string(pTotalMean) + ",\n"
"is different from the momentum given\n"
"in the \"BEAM\" command: " +
std::to_string(referencePtot) + ".\n"
"In Opal-cycl the initial distribution\n"
"is specified in the local reference frame.\n"
"When using a \"FROMFILE\" type distribution, the momentum \n"
"must be the same as the specified in the \"BEAM\" command,\n"
"which is in global reference frame.");
}
I guess easiest would be to add a tolerance parameter to the FROMFILE distribution type. Default to 1e-2.