mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Applied formatting corrections
This commit is contained in:
parent
7569139d51
commit
7ebc36b4a5
2 changed files with 34 additions and 40 deletions
|
|
@ -13,8 +13,7 @@ namespace openmc {
|
|||
//! Bins the incident neutron energy.
|
||||
//==============================================================================
|
||||
|
||||
class CollisionFilter : public Filter
|
||||
{
|
||||
class CollisionFilter : public Filter {
|
||||
public:
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructors, destructors
|
||||
|
|
@ -24,12 +23,12 @@ public:
|
|||
//----------------------------------------------------------------------------
|
||||
// Methods
|
||||
|
||||
std::string type() const override {return "numCollisions";}
|
||||
std::string type() const override { return "numCollisions"; }
|
||||
|
||||
void from_xml(pugi::xml_node node) override;
|
||||
|
||||
void get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match)
|
||||
const override;
|
||||
void get_all_bins(const Particle& p, TallyEstimator estimator,
|
||||
FilterMatch& match) const override;
|
||||
|
||||
void to_statepoint(hid_t filter_group) const override;
|
||||
|
||||
|
|
@ -46,9 +45,7 @@ protected:
|
|||
// Data members
|
||||
|
||||
std::vector<int> bins_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // namespace openmc
|
||||
#endif // OPENMC_TALLIES_FILTER_COLLISIONS_H
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include <fmt/core.h>
|
||||
|
||||
#include "openmc/capi.h"
|
||||
#include "openmc/constants.h" // For F90_NONE
|
||||
#include "openmc/constants.h" // For F90_NONE
|
||||
#include "openmc/mgxs_interface.h"
|
||||
#include "openmc/search.h"
|
||||
#include "openmc/settings.h"
|
||||
|
|
@ -15,15 +15,13 @@ namespace openmc {
|
|||
// CollisionFilter implementation
|
||||
//==============================================================================
|
||||
|
||||
void
|
||||
CollisionFilter::from_xml(pugi::xml_node node)
|
||||
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)
|
||||
void CollisionFilter::set_bins(gsl::span<const int> bins)
|
||||
{
|
||||
// Clear existing bins
|
||||
bins_.clear();
|
||||
|
|
@ -31,45 +29,42 @@ CollisionFilter::set_bins(gsl::span<const int> bins)
|
|||
|
||||
// Copy bins, ensuring they are valid
|
||||
for (gsl::index i = 0; i < bins.size(); ++i) {
|
||||
if (i > 0 && bins[i] <= bins[i-1]) {
|
||||
throw std::runtime_error{"Number of Collisions bins must be monotonically increasing."};
|
||||
if (i > 0 && bins[i] <= bins[i - 1]) {
|
||||
throw std::runtime_error {
|
||||
"Number of Collisions bins must be monotonically increasing."};
|
||||
}
|
||||
bins_.push_back(bins[i]);
|
||||
}
|
||||
|
||||
n_bins_ = bins_.size();
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
CollisionFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match)
|
||||
const
|
||||
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_;
|
||||
// Get the number of collisions for the particle
|
||||
auto n = p.n_collision_;
|
||||
|
||||
// Bin the collision number. Must fit exactly the desired collision number .
|
||||
if (n >= bins_.front() && n <= bins_.back()) {
|
||||
auto it = find(bins_.begin(), bins_.end(), n);
|
||||
if (it != bins_.end()){
|
||||
size_t bin = it - bins_.begin();
|
||||
if (int(bins_[bin]) == n){
|
||||
match.bins_.push_back(bin);
|
||||
match.weights_.push_back(1.0);
|
||||
}
|
||||
// Bin the collision number. Must fit exactly the desired collision number .
|
||||
if (n >= bins_.front() && n <= bins_.back()) {
|
||||
auto it = find(bins_.begin(), bins_.end(), n);
|
||||
if (it != bins_.end()) {
|
||||
size_t bin = it - bins_.begin();
|
||||
if (int(bins_[bin]) == n) {
|
||||
match.bins_.push_back(bin);
|
||||
match.weights_.push_back(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CollisionFilter::to_statepoint(hid_t filter_group) const
|
||||
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
|
||||
std::string CollisionFilter::text_label(int bin) const
|
||||
{
|
||||
return fmt::format("Collision Number {}", int(bins_[bin]));
|
||||
}
|
||||
|
|
@ -78,11 +73,12 @@ CollisionFilter::text_label(int bin) const
|
|||
// C-API functions
|
||||
//==============================================================================
|
||||
|
||||
extern"C" int
|
||||
openmc_collision_filter_get_bins(int32_t index, const int** energies, size_t* n)
|
||||
extern "C" int openmc_collision_filter_get_bins(
|
||||
int32_t index, const int** energies, size_t* n)
|
||||
{
|
||||
// Make sure this is a valid index to an allocated filter.
|
||||
if (int err = verify_filter(index)) return err;
|
||||
if (int err = verify_filter(index))
|
||||
return err;
|
||||
|
||||
// Get a pointer to the filter and downcast.
|
||||
const auto& filt_base = model::tally_filters[index].get();
|
||||
|
|
@ -100,11 +96,12 @@ openmc_collision_filter_get_bins(int32_t index, const int** energies, size_t* n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
openmc_collision_filter_set_bins(int32_t index, size_t n, const int* energies)
|
||||
extern "C" int openmc_collision_filter_set_bins(
|
||||
int32_t index, size_t n, const int* energies)
|
||||
{
|
||||
// Make sure this is a valid index to an allocated filter.
|
||||
if (int err = verify_filter(index)) return err;
|
||||
if (int err = verify_filter(index))
|
||||
return err;
|
||||
|
||||
// Get a pointer to the filter and downcast.
|
||||
const auto& filt_base = model::tally_filters[index].get();
|
||||
|
|
@ -121,4 +118,4 @@ openmc_collision_filter_set_bins(int32_t index, size_t n, const int* energies)
|
|||
return 0;
|
||||
}
|
||||
|
||||
}// namespace openmc
|
||||
} // namespace openmc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue