diff --git a/src/geometry_aux.cpp b/src/geometry_aux.cpp index 8a33947435..d31657e74e 100644 --- a/src/geometry_aux.cpp +++ b/src/geometry_aux.cpp @@ -329,17 +329,15 @@ prepare_distribcell() if (distrib_filt) { distribcells.insert(distrib_filt->cell()); } - - auto* ci_filt = dynamic_cast(filt.get()); - if (ci_filt) { - for (const auto& i : ci_filt->cell_instances()) { - distribcells.insert(i.index_cell); - } - } } - // Find all cells with distributed materials or temperatures. Make sure that - // the number of materials/temperatures matches the number of cell instances. + // By default, add material cells to the list of distributed cells + for (gsl::index i = 0; i < model::cells.size(); ++i) { + if (model::cells[i]->type_ == FILL_MATERIAL) distribcells.insert(i); + } + + // Make sure that the number of materials/temperatures matches the number of + // cell instances. for (int i = 0; i < model::cells.size(); i++) { Cell& c {*model::cells[i]}; @@ -352,7 +350,6 @@ prepare_distribcell() "one or the number of instances."; fatal_error(err_msg); } - distribcells.insert(i); } if (c.sqrtkT_.size() > 1) { @@ -364,20 +361,18 @@ prepare_distribcell() "one or the number of instances."; fatal_error(err_msg); } - distribcells.insert(i); } } - // Search through universes for distributed cells and assign each one a + // Search through universes for material cells and assign each one a // unique distribcell array index. int distribcell_index = 0; std::vector target_univ_ids; for (const auto& u : model::universes) { - for (auto cell_indx : u->cells_) { - if (distribcells.find(cell_indx) != distribcells.end()) { - model::cells[cell_indx]->distribcell_index_ = distribcell_index; + for (auto idx : u->cells_) { + if (distribcells.find(idx) != distribcells.end()) { + model::cells[idx]->distribcell_index_ = distribcell_index++; target_univ_ids.push_back(u->id_); - ++distribcell_index; } } } diff --git a/src/initialize.cpp b/src/initialize.cpp index 387fd9f116..460db24363 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -269,6 +269,9 @@ void read_input_xml() read_tallies_xml(); + // Initialize distribcell_filters + prepare_distribcell(); + if (settings::run_mode == RUN_MODE_PLOTTING) { // Read plots.xml if it exists read_plots_xml(); diff --git a/src/simulation.cpp b/src/simulation.cpp index ec588a9ada..eaed2badf5 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -58,9 +58,6 @@ int openmc_simulation_init() // Skip if simulation has already been initialized if (simulation::initialized) return 0; - // Initialize distribcell_filters - prepare_distribcell(); - // Determine how much work each process should do calculate_work(); diff --git a/src/tallies/filter_cell_instance.cpp b/src/tallies/filter_cell_instance.cpp index 8149f746f5..a79e3017c3 100644 --- a/src/tallies/filter_cell_instance.cpp +++ b/src/tallies/filter_cell_instance.cpp @@ -1,6 +1,7 @@ #include "openmc/tallies/filter_cell_instance.h" #include +#include #include "openmc/capi.h" #include "openmc/cell.h" @@ -52,6 +53,12 @@ CellInstanceFilter::set_cell_instances(gsl::span instances) for (auto& x : instances) { Expects(x.index_cell >= 0); Expects(x.index_cell < model::cells.size()); + const auto& c {model::cells[x.index_cell]}; + if (c->type_ != FILL_MATERIAL) { + throw std::invalid_argument{"Cell " + std::to_string(c->id_) + " is not " + "filled with a material. Only material cells can be used in a cell " + "instance filter."}; + } cell_instances_.push_back(x); map_[x] = cell_instances_.size() - 1; }