Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into range-calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
amandalund committed Feb 9, 2025
2 parents a7b9386 + 03e405a commit 249bd09
Show file tree
Hide file tree
Showing 42 changed files with 195 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/celeritas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ list(APPEND SOURCES
global/DebugIO.json.cc
global/KernelContextException.cc
global/Stepper.cc
grid/GenericGridBuilder.cc
grid/NonuniformGridBuilder.cc
grid/RangeGridCalculator.cc
grid/SplineDerivCalculator.cc
grid/TwodGridBuilder.cc
Expand Down
8 changes: 4 additions & 4 deletions src/celeritas/em/data/LivermorePEData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "corecel/math/Quantity.hh"
#include "celeritas/Quantities.hh"
#include "celeritas/Types.hh"
#include "celeritas/grid/GenericGridData.hh"
#include "celeritas/grid/NonuniformGridData.hh"

namespace celeritas
{
Expand All @@ -36,7 +36,7 @@ struct LivermoreSubshell
Energy binding_energy;

// Tabulated subshell photoionization cross section (used below 5 keV)
GenericGridRecord xs;
NonuniformGridRecord xs;

// Fit parameters for the integrated subshell photoionization cross
// sections in the two different energy ranges (used above 5 keV)
Expand All @@ -60,12 +60,12 @@ struct LivermoreElement
// TOTAL CROSS SECTIONS

// Total cross section below the K-shell energy. Uses linear interpolation.
GenericGridRecord xs_lo;
NonuniformGridRecord xs_lo;

// Total cross section above the K-shell energy but below the energy
// threshold for the parameterized cross sections. Uses spline
// interpolation.
GenericGridRecord xs_hi;
NonuniformGridRecord xs_hi;

// SUBSHELL CROSS SECTIONS

Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/interactor/LivermorePEInteractor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "celeritas/Quantities.hh"
#include "celeritas/em/data/LivermorePEData.hh"
#include "celeritas/em/xs/LivermorePEMicroXsCalculator.hh"
#include "celeritas/grid/GenericCalculator.hh"
#include "celeritas/grid/NonuniformGridCalculator.hh"
#include "celeritas/phys/CutoffView.hh"
#include "celeritas/phys/Interaction.hh"
#include "celeritas/phys/InteractionUtils.hh"
Expand Down Expand Up @@ -250,7 +250,7 @@ CELER_FUNCTION SubshellId LivermorePEInteractor::sample_subshell(Engine& rng) co
}

// Use the tabulated subshell cross sections
GenericCalculator calc_xs(shell.xs, shared_.xs.reals);
NonuniformGridCalculator calc_xs(shell.xs, shared_.xs.reals);
xs += inv_cube_energy * calc_xs(inc_energy_);

if (xs > cutoff)
Expand Down
4 changes: 2 additions & 2 deletions src/celeritas/em/model/detail/LivermoreXsInserter.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "corecel/data/CollectionBuilder.hh"
#include "celeritas/em/data/LivermorePEData.hh"
#include "celeritas/grid/GenericGridBuilder.hh"
#include "celeritas/grid/NonuniformGridBuilder.hh"
#include "celeritas/io/ImportLivermorePE.hh"
#include "celeritas/io/ImportPhysicsVector.hh"

Expand Down Expand Up @@ -36,7 +36,7 @@ class LivermoreXsInserter
inline void operator()(ImportLivermorePE const& inp);

private:
GenericGridBuilder build_grid_;
NonuniformGridBuilder build_grid_;

CollectionBuilder<LivermoreSubshell> shells_;
CollectionBuilder<LivermoreElement, MemSpace::host, ElementId> elements_;
Expand Down
6 changes: 3 additions & 3 deletions src/celeritas/em/params/detail/MscParamsHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ void MscParamsHelper::build_xs(XsValues* scaled_xs, Values* reals) const
xs.reserve(par_ids_.size() * num_materials);

// TODO: simplify when refactoring ValueGridInserter, etc
ValueGridInserter::XsGridCollection xgc;
ValueGridInserter vgi{reals, &xgc};
ValueGridInserter::GridValues grids;
ValueGridInserter vgi{reals, &grids};

for (size_type mat_idx : range(num_materials))
{
Expand All @@ -122,7 +122,7 @@ void MscParamsHelper::build_xs(XsValues* scaled_xs, Values* reals) const
make_span(pvec.y));
auto grid_id = vgb->build(vgi);
CELER_ASSERT(grid_id.get() == xs.size());
xs.push_back(xgc[grid_id]);
xs.push_back(grids[grid_id]);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/celeritas/em/xs/LivermorePEMicroXsCalculator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "celeritas/Quantities.hh"
#include "celeritas/Types.hh"
#include "celeritas/em/data/LivermorePEData.hh"
#include "celeritas/grid/GenericCalculator.hh"
#include "celeritas/grid/NonuniformGridCalculator.hh"

namespace celeritas
{
Expand Down Expand Up @@ -91,14 +91,14 @@ auto LivermorePEMicroXsCalculator::operator()(ElementId el_id) const -> BarnXs
{
// Use tabulated cross sections above K-shell energy but below energy
// limit for parameterization
GenericCalculator calc_xs(el.xs_hi, shared_.xs.reals);
NonuniformGridCalculator calc_xs(el.xs_hi, shared_.xs.reals);
result = ipow<3>(inv_energy) * calc_xs(energy.value());
}
else
{
CELER_ASSERT(el.xs_lo);
// Use tabulated cross sections below K-shell energy
GenericCalculator calc_xs(el.xs_lo, shared_.xs.reals);
NonuniformGridCalculator calc_xs(el.xs_lo, shared_.xs.reals);
result = ipow<3>(inv_energy) * calc_xs(energy.value());
}
return BarnXs{result};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/grid/GenericGridBuilder.cc
//! \file celeritas/grid/NonuniformGridBuilder.cc
//---------------------------------------------------------------------------//
#include "GenericGridBuilder.hh"
#include "NonuniformGridBuilder.hh"

#include "celeritas/io/ImportPhysicsVector.hh"

Expand All @@ -14,7 +14,8 @@ namespace celeritas
/*!
* Construct with pointers to data that will be modified.
*/
GenericGridBuilder::GenericGridBuilder(Items<real_type>* reals) : reals_{reals}
NonuniformGridBuilder::NonuniformGridBuilder(Items<real_type>* reals)
: reals_{reals}
{
CELER_EXPECT(reals);
}
Expand All @@ -23,8 +24,8 @@ GenericGridBuilder::GenericGridBuilder(Items<real_type>* reals) : reals_{reals}
/*!
* Add a grid of generic data with linear interpolation.
*/
auto GenericGridBuilder::operator()(SpanConstFlt grid,
SpanConstFlt values) -> Grid
auto NonuniformGridBuilder::operator()(SpanConstFlt grid, SpanConstFlt values)
-> Grid
{
return this->insert_impl(grid, values);
}
Expand All @@ -33,8 +34,8 @@ auto GenericGridBuilder::operator()(SpanConstFlt grid,
/*!
* Add a grid of generic data with linear interpolation.
*/
auto GenericGridBuilder::operator()(SpanConstDbl grid,
SpanConstDbl values) -> Grid
auto NonuniformGridBuilder::operator()(SpanConstDbl grid, SpanConstDbl values)
-> Grid
{
return this->insert_impl(grid, values);
}
Expand All @@ -43,7 +44,7 @@ auto GenericGridBuilder::operator()(SpanConstDbl grid,
/*!
* Add a grid from an imported physics vector.
*/
auto GenericGridBuilder::operator()(ImportPhysicsVector const& pvec) -> Grid
auto NonuniformGridBuilder::operator()(ImportPhysicsVector const& pvec) -> Grid
{
CELER_EXPECT(pvec.vector_type == ImportPhysicsVectorType::free);
return this->insert_impl(make_span(pvec.x), make_span(pvec.y));
Expand All @@ -54,8 +55,8 @@ auto GenericGridBuilder::operator()(ImportPhysicsVector const& pvec) -> Grid
* Add a grid from container references.
*/
template<class T>
auto GenericGridBuilder::insert_impl(Span<T const> grid,
Span<T const> values) -> Grid
auto NonuniformGridBuilder::insert_impl(Span<T const> grid,
Span<T const> values) -> Grid
{
CELER_EXPECT(grid.size() >= 2);
CELER_EXPECT(grid.front() <= grid.back());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/grid/GenericGridBuilder.hh
//! \file celeritas/grid/NonuniformGridBuilder.hh
//---------------------------------------------------------------------------//
#pragma once

#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "corecel/data/DedupeCollectionBuilder.hh"

#include "GenericGridData.hh"
#include "NonuniformGridData.hh"

namespace celeritas
{
Expand All @@ -21,21 +21,21 @@ struct ImportPhysicsVector;
*
* This uses a deduplicating inserter for real values to improve cacheing.
*/
class GenericGridBuilder
class NonuniformGridBuilder
{
public:
//!@{
//! \name Type aliases
template<class T>
using Items = Collection<T, Ownership::value, MemSpace::host>;
using Grid = GenericGridRecord;
using Grid = NonuniformGridRecord;
using SpanConstFlt = Span<float const>;
using SpanConstDbl = Span<double const>;
//!@}

public:
// Construct with pointers to data that will be modified
explicit GenericGridBuilder(Items<real_type>* reals);
explicit NonuniformGridBuilder(Items<real_type>* reals);

// Add a grid of generic data with linear interpolation
Grid operator()(SpanConstFlt grid, SpanConstFlt values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/grid/GenericCalculator.hh
//! \file celeritas/grid/NonuniformGridCalculator.hh
//---------------------------------------------------------------------------//
#pragma once

Expand All @@ -14,7 +14,7 @@
#include "corecel/grid/Interpolator.hh"
#include "corecel/grid/NonuniformGrid.hh"

#include "GenericGridData.hh"
#include "NonuniformGridData.hh"

namespace celeritas
{
Expand All @@ -24,9 +24,9 @@ namespace celeritas
*
* The end points of the grid are extrapolated outward as constant values.
*
* \todo Rename NonuniformGridCalculator? Template on value type and/or units?
* \todo Template on value type and/or units?
*/
class GenericCalculator
class NonuniformGridCalculator
{
public:
//@{
Expand All @@ -38,12 +38,13 @@ class GenericCalculator

public:
// Construct by *inverting* a monotonicially increasing generic grid
static inline CELER_FUNCTION GenericCalculator
from_inverse(GenericGridRecord const& grid, Reals const& storage);
static inline CELER_FUNCTION NonuniformGridCalculator
from_inverse(NonuniformGridRecord const& grid, Reals const& storage);

// Construct from grid data and backend storage
inline CELER_FUNCTION
GenericCalculator(GenericGridRecord const& grid, Reals const& storage);
NonuniformGridCalculator(NonuniformGridRecord const& grid,
Reals const& storage);

// Find and interpolate the y value from the given x value
inline CELER_FUNCTION real_type operator()(real_type x) const;
Expand All @@ -55,7 +56,7 @@ class GenericCalculator
inline CELER_FUNCTION Grid const& grid() const;

// Make a calculator with x and y flipped
inline CELER_FUNCTION GenericCalculator make_inverse() const;
inline CELER_FUNCTION NonuniformGridCalculator make_inverse() const;

private:
//// TYPES ////
Expand All @@ -71,8 +72,9 @@ class GenericCalculator
//// HELPERS ////

// Private constructor implementation
inline CELER_FUNCTION
GenericCalculator(Reals const& storage, RealIds x_grid, RealIds y_grid);
inline CELER_FUNCTION NonuniformGridCalculator(Reals const& storage,
RealIds x_grid,
RealIds y_grid);
};

//---------------------------------------------------------------------------//
Expand All @@ -81,20 +83,20 @@ class GenericCalculator
/*!
* Construct by \em inverting a monotonicially increasing generic grid.
*/
CELER_FUNCTION GenericCalculator GenericCalculator::from_inverse(
GenericGridRecord const& grid, Reals const& storage)
CELER_FUNCTION NonuniformGridCalculator NonuniformGridCalculator::from_inverse(
NonuniformGridRecord const& grid, Reals const& storage)
{
return GenericCalculator{storage, grid.value, grid.grid};
return NonuniformGridCalculator{storage, grid.value, grid.grid};
}

//---------------------------------------------------------------------------//
/*!
* Construct from grid data and backend storage.
*/
CELER_FUNCTION
GenericCalculator::GenericCalculator(GenericGridRecord const& grid,
Reals const& storage)
: GenericCalculator{storage, grid.grid, grid.value}
NonuniformGridCalculator::NonuniformGridCalculator(
NonuniformGridRecord const& grid, Reals const& storage)
: NonuniformGridCalculator{storage, grid.grid, grid.value}
{
CELER_EXPECT(grid);
}
Expand All @@ -103,7 +105,7 @@ GenericCalculator::GenericCalculator(GenericGridRecord const& grid,
/*!
* Calculate the y value at the given x value.
*/
CELER_FUNCTION real_type GenericCalculator::operator()(real_type x) const
CELER_FUNCTION real_type NonuniformGridCalculator::operator()(real_type x) const
{
// Snap out-of-bounds values to closest grid points
if (x <= x_grid_.front())
Expand All @@ -130,7 +132,7 @@ CELER_FUNCTION real_type GenericCalculator::operator()(real_type x) const
/*!
* Get the tabulated y value at a particular index.
*/
CELER_FUNCTION real_type GenericCalculator::operator[](size_type index) const
CELER_FUNCTION real_type NonuniformGridCalculator::operator[](size_type index) const
{
CELER_EXPECT(index < y_offset_.size());
return reals_[y_offset_[index]];
Expand All @@ -141,7 +143,7 @@ CELER_FUNCTION real_type GenericCalculator::operator[](size_type index) const
* Get the tabulated x values.
*/
CELER_FORCEINLINE_FUNCTION NonuniformGrid<real_type> const&
GenericCalculator::grid() const
NonuniformGridCalculator::grid() const
{
return x_grid_;
}
Expand All @@ -152,9 +154,10 @@ GenericCalculator::grid() const
*
* \pre The y values must be monotonic increasing.
*/
CELER_FUNCTION GenericCalculator GenericCalculator::make_inverse() const
CELER_FUNCTION NonuniformGridCalculator
NonuniformGridCalculator::make_inverse() const
{
return GenericCalculator{reals_, y_offset_, x_grid_.offset()};
return NonuniformGridCalculator{reals_, y_offset_, x_grid_.offset()};
}

//---------------------------------------------------------------------------//
Expand All @@ -164,9 +167,9 @@ CELER_FUNCTION GenericCalculator GenericCalculator::make_inverse() const
* Construct from grid data and backend storage.
*/
CELER_FUNCTION
GenericCalculator::GenericCalculator(Reals const& storage,
RealIds x_grid,
RealIds y_grid)
NonuniformGridCalculator::NonuniformGridCalculator(Reals const& storage,
RealIds x_grid,
RealIds y_grid)
: reals_{storage}, x_grid_{x_grid, reals_}, y_offset_{y_grid}
{
CELER_EXPECT(!x_grid.empty() && x_grid.size() == y_grid.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/grid/GenericGridData.hh
//! \file celeritas/grid/NonuniformGridData.hh
//---------------------------------------------------------------------------//
#pragma once

Expand All @@ -16,7 +16,7 @@ namespace celeritas
/*!
* A grid of increasing, sorted 1D data with linear-linear interpolation.
*/
struct GenericGridRecord
struct NonuniformGridRecord
{
ItemRange<real_type> grid; //!< x grid
ItemRange<real_type> value; //!< f(x) value
Expand Down
Loading

0 comments on commit 249bd09

Please sign in to comment.