Skip to content

Commit 12f8b4a

Browse files
authored
Merge branch 'develop' into mybfgs
2 parents 97211a5 + 48788b8 commit 12f8b4a

Some content is hidden

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

58 files changed

+1422
-1591
lines changed

source/Makefile.Objects

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ OBJS_LCAO=evolve_elec.o\
585585
LCAO_set_fs.o\
586586
LCAO_set_st.o\
587587
LCAO_nl_mu.o\
588-
LCAO_nnr.o\
589588
LCAO_set_zero.o\
590589
LCAO_allocate.o\
591590
LCAO_set_mat2d.o\

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef _OPENMP
12
#include <omp.h>
3+
#endif
24

35
#include "../broyden_mixing.h"
46
#include "../plain_mixing.h"
@@ -151,7 +153,9 @@ class Mixing_Test : public testing::Test
151153

152154
TEST_F(Mixing_Test, BroydenSolveLinearEq)
153155
{
156+
#ifdef _OPENMP
154157
omp_set_num_threads(1);
158+
#endif
155159
init_method("broyden");
156160
std::vector<double> x_in = xd_ref;
157161
std::vector<double> x_out(3);
@@ -196,7 +200,9 @@ TEST_F(Mixing_Test, BroydenSolveLinearEq)
196200

197201
TEST_F(Mixing_Test, PulaySolveLinearEq)
198202
{
203+
#ifdef _OPENMP
199204
omp_set_num_threads(1);
205+
#endif
200206
init_method("pulay");
201207
std::vector<double> x_in = xd_ref;
202208
std::vector<double> x_out(3);
@@ -242,7 +248,9 @@ TEST_F(Mixing_Test, PulaySolveLinearEq)
242248

243249
TEST_F(Mixing_Test, PlainSolveLinearEq)
244250
{
251+
#ifdef _OPENMP
245252
omp_set_num_threads(1);
253+
#endif
246254
init_method("plain");
247255
std::vector<double> x_in = xd_ref;
248256
std::vector<double> x_out(3);

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_elecstate/test/charge_mixing_test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
#include "module_basis/module_pw/pw_basis.h"
1111
#include "module_hamilt_general/module_xc/xc_functional.h"
1212
#undef private
13+
14+
#ifdef _OPENMP
1315
#include <omp.h>
16+
#endif
1417

1518
int FUNC_TYPE = 1;
1619

@@ -116,7 +119,9 @@ class ChargeMixingTest : public ::testing::Test
116119

117120
TEST_F(ChargeMixingTest, SetMixingTest)
118121
{
122+
#ifdef _OPENMP
119123
omp_set_num_threads(1);
124+
#endif
120125
PARAM.input.nspin = 1;
121126
Charge_Mixing CMtest;
122127
CMtest.set_rhopw(&pw_basis, &pw_basis);
@@ -214,7 +219,9 @@ TEST_F(ChargeMixingTest, SetMixingTest)
214219

215220
TEST_F(ChargeMixingTest, InitMixingTest)
216221
{
222+
#ifdef _OPENMP
217223
omp_set_num_threads(1);
224+
#endif
218225
PARAM.input.nspin = 1;
219226
FUNC_TYPE = 1;
220227
Charge_Mixing CMtest;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,22 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(const int istep, const int iter)
634634

635635
#ifdef __EXX
636636
// calculate exact-exchange
637-
if (GlobalC::exx_info.info_ri.real_number)
638-
{
639-
this->exd->exx_eachiterinit(istep,
640-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
641-
this->kv,
642-
iter);
643-
}
644-
else
637+
if (PARAM.inp.calculation != "nscf")
645638
{
646-
this->exc->exx_eachiterinit(istep,
647-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
648-
this->kv,
649-
iter);
639+
if (GlobalC::exx_info.info_ri.real_number)
640+
{
641+
this->exd->exx_eachiterinit(istep,
642+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
643+
this->kv,
644+
iter);
645+
}
646+
else
647+
{
648+
this->exc->exx_eachiterinit(istep,
649+
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
650+
this->kv,
651+
iter);
652+
}
650653
}
651654
#endif
652655

@@ -728,13 +731,16 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2density_single(int istep, int iter, double
728731

729732
// 5) what's the exd used for?
730733
#ifdef __EXX
731-
if (GlobalC::exx_info.info_ri.real_number)
734+
if (PARAM.inp.calculation != "nscf")
732735
{
733-
this->exd->exx_hamilt2density(*this->pelec, this->pv, iter);
734-
}
735-
else
736-
{
737-
this->exc->exx_hamilt2density(*this->pelec, this->pv, iter);
736+
if (GlobalC::exx_info.info_ri.real_number)
737+
{
738+
this->exd->exx_hamilt2density(*this->pelec, this->pv, iter);
739+
}
740+
else
741+
{
742+
this->exc->exx_hamilt2density(*this->pelec, this->pv, iter);
743+
}
738744
}
739745
#endif
740746

@@ -921,11 +927,29 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(const int istep, int& iter)
921927

922928
#ifdef __EXX
923929
// 3) save exx matrix
924-
if (GlobalC::exx_info.info_global.cal_exx)
930+
if (PARAM.inp.calculation != "nscf")
925931
{
926-
GlobalC::exx_info.info_ri.real_number ?
927-
this->exd->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, istep, this->conv_esolver) :
928-
this->exc->exx_iter_finish(this->kv, GlobalC::ucell, *this->p_hamilt, *this->pelec, *this->p_chgmix, this->scf_ene_thr, iter, istep, this->conv_esolver);
932+
if (GlobalC::exx_info.info_global.cal_exx)
933+
{
934+
GlobalC::exx_info.info_ri.real_number ? this->exd->exx_iter_finish(this->kv,
935+
GlobalC::ucell,
936+
*this->p_hamilt,
937+
*this->pelec,
938+
*this->p_chgmix,
939+
this->scf_ene_thr,
940+
iter,
941+
istep,
942+
this->conv_esolver)
943+
: this->exc->exx_iter_finish(this->kv,
944+
GlobalC::ucell,
945+
*this->p_hamilt,
946+
*this->pelec,
947+
*this->p_chgmix,
948+
this->scf_ene_thr,
949+
iter,
950+
istep,
951+
this->conv_esolver);
952+
}
929953
}
930954
#endif
931955

@@ -1040,17 +1064,20 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(const int istep)
10401064

10411065
#ifdef __EXX
10421066
// 5) write Hexx matrix for NSCF (see `out_chg` in docs/advanced/input_files/input-main.md)
1043-
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.out_chg[0]
1044-
&& istep % PARAM.inp.out_interval == 0) // Peize Lin add if 2022.11.14
1067+
if (PARAM.inp.calculation != "nscf")
10451068
{
1046-
const std::string file_name_exx = PARAM.globalv.global_out_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
1047-
if (GlobalC::exx_info.info_ri.real_number)
1069+
if (GlobalC::exx_info.info_global.cal_exx && PARAM.inp.out_chg[0]
1070+
&& istep % PARAM.inp.out_interval == 0) // Peize Lin add if 2022.11.14
10481071
{
1049-
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exd->get_Hexxs());
1050-
}
1051-
else
1052-
{
1053-
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exc->get_Hexxs());
1072+
const std::string file_name_exx = PARAM.globalv.global_out_dir + "HexxR" + std::to_string(GlobalV::MY_RANK);
1073+
if (GlobalC::exx_info.info_ri.real_number)
1074+
{
1075+
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exd->get_Hexxs());
1076+
}
1077+
else
1078+
{
1079+
ModuleIO::write_Hexxs_csr(file_name_exx, GlobalC::ucell, this->exc->get_Hexxs());
1080+
}
10541081
}
10551082
}
10561083
#endif

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -422,19 +422,21 @@ void ESolver_KS_PW<T, Device>::update_pot(const int istep, const int iter)
422422
template <typename T, typename Device>
423423
void ESolver_KS_PW<T, Device>::iter_finish(const int istep, int& iter)
424424
{
425-
// call iter_finish() of ESolver_KS
425+
// 1) Call iter_finish() of ESolver_KS
426426
ESolver_KS<T, Device>::iter_finish(istep, iter);
427427

428-
// liuyu 2023-10-24
428+
// 2) Update USPP-related quantities
429429
// D in uspp need vloc, thus needs update when veff updated
430430
// calculate the effective coefficient matrix for non-local pseudopotential
431-
// projectors
431+
// projectors
432+
// liuyu 2023-10-24
432433
if (PARAM.globalv.use_uspp)
433434
{
434435
ModuleBase::matrix veff = this->pelec->pot->get_effective_v();
435436
GlobalC::ppcell.cal_effective_D(veff, this->pw_rhod, GlobalC::ucell);
436437
}
437438

439+
// 3) Print out charge density
438440
if (this->out_freq_elec && iter % this->out_freq_elec == 0)
439441
{
440442
if (PARAM.inp.out_chg[0] > 0)
@@ -475,7 +477,8 @@ void ESolver_KS_PW<T, Device>::iter_finish(const int istep, int& iter)
475477
}
476478
}
477479
}
478-
// output wavefunctions
480+
481+
// 4) Print out electronic wavefunctions
479482
if (this->wf.out_wfc_pw == 1 || this->wf.out_wfc_pw == 2)
480483
{
481484
std::stringstream ssw;
@@ -509,6 +512,7 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
509512
ModuleIO::write_wfc_pw(ssw.str(), this->psi[0], this->kv, this->pw_wfc);
510513
}
511514

515+
// 4) Transfer data from GPU to CPU
512516
if (this->device == base_device::GpuDevice)
513517
{
514518
castmem_2d_d2h_op()(this->psi[0].get_device(),
@@ -518,7 +522,7 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
518522
this->psi[0].size());
519523
}
520524

521-
// Calculate band-decomposed (partial) charge density
525+
// 5) Calculate band-decomposed (partial) charge density
522526
const std::vector<int> bands_to_print = PARAM.inp.bands_to_print;
523527
if (bands_to_print.size() > 0)
524528
{
@@ -545,7 +549,7 @@ void ESolver_KS_PW<T, Device>::after_scf(const int istep)
545549
PARAM.inp.if_separate_k);
546550
}
547551

548-
//! 6) calculate Wannier functions
552+
//! 6) Calculate Wannier functions
549553
if (PARAM.inp.calculation == "nscf" && PARAM.inp.towannier90)
550554
{
551555
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "Wannier functions calculation");
@@ -638,6 +642,7 @@ void ESolver_KS_PW<T, Device>::cal_stress(ModuleBase::matrix& stress)
638642
template <typename T, typename Device>
639643
void ESolver_KS_PW<T, Device>::after_all_runners()
640644
{
645+
//! 1) Output information to screen
641646
GlobalV::ofs_running << "\n\n --------------------------------------------" << std::endl;
642647
GlobalV::ofs_running << std::setprecision(16);
643648
GlobalV::ofs_running << " !FINAL_ETOT_IS " << this->pelec->f_en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl;
@@ -681,10 +686,11 @@ void ESolver_KS_PW<T, Device>::after_all_runners()
681686
{
682687
nspin0 = 2;
683688
}
684-
//! print occupation in istate.info
689+
690+
//! 2) Print occupation numbers into istate.info
685691
ModuleIO::write_istate_info(this->pelec->ekb, this->pelec->wg, this->kv, &(GlobalC::Pkpoints));
686692

687-
//! compute density of states
693+
//! 3) Compute density of states (DOS)
688694
if (PARAM.inp.out_dos)
689695
{
690696
ModuleIO::write_dos_pw(this->pelec->ekb,
@@ -707,7 +713,8 @@ void ESolver_KS_PW<T, Device>::after_all_runners()
707713
}
708714
}
709715

710-
if (PARAM.inp.out_band[0]) // pengfei 2014-10-13
716+
//! 4) Print out band structure information
717+
if (PARAM.inp.out_band[0])
711718
{
712719
for (int is = 0; is < nspin0; is++)
713720
{
@@ -725,12 +732,10 @@ void ESolver_KS_PW<T, Device>::after_all_runners()
725732
}
726733
}
727734

728-
if (PARAM.inp.basis_type == "pw" && winput::out_spillage) // xiaohui add 2013-09-01
735+
//! 5) Calculate the spillage value, used to generate numerical atomic orbitals
736+
if (PARAM.inp.basis_type == "pw" && winput::out_spillage)
729737
{
730-
// calculate spillage value.
731-
732-
// ! Print out overlap before spillage optimization to generate atomic
733-
// orbitals
738+
// ! Print out overlap matrices
734739
if (winput::out_spillage <= 2)
735740
{
736741
for (int i = 0; i < PARAM.inp.bessel_nao_rcuts.size(); i++)
@@ -747,13 +752,13 @@ void ESolver_KS_PW<T, Device>::after_all_runners()
747752
}
748753
}
749754

750-
//! Print out wave functions in real space
755+
//! 6) Print out electronic wave functions in real space
751756
if (this->wf.out_wfc_r == 1) // Peize Lin add 2021.11.21
752757
{
753758
ModuleIO::write_psi_r_1(this->psi[0], this->pw_wfc, "wfc_realspace", true, this->kv);
754759
}
755760

756-
//! Use Kubo-Greenwood method to compute conductivities
761+
//! 7) Use Kubo-Greenwood method to compute conductivities
757762
if (PARAM.inp.cal_cond)
758763
{
759764
EleCond elec_cond(&GlobalC::ucell, &this->kv, this->pelec, this->pw_wfc, this->psi, &GlobalC::ppcell);

source/module_esolver/lcao_before_scf.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(const int istep)
210210

211211
// Peize Lin add 2016-12-03
212212
#ifdef __EXX // set xc type before the first cal of xc in pelec->init_scf
213-
if (GlobalC::exx_info.info_ri.real_number)
213+
if (PARAM.inp.calculation != "nscf")
214214
{
215-
this->exd->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
216-
}
217-
else
218-
{
219-
this->exc->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
215+
if (GlobalC::exx_info.info_ri.real_number)
216+
{
217+
this->exd->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
218+
}
219+
else
220+
{
221+
this->exc->exx_beforescf(istep, this->kv, *this->p_chgmix, GlobalC::ucell, orb_);
222+
}
220223
}
221224
#endif // __EXX
222225

0 commit comments

Comments
 (0)