From 7323ae526fd4e61c97989bd303ab7aea7f2d124c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 10 Apr 2020 17:17:45 -0500 Subject: [PATCH] Updates to get the timing of variable addition and score setting right for libmesh. --- CMakeLists.txt | 4 ++++ cmake/Modules/FindLIBMESH.cmake | 11 +++-------- src/finalize.cpp | 8 ++++---- src/initialize.cpp | 8 ++------ src/mesh.cpp | 24 +++++++++++++----------- src/state_point.cpp | 16 +++++++++++++++- 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 499e006a0..8bd798828 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -415,8 +415,12 @@ if(dagmc) endif() if(libmesh) +if (debug) + target_link_libraries(libopenmc PkgConfig::LIBMESH_DEVEL) +else() target_link_libraries(libopenmc PkgConfig::LIBMESH) endif() +endif() #=============================================================================== # openmc executable diff --git a/cmake/Modules/FindLIBMESH.cmake b/cmake/Modules/FindLIBMESH.cmake index 1039e3e3b..8d3097f64 100644 --- a/cmake/Modules/FindLIBMESH.cmake +++ b/cmake/Modules/FindLIBMESH.cmake @@ -1,11 +1,5 @@ -# Try to find LIBMESH -# -# Once done this will define -# -# LIBMESH_FOUND - system has LIBMESH -# LIBMESH_INCLUDE_DIRS - the LIBMESH include directory -# LIBMESH_LIBRARIES - Link these to use LIBMESH -# LIBMESH_DEFINITIONS - Compiler switches required for using LIBMESH +# Finds the libMesh installation using CMake's PkgConfig +# module and creates a libmesh imported target find_path(LIBMESH_PC NAMES libmesh-opt.pc HINTS ${LIBMESH_ROOT} $ENV{LIBMESH_ROOT} @@ -16,5 +10,6 @@ find_path(LIBMESH_PC NAMES libmesh-opt.pc include(FindPkgConfig) set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${LIBMESH_PC}") pkg_check_modules(LIBMESH REQUIRED libmesh IMPORTED_TARGET) +pkg_check_modules(LIBMESH_DEVEL REQUIRED libmesh-devel IMPORTED_TARGET) message(STATUS "Found LIBMESH in ${LIBMESH_PC}") diff --git a/src/finalize.cpp b/src/finalize.cpp index 35e52743c..3afd9e186 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -68,10 +68,6 @@ int openmc_finalize() // Reset timers reset_timers(); -#ifdef LIBMESH - settings::LMI.reset(); -#endif - // Reset global variables settings::assume_separate = false; settings::check_overlaps = false; @@ -141,6 +137,10 @@ int openmc_finalize() // Deallocate arrays free_memory(); +#ifdef LIBMESH + settings::LMI.reset(); +#endif + // Free all MPI types #ifdef OPENMC_MPI if (mpi::bank != MPI_DATATYPE_NULL) MPI_Type_free(&mpi::bank); diff --git a/src/initialize.cpp b/src/initialize.cpp index 9c2861be0..fcb6d98b1 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -67,12 +67,8 @@ int openmc_init(int argc, char* argv[], const void* intracomm) int n_threads = 1; #endif - // initialize libmesh -#ifdef OPENMC_MPI - if (!settings::LMI) settings::LMI = std::make_unique(argc, argv, mpi::intracomm, n_threads); -#else - if (!settings::LMI) settings::LMI = std::make_unique(argc, argv, n_threads); -#endif +// initialize libmesh +if (!settings::LMI) settings::LMI = std::make_unique(argc, argv, n_threads); #endif diff --git a/src/mesh.cpp b/src/mesh.cpp index c309f8a96..72abb6d16 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -2238,12 +2238,11 @@ LibMesh::surface_bins_crossed(const Particle* p, void LibMesh::add_score(const std::string& var_name) { // check if this is a new varaible - std::string value_name = var_name + "_value"; + std::string value_name = var_name + "_mean"; if (!variable_map_.count(value_name)) { auto& eqn_sys = equation_systems_->get_system(eq_system_name_); auto var_num = eqn_sys.add_variable(value_name, libMesh::CONSTANT, libMesh::MONOMIAL); variable_map_[value_name] = var_num; - equation_systems_->init(); } std::string std_dev_name = var_name + "_std_dev"; @@ -2252,7 +2251,6 @@ LibMesh::add_score(const std::string& var_name) { auto& eqn_sys = equation_systems_->get_system(eq_system_name_); auto var_num = eqn_sys.add_variable(std_dev_name, libMesh::CONSTANT, libMesh::MONOMIAL); variable_map_[std_dev_name] = var_num; - equation_systems_->init(); } } @@ -2261,15 +2259,18 @@ LibMesh::set_score_data(const std::string& var_name, std::vector values, std::vector std_dev) { - auto& eqn_sys = equation_systems_->get_system(eq_system_name_); - const libMesh::DofMap& dof_map = eqn_sys.get_dof_map(); + auto& eqn_sys = equation_systems_->get_system(eq_system_name_); - // look up the value variable - std::string value_name = var_name + "_value"; - unsigned int value_num = variable_map_.at(value_name); - // look up the std dev variable - std::string std_dev_name = var_name + "_std_dev"; - unsigned int std_dev_num = variable_map_.at(std_dev_name); + if (!eqn_sys.is_initialized()) { equation_systems_->init(); } + + const libMesh::DofMap& dof_map = eqn_sys.get_dof_map(); + + // look up the value variable + std::string value_name = var_name + "_mean"; + unsigned int value_num = variable_map_.at(value_name); + // look up the std dev variable + std::string std_dev_name = var_name + "_std_dev"; + unsigned int std_dev_num = variable_map_.at(std_dev_name); for (int bin = 0; bin < this->n_bins(); bin++) { auto e = m_->elem_ptr(bin); @@ -2290,6 +2291,7 @@ LibMesh::set_score_data(const std::string& var_name, } void LibMesh::write(std::string filename) const { + std::cout << "Writing file : " << filename + ".e" << std::endl; libMesh::ExodusII_IO exo(*m_); std::set systems_out = {eq_system_name_}; exo.write_discontinuous_exodusII(filename + ".e", *equation_systems_, &systems_out); diff --git a/src/state_point.cpp b/src/state_point.cpp index e8767947c..0eb7334b6 100644 --- a/src/state_point.cpp +++ b/src/state_point.cpp @@ -799,6 +799,20 @@ void write_unstructured_mesh_results() { int n_realizations = tally->n_realizations_; + for (int i_score = 0; i_score < tally->scores_.size(); i_score++) { + for (int i_nuc = 0; i_nuc < tally->nuclides_.size(); i_nuc++) { + // generate a name for the value + std::string nuclide_name = "total"; // start with total by default + if (tally->nuclides_[i_nuc] > -1) { + nuclide_name = data::nuclides[tally->nuclides_[i_nuc]]->name_; + } + + std::string score_name = tally->score_name(i_score); + auto score_str = fmt::format("{}_{}", score_name, nuclide_name); + umesh->add_score(score_str); + } + } + // write each score/nuclide combination for this tally for (int i_score = 0; i_score < tally->scores_.size(); i_score++) { for (int i_nuc = 0; i_nuc < tally->nuclides_.size(); i_nuc++) { @@ -828,10 +842,10 @@ void write_unstructured_mesh_results() { if (tally->nuclides_[i_nuc] > -1) { nuclide_name = data::nuclides[tally->nuclides_[i_nuc]]->name_; } - std::string score_name = tally->score_name(i_score); auto score_str = fmt::format("{}_{}", score_name, nuclide_name); tally_scores.push_back(score_str); + // set the data for this score umesh->set_score_data(score_str, mean_vec, std_dev_vec); } }