From 114a1062eadd851f0a0a16586ead5b3217e0e3a7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Mar 2021 23:23:06 -0500 Subject: [PATCH 1/3] Adding a test for adjacent rotated and unrotated cells. --- .../adj_cell_rotation/__init__.py | 0 .../adj_cell_rotation/inputs_true.dat | 38 ++++++++++++++ .../adj_cell_rotation/results_true.dat | 2 + .../adj_cell_rotation/test.py | 50 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 tests/regression_tests/adj_cell_rotation/__init__.py create mode 100644 tests/regression_tests/adj_cell_rotation/inputs_true.dat create mode 100644 tests/regression_tests/adj_cell_rotation/results_true.dat create mode 100644 tests/regression_tests/adj_cell_rotation/test.py diff --git a/tests/regression_tests/adj_cell_rotation/__init__.py b/tests/regression_tests/adj_cell_rotation/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regression_tests/adj_cell_rotation/inputs_true.dat b/tests/regression_tests/adj_cell_rotation/inputs_true.dat new file mode 100644 index 0000000000..24b00199be --- /dev/null +++ b/tests/regression_tests/adj_cell_rotation/inputs_true.dat @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 10000 + 10 + 5 + + + -4.0 -4.0 -4.0 4.0 4.0 4.0 + + + diff --git a/tests/regression_tests/adj_cell_rotation/results_true.dat b/tests/regression_tests/adj_cell_rotation/results_true.dat new file mode 100644 index 0000000000..a58aa1c8ec --- /dev/null +++ b/tests/regression_tests/adj_cell_rotation/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +4.453328E-01 5.918369E-03 diff --git a/tests/regression_tests/adj_cell_rotation/test.py b/tests/regression_tests/adj_cell_rotation/test.py new file mode 100644 index 0000000000..25aada5aad --- /dev/null +++ b/tests/regression_tests/adj_cell_rotation/test.py @@ -0,0 +1,50 @@ +import pytest +import openmc + +from tests.testing_harness import PyAPITestHarness + + +@pytest.fixture +def model(): + model = openmc.model.Model() + + fuel = openmc.Material() + fuel.set_density('g/cc', 10.0) + fuel.add_nuclide('U235', 1.0) + + h1 = openmc.Material() + h1.set_density('g/cc', 0.1) + h1.add_nuclide('H1', 0.1) + + inner_sphere = openmc.Sphere(x0=1.0, r=5.0) + + fuel_cell = openmc.Cell(fill=fuel, region=-inner_sphere) + hydrogen_cell = openmc.Cell(fill=h1, region=+inner_sphere) + univ = openmc.Universe(cells=[fuel_cell, hydrogen_cell]) + + # Create one cell on top of the other. Only one + # has a rotation + box = openmc.rectangular_prism(15., 15., 'z', boundary_type='vacuum') + lower_z = openmc.ZPlane(-7.5, boundary_type='vacuum') + upper_z = openmc.ZPlane(22.5, boundary_type='vacuum') + middle_z = openmc.ZPlane(7.5) + + lower_cell = openmc.Cell(fill=univ, region=box & +lower_z & -middle_z) + lower_cell.rotation = (10, 20, 30) + upper_cell = openmc.Cell(fill=univ, region=box & +middle_z & -upper_z) + upper_cell.translation = (0, 0, 15) + + model.geometry = openmc.Geometry(root=[lower_cell, upper_cell]) + + model.settings.particles = 10000 + model.settings.inactive = 5 + model.settings.batches = 10 + source_box = openmc.stats.Box((-4., -4., -4.), (4., 4., 4.)) + model.settings.source = openmc.Source(space=source_box) + + return model + + +def test_rotation(model): + harness = PyAPITestHarness('statepoint.10.h5', model) + harness.main() From 66e7e998af4f37b70b48f6dbf6526724adfbd76e Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Mar 2021 23:31:12 -0500 Subject: [PATCH 2/3] Always call LocalCoord::rotate and set LocalCoord::rotated. --- src/geometry.cpp | 4 +--- src/particle.cpp | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/geometry.cpp b/src/geometry.cpp index 8e6519fa86..9d612412b5 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -188,9 +188,7 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) coord.r -= c.translation_; // Apply rotation. - if (!c.rotation_.empty()) { - coord.rotate(c.rotation_); - } + coord.rotate(c.rotation_); } else if (c.type_ == Fill::LATTICE) { //======================================================================== diff --git a/src/particle.cpp b/src/particle.cpp index 2e24131742..d05b81d848 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -38,6 +38,10 @@ namespace openmc { void LocalCoord::rotate(const std::vector& rotation) { + if (rotation.empty()) { + this->rotated = false; + return; + } this->r = this->r.rotate(rotation); this->u = this->u.rotate(rotation); this->rotated = true; From a8ce1445859c8be4ff794648693b3f966e7848fd Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 31 Mar 2021 23:38:25 -0500 Subject: [PATCH 3/3] Resetting coordinates at lower levels in neighbor_list_find_cell. --- src/geometry.cpp | 10 +++++++++- src/particle.cpp | 4 ---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/geometry.cpp b/src/geometry.cpp index 9d612412b5..06d35cacec 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -188,7 +188,9 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) coord.r -= c.translation_; // Apply rotation. - coord.rotate(c.rotation_); + if (!c.rotation_.empty()) { + coord.rotate(c.rotation_); + } } else if (c.type_ == Fill::LATTICE) { //======================================================================== @@ -245,6 +247,12 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list) bool neighbor_list_find_cell(Particle& p) { + + // Reset all the deeper coordinate levels. + for (int i = p.n_coord_; i < p.coord_.size(); i++) { + p.coord_[i].reset(); + } + // Get the cell this particle was in previously. auto coord_lvl = p.n_coord_ - 1; auto i_cell = p.coord_[coord_lvl].cell; diff --git a/src/particle.cpp b/src/particle.cpp index d05b81d848..2e24131742 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -38,10 +38,6 @@ namespace openmc { void LocalCoord::rotate(const std::vector& rotation) { - if (rotation.empty()) { - this->rotated = false; - return; - } this->r = this->r.rotate(rotation); this->u = this->u.rotate(rotation); this->rotated = true;