mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 05:35:49 -04:00
Provide Tally writable_ setter and getters
New member functions openmc::Tally.set_writable and get_writable act on the writable attribute. These are used in the external API with openmc_tally_set_writable and openmc_tally_get_writable functions. Cleaned up some other writeable -> writable typos as well
This commit is contained in:
parent
7a1a424d0f
commit
801f18b357
5 changed files with 20 additions and 18 deletions
|
|
@ -37,6 +37,8 @@ public:
|
|||
|
||||
void set_active(bool active) { active_ = active; }
|
||||
|
||||
void set_writable(bool writable) { writable_ = writable; }
|
||||
|
||||
void set_scores(pugi::xml_node node);
|
||||
|
||||
void set_scores(const std::vector<std::string>& scores);
|
||||
|
|
@ -55,6 +57,8 @@ public:
|
|||
|
||||
int32_t n_filter_bins() const {return n_filter_bins_;}
|
||||
|
||||
bool get_writable() const { return writable_;}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Other methods.
|
||||
|
||||
|
|
|
|||
|
|
@ -643,7 +643,7 @@ write_tallies()
|
|||
if (!tally.name_.empty()) tally_header += ": " + tally.name_;
|
||||
tallies_out << header(tally_header) << "\n\n";
|
||||
|
||||
if (!tally.writeable_) {
|
||||
if (!tally.writable_) {
|
||||
tallies_out << " Internal\n\n";
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ openmc_statepoint_write(const char* filename, bool* write_source)
|
|||
|
||||
write_dataset(tally_group, "name", tally->name_);
|
||||
|
||||
if (tally->writeable_) {
|
||||
if (tally->writable_) {
|
||||
write_attribute(tally_group, "internal", 0);
|
||||
} else {
|
||||
write_attribute(tally_group, "internal", 1);
|
||||
|
|
@ -239,7 +239,7 @@ openmc_statepoint_write(const char* filename, bool* write_source)
|
|||
|
||||
// Write all tally results
|
||||
for (const auto& tally : model::tallies) {
|
||||
if (!tally->writeable_) continue;
|
||||
if (!tally->writable_) continue;
|
||||
// Write sum and sum_sq for each bin
|
||||
std::string name = "tally " + std::to_string(tally->id_);
|
||||
hid_t tally_group = open_group(tallies_group, name.c_str());
|
||||
|
|
@ -434,14 +434,12 @@ void load_state_point()
|
|||
std::string name = "tally " + std::to_string(tally->id_);
|
||||
hid_t tally_group = open_group(tallies_group, name.c_str());
|
||||
|
||||
int internal;
|
||||
int internal=0;
|
||||
if (attribute_exists(tally_group, "internal")) {
|
||||
read_attribute(tally_group, "internal", internal);
|
||||
} else {
|
||||
internal = 0;
|
||||
}
|
||||
if (internal) {
|
||||
tally->writeable_ = false;
|
||||
tally->writable_ = false;
|
||||
} else {
|
||||
|
||||
auto& results = tally->results_;
|
||||
|
|
@ -717,7 +715,7 @@ void write_tally_results_nr(hid_t file_id)
|
|||
for (const auto& t : model::tallies) {
|
||||
// Skip any tallies that are not active
|
||||
if (!t->active_) continue;
|
||||
if (!t->writeable_) continue;
|
||||
if (!t->writable_) continue;
|
||||
|
||||
if (mpi::master && !object_exists(file_id, "tallies_present")) {
|
||||
write_attribute(file_id, "tallies_present", 1);
|
||||
|
|
|
|||
|
|
@ -1221,25 +1221,25 @@ openmc_tally_set_active(int32_t index, bool active)
|
|||
}
|
||||
|
||||
extern "C" int
|
||||
openmc_tally_get_writeable(int32_t index, bool* writeable)
|
||||
openmc_tally_get_writable(int32_t index, bool* writable)
|
||||
{
|
||||
if (index < 0 || index >= model::tallies.size()) {
|
||||
set_errmsg("Index in tallies array is out of bounds.");
|
||||
return OPENMC_E_OUT_OF_BOUNDS;
|
||||
}
|
||||
*writeable = model::tallies[index]->writeable_;
|
||||
*writable = model::tallies[index]->get_writable();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int
|
||||
openmc_tally_set_writeable(int32_t index, bool writeable)
|
||||
openmc_tally_set_writable(int32_t index, bool writable)
|
||||
{
|
||||
if (index < 0 || index >= model::tallies.size()) {
|
||||
set_errmsg("Index in tallies array is out of bounds.");
|
||||
return OPENMC_E_OUT_OF_BOUNDS;
|
||||
}
|
||||
model::tallies[index]->writeable_ = writeable;
|
||||
model::tallies[index]->set_writable(writable);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -256,13 +256,13 @@ def test_tally_activate(lib_simulation_init):
|
|||
assert t.active
|
||||
|
||||
|
||||
def test_tally_writeable(lib_simulation_init):
|
||||
def test_tally_writable(lib_simulation_init):
|
||||
t = openmc.lib.tallies[1]
|
||||
assert t.writeable
|
||||
t.writeable = False
|
||||
assert not t.writeable
|
||||
# Revert tally to writeable state for lib_run fixtures
|
||||
t.writeable = True
|
||||
assert t.writable
|
||||
t.writable = False
|
||||
assert not t.writable
|
||||
# Revert tally to writable state for lib_run fixtures
|
||||
t.writable = True
|
||||
|
||||
|
||||
def test_tally_results(lib_run):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue