From f48f6c6ab8dd0ffd2fceb1200d9f3905e214f6fa Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 26 Oct 2020 15:50:51 -0500 Subject: [PATCH 01/23] Condensing filter translation into single commit. --- include/openmc/mesh.h | 61 +++++++++++++++++----- include/openmc/tallies/filter_mesh.h | 12 +++++ src/mesh.cpp | 78 +++++++++++++++------------- src/tallies/filter_mesh.cpp | 50 +++++++++++++++++- src/tallies/filter_meshsurface.cpp | 5 +- 5 files changed, 154 insertions(+), 52 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index e9519ca0a1..d2e3724972 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -71,18 +71,28 @@ public: //! Determine which bins were crossed by a particle // - //! \param[in] p Particle to check + //! \param[in] last_r Previous position of the particle + //! \param[in] r Current position of the particle + //! \param[in] u Particle direction //! \param[out] bins Bins that were crossed //! \param[out] lengths Fraction of tracklength in each bin - virtual void bins_crossed(const Particle& p, std::vector& bins, + virtual void bins_crossed(Position last_r, + Position r, + const Direction& u, + std::vector& bins, std::vector& lengths) const = 0; //! Determine which surface bins were crossed by a particle // - //! \param[in] p Particle to check + //! \param[in] r0 Previous position of the particle + //! \param[in] r1 Current position of the particle + //! \param[in] u Particle direction //! \param[out] bins Surface bins that were crossed virtual void - surface_bins_crossed(const Particle& p, std::vector& bins) const = 0; + surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const = 0; //! Get bin at a given position in space // @@ -137,7 +147,10 @@ public: int n_surface_bins() const override; - void bins_crossed(const Particle& p, std::vector& bins, + void bins_crossed(Position last_r, + Position r, + const Direction& u, + std::vector& bins, std::vector& lengths) const override; //! Count number of bank sites in each mesh bin / energy bin @@ -219,9 +232,11 @@ public: RegularMesh(pugi::xml_node node); // Overriden methods - - void surface_bins_crossed(const Particle& p, std::vector& bins) - const override; + void + surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const override; int get_index_in_direction(double r, int i) const override; @@ -259,9 +274,11 @@ public: RectilinearMesh(pugi::xml_node node); // Overriden methods - - void surface_bins_crossed(const Particle& p, std::vector& bins) - const override; + void + surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const override; int get_index_in_direction(double r, int i) const override; @@ -325,7 +342,7 @@ public: std::string bin_label(int bin) const override; void surface_bins_crossed(const Particle& p, - std::vector& bins) const override; + std::vector& bins) const; void to_hdf5(hid_t group) const override; @@ -348,10 +365,18 @@ public: MOABMesh(pugi::xml_node); MOABMesh(const std::string& filename); - void bins_crossed(const Particle& p, + void bins_crossed(Position last_r, + Position r, + const Direction& u, std::vector& bins, std::vector& lengths) const override; + void + surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const override; + int get_bin(Position r) const; int n_bins() const override; @@ -496,10 +521,18 @@ public: LibMesh(const std::string& filename); // Methods - void bins_crossed(const Particle& p, + void bins_crossed(Position last_r, + Position r, + const Direction& u, std::vector& bins, std::vector& lengths) const override; + void + surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const override; + int get_bin(Position r) const override; int n_bins() const override; diff --git a/include/openmc/tallies/filter_mesh.h b/include/openmc/tallies/filter_mesh.h index fa64877e36..8a712f4cb0 100644 --- a/include/openmc/tallies/filter_mesh.h +++ b/include/openmc/tallies/filter_mesh.h @@ -4,6 +4,7 @@ #include #include "openmc/tallies/filter.h" +#include "openmc/position.h" namespace openmc { @@ -42,11 +43,22 @@ public: virtual void set_mesh(int32_t mesh); + virtual void set_translation(const Position& translation); + + virtual void set_translation(const double translation[3]); + + virtual const Position& translation() const {return translation_;} + + virtual bool translated() const {return translated_;} + + protected: //---------------------------------------------------------------------------- // Data members int32_t mesh_; + bool translated_ {false}; + Position translation_ {0.0, 0.0, 0.0}; }; } // namespace openmc diff --git a/src/mesh.cpp b/src/mesh.cpp index 16ce630ae0..4274912f66 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -581,17 +581,15 @@ bool StructuredMesh::intersects_3d(Position& r0, Position r1, int* ijk) const return min_dist < INFTY; } -void StructuredMesh::bins_crossed(const Particle& p, std::vector& bins, - std::vector& lengths) const +void StructuredMesh::bins_crossed(Position last_r, + Position r, + const Direction& u, + std::vector& bins, + std::vector& lengths) const { // ======================================================================== // Determine where the track intersects the mesh and if it intersects at all. - // Copy the starting and ending coordinates of the particle. - Position last_r {p.r_last_}; - Position r {p.r()}; - Direction u {p.u()}; - // Compute the length of the entire track. double total_distance = (r - last_r).norm(); if (total_distance == 0.0) return; @@ -797,17 +795,12 @@ double RegularMesh::negative_grid_boundary(int* ijk, int i) const return lower_left_[i] + (ijk[i] - 1) * width_[i]; } -void RegularMesh::surface_bins_crossed(const Particle& p, - std::vector& bins) const +void +RegularMesh::surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const { - // ======================================================================== - // Determine if the track intersects the tally mesh. - - // Copy the starting and ending coordinates of the particle. - Position r0 {p.r_last_current_}; - Position r1 {p.r()}; - Direction u {p.u()}; - // Determine indices for starting and ending location. int n = n_dimension_; std::vector ijk0(n), ijk1(n); @@ -1107,17 +1100,11 @@ int RectilinearMesh::set_grid() return 0; } -void RectilinearMesh::surface_bins_crossed(const Particle& p, +void RectilinearMesh::surface_bins_crossed(Position r0, + Position r1, + const Direction& u, std::vector& bins) const { - // ======================================================================== - // Determine if the track intersects the tally mesh. - - // Copy the starting and ending coordinates of the particle. - Position r0 {p.r_last_current_}; - Position r1 {p.r()}; - Direction u {p.u()}; - // Determine indices for starting and ending location. int ijk0[3], ijk1[3]; bool start_in_mesh; @@ -1701,14 +1688,13 @@ MOABMesh::intersect_track(const moab::CartVect& start, } void -MOABMesh::bins_crossed(const Particle& p, - std::vector& bins, - std::vector& lengths) const +MOABUnstructuredMesh::bins_crossed(Position last_r, + Position r, + const Direction& u, + std::vector& bins, + std::vector& lengths) const { - Position last_r{p.r_last_}; - Position r{p.r()}; - Direction u{p.u()}; - u /= u.norm(); + // u /= u.norm(); moab::CartVect r0(last_r.x, last_r.y, last_r.z); moab::CartVect r1(r.x, r.y, r.z); moab::CartVect dir(u.x, u.y, u.z); @@ -1833,6 +1819,16 @@ double MOABMesh::tet_volume(moab::EntityHandle tet) const return 1.0 / 6.0 * (((p[1] - p[0]) * (p[2] - p[0])) % (p[3] - p[0])); } +void MOABUnstructuredMesh::surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const +{ + + // TODO: Implement triangle crossings here + throw std::runtime_error{"Unstructured mesh surface tallies are not implemented."}; +} + int MOABMesh::get_bin(Position r) const { moab::EntityHandle tet = get_tet(r); @@ -2212,8 +2208,18 @@ int LibMesh::n_bins() const return m_->n_elem(); } -int LibMesh::n_surface_bins() const +void +LibMesh::surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const { + // TODO: Implement triangle crossings here + throw std::runtime_error{"Unstructured mesh surface tallies are not implemented."}; +} + +int +LibMesh::n_surface_bins() const { int n_bins = 0; for (int i = 0; i < this->n_bins(); i++) { const libMesh::Elem& e = get_element_from_bin(i); @@ -2300,7 +2306,9 @@ void LibMesh::write(const std::string& filename) const } void -LibMesh::bins_crossed(const Particle& p, +LibMesh::bins_crossed(Position last_r, + Position r, + const Direction& u, std::vector& bins, std::vector& lengths) const { diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 7897173868..b85a08263e 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -34,14 +34,25 @@ void MeshFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { + + Position last_r = p.r_last_; + Position r = p.r(); + Position u = p.u(); + + // apply translation if present + if (translated_) { + last_r -= translation_; + r -= translation_; + } + if (estimator != TallyEstimator::TRACKLENGTH) { - auto bin = model::meshes[mesh_]->get_bin(p.r()); + auto bin = model::meshes[mesh_]->get_bin(r); if (bin >= 0) { match.bins_.push_back(bin); match.weights_.push_back(1.0); } } else { - model::meshes[mesh_]->bins_crossed(p, match.bins_, match.weights_); + model::meshes[mesh_]->bins_crossed(last_r, r, u, match.bins_, match.weights_); } } @@ -66,6 +77,18 @@ MeshFilter::set_mesh(int32_t mesh) n_bins_ = model::meshes[mesh_]->n_bins(); } +void MeshFilter::set_translation(const Position& translation) +{ + translated_ = true; + translation_ = translation; +} + +void MeshFilter::set_translation(const double translation[3]) +{ + translated_ = true; + translation_ = translation; +} + //============================================================================== // C-API functions //============================================================================== @@ -123,4 +146,27 @@ openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh) return 0; } +extern "C" int +openmc_mesh_filter_set_translation(int32_t index, double translation[3]) +{ + // Make sure this is a valid index to an allocated filter + if (int err = verify_filter(index)) return err; + + // Get a pointer to the filter and downcast. + const auto& filt_base = model::tally_filters[index].get(); + auto* filt = dynamic_cast(filt_base); + + // Check the filter type + if (!filt) { + set_errmsg("Tried to set mesh on a non-mesh filter."); + return OPENMC_E_INVALID_TYPE; + } + + // Set the translation + filt->set_translation(translation); + + return 0; +} + + } // namespace openmc diff --git a/src/tallies/filter_meshsurface.cpp b/src/tallies/filter_meshsurface.cpp index 997fef7293..02fc815b75 100644 --- a/src/tallies/filter_meshsurface.cpp +++ b/src/tallies/filter_meshsurface.cpp @@ -11,7 +11,10 @@ void MeshSurfaceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, FilterMatch& match) const { - model::meshes[mesh_]->surface_bins_crossed(p, match.bins_); + Position r0 = p.r_last_current_; + Position r1 = p.r(); + Direction u = p.u(); + model::meshes[mesh_]->surface_bins_crossed(r0, r1, u, match.bins_); for (auto b : match.bins_) match.weights_.push_back(1.0); } From 0486d006ce0c879035990ef53c42ad9a050e27b0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 15 Feb 2021 15:30:09 -0600 Subject: [PATCH 02/23] Updating label, creation, and statepoint methods for the mesh filter. --- src/tallies/filter_mesh.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index b85a08263e..382a5ae13f 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -28,6 +28,11 @@ MeshFilter::from_xml(pugi::xml_node node) fatal_error(fmt::format( "Could not find mesh {} specified on tally filter.", id)); } + + if (check_for_node(node, "translation")) { + set_translation(get_node_array(node, "translation")); + } + } void @@ -61,13 +66,21 @@ MeshFilter::to_statepoint(hid_t filter_group) const { Filter::to_statepoint(filter_group); write_dataset(filter_group, "bins", model::meshes[mesh_]->id_); + if (translated_) { + write_dataset(filter_group, "translation", translation_); + } } std::string MeshFilter::text_label(int bin) const { auto& mesh = *model::meshes.at(mesh_); - return mesh.bin_label(bin); + std::string label = mesh.bin_label(bin); + if (translated_) { + label += fmt::format("\nTranslation: {}, {}, {}\n", + translation_.x, translation_.y, translation_.z); + } + return label; } void From 574c8794f7fd9ac81832a9db4e6d96aed74a68b7 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 15 Feb 2021 15:30:27 -0600 Subject: [PATCH 03/23] Updating MeshFilter class in the Python API. --- openmc/filter.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 2d8faf3784..44e1edf560 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -724,9 +724,11 @@ class MeshFilter(Filter): """ - def __init__(self, mesh, filter_id=None): + def __init__(self, mesh, filter_id=None, translation=None): + super().__init__(filter_id) self.mesh = mesh self.id = filter_id + self._translation = translation def __hash__(self): string = type(self).__name__ + '\n' @@ -750,11 +752,14 @@ class MeshFilter(Filter): raise ValueError(cls.__name__ + " requires a 'meshes' keyword " "argument.") + if 'translation' in group: + translation = group['translation'][()] + mesh_id = group['bins'][()] mesh_obj = kwargs['meshes'][mesh_id] filter_id = int(group.name.split('/')[-1].lstrip('filter ')) - out = cls(mesh_obj, filter_id=filter_id) + out = cls(mesh_obj, filter_id=filter_id, translation=translation) return out @@ -774,6 +779,17 @@ class MeshFilter(Filter): else: self.bins = list(mesh.indices) + @property + def translation(self): + return self._translation + + @translation.setter + def translation(self, t): + if t is not None: + cv.check_type('mesh filter translation', t, Iterable, Real) + cv.check_length('mesh filter translation', t, 3) + self._translation = t + def can_merge(self, other): # Mesh filters cannot have more than one bin return False @@ -854,6 +870,8 @@ class MeshFilter(Filter): """ element = super().to_xml_element() element[0].text = str(self.mesh.id) + if self.translation: + element.set("translation", ' '.join(map(str, self._translation))) return element From a0142f183bc4708635a6b598e1ed643f39f5aef5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 15 Feb 2021 15:50:16 -0600 Subject: [PATCH 04/23] Adding translation to MeshFilter repr. Fix for reading filters without a translation. --- openmc/filter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 44e1edf560..02901b9c62 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -739,6 +739,7 @@ class MeshFilter(Filter): string = type(self).__name__ + '\n' string += '{: <16}=\t{}\n'.format('\tMesh ID', self.mesh.id) string += '{: <16}=\t{}\n'.format('\tID', self.id) + string += '{: <16}=\t{}\n'.format('\tTranslation', self.translation) return string @classmethod @@ -752,13 +753,14 @@ class MeshFilter(Filter): raise ValueError(cls.__name__ + " requires a 'meshes' keyword " "argument.") - if 'translation' in group: - translation = group['translation'][()] - mesh_id = group['bins'][()] mesh_obj = kwargs['meshes'][mesh_id] filter_id = int(group.name.split('/')[-1].lstrip('filter ')) + translation = group.get('translation') + if translation: + translation = translation[()] + out = cls(mesh_obj, filter_id=filter_id, translation=translation) return out From e091a172472e374e373c9cd304c3b06f499be702 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 10:19:27 -0600 Subject: [PATCH 05/23] Adding an initial test for mesh filter translations. --- .../filter_translations/__init__.py | 0 .../input_dat_-10_-5_0.dat | 60 ++++++++++++++++ .../input_dat_-10_0_-5.dat | 60 ++++++++++++++++ .../input_dat_-5_-10_0.dat | 60 ++++++++++++++++ .../input_dat_-5_0_-10.dat | 60 ++++++++++++++++ .../input_dat_0_-10_-5.dat | 60 ++++++++++++++++ .../input_dat_0_-5_-10.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_0_10_5.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_0_5_10.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_10_0_5.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_10_5_0.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_5_0_10.dat | 60 ++++++++++++++++ .../filter_translations/input_dat_5_10_0.dat | 60 ++++++++++++++++ .../filter_translations/results_true.dat | 1 + .../filter_translations/test.py | 70 +++++++++++++++++++ 15 files changed, 791 insertions(+) create mode 100644 tests/regression_tests/filter_translations/__init__.py create mode 100644 tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_0_10_5.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_0_5_10.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_10_0_5.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_10_5_0.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_5_0_10.dat create mode 100644 tests/regression_tests/filter_translations/input_dat_5_10_0.dat create mode 100644 tests/regression_tests/filter_translations/results_true.dat create mode 100644 tests/regression_tests/filter_translations/test.py diff --git a/tests/regression_tests/filter_translations/__init__.py b/tests/regression_tests/filter_translations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat b/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat new file mode 100644 index 0000000000..ed062f2aa9 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + 1 -4 -9 + 19 14 9 + + + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + + + 13 + + + 14 + + + 13 + total + + + 14 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat b/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat new file mode 100644 index 0000000000..e9a1119bb1 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + 1 -9 -4 + 19 9 14 + + + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + + + 15 + + + 16 + + + 15 + total + + + 16 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat b/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat new file mode 100644 index 0000000000..88ae5c4346 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -4 1 -9 + 14 19 9 + + + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + + + 17 + + + 18 + + + 17 + total + + + 18 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat b/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat new file mode 100644 index 0000000000..d523149d0f --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -4 -9 1 + 14 9 19 + + + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + + + 19 + + + 20 + + + 19 + total + + + 20 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat b/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat new file mode 100644 index 0000000000..a29f8f63df --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -9 1 -4 + 9 19 14 + + + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + + + 21 + + + 22 + + + 21 + total + + + 22 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat b/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat new file mode 100644 index 0000000000..17c7af7dd3 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -9 -4 1 + 9 14 19 + + + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 + 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 + + + 23 + + + 24 + + + 23 + total + + + 24 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_0_10_5.dat b/tests/regression_tests/filter_translations/input_dat_0_10_5.dat new file mode 100644 index 0000000000..ce4d481e57 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_0_10_5.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -9 -19 -14 + 9 -1 4 + + + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + + + 9 + + + 10 + + + 9 + total + + + 10 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_0_5_10.dat b/tests/regression_tests/filter_translations/input_dat_0_5_10.dat new file mode 100644 index 0000000000..bdd361ce7f --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_0_5_10.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -9 -14 -19 + 9 4 -1 + + + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + + + 11 + + + 12 + + + 11 + total + + + 12 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_10_0_5.dat b/tests/regression_tests/filter_translations/input_dat_10_0_5.dat new file mode 100644 index 0000000000..72c17754b9 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_10_0_5.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -19 -9 -14 + -1 9 4 + + + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + + + 3 + + + 4 + + + 3 + total + + + 4 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_10_5_0.dat b/tests/regression_tests/filter_translations/input_dat_10_5_0.dat new file mode 100644 index 0000000000..73a11537a7 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_10_5_0.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -19 -14 -9 + -1 4 9 + + + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + + + 1 + + + 2 + + + 1 + total + + + 2 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_5_0_10.dat b/tests/regression_tests/filter_translations/input_dat_5_0_10.dat new file mode 100644 index 0000000000..753930f7db --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_5_0_10.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -14 -9 -19 + 4 9 -1 + + + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + + + 7 + + + 8 + + + 7 + total + + + 8 + total + + diff --git a/tests/regression_tests/filter_translations/input_dat_5_10_0.dat b/tests/regression_tests/filter_translations/input_dat_5_10_0.dat new file mode 100644 index 0000000000..98a93483e3 --- /dev/null +++ b/tests/regression_tests/filter_translations/input_dat_5_10_0.dat @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eigenvalue + 1000 + 5 + 0 + + + + + 9 9 9 + -14 -19 -9 + 4 -1 9 + + + -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 + -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 + -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + + + 5 + + + 6 + + + 5 + total + + + 6 + total + + diff --git a/tests/regression_tests/filter_translations/results_true.dat b/tests/regression_tests/filter_translations/results_true.dat new file mode 100644 index 0000000000..105ef304ba --- /dev/null +++ b/tests/regression_tests/filter_translations/results_true.dat @@ -0,0 +1 @@ +3e9446ca032f10b5d2c65529a55264eb7f995f9890180547a838d8cc130c7258e094742b7b20578e95667c63b5634eadab5b53273c9cf297e58536abb411b985 \ No newline at end of file diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py new file mode 100644 index 0000000000..075cabcbcf --- /dev/null +++ b/tests/regression_tests/filter_translations/test.py @@ -0,0 +1,70 @@ +from itertools import permutations +import numpy as np + +import openmc +import pytest + +from tests.testing_harness import HashedPyAPITestHarness + + +translations = list(permutations((10, 5, 0))) + list(permutations((-10, -5, 0))) +@pytest.fixture(params=translations) +def model(request): + + translation = np.array(request.param) + + model = openmc.model.Model() + + fuel = openmc.Material() + fuel.set_density('g/cm3', 10.0) + fuel.add_nuclide('U235', 1.0) + zr = openmc.Material() + zr.set_density('g/cm3', 1.0) + zr.add_nuclide('Zr90', 1.0) + model.materials.extend([fuel, zr]) + + box1 = openmc.model.rectangular_prism(10.0, 10.0) + box2 = openmc.model.rectangular_prism(20.0, 20.0, boundary_type='reflective') + top = openmc.ZPlane(z0=10.0, boundary_type='vacuum') + bottom = openmc.ZPlane(z0=-10.0, boundary_type='vacuum') + cell1 = openmc.Cell(fill=fuel, region=box1 & +bottom & -top) + cell2 = openmc.Cell(fill=zr, region=~box1 & box2 & +bottom & -top) + model.geometry = openmc.Geometry([cell1, cell2]) + + model.settings.batches = 5 + model.settings.inactive = 0 + model.settings.particles = 1000 + + llc = np.array([-9, -9, -9]) - translation + urc = np.array([9, 9, 9]) - translation + + reg_mesh = openmc.RegularMesh() + reg_mesh.dimension = [9, 9, 9] + reg_mesh.lower_left = llc + reg_mesh.upper_right = urc + + recti_mesh = openmc.RectilinearMesh() + recti_mesh.x_grid = np.linspace(llc[0], urc[0], 17) + recti_mesh.y_grid = np.linspace(llc[1], urc[1], 17) + recti_mesh.z_grid = np.linspace(llc[2], urc[2], 17) + + # Create filters + filters = [openmc.MeshFilter(reg_mesh, translation=translation), + openmc.MeshFilter(recti_mesh, translation=translation)] + + # Create tallies + for f in filters: + tally = openmc.Tally() + tally.filters = [f] + tally.scores = ['total'] + model.tallies.append(tally) + + input_name = 'input_dat_' + '_'.join(map(str, translation)) + '.dat' + return model, input_name + + +def test_filter_mesh_translations(model): + harness = HashedPyAPITestHarness('statepoint.5.h5', *model) + harness.main() + + From 706f8abb281f4cfcfcfd7c14cbb5d5aad9e3c2cf Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 21:29:38 -0600 Subject: [PATCH 06/23] Corrections to translations in MeshFilter. --- openmc/filter.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 02901b9c62..b70d8f74f4 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -725,7 +725,6 @@ class MeshFilter(Filter): """ def __init__(self, mesh, filter_id=None, translation=None): - super().__init__(filter_id) self.mesh = mesh self.id = filter_id self._translation = translation @@ -872,8 +871,8 @@ class MeshFilter(Filter): """ element = super().to_xml_element() element[0].text = str(self.mesh.id) - if self.translation: - element.set("translation", ' '.join(map(str, self._translation))) + if self.translation is not None: + element.set('translation', ' '.join(map(str, self._translation))) return element From 08e4b43d94958ae9b8bf8971e61692684d66a6f5 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 21:30:05 -0600 Subject: [PATCH 07/23] Fix typo in docstring. --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 4274912f66..3725d6e267 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1431,7 +1431,7 @@ openmc_get_mesh_index(int32_t id, int32_t* index) return 0; } -// Return the ID of a mesh +//! Return the ID of a mesh extern "C" int openmc_mesh_get_id(int32_t index, int32_t* id) { From 711d9267bd10d5f9bdd3b937ae7ff53f48cf6168 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 21:30:59 -0600 Subject: [PATCH 08/23] Applying translation for mesh surface filters. --- src/tallies/filter_meshsurface.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tallies/filter_meshsurface.cpp b/src/tallies/filter_meshsurface.cpp index 02fc815b75..af595ad52a 100644 --- a/src/tallies/filter_meshsurface.cpp +++ b/src/tallies/filter_meshsurface.cpp @@ -13,6 +13,11 @@ MeshSurfaceFilter::get_all_bins(const Particle& p, TallyEstimator estimator, { Position r0 = p.r_last_current_; Position r1 = p.r(); + if (translated_) { + r0 -= translation(); + r1 -= translation(); + } + Direction u = p.u(); model::meshes[mesh_]->surface_bins_crossed(r0, r1, u, match.bins_); for (auto b : match.bins_) match.weights_.push_back(1.0); From 0488f589418858d134f6e5f67ae5474fe5c9ac0c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 21:32:57 -0600 Subject: [PATCH 09/23] Exposing translation getting/setting through CAPI --- include/openmc/capi.h | 2 ++ src/tallies/filter_mesh.cpp | 38 ++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/openmc/capi.h b/include/openmc/capi.h index 64b62f3e5b..2ca9fc430f 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -74,6 +74,8 @@ extern "C" { int openmc_material_filter_set_bins(int32_t index, size_t n, const int32_t* bins); int openmc_mesh_filter_get_mesh(int32_t index, int32_t* index_mesh); int openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh); + int openmc_mesh_filter_get_translation(int32_t index, double translation[3]); + int openmc_mesh_filter_set_translation(int32_t index, double translation[3]); int openmc_mesh_get_id(int32_t index, int32_t* id); int openmc_mesh_set_id(int32_t index, int32_t id); int openmc_meshsurface_filter_get_mesh(int32_t index, int32_t* index_mesh); diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 382a5ae13f..4b63be3c99 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -159,27 +159,47 @@ openmc_mesh_filter_set_mesh(int32_t index, int32_t index_mesh) return 0; } +extern "C" int +openmc_mesh_filter_get_translation(int32_t index, double translation[3]) +{ + // Make sure this is a valid index to an allocated filter + if (int err = verify_filter(index)) return err; + + // Check the filter type + const auto& filter = model::tally_filters[index]; + if (filter->type() != "mesh" && filter->type() != "meshsurface") { + set_errmsg("Tried to get a translation from a non-mesh, non-meshsurface filter."); + return OPENMC_E_INVALID_TYPE; + } + + // Get translation from the mesh filter and set value + auto mesh_filter = static_cast(filter.get()); + const auto& t = mesh_filter->translation(); + for (int i = 0; i < 3; i++) { translation[i] = t[i]; } + + return 0; +} + extern "C" int openmc_mesh_filter_set_translation(int32_t index, double translation[3]) { // Make sure this is a valid index to an allocated filter if (int err = verify_filter(index)) return err; - // Get a pointer to the filter and downcast. - const auto& filt_base = model::tally_filters[index].get(); - auto* filt = dynamic_cast(filt_base); - + const auto& filter = model::tally_filters[index]; // Check the filter type - if (!filt) { - set_errmsg("Tried to set mesh on a non-mesh filter."); + if (filter->type() != "mesh" && filter->type() != "meshsurface") { + set_errmsg("Tried to set mesh on a non-mesh, non-meshsurface filter."); return OPENMC_E_INVALID_TYPE; } + // Get a pointer to the filter and downcast + auto mesh_filter = dynamic_cast(filter.get()); + // Set the translation - filt->set_translation(translation); + mesh_filter->set_translation(translation); return 0; } - -} // namespace openmc +} // namespace openmc \ No newline at end of file From 933bc22c0a12488e59f8cf8ce60d17db4690cf1f Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 21:34:21 -0600 Subject: [PATCH 10/23] Exposing translations through the Python CAPI. --- openmc/lib/filter.py | 26 ++++++++++++++++++++++++++ tests/unit_tests/test_lib.py | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/openmc/lib/filter.py b/openmc/lib/filter.py index 497d4592b9..5d2231cc2e 100644 --- a/openmc/lib/filter.py +++ b/openmc/lib/filter.py @@ -84,6 +84,12 @@ _dll.openmc_meshsurface_filter_get_mesh.errcheck = _error_handler _dll.openmc_meshsurface_filter_set_mesh.argtypes = [c_int32, c_int32] _dll.openmc_meshsurface_filter_set_mesh.restype = c_int _dll.openmc_meshsurface_filter_set_mesh.errcheck = _error_handler +_dll.openmc_mesh_filter_get_translation.argtypes = [c_int32, POINTER(c_double*3)] +_dll.openmc_mesh_filter_get_translation.restype = c_int +_dll.openmc_mesh_filter_get_translation.errcheck = _error_handler +_dll.openmc_mesh_filter_set_translation.argtypes = [c_int32, POINTER(c_double*3)] +_dll.openmc_mesh_filter_set_translation.restype = c_int +_dll.openmc_mesh_filter_set_translation.errcheck = _error_handler _dll.openmc_new_filter.argtypes = [c_char_p, POINTER(c_int32)] _dll.openmc_new_filter.restype = c_int _dll.openmc_new_filter.errcheck = _error_handler @@ -325,6 +331,16 @@ class MeshFilter(Filter): def mesh(self, mesh): _dll.openmc_mesh_filter_set_mesh(self._index, mesh._index) + @property + def translation(self): + translation = (c_double*3)() + _dll.openmc_mesh_filter_get_translation(self._index, translation) + return tuple(translation) + + @translation.setter + def translation(self, translation): + _dll.openmc_mesh_filter_set_translation(self._index, (c_double*3)(*translation)) + class MeshSurfaceFilter(Filter): filter_type = 'meshsurface' @@ -344,6 +360,16 @@ class MeshSurfaceFilter(Filter): def mesh(self, mesh): _dll.openmc_meshsurface_filter_set_mesh(self._index, mesh._index) + @property + def translation(self): + translation = (c_double*3)() + _dll.openmc_mesh_filter_get_translation(self._index, translation) + return tuple(translation) + + @translation.setter + def translation(self, translation): + _dll.openmc_mesh_filter_set_translation(self._index, (c_double*3)(*translation)) + class MuFilter(Filter): filter_type = 'mu' diff --git a/tests/unit_tests/test_lib.py b/tests/unit_tests/test_lib.py index 4a6d692555..6d8f567bc8 100644 --- a/tests/unit_tests/test_lib.py +++ b/tests/unit_tests/test_lib.py @@ -470,11 +470,17 @@ def test_regular_mesh(lib_init): assert isinstance(mesh, openmc.lib.RegularMesh) assert mesh_id == mesh.id + translation = (1.0, 2.0, 3.0) + mf = openmc.lib.MeshFilter(mesh) assert mf.mesh == mesh + mf.translation = translation + assert mf.translation == translation msf = openmc.lib.MeshSurfaceFilter(mesh) assert msf.mesh == mesh + msf.translation = translation + assert msf.translation == translation def test_rectilinear_mesh(lib_init): From d0353c8c15a6935b394e4f05b3ea3aa8c6d98946 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 22:29:00 -0600 Subject: [PATCH 11/23] Updating MeshFilter and MeshSurfaceFilter docstrings. --- openmc/filter.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openmc/filter.py b/openmc/filter.py index b70d8f74f4..403c743130 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -716,6 +716,9 @@ class MeshFilter(Filter): The mesh object that events will be tallied onto id : int Unique identifier for the filter + translation : Iterable of float + This array specifies a vector that is used to translate (shift) + the mesh for this filter bins : list of tuple A list of mesh indices for each filter bin, e.g. [(1, 1, 1), (2, 1, 1), ...] @@ -789,7 +792,7 @@ class MeshFilter(Filter): if t is not None: cv.check_type('mesh filter translation', t, Iterable, Real) cv.check_length('mesh filter translation', t, 3) - self._translation = t + self._translation = np.asarray(t) def can_merge(self, other): # Mesh filters cannot have more than one bin @@ -892,6 +895,9 @@ class MeshSurfaceFilter(MeshFilter): The mesh ID mesh : openmc.MeshBase The mesh object that events will be tallied onto + translation : Iterable of float + This array specifies a vector that is used to translate (shift) + the mesh for this filter id : int Unique identifier for the filter bins : list of tuple From 704c4590a0fa5f4480dde46ef76190c06eef6809 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 16 Feb 2021 22:48:28 -0600 Subject: [PATCH 12/23] Correcting name of the MOAB class. --- src/mesh.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 3725d6e267..a5e870e2b6 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1688,11 +1688,11 @@ MOABMesh::intersect_track(const moab::CartVect& start, } void -MOABUnstructuredMesh::bins_crossed(Position last_r, - Position r, - const Direction& u, - std::vector& bins, - std::vector& lengths) const +MOABMesh::bins_crossed(Position last_r, + Position r, + const Direction& u, + std::vector& bins, + std::vector& lengths) const { // u /= u.norm(); moab::CartVect r0(last_r.x, last_r.y, last_r.z); @@ -1819,10 +1819,10 @@ double MOABMesh::tet_volume(moab::EntityHandle tet) const return 1.0 / 6.0 * (((p[1] - p[0]) * (p[2] - p[0])) % (p[3] - p[0])); } -void MOABUnstructuredMesh::surface_bins_crossed(Position r0, - Position r1, - const Direction& u, - std::vector& bins) const +void MOABMesh::surface_bins_crossed(Position r0, + Position r1, + const Direction& u, + std::vector& bins) const { // TODO: Implement triangle crossings here From 7eeb9ffa8933af3b65d53a0b16a0d77f4b24f749 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 12 Apr 2021 22:34:03 -0500 Subject: [PATCH 13/23] Re-adding commented normalization. --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index a5e870e2b6..b140f9b311 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1694,10 +1694,10 @@ MOABMesh::bins_crossed(Position last_r, std::vector& bins, std::vector& lengths) const { - // u /= u.norm(); moab::CartVect r0(last_r.x, last_r.y, last_r.z); moab::CartVect r1(r.x, r.y, r.z); moab::CartVect dir(u.x, u.y, u.z); + dir.normalize(); double track_len = (r1 - r0).length(); if (track_len == 0.0) return; From 41a7f5453edd76643bc0dcbe13b6d7f60667ab7d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 09:06:46 -0500 Subject: [PATCH 14/23] Apply suggestions from @paulromano Co-authored-by: Paul Romano --- openmc/filter.py | 2 +- src/tallies/filter_mesh.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 403c743130..94522891bf 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -730,7 +730,7 @@ class MeshFilter(Filter): def __init__(self, mesh, filter_id=None, translation=None): self.mesh = mesh self.id = filter_id - self._translation = translation + self.translation = translation def __hash__(self): string = type(self).__name__ + '\n' diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 4b63be3c99..ca513a07fb 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -173,7 +173,7 @@ openmc_mesh_filter_get_translation(int32_t index, double translation[3]) } // Get translation from the mesh filter and set value - auto mesh_filter = static_cast(filter.get()); + auto mesh_filter = dynamic_cast(filter.get()); const auto& t = mesh_filter->translation(); for (int i = 0; i < 3; i++) { translation[i] = t[i]; } @@ -202,4 +202,4 @@ openmc_mesh_filter_set_translation(int32_t index, double translation[3]) return 0; } -} // namespace openmc \ No newline at end of file +} // namespace openmc From 56362eceb97b66260543c7ac1d215566b8274e24 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 09:06:30 -0500 Subject: [PATCH 15/23] Updating error messages and filter labels for mesh filters. --- src/tallies/filter_mesh.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index ca513a07fb..8cb33b3dff 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -76,10 +76,6 @@ MeshFilter::text_label(int bin) const { auto& mesh = *model::meshes.at(mesh_); std::string label = mesh.bin_label(bin); - if (translated_) { - label += fmt::format("\nTranslation: {}, {}, {}\n", - translation_.x, translation_.y, translation_.z); - } return label; } @@ -98,8 +94,7 @@ void MeshFilter::set_translation(const Position& translation) void MeshFilter::set_translation(const double translation[3]) { - translated_ = true; - translation_ = translation; + this->set_translation({translation[0], translation[1], translation[2]}); } //============================================================================== @@ -168,7 +163,7 @@ openmc_mesh_filter_get_translation(int32_t index, double translation[3]) // Check the filter type const auto& filter = model::tally_filters[index]; if (filter->type() != "mesh" && filter->type() != "meshsurface") { - set_errmsg("Tried to get a translation from a non-mesh, non-meshsurface filter."); + set_errmsg("Tried to get a translation from a non-mesh-based filter."); return OPENMC_E_INVALID_TYPE; } @@ -189,7 +184,7 @@ openmc_mesh_filter_set_translation(int32_t index, double translation[3]) const auto& filter = model::tally_filters[index]; // Check the filter type if (filter->type() != "mesh" && filter->type() != "meshsurface") { - set_errmsg("Tried to set mesh on a non-mesh, non-meshsurface filter."); + set_errmsg("Tried to set mesh on a non-mesh-based filter."); return OPENMC_E_INVALID_TYPE; } From 73aef414ca43e33987e29da4631d085429165715 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 10:33:53 -0500 Subject: [PATCH 16/23] Updating variable names of the methods. --- include/openmc/mesh.h | 23 +++++++++-------- src/mesh.cpp | 59 ++++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index d2e3724972..2af2e87df2 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -71,13 +71,13 @@ public: //! Determine which bins were crossed by a particle // - //! \param[in] last_r Previous position of the particle - //! \param[in] r Current position of the particle + //! \param[in] r0 Previous position of the particle + //! \param[in] r1 Current position of the particle //! \param[in] u Particle direction //! \param[out] bins Bins that were crossed //! \param[out] lengths Fraction of tracklength in each bin - virtual void bins_crossed(Position last_r, - Position r, + virtual void bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const = 0; @@ -147,8 +147,8 @@ public: int n_surface_bins() const override; - void bins_crossed(Position last_r, - Position r, + void bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const override; @@ -341,7 +341,8 @@ public: std::string bin_label(int bin) const override; - void surface_bins_crossed(const Particle& p, + void surface_bins_crossed(Position r0, + Position r1, std::vector& bins) const; void to_hdf5(hid_t group) const override; @@ -365,8 +366,8 @@ public: MOABMesh(pugi::xml_node); MOABMesh(const std::string& filename); - void bins_crossed(Position last_r, - Position r, + void bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const override; @@ -521,8 +522,8 @@ public: LibMesh(const std::string& filename); // Methods - void bins_crossed(Position last_r, - Position r, + void bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const override; diff --git a/src/mesh.cpp b/src/mesh.cpp index b140f9b311..9e974477cb 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -190,7 +190,8 @@ UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) { } void -UnstructuredMesh::surface_bins_crossed(const Particle& p, +UnstructuredMesh::surface_bins_crossed(Position r0, + Position r1, std::vector& bins) const { fatal_error("Unstructured mesh surface tallies are not implemented."); } @@ -581,8 +582,8 @@ bool StructuredMesh::intersects_3d(Position& r0, Position r1, int* ijk) const return min_dist < INFTY; } -void StructuredMesh::bins_crossed(Position last_r, - Position r, +void StructuredMesh::bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const @@ -591,14 +592,14 @@ void StructuredMesh::bins_crossed(Position last_r, // Determine where the track intersects the mesh and if it intersects at all. // Compute the length of the entire track. - double total_distance = (r - last_r).norm(); + double total_distance = (r1 - r0).norm(); if (total_distance == 0.0) return; // While determining if this track intersects the mesh, offset the starting // and ending coords by a bit. This avoid finite-precision errors that can // occur when the mesh surfaces coincide with lattice or geometric surfaces. - Position r0 = last_r + TINY_BIT*u; - Position r1 = r - TINY_BIT*u; + Position last_r = r0 + TINY_BIT*u; + Position r = r1 - TINY_BIT*u; // Determine the mesh indices for the starting and ending coords. Here, we // use arrays for ijk0 and ijk1 instead of std::vector because we obtain a @@ -609,21 +610,21 @@ void StructuredMesh::bins_crossed(Position last_r, int n = n_dimension_; int ijk0[3], ijk1[3]; bool start_in_mesh; - get_indices(r0, ijk0, &start_in_mesh); + get_indices(last_r, ijk0, &start_in_mesh); bool end_in_mesh; - get_indices(r1, ijk1, &end_in_mesh); + get_indices(r, ijk1, &end_in_mesh); // Reset coordinates and check for a mesh intersection if necessary. if (start_in_mesh) { // The initial coords lie in the mesh, use those coords for tallying. - r0 = last_r; + last_r = r0; } else { // The initial coords do not lie in the mesh. Check to see if the particle // eventually intersects the mesh and compute the relevant coords and // indices. - if (!intersects(r0, r1, ijk0)) return; + if (!intersects(last_r, r, ijk0)) return; } - r1 = r; + r = r1; // The TINY_BIT offsets above mean that the preceding logic cannot always find // the correct ijk0 and ijk1 indices. For tracks shorter than 2*TINY_BIT, just @@ -642,7 +643,7 @@ void StructuredMesh::bins_crossed(Position last_r, if (std::equal(ijk0, ijk0 + n, ijk1)) { // The track ends in this cell. Use the particle end location rather // than the mesh surface and stop iterating. - double distance = (r1 - r0).norm(); + double distance = (last_r - r).norm(); bins.push_back(get_bin_from_indices(ijk0)); lengths.push_back(distance / total_distance); break; @@ -655,10 +656,10 @@ void StructuredMesh::bins_crossed(Position last_r, d[k] = INFTY; } else if (u[k] > 0) { double xyz_cross = positive_grid_boundary(ijk0, k); - d[k] = (xyz_cross - r0[k]) / u[k]; + d[k] = (xyz_cross - last_r[k]) / u[k]; } else { double xyz_cross = negative_grid_boundary(ijk0, k); - d[k] = (xyz_cross - r0[k]) / u[k]; + d[k] = (xyz_cross - last_r[k]) / u[k]; } } @@ -669,7 +670,7 @@ void StructuredMesh::bins_crossed(Position last_r, lengths.push_back(distance / total_distance); // Translate to the oncoming mesh surface. - r0 += distance * u; + last_r += distance * u; // Increment the indices into the next mesh cell. if (u[j] > 0.0) { @@ -1688,25 +1689,25 @@ MOABMesh::intersect_track(const moab::CartVect& start, } void -MOABMesh::bins_crossed(Position last_r, - Position r, +MOABMesh::bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const { - moab::CartVect r0(last_r.x, last_r.y, last_r.z); - moab::CartVect r1(r.x, r.y, r.z); + moab::CartVect start(r0.x, r0.y, r0.z); + moab::CartVect end(r1.x, r1.y, r1.z); moab::CartVect dir(u.x, u.y, u.z); dir.normalize(); - double track_len = (r1 - r0).length(); + double track_len = (end - start).length(); if (track_len == 0.0) return; - r0 -= TINY_BIT * dir; - r1 += TINY_BIT * dir; + start -= TINY_BIT * dir; + end += TINY_BIT * dir; std::vector hits; - intersect_track(r0, dir, track_len, hits); + intersect_track(start, dir, track_len, hits); bins.clear(); lengths.clear(); @@ -1715,7 +1716,7 @@ MOABMesh::bins_crossed(Position last_r, // within a single tet. If this is the case, apply entire // score to that tet and return. if (hits.size() == 0) { - Position midpoint = last_r + u * (track_len * 0.5); + Position midpoint = r0 + u * (track_len * 0.5); int bin = this->get_bin(midpoint); if (bin != -1) { bins.push_back(bin); @@ -1726,7 +1727,7 @@ MOABMesh::bins_crossed(Position last_r, // for each segment in the set of tracks, try to look up a tet // at the midpoint of the segment - Position current = last_r; + Position current = r0; double last_dist = 0.0; for (const auto& hit : hits) { // get the segment length @@ -1738,7 +1739,7 @@ MOABMesh::bins_crossed(Position last_r, int bin = this->get_bin(midpoint); // determine the start point for this segment - current = last_r + u * hit; + current = r0 + u * hit; if (bin == -1) { continue; @@ -1753,7 +1754,7 @@ MOABMesh::bins_crossed(Position last_r, // the last segment of the track is in the mesh but doesn't // reach the other side of the tet if (hits.back() < track_len) { - Position segment_start = last_r + u * hits.back(); + Position segment_start = r0 + u * hits.back(); double segment_length = track_len - hits.back(); Position midpoint = segment_start + u * (segment_length * 0.5); int bin = this->get_bin(midpoint); @@ -2306,8 +2307,8 @@ void LibMesh::write(const std::string& filename) const } void -LibMesh::bins_crossed(Position last_r, - Position r, +LibMesh::bins_crossed(Position r0, + Position r1, const Direction& u, std::vector& bins, std::vector& lengths) const From 86a8faf87fde473863ad54c54df2e56c30142ec3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 10:35:03 -0500 Subject: [PATCH 17/23] Making the mesh filter translation an attribute instead of a parameter for consistency. --- openmc/filter.py | 26 +++++++++---------- .../filter_translations/test.py | 6 +++-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index 94522891bf..affe7ed378 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -727,10 +727,10 @@ class MeshFilter(Filter): """ - def __init__(self, mesh, filter_id=None, translation=None): + def __init__(self, mesh, filter_id=None): self.mesh = mesh self.id = filter_id - self.translation = translation + self._translation = None def __hash__(self): string = type(self).__name__ + '\n' @@ -759,11 +759,12 @@ class MeshFilter(Filter): mesh_obj = kwargs['meshes'][mesh_id] filter_id = int(group.name.split('/')[-1].lstrip('filter ')) + + out = cls(mesh_obj, filter_id=filter_id) + translation = group.get('translation') if translation: - translation = translation[()] - - out = cls(mesh_obj, filter_id=filter_id, translation=translation) + cls.translation = translation[()] return out @@ -789,10 +790,9 @@ class MeshFilter(Filter): @translation.setter def translation(self, t): - if t is not None: - cv.check_type('mesh filter translation', t, Iterable, Real) - cv.check_length('mesh filter translation', t, 3) - self._translation = np.asarray(t) + cv.check_type('mesh filter translation', t, Iterable, Real) + cv.check_length('mesh filter translation', t, 3) + self._translation = np.asarray(t) def can_merge(self, other): # Mesh filters cannot have more than one bin @@ -875,7 +875,7 @@ class MeshFilter(Filter): element = super().to_xml_element() element[0].text = str(self.mesh.id) if self.translation is not None: - element.set('translation', ' '.join(map(str, self._translation))) + element.set('translation', ' '.join(map(str, self.translation))) return element @@ -996,9 +996,9 @@ class CollisionFilter(Filter): Parameters ---------- bins : Iterable of int - A list or iterable of the number of collisions, as integer values. - The events whose post-scattering collision number equals one of - the provided values will be counted. + A list or iterable of the number of collisions, as integer values. + The events whose post-scattering collision number equals one of + the provided values will be counted. filter_id : int Unique identifier for the filter diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py index 075cabcbcf..a8d96158f5 100644 --- a/tests/regression_tests/filter_translations/test.py +++ b/tests/regression_tests/filter_translations/test.py @@ -49,8 +49,10 @@ def model(request): recti_mesh.z_grid = np.linspace(llc[2], urc[2], 17) # Create filters - filters = [openmc.MeshFilter(reg_mesh, translation=translation), - openmc.MeshFilter(recti_mesh, translation=translation)] + filters = [openmc.MeshFilter(reg_mesh), + openmc.MeshFilter(recti_mesh)] + for f in filters: + f.translation = translation # Create tallies for f in filters: From 52e005b3aa5d32709b45c20a5b8bfa141cbaa924 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 11:54:37 -0500 Subject: [PATCH 18/23] Using accessor method in MeshFilter::get_all_bins. --- src/tallies/filter_mesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index 8cb33b3dff..1595de70c9 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -46,8 +46,8 @@ const // apply translation if present if (translated_) { - last_r -= translation_; - r -= translation_; + last_r -= translation(); + r -= translation(); } if (estimator != TallyEstimator::TRACKLENGTH) { From 56c92cd2dbb717e04ee3153a7901044963beca17 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 12:45:21 -0500 Subject: [PATCH 19/23] Setting translation in instance instead of the MeshFilter class type. --- openmc/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/filter.py b/openmc/filter.py index affe7ed378..8da3cf78f6 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -764,7 +764,7 @@ class MeshFilter(Filter): translation = group.get('translation') if translation: - cls.translation = translation[()] + out.translation = translation[()] return out From 7961ebcdb96c7ac277da3c064e5f3345080ef1fc Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 27 Apr 2021 23:59:20 -0500 Subject: [PATCH 20/23] Simplifying test cases based on @paulromano's recommendation. --- .../input_dat_-10_-5_0.dat | 60 --- .../input_dat_-10_0_-5.dat | 60 --- .../input_dat_-5_-10_0.dat | 60 --- .../input_dat_-5_0_-10.dat | 60 --- .../input_dat_0_-10_-5.dat | 60 --- .../input_dat_0_-5_-10.dat | 60 --- .../filter_translations/input_dat_0_10_5.dat | 60 --- .../filter_translations/input_dat_0_5_10.dat | 60 --- .../filter_translations/input_dat_10_0_5.dat | 60 --- .../filter_translations/input_dat_5_0_10.dat | 60 --- .../filter_translations/input_dat_5_10_0.dat | 60 --- .../{input_dat_10_5_0.dat => inputs_true.dat} | 40 +- .../filter_translations/results_true.dat | 343 +++++++++++++++++- .../filter_translations/test.py | 62 +++- 14 files changed, 416 insertions(+), 689 deletions(-) delete mode 100644 tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_0_10_5.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_0_5_10.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_10_0_5.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_5_0_10.dat delete mode 100644 tests/regression_tests/filter_translations/input_dat_5_10_0.dat rename tests/regression_tests/filter_translations/{input_dat_10_5_0.dat => inputs_true.dat} (66%) diff --git a/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat b/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat deleted file mode 100644 index ed062f2aa9..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_-10_-5_0.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - 1 -4 -9 - 19 14 9 - - - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - - - 13 - - - 14 - - - 13 - total - - - 14 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat b/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat deleted file mode 100644 index e9a1119bb1..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_-10_0_-5.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - 1 -9 -4 - 19 9 14 - - - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - - - 15 - - - 16 - - - 15 - total - - - 16 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat b/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat deleted file mode 100644 index 88ae5c4346..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_-5_-10_0.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -4 1 -9 - 14 19 9 - - - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - - - 17 - - - 18 - - - 17 - total - - - 18 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat b/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat deleted file mode 100644 index d523149d0f..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_-5_0_-10.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -4 -9 1 - 14 9 19 - - - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - - - 19 - - - 20 - - - 19 - total - - - 20 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat b/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat deleted file mode 100644 index a29f8f63df..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_0_-10_-5.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -9 1 -4 - 9 19 14 - - - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - - - 21 - - - 22 - - - 21 - total - - - 22 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat b/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat deleted file mode 100644 index 17c7af7dd3..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_0_-5_-10.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -9 -4 1 - 9 14 19 - - - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -4.0 -2.875 -1.75 -0.625 0.5 1.625 2.75 3.875 5.0 6.125 7.25 8.375 9.5 10.625 11.75 12.875 14.0 - 1.0 2.125 3.25 4.375 5.5 6.625 7.75 8.875 10.0 11.125 12.25 13.375 14.5 15.625 16.75 17.875 19.0 - - - 23 - - - 24 - - - 23 - total - - - 24 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_0_10_5.dat b/tests/regression_tests/filter_translations/input_dat_0_10_5.dat deleted file mode 100644 index ce4d481e57..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_0_10_5.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -9 -19 -14 - 9 -1 4 - - - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - - - 9 - - - 10 - - - 9 - total - - - 10 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_0_5_10.dat b/tests/regression_tests/filter_translations/input_dat_0_5_10.dat deleted file mode 100644 index bdd361ce7f..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_0_5_10.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -9 -14 -19 - 9 4 -1 - - - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - - - 11 - - - 12 - - - 11 - total - - - 12 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_10_0_5.dat b/tests/regression_tests/filter_translations/input_dat_10_0_5.dat deleted file mode 100644 index 72c17754b9..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_10_0_5.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -19 -9 -14 - -1 9 4 - - - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - - - 3 - - - 4 - - - 3 - total - - - 4 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_5_0_10.dat b/tests/regression_tests/filter_translations/input_dat_5_0_10.dat deleted file mode 100644 index 753930f7db..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_5_0_10.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -14 -9 -19 - 4 9 -1 - - - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - - - 7 - - - 8 - - - 7 - total - - - 8 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_5_10_0.dat b/tests/regression_tests/filter_translations/input_dat_5_10_0.dat deleted file mode 100644 index 98a93483e3..0000000000 --- a/tests/regression_tests/filter_translations/input_dat_5_10_0.dat +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - eigenvalue - 1000 - 5 - 0 - - - - - 9 9 9 - -14 -19 -9 - 4 -1 9 - - - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 - - - 5 - - - 6 - - - 5 - total - - - 6 - total - - diff --git a/tests/regression_tests/filter_translations/input_dat_10_5_0.dat b/tests/regression_tests/filter_translations/inputs_true.dat similarity index 66% rename from tests/regression_tests/filter_translations/input_dat_10_5_0.dat rename to tests/regression_tests/filter_translations/inputs_true.dat index 73a11537a7..14481f804a 100644 --- a/tests/regression_tests/filter_translations/input_dat_10_5_0.dat +++ b/tests/regression_tests/filter_translations/inputs_true.dat @@ -34,21 +34,37 @@ - 9 9 9 - -19 -14 -9 - -1 4 9 + 3 4 5 + -19 -4 -9 + -1 14 9 - -19.0 -17.875 -16.75 -15.625 -14.5 -13.375 -12.25 -11.125 -10.0 -8.875 -7.75 -6.625 -5.5 -4.375 -3.25 -2.125 -1.0 - -14.0 -12.875 -11.75 -10.625 -9.5 -8.375 -7.25 -6.125 -5.0 -3.875 -2.75 -1.625 -0.5 0.625 1.75 2.875 4.0 - -9.0 -7.875 -6.75 -5.625 -4.5 -3.375 -2.25 -1.125 0.0 1.125 2.25 3.375 4.5 5.625 6.75 7.875 9.0 + -9.0 0.0 9.0 + -9.0 -3.0 3.0 9.0 + -9.0 -4.5 0.0 4.5 9.0 - + + 3 4 5 + -19 -4 -9 + -1 14 9 + + + -19.0 -10.0 -1.0 + -4.0 2.0 8.0 14.0 + -9.0 -4.5 0.0 4.5 9.0 + + 1 - + 2 + + 3 + + + 4 + 1 total @@ -57,4 +73,12 @@ 2 total + + 3 + total + + + 4 + total + diff --git a/tests/regression_tests/filter_translations/results_true.dat b/tests/regression_tests/filter_translations/results_true.dat index 105ef304ba..6782ab2aa2 100644 --- a/tests/regression_tests/filter_translations/results_true.dat +++ b/tests/regression_tests/filter_translations/results_true.dat @@ -1 +1,342 @@ -3e9446ca032f10b5d2c65529a55264eb7f995f9890180547a838d8cc130c7258e094742b7b20578e95667c63b5634eadab5b53273c9cf297e58536abb411b985 \ No newline at end of file +k-combined: +7.656044E-01 5.168921E-02 +tally 1: +0.000000E+00 +0.000000E+00 +2.220139E-02 +1.051536E-04 +2.437996E-01 +1.218585E-02 +0.000000E+00 +0.000000E+00 +2.076286E-02 +9.030648E-05 +2.355202E-01 +1.163053E-02 +0.000000E+00 +0.000000E+00 +2.087721E-02 +9.001706E-05 +4.525189E-02 +4.184578E-04 +0.000000E+00 +0.000000E+00 +2.481968E-03 +1.491717E-06 +4.714053E-03 +4.644899E-06 +0.000000E+00 +0.000000E+00 +2.998461E-02 +1.842671E-04 +3.718895E-01 +2.778255E-02 +0.000000E+00 +0.000000E+00 +2.936209E-02 +1.744066E-04 +3.714258E-01 +2.764128E-02 +0.000000E+00 +0.000000E+00 +2.430409E-02 +1.220833E-04 +5.554247E-02 +6.252448E-04 +0.000000E+00 +0.000000E+00 +3.277097E-03 +2.289856E-06 +5.878108E-03 +7.064854E-06 +0.000000E+00 +0.000000E+00 +3.732383E-02 +2.872115E-04 +5.140728E-01 +5.776753E-02 +0.000000E+00 +0.000000E+00 +2.888862E-02 +1.727185E-04 +3.995844E-01 +3.239513E-02 +0.000000E+00 +0.000000E+00 +2.245006E-02 +1.063493E-04 +6.012618E-02 +7.350842E-04 +0.000000E+00 +0.000000E+00 +2.364876E-03 +1.151142E-06 +6.103232E-03 +8.126910E-06 +0.000000E+00 +0.000000E+00 +3.151201E-02 +2.108865E-04 +3.437759E-01 +2.398626E-02 +0.000000E+00 +0.000000E+00 +2.757290E-02 +1.564838E-04 +3.374672E-01 +2.299073E-02 +0.000000E+00 +0.000000E+00 +2.008679E-02 +8.306765E-05 +5.170394E-02 +5.380731E-04 +0.000000E+00 +0.000000E+00 +1.931921E-03 +1.005318E-06 +5.262659E-03 +5.860208E-06 +0.000000E+00 +0.000000E+00 +2.095824E-02 +8.922951E-05 +2.186066E-01 +1.004483E-02 +0.000000E+00 +0.000000E+00 +2.494169E-02 +1.252761E-04 +2.315602E-01 +1.119928E-02 +0.000000E+00 +0.000000E+00 +1.851532E-02 +6.983649E-05 +4.501001E-02 +4.136072E-04 +0.000000E+00 +0.000000E+00 +2.221694E-03 +1.048753E-06 +5.820195E-03 +7.008120E-06 +tally 2: +2.194240E-01 +9.811952E-03 +2.718491E-01 +1.501408E-02 +5.823038E-01 +6.967280E-02 +5.955012E-01 +7.246929E-02 +2.496521E-01 +1.268521E-02 +2.623766E-01 +1.397567E-02 +3.475667E-01 +2.453188E-02 +3.290723E-01 +2.187833E-02 +1.123843E+00 +2.718539E-01 +1.060797E+00 +2.384769E-01 +3.373095E-01 +2.280788E-02 +3.563621E-01 +2.594087E-02 +3.442434E-01 +2.400708E-02 +3.319540E-01 +2.206590E-02 +1.051427E+00 +2.459968E-01 +1.065112E+00 +2.465202E-01 +3.182627E-01 +2.049613E-02 +3.724575E-01 +2.824300E-02 +2.274581E-01 +1.052009E-02 +2.558629E-01 +1.318940E-02 +5.434276E-01 +6.081708E-02 +5.623197E-01 +6.408372E-02 +2.320052E-01 +1.096050E-02 +2.380175E-01 +1.168927E-02 +tally 3: +4.195134E-02 +3.639654E-04 +7.345058E-02 +1.082591E-03 +5.325577E-02 +5.772001E-04 +1.390109E-01 +3.954675E-03 +3.829062E-01 +3.001419E-02 +1.408217E-01 +4.113283E-03 +1.412139E-01 +4.218445E-03 +3.567122E-01 +2.663446E-02 +1.393013E-01 +3.978946E-03 +5.117767E-02 +5.394412E-04 +8.111129E-02 +1.362452E-03 +5.594852E-02 +6.333549E-04 +6.298061E-02 +8.073054E-04 +9.082908E-02 +1.668351E-03 +6.783427E-02 +9.250122E-04 +1.999222E-01 +8.028088E-03 +5.909662E-01 +7.061368E-02 +1.896895E-01 +7.242074E-03 +1.877543E-01 +7.145844E-03 +6.189100E-01 +7.667032E-02 +1.847604E-01 +6.905108E-03 +6.017074E-02 +7.311068E-04 +1.109867E-01 +2.474797E-03 +7.322493E-02 +1.112742E-03 +6.859899E-02 +9.576740E-04 +1.062208E-01 +2.360724E-03 +6.762553E-02 +9.247454E-04 +2.367276E-01 +1.130443E-02 +9.674870E-01 +2.606562E-01 +2.113618E-01 +8.988266E-03 +2.079097E-01 +8.765092E-03 +9.535566E-01 +2.216359E-01 +2.131094E-01 +9.143533E-03 +6.644946E-02 +9.024189E-04 +1.064224E-01 +2.284439E-03 +8.143154E-02 +1.362849E-03 +6.209959E-02 +7.875797E-04 +9.702493E-02 +1.902685E-03 +6.416842E-02 +8.369934E-04 +1.727520E-01 +6.027045E-03 +5.966710E-01 +7.197863E-02 +1.889340E-01 +7.213441E-03 +1.914452E-01 +7.420265E-03 +5.726219E-01 +6.723631E-02 +1.646287E-01 +5.489910E-03 +5.663491E-02 +6.494568E-04 +9.923269E-02 +2.053123E-03 +6.809958E-02 +9.386140E-04 +4.850339E-02 +4.856214E-04 +8.169408E-02 +1.354206E-03 +5.474566E-02 +6.128204E-04 +1.208954E-01 +3.074917E-03 +3.393101E-01 +2.398955E-02 +1.358915E-01 +3.758521E-03 +1.347810E-01 +3.718991E-03 +3.404279E-01 +2.380238E-02 +1.315829E-01 +3.585161E-03 +4.754269E-02 +4.593490E-04 +7.591439E-02 +1.170776E-03 +5.121227E-02 +5.346435E-04 +tally 4: +2.194240E-01 +9.811952E-03 +2.718491E-01 +1.501408E-02 +5.823038E-01 +6.967280E-02 +5.955012E-01 +7.246929E-02 +2.496521E-01 +1.268521E-02 +2.623766E-01 +1.397567E-02 +3.475667E-01 +2.453188E-02 +3.290723E-01 +2.187833E-02 +1.123843E+00 +2.718539E-01 +1.060797E+00 +2.384769E-01 +3.373095E-01 +2.280788E-02 +3.563621E-01 +2.594087E-02 +3.442434E-01 +2.400708E-02 +3.319540E-01 +2.206590E-02 +1.051427E+00 +2.459968E-01 +1.065112E+00 +2.465202E-01 +3.182627E-01 +2.049613E-02 +3.724575E-01 +2.824300E-02 +2.274581E-01 +1.052009E-02 +2.558629E-01 +1.318940E-02 +5.434276E-01 +6.081708E-02 +5.623197E-01 +6.408372E-02 +2.320052E-01 +1.096050E-02 +2.380175E-01 +1.168927E-02 diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py index a8d96158f5..6d2554ed2d 100644 --- a/tests/regression_tests/filter_translations/test.py +++ b/tests/regression_tests/filter_translations/test.py @@ -1,18 +1,16 @@ from itertools import permutations +from openmc import mesh import numpy as np import openmc import pytest -from tests.testing_harness import HashedPyAPITestHarness +from tests.testing_harness import PyAPITestHarness -translations = list(permutations((10, 5, 0))) + list(permutations((-10, -5, 0))) -@pytest.fixture(params=translations) +@pytest.fixture def model(request): - translation = np.array(request.param) - model = openmc.model.Model() fuel = openmc.Material() @@ -35,24 +33,49 @@ def model(request): model.settings.inactive = 0 model.settings.particles = 1000 - llc = np.array([-9, -9, -9]) - translation - urc = np.array([9, 9, 9]) - translation + translation = np.array((10, -5, 0)) + llc = np.array([-9, -9, -9]) + urc = np.array([9, 9, 9]) + + mesh_dims = (3, 4, 5) + + filters = [] + + # un-translated meshes reg_mesh = openmc.RegularMesh() - reg_mesh.dimension = [9, 9, 9] + reg_mesh.dimension = mesh_dims reg_mesh.lower_left = llc reg_mesh.upper_right = urc - recti_mesh = openmc.RectilinearMesh() - recti_mesh.x_grid = np.linspace(llc[0], urc[0], 17) - recti_mesh.y_grid = np.linspace(llc[1], urc[1], 17) - recti_mesh.z_grid = np.linspace(llc[2], urc[2], 17) + filters.append(openmc.MeshFilter(reg_mesh)) - # Create filters - filters = [openmc.MeshFilter(reg_mesh), - openmc.MeshFilter(recti_mesh)] - for f in filters: - f.translation = translation + recti_mesh = openmc.RectilinearMesh() + recti_mesh.x_grid = np.linspace(llc[0], urc[0], mesh_dims[0]) + recti_mesh.y_grid = np.linspace(llc[1], urc[1], mesh_dims[1]) + recti_mesh.z_grid = np.linspace(llc[2], urc[2], mesh_dims[2]) + + filters.append(openmc.MeshFilter(recti_mesh)) + + llc -= translation + urc -= translation + + # translated meshes + translated_reg_mesh = openmc.RegularMesh() + translated_reg_mesh.dimension = mesh_dims + translated_reg_mesh.lower_left = llc + translated_reg_mesh.upper_right = urc + + filters.append(openmc.MeshFilter(translated_reg_mesh)) + filters[-1].translation = translation + + translated_recti_mesh = openmc.RectilinearMesh() + translated_recti_mesh.x_grid = np.linspace(llc[0], urc[0], mesh_dims[0]) + translated_recti_mesh.y_grid = np.linspace(llc[1], urc[1], mesh_dims[1]) + translated_recti_mesh.z_grid = np.linspace(llc[2], urc[2], mesh_dims[2]) + + filters.append(openmc.MeshFilter(translated_recti_mesh)) + filters[-1].translation = translation # Create tallies for f in filters: @@ -61,12 +84,11 @@ def model(request): tally.scores = ['total'] model.tallies.append(tally) - input_name = 'input_dat_' + '_'.join(map(str, translation)) + '.dat' - return model, input_name + return model def test_filter_mesh_translations(model): - harness = HashedPyAPITestHarness('statepoint.5.h5', *model) + harness = PyAPITestHarness('statepoint.5.h5', model) harness.main() From 9ad45c61d90d66eb57ad579f7d540832043420a1 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 29 Apr 2021 10:03:09 -0500 Subject: [PATCH 21/23] Apply suggestions from @paulromano Co-authored-by: Paul Romano --- tests/regression_tests/filter_translations/test.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py index 6d2554ed2d..cbb1b2ec0e 100644 --- a/tests/regression_tests/filter_translations/test.py +++ b/tests/regression_tests/filter_translations/test.py @@ -1,5 +1,3 @@ -from itertools import permutations -from openmc import mesh import numpy as np import openmc @@ -9,7 +7,7 @@ from tests.testing_harness import PyAPITestHarness @pytest.fixture -def model(request): +def model(): model = openmc.model.Model() @@ -90,5 +88,3 @@ def model(request): def test_filter_mesh_translations(model): harness = PyAPITestHarness('statepoint.5.h5', model) harness.main() - - From 60e216a16f0014ae6993ca7a0ea938d805d05538 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 29 Apr 2021 10:07:15 -0500 Subject: [PATCH 22/23] Fixing incorrect translation setting in mesh filter translation test. --- .../filter_translations/inputs_true.dat | 4 +- .../filter_translations/results_true.dat | 240 +++++++++--------- .../filter_translations/test.py | 4 +- 3 files changed, 124 insertions(+), 124 deletions(-) diff --git a/tests/regression_tests/filter_translations/inputs_true.dat b/tests/regression_tests/filter_translations/inputs_true.dat index 14481f804a..d38bec39f1 100644 --- a/tests/regression_tests/filter_translations/inputs_true.dat +++ b/tests/regression_tests/filter_translations/inputs_true.dat @@ -35,8 +35,8 @@ 3 4 5 - -19 -4 -9 - -1 14 9 + -9 -9 -9 + 9 9 9 -9.0 0.0 9.0 diff --git a/tests/regression_tests/filter_translations/results_true.dat b/tests/regression_tests/filter_translations/results_true.dat index 6782ab2aa2..e9813b183e 100644 --- a/tests/regression_tests/filter_translations/results_true.dat +++ b/tests/regression_tests/filter_translations/results_true.dat @@ -1,126 +1,126 @@ k-combined: 7.656044E-01 5.168921E-02 tally 1: -0.000000E+00 -0.000000E+00 -2.220139E-02 -1.051536E-04 -2.437996E-01 -1.218585E-02 -0.000000E+00 -0.000000E+00 -2.076286E-02 -9.030648E-05 -2.355202E-01 -1.163053E-02 -0.000000E+00 -0.000000E+00 -2.087721E-02 -9.001706E-05 -4.525189E-02 -4.184578E-04 -0.000000E+00 -0.000000E+00 -2.481968E-03 -1.491717E-06 -4.714053E-03 -4.644899E-06 -0.000000E+00 -0.000000E+00 -2.998461E-02 -1.842671E-04 -3.718895E-01 -2.778255E-02 -0.000000E+00 -0.000000E+00 -2.936209E-02 -1.744066E-04 -3.714258E-01 -2.764128E-02 -0.000000E+00 -0.000000E+00 -2.430409E-02 -1.220833E-04 -5.554247E-02 -6.252448E-04 -0.000000E+00 -0.000000E+00 -3.277097E-03 -2.289856E-06 -5.878108E-03 -7.064854E-06 -0.000000E+00 -0.000000E+00 -3.732383E-02 -2.872115E-04 -5.140728E-01 -5.776753E-02 -0.000000E+00 -0.000000E+00 -2.888862E-02 -1.727185E-04 -3.995844E-01 -3.239513E-02 -0.000000E+00 -0.000000E+00 -2.245006E-02 -1.063493E-04 -6.012618E-02 -7.350842E-04 -0.000000E+00 -0.000000E+00 -2.364876E-03 -1.151142E-06 -6.103232E-03 -8.126910E-06 -0.000000E+00 -0.000000E+00 -3.151201E-02 -2.108865E-04 -3.437759E-01 -2.398626E-02 -0.000000E+00 -0.000000E+00 -2.757290E-02 -1.564838E-04 -3.374672E-01 -2.299073E-02 -0.000000E+00 -0.000000E+00 -2.008679E-02 -8.306765E-05 -5.170394E-02 -5.380731E-04 -0.000000E+00 -0.000000E+00 -1.931921E-03 -1.005318E-06 -5.262659E-03 -5.860208E-06 -0.000000E+00 -0.000000E+00 -2.095824E-02 -8.922951E-05 -2.186066E-01 -1.004483E-02 -0.000000E+00 -0.000000E+00 -2.494169E-02 -1.252761E-04 -2.315602E-01 -1.119928E-02 -0.000000E+00 -0.000000E+00 -1.851532E-02 -6.983649E-05 -4.501001E-02 -4.136072E-04 -0.000000E+00 -0.000000E+00 -2.221694E-03 -1.048753E-06 -5.820195E-03 -7.008120E-06 +4.195134E-02 +3.639654E-04 +7.345058E-02 +1.082591E-03 +5.325577E-02 +5.772001E-04 +1.390109E-01 +3.954675E-03 +3.829062E-01 +3.001419E-02 +1.408217E-01 +4.113283E-03 +1.412139E-01 +4.218445E-03 +3.567122E-01 +2.663446E-02 +1.393013E-01 +3.978946E-03 +5.117767E-02 +5.394412E-04 +8.111129E-02 +1.362452E-03 +5.594852E-02 +6.333549E-04 +6.298061E-02 +8.073054E-04 +9.082908E-02 +1.668351E-03 +6.783427E-02 +9.250122E-04 +1.999222E-01 +8.028088E-03 +5.909662E-01 +7.061368E-02 +1.896895E-01 +7.242074E-03 +1.877543E-01 +7.145844E-03 +6.189100E-01 +7.667032E-02 +1.847604E-01 +6.905108E-03 +6.017074E-02 +7.311068E-04 +1.109867E-01 +2.474797E-03 +7.322493E-02 +1.112742E-03 +6.859899E-02 +9.576740E-04 +1.062208E-01 +2.360724E-03 +6.762553E-02 +9.247454E-04 +2.367276E-01 +1.130443E-02 +9.674870E-01 +2.606562E-01 +2.113618E-01 +8.988266E-03 +2.079097E-01 +8.765092E-03 +9.535566E-01 +2.216359E-01 +2.131094E-01 +9.143533E-03 +6.644946E-02 +9.024189E-04 +1.064224E-01 +2.284439E-03 +8.143154E-02 +1.362849E-03 +6.209959E-02 +7.875797E-04 +9.702493E-02 +1.902685E-03 +6.416842E-02 +8.369934E-04 +1.727520E-01 +6.027045E-03 +5.966710E-01 +7.197863E-02 +1.889340E-01 +7.213441E-03 +1.914452E-01 +7.420265E-03 +5.726219E-01 +6.723631E-02 +1.646287E-01 +5.489910E-03 +5.663491E-02 +6.494568E-04 +9.923269E-02 +2.053123E-03 +6.809958E-02 +9.386140E-04 +4.850339E-02 +4.856214E-04 +8.169408E-02 +1.354206E-03 +5.474566E-02 +6.128204E-04 +1.208954E-01 +3.074917E-03 +3.393101E-01 +2.398955E-02 +1.358915E-01 +3.758521E-03 +1.347810E-01 +3.718991E-03 +3.404279E-01 +2.380238E-02 +1.315829E-01 +3.585161E-03 +4.754269E-02 +4.593490E-04 +7.591439E-02 +1.170776E-03 +5.121227E-02 +5.346435E-04 tally 2: 2.194240E-01 9.811952E-03 diff --git a/tests/regression_tests/filter_translations/test.py b/tests/regression_tests/filter_translations/test.py index cbb1b2ec0e..d61667b014 100644 --- a/tests/regression_tests/filter_translations/test.py +++ b/tests/regression_tests/filter_translations/test.py @@ -55,8 +55,8 @@ def model(): filters.append(openmc.MeshFilter(recti_mesh)) - llc -= translation - urc -= translation + llc = np.array(llc - translation) + urc = np.array(urc - translation) # translated meshes translated_reg_mesh = openmc.RegularMesh() From 10e34b094c399d04ef8e7124454d3eea66951548 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 29 Apr 2021 10:07:35 -0500 Subject: [PATCH 23/23] Adding dimenson parameter to the RectilinearMesh class. --- openmc/mesh.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/openmc/mesh.py b/openmc/mesh.py index 459b48a694..16e25cddc4 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -471,6 +471,8 @@ class RectilinearMesh(MeshBase): Unique identifier for the mesh name : str Name of the mesh + dimension : Iterable of int + The number of mesh cells in each direction. n_dimension : int Number of mesh dimensions (always 3 for a RectilinearMesh). x_grid : Iterable of float @@ -492,6 +494,12 @@ class RectilinearMesh(MeshBase): self._y_grid = None self._z_grid = None + @property + def dimension(self): + return (len(self.x_grid) - 1, + len(self.y_grid) - 1, + len(self.z_grid) - 1) + @property def n_dimension(self): return 3