Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
accd6da
remove some codes in esolver_ks_lcao and add LCAO_set.cpp
mohanchen Nov 10, 2025
98240e6
add LCAO_set.h and LCAO_set.cpp
mohanchen Nov 11, 2025
f438e2e
finish updating esolver
mohanchen Nov 11, 2025
0eb5a8b
update LCAO_set, fix ref of pointer of psi
mohanchen Nov 11, 2025
653089a
update esolver
mohanchen Nov 11, 2025
d642fd4
delete useless head files
mohanchen Nov 11, 2025
a4cc365
update esolver
mohanchen Nov 11, 2025
e5cbfc7
update
mohanchen Nov 11, 2025
0472d9f
change effective to eff for short
mohanchen Nov 12, 2025
c5f52e1
add dm2rho in init_dm
mohanchen Nov 12, 2025
595d1b1
Merge branch 'deepmodeling:develop' into develop
mohanchen Nov 28, 2025
4b782c1
delete useless calculate_weights
mohanchen Nov 28, 2025
4e73529
fix a potential bug, the bcast of descf
mohanchen Nov 28, 2025
af44de1
move init_rho to KS:before_all_runners
mohanchen Nov 28, 2025
f73d73d
fix the input parametes of init_rho
mohanchen Nov 29, 2025
bbaddb3
small update of esolver_of.cpp
mohanchen Nov 29, 2025
5435fb5
Merge branch 'develop' into develop
mohanchen Nov 29, 2025
fed376d
fix tests
mohanchen Nov 29, 2025
230add5
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Nov 29, 2025
9b1613a
update eff in ML_KEDF
mohanchen Nov 29, 2025
68ed730
fix a potential bug in allocate() function in charge.cpp
mohanchen Nov 29, 2025
65bbaa9
move set_rhopw from elecstate to before charge.allocate
mohanchen Nov 30, 2025
1c576ab
fix bug about two allocations of charge class
mohanchen Nov 30, 2025
2b2580c
fix a bug in OFDFT
mohanchen Nov 30, 2025
c36a189
move the common parts in esolver_ks and esolver_of to esolver_fp
mohanchen Nov 30, 2025
0938f5a
small updates of fp and ks esolvers
mohanchen Nov 30, 2025
ab23e5e
update double xc
mohanchen Nov 30, 2025
4bd1c37
Merge branch 'deepmodeling:develop' into develop
mohanchen Dec 2, 2025
1058756
fix bug about allocation of charge density
mohanchen Dec 2, 2025
8b8e430
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into…
mohanchen Dec 2, 2025
caf0045
delete istep in init_pot and init_scf
mohanchen Dec 2, 2025
43faa3d
add an input parameter in chr.allocate
mohanchen Dec 2, 2025
d102b5e
update directory names of deepks
mohanchen Dec 2, 2025
054805a
update some small places
mohanchen Dec 2, 2025
234aa3d
add of_print_info in ofdft directory and delete the function in esolv…
mohanchen Dec 2, 2025
24cacd9
move ofdft print_info to module_ofdft
mohanchen Dec 2, 2025
06c4263
fix bugs in tests
mohanchen Dec 3, 2025
67cce25
add header
mohanchen Dec 3, 2025
f18f3d5
Merge branch 'develop' into develop
mohanchen Dec 3, 2025
6dd242d
small update of timer in ofdft
mohanchen Dec 3, 2025
74f4895
fix a bug related to timer
mohanchen Dec 3, 2025
9eadc4b
update
mohanchen Dec 3, 2025
1342c54
update
mohanchen Dec 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
stress_func_onsite.o\
stress_pw.o\
of_stress_pw.o\
of_print_info.o\
symmetry_rho.o\
symmetry_rhog.o\
setup_psi_pw.o\
Expand Down
5 changes: 3 additions & 2 deletions source/source_esolver/esolver_double_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(UnitCell& ucell, const Input_p

// 10) inititlize the charge density
this->chr_base.set_rhopw(this->pw_rhod); // mohan add 20251130
this->chr_base.allocate(PARAM.inp.nspin);
const bool kin_den = this->chr_base.kin_density(); // mohan add 20251202
this->chr_base.allocate(PARAM.inp.nspin, kin_den);
this->chr_base.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv);
this->chr_base.check_rho();

Expand Down Expand Up @@ -156,7 +157,7 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
}

XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
this->pelec_base->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
this->pelec_base->init_scf(ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);

// DMR should be same size with Hamiltonian(R)
Expand Down
3 changes: 2 additions & 1 deletion source/source_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void ESolver_FP::before_all_runners(UnitCell& ucell, const Input_para& inp)
//! 11) initialize the charge density, we need to first set xc_type,
// then we can call chr.allocate()
this->chr.set_rhopw(this->pw_rhod); // mohan add 20251130
this->chr.allocate(inp.nspin); // mohan move this from setup_estate_pw, 20251128
const bool kin_den = this->chr.kin_density(); // mohan add 20251202
this->chr.allocate(inp.nspin, kin_den); // mohan move this from setup_estate_pw, 20251128


return;
Expand Down
10 changes: 3 additions & 7 deletions source/source_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,18 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
// cell_factor
this->ppcell.cell_factor = inp.cell_factor;

//! 3) setup Exc for the first element '0' (all elements have same exc)
// XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
// GlobalV::ofs_running<<XC_Functional::output_info()<<std::endl;

//! 4) setup charge mixing
//! 3) setup charge mixing
p_chgmix = new Charge_Mixing();
p_chgmix->set_rhopw(this->pw_rho, this->pw_rhod);
p_chgmix->set_mixing(inp.mixing_mode, inp.mixing_beta, inp.mixing_ndim,
inp.mixing_gg0, inp.mixing_tau, inp.mixing_beta_mag, inp.mixing_gg0_mag,
inp.mixing_gg0_min, inp.mixing_angle, inp.mixing_dmr, ucell.omega, ucell.tpiba);
p_chgmix->init_mixing();

//! 5) setup plane wave for electronic wave functions
//! 4) setup plane wave for electronic wave functions
pw::setup_pwwfc(inp, ucell, *this->pw_rho, this->kv, this->pw_wfc);

//! 6) read in charge density, mohan add 2025-11-28
//! 5) read in charge density, mohan add 2025-11-28
//! Inititlize the charge density.
this->chr.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv, this->pw_wfc);
this->chr.check_rho(); // check the rho
Expand Down
2 changes: 1 addition & 1 deletion source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), PARAM.inp.nspin, this->pelec->charge, true);
}
// 12.2) init_scf, should be before_scf? mohan add 2025-03-10
this->pelec->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
this->pelec->init_scf(ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);

// 13) initalize DM(R), which has the same size with Hamiltonian(R)
auto* hamilt_lcao = dynamic_cast<hamilt::HamiltLCAO<TK, TR>*>(this->p_hamilt);
Expand Down
2 changes: 1 addition & 1 deletion source/source_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::runner(UnitCell& ucell, const int istep)
GlobalV::ofs_running,
GlobalV::ofs_warning);
// need to test if correct when estep>0
this->pelec->init_scf(totstep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
this->pelec->init_scf(ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);

if (totstep <= PARAM.inp.td_tend + 1)
{
Expand Down
29 changes: 14 additions & 15 deletions source/source_esolver/esolver_of.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "source_estate/cal_ux.h"
#include "source_pw/module_pwdft/forces.h"
#include "source_pw/module_ofdft/of_stress_pw.h"
// mohan add
#include "source_pw/module_ofdft/of_print_info.h"

namespace ModuleESolver
{
Expand Down Expand Up @@ -92,7 +94,7 @@ void ESolver_OF::before_all_runners(UnitCell& ucell, const Input_para& inp)
this->init_elecstate(ucell);

// calculate the total local pseudopotential in real space
this->pelec->init_scf(0, ucell, Pgrid, sf.strucFac, locpp.numeric, ucell.symm); // atomic_rho, v_of_rho, set_vrs
this->pelec->init_scf(ucell, Pgrid, sf.strucFac, locpp.numeric, ucell.symm); // atomic_rho, v_of_rho, set_vrs

// liuyu move here 2023-10-09
// D in uspp need vloc, thus behind init_scf()
Expand Down Expand Up @@ -206,20 +208,19 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)

// Refresh the arrays
delete this->psi_;
this->psi_ = new psi::Psi<double>(1,
PARAM.inp.nspin,
this->pw_rho->nrxx,
this->pw_rho->nrxx,
true);
this->psi_ = new psi::Psi<double>(1, PARAM.inp.nspin,
this->pw_rho->nrxx, this->pw_rho->nrxx, true);

for (int is = 0; is < PARAM.inp.nspin; ++is)
{
this->pphi_[is] = this->psi_->get_pointer(is);
}

delete this->ptemp_rho_;
this->ptemp_rho_ = new Charge();
this->ptemp_rho_->set_rhopw(this->pw_rho);
this->ptemp_rho_->allocate(PARAM.inp.nspin);
this->ptemp_rho_->set_rhopw(this->pw_rho);
const bool kin_den = this->ptemp_rho_->kin_density(); // mohan add 20251202
this->ptemp_rho_->allocate(PARAM.inp.nspin, kin_den);

for (int is = 0; is < PARAM.inp.nspin; ++is)
{
Expand All @@ -234,7 +235,7 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
}
}

this->pelec->init_scf(istep, ucell, Pgrid, sf.strucFac, locpp.numeric, ucell.symm);
this->pelec->init_scf(ucell, Pgrid, sf.strucFac, locpp.numeric, ucell.symm);

Symmetry_rho srho;
for (int is = 0; is < PARAM.inp.nspin; is++)
Expand Down Expand Up @@ -431,7 +432,8 @@ bool ESolver_OF::check_exit(bool& conv_esolver)
conv_esolver = (this->of_conv_ == "energy" && energyConv) || (this->of_conv_ == "potential" && potConv)
|| (this->of_conv_ == "both" && potConv && energyConv);

this->print_info(conv_esolver);
OFDFT::print_info(this->iter_, this->iter_time, this->energy_current_, this->energy_last_,
this->normdLdphi_, this->pelec, this->kedf_manager_, conv_esolver);

if (conv_esolver || this->iter_ >= this->max_iter_)
{
Expand Down Expand Up @@ -567,11 +569,8 @@ void ESolver_OF::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress)
{
ModuleBase::matrix kinetic_stress_;
kinetic_stress_.create(3, 3);
this->kedf_manager_->get_stress(ucell.omega,
this->chr.rho,
this->pphi_,
this->pw_rho,
kinetic_stress_); // kinetic stress
this->kedf_manager_->get_stress(ucell.omega, this->chr.rho,
this->pphi_, this->pw_rho, kinetic_stress_); // kinetic stress

OF_Stress_PW ss(this->pelec, this->pw_rho);
ss.cal_stress(stress, kinetic_stress_, ucell, &ucell.symm, this->locpp, &sf, &kv);
Expand Down
3 changes: 0 additions & 3 deletions source/source_esolver/esolver_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ class ESolver_OF : public ESolver_FP
void check_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell);
void test_direction(double* dEdtheta, double** ptemp_phi, UnitCell& ucell);

// --------------------- output the necessary information -----------
void print_info(const bool conv_esolver);

// --------------------- interface to blas --------------------------
double inner_product(double* pa, double* pb, int length, double dV = 1)
{
Expand Down
140 changes: 7 additions & 133 deletions source/source_esolver/esolver_of_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ void ESolver_OF::allocate_array()
delete this->ptemp_rho_;
this->ptemp_rho_ = new Charge();
this->ptemp_rho_->set_rhopw(this->pw_rho);
this->ptemp_rho_->allocate(PARAM.inp.nspin);
const bool kin_den = this->ptemp_rho_->kin_density(); // mohan add 20251202
this->ptemp_rho_->allocate(PARAM.inp.nspin, kin_den);

this->theta_ = new double[PARAM.inp.nspin];
this->pdLdphi_ = new double*[PARAM.inp.nspin];
Expand Down Expand Up @@ -378,140 +379,13 @@ void ESolver_OF::test_direction(double* dEdtheta, double** ptemp_phi, UnitCell&
Parallel_Reduce::reduce_all(pseudopot_energy);
temp_energy += kinetic_energy + pseudopot_energy;
GlobalV::ofs_warning << i << " " << dEdtheta[0] << " " << temp_energy << std::endl;
if (this->theta_[0] == 0) {
std::cout << "dEdtheta " << dEdtheta[0] << std::endl;
}
}
if (this->theta_[0] == 0)
{
std::cout << "dEdtheta " << dEdtheta[0] << std::endl;
}
}
exit(0);
}
}

/**
* @brief Print nessecary information to the screen,
* and write the components of the total energy into running_log.
*/
void ESolver_OF::print_info(const bool conv_esolver)
{
if (this->iter_ == 0)
{
std::cout << " ============================= Running OFDFT "
"=============================="
<< std::endl;
std::cout << " ITER ETOT/eV EDIFF/eV EFERMI/eV POTNORM TIME/s"
<< std::endl;
}

std::map<std::string, std::string> prefix_map = {
{"cg1", "CG"},
{"cg2", "CG"},
{"tn", "TN"}
};
std::string iteration = prefix_map[PARAM.inp.of_method] + std::to_string(this->iter_);
#ifdef __MPI
double duration = (double)(MPI_Wtime() - this->iter_time);
#else
double duration
= (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - this->iter_time)).count()
/ static_cast<double>(1e6);
#endif
std::cout << " " << std::setw(8) << iteration
<< std::setw(18) << std::scientific << std::setprecision(8) << this->energy_current_ * ModuleBase::Ry_to_eV
<< std::setw(18) << (this->energy_current_ - this->energy_last_) * ModuleBase::Ry_to_eV
<< std::setw(13) << std::setprecision(4) << this->pelec->eferm.get_efval(0) * ModuleBase::Ry_to_eV
<< std::setw(13) << std::setprecision(4) << this->normdLdphi_
<< std::setw(6) << std::fixed << std::setprecision(2) << duration << std::endl;

GlobalV::ofs_running << std::setprecision(12);
GlobalV::ofs_running << std::setiosflags(std::ios::right);

GlobalV::ofs_running << "\nIter" << this->iter_ << ": the norm of potential is " << this->normdLdphi_ << std::endl;

std::vector<std::string> titles;
std::vector<double> energies_Ry;
std::vector<double> energies_eV;
if ((PARAM.inp.out_band[0] > 0 &&
((this->iter_ + 1) % PARAM.inp.out_band[0] == 0 ||
conv_esolver ||
this->iter_ == PARAM.inp.scf_nmax)) ||
PARAM.inp.init_chg == "file")
{
titles.push_back("E_Total");
energies_Ry.push_back(this->pelec->f_en.etot);
titles.push_back("E_Kinetic");
energies_Ry.push_back(this->pelec->f_en.ekinetic);
titles.push_back("E_Hartree");
energies_Ry.push_back(this->pelec->f_en.hartree_energy);
titles.push_back("E_xc");
energies_Ry.push_back(this->pelec->f_en.etxc - this->pelec->f_en.etxcc);
titles.push_back("E_LocalPP");
energies_Ry.push_back(this->pelec->f_en.e_local_pp);
titles.push_back("E_Ewald");
energies_Ry.push_back(this->pelec->f_en.ewald_energy);

this->kedf_manager_->record_energy(titles, energies_Ry);

std::string vdw_method = PARAM.inp.vdw_method;
if (vdw_method == "d2") // Peize Lin add 2014-04, update 2021-03-09
{
titles.push_back("E_vdwD2");
energies_Ry.push_back(this->pelec->f_en.evdw);
}
else if (vdw_method == "d3_0" || vdw_method == "d3_bj") // jiyy add 2019-05, update 2021-05-02
{
titles.push_back("E_vdwD3");
energies_Ry.push_back(this->pelec->f_en.evdw);
}
if (PARAM.inp.imp_sol)
{
titles.push_back("E_sol_el");
energies_Ry.push_back(this->pelec->f_en.esol_el);
titles.push_back("E_sol_cav");
energies_Ry.push_back(this->pelec->f_en.esol_cav);
}
if (PARAM.inp.efield_flag)
{
titles.push_back("E_efield");
energies_Ry.push_back(elecstate::Efield::etotefield);
}
if (PARAM.inp.gate_flag)
{
titles.push_back("E_gatefield");
energies_Ry.push_back(elecstate::Gatefield::etotgatefield);
}
}
else
{
titles.push_back("E_Total");
energies_Ry.push_back(this->pelec->f_en.etot);
}

if (PARAM.globalv.two_fermi)
{
titles.push_back("E_Fermi_up");
energies_Ry.push_back(this->pelec->eferm.get_efval(0));
titles.push_back("E_Fermi_dw");
energies_Ry.push_back(this->pelec->eferm.get_efval(1));
}
else
{
titles.push_back("E_Fermi");
energies_Ry.push_back(this->pelec->eferm.get_efval(0));
}
energies_eV.resize(energies_Ry.size());
std::transform(energies_Ry.begin(), energies_Ry.end(), energies_eV.begin(), [](double energy) {
return energy * ModuleBase::Ry_to_eV;
});
FmtTable table(/*titles=*/{"Energy", "Rydberg", "eV"},
/*nrows=*/titles.size(),
/*formats=*/{"%20s", "%20.12f", "%20.12f"}, 0);
table << titles << energies_Ry << energies_eV;
GlobalV::ofs_running << table.str() << std::endl;

// reset the iter_time for the next iteration
#ifdef __MPI
this->iter_time = MPI_Wtime();
#else
this->iter_time = std::chrono::system_clock::now();
#endif
}
} // namespace ModuleESolver
2 changes: 1 addition & 1 deletion source/source_esolver/lcao_others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
elecstate::cal_ux(ucell);

// pelec should be initialized before these calculations
this->pelec->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
this->pelec->init_scf(ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);

// self consistent calculations for electronic ground state
if (cal_type == "get_pchg")
Expand Down
16 changes: 2 additions & 14 deletions source/source_estate/elecstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void ElecState::init_nelec_spin()
}
}

void ElecState::init_scf(const int istep,
const UnitCell& ucell,
void ElecState::init_scf(const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucfac,
const bool* numeric,
Expand All @@ -38,21 +37,11 @@ void ElecState::init_scf(const int istep,
//! core correction potential.
this->charge->set_rho_core(ucell,strucfac, numeric);

//! other effective potentials need charge density,
// choose charge density from ionic step 0.
/*
if (istep == 0)
{
this->charge->init_rho(this->eferm,ucell, pgrid, strucfac, symm, (const void*)this->klist, wfcpw);
this->charge->check_rho(); // check the rho
}
*/

//! renormalize the charge density
this->charge->renormalize_rho();

//! initialize the potential
this->pot->init_pot(istep, this->charge);
this->pot->init_pot(this->charge);
}


Expand All @@ -63,7 +52,6 @@ void ElecState::init_ks(Charge* chr_in, // pointer for class Charge
{
this->charge = chr_in;
this->klist = klist_in;
// this->charge->set_rhopw(rhopw_in); // mohan comment out 20251130
this->bigpw = bigpw_in;
// init nelec_spin with nelec and nupdown
this->init_nelec_spin();
Expand Down
4 changes: 1 addition & 3 deletions source/source_estate/elecstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ class ElecState
/**
* @brief Init rho_core, init rho, renormalize rho, init pot
*
* @param istep i-th step
* @param ucell unit cell
* @param strucfac structure factor
* @param symm symmetry
* @param wfcpw PW basis for wave function if needed
*/
void init_scf(const int istep,
const UnitCell& ucell,
void init_scf(const UnitCell& ucell,
const Parallel_Grid& pgrid,
const ModuleBase::ComplexMatrix& strucfac,
const bool* numeric,
Expand Down
Loading
Loading