1+ #include < string>
2+ #include < vector>
3+
4+ #include < catch2/catch_test_macros.hpp>
5+ #include < pugixml.hpp>
6+
7+ #include " openmc/settings.h"
8+
9+ auto ssw_cells_from_xml (std::string xml_string) {
10+
11+ // Create a pugixml document object
12+ pugi::xml_document doc;
13+
14+ // Load the XML from the string
15+ pugi::xml_parse_result result = doc.load_string (xml_string.c_str ());
16+
17+ pugi::xml_node root = doc.child (" settings" );
18+
19+ // Read the surface source settings
20+ openmc::read_settings_xml (root);
21+
22+ // Get the cell direction map
23+ auto ssw_cells = openmc::settings::ssw_cells;
24+
25+ // Finalize to allow more tests
26+ openmc::free_memory_settings ();
27+ openmc::settings::n_particles = -1 ;
28+ openmc::settings::run_mode = openmc::RunMode::UNSET;
29+
30+ return ssw_cells;
31+ }
32+
33+ TEST_CASE (" Test duplicate cells in surface source write" )
34+ {
35+ std::vector<std::string> xml_strings = {
36+ R"(
37+ <settings>
38+ <run_mode>fixed source</run_mode>
39+ <particles>60</particles>
40+ <batches>1</batches>
41+ <surf_source_write>
42+ <surface_ids>1</surface_ids>
43+ <max_particles>300</max_particles>
44+ <cells>1 1</cells>
45+ <directions>to to</directions>
46+ </surf_source_write>
47+ </settings>
48+ )" ,
49+ R"(
50+ <settings>
51+ <run_mode>fixed source</run_mode>
52+ <particles>60</particles>
53+ <batches>1</batches>
54+ <surf_source_write>
55+ <surface_ids>1</surface_ids>
56+ <max_particles>300</max_particles>
57+ <cells>1 1</cells>
58+ <directions>to from</directions>
59+ </surf_source_write>
60+ </settings>
61+ )" ,
62+ R"(
63+ <settings>
64+ <run_mode>fixed source</run_mode>
65+ <particles>60</particles>
66+ <batches>1</batches>
67+ <surf_source_write>
68+ <surface_ids>1</surface_ids>
69+ <max_particles>300</max_particles>
70+ <cells>1 1</cells>
71+ <directions>to both</directions>
72+ </surf_source_write>
73+ </settings>
74+ )" ,
75+ R"(
76+ <settings>
77+ <run_mode>fixed source</run_mode>
78+ <particles>60</particles>
79+ <batches>1</batches>
80+ <surf_source_write>
81+ <surface_ids>1</surface_ids>
82+ <max_particles>300</max_particles>
83+ <cells>1 1</cells>
84+ <directions>both to</directions>
85+ </surf_source_write>
86+ </settings>
87+ )"
88+ };
89+
90+ auto ssw_cells = ssw_cells_from_xml (xml_strings[0 ]);
91+ REQUIRE (ssw_cells.size () == 1 );
92+ REQUIRE (ssw_cells.at (1 ) == openmc::SSWCellType::To);
93+
94+ ssw_cells = ssw_cells_from_xml (xml_strings[1 ]);
95+ REQUIRE (ssw_cells.size () == 1 );
96+ REQUIRE (ssw_cells.at (1 ) == openmc::SSWCellType::Both);
97+
98+ ssw_cells = ssw_cells_from_xml (xml_strings[2 ]);
99+ REQUIRE (ssw_cells.size () == 1 );
100+ REQUIRE (ssw_cells.at (1 ) == openmc::SSWCellType::Both);
101+
102+ ssw_cells = ssw_cells_from_xml (xml_strings[3 ]);
103+ REQUIRE (ssw_cells.size () == 1 );
104+ REQUIRE (ssw_cells.at (1 ) == openmc::SSWCellType::Both);
105+ }
0 commit comments