Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
66f6f92
deltaspin: mirror print_header output into running_scf.log
Aug 24, 2026
3e56332
deltaspin: mirror print_termination footer output into running_scf.log
Aug 24, 2026
206ee6d
deltaspin: mirror check_rms_stop output into running_scf.log
Aug 24, 2026
0e9a4ab
deltaspin: mirror check_restriction output into running_scf.log
Aug 24, 2026
89a3610
deltaspin: mirror check_gradient_decay diagnostic output to ofs_running
Aug 24, 2026
bd40359
deltaspin: mirror print_2d tables into running_scf.log
Aug 24, 2026
fd0cd59
deltaspin: mirror run_lambda_loop scalar diagnostics to ofs_running
Aug 24, 2026
32c0a54
deltaspin: mirror run_lambda_linear_scan [DS-DIAG] output into runnin…
Aug 24, 2026
f0d26c3
elecstate: mirror SCF per-iter compact table to running_scf.log
Aug 24, 2026
9042d28
deltaspin: split output between screen and running_scf.log
Aug 24, 2026
bed203a
deltaspin: add RMS column to SCF table, move converged summary to log
Aug 24, 2026
c86d36c
deltaspin: remove GlobalV::ofs_running dependency from module_deltaspin
Aug 25, 2026
1217278
deltaspin: add empty deltaspin_pw_impl.cpp in module_pwdft
Aug 25, 2026
bb427a1
deltaspin: move cal_mi_pw implementation to module_pwdft
Aug 25, 2026
cd6e047
deltaspin: move calculate_delta_hcc to module_pwdft
Aug 25, 2026
b1a06f2
deltaspin: move update_psi_charge_pw_cpu/gpu to module_pwdft
Aug 25, 2026
a1526a1
deltaspin: finalize PW code relocation and clean up includes
Aug 25, 2026
ac49785
Merge branch 'develop' into 2026-08-24-b
mohanchen Aug 25, 2026
5ff084e
deltaspin: lift 6 lambda-loop helpers out of SpinConstrain class
Aug 25, 2026
512a3a7
deltaspin: lift print_Mi / print_Mag_Force out of SpinConstrain class
Aug 25, 2026
25ebd05
Refactor: extract accumulate_Mi_from_becp as free function in mi_tools
Aug 25, 2026
6356f78
Merge remote-tracking branch 'upstream/develop' into pr-7857-merge-test
Aug 25, 2026
5b84c1a
deltaspin: remove redundant sc_parse_json.cpp
Aug 25, 2026
875c5b0
remove some PARAM usage
Aug 25, 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
8 changes: 6 additions & 2 deletions source/source_esolver/esolver_ks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ void ESolver_KS::iter_init(UnitCell& ucell, const int istep, const int iter)

iter_time = ModuleBase::get_time();

// Reset DeltaSpin RMS for this SCF iteration. If DeltaSpin is enabled, use 0
// (meaning "lambda loop not yet run this iteration"); otherwise -1 (no RMS column).
this->ds_rms_ = this->inp_->sc_mag_switch ? 0.0 : -1.0;

if (this->inp_->esolver_type == "ksdft")
{
diag_ethr = hsolver::set_diagethr_ks(this->inp_->basis_type, this->inp_->esolver_type,
Expand Down Expand Up @@ -279,8 +283,8 @@ void ESolver_KS::iter_finish(UnitCell& ucell, const int istep, int& iter, bool &
double duration = ModuleBase::get_duration(iter_time, ModuleBase::get_time());

// print energies
elecstate::print_etot(ucell.magnet, *pelec, conv_esolver, iter, drho,
dkin, duration, diag_ethr);
elecstate::print_etot(ucell.magnet, *pelec, conv_esolver, iter, drho,
dkin, duration, diag_ethr, 0, true, this->ds_rms_);


#ifdef __RAPIDJSON
Expand Down
3 changes: 3 additions & 0 deletions source/source_esolver/esolver_ks.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class ESolver_KS : public ESolver_FP
double scf_ene_thr; //! scf energy threshold
double drho; //! the difference between rho_in (before HSolver) and rho_out (After HSolver)
double hsolver_error; //! the error of HSolver
/// DeltaSpin RMS from the most recent lambda optimization loop; -1.0 means no DeltaSpin.
/// Set by ESolver_KS_LCAO after run_lambda_loop, read by ESolver_KS::iter_finish when calling print_etot.
double ds_rms_ = -1.0;
int maxniter; //! maximum iter steps for scf
int niter; //! iter steps actually used in scf
bool oscillate_esolver = false; // whether esolver is oscillated
Expand Down
8 changes: 5 additions & 3 deletions source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,18 +430,20 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
if (this->inp_->sc_lambda_strategy == "linear_scan")
{
sc.run_lambda_linear_scan(iter - 1);
sc.run_lambda_linear_scan(iter - 1, GlobalV::ofs_running);
skip_solve = true;
}
else if (!sc.mag_converged() && this->drho > 0 && this->drho < this->inp_->sc_scf_thr)
{
sc.run_lambda_loop(iter - 1);
sc.run_lambda_loop(iter - 1, true, GlobalV::ofs_running);
this->ds_rms_ = sc.get_last_rms_error();
sc.set_mag_converged(true);
skip_solve = true;
}
else if (sc.mag_converged())
{
sc.run_lambda_loop(iter - 1);
sc.run_lambda_loop(iter - 1, true, GlobalV::ofs_running);
this->ds_rms_ = sc.get_last_rms_error();
skip_solve = true;
}
}
Expand Down
10 changes: 9 additions & 1 deletion source/source_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "source_hamilt/module_xc/general_exx_info.h" // for General_Exx_Info type used via general_exx_info_
#include "source_io/module_ctrl/ctrl_output_pw.h" // mohan add 20250927
#include "source_pw/module_pwdft/deltaspin_pw.h" // mohan add 20250309
#include "source_lcao/module_deltaspin/spin_constrain.h"
#include "source_pw/module_pwdft/setup_pot.h" // mohan add 20250929
#include "source_pw/module_pwdft/update_cell_pw.h" // mohan add 20250309
#include "source_pw/module_pwdft/setup_dftu_pw.h" // mohan add 20250309
Expand Down Expand Up @@ -227,7 +228,14 @@ void ESolver_KS_PW<T, Device>::hamilt2rho_single(UnitCell& ucell, const int iste
bool skip_charge = this->inp_->calculation == "nscf" ? true : false;

// run the inner lambda loop to contrain atomic moments with the DeltaSpin method
bool skip_solve = pw::run_deltaspin_lambda_loop(iter - 1, this->drho, *this->inp_);
bool skip_solve = pw::run_deltaspin_lambda_loop(iter - 1, this->drho, *this->inp_, GlobalV::ofs_running);
if (skip_solve)
{
// Fetch the most recent DeltaSpin RMS for display in the SCF iteration table.
spinconstrain::SpinConstrain<std::complex<double>>& sc
= spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
this->ds_rms_ = sc.get_last_rms_error();
}

if (!skip_solve)
{
Expand Down
20 changes: 11 additions & 9 deletions source/source_esolver/lcao_others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
ModuleBase::timer::start("ESolver_KS_LCAO", "others");

const std::string cal_type = this->inp_->calculation;
const std::string global_out_dir = PARAM.globalv.global_out_dir;
const bool gamma_only_local = PARAM.globalv.gamma_only_local;

if (cal_type == "test_memory")
{
Expand Down Expand Up @@ -78,7 +80,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->inp_->out_level,
orb_.get_rcutmax_Phi(),
ucell.infoNL->get_rcutmax_Beta(),
PARAM.globalv.gamma_only_local);
gamma_only_local);

atom_arrange::search(PARAM.globalv.search_pbc,
GlobalV::ofs_running,
Expand Down Expand Up @@ -108,7 +110,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
// (2)For each atom, calculate the adjacent atoms in different cells
// and allocate the space for H(R) and S(R).
// If k point is used here, allocate HlocR after atom_arrange.
this->RA.for_2d(ucell, this->gd, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
this->RA.for_2d(ucell, this->gd, this->pv, gamma_only_local, orb_.cutoffs());

// 2. density matrix extrapolation

Expand Down Expand Up @@ -175,14 +177,14 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)

// pelec should be initialized before these calculations
elecstate::init_scf(ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric,
istep, PARAM.globalv.global_out_dir, *this->inp_, this->pelec);
istep, global_out_dir, *this->inp_, this->pelec);

// self consistent calculations for electronic ground state
if (cal_type == "get_pchg")
{
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "getting partial charge");
Get_pchg_lcao get_pchg(this->psi, &(this->pv));
if (PARAM.globalv.gamma_only_local)
if (gamma_only_local)
{
get_pchg.begin(this->chr.rho,
this->pelec->wg,
Expand All @@ -196,7 +198,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->Pgrid,
&this->gd,
this->kv,
PARAM.globalv.global_out_dir,
global_out_dir,
GlobalV::ofs_running);
}
else
Expand All @@ -215,7 +217,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->Pgrid,
&this->gd,
this->kv,
PARAM.globalv.global_out_dir,
global_out_dir,
GlobalV::ofs_running,
this->inp_->if_separate_k,
this->chr.ngmc);
Expand All @@ -226,7 +228,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
{
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "getting wave function");
Get_wf_lcao get_wf(this->pelec);
if (PARAM.globalv.gamma_only_local)
if (gamma_only_local)
{
get_wf.begin(ucell,
this->psi,
Expand All @@ -241,7 +243,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->inp_->nbands,
this->inp_->nspin,
PARAM.globalv.nlocal,
PARAM.globalv.global_out_dir,
global_out_dir,
GlobalV::ofs_running);
}
else
Expand All @@ -259,7 +261,7 @@ void ESolver_KS_LCAO<TK, TR>::others(BaseCell& basecell, const int istep)
this->inp_->nbands,
this->inp_->nspin,
PARAM.globalv.nlocal,
PARAM.globalv.global_out_dir,
global_out_dir,
GlobalV::ofs_running);
}
std::cout << FmtCore::format(" >> Finish %s.\n * * * * * *\n", "getting wave function");
Expand Down
22 changes: 19 additions & 3 deletions source/source_estate/elecstate_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void print_scf_iterinfo(const std::string& ks_solver,
const std::vector<double>& drho,
const int& wrho,
const double& time,
const int& wtime)
const int& wtime,
const double& ds_rms)
{
std::map<std::string, std::string> iter_header_dict
= {{"cg", "CG"},
Expand Down Expand Up @@ -91,6 +92,12 @@ void print_scf_iterinfo(const std::string& ks_solver,
{
td_fmt.emplace_back(" %" + std::to_string(wrho) + ".4e");
}
// DeltaSpin RMS column (optional, same width/format as DRHO/DKIN)
if (ds_rms >= 0)
{
th_fmt.emplace_back(" %" + std::to_string(wrho) + "s");
td_fmt.emplace_back(" %" + std::to_string(wrho) + ".4e");
}
// time column, trivial
th_fmt.emplace_back(" %" + std::to_string(wtime) + "s\n");
td_fmt.emplace_back(" %" + std::to_string(wtime) + ".2f\n");
Expand Down Expand Up @@ -132,6 +139,13 @@ void print_scf_iterinfo(const std::string& ks_solver,
titles.push_back(FmtCore::center("DKIN", wrho));
values.push_back(drho[1]);
}
// DeltaSpin RMS column: shown only when a valid RMS value is provided (>= 0).
// Placed after DKIN (if any) and before TIME.
if (ds_rms >= 0)
{
titles.push_back(FmtCore::center("RMS", wrho));
values.push_back(ds_rms);
}
titles.push_back(FmtCore::center("TIME/s", wtime));
values.push_back(time);
std::string buf;
Expand Down Expand Up @@ -168,7 +182,8 @@ void print_etot(const Magnetism& magnet,
const double& duration,
const double& pw_diag_thr,
const double& avg_iter,
const bool print)
const bool print,
const double& ds_rms)
{
ModuleBase::TITLE("energy", "print_etot");
const int iter = iter_in;
Expand Down Expand Up @@ -395,7 +410,8 @@ void print_etot(const Magnetism& magnet,
drho,
12,
duration,
6);
6,
ds_rms);
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion source/source_estate/elecstate_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace elecstate
const double& duration,
const double& pw_diag_thr = 0,
const double& avg_iter = 0,
bool print = true);
bool print = true,
const double& ds_rms = -1.0);
}
#endif
3 changes: 2 additions & 1 deletion source/source_io/module_ctrl/ctrl_output_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../module_wf/get_wf_pw.h"
#include "../module_wf/write_wfc_pw.h" // use write_wfc_pw
#include "source_base/formatter.h"
#include "source_lcao/module_deltaspin/lambda_loop_helper.h"
#include "source_lcao/module_deltaspin/spin_constrain.h"
#include "source_pw/module_pwdft/elecond.h"
#include "source_pw/module_pwdft/onsite_proj.h" // use projector
Expand Down Expand Up @@ -214,7 +215,7 @@ void ModuleIO::ctrl_scf_pw(const int istep,
{
spinconstrain::SpinConstrain<std::complex<double>>& sc = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
sc.cal_mi_pw();
sc.print_Mag_Force(GlobalV::ofs_running);
spinconstrain::print_Mag_Force(sc, GlobalV::ofs_running);
}

//------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions source/source_io/module_ctrl/ctrl_scf_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "../module_dm/write_dmr.h" // use ModuleIO::write_dmr()
#include "../module_dos/write_dos_lcao.h" // use ModuleIO::write_dos_lcao()
#include "../module_wf/write_wfc_nao.h" // use ModuleIO::write_wfc_nao()
#include "source_lcao/module_deltaspin/lambda_loop_helper.h" // print_Mi / print_Mag_Force free functions
#include "source_lcao/module_deltaspin/spin_constrain.h" // use spinconstrain::SpinConstrain<TK>
#include "source_lcao/module_operator_lcao/ekinetic.h" // use hamilt::EKinetic
#ifdef __MLALGO
Expand Down Expand Up @@ -554,8 +555,8 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
{
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
sc.cal_mi_lcao(istep);
sc.print_Mi(GlobalV::ofs_running);
sc.print_Mag_Force(GlobalV::ofs_running);
spinconstrain::print_Mi(sc, GlobalV::ofs_running);
spinconstrain::print_Mag_Force(sc, GlobalV::ofs_running);
}

//------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion source/source_lcao/module_deltaspin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ list(APPEND objects
cal_mw_from_lambda.cpp
template_helpers.cpp
deltaspin_lcao.cpp
sc_parse_json.cpp
cal_mw_helper.cpp
mi_tools.cpp
)

add_library(
Expand Down
13 changes: 9 additions & 4 deletions source/source_lcao/module_deltaspin/basic_funcs.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "basic_funcs.h"

#include <iostream>
#include "source_base/formatter.h"
#include "source_base/constants.h"
#include "source_base/formatter.h"

double maxval_abs_2d(const std::vector<ModuleBase::Vector3<double>>& array)
{
Expand Down Expand Up @@ -142,8 +142,13 @@ void print_2d(const std::string info, const std::vector<ModuleBase::Vector3<doub
for (const auto &row : array)
{
iat += 1;
if (nspin == 2) { ofs << FmtCore::format("ATOM %6d %20.10f\n", iat, row.z*unit_convert);
} else if (nspin == 4) { ofs << FmtCore::format("ATOM %6d %20.10f %20.10f %20.10f\n", iat, row.x*unit_convert, row.y*unit_convert, row.z*unit_convert);
}
if (nspin == 2)
{
ofs << FmtCore::format(" ATOM %6d %20.10f\n", iat, row.z*unit_convert);
}
else if (nspin == 4)
{
ofs << FmtCore::format(" ATOM %6d %20.10f %20.10f %20.10f\n", iat, row.x*unit_convert, row.y*unit_convert, row.z*unit_convert);
}
}
}
Loading
Loading