Skip to content

Commit 30aff49

Browse files
committed
test: add the unit test and comments of math_sphbes.h
range: source/module_base
1 parent 7f6bf84 commit 30aff49

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

source/module_base/math_sphbes.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ class Sphbes
5252
double *sjp
5353
);
5454

55-
55+
/**
56+
* @brief return num eigenvalues of spherical bessel function
57+
*
58+
* @param num [in] the number of eigenvalues
59+
* @param l [in] angular number
60+
* @param epsilon [in] the accuracy
61+
* @param eigenvalue [out] the calculated eigenvalues
62+
* @param rcut [in] the cutoff the radial function
63+
*/
5664
static void Spherical_Bessel_Roots
5765
(
5866
const int &num,

source/module_base/test/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ AddTest(
4747
TARGET base_sph_bessel_recursive
4848
SOURCES sph_bessel_recursive_test.cpp ../sph_bessel_recursive-d1.cpp ../sph_bessel_recursive-d2.cpp
4949
)
50+
AddTest(
51+
TARGET base_math_sphbes
52+
SOURCES math_sphbes_test.cpp ../math_sphbes.cpp ../timer.cpp
53+
)
5054
AddTest(
5155
TARGET base_realarray
5256
SOURCES realarray_test.cpp ../realarray.cpp

source/module_base/test/math_sphbes_test.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
* and the reference results are produced by ABACUS
2121
* at 2022-1-27.
2222
*
23-
* Tested function: Spherical_Bessel.
23+
* Tested function:
24+
* - Spherical_Bessel.
25+
* - Spherical_Bessel_Roots
2426
*
2527
*/
2628

@@ -124,6 +126,46 @@ TEST_F(Sphbes,SphericalBessel)
124126
EXPECT_NEAR(mean(jl,msh)/0.015215556095798710851, 1.0,doublethreshold);
125127
}
126128

129+
TEST_F(Sphbes,SphericalBesselRoots)
130+
{
131+
int neign = 100;
132+
double **eign = new double*[8];
133+
for(int i=0;i<8;++i)
134+
{
135+
eign[i] = new double[neign];
136+
ModuleBase::Sphbes::Spherical_Bessel_Roots(neign,i,1.0e-12,eign[i],10.0);
137+
}
138+
139+
EXPECT_NEAR(eign[0][0]/0.31415926535899563188, 1.0,doublethreshold);
140+
EXPECT_NEAR(eign[0][99]/31.415926535896932847, 1.0,doublethreshold);
141+
EXPECT_NEAR(mean(eign[0],100)/15.865042900628463229, 1.0,doublethreshold);
142+
EXPECT_NEAR(eign[1][0]/0.44934094579091843347, 1.0,doublethreshold);
143+
EXPECT_NEAR(eign[1][99]/31.572689440204385392, 1.0,doublethreshold);
144+
EXPECT_NEAR(mean(eign[1],100)/16.020655759558295017, 1.0,doublethreshold);
145+
EXPECT_NEAR(eign[2][0]/0.57634591968946913276, 1.0,doublethreshold);
146+
EXPECT_NEAR(eign[2][99]/31.729140298172534784, 1.0,doublethreshold);
147+
EXPECT_NEAR(mean(eign[2],100)/16.175128483074864505, 1.0,doublethreshold);
148+
EXPECT_NEAR(eign[3][0]/0.69879320005004752492, 1.0,doublethreshold);
149+
EXPECT_NEAR(eign[3][99]/31.885283678838447941, 1.0,doublethreshold);
150+
EXPECT_NEAR(mean(eign[3],100)/16.328616567969248763, 1.0,doublethreshold);
151+
EXPECT_NEAR(eign[4][0]/0.81825614525711076741, 1.0,doublethreshold);
152+
EXPECT_NEAR(eign[4][99]/32.041124042016576823, 1.0,doublethreshold);
153+
EXPECT_NEAR(mean(eign[4],100)/16.481221742387987206, 1.0,doublethreshold);
154+
EXPECT_NEAR(eign[5][0]/0.93558121110426506473, 1.0,doublethreshold);
155+
EXPECT_NEAR(eign[5][99]/32.196665741899131774, 1.0,doublethreshold);
156+
EXPECT_NEAR(mean(eign[5],100)/16.633019118735202113, 1.0,doublethreshold);
157+
EXPECT_NEAR(eign[6][0]/1.051283540809391015, 1.0,doublethreshold);
158+
EXPECT_NEAR(eign[6][99]/32.351913030537232885, 1.0,doublethreshold);
159+
EXPECT_NEAR(mean(eign[6],100)/16.784067905062840964, 1.0,doublethreshold);
160+
EXPECT_NEAR(eign[7][0]/1.1657032192516516567, 1.0,doublethreshold);
161+
EXPECT_NEAR(eign[7][99]/32.506870061157627561, 1.0,doublethreshold);
162+
EXPECT_NEAR(mean(eign[7],100)/16.934416735327332049, 1.0,doublethreshold);
163+
164+
for(int i=0;i<8;++i) delete [] eign[i];
165+
delete [] eign;
166+
}
167+
168+
127169
int main(int argc, char **argv)
128170
{
129171
#ifdef __MPI

0 commit comments

Comments
 (0)