From 9695cc2771c3cae811894a278ba3a0c5ea489a48 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Mon, 13 Jan 2020 11:34:15 -0600 Subject: [PATCH] Updating unstructured mesh constructors to take a filename (template). Exposing unstructured mesh addition via CAPI. --- include/openmc/capi.h | 1 + include/openmc/mesh.h | 15 +++++++++++++-- src/mesh.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/openmc/capi.h b/include/openmc/capi.h index a36f0e280c..64b62f3e5b 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -47,6 +47,7 @@ extern "C" { int openmc_get_mesh_index(int32_t id, int32_t* index); int openmc_get_n_batches(int* n_batches, bool get_max_batches); int openmc_get_nuclide_index(const char name[], int* index); + int openmc_add_unstructured_mesh(const char filename[], const char library[], int* id); int64_t openmc_get_seed(); int openmc_get_tally_index(int32_t id, int32_t* index); void openmc_get_tally_next_id(int32_t* id); diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 5e16c6a62e..77c01bd3aa 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -266,17 +266,23 @@ public: class UnstructuredMeshBase : public Mesh { public: + // constructors + UnstructuredMeshBase() {}; UnstructuredMeshBase(pugi::xml_node node); + UnstructuredMeshBase(const std::string& filename); + std::string filename_; }; #ifdef DAGMC -class UnstructuredMesh : public Mesh { +class UnstructuredMesh : public UnstructuredMeshBase { public: + UnstructuredMesh() = default; UnstructuredMesh(pugi::xml_node); + UnstructuredMesh(const std::string& filename); ~UnstructuredMesh() = default; void bins_crossed(const Particle& p, @@ -447,8 +453,9 @@ class LibMesh : public UnstructuredMeshBase { typedef std::vector> UnstructuredMeshHits; public: - // Constructor + // Constructors LibMesh(pugi::xml_node node); + LibMesh(const std::string& filename); // Methods @@ -489,6 +496,10 @@ public: private: + //! Setup method for the mesh. Builds data structures, + //! element mapping, etc. + void initialize(); + //! Translate a bin value to an element pointer const libMesh::Elem* get_element_from_bin(int bin) const; diff --git a/src/mesh.cpp b/src/mesh.cpp index a3985de1d4..063c3a9047 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -1295,6 +1295,27 @@ openmc_extend_meshes(int32_t n, const char* type, int32_t* index_start, return 0; } +//! Adds a new unstructured mesh to OpenMC +extern "C" int openmc_add_unstrucutred_mesh(const char filename[], + const char library[], + int* mesh_id) +{ + if (library == "moab") { + model::meshes.push_back(std::move(std::make_unique(filename))); + } else if (library == "libmesh") { + model::meshes.push_back(std::move(std::make_unique(filename))); + } else { + set_errmsg("Mesh library " + std::string(library) + \ + "is not supported by this build of OpenMC"); + return OPENMC_E_INVALID_ARGUMENT; + } + + *mesh_id = model::meshes.back()->id_; + + return 0; +} + + //! Return the index in the meshes array of a mesh with a given ID extern "C" int openmc_get_mesh_index(int32_t id, int32_t* index) @@ -1452,6 +1473,7 @@ openmc_rectilinear_mesh_set_grid(int32_t index, const double* grid_x, #ifdef DAGMC +<<<<<<< HEAD UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) { // unstructured always assumed to be 3D @@ -1472,7 +1494,18 @@ UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) fatal_error("No filename supplied for unstructured mesh with ID: " + std::to_string(id_)); } +======= +UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : UnstructuredMeshBase(node) { + initialize(); +} +UnstructuredMesh::UnstructuredMesh(const std::string& filename) { + filename_ = filename; + initialize(); +} +>>>>>>> Updating unstructured mesh constructors to take a filename (template). Exposing unstructured mesh addition via CAPI. + +void UnstructuredMesh::initialize() { // create MOAB instance mbi_ = std::make_unique(); // load unstructured mesh file @@ -2057,8 +2090,16 @@ UnstructuredMeshBase::UnstructuredMeshBase(pugi::xml_node node) : Mesh(node) { #ifdef LIBMESH LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMeshBase(node) { + initialize(); +} - // always 3 for unstructured meshes +LibMesh::LibMesh(const std::string& filename) { + filename_ = filename; + initialize(); +} + +void LibMesh::initialize() { + // always 3 for unstructured meshes n_dimension_ = 3; m_ = std::unique_ptr(new libMesh::Mesh(settings::LMI->comm(), 3));