Skip to content

Commit d6f28c5

Browse files
authored
Merge branch 'develop' into tool-quit-1
2 parents b54231c + da1baf5 commit d6f28c5

File tree

112 files changed

+3566
-3335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+3566
-3335
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ These variables are used to control the geometry relaxation.
13891389

13901390
- **Type**: Integer
13911391
- **Description**: The maximal number of ionic iteration steps, the minimum value is 1.
1392-
- **Default**: 1
1392+
- **Default**: 1 for SCF, 50 for relax and cell-relax calcualtions
13931393

13941394
### relax_cg_thr
13951395

source/Makefile.Objects

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,9 @@ OBJS_ESOLVER=esolver.o\
253253
OBJS_ESOLVER_LCAO=esolver_ks_lcao.o\
254254
esolver_ks_lcao_tddft.o\
255255
dpks_cal_e_delta_band.o\
256-
dftu_cal_occup_m.o\
257256
set_matrix_grid.o\
258257
lcao_before_scf.o\
259-
lcao_gets.o\
258+
esolver_gets.o\
260259
lcao_others.o\
261260
lcao_init_after_vc.o\
262261

@@ -582,7 +581,6 @@ OBJS_LCAO=evolve_elec.o\
582581
LCAO_set_fs.o\
583582
LCAO_set_st.o\
584583
LCAO_nl_mu.o\
585-
LCAO_nnr.o\
586584
LCAO_set_zero.o\
587585
LCAO_allocate.o\
588586
LCAO_set_mat2d.o\
@@ -685,7 +683,9 @@ OBJS_VDW=vdw.o\
685683
vdwd3_parameters.o\
686684
vdwd2.o\
687685
vdwd3.o\
688-
vdwd3_parameters_tab.o
686+
vdwd3_parameters_tab.o\
687+
vdwd3_autoset_xcname.o\
688+
vdwd3_autoset_xcparam.o
689689

690690
OBJS_DFTU=dftu.o\
691691
dftu_force.o\

source/driver_run.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ void Driver::driver_run() {
6767
Relax_Driver rl_driver;
6868
rl_driver.relax_driver(p_esolver);
6969
}
70+
else if (cal_type == "get_S")
71+
{
72+
p_esolver->runner(0, GlobalC::ucell);
73+
}
7074
else
7175
{
7276
//! supported "other" functions:
7377
//! get_pchg(LCAO),
7478
//! test_memory(PW,LCAO),
7579
//! test_neighbour(LCAO),
76-
//! get_S(LCAO),
7780
//! gen_bessel(PW), et al.
7881
const int istep = 0;
7982
p_esolver->others(istep);

source/module_base/formatter.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ class FmtCore
145145
[&delim](const std::string& acc, const std::string& s) { return acc + delim + s; });
146146
}
147147

148+
static std::string upper(const std::string& in)
149+
{
150+
std::string dst = in;
151+
std::transform(dst.begin(), dst.end(), dst.begin(), ::toupper);
152+
return dst;
153+
}
154+
155+
static std::string lower(const std::string& in)
156+
{
157+
std::string dst = in;
158+
std::transform(dst.begin(), dst.end(), dst.begin(), ::tolower);
159+
return dst;
160+
}
161+
148162
private:
149163
std::string fmt_;
150164
template<typename T>

source/module_base/module_mixing/test/mixing_test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#ifdef _OPENMP
55
#include <omp.h>
66
#endif
7+
78
#include "../broyden_mixing.h"
89
#include "../plain_mixing.h"
910
#include "../pulay_mixing.h"
@@ -212,6 +213,9 @@ TEST_F(Mixing_Test, PulaySolveLinearEq)
212213

213214
TEST_F(Mixing_Test, PlainSolveLinearEq)
214215
{
216+
#ifdef _OPENMP
217+
omp_set_num_threads(1);
218+
#endif
215219
init_method("plain");
216220
std::vector<double> x_in = xd_ref;
217221
std::vector<double> x_out(3);

source/module_base/test/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ AddTest(
230230
SOURCES formatter_test.cpp
231231
)
232232

233+
AddTest(
234+
TARGET lebedev_laikov
235+
SOURCES test_lebedev_laikov.cpp ../ylm.cpp ../math_lebedev_laikov.cpp
236+
)
237+
233238
if(ENABLE_GOOGLEBENCH)
234239
AddTest(
235240
TARGET perf_sphbes
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
#include "module_base/math_lebedev_laikov.h"
2+
#include "module_base/ylm.h"
3+
4+
#include "gtest/gtest.h"
5+
#include <random>
6+
#ifdef __MPI
7+
#include <mpi.h>
8+
#endif
9+
10+
using ModuleBase::Lebedev_laikov_grid;
11+
12+
// mock the function to prevent unnecessary dependency
13+
namespace ModuleBase {
14+
void WARNING_QUIT(const std::string&, const std::string&) {}
15+
}
16+
17+
class LebedevLaikovTest: public ::testing::Test {
18+
protected:
19+
void randgen(int lmax, std::vector<double>& coef);
20+
const double tol = 1e-12;
21+
};
22+
23+
24+
void LebedevLaikovTest::randgen(int lmax, std::vector<double>& coef) {
25+
coef.resize((lmax + 1) * (lmax + 1));
26+
27+
// fill coef with uniformly distributed random numbers
28+
std::random_device rd;
29+
std::mt19937 gen(rd());
30+
std::uniform_real_distribution<double> dis(0.0, 1.0);
31+
for (size_t i = 0; i < coef.size(); ++i) {
32+
coef[i] = dis(gen);
33+
}
34+
35+
// normalize the coefficients
36+
double fac = 0.0;
37+
for (size_t i = 0; i < coef.size(); ++i) {
38+
fac += coef[i] * coef[i];
39+
}
40+
41+
fac = 1.0 / std::sqrt(fac);
42+
for (size_t i = 0; i < coef.size(); ++i) {
43+
coef[i] *= fac;
44+
}
45+
}
46+
47+
48+
TEST_F(LebedevLaikovTest, Accuracy) {
49+
/*
50+
* Given
51+
*
52+
* f = c[0]*Y00 + c[1]*Y10 + c[2]*Y11 + ...,
53+
*
54+
* where c[0], c[1], c[2], ... are some random numbers, the integration
55+
* of |f|^2 on the unit sphere
56+
*
57+
* \int |f|^2 d\Omega = c[0]^2 + c[1]^2 + c[2]^2 + ... .
58+
*
59+
* This test verifies with the above integral that quadrature with
60+
* Lebedev grid is exact up to floating point errors.
61+
*
62+
*/
63+
64+
// (ngrid, lmax)
65+
std::set<std::pair<int, int>> supported = {
66+
{6, 3},
67+
{14, 5},
68+
{26, 7},
69+
{38, 9},
70+
{50, 11},
71+
{74, 13},
72+
{86, 15},
73+
{110, 17},
74+
{146, 19},
75+
{170, 21},
76+
{194, 23},
77+
{230, 25},
78+
{266, 27},
79+
{302, 29},
80+
{350, 31},
81+
{434, 35},
82+
{590, 41},
83+
{770, 47},
84+
{974, 53},
85+
{1202, 59},
86+
{1454, 65},
87+
{1730, 71},
88+
{2030, 77},
89+
{2354, 83},
90+
{2702, 89},
91+
{3074, 95},
92+
{3470, 101},
93+
{3890, 107},
94+
{4334, 113},
95+
{4802, 119},
96+
{5294, 125},
97+
{5810, 131},
98+
};
99+
100+
std::vector<double> coef;
101+
102+
for (auto& grid_info: supported) {
103+
int ngrid = grid_info.first;
104+
int grid_lmax = grid_info.second;
105+
106+
Lebedev_laikov_grid lebgrid(ngrid);
107+
lebgrid.generate_grid_points();
108+
109+
const double* weight = lebgrid.get_weight();
110+
const ModuleBase::Vector3<double>* grid = lebgrid.get_grid_coor();
111+
112+
int func_lmax = grid_lmax / 2;
113+
randgen(func_lmax, coef);
114+
115+
double val = 0.0;
116+
std::vector<double> ylm_real;
117+
for (int i = 0; i < ngrid; i++) {
118+
ModuleBase::Ylm::sph_harm(func_lmax,
119+
grid[i].x, grid[i].y, grid[i].z, ylm_real);
120+
double tmp = 0.0;
121+
for (size_t j = 0; j < coef.size(); ++j) {
122+
tmp += coef[j] * ylm_real[j];
123+
}
124+
val += weight[i] * tmp * tmp;
125+
}
126+
127+
double val_ref = 0.0;
128+
for (size_t i = 0; i < coef.size(); ++i) {
129+
val_ref += coef[i] * coef[i];
130+
}
131+
132+
double abs_diff = std::abs(val - val_ref);
133+
EXPECT_LT(abs_diff, tol);
134+
}
135+
}
136+
137+
138+
int main(int argc, char** argv)
139+
{
140+
#ifdef __MPI
141+
MPI_Init(&argc, &argv);
142+
#endif
143+
144+
testing::InitGoogleTest(&argc, argv);
145+
int result = RUN_ALL_TESTS();
146+
147+
#ifdef __MPI
148+
MPI_Finalize();
149+
#endif
150+
151+
return result;
152+
}

source/module_basis/module_ao/parallel_orbitals.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ int Parallel_Orbitals::set_nloc_wfc_Eij(
247247
}
248248
else
249249
{
250-
ModuleBase::WARNING_QUIT("Parallel_Orbitals::set_nloc_wfc_Eij", "some processor has no bands-row-blocks.");
250+
ModuleBase::WARNING_QUIT("Parallel_Orbitals::set_nloc_wfc_Eij",
251+
"The number of columns of the 2D process grid exceeds the number of bands. "
252+
"Try launching the calculation with fewer MPI processes."
253+
);
251254
}
252255
}
253256
int col_b_bands = block / dim1;

source/module_basis/module_nao/two_center_bundle.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void TwoCenterBundle::tabulate()
6363
{
6464
ModuleBase::SphericalBesselTransformer sbt(true);
6565
orb_->set_transformer(sbt);
66-
beta_->set_transformer(sbt);
66+
if (beta_) { beta_->set_transformer(sbt); }
6767
if (alpha_) {
6868
alpha_->set_transformer(sbt);
6969
}
@@ -75,22 +75,17 @@ void TwoCenterBundle::tabulate()
7575
// build two-center integration tables
7676
//================================================================
7777
// set up a universal radial grid
78-
double rmax = std::max(orb_->rcut_max(), beta_->rcut_max());
79-
if (alpha_) {
80-
rmax = std::max(rmax, alpha_->rcut_max());
81-
}
78+
double rmax = orb_->rcut_max();
79+
if (beta_) { rmax = std::max(rmax, beta_->rcut_max()); }
80+
if (alpha_) { rmax = std::max(rmax, alpha_->rcut_max()); }
8281
double dr = 0.01;
8382
double cutoff = 2.0 * rmax;
8483
int nr = static_cast<int>(rmax / dr) + 1;
8584

8685
orb_->set_uniform_grid(true, nr, cutoff, 'i', true);
87-
beta_->set_uniform_grid(true, nr, cutoff, 'i', true);
88-
if (alpha_) {
89-
alpha_->set_uniform_grid(true, nr, cutoff, 'i', true);
90-
}
91-
if (orb_onsite_) {
92-
orb_onsite_->set_uniform_grid(true, nr, cutoff, 'i', true);
93-
}
86+
if (beta_) { beta_->set_uniform_grid(true, nr, cutoff, 'i', true); }
87+
if (alpha_) { alpha_->set_uniform_grid(true, nr, cutoff, 'i', true);}
88+
if (orb_onsite_) { orb_onsite_->set_uniform_grid(true, nr, cutoff, 'i', true);}
9489

9590
// build TwoCenterIntegrator objects
9691
kinetic_orb = std::unique_ptr<TwoCenterIntegrator>(new TwoCenterIntegrator);
@@ -101,9 +96,12 @@ void TwoCenterBundle::tabulate()
10196
overlap_orb->tabulate(*orb_, *orb_, 'S', nr, cutoff);
10297
ModuleBase::Memory::record("TwoCenterTable: Overlap", overlap_orb->table_memory());
10398

104-
overlap_orb_beta = std::unique_ptr<TwoCenterIntegrator>(new TwoCenterIntegrator);
105-
overlap_orb_beta->tabulate(*orb_, *beta_, 'S', nr, cutoff);
106-
ModuleBase::Memory::record("TwoCenterTable: Nonlocal", overlap_orb_beta->table_memory());
99+
if (beta_)
100+
{
101+
overlap_orb_beta = std::unique_ptr<TwoCenterIntegrator>(new TwoCenterIntegrator);
102+
overlap_orb_beta->tabulate(*orb_, *beta_, 'S', nr, cutoff);
103+
ModuleBase::Memory::record("TwoCenterTable: Nonlocal", overlap_orb_beta->table_memory());
104+
}
107105

108106
if (alpha_)
109107
{

source/module_basis/module_pw/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ if (ENABLE_FLOAT_FFTW)
33
module_fft/fft_cpu_float.cpp
44
)
55
endif()
6+
if (USE_CUDA)
7+
list (APPEND FFT_SRC
8+
module_fft/fft_cuda.cpp
9+
)
10+
endif()
11+
if (USE_ROCM)
12+
list (APPEND FFT_SRC
13+
module_fft/fft_rcom.cpp
14+
)
15+
endif()
16+
617
list(APPEND objects
718
fft.cpp
819
pw_basis.cpp

0 commit comments

Comments
 (0)