Skip to content

Commit eb05e52

Browse files
authored
Merge pull request #740 from pxlxingliang/develop
test: add the unit test and comments for ylm.h
2 parents eeb8cc7 + 3523ec0 commit eb05e52

File tree

3 files changed

+261
-35
lines changed

3 files changed

+261
-35
lines changed

source/module_base/test/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ AddTest(
7373
SOURCES math_polyint_test.cpp ../math_polyint.cpp ../realarray.cpp ../timer.cpp
7474
)
7575
AddTest(
76-
TARGET base_mathzone_add1
76+
TARGET base_ylmreal
7777
LIBS ${math_libs}
78-
SOURCES mathzone_add1_test.cpp ../mathzone_add1.cpp ../math_sphbes.cpp ../mathzone.cpp ../matrix3.cpp ../matrix.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
78+
SOURCES math_ylmreal_test.cpp ../math_ylmreal.cpp ../ylm.cpp ../realarray.cpp ../timer.cpp ../matrix.cpp ../vector3.h
7979
)
8080
AddTest(
81-
TARGET base_math_ylmreal
81+
TARGET base_mathzone_add1
8282
LIBS ${math_libs}
83-
SOURCES math_ylmreal_test.cpp ../math_ylmreal.cpp ../realarray.cpp ../timer.cpp ../matrix.cpp
83+
SOURCES mathzone_add1_test.cpp ../mathzone_add1.cpp ../math_sphbes.cpp ../mathzone.cpp ../matrix3.cpp ../matrix.cpp ../tool_quit.cpp ../global_variable.cpp ../global_file.cpp ../memory.cpp ../timer.cpp
8484
)

source/module_base/test/math_ylmreal_test.cpp

Lines changed: 186 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include"../math_ylmreal.h"
2+
#include"../ylm.h"
23
#include"../vector3.h"
34
#include"../matrix.h"
45
#include"gtest/gtest.h"
@@ -21,6 +22,13 @@
2122
* - Ylm_Real
2223
* - Ylm_Real2
2324
* - rlylm
25+
*
26+
* - Tested functions of class Ylm
27+
* - get_ylm_real
28+
* - sph_harm
29+
* - rl_sph_harm
30+
* - grad_rl_sph_harm
31+
* -
2432
*/
2533

2634

@@ -37,17 +45,19 @@ class YlmRealTest : public testing::Test
3745
{
3846
protected:
3947

40-
int lmax = 7;
41-
int ng = 4; //test the 4 selected points on the sphere
42-
int nylm ; // total Ylm number;
43-
ModuleBase::matrix ylm;
44-
ModuleBase::Vector3<double> *g;
45-
double *ref;
46-
double *rly;
48+
int lmax = 7; //maximum angular quantum number
49+
int ng = 4; //test the 4 selected points on the sphere
50+
int nylm = 64; //total Ylm number;
51+
52+
ModuleBase::matrix ylm; //Ylm
53+
ModuleBase::Vector3<double> *g; //vectors of the 4 points
54+
double *ref; //reference of Ylm
55+
double *rly; //Ylm
56+
double (*rlgy)[3]; //the gradient of Ylm
57+
std::vector<double> rlyvector; //Ylm
58+
std::vector<std::vector<double>> rlgyvector; //the gradient of Ylm
4759

4860
//Ylm function
49-
//https://formulasearchengine.com/wiki/Table_of_spherical_harmonics
50-
//multipy the Condon–Shortley phase (-1)^m
5161
inline double norm(const double &x, const double &y, const double &z) {return sqrt(x*x + y*y + z*z);}
5262
double y00(const double &x, const double &y, const double &z) {return 1.0/2.0/sqrt(M_PI);}
5363
double y10(const double &x, const double &y, const double &z) {double r=norm(x,y,z); return sqrt(3.0/(4.0*M_PI)) * z / r;}
@@ -75,9 +85,108 @@ class YlmRealTest : public testing::Test
7585
double y44(const double &x, const double &y, const double &z) {double r=norm(x,y,z); return 3./16.*sqrt(35./M_PI) * (x*x*(x*x - 3.*y*y) - y*y*(3.*x*x-y*y)) / (r*r*r*r);}
7686
double y4m4(const double &x, const double &y, const double &z) {double r=norm(x,y,z); return 3./4.*sqrt(35./M_PI) * x*y*(x*x - y*y) / (r*r*r*r);}
7787

88+
//the reference values are calculated by ModuleBase::Ylm::grad_rl_sph_harm
89+
//1st dimension: example, 2nd dimension: Ylm, 3rd dimension: dx/dy/dz
90+
double rlgyref[4][64][3] = {
91+
{ { 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.88603e-01}, {-4.88603e-01, 0.00000e+00, 0.00000e+00},
92+
{ 0.00000e+00, -4.88603e-01, 0.00000e+00}, {-6.30783e-01, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, -1.09255e+00},
93+
{ 0.00000e+00, -0.00000e+00, 0.00000e+00}, { 1.09255e+00, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, 1.09255e+00, -0.00000e+00},
94+
{-0.00000e+00, 0.00000e+00, -1.11953e+00}, { 1.37114e+00, 0.00000e+00, -0.00000e+00}, { 0.00000e+00, 4.57046e-01, 0.00000e+00},
95+
{ 0.00000e+00, 0.00000e+00, 1.44531e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00}, {-1.77013e+00, 0.00000e+00, -0.00000e+00},
96+
{ 0.00000e+00, -1.77013e+00, 0.00000e+00}, { 1.26943e+00, 0.00000e+00, -0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.00714e+00},
97+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, {-1.89235e+00, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, -9.46175e-01, 0.00000e+00},
98+
{-0.00000e+00, 0.00000e+00, -1.77013e+00}, { 0.00000e+00, -0.00000e+00, 0.00000e+00}, { 2.50334e+00, 0.00000e+00, 0.00000e+00},
99+
{-0.00000e+00, 2.50334e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 1.75425e+00}, {-2.26473e+00, 0.00000e+00, 0.00000e+00},
100+
{ 0.00000e+00, -4.52947e-01, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, -2.39677e+00}, {-0.00000e+00, -0.00000e+00, 0.00000e+00},
101+
{ 2.44619e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 1.46771e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.07566e+00},
102+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, {-3.28191e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -3.28191e+00, 0.00000e+00},
103+
{-1.90708e+00, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, -2.91311e+00}, { 0.00000e+00, -0.00000e+00, 0.00000e+00},
104+
{ 2.76362e+00, 0.00000e+00, -0.00000e+00}, {-0.00000e+00, 9.21205e-01, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.76362e+00},
105+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, {-3.02739e+00, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, -2.01826e+00, 0.00000e+00},
106+
{-0.00000e+00, 0.00000e+00, -2.36662e+00}, { 0.00000e+00, -0.00000e+00, 0.00000e+00}, { 4.09910e+00, 0.00000e+00, 0.00000e+00},
107+
{-0.00000e+00, 4.09910e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, -2.38995e+00}, { 3.16161e+00, 0.00000e+00, -0.00000e+00},
108+
{ 0.00000e+00, 4.51658e-01, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 3.31900e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
109+
{-3.28564e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -1.40813e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, -3.11349e+00},
110+
{-0.00000e+00, -0.00000e+00, 0.00000e+00}, { 3.63241e+00, 0.00000e+00, -0.00000e+00}, { 0.00000e+00, 2.59458e+00, 0.00000e+00},
111+
{ 0.00000e+00, 0.00000e+00, 2.64596e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00}, {-4.95014e+00, 0.00000e+00, -0.00000e+00},
112+
{ 0.00000e+00, -4.95014e+00, 0.00000e+00}
113+
},
114+
{
115+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.88603e-01}, {-4.88603e-01, 0.00000e+00, 0.00000e+00},
116+
{ 0.00000e+00, -4.88603e-01, 0.00000e+00}, { 0.00000e+00, -6.30783e-01, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
117+
{ 0.00000e+00, -0.00000e+00, -1.09255e+00}, { 0.00000e+00, -1.09255e+00, 0.00000e+00}, { 1.09255e+00, 0.00000e+00, -0.00000e+00},
118+
{ 0.00000e+00, -0.00000e+00, -1.11953e+00}, { 4.57046e-01, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 1.37114e+00, -0.00000e+00},
119+
{ 0.00000e+00, -0.00000e+00, -1.44531e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 1.77013e+00, 0.00000e+00, 0.00000e+00},
120+
{ 0.00000e+00, 1.77013e+00, 0.00000e+00}, { 0.00000e+00, 1.26943e+00, -0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
121+
{ 0.00000e+00, 0.00000e+00, 2.00714e+00}, { 0.00000e+00, 1.89235e+00, -0.00000e+00}, {-9.46175e-01, 0.00000e+00, 0.00000e+00},
122+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 1.77013e+00}, { 0.00000e+00, 2.50334e+00, -0.00000e+00},
123+
{-2.50334e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 1.75425e+00}, {-4.52947e-01, 0.00000e+00, 0.00000e+00},
124+
{ 0.00000e+00, -2.26473e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.39677e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
125+
{-1.46771e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -2.44619e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.07566e+00},
126+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, {-3.28191e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -3.28191e+00, 0.00000e+00},
127+
{ 0.00000e+00, -1.90708e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -0.00000e+00, -2.91311e+00},
128+
{ 0.00000e+00, -2.76362e+00, 0.00000e+00}, { 9.21205e-01, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
129+
{ 0.00000e+00, -0.00000e+00, -2.76362e+00}, { 0.00000e+00, -3.02739e+00, 0.00000e+00}, { 2.01826e+00, 0.00000e+00, 0.00000e+00},
130+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -0.00000e+00, -2.36662e+00}, { 0.00000e+00, -4.09910e+00, 0.00000e+00},
131+
{ 4.09910e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -0.00000e+00, -2.38995e+00}, { 4.51658e-01, 0.00000e+00, 0.00000e+00},
132+
{ 0.00000e+00, 3.16161e+00, -0.00000e+00}, { 0.00000e+00, -0.00000e+00, -3.31900e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
133+
{ 1.40813e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 3.28564e+00, -0.00000e+00}, { 0.00000e+00, -0.00000e+00, -3.11349e+00},
134+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 2.59458e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 3.63241e+00, -0.00000e+00},
135+
{ 0.00000e+00, 0.00000e+00, -2.64596e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 4.95014e+00, 0.00000e+00, 0.00000e+00},
136+
{ 0.00000e+00, 4.95014e+00, -0.00000e+00}
137+
},
138+
{
139+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.88603e-01}, {-4.88603e-01, 0.00000e+00, 0.00000e+00},
140+
{ 0.00000e+00, -4.88603e-01, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 1.26157e+00}, {-1.09255e+00, 0.00000e+00, 0.00000e+00},
141+
{ 0.00000e+00, -1.09255e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.22045e-16}, {-0.00000e+00, 0.00000e+00, -0.00000e+00},
142+
{ 0.00000e+00, 0.00000e+00, 2.23906e+00}, {-1.82818e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -1.82818e+00, 0.00000e+00},
143+
{ 0.00000e+00, 0.00000e+00, 8.81212e-16}, {-0.00000e+00, 0.00000e+00, 0.00000e+00}, {-1.84324e-16, 0.00000e+00, 0.00000e+00},
144+
{ 0.00000e+00, 5.55112e-17, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 3.38514e+00}, {-2.67619e+00, 0.00000e+00, 0.00000e+00},
145+
{ 0.00000e+00, -2.67619e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 2.30756e-15}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
146+
{-5.52973e-16, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 1.66533e-16, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
147+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.67801e+00}, {-3.62357e+00, 0.00000e+00, 0.00000e+00},
148+
{ 0.00000e+00, -3.62357e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.87108e-15}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
149+
{-1.22267e-15, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 3.68219e-16, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
150+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 4.93038e-32, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -6.16298e-33, 0.00000e+00},
151+
{ 0.00000e+00, 0.00000e+00, 6.10264e+00}, {-4.66097e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -4.66097e+00, 0.00000e+00},
152+
{ 0.00000e+00, 0.00000e+00, 8.98664e-15}, {-0.00000e+00, 0.00000e+00, 0.00000e+00}, {-2.30221e-15, 0.00000e+00, 0.00000e+00},
153+
{ 0.00000e+00, 6.93334e-16, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
154+
{ 1.77767e-31, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -2.22209e-32, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
155+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 7.64784e+00}, {-5.78122e+00, 0.00000e+00, 0.00000e+00},
156+
{ 0.00000e+00, -5.78122e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 1.51096e-14}, {-0.00000e+00, 0.00000e+00, 0.00000e+00},
157+
{-3.91011e-15, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 1.17757e-15, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00},
158+
{-0.00000e+00, 0.00000e+00, 0.00000e+00}, { 4.67737e-31, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, -5.84671e-32, 0.00000e+00},
159+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 1.13319e-47, 0.00000e+00, 0.00000e+00},
160+
{ 0.00000e+00, -1.41649e-48, 0.00000e+00}
161+
},
162+
{
163+
{ 0.00000e+00, 0.00000e+00, 0.00000e+00}, { 0.00000e+00, 0.00000e+00, 4.88603e-01}, {-4.88603e-01, 0.00000e+00, 0.00000e+00},
164+
{ 0.00000e+00, -4.88603e-01, 0.00000e+00}, { 3.64183e-01, 3.64183e-01, -7.28366e-01}, { 6.30783e-01, -0.00000e+00, 6.30783e-01},
165+
{-0.00000e+00, 6.30783e-01, 6.30783e-01}, {-6.30783e-01, 6.30783e-01, -1.66533e-16}, {-6.30783e-01, -6.30783e-01, 0.00000e+00},
166+
{-7.46353e-01, -7.46353e-01, 0.00000e+00}, { 0.00000e+00, 3.04697e-01, -1.21879e+00}, { 3.04697e-01, 0.00000e+00, -1.21879e+00},
167+
{ 9.63537e-01, -9.63537e-01, 4.01253e-16}, { 9.63537e-01, 9.63537e-01, 9.63537e-01}, {-4.44089e-16, 1.18009e+00, -2.22045e-16},
168+
{-1.18009e+00, -1.11022e-16, 0.00000e+00}, { 4.88603e-01, 4.88603e-01, 1.30294e+00}, {-1.03006e+00, -7.72548e-01, 7.72548e-01},
169+
{-7.72548e-01, -1.03006e+00, 7.72548e-01}, {-7.28366e-01, 7.28366e-01, -5.25363e-16}, {-3.64183e-01, -3.64183e-01, -2.18510e+00},
170+
{ 7.69185e-16, -2.04397e+00, -6.81324e-01}, { 2.04397e+00, 1.92296e-16, 6.81324e-01}, { 9.63537e-01, 9.63537e-01, -1.44756e-16},
171+
{-9.63537e-01, 9.63537e-01, -5.55112e-17}, { 5.19779e-01, 5.19779e-01, -1.81923e+00}, { 1.40917e+00, 8.05238e-01, 8.05238e-01},
172+
{ 8.05238e-01, 1.40917e+00, 8.05238e-01}, { 0.00000e+00, -4.44089e-16, 3.24739e-16}, {-1.06523e+00, -1.06523e+00, 2.13046e+00},
173+
{-2.17439e-01, 1.73951e+00, 1.73951e+00}, {-1.73951e+00, 2.17439e-01, -1.73951e+00}, {-1.84503e+00, -1.84503e+00, -9.22517e-01},
174+
{ 1.84503e+00, -1.84503e+00, 6.58625e-16}, { 1.45863e+00, 1.11022e-15, 0.00000e+00}, {-8.88178e-16, 1.45863e+00, 0.00000e+00},
175+
{-1.46807e+00, -1.46807e+00, 5.87227e-01}, {-4.48502e-01, -3.36617e-16, -2.24251e+00}, {-3.36617e-16, -4.48502e-01, -2.24251e+00},
176+
{ 7.09144e-01, -7.09144e-01, 1.87222e-16}, { 2.12743e+00, 2.12743e+00, -9.38779e-16}, { 7.09144e-01, -5.11006e-16, -2.12743e+00},
177+
{ 1.02201e-15, -7.09144e-01, 2.12743e+00}, { 1.81260e+00, 1.81260e+00, 2.58943e+00}, {-2.07154e+00, 2.07154e+00, -1.66969e-15},
178+
{-3.03637e+00, -2.31111e-15, -6.07275e-01}, { 1.84889e-15, -3.03637e+00, -6.07275e-01}, { 1.05183e+00, -1.05183e+00, 5.77778e-17},
179+
{ 1.05183e+00, 1.05183e+00, 4.03986e-17}, { 1.27464e+00, 1.27464e+00, 1.69952e+00}, {-1.28472e+00, -1.20442e+00, 1.92707e+00},
180+
{-1.20442e+00, -1.28472e+00, 1.92707e+00}, {-8.52285e-01, 8.52285e-01, -6.74704e-16}, {-1.50789e+00, -1.50789e+00, -2.95022e+00},
181+
{-1.11260e+00, -2.08612e+00, 9.27164e-01}, { 2.08612e+00, 1.11260e+00, -9.27164e-01}, {-3.07506e-01, -3.07506e-01, -3.69007e+00},
182+
{ 1.23002e+00, -1.23002e+00, 2.28018e-15}, { 3.69007e+00, -1.53753e-01, 1.84503e+00}, {-1.53753e-01, 3.69007e+00, 1.84503e+00},
183+
{-2.35197e+00, 2.35197e+00, -8.00513e-16}, {-2.35197e+00, -2.35197e+00, -7.83988e-01}, { 1.37903e-15, -1.46671e+00, 9.77875e-17},
184+
{ 1.46671e+00, 1.14919e-15, 1.34475e-16}
185+
}
186+
};
187+
78188
void SetUp()
79189
{
80-
nylm = (lmax + 1) * (lmax + 1);
81190
ylm.create(nylm,ng);
82191
g = new ModuleBase::Vector3<double>[ng];
83192
g[0].set(1.0,0.0,0.0);
@@ -86,7 +195,10 @@ class YlmRealTest : public testing::Test
86195
g[3].set(-1.0,-1.0,-1.0);
87196

88197
rly = new double[nylm];
89-
ref = new double[nylm*ng]{
198+
rlyvector.resize(nylm);
199+
rlgy = new double[nylm][3];
200+
rlgyvector.resize(nylm,std::vector<double>(3));
201+
ref = new double[64*4]{
90202
y00(g[0].x, g[0].y, g[0].z), y00(g[1].x, g[1].y, g[1].z), y00(g[2].x, g[2].y, g[2].z), y00(g[3].x, g[3].y, g[3].z),
91203
y10(g[0].x, g[0].y, g[0].z), y10(g[1].x, g[1].y, g[1].z), y10(g[2].x, g[2].y, g[2].z), y10(g[3].x, g[3].y, g[3].z),
92204
y11(g[0].x, g[0].y, g[0].z), y11(g[1].x, g[1].y, g[1].z), y11(g[2].x, g[2].y, g[2].z), y11(g[3].x, g[3].y, g[3].z),
@@ -152,15 +264,14 @@ class YlmRealTest : public testing::Test
152264
-0.707162732524596, 0.000000000000000, -0.000000000000000, 0.120972027847095,
153265
-0.000000000000000, 0.707162732524596, -0.000000000000000, -0.120972027847095
154266
} ;
155-
156-
157267
}
158268

159269
void TearDown()
160270
{
161271
delete [] g;
162272
delete [] ref;
163273
delete [] rly;
274+
delete [] rlgy;
164275
}
165276
};
166277

@@ -171,7 +282,7 @@ TEST_F(YlmRealTest,YlmReal)
171282
{
172283
for(int j=0;j<ng;++j)
173284
{
174-
EXPECT_NEAR(ylm(i,j),ref[i*ng+j],doublethreshold) << "i=" << i << " ,j=" << j;
285+
EXPECT_NEAR(ylm(i,j),ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
175286
}
176287
}
177288
}
@@ -184,21 +295,79 @@ TEST_F(YlmRealTest,YlmReal2)
184295
{
185296
for(int j=0;j<ng;++j)
186297
{
187-
EXPECT_NEAR(ylm(i,j),ref[i*ng+j],doublethreshold) << "i=" << i << " ,j=" << j;
298+
EXPECT_NEAR(ylm(i,j),ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
188299
}
189300
}
190301
}
191302

192303

193-
TEST_F(YlmRealTest,rlylm)
304+
TEST_F(YlmRealTest,YlmRealRlylm)
194305
{
195306
for(int j=0;j<ng;++j)
196307
{
197308
ModuleBase::YlmReal::rlylm(lmax,g[j].x,g[j].y,g[j].z,rly);
198309
for(int i=0;i<nylm;++i)
199310
{
200-
EXPECT_NEAR(rly[i],ref[i*ng+j],doublethreshold) << "i=" << i << " ,j=" << j;
311+
EXPECT_NEAR(rly[i],ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
312+
}
313+
}
314+
}
315+
316+
317+
TEST_F(YlmRealTest,YlmGetYlmReal)
318+
{
319+
for(int j=0;j<ng;++j)
320+
{
321+
ModuleBase::Ylm::get_ylm_real(lmax+1,g[j],rly);
322+
for(int i=0;i<nylm;++i)
323+
{
324+
EXPECT_NEAR(rly[i],ref[i*ng+j],1e-5) << "Ylm[" << i << "], example " << j << " not pass";
325+
}
326+
}
327+
}
328+
329+
TEST_F(YlmRealTest,YlmSphHarm)
330+
{
331+
ModuleBase::Ylm::set_coefficients ();
332+
for(int j=0;j<ng;++j)
333+
{
334+
double r = sqrt(g[j].x * g[j].x + g[j].y * g[j].y + g[j].z * g[j].z);
335+
ModuleBase::Ylm::sph_harm(lmax,g[j].x/r,g[j].y/r,g[j].z/r,rlyvector);
336+
for(int i=0;i<nylm;++i)
337+
{
338+
EXPECT_NEAR(rlyvector[i],ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
339+
201340
}
202341
}
203342
}
204343

344+
TEST_F(YlmRealTest,YlmRlSphHarm)
345+
{
346+
ModuleBase::Ylm::set_coefficients ();
347+
for(int j=0;j<ng;++j)
348+
{
349+
double r = sqrt(g[j].x * g[j].x + g[j].y * g[j].y + g[j].z * g[j].z);
350+
ModuleBase::Ylm::rl_sph_harm(lmax,g[j].x/r,g[j].y/r,g[j].z/r,rlyvector);
351+
for(int i=0;i<nylm;++i)
352+
{
353+
EXPECT_NEAR(rlyvector[i],ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
354+
355+
}
356+
}
357+
}
358+
359+
TEST_F(YlmRealTest,YlmGradRlSphHarm)
360+
{
361+
ModuleBase::Ylm::set_coefficients ();
362+
for(int j=0;j<ng;++j)
363+
{
364+
double r = sqrt(g[j].x * g[j].x + g[j].y * g[j].y + g[j].z * g[j].z);
365+
ModuleBase::Ylm::grad_rl_sph_harm(lmax,g[j].x/r,g[j].y/r,g[j].z/r,rlyvector,rlgyvector);
366+
for(int i=0;i<nylm;++i)
367+
{
368+
EXPECT_NEAR(rlyvector[i],ref[i*ng+j],doublethreshold) << "Ylm[" << i << "], example " << j << " not pass";
369+
for(int k=0;k<3;++k) {EXPECT_NEAR(rlgyvector[i][k],rlgyref[j][i][k],1e-5);}
370+
371+
}
372+
}
373+
}

0 commit comments

Comments
 (0)