QMCPACK
test_OneDimCubicSplineLinearGrid.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2022 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 #include "catch.hpp"
14 
15 namespace qmcplusplus
16 {
17 
18 // Copy and modified from one_dim_cubic_spline_1
19 TEST_CASE("test oneDimCubicSplineLinearGrid", "[numerics]")
20 {
21  const int n = 3;
22  std::vector<double> yvals = {1.0, 2.0, 1.5};
23 
24  auto grid = std::make_unique<LinearGrid<double>>();
25  grid->set(0.5, 2.0, n);
26 
27  OneDimCubicSpline<double> cubic_spline(std::move(grid), yvals);
28 
29  int imin = 0;
30  int imax = 3 - 1;
31 
32  double yp0 = 1.0;
33  double ypn = 2.0;
34 
35  cubic_spline.spline(imin, yp0, imax, ypn);
36 
37  OneDimCubicSplineLinearGrid linear_grid_cubic_spline(cubic_spline);
38 
39  std::vector<double> check_xvals = {0.0, 0.39999999998, 0.79999999996, 1.19999999994, 1.59999999992, 1.9999999999, 2.5};
40  std::vector<double> check_yvals;
41 
42  for (int i = 0; i < check_xvals.size(); i++)
43  {
44  double r = check_xvals[i];
45  double val = cubic_spline.splint(r);
46  check_yvals.push_back(val);
47 
48  //std::cout << i << " r = " << r << " val = " << val << " " << check_yvals[i] << std::endl;
49  }
50 
51  CHECK(check_yvals[0] == Approx(0.5));
52  CHECK(check_yvals[1] == Approx(0.9));
53  CHECK(check_yvals[2] == Approx(1.4779999999));
54  CHECK(check_yvals[3] == Approx(2.0012592592));
55  CHECK(check_yvals[4] == Approx(1.575851852));
56  CHECK(check_yvals[5] == Approx(1.5));
57  CHECK(check_yvals[6] == Approx(1.5));
58 }
59 
60 } // namespace qmcplusplus
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
value_type splint(point_type r) const override
void spline(int imin, value_type yp1, int imax, value_type ypn) override
Evaluate the 2nd derivative on the grid points.
combined OneDimCubicSpline and LinearGrid OneDimCubicSpline contains OneDimGridBase pointer and calls...
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))