diff --git a/include/openmc/distribution_spatial.h b/include/openmc/distribution_spatial.h index 939d055ba..78fb316db 100644 --- a/include/openmc/distribution_spatial.h +++ b/include/openmc/distribution_spatial.h @@ -4,8 +4,8 @@ #include "pugixml.hpp" #include "openmc/distribution.h" -#include "openmc/position.h" #include "openmc/mesh.h" +#include "openmc/position.h" namespace openmc { diff --git a/include/openmc/mesh.h b/include/openmc/mesh.h index 73a4f0bb7..7abc8a832 100644 --- a/include/openmc/mesh.h +++ b/include/openmc/mesh.h @@ -7,8 +7,8 @@ #include #include "hdf5.h" -#include "xtensor/xtensor.hpp" #include "pugixml.hpp" +#include "xtensor/xtensor.hpp" #include "openmc/memory.h" // for unique_ptr #include "openmc/particle.h" @@ -41,7 +41,7 @@ namespace openmc { // Constants //============================================================================== -enum class ElementType { UNSUPPORTED=-1, LINEAR_TET, LINEAR_HEX }; +enum class ElementType { UNSUPPORTED = -1, LINEAR_TET, LINEAR_HEX }; //============================================================================== // Global variables @@ -80,7 +80,7 @@ public: //! \param[in] seed Seed to use for random sampling //! \param[in] bin Bin value of the tet sampled //! \return sampled position within tet - virtual Position sample(uint64_t* seed, int32_t bin) const=0; + virtual Position sample(uint64_t* seed, int32_t bin) const = 0; //! Get the volume of a mesh bin // @@ -713,7 +713,7 @@ private: std::pair get_score_tags(std::string score) const; // Data members - moab::Range ehs_; //!< Range of tetrahedra EntityHandle's in the mesh + moab::Range ehs_; //!< Range of tetrahedra EntityHandle's in the mesh moab::Range verts_; //!< Range of vertex EntityHandle's in the mesh moab::EntityHandle tetset_; //!< EntitySet containing all tetrahedra moab::EntityHandle kdtree_root_; //!< Root of the MOAB KDTree @@ -731,8 +731,8 @@ class LibMesh : public UnstructuredMesh { public: // Constructors LibMesh(pugi::xml_node node); - LibMesh(const std::string & filename, double length_multiplier = 1.0); - LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier = 1.0); + LibMesh(const std::string& filename, double length_multiplier = 1.0); + LibMesh(libMesh::MeshBase& input_mesh, double length_multiplier = 1.0); static const std::string mesh_lib_type; @@ -787,8 +787,11 @@ private: int get_bin_from_element(const libMesh::Elem* elem) const; // Data members - unique_ptr unique_m_ = nullptr; //!< pointer to the libMesh MeshBase instance, only used if mesh is created inside OpenMC - libMesh::MeshBase* m_; //!< pointer to libMesh MeshBase instance, always set during intialization + unique_ptr unique_m_ = + nullptr; //!< pointer to the libMesh MeshBase instance, only used if mesh is + //!< created inside OpenMC + libMesh::MeshBase* m_; //!< pointer to libMesh MeshBase instance, always set + //!< during intialization vector> pl_; //!< per-thread point locators unique_ptr diff --git a/src/distribution_spatial.cpp b/src/distribution_spatial.cpp index fbe5ce658..fb1fbf099 100644 --- a/src/distribution_spatial.cpp +++ b/src/distribution_spatial.cpp @@ -1,10 +1,10 @@ #include "openmc/distribution_spatial.h" #include "openmc/error.h" -#include "openmc/random_lcg.h" -#include "openmc/xml_interface.h" #include "openmc/mesh.h" +#include "openmc/random_lcg.h" #include "openmc/search.h" +#include "openmc/xml_interface.h" namespace openmc { @@ -139,7 +139,8 @@ SphericalIndependent::SphericalIndependent(pugi::xml_node node) pugi::xml_node node_dist = node.child("cos_theta"); cos_theta_ = distribution_from_xml(node_dist); } else { - // If no distribution was specified, default to a single point at cos_theta=0 + // If no distribution was specified, default to a single point at + // cos_theta=0 double x[] {0.0}; double p[] {1.0}; cos_theta_ = make_unique(x, p, 1); @@ -188,8 +189,8 @@ Position SphericalIndependent::sample(uint64_t* seed) const MeshSpatial::MeshSpatial(pugi::xml_node node) { - // No in-tet distributions implemented, could include distributions for the barycentric coords - // Read in unstructured mesh from mesh_id value + // No in-tet distributions implemented, could include distributions for the + // barycentric coords Read in unstructured mesh from mesh_id value int32_t mesh_id = std::stoi(get_node_value(node, "mesh_id")); // Get pointer to spatial distribution mesh_idx_ = model::mesh_map.at(mesh_id); @@ -211,7 +212,7 @@ MeshSpatial::MeshSpatial(pugi::xml_node node) int32_t n_bins = this->n_sources(); std::vector strengths(n_bins, 0.0); - mesh_CDF_.resize(n_bins+1); + mesh_CDF_.resize(n_bins + 1); mesh_CDF_[0] = {0.0}; total_strength_ = 0.0; @@ -220,14 +221,14 @@ MeshSpatial::MeshSpatial(pugi::xml_node node) // File scheme is weighted by an array given in the xml file mesh_strengths_ = std::vector(n_bins, 1.0); if (check_for_node(node, "strengths")) { - strengths = get_node_array(node, "strengths"); - if (strengths.size() != n_bins) { - fatal_error( - fmt::format("Number of entries in the source strengths array {} does " - "not match the number of entities in mesh {} ({}).", - strengths.size(), mesh_id, n_bins)); - } - mesh_strengths_ = std::move(strengths); + strengths = get_node_array(node, "strengths"); + if (strengths.size() != n_bins) { + fatal_error( + fmt::format("Number of entries in the source strengths array {} does " + "not match the number of entities in mesh {} ({}).", + strengths.size(), mesh_id, n_bins)); + } + mesh_strengths_ = std::move(strengths); } if (get_node_value_bool(node, "volume_normalized")) { @@ -236,14 +237,17 @@ MeshSpatial::MeshSpatial(pugi::xml_node node) } } - total_strength_ = std::accumulate(mesh_strengths_.begin(), mesh_strengths_.end(), 0.0); + total_strength_ = + std::accumulate(mesh_strengths_.begin(), mesh_strengths_.end(), 0.0); for (int i = 0; i < n_bins; i++) { - mesh_CDF_[i+1] = mesh_CDF_[i] + mesh_strengths_[i]/total_strength_; + mesh_CDF_[i + 1] = mesh_CDF_[i] + mesh_strengths_[i] / total_strength_; } if (fabs(mesh_CDF_.back() - 1.0) > FP_COINCIDENT) { - fatal_error(fmt::format("Mesh sampling CDF is incorrectly formed. Final value is: {}", mesh_CDF_.back())); + fatal_error( + fmt::format("Mesh sampling CDF is incorrectly formed. Final value is: {}", + mesh_CDF_.back())); } mesh_CDF_.back() = 1.0; } diff --git a/src/initialize.cpp b/src/initialize.cpp index 913e0b1a9..6383af64e 100644 --- a/src/initialize.cpp +++ b/src/initialize.cpp @@ -106,7 +106,8 @@ int openmc_init(int argc, char* argv[], const void* intracomm) openmc::openmc_set_seed(DEFAULT_SEED); // Read XML input files - if (!read_model_xml()) read_separate_xml_files(); + if (!read_model_xml()) + read_separate_xml_files(); // Write some initial output under the header if needed initial_output(); @@ -299,7 +300,8 @@ int parse_command_line(int argc, char* argv[]) return 0; } -bool read_model_xml() { +bool read_model_xml() +{ std::string model_filename = settings::path_input.empty() ? "." : settings::path_input; @@ -314,7 +316,8 @@ bool read_model_xml() { model_filename += "/model.xml"; // if this file doesn't exist, stop here - if (!file_exists(model_filename)) return false; + if (!file_exists(model_filename)) + return false; // try to process the path input as an XML file pugi::xml_document doc; @@ -327,7 +330,7 @@ bool read_model_xml() { // Read settings if (!check_for_node(root, "settings")) { - fatal_error("No node present in the model.xml file."); + fatal_error("No node present in the model.xml file."); } auto settings_root = root.child("settings"); @@ -343,13 +346,15 @@ bool read_model_xml() { title(); } - write_message(fmt::format("Reading model XML file '{}' ...", model_filename), 5); + write_message( + fmt::format("Reading model XML file '{}' ...", model_filename), 5); read_settings_xml(settings_root); // If other XML files are present, display warning // that they will be ignored - auto other_inputs = {"materials.xml", "geometry.xml", "settings.xml", "tallies.xml", "plots.xml"}; + auto other_inputs = {"materials.xml", "geometry.xml", "settings.xml", + "tallies.xml", "plots.xml"}; for (const auto& input : other_inputs) { if (file_exists(settings::path_input + input)) { warning((fmt::format("Other XML file input(s) are present. These files " @@ -384,7 +389,7 @@ bool read_model_xml() { if (check_for_node(root, "tallies")) read_tallies_xml(root.child("tallies")); - // Initialize distribcell_filters + // Initialize distribcell_filters prepare_distribcell(); if (check_for_node(root, "plots")) @@ -415,7 +420,8 @@ void read_separate_xml_files() read_plots_xml(); } -void initial_output() { +void initial_output() +{ // write initial output if (settings::run_mode == RunMode::PLOTTING) { // Read plots.xml if it exists diff --git a/src/mesh.cpp b/src/mesh.cpp index ffe239015..121ca1f8a 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -207,24 +207,22 @@ Position UnstructuredMesh::sample_tet( // (2000) Generating Random Points in a Tetrahedron, Journal of Graphics // Tools, 5:4, 9-12, DOI: 10.1080/10867651.2000.10487528 if (s + t > 1) { - s = 1.0 - s; - t = 1.0 - t; + s = 1.0 - s; + t = 1.0 - t; } if (s + t + u > 1) { if (t + u > 1) { double old_t = t; t = 1.0 - u; u = 1.0 - s - old_t; - }else if (t + u <= 1) { + } else if (t + u <= 1) { double old_s = s; s = 1.0 - t - u; u = old_s + t + u - 1; } } - return s*(coords[1]-coords[0]) - + t*(coords[2]-coords[0]) - + u*(coords[3]-coords[0]) - + coords[0]; + return s * (coords[1] - coords[0]) + t * (coords[2] - coords[0]) + + u * (coords[3] - coords[0]) + coords[0]; } const std::string UnstructuredMesh::mesh_type = "unstructured"; @@ -268,8 +266,8 @@ void UnstructuredMesh::to_hdf5(hid_t group) const // write element types and connectivity vector volumes; - xt::xtensor connectivity ({static_cast(this->n_bins()), 8}); - xt::xtensor elem_types ({static_cast(this->n_bins()), 1}); + xt::xtensor connectivity({static_cast(this->n_bins()), 8}); + xt::xtensor elem_types({static_cast(this->n_bins()), 1}); for (int i = 0; i < this->n_bins(); i++) { auto conn = this->connectivity(i); @@ -277,17 +275,20 @@ void UnstructuredMesh::to_hdf5(hid_t group) const // write linear tet element if (conn.size() == 4) { - xt::view(elem_types, i, xt::all()) = static_cast(ElementType::LINEAR_TET); - xt::view(connectivity, i, xt::all()) = xt::xarray({conn[0], conn[1], conn[2], conn[3], - -1, -1, -1, -1}); - // write linear hex element + xt::view(elem_types, i, xt::all()) = + static_cast(ElementType::LINEAR_TET); + xt::view(connectivity, i, xt::all()) = + xt::xarray({conn[0], conn[1], conn[2], conn[3], -1, -1, -1, -1}); + // write linear hex element } else if (conn.size() == 8) { - xt::view(elem_types, i, xt::all()) = static_cast(ElementType::LINEAR_HEX); - xt::view(connectivity, i, xt::all()) = xt::xarray({conn[0], conn[1], conn[2], conn[3], - conn[4], conn[5], conn[6], conn[7]}); + xt::view(elem_types, i, xt::all()) = + static_cast(ElementType::LINEAR_HEX); + xt::view(connectivity, i, xt::all()) = xt::xarray({conn[0], conn[1], + conn[2], conn[3], conn[4], conn[5], conn[6], conn[7]}); } else { num_elem_skipped++; - xt::view(elem_types, i, xt::all()) = static_cast(ElementType::UNSUPPORTED); + xt::view(elem_types, i, xt::all()) = + static_cast(ElementType::UNSUPPORTED); xt::view(connectivity, i, xt::all()) = -1; } } @@ -1873,7 +1874,6 @@ void MOABMesh::initialize() fatal_error("Failed to get all vertex handles"); } - // make an entity set for all tetrahedra // this is used for convenience later in output rval = mbi_->create_meshset(moab::MESHSET_SET, tetset_); @@ -2104,15 +2104,15 @@ std::string MOABMesh::library() const } // Sample position within a tet for MOAB type tets -Position MOABMesh::sample(uint64_t* seed, int32_t bin) const { +Position MOABMesh::sample(uint64_t* seed, int32_t bin) const +{ moab::EntityHandle tet_ent = get_ent_handle_from_bin(bin); // Get vertex coordinates for MOAB tet const moab::EntityHandle* conn1; int conn1_size; - moab::ErrorCode rval = - mbi_->get_connectivity(tet_ent, conn1, conn1_size); + moab::ErrorCode rval = mbi_->get_connectivity(tet_ent, conn1, conn1_size); if (rval != moab::MB_SUCCESS || conn1_size != 4) { fatal_error(fmt::format( "Failed to get tet connectivity or connectivity size ({}) is invalid.", @@ -2132,7 +2132,6 @@ Position MOABMesh::sample(uint64_t* seed, int32_t bin) const { return this->sample_tet(tet_verts, seed); } - double MOABMesh::tet_volume(moab::EntityHandle tet) const { vector conn; @@ -2253,10 +2252,12 @@ std::pair, vector> MOABMesh::plot( return {}; } -int MOABMesh::get_vert_idx_from_handle(moab::EntityHandle vert) const { +int MOABMesh::get_vert_idx_from_handle(moab::EntityHandle vert) const +{ int idx = vert - verts_[0]; if (idx >= n_vertices()) { - fatal_error(fmt::format("Invalid vertex idx {} (# vertices {})", idx, n_vertices())); + fatal_error( + fmt::format("Invalid vertex idx {} (# vertices {})", idx, n_vertices())); } return idx; } @@ -2328,11 +2329,13 @@ Position MOABMesh::centroid(int bin) const return {centroid[0], centroid[1], centroid[2]}; } -int MOABMesh::n_vertices() const { +int MOABMesh::n_vertices() const +{ return verts_.size(); } -Position MOABMesh::vertex(int id) const { +Position MOABMesh::vertex(int id) const +{ moab::ErrorCode rval; @@ -2347,7 +2350,8 @@ Position MOABMesh::vertex(int id) const { return {coords[0], coords[1], coords[2]}; } -std::vector MOABMesh::connectivity(int bin) const { +std::vector MOABMesh::connectivity(int bin) const +{ moab::ErrorCode rval; auto tet = get_ent_handle_from_bin(bin); @@ -2501,14 +2505,15 @@ const std::string LibMesh::mesh_lib_type = "libmesh"; LibMesh::LibMesh(pugi::xml_node node) : UnstructuredMesh(node) { - // filename_ and length_multiplier_ will already be set by the UnstructuredMesh constructor + // filename_ and length_multiplier_ will already be set by the + // UnstructuredMesh constructor set_mesh_pointer_from_filename(filename_); set_length_multiplier(length_multiplier_); initialize(); } // create the mesh from a pointer to a libMesh Mesh -LibMesh::LibMesh(libMesh::MeshBase & input_mesh, double length_multiplier) +LibMesh::LibMesh(libMesh::MeshBase& input_mesh, double length_multiplier) { m_ = &input_mesh; set_length_multiplier(length_multiplier); @@ -2586,7 +2591,8 @@ void LibMesh::initialize() } // Sample position within a tet for LibMesh type tets -Position LibMesh::sample(uint64_t* seed, int32_t bin) const { +Position LibMesh::sample(uint64_t* seed, int32_t bin) const +{ const auto& elem = get_element_from_bin(bin); // Get tet vertex coordinates from LibMesh std::array tet_verts; diff --git a/src/settings.cpp b/src/settings.cpp index 310378517..1eceb5b3d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -214,7 +214,8 @@ void get_run_parameters(pugi::xml_node node_base) } } -void read_settings_xml() { +void read_settings_xml() +{ using namespace settings; using namespace pugi; // Check if settings.xml exists diff --git a/src/source.cpp b/src/source.cpp index 2cb5632b3..5862a41e2 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -94,7 +94,7 @@ IndependentSource::IndependentSource(pugi::xml_node node) space_ = UPtrSpace {new CylindricalIndependent(node_space)}; } else if (type == "spherical") { space_ = UPtrSpace {new SphericalIndependent(node_space)}; - } else if (type =="mesh"){ + } else if (type == "mesh") { space_ = UPtrSpace {new MeshSpatial(node_space)}; } else if (type == "box") { space_ = UPtrSpace {new SpatialBox(node_space)};