1 #include "purify/config.h" 
    4 #include "catch2/catch_all.hpp" 
    5 #include "purify/directories.h" 
   13   const t_uint max_evaluations = 1000;
 
   14   std::function<t_real(Vector<t_real>)> func;
 
   15   std::function<t_complex(Vector<t_real>)> cfunc;
 
   18       const t_uint ndim = 1;
 
   19       const Vector<t_real> xmin = -Vector<t_real>::Ones(ndim);
 
   20       const Vector<t_real> xmax = Vector<t_real>::Ones(ndim);
 
   21       func = [=](
const Vector<t_real> &x) {
 
   22         assert(x.size() == ndim);
 
   23         return (x.array() * x.array()).sum();
 
   25       cfunc = [=](
const Vector<t_real> &x) {
 
   26         assert(x.size() == ndim);
 
   27         return (x.array() * x.array()).sum();
 
   30                                                    1e-4, 1e-4, max_evaluations, int_method);
 
   31       const t_complex cresult =
 
   36       CHECK(std::abs(result - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   37       CHECK(std::abs(cresult - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   40       const t_uint ndim = 2;
 
   41       const Vector<t_real> xmin = -Vector<t_real>::Ones(ndim);
 
   42       const Vector<t_real> xmax = Vector<t_real>::Ones(ndim);
 
   43       func = [=](
const Vector<t_real> &x) {
 
   44         assert(x.size() == ndim);
 
   45         return (x.array() * x.array()).sum();
 
   47       cfunc = [=](
const Vector<t_real> &x) {
 
   48         assert(x.size() == ndim);
 
   49         return (x.array() * x.array()).sum();
 
   52                                                    1e-4, 1e-4, max_evaluations, int_method);
 
   53       const t_complex cresult =
 
   55                                  max_evaluations, int_method);
 
   58       CHECK(std::abs(result - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   59       CHECK(std::abs(cresult - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   62       const t_uint ndim = 3;
 
   63       const Vector<t_real> xmin = -Vector<t_real>::Ones(ndim);
 
   64       const Vector<t_real> xmax = Vector<t_real>::Ones(ndim);
 
   65       func = [=](
const Vector<t_real> &x) {
 
   66         assert(x.size() == ndim);
 
   67         return (x.array() * x.array()).sum();
 
   69       cfunc = [=](
const Vector<t_real> &x) {
 
   70         assert(x.size() == ndim);
 
   71         return (x.array() * x.array()).sum();
 
   74                                                    1e-4, 1e-4, max_evaluations, int_method);
 
   75       const t_complex cresult =
 
   80       CHECK(std::abs(result - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   81       CHECK(std::abs(cresult - ndim * std::pow(2, ndim - 1) * 2. / 3) < 1e-4);
 
   87   const t_uint max_evaluations = 100000;
 
   88   std::function<t_complex(Vector<t_real>)> cfunc1;
 
   90     SECTION(
"Fourier Series") {
 
   91       const t_uint ndim = 1;
 
   92       const Vector<t_real> xmin = -Vector<t_real>::Ones(ndim) * 
constant::pi;
 
   93       const Vector<t_real> xmax = Vector<t_real>::Ones(ndim) * 
constant::pi;
 
   95       const t_complex 
I(0., 1.);
 
   96       cfunc1 = [=](
const Vector<t_real> &x) {
 
   97         assert(x.size() == ndim);
 
   98         return (x(0) >= 0) ? std::exp(
I * n * x(0)) * 1. / 2. : -std::exp(
I * n * x(0)) * 1. / 2.;
 
  103       CHECK(std::abs(cresult - t_complex(0., 2.)) / 2. < 1e-4);
 
  105     SECTION(
"Fourier Series omp") {
 
  106       const t_uint ndim = 1;
 
  107       const Vector<t_real> xmin = -Vector<t_real>::Ones(ndim) * 
constant::pi;
 
  108       const Vector<t_real> xmax = Vector<t_real>::Ones(ndim) * 
constant::pi;
 
  110       const t_complex 
I(0., 1.);
 
  111       std::vector<std::function<t_complex(Vector<t_real>)>> funcs;
 
  112       for (
int i = 0; i < 4; i++) {
 
  113         funcs.push_back([=](
const Vector<t_real> &x) -> t_complex {
 
  114           assert(x.size() == ndim);
 
  115           return ((x(0) >= 0) ? std::exp(
I * n * x(0)) * 1. / 2.
 
  116                               : -std::exp(
I * n * x(0)) * 1. / 2.) *
 
  120 #pragma omp parallel for 
  121       for (
int i = 0; i < funcs.size(); i++) {
 
  122         const t_complex cresult =
 
  124                                    max_evaluations, int_method);
 
  126         CHECK(std::abs(cresult - t_complex(0., 2. * 
static_cast<t_real
>(i + 1))) /
 
  127                   (2. * 
static_cast<t_real
>(i + 1)) <
 
  135   const t_uint max_evaluations = 1e7;
 
  140   std::function<t_complex(Vector<t_real>)> cfunc;
 
  141   const t_uint ndim = 2;
 
  142   const Vector<t_real> xmin = Vector<t_real>::Zero(ndim);
 
  143   Vector<t_real> xmax = Vector<t_real>::Ones(ndim);
 
  147   const t_complex 
I(0., 1.);
 
  149   cfunc = [=, &evals](
const Vector<t_real> &x) -> t_complex {
 
  150     assert(x.size() == ndim);
 
  153                     (x(0) * std::cos(x(1)) * 
u + x(0) * std::sin(x(1)) * 
v +
 
  154                      w * (std::sqrt(1 - std::pow(x(0), 2)) - 1))) *
 
  155            x(0) / std::sqrt(1 - std::pow(x(0), 2)) / (2 * 
constant::pi);
 
  157   const t_complex cresult =
 
  162   CHECK(std::abs(cresult - t_complex(0.007601618963237, -0.003167113583181)) / std::abs(cresult) <
 
#define CHECK(CONDITION, ERROR)
 
const std::vector< t_real > u
data for u coordinate
 
const std::vector< t_real > v
data for v coordinate
 
const t_real pi
mathematical constant
 
t_real integrate(const Vector< t_real > &xmin, const Vector< t_real > &xmax, const std::function< t_real(Vector< t_real >)> &func, const norm_type norm, const t_real required_abs_error, const t_real required_rel_error, const t_uint max_evaluations, const method methodtype)
adaptive integration with cubature for real scalar to vector