Skip to content

Commit b98fce1

Browse files
authored
Merge pull request #634 from maki49/hybrid_force
Test: add the unit test of module_orbital
2 parents c4b0127 + f26107a commit b98fce1

File tree

18 files changed

+543
-215
lines changed

18 files changed

+543
-215
lines changed

source/module_md/test/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,21 @@ list(APPEND depend_files
4242

4343
AddTest(
4444
TARGET md_LJ_pot
45+
LIBS ${math_libs}
4546
SOURCES LJ_pot_test.cpp
4647
${depend_files}
4748
)
4849

4950
AddTest(
5051
TARGET md_func
52+
LIBS ${math_libs}
5153
SOURCES MD_func_test.cpp
5254
${depend_files}
5355
)
5456

5557
AddTest(
5658
TARGET md_fire
59+
LIBS ${math_libs}
5760
SOURCES FIRE_test.cpp
5861
../verlet.cpp
5962
../FIRE.cpp
@@ -62,6 +65,7 @@ AddTest(
6265

6366
AddTest(
6467
TARGET md_nve
68+
LIBS ${math_libs}
6569
SOURCES NVE_test.cpp
6670
../verlet.cpp
6771
../NVE.cpp
@@ -70,6 +74,7 @@ AddTest(
7074

7175
AddTest(
7276
TARGET md_nvt_ads
77+
LIBS ${math_libs}
7378
SOURCES NVT_ADS_test.cpp
7479
../verlet.cpp
7580
../NVT_ADS.cpp
@@ -78,6 +83,7 @@ AddTest(
7883

7984
AddTest(
8085
TARGET md_nvt_nhc
86+
LIBS ${math_libs}
8187
SOURCES NVT_NHC_test.cpp
8288
../verlet.cpp
8389
../NVT_NHC.cpp
@@ -86,6 +92,7 @@ AddTest(
8692

8793
AddTest(
8894
TARGET md_msst
95+
LIBS ${math_libs}
8996
SOURCES MSST_test.cpp
9097
../verlet.cpp
9198
../MSST.cpp
@@ -94,6 +101,7 @@ AddTest(
94101

95102
AddTest(
96103
TARGET md_lgv
104+
LIBS ${math_libs}
97105
SOURCES Langevin_test.cpp
98106
../verlet.cpp
99107
../Langevin.cpp

source/module_orbital/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ add_library(
1313
ORB_table_beta.cpp
1414
ORB_table_phi.cpp
1515
)
16+
17+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
IF (BUILD_TESTING)
19+
set(CMAKE_CXX_STANDARD 14)
20+
add_subdirectory(test)
21+
endif()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include<gtest/gtest.h>
2+
#include"ORB_unittest.h"
3+
4+
//Test whether the 2-center-int results
5+
// and its derivative from two clases are equal.
6+
// - ORB_gen_table::snap_psipsi(job=0) and Center2_Orb::Orb11::cal_overlap
7+
// - ORB_gen_table::snap_psipsi(job=1) and Center2_Orb::Orb11::cal_grad_overlap
8+
TEST_F(test_orb, equal_test)
9+
{
10+
11+
this->set_center2orbs();
12+
//equal test
13+
//orb
14+
double olm_0[1] = { 0 };
15+
double olm_1[3] = { 0,0,0 };
16+
//center2orb
17+
double clm_0 = 0;
18+
ModuleBase::Vector3<double> clm_1;
19+
20+
//test parameters
21+
const double rmax = 5; //Ry
22+
srand((unsigned)time(NULL));
23+
ModuleBase::Vector3<double> R1(0, 0, 0);
24+
ModuleBase::Vector3<double> R2(randr(rmax), randr(rmax), randr(rmax));
25+
std::cout << "random R2=(" << R2.x << "," << R2.y << "," << R2.z << ")" << std::endl;
26+
ModuleBase::Vector3<double> dR = ModuleBase::Vector3<double>(0.001, 0.001, 0.001);
27+
//4. calculate overlap and grad_overlap by both methods
28+
int T1 = 0;
29+
30+
for (int T2 = 0;T2 < ORB.get_ntype();++T2)
31+
{
32+
for (int L1 = 0;L1 < ORB.Phi[T1].getLmax();++L1)
33+
{
34+
for (int N1 = 0;N1 < ORB.Phi[T1].getNchi(L1);++N1)
35+
{
36+
for (int L2 = 0;L2 < ORB.Phi[T2].getLmax();++L2)
37+
{
38+
for (int N2 = 0;N2 < ORB.Phi[T2].getNchi(L2);++N2)
39+
{
40+
for (int m1 = 0;m1 < 2 * L1 + 1;++m1)
41+
{
42+
for (int m2 = 0;m2 < 2 * L2 + 1;++m2)
43+
{
44+
OGT.snap_psipsi(
45+
ORB, olm_0, 0, 'S',
46+
R1, T1, L1, m1, N1,
47+
R2, T2, L2, m2, N2,
48+
1, NULL);
49+
OGT.snap_psipsi(
50+
ORB, olm_1, 1, 'S',
51+
R1, T1, L1, m1, N1,
52+
R2, T2, L2, m2, N2,
53+
1, NULL);
54+
//std::cout << this->mock_center2_orb11[T1][T2][L1][N1][L2][N2]->cal_overlap(R1, R2, m1, m2);
55+
clm_0 =
56+
test_center2_orb11[T1][T2][L1][N1][L2][N2]->cal_overlap(R1, R2, m1, m2);
57+
clm_1 =
58+
test_center2_orb11[T1][T2][L1][N1][L2][N2]->cal_grad_overlap(R1, R2, m1, m2);
59+
EXPECT_NEAR(olm_0[0], clm_0, 1e-10);
60+
EXPECT_NEAR(olm_1[0], clm_1.x, 1e-10);
61+
EXPECT_NEAR(olm_1[1], clm_1.y, 1e-10);
62+
EXPECT_NEAR(olm_1[2], clm_1.z, 1e-10);
63+
ModuleBase::GlobalFunc::ZEROS(olm_1, 3);
64+
}
65+
}
66+
}
67+
68+
}
69+
}
70+
}
71+
}
72+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
remove_definitions(-D__MPI)
2+
3+
list(APPEND depend_files
4+
../../module_base/math_integral.cpp
5+
../../module_base/math_sphbes.cpp
6+
../../module_base/math_polyint.cpp
7+
../../module_base/math_ylmreal.cpp
8+
../../module_base/ylm.cpp
9+
../../module_base/memory.cpp
10+
../../module_base/complexarray.cpp
11+
../../module_base/complexmatrix.cpp
12+
../../module_base/matrix.cpp
13+
../../module_base/realarray.cpp
14+
../../module_base/intarray.cpp
15+
../../module_base/sph_bessel.cpp
16+
../../module_base/sph_bessel_recursive-d1.cpp
17+
../../module_base/sph_bessel_recursive-d2.cpp
18+
../../module_base/tool_title.cpp
19+
../../module_base/tool_quit.cpp
20+
../../module_base/tool_check.cpp
21+
../../module_base/timer.cpp
22+
../../module_base/mathzone_add1.cpp
23+
../../module_base/global_variable.cpp
24+
../../module_base/global_function.cpp
25+
../../module_base/global_file.cpp
26+
../ORB_control.cpp
27+
../ORB_read.cpp
28+
../ORB_atomic.cpp
29+
../ORB_atomic_lm.cpp
30+
../ORB_nonlocal.cpp
31+
../ORB_nonlocal_lm.cpp
32+
../ORB_gaunt_table.cpp
33+
../ORB_table_beta.cpp
34+
../ORB_table_phi.cpp
35+
../ORB_table_alpha.cpp
36+
../ORB_gen_tables.cpp
37+
../../src_lcao/center2_orb-orb11.cpp
38+
)
39+
AddTest(
40+
TARGET orbital_equal_test
41+
LIBS ${math_libs}
42+
SOURCES 1_snap_equal_test.cpp ORB_unittest.cpp
43+
${depend_files}
44+
)
45+
install(DIRECTORY GaAs DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../../../tests)
46+
install(DIRECTORY GaAs DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/module_orb/src/Makefile renamed to source/module_orbital/test/Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
#==========================
66
CPLUSPLUS = icpc
77
CPLUSPLUS_MPI = icpc
8-
FFTW_DIR = /home/liwenfei/codes/FFTW3
8+
FFTW_DIR = /home/fortneu49/soft/fftw-3.3.8
99
OBJ_DIR = orb_obj
10+
GTEST_DIR = /usr/local/lib
11+
GMOCK_DIR = /usr/local/lib
1012
NP = 1
1113

1214
#==========================
@@ -20,7 +22,7 @@ FFTW_LIB = -L${FFTW_LIB_DIR} -lfftw3 -Wl,-rpath=${FFTW_LIB_DIR}
2022
#==========================
2123
# LIBS and INCLUDES
2224
#==========================
23-
LIBS = -lifcore -lm -lpthread ${FFTW_LIB}
25+
LIBS = -lifcore -lm -lpthread ${FFTW_LIB} ${GTEST_DIR}/libgtest.a ${GMOCK_DIR}/libgmock.a
2426

2527
#==========================
2628
# OPTIMIZE OPTIONS
@@ -29,13 +31,14 @@ INCLUDES = -I. -Icommands -I${FFTW_INCLUDE_DIR}
2931

3032
# -pedantic turns off more extensions and generates more warnings
3133
# -xHost generates instructions for the highest instruction set available on the compilation host processor
32-
OPTS = ${INCLUDES} -Ofast -std=c++11 -simd -march=native -xHost -m64 -qopenmp -Werror -Wall -pedantic -g
34+
OPTS = ${INCLUDES} -Ofast -std=c++14 -simd -march=native -m64 -qopenmp -Werror -Wall -pedantic -g
3335

3436
include Makefile.Objects
3537

3638
VPATH=../../../source/module_base\
3739
:../../../source/src_global\
3840
:../../../source/module_orbital\
41+
:../../../source/src_lcao\
3942
:./\
4043

4144
#==========================
@@ -46,6 +49,8 @@ HONG= -DMETIS -DMKL_ILP64 -D__NORMAL -D__ORBITAL ${HONG_FFTW}
4649
FP_OBJS_0=main.o\
4750
$(OBJS_BASE)\
4851
$(OBJS_ORBITAL)\
52+
$(OBJS_CTO)\
53+
$(OBJS_TEST)\
4954

5055
FP_OBJS=$(patsubst %.o, ${OBJ_DIR}/%.o, ${FP_OBJS_0})
5156

@@ -60,7 +65,7 @@ init :
6065
@ if [ ! -d $(OBJ_DIR) ]; then mkdir $(OBJ_DIR); fi
6166
@ if [ ! -d $(OBJ_DIR)/README ]; then echo "This directory contains all of the .o files" > $(OBJ_DIR)/README; fi
6267

63-
serial : ${FP_OBJS}
68+
serial : ${FP_OBJS}
6469
${CPLUSPLUS} ${OPTS} $(FP_OBJS) ${LIBS} -o ${VERSION}.x
6570

6671
#==========================

tests/module_orb/src/Makefile.Objects renamed to source/module_orbital/test/Makefile.Objects

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,10 @@ ORB_table_beta.o\
3939
ORB_table_phi.o\
4040
ORB_table_alpha.o\
4141
ORB_gen_tables.o\
42-
ORB_unittest.o\
42+
43+
OBJS_CTO=center2_orb-orb11.o\
44+
45+
OBJS_TEST=ORB_unittest.o\
46+
1_snap_equal_test.o\
47+
#2_snap_finite_diff_test.o\
48+
#3_center2_finite_diff_test.o\

0 commit comments

Comments
 (0)