File indexing completed on 2025-09-17 08:53:39
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include "corecel/Types.hh"
0011 #include "corecel/grid/NonuniformGridData.hh"
0012 #include "corecel/grid/SplineDerivCalculator.hh"
0013 #include "corecel/grid/UniformGridData.hh"
0014 #include "corecel/io/Logger.hh"
0015 #include "celeritas/inp/Grid.hh"
0016
0017 namespace celeritas
0018 {
0019 namespace detail
0020 {
0021
0022 template<Ownership W>
0023 using Values = Collection<real_type, W, MemSpace::host>;
0024
0025
0026
0027
0028
0029 template<class GridRecord>
0030 void set_spline(Values<Ownership::value>* values,
0031 DedupeCollectionBuilder<real_type>& reals,
0032 inp::Interpolation const& interpolation,
0033 GridRecord& data)
0034 {
0035 CELER_EXPECT(values);
0036 CELER_EXPECT(data);
0037
0038 if (interpolation.type == InterpolationType::cubic_spline)
0039 {
0040 if (data.value.size() < SplineDerivCalculator::min_grid_size())
0041 {
0042 CELER_LOG(warning)
0043 << to_cstring(interpolation.type)
0044 << " interpolation is not supported on a grid with size "
0045 << data.value.size() << ": defaulting to linear";
0046 return;
0047 }
0048
0049 CELER_VALIDATE(interpolation.bc
0050 != SplineDerivCalculator::BoundaryCondition::size_,
0051 << "Boundary condition must be specified for "
0052 "calculating cubic spline second derivatives");
0053
0054 Values<Ownership::const_reference> ref(*values);
0055 auto deriv = SplineDerivCalculator(interpolation.bc)(data, ref);
0056 data.derivative = reals.insert_back(deriv.begin(), deriv.end());
0057 }
0058 else if (interpolation.type == InterpolationType::poly_spline)
0059 {
0060 if (data.value.size() <= interpolation.order)
0061 {
0062 CELER_LOG(warning)
0063 << to_cstring(interpolation.type)
0064 << " interpolation with order " << interpolation.order
0065 << " is not supported on a grid with size "
0066 << data.value.size() << ": defaulting to linear";
0067 return;
0068 }
0069 CELER_ASSERT(interpolation.order > 1);
0070 data.spline_order = interpolation.order;
0071 }
0072 else
0073 {
0074
0075 }
0076 CELER_ENSURE(data);
0077 }
0078
0079
0080 }
0081 }