Skip to content

Commit 3da335b

Browse files
authored
Merge branch 'develop' into blas-lapack
2 parents a548e7b + 2543590 commit 3da335b

Some content is hidden

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

46 files changed

+371
-304
lines changed

.github/workflows/version_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
fi
3434
3535
# Verify that the version in version.h matches the tag
36-
if [[ "${{ steps.versions.outputs.current_tag }}" != "v${CODE_VERSION}" ]]; then
36+
if [[ "${{ steps.versions.outputs.current_tag }}" != "${CODE_VERSION}" ]]; then
3737
echo "::error::Version mismatch: tag=${{ steps.versions.outputs.current_tag }} ≠ code=${CODE_VERSION}"
3838
exit 1
3939
fi

cmake/FindMKL.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,12 @@ endif()
9191
if(NOT TARGET MKL::MKL_SCALAPACK)
9292
find_library(MKL_SCALAPACK NAMES mkl_scalapack_lp64 HINTS ${MKLROOT}/lib ${MKLROOT}/lib/intel64)
9393
message(STATUS "Found MKL_SCALAPACK: ${MKL_SCALAPACK}")
94-
add_library(MKL::MKL_SCALAPACK OBJECT IMPORTED MKL_SCALAPACK)
94+
if(MKL_SCALAPACK)
95+
# create an IMPORTED target that points to the discovered library file
96+
add_library(MKL::MKL_SCALAPACK UNKNOWN IMPORTED)
97+
set_target_properties(MKL::MKL_SCALAPACK PROPERTIES
98+
IMPORTED_LOCATION "${MKL_SCALAPACK}"
99+
INTERFACE_INCLUDE_DIRECTORIES "${MKL_INCLUDE}"
100+
)
101+
endif()
95102
endif()

source/Makefile.Objects

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ OBJS_ELECSTAT=elecstate.o\
228228
elecstate_energy.o\
229229
elecstate_exx.o\
230230
elecstate_print.o\
231+
elecstate_tools.o\
231232
elecstate_pw.o\
232233
elecstate_pw_sdft.o\
233234
elecstate_pw_cal_tau.o\
234235
elecstate_op.o\
235-
elecstate_tools.o\
236236
efield.o\
237237
gatefield.o\
238238
potential_new.o\
@@ -252,8 +252,7 @@ OBJS_ELECSTAT=elecstate.o\
252252
update_pot.o\
253253

254254
OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
255-
elecstate_lcao_cal_tau.o\
256-
setup_dm.o\
255+
init_dm.o\
257256
density_matrix.o\
258257
density_matrix_io.o\
259258
cal_dm_psi.o\
@@ -643,6 +642,7 @@ OBJS_LCAO=evolve_elec.o\
643642
LCAO_init_basis.o\
644643
setup_exx.o\
645644
setup_deepks.o\
645+
rho_tau_lcao.o\
646646
center2_orb.o\
647647
center2_orb-orb11.o\
648648
center2_orb-orb21.o\

source/source_esolver/esolver_dm2rho.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "source_io/cube_io.h"
1111
#include "source_io/io_npz.h"
1212
#include "source_io/print_info.h"
13+
#include "source_lcao/rho_tau_lcao.h" // mohan add 2025-10-24
1314

1415
namespace ModuleESolver
1516
{
@@ -45,9 +46,16 @@ void ESolver_DM2rho<TK, TR>::runner(UnitCell& ucell, const int istep)
4546

4647
ESolver_KS_LCAO<TK, TR>::before_scf(ucell, istep);
4748

49+
auto* estate = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
50+
51+
if(!estate)
52+
{
53+
ModuleBase::WARNING_QUIT("ESolver_DM2rho::after_scf","pelec does not exist");
54+
}
55+
4856
// file name of DM
4957
std::string zipname = "output_DM0.npz";
50-
elecstate::DensityMatrix<TK, double>* dm = dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
58+
elecstate::DensityMatrix<TK, double>* dm = estate->get_DM();
5159

5260
// read DM from file
5361
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(dm->get_DMR_pointer(1)));
@@ -59,7 +67,9 @@ void ESolver_DM2rho<TK, TR>::runner(UnitCell& ucell, const int istep)
5967
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(dm->get_DMR_pointer(2)));
6068
}
6169

62-
this->pelec->psiToRho(*this->psi);
70+
// it's dangerous to design psiToRho function like this, mohan note 20251024
71+
// this->pelec->psiToRho(*this->psi);
72+
LCAO_domain::dm2rho(estate->DM->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
6373

6474
int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1;
6575

source/source_esolver/esolver_double_xc.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(UnitCell& ucell, const Input_p
8888

8989
// 10) inititlize the charge density
9090
this->chr_base.allocate(PARAM.inp.nspin);
91-
this->pelec_base->omega = ucell.omega;
9291

9392
// 11) initialize the potential
9493
if (this->pelec_base->pot == nullptr)
@@ -114,7 +113,6 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
114113

115114
ESolver_KS_LCAO<TK,TR>::before_scf(ucell, istep);
116115

117-
this->pelec_base->omega = ucell.omega;
118116
//----------------------------------------------------------
119117
//! calculate D2 or D3 vdW
120118
//----------------------------------------------------------
@@ -151,16 +149,10 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
151149
this->two_center_bundle_,
152150
this->orb_,
153151
DM,
154-
this->deepks
155-
#ifdef __EXX
156-
,
157-
istep,
158-
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
159-
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
160-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
161-
#endif
162-
);
163-
}
152+
this->deepks,
153+
istep,
154+
this->exx_nao);
155+
}
164156

165157
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
166158
this->pelec_base->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);

source/source_esolver/esolver_fp.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
108108
this->locpp.init_vloc(ucell, this->pw_rhod);
109109
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
110110

111-
this->pelec->omega = ucell.omega;
112-
113111
// perform symmetry analysis
114112
if (ModuleSymmetry::Symmetry::symm_flag == 1)
115113
{

source/source_esolver/esolver_ks.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,14 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
347347
{
348348
ModuleBase::TITLE("ESolver_KS", "after_scf");
349349

350+
/*
350351
// 1) calculate the kinetic energy density tau
351352
if (PARAM.inp.out_elf[0] > 0)
352353
{
353354
assert(this->psi != nullptr);
354355
this->pelec->cal_tau(*(this->psi));
355356
}
357+
*/
356358

357359
// 2) call after_scf() of ESolver_FP
358360
ESolver_FP::after_scf(ucell, istep, conv_esolver);

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#include "esolver_ks_lcao.h"
22
#include "source_estate/elecstate_tools.h"
33
#include "source_lcao/module_deltaspin/spin_constrain.h"
4-
#include "source_io/read_wfc_nao.h"
54
#include "source_lcao/hs_matrix_k.hpp" // there may be multiple definitions if using hpp
6-
#include "source_estate/cal_ux.h"
75
#include "source_estate/module_charge/symmetry_rho.h"
86
#include "source_lcao/LCAO_domain.h" // need DeePKS_init
97
#include "source_lcao/module_dftu/dftu.h"
@@ -16,13 +14,14 @@
1614
#endif
1715
#include "source_lcao/module_rdmft/rdmft.h"
1816
#include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
19-
#include "source_estate/module_dm/setup_dm.h" // setup dm from electronic wave functions
17+
#include "source_estate/module_dm/init_dm.h" // init dm from electronic wave functions
2018
#include "source_io/ctrl_runner_lcao.h" // use ctrl_runner_lcao()
2119
#include "source_io/ctrl_iter_lcao.h" // use ctrl_iter_lcao()
2220
#include "source_io/ctrl_scf_lcao.h" // use ctrl_scf_lcao()
2321
#include "source_psi/setup_psi.h" // mohan add 20251019
2422
#include "source_io/read_wfc_nao.h"
2523
#include "source_io/print_info.h"
24+
#include "source_lcao/rho_tau_lcao.h" // mohan add 20251024
2625

2726
namespace ModuleESolver
2827
{
@@ -110,7 +109,6 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
110109

111110
// 11) init charge density
112111
this->chr.allocate(inp.nspin);
113-
this->pelec->omega = ucell.omega;
114112

115113
// 12) init potentials
116114
if (this->pelec->pot == nullptr)
@@ -199,15 +197,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
199197

200198
this->p_hamilt = new hamilt::HamiltLCAO<TK, TR>(
201199
ucell, this->gd, &this->pv, this->pelec->pot, this->kv,
202-
two_center_bundle_, orb_, DM, this->deepks
203-
#ifdef __EXX
204-
,
205-
istep,
206-
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->two_level_step : &this->exx_nao.exc->two_level_step,
207-
GlobalC::exx_info.info_ri.real_number ? &this->exx_nao.exd->get_Hexxs() : nullptr,
208-
GlobalC::exx_info.info_ri.real_number ? nullptr : &this->exx_nao.exc->get_Hexxs()
209-
#endif
210-
);
200+
two_center_bundle_, orb_, DM, this->deepks, istep, exx_nao);
211201
}
212202

213203
// 9) for each ionic step, the overlap <phi|alpha> must be rebuilt
@@ -224,19 +214,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
224214
}
225215

226216
// 11) set xc type before the first cal of xc in pelec->init_scf, Peize Lin add 2016-12-03
227-
#ifdef __EXX
228-
if (PARAM.inp.calculation != "nscf")
229-
{
230-
if (GlobalC::exx_info.info_ri.real_number)
231-
{
232-
this->exx_nao.exd->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
233-
}
234-
else
235-
{
236-
this->exx_nao.exc->exx_beforescf(istep, this->kv, *this->p_chgmix, ucell, orb_);
237-
}
238-
}
239-
#endif
217+
this->exx_nao.before_scf(ucell, this->kv, orb_, this->p_chgmix, istep, PARAM.inp);
240218

241219
// 12) init_scf, should be before_scf? mohan add 2025-03-10
242220
this->pelec->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
@@ -318,10 +296,6 @@ void ESolver_KS_LCAO<TK, TR>::cal_force(UnitCell& ucell, ModuleBase::matrix& for
318296
ModuleBase::timer::tick("ESolver_KS_LCAO", "cal_force");
319297
}
320298

321-
//------------------------------------------------------------------------------
322-
//! the 7th function of ESolver_KS_LCAO: cal_stress
323-
//! mohan add 2024-05-11
324-
//------------------------------------------------------------------------------
325299
template <typename TK, typename TR>
326300
void ESolver_KS_LCAO<TK, TR>::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
327301
{
@@ -406,10 +380,11 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
406380
{
407381
// the following steps are only needed in the first outer exx loop
408382
exx_two_level_step
409-
= GlobalC::exx_info.info_ri.real_number ? this->exx_nao.exd->two_level_step : this->exx_nao.exc->two_level_step;
383+
= GlobalC::exx_info.info_ri.real_number ?
384+
this->exx_nao.exd->two_level_step : this->exx_nao.exc->two_level_step;
410385
}
411386
#endif
412-
elecstate::setup_dm<TK>(ucell, estate, this->psi, this->chr, iter, exx_two_level_step);
387+
elecstate::init_dm<TK>(ucell, estate, this->psi, this->chr, iter, exx_two_level_step);
413388
}
414389

415390
#ifdef __EXX
@@ -495,7 +470,7 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
495470
if (!skip_solve)
496471
{
497472
hsolver::HSolverLCAO<TK> hsolver_lcao_obj(&(this->pv), PARAM.inp.ks_solver);
498-
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, skip_charge);
473+
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, this->chr, PARAM.inp.nspin, skip_charge);
499474
}
500475

501476
// 4) EXX
@@ -563,15 +538,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
563538
}
564539

565540
// 2) for deepks, calculate delta_e, output labels during electronic steps
566-
#ifdef __MLALGO
567-
if (PARAM.inp.deepks_scf)
568-
{
569-
this->deepks.ld.dpks_cal_e_delta_band(dm_vec, this->kv.get_nks());
570-
DeePKS_domain::update_dmr(this->kv.kvec_d, dm_vec, ucell, orb_, this->pv, this->gd, this->deepks.ld.dm_r);
571-
estate->f_en.edeepks_scf = this->deepks.ld.E_delta - this->deepks.ld.e_delta_band;
572-
estate->f_en.edeepks_delta = this->deepks.ld.E_delta;
573-
}
574-
#endif
541+
this->deepks.delta_e(ucell, this->kv, this->orb_, this->pv, this->gd, dm_vec, this->pelec->f_en, PARAM.inp);
575542

576543
// 3) for delta spin
577544
if (PARAM.inp.sc_mag_switch)
@@ -617,9 +584,6 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
617584
ModuleBase::TITLE("ESolver_KS_LCAO", "after_scf");
618585
ModuleBase::timer::tick("ESolver_KS_LCAO", "after_scf");
619586

620-
//! 1) call after_scf() of ESolver_KS
621-
ESolver_KS<TK>::after_scf(ucell, istep, conv_esolver);
622-
623587
auto* estate = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec);
624588
auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
625589

@@ -633,6 +597,15 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
633597
ModuleBase::WARNING_QUIT("ESolver_KS_LCAO::after_scf","p_hamilt does not exist");
634598
}
635599

600+
if (PARAM.inp.out_elf[0] > 0)
601+
{
602+
LCAO_domain::dm2tau(estate->DM->get_DMR_vector(), PARAM.inp.nspin, estate->charge);
603+
}
604+
605+
//! 1) call after_scf() of ESolver_KS
606+
ESolver_KS<TK>::after_scf(ucell, istep, conv_esolver);
607+
608+
636609
//! 2) output of lcao every few ionic steps
637610
ModuleIO::ctrl_scf_lcao<TK, TR>(ucell,
638611
PARAM.inp, this->kv, estate, this->pv,
@@ -654,7 +627,6 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
654627
ModuleBase::timer::tick("ESolver_KS_LCAO", "after_scf");
655628
}
656629

657-
658630
template class ESolver_KS_LCAO<double, double>;
659631
template class ESolver_KS_LCAO<std::complex<double>, double>;
660632
template class ESolver_KS_LCAO<std::complex<double>, std::complex<double>>;

source/source_esolver/esolver_ks_lcao_tddft.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@
3131
#include "source_lcao/hamilt_lcao.h"
3232
#include "source_psi/psi.h"
3333

34-
//-----force& stress-------------------
3534
#include "source_lcao/FORCE_STRESS.h"
35+
#include "source_lcao/rho_tau_lcao.h" // mohan add 2025-10-24
3636

37-
//---------------------------------------------------
3837

3938
namespace ModuleESolver
4039
{
@@ -293,7 +292,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::hamilt2rho_single(UnitCell& ucell,
293292
{
294293
bool skip_charge = PARAM.inp.calculation == "nscf" ? true : false;
295294
hsolver::HSolverLCAO<std::complex<double>> hsolver_lcao_obj(&this->pv, PARAM.inp.ks_solver);
296-
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, skip_charge);
295+
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, this->chr, PARAM.inp.nspin, skip_charge);
297296
}
298297
}
299298

@@ -574,8 +573,8 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::weight_dm_rho(const UnitCell& ucell)
574573
_pes->DM->cal_DMR();
575574
}
576575

577-
// get the real-space charge density
578-
this->pelec->psiToRho(this->psi[0]);
576+
// get the real-space charge density, mohan add 2025-10-24
577+
LCAO_domain::dm2rho(_pes->DM->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
579578
}
580579

581580
template class ESolver_KS_LCAO_TDDFT<double, base_device::DEVICE_CPU>;

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
359359
if (PARAM.inp.out_elf[0] > 0)
360360
{
361361
this->ESolver_KS<T, Device>::psi = new psi::Psi<T>(this->stp.psi_cpu[0]);
362+
this->pelec->cal_tau(*(this->psi));
362363
}
363364

364365
// Call 'after_scf' of ESolver_KS

0 commit comments

Comments
 (0)