forked from openmc-dev/openmc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openmc-dev#1798 from ameliajo/collisionFilter
Added Collision filter
- Loading branch information
Showing
12 changed files
with
231 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef OPENMC_TALLIES_FILTER_COLLISIONS_H | ||
#define OPENMC_TALLIES_FILTER_COLLISIONS_H | ||
|
||
#include <vector> | ||
#include <unordered_map> | ||
#include <gsl/gsl> | ||
|
||
#include "openmc/tallies/filter.h" | ||
|
||
namespace openmc { | ||
|
||
//============================================================================== | ||
//! Bins the incident neutron energy. | ||
//============================================================================== | ||
|
||
class CollisionFilter : public Filter { | ||
public: | ||
//---------------------------------------------------------------------------- | ||
// Constructors, destructors | ||
|
||
~CollisionFilter() = default; | ||
|
||
//---------------------------------------------------------------------------- | ||
// Methods | ||
|
||
std::string type() const override { return "collision"; } | ||
|
||
void from_xml(pugi::xml_node node) override; | ||
|
||
void get_all_bins(const Particle& p, TallyEstimator estimator, | ||
FilterMatch& match) const override; | ||
|
||
void to_statepoint(hid_t filter_group) const override; | ||
|
||
std::string text_label(int bin) const override; | ||
|
||
//---------------------------------------------------------------------------- | ||
// Accessors | ||
|
||
const std::vector<int>& bins() const { return bins_; } | ||
void set_bins(gsl::span<const int> bins); | ||
|
||
protected: | ||
//---------------------------------------------------------------------------- | ||
// Data members | ||
|
||
std::vector<int> bins_; | ||
|
||
std::unordered_map<int,int> map_; | ||
|
||
}; | ||
|
||
} // namespace openmc | ||
#endif // OPENMC_TALLIES_FILTER_COLLISIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "openmc/tallies/filter_collision.h" | ||
|
||
#include <fmt/core.h> | ||
|
||
#include "openmc/capi.h" | ||
#include "openmc/search.h" | ||
#include "openmc/settings.h" | ||
#include "openmc/xml_interface.h" | ||
|
||
namespace openmc { | ||
|
||
//============================================================================== | ||
// CollisionFilter implementation | ||
//============================================================================== | ||
|
||
void CollisionFilter::from_xml(pugi::xml_node node) | ||
{ | ||
auto bins = get_node_array<int>(node, "bins"); | ||
this->set_bins(bins); | ||
} | ||
|
||
void CollisionFilter::set_bins(gsl::span<const int> bins) | ||
{ | ||
// Clear existing bins | ||
bins_.clear(); | ||
bins_.reserve(bins.size()); | ||
map_.clear(); | ||
|
||
// Copy bins | ||
for (gsl::index i = 0; i < bins.size(); ++i) { | ||
bins_.push_back(bins[i]); | ||
map_[bins[i]] = i; | ||
} | ||
|
||
n_bins_ = bins_.size(); | ||
} | ||
|
||
void CollisionFilter::get_all_bins( | ||
const Particle& p, TallyEstimator estimator, FilterMatch& match) const | ||
{ | ||
// Get the number of collisions for the particle | ||
auto n = p.n_collision_; | ||
|
||
// Bin the collision number. Must fit exactly the desired collision number. | ||
auto search = map_.find(n); | ||
if (search != map_.end()){ | ||
match.bins_.push_back(search->second); | ||
match.weights_.push_back(1.0); | ||
} | ||
} | ||
|
||
void CollisionFilter::to_statepoint(hid_t filter_group) const | ||
{ | ||
Filter::to_statepoint(filter_group); | ||
write_dataset(filter_group, "bins", bins_); | ||
} | ||
|
||
std::string CollisionFilter::text_label(int bin) const | ||
{ | ||
return fmt::format("Collision Number {}", bins_[bin]); | ||
} | ||
|
||
} // namespace openmc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0f036e2c34f3e9cf350d4f6bac6b0c5933d77d0665a5d461a3911c29d8f1d49b74100e680920da286c63538fabb86cbcd17532c6aad6048ee78e6cef75dd76ae | ||
bde3149c47242d232bf0c138609d081f9cdb11851aac7486b485c764f0d954c79bad35ffd3d78f7c3485dbdc5e93120a14ff2a21da2856a5bad6bf598551d1ee |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters