Skip to content

Commit 289f798

Browse files
authored
add unit test for class Numerical_Nonlocal_Lm (#2010)
* add unit test for class Numerical_Nonlocal_Lm * enable __MPI for orbital_equal_test * add comment for the unit test of Numerical_Nonlocal_Lm
1 parent a1437b7 commit 289f798

File tree

13 files changed

+4844
-4
lines changed

13 files changed

+4844
-4
lines changed

source/module_orbital/ORB_nonlocal_lm.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ void Numerical_Nonlocal_Lm::freemem(void)
6363
delete[] this->dbeta_uniform;
6464
delete[] this->k_radial;
6565
delete[] this->beta_k;
66+
67+
r_radial = nullptr;
68+
rab = nullptr;
69+
beta_r = nullptr;
70+
beta_uniform = nullptr;
71+
dbeta_uniform = nullptr;
72+
k_radial = nullptr;
73+
beta_k = nullptr;
6674
}
6775

6876
Numerical_Nonlocal_Lm& Numerical_Nonlocal_Lm::operator=
@@ -73,6 +81,7 @@ Numerical_Nonlocal_Lm& Numerical_Nonlocal_Lm::operator=
7381
this->label = nol.label;
7482
this->index_atom_type = nol.index_atom_type;
7583
this->angular_momentum_l = nol.angular_momentum_l;
84+
this->index_proj = nol.index_proj;
7685

7786
this->nr = nol.nr;
7887
this->nk = nol.nk;
@@ -167,6 +176,14 @@ void Numerical_Nonlocal_Lm::set_NL_proj(
167176
return;
168177
}
169178

179+
/*
180+
// extra_uniform currently does not work, because
181+
// beta[ir] = this->beta_r[ir]/r_radial[ir];
182+
// does not work for ir==0, and this formula is not stable for small r.
183+
//
184+
// If one really needs beta (in what circumstance?), one should do
185+
// extrapolation to reach r=0.
186+
170187
void Numerical_Nonlocal_Lm::extra_uniform(const double &dr_uniform_in)
171188
{
172189
assert(dr_uniform_in>0.0);
@@ -226,7 +243,7 @@ void Numerical_Nonlocal_Lm::extra_uniform(const double &dr_uniform_in)
226243
delete [] tmp1;
227244
return;
228245
}
229-
246+
*/
230247

231248
void Numerical_Nonlocal_Lm::get_kradial(void)
232249
{

source/module_orbital/ORB_nonlocal_lm.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Numerical_Nonlocal_Lm
4646
const double* getBeta_k() const { return this->beta_k; }
4747
const double& getBeta_k(const int &ik) const { return this->beta_k[ik]; }
4848

49+
// enables deep copy
4950
Numerical_Nonlocal_Lm& operator= (const Numerical_Nonlocal_Lm& nol );
5051

5152
void set_NL_proj(
@@ -66,7 +67,7 @@ class Numerical_Nonlocal_Lm
6667

6768
void freemem(void);
6869
void renew(void);
69-
void extra_uniform(const double &dr_uniform);
70+
//void extra_uniform(const double &dr_uniform);
7071
void get_kradial(void);
7172

7273
std::string label;

source/module_orbital/test/1_snap_equal_test.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include<gtest/gtest.h>
22
#include"ORB_unittest.h"
3+
#include "module_base/global_variable.h"
34

45
//Test whether the 2-center-int results
56
// and its derivative from two clases are equal.
@@ -69,4 +70,23 @@ TEST_F(test_orb, equal_test)
6970
}
7071
}
7172
}
72-
}
73+
}
74+
75+
int main(int argc, char **argv)
76+
{
77+
78+
#ifdef __MPI
79+
MPI_Init(&argc, &argv);
80+
MPI_Comm_size(MPI_COMM_WORLD,&GlobalV::NPROC);
81+
MPI_Comm_rank(MPI_COMM_WORLD,&GlobalV::MY_RANK);
82+
#endif
83+
testing::InitGoogleTest(&argc, argv);
84+
int result = RUN_ALL_TESTS();
85+
86+
#ifdef __MPI
87+
MPI_Finalize();
88+
#endif
89+
90+
return result;
91+
}
92+

source/module_orbital/test/CMakeLists.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
remove_definitions(-D__MPI)
21
remove_definitions(-D__EXX)
32

43
list(APPEND depend_files
@@ -46,3 +45,37 @@ AddTest(
4645
)
4746
install(DIRECTORY GaAs DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../../../tests)
4847
install(DIRECTORY GaAs DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
48+
49+
50+
AddTest(
51+
TARGET ORB_nonlocal_lm_test
52+
SOURCES ORB_nonlocal_lm_test.cpp
53+
../ORB_nonlocal_lm.cpp
54+
LIBS ${math_libs} device base
55+
)
56+
57+
#AddTest(
58+
# TARGET ORB_read_test
59+
# SOURCES ORB_read_test.cpp
60+
# ${depend_files}
61+
# ../../module_base/parallel_reduce.cpp
62+
# ../../module_base/parallel_global.cpp
63+
# ../../module_base/parallel_common.cpp
64+
# ../../module_cell/parallel_kpoints.cpp
65+
# LIBS ${math_libs} device
66+
#)
67+
#
68+
#AddTest(
69+
# TARGET ORB_atomic_lm_test
70+
# SOURCES ORB_atomic_lm_test.cpp
71+
# ${depend_files}
72+
# ../../module_base/parallel_reduce.cpp
73+
# ../../module_base/parallel_global.cpp
74+
# ../../module_base/parallel_common.cpp
75+
# ../../module_cell/parallel_kpoints.cpp
76+
# LIBS ${math_libs} device
77+
#)
78+
79+
install(DIRECTORY lcao_H2O DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
80+
install(DIRECTORY lcao_H2O DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../../../tests)
81+

0 commit comments

Comments
 (0)