Skip to content

Commit

Permalink
remove gsl-lite dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
gridley committed Dec 15, 2024
1 parent de8132a commit d17d978
Show file tree
Hide file tree
Showing 72 changed files with 447 additions and 239 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "vendor/pugixml"]
path = vendor/pugixml
url = https://github.com/zeux/pugixml.git
[submodule "vendor/gsl-lite"]
path = vendor/gsl-lite
url = https://github.com/martinmoene/gsl-lite.git
[submodule "vendor/xtensor"]
path = vendor/xtensor
url = https://github.com/xtensor-stack/xtensor.git
Expand Down
15 changes: 1 addition & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -274,19 +274,6 @@ if (NOT xtensor_FOUND)
add_subdirectory(vendor/xtensor)
endif()

#===============================================================================
# GSL header-only library
#===============================================================================

find_package_write_status(gsl-lite)
if (NOT gsl-lite_FOUND)
add_subdirectory(vendor/gsl-lite)

# Make sure contract violations throw exceptions
target_compile_definitions(gsl-lite-v1 INTERFACE GSL_THROW_ON_CONTRACT_VIOLATION)
target_compile_definitions(gsl-lite-v1 INTERFACE gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON=1)
endif()

#===============================================================================
# Catch2 library
#===============================================================================
Expand Down Expand Up @@ -499,7 +486,7 @@ endif()
# target_link_libraries treats any arguments starting with - but not -l as
# linker flags. Thus, we can pass both linker flags and libraries together.
target_link_libraries(libopenmc ${ldflags} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}
xtensor gsl::gsl-lite-v1 fmt::fmt ${CMAKE_DL_LIBS})
xtensor fmt::fmt ${CMAKE_DL_LIBS})

if(TARGET pugixml::pugixml)
target_link_libraries(libopenmc pugixml::pugixml)
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ recursive-include vendor *.hh
recursive-include vendor *.hpp
recursive-include vendor *.pc.in
recursive-include vendor *.natvis
include vendor/gsl-lite/include/gsl/gsl
prune docs/build
prune docs/source/pythonapi/generated/
3 changes: 1 addition & 2 deletions cmake/OpenMCConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
get_filename_component(OpenMC_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)

find_package(fmt REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../fmt)
find_package(gsl-lite REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../gsl-lite)
find_package(pugixml REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../pugixml)
find_package(xtl REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../xtl)
find_package(xtensor REQUIRED HINTS ${OpenMC_CMAKE_DIR}/../xtensor)
Expand Down Expand Up @@ -41,4 +40,4 @@ endif()

if(@OPENMC_USE_UWUW@ AND NOT ${DAGMC_BUILD_UWUW})
message(FATAL_ERROR "UWUW is enabled in OpenMC but the DAGMC installation discovered was not configured with UWUW.")
endif()
endif()
7 changes: 3 additions & 4 deletions include/openmc/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "hdf5.h"
#include "pugixml.hpp"
#include <gsl/gsl-lite.hpp>

#include "openmc/bounding_box.h"
#include "openmc/constants.h"
Expand Down Expand Up @@ -129,7 +128,7 @@ class Region {
void add_precedence();

//! Add parenthesis to enforce precedence
gsl::index add_parentheses(gsl::index start);
int64_t add_parentheses(int64_t start);

//! Remove complement operators from the expression
void remove_complement_ops();
Expand Down Expand Up @@ -415,8 +414,8 @@ struct CellInstance {
return index_cell == other.index_cell && instance == other.instance;
}

gsl::index index_cell;
gsl::index instance;
int64_t index_cell;
int64_t instance;
};

//! Structure necessary for inserting CellInstance into hashed STL data
Expand Down
6 changes: 3 additions & 3 deletions include/openmc/distribution.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <cstddef> // for size_t

#include "pugixml.hpp"
#include <gsl/gsl-lite.hpp>

#include "openmc/constants.h"
#include "openmc/memory.h" // for unique_ptr
#include "openmc/span.h"
#include "openmc/vector.h" // for vector

namespace openmc {
Expand Down Expand Up @@ -44,9 +44,9 @@ class DiscreteIndex {
public:
DiscreteIndex() {};
DiscreteIndex(pugi::xml_node node);
DiscreteIndex(gsl::span<const double> p);
DiscreteIndex(span<const double> p);

void assign(gsl::span<const double> p);
void assign(span<const double> p);

//! Sample a value from the distribution
//! \param seed Pseudorandom number seed pointer
Expand Down
5 changes: 3 additions & 2 deletions include/openmc/distribution_spatial.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "openmc/distribution.h"
#include "openmc/mesh.h"
#include "openmc/position.h"
#include "openmc/span.h"

namespace openmc {

Expand Down Expand Up @@ -104,7 +105,7 @@ class SphericalIndependent : public SpatialDistribution {
class MeshSpatial : public SpatialDistribution {
public:
explicit MeshSpatial(pugi::xml_node node);
explicit MeshSpatial(int32_t mesh_id, gsl::span<const double> strengths);
explicit MeshSpatial(int32_t mesh_id, span<const double> strengths);

//! Sample a position from the distribution
//! \param seed Pseudorandom number seed pointer
Expand Down Expand Up @@ -144,7 +145,7 @@ class PointCloud : public SpatialDistribution {
public:
explicit PointCloud(pugi::xml_node node);
explicit PointCloud(
std::vector<Position> point_cloud, gsl::span<const double> strengths);
std::vector<Position> point_cloud, span<const double> strengths);

//! Sample a position from the distribution
//! \param seed Pseudorandom number seed pointer
Expand Down
12 changes: 5 additions & 7 deletions include/openmc/interpolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#include <cmath>
#include <vector>

#include <gsl/gsl-lite.hpp>

#include "openmc/error.h"
#include "openmc/search.h"
#include "openmc/span.h"

namespace openmc {

Expand Down Expand Up @@ -36,8 +35,8 @@ inline double interpolate_log_log(
return y0 * std::exp(f * std::log(y1 / y0));
}

inline double interpolate_lagrangian(gsl::span<const double> xs,
gsl::span<const double> ys, int idx, double x, int order)
inline double interpolate_lagrangian(
span<const double> xs, span<const double> ys, int idx, double x, int order)
{
double output {0.0};

Expand All @@ -56,9 +55,8 @@ inline double interpolate_lagrangian(gsl::span<const double> xs,
return output;
}

inline double interpolate(gsl::span<const double> xs,
gsl::span<const double> ys, double x,
Interpolation i = Interpolation::lin_lin)
inline double interpolate(span<const double> xs, span<const double> ys,
double x, Interpolation i = Interpolation::lin_lin)
{
int idx = lower_bound_index(xs.begin(), xs.end(), x);

Expand Down
10 changes: 5 additions & 5 deletions include/openmc/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <string>
#include <unordered_map>

#include "openmc/span.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#include <gsl/gsl-lite.hpp>
#include <hdf5.h>

#include "openmc/bremsstrahlung.h"
Expand Down Expand Up @@ -118,21 +118,21 @@ class Material {
//
//! \param[in] density Density value
//! \param[in] units Units of density
void set_density(double density, gsl::cstring_span units);
void set_density(double density, const std::string& units);

//! Set temperature of the material
void set_temperature(double temperature) { temperature_ = temperature; };

//! Get nuclides in material
//! \return Indices into the global nuclides vector
gsl::span<const int> nuclides() const
span<const int> nuclides() const
{
return {nuclide_.data(), nuclide_.size()};
}

//! Get densities of each nuclide in material
//! \return Densities in [atom/b-cm]
gsl::span<const double> densities() const
span<const double> densities() const
{
return {atom_density_.data(), atom_density_.size()};
}
Expand Down Expand Up @@ -210,7 +210,7 @@ class Material {

//----------------------------------------------------------------------------
// Private data members
gsl::index index_;
int64_t index_;

bool depletable_ {false}; //!< Is the material depletable?
bool fissionable_ {
Expand Down
5 changes: 2 additions & 3 deletions include/openmc/mcpl_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
#define OPENMC_MCPL_INTERFACE_H

#include "openmc/particle_data.h"
#include "openmc/span.h"
#include "openmc/vector.h"

#include <gsl/gsl-lite.hpp>

#include <string>

namespace openmc {
Expand Down Expand Up @@ -36,7 +35,7 @@ vector<SourceSite> mcpl_source_sites(std::string path);
//! calculate_parallel_index_vector on
//! source_bank.size().
void write_mcpl_source_point(const char* filename,
gsl::span<SourceSite> source_bank, vector<int64_t> const& bank_index);
span<const SourceSite> source_bank, const vector<int64_t>& bank_index);
} // namespace openmc

#endif // OPENMC_MCPL_INTERFACE_H
6 changes: 3 additions & 3 deletions include/openmc/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include "hdf5.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#include <gsl/gsl-lite.hpp>

#include "openmc/bounding_box.h"
#include "openmc/error.h"
#include "openmc/memory.h" // for unique_ptr
#include "openmc/particle.h"
#include "openmc/position.h"
#include "openmc/span.h"
#include "openmc/vector.h"
#include "openmc/xml_interface.h"

Expand Down Expand Up @@ -174,8 +174,8 @@ class Mesh {
//! \param[out] Array of (material index, volume) for desired element
//! \param[inout] seed Pseudorandom number seed
//! \return Number of materials within element
int material_volumes(int n_sample, int bin, gsl::span<MaterialVolume> volumes,
uint64_t* seed) const;
int material_volumes(
int n_sample, int bin, span<MaterialVolume> volumes, uint64_t* seed) const;

//! Determine volume of materials within a single mesh elemenet
//
Expand Down
10 changes: 5 additions & 5 deletions include/openmc/nuclide.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <unordered_map>
#include <utility> // for pair

#include <gsl/gsl-lite.hpp>
#include <hdf5.h>

#include "openmc/array.h"
Expand All @@ -17,6 +16,7 @@
#include "openmc/particle.h"
#include "openmc/reaction.h"
#include "openmc/reaction_product.h"
#include "openmc/span.h"
#include "openmc/urr.h"
#include "openmc/vector.h"
#include "openmc/wmp.h"
Expand Down Expand Up @@ -81,8 +81,8 @@ class Nuclide {
//! \param[in] energy Energy group boundaries in [eV]
//! \param[in] flux Flux in each energy group (not normalized per eV)
//! \return Reaction rate
double collapse_rate(int MT, double temperature,
gsl::span<const double> energy, gsl::span<const double> flux) const;
double collapse_rate(int MT, double temperature, span<const double> energy,
span<const double> flux) const;

//============================================================================
// Data members
Expand All @@ -91,7 +91,7 @@ class Nuclide {
int A_; //!< Mass number
int metastable_; //!< Metastable state
double awr_; //!< Atomic weight ratio
gsl::index index_; //!< Index in the nuclides array
int64_t index_; //!< Index in the nuclides array

// Temperature dependent cross section data
vector<double> kTs_; //!< temperatures in eV (k*T)
Expand Down Expand Up @@ -138,7 +138,7 @@ class Nuclide {
//
//! \param[in] T Temperature in [K]
//! \return Temperature index and interpolation factor
std::pair<gsl::index, double> find_temperature(double T) const;
std::pair<int64_t, double> find_temperature(double T) const;

static int XS_TOTAL;
static int XS_ABSORPTION;
Expand Down
3 changes: 1 addition & 2 deletions include/openmc/photon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "openmc/vector.h"

#include "xtensor/xtensor.hpp"
#include <gsl/gsl-lite.hpp>
#include <hdf5.h>

#include <string>
Expand Down Expand Up @@ -61,7 +60,7 @@ class PhotonInteraction {
// Data members
std::string name_; //!< Name of element, e.g. "Zr"
int Z_; //!< Atomic number
gsl::index index_; //!< Index in global elements vector
int64_t index_; //!< Index in global elements vector

// Microscopic cross sections
xt::xtensor<double, 1> energy_;
Expand Down
8 changes: 4 additions & 4 deletions include/openmc/reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <string>

#include "hdf5.h"
#include <gsl/gsl-lite.hpp>

#include "openmc/particle_data.h"
#include "openmc/reaction_product.h"
#include "openmc/span.h"
#include "openmc/vector.h"

namespace openmc {
Expand All @@ -33,7 +33,7 @@ class Reaction {
//! \param[in] i_temp Temperature index
//! \param[in] i_grid Energy grid index
//! \param[in] interp_factor Interpolation factor between grid points
double xs(gsl::index i_temp, gsl::index i_grid, double interp_factor) const;
double xs(int64_t i_temp, int64_t i_grid, double interp_factor) const;

//! Calculate cross section
//
Expand All @@ -47,8 +47,8 @@ class Reaction {
//! \param[in] flux Flux in each energy group (not normalized per eV)
//! \param[in] grid Nuclide energy grid
//! \return Reaction rate
double collapse_rate(gsl::index i_temp, gsl::span<const double> energy,
gsl::span<const double> flux, const vector<double>& grid) const;
double collapse_rate(int64_t i_temp, span<const double> energy,
span<const double> flux, const vector<double>& grid) const;

//! Cross section at a single temperature
struct TemperatureXS {
Expand Down
Loading

0 comments on commit d17d978

Please sign in to comment.