From 91000f3ea0dac86e4129c22b75937bec85f64e75 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Fri, 1 Jul 2022 16:51:39 -0500 Subject: [PATCH 01/13] refactored mesh.cpp to allow mesh pointer or filename and reduced copied code --- include/openmc/mesh.h | 9 ++++++--- src/mesh.cpp | 27 ++++++++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 21c58862d9..4d5ebc46ea 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -53,7 +53,7 @@ extern vector> meshes; #ifdef LIBMESH namespace settings { -// used when creating new libMesh::Mesh instances +// used when creating new libMesh::MeshBase instances extern unique_ptr libmesh_init; extern const libMesh::Parallel::Communicator* libmesh_comm; } // namespace settings @@ -671,7 +671,8 @@ class LibMesh : public UnstructuredMesh { public: // Constructors LibMesh(pugi::xml_node node); - LibMesh(const std::string& filename, double length_multiplier = 1.0); + LibMesh(const std::string & filename, double length_multiplier = 1.0); + LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier = 1.0); static const std::string mesh_lib_type; @@ -705,6 +706,7 @@ public: private: void initialize() override; + void set_mesh_pointer_from_filename(const std::string& filename); // Methods @@ -715,7 +717,8 @@ private: int get_bin_from_element(const libMesh::Elem* elem) const; // Data members - unique_ptr m_; //!< pointer to the libMesh mesh instance + unique_ptr unique_m_; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC + libMesh::MeshBase * m_; //!< pointer to libMesh MeshBase instance vector> pl_; //!< per-thread point locators unique_ptr diff --git a/src/mesh.cpp b/src/mesh.cpp index e8f79aa37a..68675b9692 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2327,13 +2327,31 @@ LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) initialize(); } -LibMesh::LibMesh(const std::string& filename, double length_multiplier) +// create the mesh from a pointer to a libMesh Mesh +LibMesh::LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier) { - filename_ = filename; + m_ = &input_mesh; set_length_multiplier(length_multiplier); initialize(); } +// create the mesh from an input file +LibMesh::LibMesh(const std::string& filename, double length_multiplier) +{ + set_mesh_pointer_from_filename(filename); + set_length_multiplier(length_multiplier); + initialize(); +} + +void LibMesh::set_mesh_pointer_from_filename(const std::string& filename) +{ + filename_ = filename; + unique_m_ = make_unique(*settings::libmesh_comm, n_dimension_); + m_ = unique_m_.get(); + m_->read(filename_); +} + +// intialize from mesh file void LibMesh::initialize() { if (!settings::libmesh_comm) { @@ -2344,15 +2362,10 @@ void LibMesh::initialize() // assuming that unstructured meshes used in OpenMC are 3D n_dimension_ = 3; - 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 if (m_->mesh_dimension() != n_dimension_) { fatal_error(fmt::format("Mesh file {} specified for use in an unstructured " From 7fc9d20a3011d6aec405f6c22669da365502de1e Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 12:20:19 -0500 Subject: [PATCH 02/13] added back accidentally deleted line --- src/mesh.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesh.cpp b/src/mesh.cpp index 68675b9692..e4ede6a042 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2366,6 +2366,8 @@ void LibMesh::initialize() libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); } + m_->prepare_for_use() + // ensure that the loaded mesh is 3 dimensional if (m_->mesh_dimension() != n_dimension_) { fatal_error(fmt::format("Mesh file {} specified for use in an unstructured " From deda82d6319e628d4ca549e741730a6c1821386e Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 12:20:47 -0500 Subject: [PATCH 03/13] added clarification to comment --- include/openmc/mesh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 4d5ebc46ea..ce512c7674 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -718,7 +718,7 @@ private: // Data members unique_ptr unique_m_; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC - libMesh::MeshBase * m_; //!< pointer to libMesh MeshBase instance + libMesh::MeshBase * m_; //!< pointer to libMesh MeshBase instance, always set during intialization vector> pl_; //!< per-thread point locators unique_ptr From 6a9be64d7112ebb65cb671076385c564c9462747 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 12:22:59 -0500 Subject: [PATCH 04/13] left off semicolon --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index e4ede6a042..44580d81be 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2366,7 +2366,7 @@ void LibMesh::initialize() libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); } - m_->prepare_for_use() + m_->prepare_for_use(); // ensure that the loaded mesh is 3 dimensional if (m_->mesh_dimension() != n_dimension_) { From fd8a8207082522a7a454931c49453ee5f0c833e9 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 12:40:13 -0500 Subject: [PATCH 05/13] added public mesh_ptr() accessor. moved m->prepare_for_use() to filename constructor since it only happens there. for consistency, added theh length_multiplier scale modification to constructors --- include/openmc/mesh.h | 2 ++ src/mesh.cpp | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index ce512c7674..cd2e56bb0c 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -704,6 +704,8 @@ public: double volume(int bin) const override; + libMesh::MeshBase * mesh_ptr() const; + private: void initialize() override; void set_mesh_pointer_from_filename(const std::string& filename); diff --git a/src/mesh.cpp b/src/mesh.cpp index 44580d81be..5c2c8ea252 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2332,6 +2332,9 @@ LibMesh::LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier) { m_ = &input_mesh; set_length_multiplier(length_multiplier); + if (specified_length_multiplier_) { + libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); + } initialize(); } @@ -2340,6 +2343,10 @@ LibMesh::LibMesh(const std::string& filename, double length_multiplier) { set_mesh_pointer_from_filename(filename); set_length_multiplier(length_multiplier); + if (specified_length_multiplier_) { + libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); + } + m_->prepare_for_use(); initialize(); } @@ -2362,12 +2369,6 @@ void LibMesh::initialize() // assuming that unstructured meshes used in OpenMC are 3D n_dimension_ = 3; - if (specified_length_multiplier_) { - libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); - } - - m_->prepare_for_use(); - // ensure that the loaded mesh is 3 dimensional if (m_->mesh_dimension() != n_dimension_) { fatal_error(fmt::format("Mesh file {} specified for use in an unstructured " @@ -2565,6 +2566,11 @@ double LibMesh::volume(int bin) const return m_->elem_ref(bin).volume(); } +libMesh::MeshBase * mesh_ptr() const +{ + return m_; +} + #endif // LIBMESH //============================================================================== From 045bc34ec4353ed0ff94448198e61027a26efe66 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 12:59:43 -0500 Subject: [PATCH 06/13] moved accessor to one liner in header --- include/openmc/mesh.h | 4 ++-- src/mesh.cpp | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index cd2e56bb0c..6d2c2f0296 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -704,7 +704,7 @@ public: double volume(int bin) const override; - libMesh::MeshBase * mesh_ptr() const; + libMesh::MeshBase* mesh_ptr() const { return m_; }; private: void initialize() override; @@ -720,7 +720,7 @@ private: // Data members unique_ptr unique_m_; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC - libMesh::MeshBase * m_; //!< pointer to libMesh MeshBase instance, always set during intialization + libMesh::MeshBase* m_; //!< pointer to libMesh MeshBase instance, always set during intialization vector> pl_; //!< per-thread point locators unique_ptr diff --git a/src/mesh.cpp b/src/mesh.cpp index 5c2c8ea252..d849e5d55d 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2566,11 +2566,6 @@ double LibMesh::volume(int bin) const return m_->elem_ref(bin).volume(); } -libMesh::MeshBase * mesh_ptr() const -{ - return m_; -} - #endif // LIBMESH //============================================================================== From 5161da8031ce97d2c5b19a98614d9d5fc2a52f27 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 16:39:54 -0500 Subject: [PATCH 07/13] retrireve filename and length_multiplier from XML file and call methods similar to filename case for XML constructor --- include/openmc/mesh.h | 2 +- src/mesh.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 6d2c2f0296..0ace6dfea7 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -7,13 +7,13 @@ #include #include "hdf5.h" -#include "pugixml.hpp" #include "xtensor/xtensor.hpp" #include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" #include "openmc/position.h" #include "openmc/vector.h" +#include "openmc/xml_interface.h" #ifdef DAGMC #include "moab/AdaptiveKDTree.hpp" diff --git a/src/mesh.cpp b/src/mesh.cpp index d849e5d55d..771d6f81f2 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2324,6 +2324,14 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { + std::string& filename = node.get_node_value(node, "filename"); + double length_multiplier = std::stod(node.get_node_value(node, "length_multiplier")); + set_mesh_pointer_from_filename(filename); + set_length_multiplier(length_multiplier); + if (specified_length_multiplier_) { + libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); + } + m_->prepare_for_use(); initialize(); } From 3c2d79a24198b87a1ed4a6473c920c02da773374 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 17:01:50 -0500 Subject: [PATCH 08/13] added back in header (despite redundancy) due to use in mesh files --- include/openmc/mesh.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 0ace6dfea7..13138a739b 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -8,6 +8,7 @@ #include "hdf5.h" #include "xtensor/xtensor.hpp" +#include "pugixml.hpp" #include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" From 5f1f0827aed488f1fde8876fcf28961c2ebd7d31 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 17:55:43 -0500 Subject: [PATCH 09/13] not supposed to call method on node object, other places use it from no object. following those examples --- src/mesh.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index 771d6f81f2..e2c1e50ec3 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2324,8 +2324,8 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { - std::string& filename = node.get_node_value(node, "filename"); - double length_multiplier = std::stod(node.get_node_value(node, "length_multiplier")); + std::string& filename = get_node_value(node, "filename"); + double length_multiplier = std::stod(get_node_value(node, "length_multiplier")); set_mesh_pointer_from_filename(filename); set_length_multiplier(length_multiplier); if (specified_length_multiplier_) { From 35c3ef9e2dbfccfe212267a02a6a72a2a1849821 Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Tue, 26 Jul 2022 18:18:26 -0500 Subject: [PATCH 10/13] filenanme shouldn't be a reference since the RHS initializes with a non-const rvalue, causing an error --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index e2c1e50ec3..ca19a02b62 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2324,7 +2324,7 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { - std::string& filename = get_node_value(node, "filename"); + std::string filename = get_node_value(node, "filename"); double length_multiplier = std::stod(get_node_value(node, "length_multiplier")); set_mesh_pointer_from_filename(filename); set_length_multiplier(length_multiplier); From 3010c5e9ad27cff6c4f3a54e8d202f0ef796ef5e Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Wed, 27 Jul 2022 12:48:30 -0500 Subject: [PATCH 11/13] moved m->prepare_for_use() back to initialize, but only occurs if unique_m exists. XML constructor can access member variables from UnstucturedMesh constructor --- src/mesh.cpp | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index ca19a02b62..8e9d4bcecc 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2324,14 +2324,8 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { - std::string filename = get_node_value(node, "filename"); - double length_multiplier = std::stod(get_node_value(node, "length_multiplier")); - set_mesh_pointer_from_filename(filename); - set_length_multiplier(length_multiplier); - if (specified_length_multiplier_) { - libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); - } - m_->prepare_for_use(); + set_mesh_pointer_from_filename(filename_); + set_length_multiplier(length_multiplier_); initialize(); } @@ -2340,9 +2334,6 @@ LibMesh::LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier) { m_ = &input_mesh; set_length_multiplier(length_multiplier); - if (specified_length_multiplier_) { - libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); - } initialize(); } @@ -2351,10 +2342,6 @@ LibMesh::LibMesh(const std::string& filename, double length_multiplier) { set_mesh_pointer_from_filename(filename); set_length_multiplier(length_multiplier); - if (specified_length_multiplier_) { - libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); - } - m_->prepare_for_use(); initialize(); } @@ -2377,6 +2364,15 @@ void LibMesh::initialize() // assuming that unstructured meshes used in OpenMC are 3D n_dimension_ = 3; + if (specified_length_multiplier_) { + libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); + } + // if OpenMC is managing the libMesh::MeshBase instance, prepare the mesh. + // Otherwise assume that it is prepared by it's owning application + if (unique_m_) { + m_->prepare_for_use(); + } + // ensure that the loaded mesh is 3 dimensional if (m_->mesh_dimension() != n_dimension_) { fatal_error(fmt::format("Mesh file {} specified for use in an unstructured " From 7c215543ebe7f3090683096b93047082b325179a Mon Sep 17 00:00:00 2001 From: lewisgross1296 Date: Wed, 27 Jul 2022 12:53:19 -0500 Subject: [PATCH 12/13] added comment to XML constructor. initialized unique_m_ to nullptr to help some compilers --- include/openmc/mesh.h | 2 +- src/mesh.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 13138a739b..02bd3bc5a2 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -720,7 +720,7 @@ private: int get_bin_from_element(const libMesh::Elem* elem) const; // Data members - unique_ptr unique_m_; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC + unique_ptr unique_m_ = nullptr; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC libMesh::MeshBase* m_; //!< pointer to libMesh MeshBase instance, always set during intialization vector> pl_; //!< per-thread point locators diff --git a/src/mesh.cpp b/src/mesh.cpp index 8e9d4bcecc..dfa443b7f5 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2324,6 +2324,7 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { + // filename_ and length_multiplier_ will already be set by the UnstructuredMesh constructor set_mesh_pointer_from_filename(filename_); set_length_multiplier(length_multiplier_); initialize(); From 3374ec12f5a305e83b4d853208bd1912be03c6b5 Mon Sep 17 00:00:00 2001 From: Lewis Gross <43077972+lewisgross1296@users.noreply.github.com> Date: Thu, 28 Jul 2022 09:39:56 -0500 Subject: [PATCH 13/13] Update src/mesh.cpp grammar Co-authored-by: Patrick Shriwise --- src/mesh.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh.cpp b/src/mesh.cpp index dfa443b7f5..a8d57eef15 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2369,7 +2369,7 @@ void LibMesh::initialize() libMesh::MeshTools::Modification::scale(*m_, length_multiplier_); } // if OpenMC is managing the libMesh::MeshBase instance, prepare the mesh. - // Otherwise assume that it is prepared by it's owning application + // Otherwise assume that it is prepared by its owning application if (unique_m_) { m_->prepare_for_use(); }