From ea79fa079f6a71daac16a8d8f426c05564d4201b Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Wed, 18 Aug 2021 15:49:58 -0500 Subject: [PATCH] Allow constant scaling factor to be applied to libMesh unstructured meshes. Refs #1872 --- include/openmc/mesh.h | 7 ++++++- src/mesh.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index d3ca900cf5..7a55b5f206 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -492,7 +492,7 @@ class LibMesh : public UnstructuredMesh { public: // Constructors LibMesh(pugi::xml_node node); - LibMesh(const std::string& filename); + LibMesh(const std::string& filename, const double length_multiplier = 1.0); // Overridden Methods void bins_crossed(Position r0, Position r1, const Direction& u, @@ -533,6 +533,9 @@ private: //! Translate an element pointer to a bin index int get_bin_from_element(const libMesh::Elem* elem) const; + //! Set the length multiplier to apply to each point in the mesh + void set_length_multiplier(const double length_multiplier); + // Data members unique_ptr m_; //!< pointer to the libMesh mesh instance vector> @@ -547,6 +550,8 @@ private: libMesh::BoundingBox bbox_; //!< bounding box of the mesh libMesh::dof_id_type first_element_id_; //!< id of the first element in the mesh + double length_multiplier_ {1.0}; //!< Constant multiplication factor to apply to mesh coordinates + bool specified_length_multiplier_ {false}; }; #endif diff --git a/src/mesh.cpp b/src/mesh.cpp index 4798bfcf56..7770dfb865 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -35,6 +35,7 @@ #ifdef LIBMESH #include "libmesh/mesh_tools.h" #include "libmesh/numeric_vector.h" +#include "libmesh/mesh_modification.h" #endif namespace openmc { @@ -2141,15 +2142,32 @@ void MOABMesh::write(const std::string& base_filename) const LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { + // check if a length unit multiplier was specified + if (check_for_node(node, "length_multiplier")) { + length_multiplier_ = std::stod(get_node_value(node, "length_multiplier")); + specified_length_multiplier_ = true; + } + initialize(); } -LibMesh::LibMesh(const std::string& filename) +LibMesh::LibMesh(const std::string& filename, const double length_multiplier) { filename_ = filename; + + if (length_multiplier != 1.0) { + set_length_multiplier(length_multiplier); + } + initialize(); } +void LibMesh::set_length_multiplier(const double length_multiplier) +{ + length_multiplier_ = length_multiplier; + specified_length_multiplier_ = true; +} + void LibMesh::initialize() { if (!settings::libmesh_comm) { @@ -2162,6 +2180,11 @@ void LibMesh::initialize() m_ = make_unique(*settings::libmesh_comm, n_dimension_); m_->read(filename_); + + if (specified_length_multiplier_) { + libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); + } + m_->prepare_for_use(); // ensure that the loaded mesh is 3 dimensional