From 19de269ae65dd70bd9f900f018e55262947b01a2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 29 Aug 2018 10:31:13 -0500 Subject: [PATCH] Populate meshes vector from settings.xml --- include/openmc/mesh.h | 5 ++- src/cmfd_execute.F90 | 1 - src/mesh.cpp | 2 +- src/output.F90 | 1 - src/settings.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 101 insertions(+), 6 deletions(-) diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 151701e0b..1d75d778d 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -1,7 +1,8 @@ #ifndef OPENMC_MESH_H #define OPENMC_MESH_H -#include +#include // for size_t +#include // for unique_ptr #include #include @@ -48,7 +49,7 @@ private: // Global variables //============================================================================== -extern std::vector global_meshes; +extern std::vector> meshes; extern std::unordered_map mesh_map; diff --git a/src/cmfd_execute.F90 b/src/cmfd_execute.F90 index 7fe153d27..74264a036 100644 --- a/src/cmfd_execute.F90 +++ b/src/cmfd_execute.F90 @@ -214,7 +214,6 @@ contains use bank_header, only: source_bank use constants, only: ZERO, ONE use error, only: warning, fatal_error - use mesh_header, only: RegularMesh use mesh, only: count_bank_sites use message_passing use string, only: to_str diff --git a/src/mesh.cpp b/src/mesh.cpp index 9e4aae096..fb9ce2d0d 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -16,7 +16,7 @@ namespace openmc { // Global variables //============================================================================== -std::vector global_meshes; +std::vector> meshes; std::unordered_map mesh_map; diff --git a/src/output.F90 b/src/output.F90 index b4ecf497e..b7b418a39 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -10,7 +10,6 @@ module output use error, only: fatal_error, warning use geometry_header use math, only: t_percentile - use mesh_header, only: RegularMesh, meshes use message_passing, only: master, n_procs use mgxs_interface use nuclide_header diff --git a/src/settings.cpp b/src/settings.cpp index b7310c37f..7e727178a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,7 +1,9 @@ #include "openmc/settings.h" +#include // for ceil, pow #include // for numeric_limits #include +#include // for out_of_range #include #include @@ -13,6 +15,7 @@ #include "openmc/distribution_spatial.h" #include "openmc/error.h" #include "openmc/file_utils.h" +#include "openmc/mesh.h" #include "openmc/random_lcg.h" #include "openmc/source.h" #include "openmc/string_utils.h" @@ -484,7 +487,100 @@ read_settings_xml() //track_identifiers = reshape(temp_int_array, [3, n_tracks/3]) } - // TODO: Read meshes + // Read meshes + for (auto node : root.children("mesh")) { + // Read mesh and add to vector + meshes.emplace_back(new RegularMesh{node}); + + // Map ID to position in vector + mesh_map[meshes.back()->id_] = meshes.size() - 1; + } + + // Shannon Entropy mesh + if (check_for_node(root, "entropy_mesh")) { + int temp = std::stoi(get_node_value(root, "entropy_mesh")); + try { + index_entropy_mesh = mesh_map.at(temp); + } catch (std::out_of_range) { + std::stringstream msg; + msg << "Mesh " << temp << " specified for Shannon entropy does not exist."; + fatal_error(msg); + } + } else if (check_for_node(root, "entropy")) { + warning("Specifying a Shannon entropy mesh via the element " + "is deprecated. Please create a mesh using and then reference " + "it by specifying its ID in an element."); + + // Read entropy mesh from + auto node_entropy = root.child("entropy"); + meshes.emplace_back(new RegularMesh{node_entropy}); + + // Set entropy mesh index + index_entropy_mesh = meshes.size() - 1; + + // Assign ID and set mapping + meshes.back()->id_ = 10000; + mesh_map[10000] = index_entropy_mesh; + } + + if (index_entropy_mesh >= 0) { + auto& m = *meshes[index_entropy_mesh]; + if (m.shape_.dimension() == 0) { + // If the user did not specify how many mesh cells are to be used in + // each direction, we automatically determine an appropriate number of + // cells + int n = std::ceil(std::pow(settings::n_particles / 20, 1.0/3.0)); + m.shape_ = {n, n, n}; + m.n_dimension_ = 3; + + // Calculate width + m.width_ = (m.upper_right_ - m.lower_left_) / m.shape_; + } + + // TODO: Allocate entropy_P + // Allocate space for storing number of fission sites in each mesh cell + //allocate(entropy_p(1, product(m % dimension))) + + // Turn on Shannon entropy calculation + settings::entropy_on = true; + } + + // Uniform fission source weighting mesh + if (check_for_node(root, "ufs_mesh")) { + auto temp = std::stoi(get_node_value(root, "ufs_mesh")); + try { + index_ufs_mesh = mesh_map.at(temp); + } catch (std::out_of_range) { + std::stringstream msg; + msg << "Mesh " << temp << " specified for uniform fission site method " + "does not exist."; + fatal_error(msg); + } + } else if (check_for_node(root, "uniform_fs")) { + warning("Specifying a UFS mesh via the element " + "is deprecated. Please create a mesh using and then reference " + "it by specifying its ID in a element."); + + // Read entropy mesh from + auto node_ufs = root.child("uniform_fs"); + meshes.emplace_back(new RegularMesh{node_ufs}); + + // Set entropy mesh index + index_ufs_mesh = meshes.size() - 1; + + // Assign ID and set mapping + meshes.back()->id_ = 10001; + mesh_map[10001] = index_entropy_mesh; + } + + if (index_ufs_mesh >= 0) { + // Allocate array to store source fraction for UFS + // TODO: Allocate source_frac + //allocate(source_frac(1, product(meshes(index_ufs_mesh) % dimension))) + + // Turn on uniform fission source weighting + settings::ufs_on = true; + } // TODO: Read