Add new constructor for MOAB Unstructured Mesh class, taking a pointer to an external MOAB instance as an argument

This commit is contained in:
helen-brooks 2021-06-04 18:06:07 +01:00
parent 12bd847129
commit b3b325d02f
4 changed files with 39 additions and 14 deletions

View file

@ -366,6 +366,7 @@ public:
MOABMesh() = default;
MOABMesh(pugi::xml_node);
MOABMesh(const std::string& filename);
MOABMesh(std::shared_ptr<moab::Interface> external_mbi);
// Overridden Methods

View file

@ -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<moab::Interface> 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<moab::Core>();

View file

@ -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<moab::Interface> moabPtrLocal =
std::make_shared<moab::Core>();
@ -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 "<<filename<<std::endl;
std::cout<<"Loaded external MOAB mesh from file "<<filename<<std::endl;
}
// Initialise OpenMC
openmc_err = openmc_init(argc, argv, nullptr);
// Add a new unstructured mesh to openmc using new constructor
model::meshes.push_back(std::make_unique<MOABMesh>(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);

View file

@ -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):