mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Move cell filter get_all_bins to C++
This commit is contained in:
parent
1cc0271f4c
commit
0084ae613b
5 changed files with 49 additions and 12 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "openmc/particle.h"
|
||||
#include "openmc/xml_interface.h"
|
||||
|
||||
|
||||
|
|
@ -43,6 +44,10 @@ class TallyFilter
|
|||
{
|
||||
public:
|
||||
virtual void from_xml(pugi::xml_node node) = 0;
|
||||
|
||||
virtual void
|
||||
get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const = 0;
|
||||
|
||||
virtual void initialize() = 0;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "openmc/cell.h"
|
||||
|
|
@ -35,11 +36,27 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: mapping
|
||||
for (int i = 0; i < cells_.size(); i++) {
|
||||
map_[cells_[i]] = i;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void
|
||||
get_all_bins(Particle* p, int estimator, TallyFilterMatch& match) const
|
||||
{
|
||||
for (int i = 0; i < p->n_coord; i++) {
|
||||
auto search = map_.find(p->coord[i].cell);
|
||||
if (search != map_.end()) {
|
||||
// TODO: off-by-one
|
||||
match.bins.push_back(search->second + 1);
|
||||
match.weights.push_back(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<int32_t> cells_;
|
||||
std::unordered_map<int32_t, int> map_;
|
||||
};
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue