Commit 42181751 authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch '490-beam-without-particles-specified-crashes' into 'master'

Resolve "BEAM without particles specified crashes"

Closes #490

See merge request !305
parents a164fe31 00520044
...@@ -868,6 +868,12 @@ void Distribution::checkParticleNumber(size_t &numberOfParticles) { ...@@ -868,6 +868,12 @@ void Distribution::checkParticleNumber(size_t &numberOfParticles) {
size_t numberOfDistParticles = tOrZDist_m.size(); size_t numberOfDistParticles = tOrZDist_m.size();
reduce(numberOfDistParticles, numberOfDistParticles, OpAddAssign()); reduce(numberOfDistParticles, numberOfDistParticles, OpAddAssign());
if (numberOfDistParticles == 0) {
throw OpalException("Distribution::checkParticleNumber",
"Zero particles in the distribution! "
"The number of particles needs to be specified.");
}
if (numberOfDistParticles != numberOfParticles) { if (numberOfDistParticles != numberOfParticles) {
*gmsg << "\n--------------------------------------------------" << endl *gmsg << "\n--------------------------------------------------" << endl
<< "Warning!! The number of particles in the initial" << endl << "Warning!! The number of particles in the initial" << endl
...@@ -2816,11 +2822,10 @@ int Distribution::getLastEmittedEnergyBin() { ...@@ -2816,11 +2822,10 @@ int Distribution::getLastEmittedEnergyBin() {
double Distribution::getMaxTOrZ() { double Distribution::getMaxTOrZ() {
std::vector<double>::iterator longIt = tOrZDist_m.begin(); double maxTOrZ = std::numeric_limits<int>::min();
double maxTOrZ = *longIt; for (auto tOrZ : tOrZDist_m) {
for (++longIt; longIt != tOrZDist_m.end(); ++longIt) { if (maxTOrZ < tOrZ)
if (maxTOrZ < *longIt) maxTOrZ = tOrZ;
maxTOrZ = *longIt;
} }
reduce(maxTOrZ, maxTOrZ, OpMaxAssign()); reduce(maxTOrZ, maxTOrZ, OpMaxAssign());
...@@ -2830,11 +2835,10 @@ double Distribution::getMaxTOrZ() { ...@@ -2830,11 +2835,10 @@ double Distribution::getMaxTOrZ() {
double Distribution::getMinTOrZ() { double Distribution::getMinTOrZ() {
std::vector<double>::iterator longIt = tOrZDist_m.begin(); double minTOrZ = std::numeric_limits<int>::max();
double minTOrZ = *longIt; for (auto tOrZ : tOrZDist_m) {
for (++longIt; longIt != tOrZDist_m.end(); ++longIt) { if (minTOrZ > tOrZ)
if (minTOrZ > *longIt) minTOrZ = tOrZ;
minTOrZ = *longIt;
} }
reduce(minTOrZ, minTOrZ, OpMinAssign()); reduce(minTOrZ, minTOrZ, OpMinAssign());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment