Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions source/source_estate/elecstate_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void print_scf_iterinfo(const std::string& ks_solver,
{"cusolver", "CU"},
{"bpcg", "BP"},
{"pexsi", "PE"},
{"cusolvermp", "CM"}}; // I change the key of "cg_in_lcao" to "CG" because all the other are only two letters
{"cusolvermp", "CM"},
{"sdft", "CT"}}; // CT = Chebyshev Trace, for pure SDFT (nbands=0) where no H diagonalization is performed
// ITER column
std::vector<std::string> th_fmt = {" %-" + std::to_string(witer) + "s"}; // table header: th: ITER
std::vector<std::string> td_fmt
Expand Down Expand Up @@ -374,7 +375,12 @@ void print_etot(const Magnetism& magnet,
{
drho.push_back(scf_thr_kin);
}
elecstate::print_scf_iterinfo(PARAM.inp.ks_solver,
// Pure SDFT (nbands=0) uses Chebyshev trace (CT) since no H diagonalization is performed.
// Mixed SDFT (nbands>0) still diagonalizes KS orbitals, so use the actual ks_solver label.
const std::string iter_label = (PARAM.inp.esolver_type == "sdft" && PARAM.inp.nbands == 0)
? "sdft"
Comment thread
Cstandardlib marked this conversation as resolved.
: PARAM.inp.ks_solver;
elecstate::print_scf_iterinfo(iter_label,
iter,
6,
mag,
Expand Down
62 changes: 62 additions & 0 deletions source/source_estate/test/elecstate_print_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,65 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4)

delete elecstate.charge;
}

TEST_F(ElecStatePrintTest, PrintEtotSDFTPure)
{
bool converged = false;
int iter = 1;
double scf_thr = 0.1;
double scf_thr_kin = 0.0;
double duration = 2.0;
double pw_diag_thr = 0.1;
int avg_iter = 2;
bool print = true;
elecstate.charge = new Charge;
elecstate.charge->nrxx = 100;
elecstate.charge->nxyz = 1000;

PARAM.input.out_freq_elec = 1;
PARAM.input.nspin = 1;
GlobalV::MY_RANK = 0;
// Pure SDFT: nbands=0, no KS diagonalization -> ITER column should show CT
PARAM.input.esolver_type = "sdft";
PARAM.input.nbands = 0;
PARAM.input.ks_solver = "cg";

testing::internal::CaptureStdout();
elecstate::print_etot(ucell.magnet, elecstate, converged, iter, scf_thr,
scf_thr_kin, duration, pw_diag_thr, avg_iter, print);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("CT"));

delete elecstate.charge;
}

TEST_F(ElecStatePrintTest, PrintEtotSDFTMixed)
{
bool converged = false;
int iter = 1;
double scf_thr = 0.1;
double scf_thr_kin = 0.0;
double duration = 2.0;
double pw_diag_thr = 0.1;
int avg_iter = 2;
bool print = true;
elecstate.charge = new Charge;
elecstate.charge->nrxx = 100;
elecstate.charge->nxyz = 1000;

PARAM.input.out_freq_elec = 1;
PARAM.input.nspin = 1;
GlobalV::MY_RANK = 0;
// Mixed SDFT: nbands>0, still diagonalizes KS orbitals -> ITER column shows ks_solver label
PARAM.input.esolver_type = "sdft";
PARAM.input.nbands = 5;
PARAM.input.ks_solver = "dav";

testing::internal::CaptureStdout();
elecstate::print_etot(ucell.magnet, elecstate, converged, iter, scf_thr,
scf_thr_kin, duration, pw_diag_thr, avg_iter, print);
output = testing::internal::GetCapturedStdout();
EXPECT_THAT(output, testing::HasSubstr("DA"));

delete elecstate.charge;
}
Loading