File indexing completed on 2025-10-25 08:41:16
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <algorithm>
0011 #include <cmath>
0012 #include <vector>
0013
0014 #include "corecel/Types.hh"
0015 #include "corecel/cont/Range.hh"
0016 #include "corecel/cont/Span.hh"
0017 #include "corecel/math/Algorithms.hh"
0018 #include "corecel/math/SoftEqual.hh"
0019
0020 namespace celeritas
0021 {
0022
0023
0024 std::vector<double> linspace(double start, double stop, size_type n);
0025
0026
0027
0028 std::vector<double> logspace(double start, double stop, size_type n);
0029
0030
0031
0032
0033
0034 template<class T>
0035 inline bool is_monotonic_nondecreasing(Span<T> grid)
0036 {
0037 return all_adjacent(grid.begin(), grid.end(), [](T& left, T& right) {
0038 return left <= right;
0039 });
0040 }
0041
0042
0043
0044
0045
0046 template<class T>
0047 inline bool is_monotonic_increasing(Span<T> grid)
0048 {
0049 return all_adjacent(grid.begin(), grid.end(), [](T& left, T& right) {
0050 return left < right;
0051 });
0052 }
0053
0054
0055
0056
0057
0058 template<class T>
0059 T calc_log_delta(Span<T const> grid)
0060 {
0061 CELER_EXPECT(grid.size() > 1);
0062 return fastpow(grid.back() / grid.front(), T(1) / (grid.size() - 1));
0063 }
0064
0065
0066
0067
0068
0069 template<class T>
0070 inline bool has_log_spacing(Span<T const> grid)
0071 {
0072 T delta = calc_log_delta(grid);
0073 for (auto i : range(grid.size() - 1))
0074 {
0075 if (!soft_equal(delta, grid[i + 1] / grid[i]))
0076 return false;
0077 }
0078 return true;
0079 }
0080
0081
0082 }