|
| 1 | +#include"../sph_bessel_recursive.h" |
| 2 | +#include"gtest/gtest.h" |
| 3 | + |
| 4 | +#define threshold 1e-12 |
| 5 | + |
| 6 | +/************************************************ |
| 7 | +* unit test of class Sph_Bessel_Recursive |
| 8 | +***********************************************/ |
| 9 | + |
| 10 | +/** |
| 11 | + * Note: this unit test try to ensure the invariance |
| 12 | + * of the spherical Bessel produced by class Sph_Bessel_Recursive, |
| 13 | + * and the reference results are produced by ModuleBase::Sph_Bessel_Recursive |
| 14 | + * at 2022-1-25. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +double mean(std::vector<double> &vect) |
| 19 | +{ |
| 20 | + double meanv = 0.0; |
| 21 | + |
| 22 | + int totN = vect.size(); |
| 23 | + for (int i=0; i< totN; ++i) {meanv += vect[i]/totN;} |
| 24 | + |
| 25 | + return meanv; |
| 26 | +} |
| 27 | + |
| 28 | +TEST(SphBessel,D1) |
| 29 | +{ |
| 30 | + int lmax = 7; |
| 31 | + int rmesh = 700; |
| 32 | + double dx = 0.01; |
| 33 | + |
| 34 | + ModuleBase::Sph_Bessel_Recursive::D1 sphbesseld1; |
| 35 | + sphbesseld1.set_dx(dx); |
| 36 | + sphbesseld1.cal_jlx(lmax,rmesh); |
| 37 | + std::vector<std::vector<double>> jlx = sphbesseld1.get_jlx(); |
| 38 | + |
| 39 | + ASSERT_EQ(jlx.size(),static_cast<size_t>(lmax + 1)); |
| 40 | + EXPECT_NEAR( mean(jlx[0])/0.2084468748396, 1.0, threshold); |
| 41 | + EXPECT_NEAR( mean(jlx[1])/0.12951635180384, 1.0, threshold); |
| 42 | + EXPECT_NEAR( mean(jlx[2])/0.124201140093879, 1.0, threshold); |
| 43 | + EXPECT_NEAR( mean(jlx[3])/0.118268654505568, 1.0, threshold); |
| 44 | + EXPECT_NEAR( mean(jlx[4])/0.0933871035384385, 1.0, threshold); |
| 45 | + EXPECT_NEAR( mean(jlx[5])/0.0603800487910689, 1.0, threshold); |
| 46 | + EXPECT_NEAR( mean(jlx[6])/0.0327117051555907, 1.0, threshold); |
| 47 | + EXPECT_NEAR( mean(jlx[7])/0.0152155566653926, 1.0, threshold); |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +TEST(SphBessel,D2) |
| 52 | +{ |
| 53 | + int lmax = 7; |
| 54 | + int rmesh = 700; |
| 55 | + int kmesh = 800; |
| 56 | + double dx = 0.0001; |
| 57 | + |
| 58 | + ModuleBase::Sph_Bessel_Recursive::D2 sphbesseld2; |
| 59 | + sphbesseld2.set_dx(dx); |
| 60 | + sphbesseld2.cal_jlx(lmax,rmesh,kmesh); |
| 61 | + std::vector<std::vector<std::vector<double>>> jlxd2 = sphbesseld2.get_jlx(); |
| 62 | + std::vector<std::vector<double>> jlx(lmax+1); |
| 63 | + |
| 64 | + ASSERT_EQ(jlxd2.size(),static_cast<size_t>(lmax + 1)); |
| 65 | + |
| 66 | + //calculate the mean of jlxd2[i][j] and assign to jlx[i][j] |
| 67 | + for(int i=0; i<jlxd2.size(); ++i) |
| 68 | + { |
| 69 | + jlx[i].resize(jlxd2[i].size()); |
| 70 | + for(int j=0; j< jlxd2[i].size(); ++j) |
| 71 | + { |
| 72 | + jlx[i][j] = mean(jlxd2[i][j]); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + EXPECT_NEAR( mean(jlx[0])/0.130406547960426, 1.0, threshold); |
| 77 | + EXPECT_NEAR( mean(jlx[1])/0.0643093491554227, 1.0, threshold); |
| 78 | + EXPECT_NEAR( mean(jlx[2])/0.0434912807857165, 1.0, threshold); |
| 79 | + EXPECT_NEAR( mean(jlx[3])/0.0329463027246214, 1.0, threshold); |
| 80 | + EXPECT_NEAR( mean(jlx[4])/0.0264877891341284, 1.0, threshold); |
| 81 | + EXPECT_NEAR( mean(jlx[5])/0.0220804766801247, 1.0, threshold); |
| 82 | + EXPECT_NEAR( mean(jlx[6])/0.0188550846449362, 1.0, threshold); |
| 83 | + EXPECT_NEAR( mean(jlx[7])/0.0163891245775448, 1.0, threshold); |
| 84 | +} |
0 commit comments