diff --git a/include/openmc/cell.h b/include/openmc/cell.h index cc4429b44..ee1230595 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -10,9 +10,7 @@ #include "hdf5.h" #include "pugixml.hpp" -#ifdef DAGMC -#include "DagMC.hpp" -#endif +#include "dagmc.h" #include "openmc/constants.h" #include "openmc/neighbor_list.h" diff --git a/include/openmc/dagmc.h b/include/openmc/dagmc.h index 508b617d1..d3012e3a0 100644 --- a/include/openmc/dagmc.h +++ b/include/openmc/dagmc.h @@ -9,11 +9,19 @@ extern "C" const bool dagmc_enabled; #ifdef DAGMC #include "DagMC.hpp" -#include "openmc/cell.h" -#include "openmc/surface.h" +#include "openmc/xml_interface.h" +#include "openmc/position.h" namespace openmc { +namespace simulation { + +extern moab::DagMC::RayHistory history; //!< facet history for DagMC particles +extern Direction last_dir; //!< last direction passed to DagMC's ray_fire +#pragma omp threadprivate(history, last_dir) + +} + namespace model { extern moab::DagMC* DAG; } diff --git a/include/openmc/surface.h b/include/openmc/surface.h index 4db397a59..7b0ccefd1 100644 --- a/include/openmc/surface.h +++ b/include/openmc/surface.h @@ -12,10 +12,7 @@ #include "openmc/constants.h" #include "openmc/position.h" - -#ifdef DAGMC -#include "DagMC.hpp" -#endif +#include "dagmc.h" namespace openmc { @@ -82,7 +79,7 @@ public: //! \param[in] r The point at which the ray is incident. //! \param[in] u Incident direction of the ray //! \return Outgoing direction of the ray - Direction reflect(Position r, Direction u) const; + virtual Direction reflect(Position r, Direction u) const; //! Evaluate the equation describing the surface. //! @@ -136,6 +133,7 @@ public: double evaluate(Position r) const; double distance(Position r, Direction u, bool coincident) const; Direction normal(Position r) const; + Direction reflect(Position r, Direction u) const; //! Get the bounding box of this surface. BoundingBox bounding_box() const; diff --git a/src/cell.cpp b/src/cell.cpp index a60f20fbe..bf6703631 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1,3 +1,4 @@ + #include "openmc/cell.h" #include @@ -8,6 +9,7 @@ #include "openmc/capi.h" #include "openmc/constants.h" +#include "openmc/dagmc.h" #include "openmc/error.h" #include "openmc/geometry.h" #include "openmc/hdf5_interface.h" @@ -614,19 +616,28 @@ DAGCell::DAGCell() : Cell{} {}; std::pair DAGCell::distance(Position r, Direction u, int32_t on_surface) const { + // if we've changed direction or we're not on a surface, + // reset the history and update last direction + if (u != simulation::last_dir || on_surface == 0) { + simulation::history.reset(); + simulation::last_dir = u; + } + moab::ErrorCode rval; moab::EntityHandle vol = dagmc_ptr_->entity_by_index(3, dag_index_); moab::EntityHandle hit_surf; double dist; double pnt[3] = {r.x, r.y, r.z}; double dir[3] = {u.x, u.y, u.z}; - rval = dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist); + rval = dagmc_ptr_->ray_fire(vol, pnt, dir, hit_surf, dist, &simulation::history); MB_CHK_ERR_CONT(rval); int surf_idx; if (hit_surf != 0) { surf_idx = dagmc_ptr_->index_by_handle(hit_surf); - } else { // indicate that particle is lost + } else { + // indicate that particle is lost surf_idx = -1; + dist = INFINITY; } return {dist, surf_idx}; diff --git a/src/dagmc.cpp b/src/dagmc.cpp index 8add1f4f3..78d8bc4fb 100644 --- a/src/dagmc.cpp +++ b/src/dagmc.cpp @@ -9,6 +9,7 @@ #include "openmc/material.h" #include "openmc/string_utils.h" #include "openmc/settings.h" +#include "openmc/surface.h" #ifdef DAGMC @@ -38,6 +39,14 @@ const std::string DAGMC_FILENAME = "dagmc.h5m"; namespace openmc { + +namespace simulation { + +moab::DagMC::RayHistory history; +Direction last_dir; + +} + namespace model { moab::DagMC* DAG; diff --git a/src/particle.cpp b/src/particle.cpp index cbc6217ca..afcc56317 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -372,6 +372,10 @@ Particle::transport() } } + #ifdef DAGMC + if (settings::dagmc) simulation::history.reset(); + #endif + // Finish particle track output. if (write_track_) { write_particle_track(*this); @@ -460,12 +464,14 @@ Particle::cross_surface() // If a reflective surface is coincident with a lattice or universe // boundary, it is necessary to redetermine the particle's coordinates in // the lower universes. - - n_coord_ = 1; - if (!find_cell(this, true)) { - this->mark_as_lost("Couldn't find particle after reflecting from surface " - + std::to_string(surf->id_) + "."); - return; + // (unless we're using a dagmc model, which has exactly one universe) + if (!settings::dagmc) { + n_coord_ = 1; + if (!find_cell(this, true)) { + this->mark_as_lost("Couldn't find particle after reflecting from surface " + + std::to_string(surf->id_) + "."); + return; + } } // Set previous coordinate going slightly past surface crossing diff --git a/src/surface.cpp b/src/surface.cpp index f329fda6d..f364694a0 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -6,6 +6,7 @@ #include #include "openmc/error.h" +#include "openmc/dagmc.h" #include "openmc/hdf5_interface.h" #include "openmc/settings.h" #include "openmc/string_utils.h" @@ -255,13 +256,19 @@ DAGSurface::distance(Position r, Direction u, bool coincident) const Direction DAGSurface::normal(Position r) const { moab::ErrorCode rval; - Direction u; moab::EntityHandle surf = dagmc_ptr_->entity_by_index(2, dag_index_); double pnt[3] = {r.x, r.y, r.z}; - double dir[3] = {u.x, u.y, u.z}; + double dir[3]; rval = dagmc_ptr_->get_angle(surf, pnt, dir); MB_CHK_ERR_CONT(rval); - return u; + return dir; +} + +Direction DAGSurface::reflect(Position r, Direction u) const +{ + simulation::history.reset_to_last_intersection(); + simulation::last_dir = Surface::reflect(r, u); + return simulation::last_dir; } BoundingBox DAGSurface::bounding_box() const diff --git a/tests/regression_tests/uwuw/__init__.py b/tests/regression_tests/dagmc/legacy/__init__.py similarity index 100% rename from tests/regression_tests/uwuw/__init__.py rename to tests/regression_tests/dagmc/legacy/__init__.py diff --git a/tests/regression_tests/dagmc/dagmc.h5m b/tests/regression_tests/dagmc/legacy/dagmc.h5m similarity index 100% rename from tests/regression_tests/dagmc/dagmc.h5m rename to tests/regression_tests/dagmc/legacy/dagmc.h5m diff --git a/tests/regression_tests/dagmc/inputs_true.dat b/tests/regression_tests/dagmc/legacy/inputs_true.dat similarity index 100% rename from tests/regression_tests/dagmc/inputs_true.dat rename to tests/regression_tests/dagmc/legacy/inputs_true.dat diff --git a/tests/regression_tests/dagmc/results_true.dat b/tests/regression_tests/dagmc/legacy/results_true.dat similarity index 100% rename from tests/regression_tests/dagmc/results_true.dat rename to tests/regression_tests/dagmc/legacy/results_true.dat diff --git a/tests/regression_tests/dagmc/test.py b/tests/regression_tests/dagmc/legacy/test.py similarity index 100% rename from tests/regression_tests/dagmc/test.py rename to tests/regression_tests/dagmc/legacy/test.py diff --git a/tests/regression_tests/dagmc/refl/__init__.py b/tests/regression_tests/dagmc/refl/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/regression_tests/dagmc/refl/dagmc.h5m b/tests/regression_tests/dagmc/refl/dagmc.h5m new file mode 100644 index 000000000..ac788d2de Binary files /dev/null and b/tests/regression_tests/dagmc/refl/dagmc.h5m differ diff --git a/tests/regression_tests/uwuw/inputs_true.dat b/tests/regression_tests/dagmc/refl/inputs_true.dat similarity index 100% rename from tests/regression_tests/uwuw/inputs_true.dat rename to tests/regression_tests/dagmc/refl/inputs_true.dat diff --git a/tests/regression_tests/dagmc/refl/results_true.dat b/tests/regression_tests/dagmc/refl/results_true.dat new file mode 100644 index 000000000..ed67e2f93 --- /dev/null +++ b/tests/regression_tests/dagmc/refl/results_true.dat @@ -0,0 +1,5 @@ +k-combined: +2.053871E+00 7.718195E-03 +tally 1: +1.171003E+01 +2.864565E+01 diff --git a/tests/regression_tests/dagmc/refl/test.py b/tests/regression_tests/dagmc/refl/test.py new file mode 100644 index 000000000..93104f1d0 --- /dev/null +++ b/tests/regression_tests/dagmc/refl/test.py @@ -0,0 +1,40 @@ +import openmc +import openmc.capi +from openmc.stats import Box + +import pytest +from tests.testing_harness import PyAPITestHarness + +pytestmark = pytest.mark.skipif( + not openmc.capi._dagmc_enabled(), + reason="DAGMC CAD geometry is not enabled.") + +class UWUWTest(PyAPITestHarness): + + def _build_inputs(self): + model = openmc.model.Model() + + # settings + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 100 + + source = openmc.Source(space=Box([-4, -4, -4], + [ 4, 4, 4])) + model.settings.source = source + + model.settings.dagmc = True + + model.settings.export_to_xml() + + # tally + tally = openmc.Tally() + tally.scores = ['total'] + tally.filters = [openmc.CellFilter(1)] + model.tallies = [tally] + + model.tallies.export_to_xml() + +def test_refl(): + harness = UWUWTest('statepoint.5.h5') + harness.main() diff --git a/tests/regression_tests/dagmc/uwuw/__init__.py b/tests/regression_tests/dagmc/uwuw/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/regression_tests/uwuw/dagmc.h5m b/tests/regression_tests/dagmc/uwuw/dagmc.h5m similarity index 100% rename from tests/regression_tests/uwuw/dagmc.h5m rename to tests/regression_tests/dagmc/uwuw/dagmc.h5m diff --git a/tests/regression_tests/dagmc/uwuw/inputs_true.dat b/tests/regression_tests/dagmc/uwuw/inputs_true.dat new file mode 100644 index 000000000..87ceb944d --- /dev/null +++ b/tests/regression_tests/dagmc/uwuw/inputs_true.dat @@ -0,0 +1,23 @@ + + + eigenvalue + 100 + 5 + 0 + + + -4 -4 -4 4 4 4 + + + true + + + + + 1 + + + 1 + total + + diff --git a/tests/regression_tests/dagmc/uwuw/results_true.dat b/tests/regression_tests/dagmc/uwuw/results_true.dat new file mode 120000 index 000000000..f09f75fa5 --- /dev/null +++ b/tests/regression_tests/dagmc/uwuw/results_true.dat @@ -0,0 +1 @@ +../legacy/results_true.dat \ No newline at end of file diff --git a/tests/regression_tests/uwuw/test.py b/tests/regression_tests/dagmc/uwuw/test.py similarity index 96% rename from tests/regression_tests/uwuw/test.py rename to tests/regression_tests/dagmc/uwuw/test.py index f6713c2e4..885b83766 100644 --- a/tests/regression_tests/uwuw/test.py +++ b/tests/regression_tests/dagmc/uwuw/test.py @@ -1,7 +1,6 @@ import openmc import openmc.capi from openmc.stats import Box -from openmc.material import Materials import pytest from tests.testing_harness import PyAPITestHarness diff --git a/tests/regression_tests/uwuw/results_true.dat b/tests/regression_tests/uwuw/results_true.dat deleted file mode 120000 index 3711895ab..000000000 --- a/tests/regression_tests/uwuw/results_true.dat +++ /dev/null @@ -1 +0,0 @@ -../dagmc/results_true.dat \ No newline at end of file