TDMS
Time Domain Maxwell Solver
All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
test_interpolation_functions.cpp File Reference

Tests the performance of the interpolation functions, using 1D data mimicing a coordinate axes. More...

#include "interpolation_methods.h"
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <sstream>
#include <catch2/catch_approx.hpp>
#include <catch2/catch_test_macros.hpp>
#include <spdlog/spdlog.h>
#include "globals.h"
#include "input_flags.h"
#include "unit_test_utils.h"
Include dependency graph for test_interpolation_functions.cpp:

Functions

 TEST_CASE ("Cubic interpolation: exact for polynomials of degree <= 3")
 In the case when cubic interpolation is to be used, check that all polynomial fields up to cubic order are interpolated exactly (to within machine error)
 
 TEST_CASE ("BLi: interpolation-coefficient sums match")
 The hard-coded numerical values for the interpolation constant should all sum to the same value.
 
double constant_1 (double x)
 
double s2pi (double x)
 
double pulse (double x)
 Evaluates the smooth pulse/ mollifier Kernel function, supported between 0 and 1.
 
complex< double > complex_fn (double x)
 
 TEST_CASE ("BLi: MATLAB benchmarking")
 

Variables

const double ML_const_fn_max_pointwise_error = 2.82944733e-04
 We will check that BLi interpolation data gives comparible error to the equivalent functions in MATLAB.
 
const double ML_sin_max_pointwise_error = 2.63468327e-04
 
const double ML_pulse_max_pointwise_error = 4.87599933e-04
 
const double ML_complex_fn_max_pointwise_error = 5.35317432e-04
 
const double ML_cont_fn_norm_error = 2.81526454e-03
 
const double ML_sin_norm_error = 1.85845330e-03
 
const double ML_pulse_norm_error = 9.65609916e-04
 
const double ML_complex_fn_norm_error = 2.08892374e-03
 

Detailed Description

Tests the performance of the interpolation functions, using 1D data mimicing a coordinate axes.

Author
William Graham (ccaeg.nosp@m.ra@u.nosp@m.cl.ac.nosp@m..uk)

Function Documentation

◆ pulse()

double pulse ( double  x)
inline

Evaluates the smooth pulse/ mollifier Kernel function, supported between 0 and 1.

The smooth mollifier \phi(x) is the function \phi(x) = \begin{cases} 0 & when |x| >= 1, e^{-1/(1-|x|^2)} & when |x| < 1 \end{cases} This function is compactly supported over the interval [-1,1]. By evaluating pulse(x) = \phi(3[2x-1]), we obtain a smooth function with support in [1/3,2/3] \subset [0,1]

Parameters
xPoint of evaluation
Returns
double Evaluted value

◆ TEST_CASE() [1/2]

TEST_CASE ( "BLi: interpolation-coefficient sums match"  )

The hard-coded numerical values for the interpolation constant should all sum to the same value.

Note - the coefficients are not required to sum to unity!

◆ TEST_CASE() [2/2]

TEST_CASE ( "Cubic interpolation: exact for polynomials of degree <= 3"  )

In the case when cubic interpolation is to be used, check that all polynomial fields up to cubic order are interpolated exactly (to within machine error)

Checks are run on both the old interp{1,2,3} functions and newer const Interp_scheme instances. Old cubic methods will be redundant upon integration of BLi into the codebase.

Variable Documentation

◆ ML_const_fn_max_pointwise_error

const double ML_const_fn_max_pointwise_error = 2.82944733e-04
inline

We will check that BLi interpolation data gives comparible error to the equivalent functions in MATLAB.

  • For 100 sample points, we will use BLi to interpolate the following complex-valued function with 100 sample points: real part of sin(2\pi x) imag part of pulse function.

Interoplation will then be tested against over the range [0,1], the max element-wise error (by absolute value) will be determined. We will then check that this is of the same order of magnitude as the error produced by MATLAB, 5.35317432e-04.

For 100 sample points, we will use BLi to interpolate the following functions with 100 sample points:

  • The constant function 1 : range 0,1 : max. element-wise error (MATLAB) 2.82944733e-04
  • sin(2\pi x) : range 0,1 : max. element-wise error (MATLAB) 2.63468327e-04
  • pulse function : range 0,1 : max. element-wise error (MATLAB) 4.87599933e-04
  • complex function : range 0,1 : max. element-wise error (MATLAB) 5.35317432e-04

MATLAB norm-errors: constant function norm error: 2.81526454e-03 sin function norm error: 1.85845330e-03 pulse function norm error: 9.65609916e-04 complex fn norm error: 2.08892374e-03

Error values produced from benchmark_test_interpolation_functions.m The complex function has real part sin(2\pi x) and its imaginary part is the pulse function.