From f7220b62db48a89351b3c2d34f97e08d89e21bde Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 9 Apr 2020 13:29:55 -0500 Subject: [PATCH] Some cleanup from self-review --- cmake/OpenMCConfig.cmake.in | 6 ----- include/openmc/mesh.h | 19 ++++++++------ openmc/mesh.py | 25 +++++++++---------- src/finalize.cpp | 3 +-- src/initialize.cpp | 2 -- src/tallies/filter_mesh.cpp | 4 --- .../unstructured_mesh/test.py | 5 ++-- 7 files changed, 26 insertions(+), 38 deletions(-) diff --git a/cmake/OpenMCConfig.cmake.in b/cmake/OpenMCConfig.cmake.in index b584de5bc..94078f909 100644 --- a/cmake/OpenMCConfig.cmake.in +++ b/cmake/OpenMCConfig.cmake.in @@ -15,12 +15,6 @@ if(@LIBMESH_FOUND@) pkg_check_modules(LIBMESH REQUIRED libmesh IMPORTED_TARGET) endif() -if(@LIBMESH_FOUND@) - include(FindPkgConfig) - set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:@LIBMESH_PC@") - pkg_check_modules(LIBMESH REQUIRED libmesh IMPORTED_TARGET) -endif() - if(NOT TARGET OpenMC::libopenmc) include("${OpenMC_CMAKE_DIR}/OpenMCTargets.cmake") endif() diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index eecb06a20..674c3cb6c 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -24,15 +24,14 @@ #ifdef LIBMESH #include "libmesh/bounding_box.h" -#include "libmesh/libmesh.h" +#include "libmesh/dof_map.h" #include "libmesh/elem.h" #include "libmesh/equation_systems.h" #include "libmesh/exodusII_io.h" #include "libmesh/explicit_system.h" -#include "libmesh/dof_map.h" +#include "libmesh/libmesh.h" #include "libmesh/mesh.h" #include "libmesh/point.h" -#include "libmesh/sphere.h" #endif namespace openmc { @@ -109,7 +108,6 @@ public: virtual std::pair, std::vector> plot(Position plot_ll, Position plot_ur) const = 0; - //! Get a label for the mesh bin //! Return a string representation of the mesh bin // //! \param[in] bin Mesh bin to generate a label for @@ -285,6 +283,13 @@ public: UnstructuredMesh(const std::string& filename); // Methods +private: + + //! Setup method for the mesh. Builds data structures, + //! element mapping, etc. + virtual void initialize() = 0; + +public: //! Add a variable to the mesh instance virtual void add_score(const std::string& var_name) = 0; @@ -383,7 +388,7 @@ public: private: - void initialize(); + void initialize() override; //! Find all intersections with faces of the mesh. // @@ -528,9 +533,7 @@ public: private: - //! Setup method for the mesh. Builds data structures, - //! element mapping, etc. - void initialize(); + void initialize() override; //! Translate a bin value to an element pointer const libMesh::Elem* get_element_from_bin(int bin) const; diff --git a/openmc/mesh.py b/openmc/mesh.py index 4d65db2a9..969a77691 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -616,8 +616,8 @@ class UnstructuredMesh(MeshBase): Name of the mesh filename : str Name of the file containing the unstructured mesh - mesh_lib : str - Library used for the unstructured mesh tally + library : str + Mesh library used for the unstructured mesh tally volumes : Iterable of float Volumes of the unstructured mesh elements total_volume : float @@ -627,12 +627,12 @@ class UnstructuredMesh(MeshBase): (1.0, 1.0, 1.0), ...] """ - def __init__(self, filename, mesh_id=None, name=''): + def __init__(self, filename, library, mesh_id=None, name=''): super().__init__(mesh_id, name) self.filename = filename self._volumes = None self._centroids = None - self._library = 'moab' + self.library = library @property def filename(self): @@ -645,12 +645,12 @@ class UnstructuredMesh(MeshBase): @property def library(self): - return self._mesh_lib + return self._library @library.setter - def library(self, mesh_lib): - cv.check_value('mesh_lib', mesh_lib, ('moab', 'libmesh')) - self._library = mesh_lib + def library(self, lib): + cv.check_value('mesh_lib', lib, ('moab', 'libmesh')) + self._library = lib @property def size(self): @@ -786,13 +786,13 @@ class UnstructuredMesh(MeshBase): def from_hdf5(cls, group): mesh_id = int(group.name.split('/')[-1].lstrip('mesh ')) filename = group['filename'][()].decode() + library = group['library'][()].decode() - mesh = cls(filename, mesh_id=mesh_id) + mesh = cls(filename, library, mesh_id=mesh_id) vol_data = group['volumes'][()] centroids = group['centroids'][()] mesh.volumes = np.reshape(vol_data, (vol_data.shape[0],)) mesh.centroids = np.reshape(centroids, (vol_data.shape[0], 3)) - mesh.mesh_lib = group['library'][()].decode() mesh.size = mesh.volumes.size return mesh @@ -810,8 +810,8 @@ class UnstructuredMesh(MeshBase): element = ET.Element("mesh") element.set("id", str(self._id)) element.set("type", "unstructured") - subelement = ET.SubElement(element, "filename") element.set("library", self._library) + subelement = ET.SubElement(element, "filename") subelement.text = self.filename return element @@ -834,6 +834,5 @@ class UnstructuredMesh(MeshBase): filename = get_text(elem, 'filename') library = get_text(elem, 'library') - mesh = cls(filename, mesh_id) - mesh.library = library + mesh = cls(filename, library, mesh_id) return mesh diff --git a/src/finalize.cpp b/src/finalize.cpp index 255cc7f30..35e52743c 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -192,5 +192,4 @@ int openmc_hard_reset() // Reset the random number generator state openmc::openmc_set_seed(DEFAULT_SEED); return 0; - -} \ No newline at end of file +} diff --git a/src/initialize.cpp b/src/initialize.cpp index 8053246cd..9c2861be0 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -55,7 +55,6 @@ int openmc_init(int argc, char* argv[], const void* intracomm) initialize_mpi(comm); #endif - // Parse command-line arguments int err = parse_command_line(argc, argv); if (err) return err; @@ -89,7 +88,6 @@ int openmc_init(int argc, char* argv[], const void* intracomm) } #endif - // Initialize random number generator -- if the user specifies a seed, it // will be re-initialized later openmc::openmc_set_seed(DEFAULT_SEED); diff --git a/src/tallies/filter_mesh.cpp b/src/tallies/filter_mesh.cpp index ecbcf94ec..eb9275bd4 100644 --- a/src/tallies/filter_mesh.cpp +++ b/src/tallies/filter_mesh.cpp @@ -45,10 +45,6 @@ const } double total = std::accumulate(match.weights_.begin(), match.weights_.end(), 0.0); - // if ( fabs(1.0 - total) > FP_PRECISION) { - // std::cout << "Total weight for score < 1.0 (" << total << ")" << std::endl; - // } - } void diff --git a/tests/regression_tests/unstructured_mesh/test.py b/tests/regression_tests/unstructured_mesh/test.py index d1a013561..1ba89264e 100644 --- a/tests/regression_tests/unstructured_mesh/test.py +++ b/tests/regression_tests/unstructured_mesh/test.py @@ -184,7 +184,7 @@ def test_unstructured_mesh(test_opts): ### Tallies ### - # create meshes + # create meshes and mesh filters regular_mesh = openmc.RegularMesh() regular_mesh.dimension = (10, 10, 10) regular_mesh.lower_left = (-10.0, -10.0, -10.0) @@ -197,8 +197,7 @@ def test_unstructured_mesh(test_opts): else: mesh_filename = "test_mesh_tets.exo" - uscd_mesh = openmc.UnstructuredMesh(mesh_filename) - uscd_mesh.library = test_opts['library'] + uscd_mesh = openmc.UnstructuredMesh(mesh_filename, test_opts['library']) uscd_filter = openmc.MeshFilter(mesh=uscd_mesh) # create tallies