Skip to content

Commit

Permalink
Merge pull request openmc-dev#1486 from paulromano/copysign-fix
Browse files Browse the repository at this point in the history
Fix bug occurring when surface ID > 999999
  • Loading branch information
amandalund authored Feb 20, 2020
2 parents 9f44761 + ae69650 commit c8496aa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/particle.cpp
Original file line number Diff line number Diff line change
@@ -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>

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c8496aa

Please sign in to comment.