From b3b325d02f70db17cd65953cae359c09894d70da Mon Sep 17 00:00:00 2001 From: helen-brooks Date: Fri, 4 Jun 2021 18:06:07 +0100 Subject: [PATCH] Add new constructor for MOAB Unstructured Mesh class, taking a pointer to an external MOAB instance as an argument --- include/openmc/mesh.h | 1 + src/mesh.cpp | 11 +++++- tests/regression_tests/external_moab/main.cpp | 37 +++++++++++++------ tests/regression_tests/external_moab/test.py | 4 +- 4 files changed, 39 insertions(+), 14 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 49d9dd872..5eb56a379 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -366,6 +366,7 @@ public: MOABMesh() = default; MOABMesh(pugi::xml_node); MOABMesh(const std::string& filename); + MOABMesh(std::shared_ptr external_mbi); // Overridden Methods diff --git a/src/mesh.cpp b/src/mesh.cpp index 623589115..f9f50f95c 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -160,7 +160,6 @@ StructuredMesh::bin_label(int bin) const { //============================================================================== UnstructuredMesh::UnstructuredMesh(pugi::xml_node node) : Mesh(node) { - n_dimension_ = 3; // check the mesh type if (check_for_node(node, "type")) { @@ -1582,6 +1581,12 @@ MOABMesh::MOABMesh(const std::string& filename) { initialize(); } +MOABMesh::MOABMesh(std::shared_ptr external_mbi) { + mbi_ = external_mbi; + filename_ = "unknown (external file)"; + initialize(); +} + void MOABMesh::initialize() { // Create the MOAB interface and load data from file @@ -1590,6 +1595,9 @@ void MOABMesh::initialize() { // Initialise MOAB error code moab::ErrorCode rval = moab::MB_SUCCESS; + // Set the dimension + n_dimension_ = 3; + // set member range of tetrahedral entities rval = mbi_->get_entities_by_dimension(0, n_dimension_, ehs_); if (rval != moab::MB_SUCCESS) { @@ -1621,6 +1629,7 @@ void MOABMesh::initialize() { void MOABMesh::create_interface() { + // Do not create a MOAB instance if one is already in memory if(mbi_ == nullptr){ // create MOAB instance mbi_ = std::make_shared(); diff --git a/tests/regression_tests/external_moab/main.cpp b/tests/regression_tests/external_moab/main.cpp index ddcd29992..270bbc133 100644 --- a/tests/regression_tests/external_moab/main.cpp +++ b/tests/regression_tests/external_moab/main.cpp @@ -9,6 +9,15 @@ int main(int argc, char * argv[]){ using namespace openmc; int openmc_err; + // Initialise OpenMC + openmc_err = openmc_init(argc, argv, nullptr); + if (openmc_err == -1) { + // This happens for the -h and -v flags + return EXIT_SUCCESS; + } else if (openmc_err) { + fatal_error(openmc_err_msg); + } + // Create MOAB interface std::shared_ptr moabPtrLocal = std::make_shared(); @@ -20,23 +29,29 @@ int main(int argc, char * argv[]){ fatal_error("Failed to load the unstructured mesh file: " + filename); } else{ - std::cout<<"Loaded external mesh from file "<(moabPtrLocal)); - if (openmc_err == -1) { - // This happens for the -h and -v flags - return EXIT_SUCCESS; - } else if (openmc_err) { - fatal_error(openmc_err_msg); + // Check we now have 2 copies of the shared ptr + if(moabPtrLocal.use_count()!=2){ + fatal_error("Incorrect number of MOAB shared pointers"); } - // Create a new unstructured mesh tally using new constructor + // Set mesh ID (-1 signifies auto-assign) + model::meshes.back()->set_id(-1); + int mesh_id = model::meshes.back()->id_; + + // Check we now have 2 meshes and id was correctly set + if(model::meshes.size()!=2) + fatal_error("Wrong number of meshes."); + else if(mesh_id!=2) + fatal_error("Mesh ID is incorrect"); + + // Add a new mesh filter tally - // Add unstructured mesh tally to openmc - // Run OpenMC openmc_err = openmc_run(); if (openmc_err) fatal_error(openmc_err_msg); diff --git a/tests/regression_tests/external_moab/test.py b/tests/regression_tests/external_moab/test.py index b9926715d..113b6789e 100644 --- a/tests/regression_tests/external_moab/test.py +++ b/tests/regression_tests/external_moab/test.py @@ -39,7 +39,7 @@ def cpp_driver(request): target_link_libraries(main OpenMC::libopenmc) set_target_properties(main PROPERTIES CXX_STANDARD 14 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO) set(CMAKE_CXX_FLAGS "-pedantic-errors") - + add_compile_definitions(DAGMC=1) """.format(openmc_dir))) # Create temporary build directory and change to there @@ -93,7 +93,7 @@ class ExternalMoabTest(PyAPITestHarness): def _test_output_created(self): pass - + # Directly compare results of unstructured mesh with internal and external moab def _compare_results(self):