Celeritas  0.5.0-56+6b053cd
Public Member Functions | List of all members
celeritas::PolyEvaluator< T, N > Class Template Reference

Functor class to evaluate a polynomial. More...

#include <PolyEvaluator.hh>

Public Types

Type aliases
using result_type = T
 
using argument_type = T
 
using ArrayT = Array< T, N+1 >
 

Public Member Functions

template<class... Ts>
CELER_CONSTEXPR_FUNCTION PolyEvaluator (Ts... coeffs)
 Construct with the polynomial to evaluate.
 
CELER_CONSTEXPR_FUNCTION PolyEvaluator (ArrayT const &coeffs)
 Construct from an array of data.
 
CELER_CONSTEXPR_FUNCTIONoperator() (T arg) const
 Evaluate the polynomial at the given value.
 

Detailed Description

template<class T, size_type N>
class celeritas::PolyEvaluator< T, N >

Functor class to evaluate a polynomial.

This is an efficient and foolproof way of storing and evaluating a polynomial expansion:

\[ f(x) = a_0 + x * (a_1 + x * (a_2 + ...)) \]

It replaces opaque expressions such as:

corr = (zeff * (real_type(1.84035e-4) * zeff - real_type(1.86427e-2))
+ real_type(1.41125));
double real_type
Numerical type for real numbers.
Definition: corecel/Types.hh:35

with

corr = PolyEvaluator{1.41125, -1.86427e-2, 1.84035e-4}(zeff);
CELER_CONSTEXPR_FUNCTION PolyEvaluator(Ts... coeffs)
Construct with the polynomial to evaluate.
Definition: PolyEvaluator.hh:59

or, to use an explicit type without having to cast each coefficient:

using PolyQuad = PolyEvaluator<real_type, N>;
corr = PolyQuad{1.41125, -1.86427e-2, 1.84035e-4)(zeff);

The documentation for this class was generated from the following file: