Merge pull request #1486 from paulromano/copysign-fix

Fix bug occurring when surface ID > 999999
This commit is contained in:
Amanda Lund 2020-02-19 20:46:25 -06:00 committed by GitHub
commit c8496aaec1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View file

@ -377,7 +377,7 @@ CSGCell::CSGCell(pugi::xml_node cell_node)
throw std::runtime_error{"Invalid surface ID " + std::to_string(abs(r))
+ " specified in region for cell " + std::to_string(id_) + "."};
}
r = copysign(it->second + 1, r);
r = (r > 0) ? it->second + 1 : -(it->second + 1);
}
}
@ -536,8 +536,8 @@ CSGCell::to_hdf5(hid_t cell_group) const
region_spec << " |";
} else {
// Note the off-by-one indexing
region_spec << " "
<< copysign(model::surfaces[abs(token)-1]->id_, token);
auto surf_id = model::surfaces[abs(token)-1]->id_;
region_spec << " " << ((token > 0) ? surf_id : -surf_id);
}
}
write_string(group, "region", region_spec.str(), false);

View file

@ -192,7 +192,7 @@ extern "C" void print_particle(Particle* p)
// Display miscellaneous info.
if (p->surface_ != 0) {
const Surface& surf {*model::surfaces[std::abs(p->surface_)-1]};
fmt::print(" Surface = {}\n", std::copysign(surf.id_, p->surface_));
fmt::print(" Surface = {}\n", (p->surface_ > 0) ? surf.id_ : -surf.id_);
}
fmt::print(" Weight = {}\n", p->wgt_);
if (settings::run_CE) {

View file

@ -1,7 +1,7 @@
#include "openmc/particle.h"
#include <algorithm> // copy, min
#include <cmath> // log, abs, copysign
#include <cmath> // log, abs
#include <fmt/core.h>
@ -539,7 +539,7 @@ Particle::cross_surface()
// TODO: off-by-one
surface_ = rotational ?
surf_p->i_periodic_ + 1 :
std::copysign(surf_p->i_periodic_ + 1, surface_);
((surface_ > 0) ? surf_p->i_periodic_ + 1 : -(surf_p->i_periodic_ + 1));
// Figure out what cell particle is in now
n_coord_ = 1;