Replace xtensor with internal Tensor/View classes (#3805)

Co-authored-by: John Tramm <jtramm@gmail.com>
This commit is contained in:
John Tramm 2026-02-17 09:50:38 -06:00 committed by GitHub
parent c6ef84d1d5
commit 977ade79a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
73 changed files with 3111 additions and 908 deletions

View file

@ -3,7 +3,7 @@
#include "openmc/particle.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
namespace openmc {
@ -14,9 +14,9 @@ namespace openmc {
class BremsstrahlungData {
public:
// Data
xt::xtensor<double, 2> pdf; //!< Bremsstrahlung energy PDF
xt::xtensor<double, 2> cdf; //!< Bremsstrahlung energy CDF
xt::xtensor<double, 1> yield; //!< Photon yield
tensor::Tensor<double> pdf; //!< Bremsstrahlung energy PDF
tensor::Tensor<double> cdf; //!< Bremsstrahlung energy CDF
tensor::Tensor<double> yield; //!< Photon yield
};
class Bremsstrahlung {
@ -32,9 +32,9 @@ public:
namespace data {
extern xt::xtensor<double, 1>
extern tensor::Tensor<double>
ttb_e_grid; //! energy T of incident electron in [eV]
extern xt::xtensor<double, 1>
extern tensor::Tensor<double>
ttb_k_grid; //! reduced energy W/T of emitted photon
} // namespace data

View file

@ -5,7 +5,7 @@
#define OPENMC_DISTRIBUTION_ENERGY_H
#include "hdf5.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/constants.h"
#include "openmc/endf.h"
@ -86,9 +86,9 @@ private:
struct CTTable {
Interpolation interpolation; //!< Interpolation law
int n_discrete; //!< Number of of discrete energies
xt::xtensor<double, 1> e_out; //!< Outgoing energies in [eV]
xt::xtensor<double, 1> p; //!< Probability density
xt::xtensor<double, 1> c; //!< Cumulative distribution
tensor::Tensor<double> e_out; //!< Outgoing energies in [eV]
tensor::Tensor<double> p; //!< Probability density
tensor::Tensor<double> c; //!< Cumulative distribution
};
int n_region_; //!< Number of inteprolation regions

View file

@ -6,7 +6,7 @@
#include <cstdint> // for int64_t
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include <hdf5.h>
#include "openmc/array.h"
@ -24,7 +24,7 @@ namespace simulation {
extern double keff_generation; //!< Single-generation k on each processor
extern array<double, 2> k_sum; //!< Used to reduce sum and sum_sq
extern vector<double> entropy; //!< Shannon entropy at each generation
extern xt::xtensor<double, 1> source_frac; //!< Source fraction for UFS
extern tensor::Tensor<double> source_frac; //!< Source fraction for UFS
} // namespace simulation

View file

@ -11,8 +11,7 @@
#include "hdf5.h"
#include "hdf5_hl.h"
#include "xtensor/xadapt.hpp"
#include "xtensor/xarray.hpp"
#include "openmc/tensor.h"
#include "openmc/array.h"
#include "openmc/error.h"
@ -166,24 +165,19 @@ void read_attribute(hid_t obj_id, const char* name, vector<T>& vec)
read_attr(obj_id, name, H5TypeMap<T>::type_id, vec.data());
}
// Generic array version
// Tensor version
template<typename T>
void read_attribute(hid_t obj_id, const char* name, xt::xarray<T>& arr)
void read_attribute(hid_t obj_id, const char* name, tensor::Tensor<T>& tensor)
{
// Get shape of attribute array
// Get shape of attribute
auto shape = attribute_shape(obj_id, name);
// Allocate new array to read data into
std::size_t size = 1;
for (const auto x : shape)
size *= x;
vector<T> buffer(size);
// Resize tensor and read data directly
vector<size_t> tshape(shape.begin(), shape.end());
tensor.resize(tshape);
// Read data from attribute
read_attr(obj_id, name, H5TypeMap<T>::type_id, buffer.data());
// Adapt array into xarray
arr = xt::adapt(buffer, shape);
read_attr(obj_id, name, H5TypeMap<T>::type_id, tensor.data());
}
// overload for std::string
@ -290,63 +284,34 @@ void read_dataset(
}
template<typename T>
void read_dataset(hid_t dset, xt::xarray<T>& arr, bool indep = false)
void read_dataset(hid_t dset, tensor::Tensor<T>& tensor, bool indep = false)
{
// Get shape of dataset
vector<hsize_t> shape = object_shape(dset);
// Allocate space in the array to read data into
std::size_t size = 1;
for (const auto x : shape)
size *= x;
arr.resize(shape);
// Resize tensor and read data directly
vector<size_t> tshape(shape.begin(), shape.end());
tensor.resize(tshape);
// Read data from attribute
// Read data from dataset
read_dataset_lowlevel(
dset, nullptr, H5TypeMap<T>::type_id, H5S_ALL, indep, arr.data());
dset, nullptr, H5TypeMap<T>::type_id, H5S_ALL, indep, tensor.data());
}
template<>
void read_dataset(
hid_t dset, xt::xarray<std::complex<double>>& arr, bool indep);
hid_t dset, tensor::Tensor<std::complex<double>>& tensor, bool indep);
template<typename T>
void read_dataset(
hid_t obj_id, const char* name, xt::xarray<T>& arr, bool indep = false)
hid_t obj_id, const char* name, tensor::Tensor<T>& tensor, bool indep = false)
{
// Open dataset and read array
// Open dataset and read tensor
hid_t dset = open_dataset(obj_id, name);
read_dataset(dset, arr, indep);
read_dataset(dset, tensor, indep);
close_dataset(dset);
}
template<typename T, std::size_t N>
void read_dataset(
hid_t obj_id, const char* name, xt::xtensor<T, N>& arr, bool indep = false)
{
// Open dataset and read array
hid_t dset = open_dataset(obj_id, name);
// Get shape of dataset
vector<hsize_t> hsize_t_shape = object_shape(dset);
close_dataset(dset);
// cast from hsize_t to size_t
vector<size_t> shape(hsize_t_shape.size());
for (int i = 0; i < shape.size(); i++) {
shape[i] = static_cast<size_t>(hsize_t_shape[i]);
}
// Allocate new xarray to read data into
xt::xarray<T> xarr(shape);
// Read data from the dataset
read_dataset(obj_id, name, xarr);
// Copy into xtensor
arr = xarr;
}
// overload for Position
inline void read_dataset(
hid_t obj_id, const char* name, Position& r, bool indep = false)
@ -358,31 +323,22 @@ inline void read_dataset(
r.z = x[2];
}
template<typename T, std::size_t N>
template<typename T>
inline void read_dataset_as_shape(
hid_t obj_id, const char* name, xt::xtensor<T, N>& arr, bool indep = false)
hid_t obj_id, const char* name, tensor::Tensor<T>& tensor, bool indep = false)
{
hid_t dset = open_dataset(obj_id, name);
// Allocate new array to read data into
std::size_t size = 1;
for (const auto x : arr.shape())
size *= x;
vector<T> buffer(size);
// Read data from attribute
// Read data directly into pre-shaped tensor
read_dataset_lowlevel(
dset, nullptr, H5TypeMap<T>::type_id, H5S_ALL, indep, buffer.data());
// Adapt into xarray
arr = xt::adapt(buffer, arr.shape());
dset, nullptr, H5TypeMap<T>::type_id, H5S_ALL, indep, tensor.data());
close_dataset(dset);
}
template<typename T, std::size_t N>
inline void read_nd_vector(hid_t obj_id, const char* name,
xt::xtensor<T, N>& result, bool must_have = false)
template<typename T>
inline void read_nd_tensor(hid_t obj_id, const char* name,
tensor::Tensor<T>& result, bool must_have = false)
{
if (object_exists(obj_id, name)) {
read_dataset_as_shape(obj_id, name, result, true);
@ -496,12 +452,16 @@ inline void write_dataset(
false, buffer.data());
}
// Template for xarray, xtensor, etc.
template<typename D>
inline void write_dataset(
hid_t obj_id, const char* name, const xt::xcontainer<D>& arr)
// Template for Tensor and StaticTensor2D. A SFINAE guard is used here to
// prevent this template from matching vector/string types that have their own
// overloads above. A generic Container parameter avoids duplicating the body
// for both Tensor<T> and StaticTensor2D<T,R,C>.
template<typename Container,
typename =
std::enable_if_t<tensor::is_tensor<std::decay_t<Container>>::value>>
inline void write_dataset(hid_t obj_id, const char* name, const Container& arr)
{
using T = typename D::value_type;
using T = typename std::decay_t<Container>::value_type;
auto s = arr.shape();
vector<hsize_t> dims {s.cbegin(), s.cend()};
write_dataset_lowlevel(obj_id, dims.size(), dims.data(), name,

View file

@ -5,8 +5,8 @@
#include <unordered_map>
#include "openmc/span.h"
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#include <hdf5.h>
#include "openmc/bremsstrahlung.h"
@ -189,7 +189,7 @@ public:
vector<int> nuclide_; //!< Indices in nuclides vector
vector<int> element_; //!< Indices in elements vector
NCrystalMat ncrystal_mat_; //!< NCrystal material object
xt::xtensor<double, 1> atom_density_; //!< Nuclide atom density in [atom/b-cm]
tensor::Tensor<double> atom_density_; //!< Nuclide atom density in [atom/b-cm]
double density_; //!< Total atom density in [atom/b-cm]
double density_gpcc_; //!< Total atom density in [g/cm^3]
double charge_density_; //!< Total charge density in [e/b-cm]

View file

@ -8,8 +8,8 @@
#include <unordered_map>
#include "hdf5.h"
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#include "openmc/bounding_box.h"
#include "openmc/error.h"
@ -284,8 +284,8 @@ public:
virtual Position upper_right() const = 0;
// Data members
xt::xtensor<double, 1> lower_left_; //!< Lower-left coordinates of mesh
xt::xtensor<double, 1> upper_right_; //!< Upper-right coordinates of mesh
tensor::Tensor<double> lower_left_; //!< Lower-left coordinates of mesh
tensor::Tensor<double> upper_right_; //!< Upper-right coordinates of mesh
int id_ {-1}; //!< Mesh ID
std::string name_; //!< User-specified name
int n_dimension_ {-1}; //!< Number of dimensions
@ -348,7 +348,7 @@ public:
//! \param[in] Pointer to bank sites
//! \param[in] Number of bank sites
//! \param[out] Whether any bank sites are outside the mesh
xt::xtensor<double, 1> count_sites(
tensor::Tensor<double> count_sites(
const SourceSite* bank, int64_t length, bool* outside) const;
//! Get bin given mesh indices
@ -419,8 +419,8 @@ public:
//! Get a label for the mesh bin
std::string bin_label(int bin) const override;
//! Get shape as xt::xtensor
xt::xtensor<int, 1> get_x_shape() const;
//! Get mesh dimensions as a tensor
tensor::Tensor<int> get_shape_tensor() const;
double volume(int bin) const override
{
@ -515,7 +515,7 @@ public:
//! \param[in] bank Array of bank sites
//! \param[out] Whether any bank sites are outside the mesh
//! \return Array indicating number of sites in each mesh/energy bin
xt::xtensor<double, 1> count_sites(
tensor::Tensor<double> count_sites(
const SourceSite* bank, int64_t length, bool* outside) const;
//! Return the volume for a given mesh index
@ -526,7 +526,7 @@ public:
// Data members
double volume_frac_; //!< Volume fraction of each mesh element
double element_volume_; //!< Volume of each mesh element
xt::xtensor<double, 1> width_; //!< Width of each mesh element
tensor::Tensor<double> width_; //!< Width of each mesh element
};
class RectilinearMesh : public StructuredMesh {

View file

@ -6,7 +6,7 @@
#include <string>
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/constants.h"
#include "openmc/hdf5_interface.h"
@ -22,7 +22,7 @@ namespace openmc {
class Mgxs {
private:
xt::xtensor<double, 1> kTs; // temperature in eV (k * T)
tensor::Tensor<double> kTs; // temperature in eV (k * T)
AngleDistributionType
scatter_format; // flag for if this is legendre, histogram, or tabular
int num_groups; // number of energy groups

View file

@ -96,7 +96,7 @@ public:
// Temperature dependent cross section data
vector<double> kTs_; //!< temperatures in eV (k*T)
vector<EnergyGrid> grid_; //!< Energy grid at each temperature
vector<xt::xtensor<double, 2>> xs_; //!< Cross sections at each temperature
vector<tensor::Tensor<double>> xs_; //!< Cross sections at each temperature
// Multipole data
unique_ptr<WindowedMultipole> multipole_;

View file

@ -6,7 +6,7 @@
#include "openmc/particle.h"
#include "openmc/vector.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include <hdf5.h>
#include <string>
@ -62,14 +62,14 @@ public:
int64_t index_; //!< Index in global elements vector
// Microscopic cross sections
xt::xtensor<double, 1> energy_;
xt::xtensor<double, 1> coherent_;
xt::xtensor<double, 1> incoherent_;
xt::xtensor<double, 1> photoelectric_total_;
xt::xtensor<double, 1> pair_production_total_;
xt::xtensor<double, 1> pair_production_electron_;
xt::xtensor<double, 1> pair_production_nuclear_;
xt::xtensor<double, 1> heating_;
tensor::Tensor<double> energy_;
tensor::Tensor<double> coherent_;
tensor::Tensor<double> incoherent_;
tensor::Tensor<double> photoelectric_total_;
tensor::Tensor<double> pair_production_total_;
tensor::Tensor<double> pair_production_electron_;
tensor::Tensor<double> pair_production_nuclear_;
tensor::Tensor<double> heating_;
// Form factors
Tabulated1D incoherent_form_factor_;
@ -81,27 +81,27 @@ public:
// stored separately to improve memory access pattern when calculating the
// total cross section
vector<ElectronSubshell> shells_;
xt::xtensor<double, 2> cross_sections_;
tensor::Tensor<double> cross_sections_;
// Compton profile data
xt::xtensor<double, 2> profile_pdf_;
xt::xtensor<double, 2> profile_cdf_;
xt::xtensor<double, 1> binding_energy_;
xt::xtensor<double, 1> electron_pdf_;
tensor::Tensor<double> profile_pdf_;
tensor::Tensor<double> profile_cdf_;
tensor::Tensor<double> binding_energy_;
tensor::Tensor<double> electron_pdf_;
// Map subshells from Compton profile data obtained from Biggs et al,
// "Hartree-Fock Compton profiles for the elements" to ENDF/B atomic
// relaxation data
xt::xtensor<int, 1> subshell_map_;
tensor::Tensor<int> subshell_map_;
// Stopping power data
double I_; // mean excitation energy
xt::xtensor<int, 1> n_electrons_;
xt::xtensor<double, 1> ionization_energy_;
xt::xtensor<double, 1> stopping_power_radiative_;
tensor::Tensor<int> n_electrons_;
tensor::Tensor<double> ionization_energy_;
tensor::Tensor<double> stopping_power_radiative_;
// Bremsstrahlung scaled DCS
xt::xtensor<double, 2> dcs_;
tensor::Tensor<double> dcs_;
// Whether atomic relaxation data is present
bool has_atomic_relaxation_ {false};
@ -137,7 +137,7 @@ void free_memory_photon();
namespace data {
extern xt::xtensor<double, 1>
extern tensor::Tensor<double>
compton_profile_pz; //! Compton profile momentum grid
//! Photon interaction data for each element

View file

@ -6,8 +6,8 @@
#include <unordered_map>
#include <unordered_set>
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xarray.hpp"
#include "hdf5.h"
#include "openmc/cell.h"
@ -90,7 +90,7 @@ const RGBColor BLACK {0, 0, 0};
* visualized.
*/
typedef xt::xtensor<RGBColor, 2> ImageData;
typedef tensor::Tensor<RGBColor> ImageData;
class PlottableInterface {
public:
PlottableInterface() = default;
@ -154,7 +154,7 @@ struct IdData {
void set_overlap(size_t y, size_t x);
// Members
xt::xtensor<int32_t, 3> data_; //!< 2D array of cell & material ids
tensor::Tensor<int32_t> data_; //!< 2D array of cell & material ids
};
struct PropertyData {
@ -166,7 +166,7 @@ struct PropertyData {
void set_overlap(size_t y, size_t x);
// Members
xt::xtensor<double, 3> data_; //!< 2D array of temperature & density data
tensor::Tensor<double> data_; //!< 2D array of temperature & density data
};
//===============================================================================

View file

@ -178,10 +178,10 @@ protected:
// Volumes for each tally and bin/score combination. This intermediate data
// structure is used when tallying quantities that must be normalized by
// volume (i.e., flux). The vector is index by tally index, while the inner 2D
// xtensor is indexed by bin index and score index in a similar manner to the
// tensor is indexed by bin index and score index in a similar manner to the
// results tensor in the Tally class, though without the third dimension, as
// SUM and SUM_SQ do not need to be tracked.
vector<xt::xtensor<double, 2>> tally_volumes_;
vector<tensor::Tensor<double>> tally_volumes_;
}; // class FlatSourceDomain

View file

@ -4,7 +4,7 @@
#ifndef OPENMC_SCATTDATA_H
#define OPENMC_SCATTDATA_H
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/constants.h"
#include "openmc/vector.h"
@ -26,23 +26,23 @@ public:
protected:
//! \brief Initializes the attributes of the base class.
void base_init(int order, const xt::xtensor<int, 1>& in_gmin,
const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_energy,
void base_init(int order, const tensor::Tensor<int>& in_gmin,
const tensor::Tensor<int>& in_gmax, const double_2dvec& in_energy,
const double_2dvec& in_mult);
//! \brief Combines microscopic ScattDatas into a macroscopic one.
void base_combine(size_t max_order, size_t order_dim,
const vector<ScattData*>& those_scatts, const vector<double>& scalars,
xt::xtensor<int, 1>& in_gmin, xt::xtensor<int, 1>& in_gmax,
tensor::Tensor<int>& in_gmin, tensor::Tensor<int>& in_gmax,
double_2dvec& sparse_mult, double_3dvec& sparse_scatter);
public:
double_2dvec energy; // Normalized p0 matrix for sampling Eout
double_2dvec mult; // nu-scatter multiplication (nu-scatt/scatt)
double_3dvec dist; // Angular distribution
xt::xtensor<int, 1> gmin; // minimum outgoing group
xt::xtensor<int, 1> gmax; // maximum outgoing group
xt::xtensor<double, 1> scattxs; // Isotropic Sigma_{s,g_{in}}
tensor::Tensor<int> gmin; // minimum outgoing group
tensor::Tensor<int> gmax; // maximum outgoing group
tensor::Tensor<double> scattxs; // Isotropic Sigma_{s,g_{in}}
//! \brief Calculates the value of normalized f(mu).
//!
@ -72,8 +72,8 @@ public:
//! @param in_gmax List of maximum outgoing groups for every incoming group
//! @param in_mult Input sparse multiplicity matrix
//! @param coeffs Input sparse scattering matrix
virtual void init(const xt::xtensor<int, 1>& in_gmin,
const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
virtual void init(const tensor::Tensor<int>& in_gmin,
const tensor::Tensor<int>& in_gmax, const double_2dvec& in_mult,
const double_3dvec& coeffs) = 0;
//! \brief Combines the microscopic data.
@ -96,7 +96,7 @@ public:
//! @param max_order If Legendre this is the maximum value of "n" in "Pn"
//! requested; ignored otherwise.
//! @return The dense scattering matrix.
virtual xt::xtensor<double, 3> get_matrix(size_t max_order) = 0;
virtual tensor::Tensor<double> get_matrix(size_t max_order) = 0;
//! \brief Samples the outgoing energy from the ScattData info.
//!
@ -135,8 +135,8 @@ protected:
ScattDataLegendre& leg, ScattDataTabular& tab);
public:
void init(const xt::xtensor<int, 1>& in_gmin,
const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
void init(const tensor::Tensor<int>& in_gmin,
const tensor::Tensor<int>& in_gmax, const double_2dvec& in_mult,
const double_3dvec& coeffs) override;
void combine(const vector<ScattData*>& those_scatts,
@ -153,7 +153,7 @@ public:
size_t get_order() override { return dist[0][0].size() - 1; };
xt::xtensor<double, 3> get_matrix(size_t max_order) override;
tensor::Tensor<double> get_matrix(size_t max_order) override;
};
//==============================================================================
@ -164,13 +164,13 @@ public:
class ScattDataHistogram : public ScattData {
protected:
xt::xtensor<double, 1> mu; // Angle distribution mu bin boundaries
tensor::Tensor<double> mu; // Angle distribution mu bin boundaries
double dmu; // Quick storage of the mu spacing
double_3dvec fmu; // The angular distribution histogram
public:
void init(const xt::xtensor<int, 1>& in_gmin,
const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
void init(const tensor::Tensor<int>& in_gmin,
const tensor::Tensor<int>& in_gmax, const double_2dvec& in_mult,
const double_3dvec& coeffs) override;
void combine(const vector<ScattData*>& those_scatts,
@ -183,7 +183,7 @@ public:
size_t get_order() override { return dist[0][0].size(); };
xt::xtensor<double, 3> get_matrix(size_t max_order) override;
tensor::Tensor<double> get_matrix(size_t max_order) override;
};
//==============================================================================
@ -194,7 +194,7 @@ public:
class ScattDataTabular : public ScattData {
protected:
xt::xtensor<double, 1> mu; // Angle distribution mu grid points
tensor::Tensor<double> mu; // Angle distribution mu grid points
double dmu; // Quick storage of the mu spacing
double_3dvec fmu; // The angular distribution function
@ -204,8 +204,8 @@ protected:
ScattDataLegendre& leg, ScattDataTabular& tab);
public:
void init(const xt::xtensor<int, 1>& in_gmin,
const xt::xtensor<int, 1>& in_gmax, const double_2dvec& in_mult,
void init(const tensor::Tensor<int>& in_gmin,
const tensor::Tensor<int>& in_gmax, const double_2dvec& in_mult,
const double_3dvec& coeffs) override;
void combine(const vector<ScattData*>& those_scatts,
@ -218,7 +218,7 @@ public:
size_t get_order() override { return dist[0][0].size(); };
xt::xtensor<double, 3> get_matrix(size_t max_order) override;
tensor::Tensor<double> get_matrix(size_t max_order) override;
};
//==============================================================================

View file

@ -5,7 +5,7 @@
#define OPENMC_SECONDARY_CORRELATED_H
#include "hdf5.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/angle_energy.h"
#include "openmc/distribution.h"
@ -25,9 +25,9 @@ public:
struct CorrTable {
int n_discrete; //!< Number of discrete lines
Interpolation interpolation; //!< Interpolation law
xt::xtensor<double, 1> e_out; //!< Outgoing energies [eV]
xt::xtensor<double, 1> p; //!< Probability density
xt::xtensor<double, 1> c; //!< Cumulative distribution
tensor::Tensor<double> e_out; //!< Outgoing energies [eV]
tensor::Tensor<double> p; //!< Probability density
tensor::Tensor<double> c; //!< Cumulative distribution
vector<unique_ptr<Tabular>> angle; //!< Angle distribution
};

View file

@ -5,7 +5,7 @@
#define OPENMC_SECONDARY_KALBACH_H
#include "hdf5.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/angle_energy.h"
#include "openmc/constants.h"
@ -37,11 +37,11 @@ private:
struct KMTable {
int n_discrete; //!< Number of discrete lines
Interpolation interpolation; //!< Interpolation law
xt::xtensor<double, 1> e_out; //!< Outgoing energies [eV]
xt::xtensor<double, 1> p; //!< Probability density
xt::xtensor<double, 1> c; //!< Cumulative distribution
xt::xtensor<double, 1> r; //!< Pre-compound fraction
xt::xtensor<double, 1> a; //!< Parameterized function
tensor::Tensor<double> e_out; //!< Outgoing energies [eV]
tensor::Tensor<double> p; //!< Probability density
tensor::Tensor<double> c; //!< Cumulative distribution
tensor::Tensor<double> r; //!< Pre-compound fraction
tensor::Tensor<double> a; //!< Parameterized function
};
int n_region_; //!< Number of interpolation regions

View file

@ -9,7 +9,7 @@
#include "openmc/secondary_correlated.h"
#include "openmc/vector.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include <hdf5.h>
namespace openmc {
@ -83,7 +83,7 @@ public:
private:
const vector<double>& energy_; //!< Energies at which cosines are tabulated
xt::xtensor<double, 2> mu_out_; //!< Cosines for each incident energy
tensor::Tensor<double> mu_out_; //!< Cosines for each incident energy
};
//==============================================================================
@ -109,9 +109,9 @@ public:
private:
const vector<double>& energy_; //!< Incident energies
xt::xtensor<double, 2>
tensor::Tensor<double>
energy_out_; //!< Outgoing energies for each incident energy
xt::xtensor<double, 3>
tensor::Tensor<double>
mu_out_; //!< Outgoing cosines for each incident/outgoing energy
bool skewed_; //!< Whether outgoing energy distribution is skewed
};
@ -139,10 +139,10 @@ private:
//! Secondary energy/angle distribution
struct DistEnergySab {
std::size_t n_e_out; //!< Number of outgoing energies
xt::xtensor<double, 1> e_out; //!< Outgoing energies
xt::xtensor<double, 1> e_out_pdf; //!< Probability density function
xt::xtensor<double, 1> e_out_cdf; //!< Cumulative distribution function
xt::xtensor<double, 2> mu; //!< Equiprobable angles at each outgoing energy
tensor::Tensor<double> e_out; //!< Outgoing energies
tensor::Tensor<double> e_out_pdf; //!< Probability density function
tensor::Tensor<double> e_out_cdf; //!< Cumulative distribution function
tensor::Tensor<double> mu; //!< Equiprobable angles at each outgoing energy
};
vector<double> energy_; //!< Incident energies

View file

@ -8,9 +8,8 @@
#include "openmc/tallies/trigger.h"
#include "openmc/vector.h"
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xfixed.hpp"
#include "xtensor/xtensor.hpp"
#include <string>
#include <unordered_map>
@ -55,7 +54,7 @@ public:
void set_nuclides(const vector<std::string>& nuclides);
const xt::xtensor<double, 3>& results() const { return results_; }
const tensor::Tensor<double>& results() const { return results_; }
//! returns vector of indices corresponding to the tally this is called on
const vector<int32_t>& filters() const { return filters_; }
@ -125,7 +124,7 @@ public:
int score_index(const std::string& score) const;
//! Tally results reshaped according to filter sizes
xt::xarray<double> get_reshaped_data() const;
tensor::Tensor<double> get_reshaped_data() const;
//! A string representing the i-th score on this tally
std::string score_name(int score_idx) const;
@ -160,7 +159,7 @@ public:
//! combination of filters (e.g. specific cell, specific energy group, etc.)
//! and the second dimension of the array is for scores (e.g. flux, total
//! reaction rate, fission reaction rate, etc.)
xt::xtensor<double, 3> results_;
tensor::Tensor<double> results_;
//! True if this tally should be written to statepoint files
bool writable_ {true};
@ -220,8 +219,7 @@ extern vector<double> time_grid;
namespace simulation {
//! Global tallies (such as k-effective estimators)
extern xt::xtensor_fixed<double, xt::xshape<N_GLOBAL_TALLIES, 3>>
global_tallies;
extern tensor::StaticTensor2D<double, N_GLOBAL_TALLIES, 3> global_tallies;
//! Number of realizations for global tallies
extern "C" int32_t n_realizations;
@ -257,12 +255,6 @@ double distance_to_time_boundary(double time, double speed);
//! Determine which tallies should be active
void setup_active_tallies();
// Alias for the type returned by xt::adapt(...). N is the dimension of the
// multidimensional array
template<std::size_t N>
using adaptor_type =
xt::xtensor_adaptor<xt::xbuffer_adaptor<double*&, xt::no_ownership>, N>;
#ifdef OPENMC_MPI
//! Collect all tally results onto master process
void reduce_tally_results();

1185
include/openmc/tensor.h Normal file

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,7 @@
#include <string>
#include <unordered_map>
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/angle_energy.h"
#include "openmc/endf.h"

View file

@ -3,7 +3,7 @@
#ifndef OPENMC_URR_H
#define OPENMC_URR_H
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/constants.h"
#include "openmc/hdf5_interface.h"
@ -40,11 +40,11 @@ public:
* below, obviously, values of the CDF are stored. For the xs_values
* variable, the columns line up with the index of cdf_values.
*/
xt::xtensor<double, 2> cdf_values_; // Note: must be row major!
xt::xtensor<XSSet, 2> xs_values_;
tensor::Tensor<double> cdf_values_; // Note: must be row major!
tensor::Tensor<XSSet> xs_values_;
// Number of points in the CDF
auto n_cdf() const { return cdf_values_.shape()[1]; }
auto n_cdf() const { return cdf_values_.shape(1); }
//! \brief Load the URR data from the provided HDF5 group
explicit UrrData(hid_t group_id);

View file

@ -12,8 +12,8 @@
#include "openmc/tallies/trigger.h"
#include "openmc/vector.h"
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
#ifdef _OPENMP
#include <omp.h>
#endif

View file

@ -143,10 +143,10 @@ public:
const vector<double>& energy_bounds() const { return energy_bounds_; }
void set_bounds(const xt::xtensor<double, 2>& lower_ww_bounds,
const xt::xtensor<double, 2>& upper_bounds);
void set_bounds(const tensor::Tensor<double>& lower_ww_bounds,
const tensor::Tensor<double>& upper_bounds);
void set_bounds(const xt::xtensor<double, 2>& lower_bounds, double ratio);
void set_bounds(const tensor::Tensor<double>& lower_bounds, double ratio);
void set_bounds(
span<const double> lower_bounds, span<const double> upper_bounds);
@ -182,11 +182,11 @@ public:
const std::unique_ptr<Mesh>& mesh() const { return model::meshes[mesh_idx_]; }
const xt::xtensor<double, 2>& lower_ww_bounds() const { return lower_ww_; }
xt::xtensor<double, 2>& lower_ww_bounds() { return lower_ww_; }
const tensor::Tensor<double>& lower_ww_bounds() const { return lower_ww_; }
tensor::Tensor<double>& lower_ww_bounds() { return lower_ww_; }
const xt::xtensor<double, 2>& upper_ww_bounds() const { return upper_ww_; }
xt::xtensor<double, 2>& upper_ww_bounds() { return upper_ww_; }
const tensor::Tensor<double>& upper_ww_bounds() const { return upper_ww_; }
tensor::Tensor<double>& upper_ww_bounds() { return upper_ww_; }
ParticleType particle_type() const { return particle_type_; }
@ -197,9 +197,9 @@ private:
int64_t index_; //!< Index into weight windows vector
ParticleType particle_type_; //!< Particle type to apply weight windows to
vector<double> energy_bounds_; //!< Energy boundaries [eV]
xt::xtensor<double, 2> lower_ww_; //!< Lower weight window bounds (shape:
tensor::Tensor<double> lower_ww_; //!< Lower weight window bounds (shape:
//!< energy_bins, mesh_bins (k, j, i))
xt::xtensor<double, 2>
tensor::Tensor<double>
upper_ww_; //!< Upper weight window bounds (shape: energy_bins, mesh_bins)
double survival_ratio_ {3.0}; //!< Survival weight ratio
double max_lb_ratio_ {1.0}; //!< Maximum lower bound to particle weight ratio

View file

@ -2,7 +2,7 @@
#define OPENMC_WMP_H
#include "hdf5.h"
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include <complex>
#include <string>
@ -78,9 +78,9 @@ public:
int fit_order_; //!< Order of the fit
bool fissionable_; //!< Is the nuclide fissionable?
vector<WindowInfo> window_info_; // Information about a window
xt::xtensor<double, 3>
tensor::Tensor<double>
curvefit_; // Curve fit coefficients (window, poly order, reaction)
xt::xtensor<std::complex<double>, 2> data_; //!< Poles and residues
tensor::Tensor<std::complex<double>> data_; //!< Poles and residues
// Constant data
static constexpr int MAX_POLY_COEFFICIENTS =

View file

@ -5,9 +5,8 @@
#include <sstream> // for stringstream
#include <string>
#include "openmc/tensor.h"
#include "pugixml.hpp"
#include "xtensor/xadapt.hpp"
#include "xtensor/xarray.hpp"
#include "openmc/position.h"
#include "openmc/vector.h"
@ -42,12 +41,11 @@ vector<T> get_node_array(
}
template<typename T>
xt::xarray<T> get_node_xarray(
tensor::Tensor<T> get_node_tensor(
pugi::xml_node node, const char* name, bool lowercase = false)
{
vector<T> v = get_node_array<T>(node, name, lowercase);
vector<std::size_t> shape = {v.size()};
return xt::adapt(v, shape);
return tensor::Tensor<T>(v.data(), v.size());
}
std::vector<Position> get_node_position_array(

View file

@ -4,7 +4,7 @@
#ifndef OPENMC_XSDATA_H
#define OPENMC_XSDATA_H
#include "xtensor/xtensor.hpp"
#include "openmc/tensor.h"
#include "openmc/hdf5_interface.h"
#include "openmc/memory.h"
@ -69,26 +69,26 @@ private:
public:
// The following quantities have the following dimensions:
// [angle][incoming group]
xt::xtensor<double, 2> total;
xt::xtensor<double, 2> absorption;
xt::xtensor<double, 2> nu_fission;
xt::xtensor<double, 2> prompt_nu_fission;
xt::xtensor<double, 2> kappa_fission;
xt::xtensor<double, 2> fission;
xt::xtensor<double, 2> inverse_velocity;
tensor::Tensor<double> total;
tensor::Tensor<double> absorption;
tensor::Tensor<double> nu_fission;
tensor::Tensor<double> prompt_nu_fission;
tensor::Tensor<double> kappa_fission;
tensor::Tensor<double> fission;
tensor::Tensor<double> inverse_velocity;
// decay_rate has the following dimensions:
// [angle][delayed group]
xt::xtensor<double, 2> decay_rate;
tensor::Tensor<double> decay_rate;
// delayed_nu_fission has the following dimensions:
// [angle][delayed group][incoming group]
xt::xtensor<double, 3> delayed_nu_fission;
tensor::Tensor<double> delayed_nu_fission;
// chi_prompt has the following dimensions:
// [angle][incoming group][outgoing group]
xt::xtensor<double, 3> chi_prompt;
tensor::Tensor<double> chi_prompt;
// chi_delayed has the following dimensions:
// [angle][incoming group][outgoing group][delayed group]
xt::xtensor<double, 4> chi_delayed;
tensor::Tensor<double> chi_delayed;
// scatter has the following dimensions: [angle]
vector<std::shared_ptr<ScattData>> scatter;