Repository navigation
Expand file tree
/
Copy pathtest_geometry.cpp
More file actions
127 lines (109 loc) · 3.64 KB
/
Copy pathtest_geometry.cpp
File metadata and controls
127 lines (109 loc) · 3.64 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <catch2/catch_test_macros.hpp>
#include "openmc/cell.h"
#include "openmc/geometry.h"
#include "openmc/particle_data.h"
#include "openmc/surface.h"
#include "openmc/universe.h"
#include <memory>
#include <string>
#include <pugixml.hpp>
namespace {
class GeometryFixture {
public:
GeometryFixture()
: root_universe_ {openmc::model::root_universe},
n_coord_levels_ {openmc::model::n_coord_levels}
{
openmc::model::cells.clear();
openmc::model::cell_map.clear();
openmc::model::universes.clear();
openmc::model::universe_map.clear();
openmc::model::surfaces.clear();
openmc::model::surface_map.clear();
openmc::model::n_coord_levels = 2;
openmc::model::root_universe = 0;
pugi::xml_document surface_doc;
auto surface_node = surface_doc.append_child("surface");
surface_node.append_attribute("id") = 1;
surface_node.append_attribute("type") = "sphere";
surface_node.append_attribute("coeffs") = "0 0 0 1";
openmc::model::surfaces.push_back(
std::make_unique<openmc::SurfaceSphere>(surface_node));
openmc::model::surface_map[1] = 0;
openmc::model::cells.push_back(make_cell(1, 0, 1, ""));
openmc::model::cells.push_back(make_cell(2, 1, -1, "-1"));
openmc::model::cells.push_back(make_cell(3, 1, -1, "+1"));
for (int i = 0; i < openmc::model::cells.size(); ++i)
openmc::model::cell_map[openmc::model::cells[i]->id_] = i;
auto root = std::make_unique<openmc::Universe>();
root->id_ = 0;
root->cells_ = {0};
root->n_instances_ = 1;
openmc::model::universes.push_back(std::move(root));
openmc::model::universe_map[0] = 0;
auto nested = std::make_unique<openmc::Universe>();
nested->id_ = 1;
nested->cells_ = {1, 2};
nested->n_instances_ = 1;
openmc::model::universes.push_back(std::move(nested));
openmc::model::universe_map[1] = 1;
}
~GeometryFixture()
{
openmc::model::cells.clear();
openmc::model::cell_map.clear();
openmc::model::universes.clear();
openmc::model::universe_map.clear();
openmc::model::surfaces.clear();
openmc::model::surface_map.clear();
openmc::model::root_universe = root_universe_;
openmc::model::n_coord_levels = n_coord_levels_;
}
private:
static std::unique_ptr<openmc::CSGCell> make_cell(
int id, int universe, int fill, const char* region)
{
pugi::xml_document doc;
auto node = doc.append_child("cell");
node.append_attribute("id") = id;
node.append_attribute("universe") = universe;
if (fill >= 0) {
const auto fill_value {std::to_string(fill)};
node.append_child("fill").text() = fill_value.c_str();
} else {
node.append_child("material").text() = "void";
}
if (region[0] != '\0')
node.append_child("region").text() = region;
auto cell = std::make_unique<openmc::CSGCell>(node);
if (fill < 0) {
cell->type_ = openmc::Fill::MATERIAL;
cell->sqrtkT_.push_back(0.0);
cell->density_mult_.push_back(1.0);
} else {
cell->type_ = openmc::Fill::UNIVERSE;
}
return cell;
}
int root_universe_;
int n_coord_levels_;
};
} // namespace
TEST_CASE("Reconcile a particle after a collision near a surface")
{
GeometryFixture fixture;
openmc::GeometryState p;
p.n_coord() = 2;
p.coord(0).universe() = 0;
p.coord(0).cell() = 0;
p.coord(0).r() = {0.0, 0.0, 0.0};
p.coord(0).u() = {-1.0, 0.0, 0.0};
p.coord(1).universe() = 1;
p.coord(1).cell() = 2;
p.coord(1).r() = {1.0 - 1.0e-13, 0.0, 0.0};
p.coord(1).u() = {-1.0, 0.0, 0.0};
openmc::reconcile_cell_after_collision(p);
REQUIRE(p.n_coord() == 2);
REQUIRE(p.coord(0).cell() == 0);
REQUIRE(p.coord(1).cell() == 1);
}