mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Reworking Tally::add_filter a bit (#2501)
This commit is contained in:
parent
dea5e46c3c
commit
0a950eb623
4 changed files with 75 additions and 12 deletions
55
tests/cpp_unit_tests/test_tally.cpp
Normal file
55
tests/cpp_unit_tests/test_tally.cpp
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#include "openmc/tallies/tally.h"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
using namespace openmc;
|
||||
|
||||
TEST_CASE("Test add/set_filter")
|
||||
{
|
||||
// create a new tally object
|
||||
Tally* tally = Tally::create();
|
||||
|
||||
// create a new particle filter
|
||||
Filter* particle_filter = Filter::create("particle");
|
||||
|
||||
// add the particle filter to the tally
|
||||
tally->add_filter(particle_filter);
|
||||
|
||||
// the filter should be added to the tally
|
||||
REQUIRE(tally->filters().size() == 1);
|
||||
REQUIRE(model::filter_map[particle_filter->id()] == tally->filters(0));
|
||||
|
||||
// add the particle filter to the tally again
|
||||
tally->add_filter(particle_filter);
|
||||
// the tally should have the same number of filters
|
||||
REQUIRE(tally->filters().size() == 1);
|
||||
|
||||
// create a cell filter
|
||||
Filter* cell_filter = Filter::create("cell");
|
||||
tally->add_filter(cell_filter);
|
||||
|
||||
// now the size of the filters should have increased
|
||||
REQUIRE(tally->filters().size() == 2);
|
||||
REQUIRE(model::filter_map[cell_filter->id()] == tally->filters(1));
|
||||
|
||||
// if we set the filters explicitly there shouldn't be extra filters hanging
|
||||
// around
|
||||
tally->set_filters({&cell_filter, 1});
|
||||
|
||||
REQUIRE(tally->filters().size() == 1);
|
||||
REQUIRE(model::filter_map[cell_filter->id()] == tally->filters(0));
|
||||
|
||||
// set filters again using both filters
|
||||
std::vector<Filter*> filters = {cell_filter, particle_filter};
|
||||
tally->set_filters(filters);
|
||||
|
||||
REQUIRE(tally->filters().size() == 2);
|
||||
REQUIRE(model::filter_map[cell_filter->id()] == tally->filters(0));
|
||||
REQUIRE(model::filter_map[particle_filter->id()] == tally->filters(1));
|
||||
|
||||
// set filters with a duplicate filter, should only add the filter to the tally once
|
||||
filters = {cell_filter, cell_filter};
|
||||
tally->set_filters(filters);
|
||||
REQUIRE(tally->filters().size() == 1);
|
||||
REQUIRE(model::filter_map[cell_filter->id()] == tally->filters(0));
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue