Skip to content
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
83eb5d0
module_charge: normalize indentation and brace single-statement contr…
Sep 16, 2026
aa9e515
module_charge: aggregate Charge_Mixing params into MixingConfig
Sep 16, 2026
589e65f
module_charge: deduplicate twobeta_mix lambdas and replace raw new wi…
Sep 16, 2026
8246456
module_charge: move residual/inner-product globals into MixingConfig
Sep 16, 2026
ecf5084
module_charge: own Charge's _space_* storage with std::vector (Step 5a)
Sep 16, 2026
25bd441
module_charge: route chgmixing_ks through its inp parameter
Sep 16, 2026
1e9411c
module_charge: split Charge::init_rho into per-stage private methods
Sep 16, 2026
c4a8ed2
module_charge: extract Charge density math into charge_math free func…
Sep 16, 2026
e074dd0
module_charge: register charge_math.o in the hand-written Makefile build
Sep 16, 2026
aab8b0e
Merge branch 'develop' into 20260916
mohanchen Sep 16, 2026
7b346dc
module_charge: extract Charge::atomic_rho into charge_atomic free fun…
Sep 16, 2026
0c7109d
module_charge: forbid Charge copies and guard tau.cube write
Sep 16, 2026
871f8f2
module_base: tolerate null grid buffer when a rank owns no grid points
Sep 16, 2026
1d3beac
module_charge: extract Charge::set_rho_core into charge_math free fun…
Sep 16, 2026
49b0a65
module_charge: vectorize Charge_Extra history arrays and forbid copies
Sep 16, 2026
e0480f3
Rename charge_math to chg_tools and unify namespace module_charge
Sep 17, 2026
5154f98
module_charge: refactor Symmetry_rho class to free functions
Sep 17, 2026
dfbf99d
module_charge: extract MixingConfig header and drop unused inner_prod…
Sep 17, 2026
619029d
module_gint: move gint_prec_ctrl from module_charge
Sep 17, 2026
2ac0017
module_charge: extract mixing inner products into chg_drho free funct…
Sep 17, 2026
61c2529
module_charge: hide cal_drho/cal_dkin in an anonymous namespace
Sep 17, 2026
dfe1dac
module_gint: fix include path in test_gint_prec_ctrl after relocation
Sep 17, 2026
6d127d5
module_charge: extract Kerker screen kernels into chg_precond free fu…
Sep 17, 2026
e4e6fc9
module_charge: fix Makefile.Objects after mix_precond -> chg_precond …
Sep 17, 2026
9a96847
module_charge: drop Charge_Mixing::get_drho/get_dkin wrappers
Sep 17, 2026
c89aba3
module_charge: rename chgmixing.h/cpp to chg_routine.h/cpp
Sep 17, 2026
ae65748
module_charge: rename mixing_config.h to chg_mix_cfg.h
Sep 17, 2026
c531ea4
module_charge: convert Charge MPI helpers into chg_parallel free func…
Sep 17, 2026
b976259
Rename charge_atomic files to chg_atomic
Sep 17, 2026
2f49955
module_charge: extract USPP double-grid split/merge into chg_uspp fre…
Sep 17, 2026
4650306
module_charge: rewrite MixDivCombTest for the new split_dgrid/merge_d…
Sep 17, 2026
2670f86
module_charge: drop legacy divide_data/combine_data/clean_data members
Sep 17, 2026
e4f111f
module_charge: rename charge_extra files to chg_extra and move class …
Sep 18, 2026
570dd49
module_charge: extract DMR mixing into chg_dmr free functions
Sep 18, 2026
86b4f54
module_charge: remove Charge_Mixing DMR wrappers, call chg_dmr directly
Sep 18, 2026
6d174ff
module_charge: decouple chg_dmr kernel from HContainer, mix raw buffers
Sep 18, 2026
d9685d4
module_charge: refactor charge_mixing_rho free functions and cleanup
Sep 18, 2026
36da8fd
module_charge: split member functions into charge_mixing.cpp, free fu…
Sep 18, 2026
426c572
module_charge: rename charge_{init,mixing_rho} to chg_{init,tau}, wid…
Sep 18, 2026
1663581
module_charge: rename charge_mixing.{h,cpp} to chg_mix.{h,cpp}, test …
Sep 18, 2026
3540a2b
module_charge: remove duplicate doc block comments (Phase 1a)
Sep 18, 2026
da75e2e
module_charge: replace auto with explicit std::function types (Phase 1b)
Sep 18, 2026
9038abd
module_charge: wrap lines over 120 chars (Phase 1c)
Sep 18, 2026
a770ca7
module_charge: remove default parameter from Charge::init_rho (Phase 1d)
Sep 18, 2026
0dc34cf
module_charge: replace raw new/delete with std::vector and unique_ptr…
Sep 18, 2026
962b0b3
module_charge: replace raw new/delete in Charge with vector-backed st…
Sep 18, 2026
03e3e5e
module_charge: replace std::make_unique with C++11-compatible unique_…
Sep 18, 2026
fd38f2c
module_charge: fix duplicate doc block in charge.cpp init_final_scf
Sep 18, 2026
73eee04
module_charge: aggregate chgmixing_ks parameters into ScfMixingCtx st…
Sep 18, 2026
b8cb59d
module_charge: aggregate read_rho_file/read_kin_file parameters into …
Sep 18, 2026
b96b143
module_charge: aggregate non_linear_core_correction parameters into N…
Sep 18, 2026
48866d9
module_charge: split chg_mix.cpp into init and rho mixing files (Phas…
Sep 18, 2026
23f12da
module_charge: split chg_drho.cpp and decompose inner product functio…
Sep 18, 2026
872f6d1
refactor(module_charge): split atomic_rho and remove ZEROS in charge …
Sep 18, 2026
2411e80
Refactor: remove redundant Charge& overload of cal_rhog_symm_soc
Sep 18, 2026
0b8dfbe
module_charge: fix stale TITLE/timer labels and drop unused xc_functi…
Sep 18, 2026
7a00138
module_charge: remove redundant #ifdef __MPI guards around parallel w…
Sep 18, 2026
a669eea
module_charge: decouple chg_routine from spin_constrain singleton
Sep 18, 2026
c9ba84b
module_charge: remove PARAM dependencies via explicit configuration s…
Sep 18, 2026
2d3592a
Merge branch 'develop' into 20260916
mohanchen Sep 18, 2026
4dcbd1c
module_charge: restore #ifdef __MPI guards around parallel wrapper calls
Sep 18, 2026
65252c4
Remove dead PAW compensation charge members
Sep 18, 2026
6a67c09
Refactor: remove unused Charge::prenspin member
Sep 18, 2026
f489a13
Refactor: move Charge::cal_rho2ne/check_rho to module_charge free fun…
Sep 18, 2026
34b441e
Refactor: remove redundant Charge::omega_ pointer
Sep 18, 2026
07ebcc1
Remove dead Charge::init_final_scf and allocate_rho_final_scf
Sep 18, 2026
1e492e5
Refactor: pass rhopw explicitly to chg_init/chg_routine/chg_extra/chg…
Sep 18, 2026
58c7fe4
Comments: add TODOs for LCAO+USPP double-grid follow-ups
Sep 18, 2026
a1fc87f
Refactor: replace sticky Charge::cal_elf flag with explicit symm_kin …
Sep 19, 2026
87b818f
Refactor: resolve mixing_tau at config assembly, drop XC dependency f…
Sep 19, 2026
ee70805
Fix: restore complete types in chg_drho_inner.cpp after include removal
Sep 19, 2026
dbf9d50
Refactor: derive tau symmetrization/reduction from kin_r buffer exist…
Sep 19, 2026
ecf8418
Refactor: remove module_xc dependency from module_charge (meta_gga st…
Sep 19, 2026
25f51c5
Fix: allow null rho buffers on ranks with empty real-space grid parti…
Sep 19, 2026
1528e79
Refactor: move rhog_io into module_charge as chg_rhog_io
Sep 19, 2026
15f7026
Refactor: create module_charge/test with the rhog io unit test
Sep 19, 2026
3b66374
Refactor: move charge and charge-extra unit tests into module_charge/…
Sep 19, 2026
eeb2740
Refactor: move mix, parallel and tools unit tests into module_charge/…
Sep 19, 2026
ff766ac
Refactor: rename module_charge test dir to unittests and wire CI for it
Sep 19, 2026
ce50549
Fix: pass ucell.omega to Charge::sum_rho/renormalize_rho to fix NPT s…
Sep 19, 2026
140be65
Fix: add omega arg to remaining dm2rho call sites
Sep 19, 2026
46a9665
Fix: restore HamiltHSMatrix hs declaration in cal_mw_from_lambda
Sep 19, 2026
cc3a0af
Merge branch 'develop' into 20260916
mohanchen Sep 19, 2026
0088c1d
Merge branch 'develop' into 20260916
Critsium-xy Sep 20, 2026
431f9a3
Fix: close_kerker_gg0 actually disables Kerker; drop dead mixing_gg0 …
Sep 20, 2026
03b47a7
Fix: relax over-strict null-buffer asserts for empty grid partitions
Sep 20, 2026
01000c6
Fix: relax over-strict null-buffer assert in ParaRgridWorld::reduce_a…
Sep 20, 2026
7ba427c
Fix: allow nnr == 0 in DMR mixing for empty MPI partitions
Sep 20, 2026
4e3966e
Fix: split reciprocal rho copy from real-space |m| rescale in mix_rho…
Sep 20, 2026
22391b3
Refactor: remove unused Charge_Mixing::conserve_setting
Sep 20, 2026
4424915
Refactor: drop dead Charge_Mixing::tpiba2 member
Sep 20, 2026
b01a330
Refactor: route Charge_Mixing getters through cfg_
Sep 20, 2026
f2e4685
Refactor: init_mixing constructs Mixing from cfg_ not legacy mirrors
Sep 20, 2026
ce98bd5
Refactor: mix_rho_recip/mix_rho_real read mixing_beta from cfg_
Sep 20, 2026
60a7586
Refactor: set_mixing stops mirroring cfg_ into legacy members
Sep 20, 2026
6c0c079
Refactor: drop legacy Charge_Mixing mirror members; cfg_ is single so…
Sep 20, 2026
52593de
Refactor: drop NSDMI from MixingConfig to force explicit construction
Sep 20, 2026
c14afdd
Refactor: aggregate-init MixingConfig in esolver_ks with pragma guard
Sep 20, 2026
ca5a30f
Refactor: aggregate-init MixingConfig in test_chg_mix with pragma guard
Sep 20, 2026
dd2d478
Merge branch '20260916' of github.com:mohanchen/abacus-mc into 20260916
Sep 20, 2026
dfaefdf
Fix: fail-fast guards in Charge_Mixing and update chg_mix tests
Sep 20, 2026
8cbc558
test(module_charge): add unit tests for chg_uspp and chg_dmr
Sep 20, 2026
68e820f
test(module_charge): add unit tests for chg_precond, chg_drho, chg_dr…
Sep 20, 2026
f10bd03
test(module_charge): add unit tests for chg_symm, chg_symm_detail, ch…
Sep 20, 2026
35bf4fe
test(module_charge): add chg_tau/chg_routine/chg_init tests; drop spu…
Sep 20, 2026
5b9f83a
test(module_charge): fix broken includes in unit tests
Sep 20, 2026
a04584f
test(module_charge): fix link/build issues; temporarily disable routi…
Sep 20, 2026
b2fca4e
fix bug
Sep 20, 2026
6e8708e
format tool_quit
Sep 21, 2026
2530392
remove a test due to WARNING_QUIT funcitno
Sep 21, 2026
ce9271d
delete the support file charge-density.dat because unittests never ne…
Sep 21, 2026
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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/test/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info
lcov --remove coverage.info '/usr/*' '*/test/*' '*/unittests/*' '*/external/*' '*/build/*' --output-file coverage.filtered.info
genhtml coverage.filtered.info --output-directory coverage-report
Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ jobs:
run: |
ctest --test-dir build -V --timeout 1700 -R MODULE_ESTATE

- name: Module_Charge Unittests
env:
GTEST_COLOR: 'yes'
OMP_NUM_THREADS: '2'
run: |
ctest --test-dir build -V --timeout 1700 -R MODULE_CHARGE

- name: Module_Hamilt Unittests
env:
GTEST_COLOR: 'yes'
Expand Down Expand Up @@ -343,4 +350,4 @@ jobs:
GTEST_COLOR: 'yes'
OMP_NUM_THREADS: '2'
run: |
ctest --test-dir build -V --timeout 1700 -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|17_DS_DFTU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|MODULE_PSI|MODULE_ESTATE|MODULE_RI|MODULE_HAMILT|MODULE_PW|MODULE_LCAO|MODULE_AO|MODULE_NAO|MODULE_RELAX|MODULE_LR'
ctest --test-dir build -V --timeout 1700 -E 'integrate_test|01_PW|02_NAO_Gamma|03_NAO_multik|04_FF|05_rtTDDFT|06_SDFT|07_OFDFT|08_EXX|09_DeePKS|10_others|11_PW_GPU|12_NAO_Gamma_GPU|13_NAO_multik_GPU|15_rtTDDFT_GPU|16_SDFT_GPU|17_DS_DFTU|MODULE_BASE|MODULE_IO|MODULE_HSOLVER|MODULE_CELL|MODULE_MD|MODULE_PSI|MODULE_ESTATE|MODULE_CHARGE|MODULE_RI|MODULE_HAMILT|MODULE_PW|MODULE_LCAO|MODULE_AO|MODULE_NAO|MODULE_RELAX|MODULE_LR'
8 changes: 0 additions & 8 deletions source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,6 @@ ${OBJ_DIR}/parse_args.o: $(ABACUS_ROOT)source_io/parse_args.cpp $(BUILD_INFO_DIR
@mkdir -p $(dir $@)
${CXX} ${OPTS} ${OPTS_MPI} -c ${HONG} $< -o $@

# Explicit rule: source_cell/module_symmetry and source_estate/module_charge
# both contain a symm_rho.cpp. VPATH resolves symm_rho.o to the source_cell
# one (listed first), so the Symmetry_rho implementation needs an explicit
# object name to be compiled from the correct source.
${OBJ_DIR}/symm_rho_charge.o: $(ABACUS_ROOT)source_estate/module_charge/symm_rho.cpp
@mkdir -p $(dir $@)
${CXX} ${OPTS} ${OPTS_MPI} -c ${HONG} $< -o $@

###### END of ABACUS INFO PART ######

#==========================
Expand Down
33 changes: 19 additions & 14 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ OBJS_GINT=batch_biggrid.o\
gint_fvl.o\
gint_info.o\
gint_interface.o\
gint_prec_ctrl.o\
gint_rho.o\
gint_drho.o\
gint_tau.o\
Expand Down Expand Up @@ -825,19 +826,25 @@ OBJS_SRCPW=h_ewald_pw.o\
vnl_pw_grad.o\
vnl_pw_init_vnl.o\
vnl_pw_qrad.o\
chgmixing.o\
gint_prec_ctrl.o\
chg_routine.o\
charge.o\
charge_init.o\
charge_mpi.o\
charge_extra.o\
charge_mixing.o\
charge_mixing_dmr.o\
mix_resid.o\
mix_precond.o\
charge_mixing_rho.o\
charge_mixing_uspp.o\
rhog_io.o\
chg_atomic.o\
chg_atomic_inner.o\
chg_init.o\
chg_tools.o\
chg_parallel.o\
chg_extra.o\
chg_mix.o\
chg_mix_rho.o\
chg_dmr.o\
chg_drho.o\
chg_drho_inner.o\
chg_precond.o\
chg_tau.o\
chg_symm.o\
chg_symm_detail.o\
chg_uspp.o\
chg_rhog_io.o\
write_elecstat_pot.o\
write_init.o\
fp_energy.o\
Expand Down Expand Up @@ -894,8 +901,6 @@ OBJS_SRCPW=h_ewald_pw.o\
stress_pw.o\
of_stress_pw.o\
of_print_info.o\
symm_rho_charge.o\
symm_rhog.o\
setup_psi_pw.o\
setup_psi.o\
psi_prepare.o\
Expand Down
7 changes: 6 additions & 1 deletion source/source_base/parallel_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ void Parallel_Grid::reduce(double* rhotot, const double* const rhoin, const bool
return;
}

assert(rhoin != nullptr);
// A rank may own zero real-space grid points (nrxx == 0) when the grid is
// decomposed across more processes than it has slabs. In that case the
// source buffer is legitimately null: MPI_Gatherv is called with
// sendcount 0 below and ignores the send buffer. Only a null buffer with a
// non-zero nrxx is a genuine bug.
assert(rhoin != nullptr || this->nrxx == 0);
assert(this->nrxx == this->ncxy * this->nczp);

int pool_size = 0;
Expand Down
2 changes: 1 addition & 1 deletion source/source_esolver/esolver_dfpt_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class XC_First_Order_FDM : public ModuleDFPT::XC_First_Order
fdm_ = new elecstate::PotXC_FDM(rho_basis, chg0, ucell);
chg1_ = new Charge();
chg1_->set_rhopw(rho_basis);
chg1_->allocate(chg0->nspin, false);
chg1_->allocate(chg0->nspin, false, false, PARAM.inp.test_charge);
veff_1_.create(chg0->nspin, chg0->nrxx);
}

Expand Down
2 changes: 1 addition & 1 deletion source/source_esolver/esolver_dm2rho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell& basecell, const int istep)

// it's dangerous to design psiToRho function like this, mohan note 20251024
// this->pelec->psiToRho(*this->psi);
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), this->inp_->nspin, &this->chr);
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), this->inp_->nspin, &this->chr, this->inp_->nelec, ucell.omega, false);

int nspin0 = this->inp_->nspin == 2 ? 2 : 1;

Expand Down
25 changes: 21 additions & 4 deletions source/source_esolver/esolver_double_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//-----HSolver ElecState Hamilt--------
#include "source_estate/elecstate_lcao.h"
#include "source_estate/elecstate_tools.h"
#include "source_estate/module_charge/chg_init.h"
#include "source_estate/module_charge/chg_tools.h"
#include "source_hsolver/hsolver_lcao.h"
#include "source_io/module_parameter/parameter.h"
#include "source_io/module_restart/restart.h" // GlobalC::restart for load_exx_flag
Expand Down Expand Up @@ -90,11 +92,26 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(BaseCell& basecell, const Inpu
this->dmat_base.allocate_dm(&this->kv, &this->pv, this->inp_->nspin);

// 10) inititlize the charge density
module_charge::InitRhoCfg init_rho_cfg;
init_rho_cfg.init_chg = this->inp_->init_chg;
init_rho_cfg.suffix = this->inp_->suffix;
init_rho_cfg.esolver_type = this->inp_->esolver_type;
init_rho_cfg.global_readin_dir = PARAM.globalv.global_readin_dir;
init_rho_cfg.nelec = this->inp_->nelec;
init_rho_cfg.nbands = this->inp_->nbands;
init_rho_cfg.test_charge = this->inp_->test_charge;
init_rho_cfg.domag = PARAM.globalv.domag;
init_rho_cfg.domag_z = PARAM.globalv.domag_z;
init_rho_cfg.npol = PARAM.globalv.npol;
init_rho_cfg.meta_gga = XC_Functional::get_ked_flag();
this->chr_base.set_rhopw(this->pw_rhod); // mohan add 20251130
const bool kin_den = this->chr_base.kin_density(); // mohan add 20251202
this->chr_base.allocate(this->inp_->nspin, kin_den);
this->chr_base.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv);
this->chr_base.check_rho();
const bool kin_den = XC_Functional::get_ked_flag() || (this->inp_->out_elf[0] > 0); // mohan add 20251202
this->chr_base.allocate(this->inp_->nspin, kin_den, XC_Functional::get_ked_flag(),
this->inp_->test_charge);
this->chr_base.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv, nullptr, init_rho_cfg);
module_charge::check_rho(this->chr_base.rho, this->chr_base.nspin,
this->chr_base.rhopw->nrxx, ucell.omega,
this->chr_base.rhopw->nxyz, this->inp_->nelec);

// 11) initialize the potential
if (this->pelec_base->pot == nullptr)
Expand Down
32 changes: 23 additions & 9 deletions source/source_esolver/esolver_fp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

#include "source_base/tool_quit.h"
#include "source_cell/cal_ux.h"
#include "source_estate/module_charge/symm_rho.h"
#include "source_estate/module_charge/chg_atomic.h"
#include "source_estate/module_charge/chg_symm.h"
#include "source_cell/read_pp_ucell.h"
#include "source_estate/param_update.h"
#include "source_hamilt/module_ewald/h_ewald_pw.h"
#include "source_hamilt/module_vdw/vdw.h"
#include "source_io/module_output/output_log.h"
#include "source_io/module_output/print_info.h"
#include "source_estate/rhog_io.h"
#include "source_estate/module_charge/chg_rhog_io.h"
#include "source_io/module_parameter/parameter.h"

#include "source_pw/module_pwdft/setup_pwrho.h" // mohan 20251005
Expand Down Expand Up @@ -147,8 +148,8 @@ void ESolver_FP::before_all_runners(BaseCell& basecell, 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
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
const bool kin_den = XC_Functional::get_ked_flag() || (inp.out_elf[0] > 0); // mohan add 20251202
this->chr.allocate(inp.nspin, kin_den, XC_Functional::get_ked_flag(), inp.test_charge); // mohan move this from setup_estate_pw, 20251128


return;
Expand All @@ -165,7 +166,13 @@ void ESolver_FP::after_scf(UnitCell& ucell, const int istep, const bool conv_eso
ModuleIO::output_efermi(conv_esolver, this->pelec->eferm.ef);

//! Update delta_rho for charge extrapolation
CE.update_delta_rho(ucell, &(this->chr), &(this->sf));
const module_charge::AtomicRhoCfg atomic_rho_cfg_after{
PARAM.inp.nelec,
PARAM.inp.test_charge,
PARAM.globalv.domag,
PARAM.globalv.domag_z,
GlobalV::ofs_warning};
CE.update_delta_rho(ucell, &(this->chr), *this->pw_rhod, &(this->sf), atomic_rho_cfg_after);

//! print out charge density, potential, elf, etc.
ModuleIO::ctrl_output_fp(ucell, *this->inp_, this->pelec, this->pw_big, this->pw_rhod,
Expand Down Expand Up @@ -218,8 +225,15 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
if (ucell.ionic_position_updated)
{
this->CE.update_all_dis(ucell);
this->CE.extrapolate_charge(&this->Pgrid, ucell, &this->chr, &this->sf,
GlobalV::ofs_running, GlobalV::ofs_warning);
const module_charge::AtomicRhoCfg atomic_rho_cfg_before{
PARAM.inp.nelec,
PARAM.inp.test_charge,
PARAM.globalv.domag,
PARAM.globalv.domag_z,
GlobalV::ofs_warning};
this->CE.extrapolate_charge(&this->Pgrid, ucell, &this->chr, *this->pw_rhod,
&this->sf, GlobalV::ofs_running, GlobalV::ofs_warning,
atomic_rho_cfg_before);
}

//! Evaluate the vdW correction once for this ionic configuration.
Expand Down Expand Up @@ -268,7 +282,7 @@ void ESolver_FP::iter_finish(UnitCell& ucell, const int istep, int& iter, bool&
// Only pool 0 writes the rhog file (rhog is identical across pools).
if (GlobalV::MY_POOL == 0)
{
elecstate::write_rhog(PARAM.globalv.global_out_dir + this->inp_->suffix + "-CHARGE-DENSITY.restart",
module_charge::write_rhog(PARAM.globalv.global_out_dir + this->inp_->suffix + "-CHARGE-DENSITY.restart",
PARAM.globalv.gamma_only_pw,
this->pw_rhod,
this->inp_->nspin,
Expand All @@ -289,7 +303,7 @@ void ESolver_FP::iter_finish(UnitCell& ucell, const int istep, int& iter, bool&
}
if (GlobalV::MY_POOL == 0)
{
elecstate::write_rhog(PARAM.globalv.global_out_dir + this->inp_->suffix + "-TAU-DENSITY.restart",
module_charge::write_rhog(PARAM.globalv.global_out_dir + this->inp_->suffix + "-TAU-DENSITY.restart",
PARAM.globalv.gamma_only_pw,
this->pw_rhod,
this->inp_->nspin,
Expand Down
4 changes: 2 additions & 2 deletions source/source_esolver/esolver_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "source_base/timer_wrapper.h"
#include "source_basis/module_pw/pw_basis.h" // plane wave basis
#include "source_estate/elecstate.h" // electronic states
#include "source_estate/module_charge/charge_extra.h" // charge extrapolation
#include "source_estate/module_charge/chg_extra.h" // charge extrapolation
#include "source_hamilt/module_surchem/surchem.h" // solvation model
#include "source_base/parallel_grid.h" // Parallel_Grid (value member below)
#include "source_pw/module_pwdft/stru_fac.h" // structure factor
Expand Down Expand Up @@ -81,7 +81,7 @@ class ESolver_FP : public ESolver
pseudopot_cell_vl locpp;

//! charge extrapolation method
Charge_Extra CE;
module_charge::Charge_Extra CE;

//! solvent model
surchem solvent;
Expand Down
1 change: 1 addition & 0 deletions source/source_esolver/esolver_gets.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ESOLVER_GETS_H
#define ESOLVER_GETS_H

#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_basis/module_nao/two_center_bundle.h"
#include "source_cell/unitcell.h"
#include "source_esolver/esolver_ks.h"
Expand Down
71 changes: 59 additions & 12 deletions source/source_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
#include "source_io/module_json/output_info.h"

#include "source_estate/update_pot.h" // mohan add 20251016
#include "source_estate/module_charge/chgmixing.h" // mohan add 20251018
#include "source_estate/module_charge/chg_routine.h" // mohan add 20251018
#include "source_estate/module_charge/chg_drho.h" // module_charge::cal_drho/cal_dkin
#include "source_estate/module_charge/chg_init.h" // module_charge::InitRhoCfg
#include "source_estate/module_charge/chg_tools.h" // module_charge::check_rho
#include "source_pw/module_pwdft/setup_pwwfc.h" // mohan add 20251018
#include "source_hsolver/hsolver.h"
#include "source_io/module_energy/write_eig_occ.h"
Expand Down Expand Up @@ -65,18 +68,48 @@ void ESolver_KS::before_all_runners(BaseCell& basecell, const Input_para& inp)
//! 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);
MixingConfig mix_cfg;
mix_cfg.mixing_mode = inp.mixing_mode;
mix_cfg.mixing_beta = inp.mixing_beta;
mix_cfg.mixing_ndim = inp.mixing_ndim;
mix_cfg.mixing_gg0 = inp.mixing_gg0;
// tau mixing is only meaningful for kinetic-energy-density functionals
mix_cfg.mixing_tau = inp.mixing_tau && XC_Functional::get_ked_flag();
mix_cfg.mixing_beta_mag = inp.mixing_beta_mag;
mix_cfg.mixing_gg0_mag = inp.mixing_gg0_mag;
mix_cfg.mixing_gg0_min = inp.mixing_gg0_min;
mix_cfg.mixing_angle = inp.mixing_angle;
mix_cfg.mixing_dmr = inp.mixing_dmr;
mix_cfg.nspin = inp.nspin;
mix_cfg.scf_thr_type = inp.scf_thr_type;
mix_cfg.double_grid = PARAM.globalv.double_grid;
mix_cfg.gamma_only_pw = PARAM.globalv.gamma_only_pw;
mix_cfg.domag = PARAM.globalv.domag;
mix_cfg.domag_z = PARAM.globalv.domag_z;
mix_cfg.scf_nmax = inp.scf_nmax;
p_chgmix->set_mixing(mix_cfg, ucell.omega, ucell.tpiba);
p_chgmix->init_mixing();

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

//! 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
module_charge::InitRhoCfg init_rho_cfg;
init_rho_cfg.init_chg = inp.init_chg;
init_rho_cfg.suffix = inp.suffix;
init_rho_cfg.esolver_type = inp.esolver_type;
init_rho_cfg.global_readin_dir = PARAM.globalv.global_readin_dir;
init_rho_cfg.nelec = inp.nelec;
init_rho_cfg.nbands = inp.nbands;
init_rho_cfg.test_charge = inp.test_charge;
init_rho_cfg.domag = PARAM.globalv.domag;
init_rho_cfg.domag_z = PARAM.globalv.domag_z;
init_rho_cfg.npol = PARAM.globalv.npol;
init_rho_cfg.meta_gga = XC_Functional::get_ked_flag();
Comment thread
mohanchen marked this conversation as resolved.
Outdated
this->chr.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv, this->pw_wfc, init_rho_cfg);
module_charge::check_rho(this->chr.rho, this->chr.nspin, this->chr.rhopw->nrxx, ucell.omega,
this->chr.rhopw->nxyz, inp.nelec); // check the rho

}

Expand All @@ -97,7 +130,8 @@ void ESolver_KS::hamilt2rho(UnitCell& ucell, const int istep, const int iter, co
// example wavefunctions uses 20 processors while density uses 10.
if (PARAM.globalv.ks_run)
{
drho = p_chgmix->get_drho(&this->chr, this->inp_->nelec);
drho = module_charge::cal_drho(&this->chr, this->inp_->nelec, *this->pw_rho,
p_chgmix->get_mixing_config(), ucell.omega, ucell.tpiba);
hsolver_error = 0.0;
if (iter == 1 && this->inp_->calculation != "nscf")
{
Expand All @@ -114,7 +148,8 @@ void ESolver_KS::hamilt2rho(UnitCell& ucell, const int istep, const int iter, co

this->hamilt2rho_single(ucell, istep, iter, diag_ethr);

drho = p_chgmix->get_drho(&this->chr, this->inp_->nelec);
drho = module_charge::cal_drho(&this->chr, this->inp_->nelec, *this->pw_rho,
p_chgmix->get_mixing_config(), ucell.omega, ucell.tpiba);

hsolver_error = hsolver::cal_hsolve_error(this->inp_->basis_type,
this->inp_->esolver_type, diag_ethr, this->inp_->nelec);
Expand Down Expand Up @@ -255,9 +290,20 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& iter, bool &
}
#endif

module_charge::chgmixing_ks(iter, ucell, this->pelec, this->chr, this->p_chgmix,
this->pw_rhod->nrxx, this->drho, this->oscillate_esolver, conv_esolver, hsolver_error,
this->scf_thr, this->scf_ene_thr, converged_u, *this->inp_);
module_charge::ScfMixingCtx ctx;
ctx.hsolver_error = hsolver_error;
ctx.scf_thr = this->scf_thr;
ctx.scf_ene_thr = this->scf_ene_thr;
ctx.converged_u = converged_u;
ctx.ks_run = PARAM.globalv.ks_run;
ctx.drho = this->drho;
ctx.oscillate_esolver = this->oscillate_esolver;
ctx.conv_esolver = conv_esolver;
module_charge::chgmixing_ks(iter, ucell, this->pelec, this->chr,
*this->chr.rhopw, this->p_chgmix, ctx, *this->inp_);
this->drho = ctx.drho;
this->oscillate_esolver = ctx.oscillate_esolver;
conv_esolver = ctx.conv_esolver;

// 2.3) Update potentials (should be done every SF iter)
elecstate::update_pot(ucell, this->pelec, this->chr, conv_esolver);
Expand All @@ -277,7 +323,8 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& iter, bool &
double dkin = 0.0; // for meta-GGA
if (XC_Functional::get_ked_flag())
{
dkin = p_chgmix->get_dkin(&this->chr, this->inp_->nelec);
dkin = module_charge::cal_dkin(&this->chr, this->inp_->nelec, *this->pw_rho,
p_chgmix->get_mixing_config(), ucell.omega);
}

// Iter finish
Expand Down
Loading
Loading