mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Move DistribcellFilter to C++
This commit is contained in:
parent
bf025edd58
commit
f2a5e10c46
9 changed files with 121 additions and 317 deletions
|
|
@ -5,6 +5,7 @@
|
|||
#define OPENMC_GEOMETRY_AUX_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace openmc {
|
||||
|
|
@ -41,7 +42,7 @@ extern "C" void neighbor_lists();
|
|||
//! Populate all data structures needed for distribcells.
|
||||
//==============================================================================
|
||||
|
||||
extern "C" void prepare_distribcell(int32_t* filter_cell_list, int n);
|
||||
extern "C" void prepare_distribcell();
|
||||
|
||||
//==============================================================================
|
||||
//! Recursively search through the geometry and count cell instances.
|
||||
|
|
@ -65,21 +66,6 @@ extern "C" void count_cell_instances(int32_t univ_indx);
|
|||
extern "C" int
|
||||
count_universe_instances(int32_t search_univ, int32_t target_univ_id);
|
||||
|
||||
//==============================================================================
|
||||
//! Find the length necessary for a string to contain a distribcell path.
|
||||
//! @param target_cell The index of the Cell in the global Cell array.
|
||||
//! @param map The index of the distribcell mapping corresponding to the target
|
||||
//! cell.
|
||||
//! @param target_offset An instance number for a distributed cell.
|
||||
//! @param root_univ The index of the root Universe in the global Universe
|
||||
//! array.
|
||||
//! @return The size of a character array needed to fit the distribcell path.
|
||||
//==============================================================================
|
||||
|
||||
extern "C" int
|
||||
distribcell_path_len(int32_t target_cell, int32_t map, int32_t target_offset,
|
||||
int32_t root_univ);
|
||||
|
||||
//==============================================================================
|
||||
//! Build a character array representing the path to a distribcell instance.
|
||||
//! @param target_cell The index of the Cell in the global Cell array.
|
||||
|
|
@ -88,13 +74,12 @@ distribcell_path_len(int32_t target_cell, int32_t map, int32_t target_offset,
|
|||
//! @param target_offset An instance number for a distributed cell.
|
||||
//! @param root_univ The index of the root Universe in the global Universe
|
||||
//! array.
|
||||
//! @param[out] path The unique traversal through the geometry tree that leads
|
||||
//! to the desired instance of the target cell.
|
||||
//! @return The unique traversal through the geometry tree that leads to the
|
||||
//! desired instance of the target cell.
|
||||
//==============================================================================
|
||||
|
||||
extern "C" void
|
||||
distribcell_path(int32_t target_cell, int32_t map, int32_t target_offset,
|
||||
int32_t root_univ, char *path);
|
||||
std::string
|
||||
distribcell_path(int32_t target_cell, int32_t map, int32_t target_offset);
|
||||
|
||||
//==============================================================================
|
||||
//! Determine the maximum number of nested coordinate levels in the geometry.
|
||||
|
|
|
|||
93
include/openmc/tallies/tally_filter_distribcell.h
Normal file
93
include/openmc/tallies/tally_filter_distribcell.h
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#ifndef OPENMC_TALLY_FILTER_DISTRIBCELL_H
|
||||
#define OPENMC_TALLY_FILTER_DISTRIBCELL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "openmc/cell.h"
|
||||
#include "openmc/error.h"
|
||||
#include "openmc/geometry_aux.h" // For distribcell_path
|
||||
#include "openmc/lattice.h"
|
||||
#include "openmc/tallies/tally_filter.h"
|
||||
|
||||
|
||||
namespace openmc {
|
||||
|
||||
class DistribcellFilter : public TallyFilter
|
||||
{
|
||||
public:
|
||||
virtual ~DistribcellFilter() override = default;
|
||||
|
||||
virtual void
|
||||
from_xml(pugi::xml_node node) override
|
||||
{
|
||||
auto cells = get_node_array<int32_t>(node, "bins");
|
||||
if (cells.size() != 1) {
|
||||
fatal_error("Only one cell can be specified per distribcell filter.");
|
||||
}
|
||||
cell_ = cells[0];
|
||||
}
|
||||
|
||||
virtual void
|
||||
initialize() override
|
||||
{
|
||||
auto search = cell_map.find(cell_);
|
||||
if (search != cell_map.end()) {
|
||||
cell_ = search->second;
|
||||
n_bins_ = cells[cell_]->n_instances_;
|
||||
} else {
|
||||
std::stringstream err_msg;
|
||||
err_msg << "Could not find cell " << cell_
|
||||
<< " specified on tally filter.";
|
||||
fatal_error(err_msg);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void
|
||||
get_all_bins(Particle* p, int estimator, TallyFilterMatch& match)
|
||||
const override
|
||||
{
|
||||
int offset = 0;
|
||||
auto distribcell_index = cells[cell_]->distribcell_index_;
|
||||
for (int i = 0; i < p->n_coord; i++) {
|
||||
auto& c {*cells[p->coord[i].cell]};
|
||||
if (c.type_ == FILL_UNIVERSE) {
|
||||
offset += c.offset_[distribcell_index];
|
||||
} else if (c.type_ == FILL_LATTICE) {
|
||||
auto& lat {*lattices[p->coord[i+1].lattice-1]};
|
||||
int i_xyz[3] {p->coord[i+1].lattice_x,
|
||||
p->coord[i+1].lattice_y,
|
||||
p->coord[i+1].lattice_z};
|
||||
if (lat.are_valid_indices(i_xyz)) {
|
||||
offset += lat.offset(distribcell_index, i_xyz);
|
||||
}
|
||||
}
|
||||
if (cell_ == p->coord[i].cell) {
|
||||
match.bins.push_back(offset + 1);
|
||||
match.weights.push_back(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void
|
||||
to_statepoint(hid_t filter_group) const override
|
||||
{
|
||||
write_dataset(filter_group, "type", "distribcell");
|
||||
write_dataset(filter_group, "n_bins", n_bins_);
|
||||
write_dataset(filter_group, "bins", cells[cell_]->id_);
|
||||
}
|
||||
|
||||
virtual std::string
|
||||
text_label(int bin) const override
|
||||
{
|
||||
auto map = cells[cell_]->distribcell_index_;
|
||||
auto path = distribcell_path(cell_, map, bin-1);
|
||||
|
||||
return "Distributed Cell " + path;
|
||||
}
|
||||
|
||||
int32_t cell_;
|
||||
};
|
||||
|
||||
} // namespace openmc
|
||||
#endif // OPENMC_TALLY_FILTER_DISTRIBCELL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue