Celeritas  0.5.0-86+4a8eea4
Public Member Functions | List of all members
celeritas::test::DiagnosticRealFunc< F > Class Template Reference

Wrap a numerical single-argument function with a counter and logger. More...

#include <DiagnosticRealFunc.hh>

Public Member Functions

 DiagnosticRealFunc (F &&eval)
 Construct by forwarding a function.
 
size_type exchange_count ()
 Get and reset the counter.
 
real_type operator() (real_type v)
 Evaluate the underlying function and increment the counter.
 

Detailed Description

template<class F>
class celeritas::test::DiagnosticRealFunc< F >

Wrap a numerical single-argument function with a counter and logger.

This takes a function:

\[ f\colon\mathbb{R^1}\to\mathbb{R^1} \]

and adds a counter that increments every time the function is invoked. This is very useful for unit testing the convergence properties of numerical integrators, root finders, etc.

Example:

DiagnosticFunc f{[](real_type x) { return 2 * x; }};
Integrator integrate{f};
EXPECT_SOFT_EQ(4 - 1, integrate(1, 2));
EXPECT_EQ(3, f.exchange_count());
#define EXPECT_SOFT_EQ(expected, actual)
Soft equivalence macro.
Definition: TestMacros.hh:32
double real_type
Numerical type for real numbers.
Definition: corecel/Types.hh:35
@ x
X axis/I index coordinate.

This wrapper also checks the input and output for NaN, and it outputs the function counter and evaluation to the logger (export CELER_LOG=debug).


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