Simple rejection based on a vector of cell IDs

This commit is contained in:
Paul Romano 2022-08-05 11:39:48 -05:00
parent 1d140e348d
commit aff6316642
3 changed files with 65 additions and 15 deletions

View file

@ -16,8 +16,10 @@
#include "openmc/bank.h"
#include "openmc/capi.h"
#include "openmc/cell.h"
#include "openmc/container_util.h"
#include "openmc/error.h"
#include "openmc/file_utils.h"
#include "openmc/geometry.h"
#include "openmc/hdf5_interface.h"
#include "openmc/material.h"
#include "openmc/memory.h"
@ -151,29 +153,36 @@ IndependentSource::IndependentSource(pugi::xml_node node)
double p[] {1.0};
time_ = UPtrDist {new Discrete {T, p, 1}};
}
// Check for cells to reject from
if (check_for_node(node, "cells")) {
auto cells = get_node_array<int>(node, "cells");
cells_.insert(cells.cbegin(), cells.cend());
}
}
}
SourceSite IndependentSource::sample(uint64_t* seed) const
{
SourceSite site;
site.particle = particle_;
// Repeat sampling source location until a good site has been found
bool found = false;
int n_reject = 0;
static int n_accept = 0;
while (!found) {
// Set particle type
site.particle = particle_;
Particle p;
p.type() = particle_;
p.u() = {0.0, 0.0, 1.0};
// Sample spatial distribution
site.r = space_->sample(seed);
p.r() = space_->sample(seed);
// Now search to see if location exists in geometry
int32_t cell_index, instance;
double xyz[] {site.r.x, site.r.y, site.r.z};
int err = openmc_find_cell(xyz, &cell_index, &instance);
found = (err != OPENMC_E_GEOMETRY);
found = exhaustive_find_cell(p);
// Check if spatial site is in fissionable material
if (found) {
@ -181,15 +190,22 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
if (space_box) {
if (space_box->only_fissionable()) {
// Determine material
const auto& c = model::cells[cell_index];
auto mat_index =
c->material_.size() == 1 ? c->material_[0] : c->material_[instance];
auto mat_index = p.material();
if (mat_index == MATERIAL_VOID) {
found = false;
} else {
if (!model::materials[mat_index]->fissionable_)
found = false;
found = model::materials[mat_index]->fissionable_;
}
}
}
// Rejection based on cells
if (!cells_.empty()) {
found = false;
for (const auto& coord : p.coord()) {
if (contains(cells_, model::cells[coord.cell]->id_)) {
found = true;
break;
}
}
}
@ -205,6 +221,8 @@ SourceSite IndependentSource::sample(uint64_t* seed) const
"definition.");
}
}
site.r = p.r();
}
// Sample angle