-
Notifications
You must be signed in to change notification settings - Fork 654
Expand file tree
/
Copy pathtest_mcpl_stat_sum.cpp
More file actions
108 lines (87 loc) · 3.17 KB
/
Copy pathtest_mcpl_stat_sum.cpp
File metadata and controls
108 lines (87 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <catch2/catch_test_macros.hpp>
#include <cstdio>
#include <string>
#include <vector>
#include "openmc/bank.h"
#include "openmc/mcpl_interface.h"
// Test the MCPL stat:sum functionality (issue #3514)
TEST_CASE("MCPL stat:sum field")
{
// Check if MCPL interface is available
if (!openmc::is_mcpl_interface_available()) {
SKIP("MCPL library not available");
}
SECTION("stat:sum field is written to MCPL files")
{
// Create a temporary filename
std::string filename = "test_stat_sum.mcpl";
// Create some test particles
std::vector<openmc::SourceSite> source_bank(100);
std::vector<int64_t> bank_index = {0, 100}; // 100 particles total
// Initialize test particles
for (int i = 0; i < 100; ++i) {
source_bank[i].particle = openmc::ParticleType::neutron();
source_bank[i].r = {i * 0.1, i * 0.2, i * 0.3};
source_bank[i].u = {0.0, 0.0, 1.0};
source_bank[i].E = 2.0e6; // 2 MeV
source_bank[i].time = 0.0;
source_bank[i].wgt = 1.0;
}
// Write the MCPL file
openmc::write_mcpl_source_point(filename.c_str(), source_bank, bank_index);
// Verify the file was created
FILE* f = std::fopen(filename.c_str(), "r");
REQUIRE(f != nullptr);
std::fclose(f);
// Read the file back to check stat:sum
// Note: This would require mcpl_open_file and checking the header
// Since we can't easily read MCPL headers in C++ without the full MCPL API,
// we rely on the Python test to verify the actual content
// Clean up
std::remove(filename.c_str());
}
SECTION("stat:sum uses correct particle count")
{
std::string filename = "test_count.mcpl";
// Test with different particle counts
std::vector<int> test_counts = {1, 10, 100, 1000};
for (int count : test_counts) {
std::vector<openmc::SourceSite> source_bank(count);
std::vector<int64_t> bank_index = {0, count};
// Initialize particles
for (int i = 0; i < count; ++i) {
source_bank[i].particle = openmc::ParticleType::neutron();
source_bank[i].r = {0.0, 0.0, 0.0};
source_bank[i].u = {0.0, 0.0, 1.0};
source_bank[i].E = 1.0e6;
source_bank[i].time = 0.0;
source_bank[i].wgt = 1.0;
}
// Write MCPL file
openmc::write_mcpl_source_point(
filename.c_str(), source_bank, bank_index);
// The stat:sum should equal count (verified by Python test)
// Here we just verify the file was created successfully
FILE* f = std::fopen(filename.c_str(), "r");
REQUIRE(f != nullptr);
std::fclose(f);
// Clean up
std::remove(filename.c_str());
}
}
SECTION("stat:sum handles empty particle bank")
{
std::string filename = "test_empty.mcpl";
// Create empty particle bank
std::vector<openmc::SourceSite> source_bank;
std::vector<int64_t> bank_index = {0};
// This should still create a valid MCPL file with stat:sum = 0
openmc::write_mcpl_source_point(filename.c_str(), source_bank, bank_index);
// Verify file was created
FILE* f = std::fopen(filename.c_str(), "r");
REQUIRE(f != nullptr);
std::fclose(f);
// Clean up
std::remove(filename.c_str());
}
}