Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/tallies/tally.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "openmc/array.h"
#include "openmc/capi.h"
#include "openmc/cell.h"
#include "openmc/constants.h"
#include "openmc/container_util.h"
#include "openmc/error.h"
Expand Down Expand Up @@ -634,21 +635,30 @@ void Tally::set_scores(const vector<std::string>& scores)
"other than CellFilter and EnergyFilter");
}
type_ = TallyType::PULSE_HEIGHT;

// Collecting indices of all cells covered by the filters in the pulse
// height tally in global variable pulse_height_cells
for (const auto& i_filt : filters_) {
auto cell_filter =
dynamic_cast<CellFilter*>(model::tally_filters[i_filt].get());
if (cell_filter) {
const auto& cells = cell_filter->cells();
for (int i = 0; i < cell_filter->n_bins(); i++) {
int cell_index = cells[i];
if (!contains(model::pulse_height_cells, cell_index)) {
model::pulse_height_cells.push_back(cell_index);
if (cell_present) {
// Collecting indices of all cells covered by the filters in the pulse
// height tally in global variable pulse_height_cells
for (const auto& i_filt : filters_) {
auto cell_filter =
dynamic_cast<CellFilter*>(model::tally_filters[i_filt].get());
if (cell_filter) {
const auto& cells = cell_filter->cells();
for (int i = 0; i < cell_filter->n_bins(); i++) {
int cell_index = cells[i];
if (!contains(model::pulse_height_cells, cell_index)) {
model::pulse_height_cells.push_back(cell_index);
}
}
}
}
} else {
// The pulse height tally covers all of the geometry
for (int cell_index = 0; cell_index < model::cells.size();
++cell_index) {
if (!contains(model::pulse_height_cells, cell_index)) {
model::pulse_height_cells.push_back(cell_index);
}
}
}
break;

Expand Down
85 changes: 40 additions & 45 deletions src/tallies/tally_scoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2672,56 +2672,51 @@ void score_pulse_height_tally(Particle& p, const vector<int>& tallies)
for (auto i_tally : tallies) {
auto& tally {*model::tallies[i_tally]};

// Determine all CellFilter in the tally
for (const auto& filter : tally.filters()) {
auto cell_filter =
dynamic_cast<CellFilter*>(model::tally_filters[filter].get());
if (cell_filter != nullptr) {

const auto& cells = cell_filter->cells();
// Loop over all cells in the CellFilter
for (auto cell_index = 0; cell_index < cells.size(); ++cell_index) {
int cell_id = cells[cell_index];

// Temporarily change cell of particle
p.n_coord() = 1;
p.coord(0).cell() = cell_id;

// Determine index of cell in model::pulse_height_cells
auto it = std::find(model::pulse_height_cells.begin(),
model::pulse_height_cells.end(), cell_id);
int index = std::distance(model::pulse_height_cells.begin(), it);

// Temporarily change energy of particle to pulse-height value
p.E_last() = p.pht_storage()[index];

// Initialize an iterator over valid filter bin combinations. If
// there are no valid combinations, use a continue statement to ensure
// we skip the assume_separate break below.
auto filter_iter = FilterBinIter(tally, p);
auto end = FilterBinIter(tally, true, &p.filter_matches());
if (filter_iter == end)
continue;
auto& cells = model::pulse_height_cells;

// Find CellFilter in the tally
auto cell_filter = tally.get_filter<CellFilter>();
if (cell_filter != nullptr)
cells = cell_filter->cells();

for (auto cell_id : cells) {
// Temporarily change cell of particle
p.n_coord() = 1;
p.coord(0).cell() = cell_id;

// Determine index of cell in model::pulse_height_cells
auto it = std::find(model::pulse_height_cells.begin(),
model::pulse_height_cells.end(), cell_id);
int index = std::distance(model::pulse_height_cells.begin(), it);

// Temporarily change energy of particle to pulse-height value
p.E_last() = p.pht_storage()[index];

// Initialize an iterator over valid filter bin combinations. If
// there are no valid combinations, use a continue statement to ensure
// we skip the assume_separate break below.
auto filter_iter = FilterBinIter(tally, p);
auto end = FilterBinIter(tally, true, &p.filter_matches());
if (filter_iter == end)
continue;

// Loop over filter bins.
for (; filter_iter != end; ++filter_iter) {
auto filter_index = filter_iter.index_;
auto filter_weight = filter_iter.weight_;
// Loop over filter bins.
for (; filter_iter != end; ++filter_iter) {
auto filter_index = filter_iter.index_;
auto filter_weight = filter_iter.weight_;

// Loop over scores.
for (auto score_index = 0; score_index < tally.scores_.size();
++score_index) {
// Loop over scores.
for (auto score_index = 0; score_index < tally.scores_.size();
++score_index) {
#pragma omp atomic
tally.results_(filter_index, score_index, TallyResult::VALUE) +=
filter_weight;
}
}

// Reset all the filter matches for the next tally event.
for (auto& match : p.filter_matches())
match.bins_present_ = false;
tally.results_(filter_index, score_index, TallyResult::VALUE) +=
filter_weight;
}
}

// Reset all the filter matches for the next tally event.
for (auto& match : p.filter_matches())
match.bins_present_ = false;
}
// Restore cell/energy
p.n_coord() = orig_n_coord;
Expand Down
Loading