Skip to content

Commit d0cc63d

Browse files
author
Kai Luo
committed
Refactor setup_solver in ESolver_DirectMin_LCAO: Remove redundant domain checks and enhance logging for KS solver convergence
1 parent 4990f99 commit d0cc63d

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

source/source_esolver/esolver_directmin_lcao.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ void ESolver_DirectMin_LCAO::setup_solver(UnitCell& ucell, const Input_para& inp
382382
// for the moment, use random use random orbitals and fixed weights
383383
else if (inp.directmin_objective == "rdmft")
384384
{
385-
Manifold* domain = this->prob->GetDomain();
386-
if (domain == nullptr)
387-
{
388-
ModuleBase::WARNING_QUIT("ESolver_DirectMin_LCAO", "RDMFT problem domain is undefined");
389-
}
385+
// Manifold* domain = this->prob->GetDomain();
386+
// if (domain == nullptr)
387+
// {
388+
// ModuleBase::WARNING_QUIT("ESolver_DirectMin_LCAO", "RDMFT problem domain is undefined");
389+
// }
390390

391-
Variable initial_variable = domain->RandominManifold();
391+
Variable initial_variable =this->prob->GetDomain()->RandominManifold();
392392
bool seeded = false;
393393
std::string seed_error;
394394

@@ -410,8 +410,21 @@ void ESolver_DirectMin_LCAO::setup_solver(UnitCell& ucell, const Input_para& inp
410410

411411
try
412412
{
413+
// temporarily use esolver_type=ksdft
414+
inp.
413415
p_esolver->before_all_runners(ucell, inp);
416+
417+
std::cout << "Setting up KS solver for seeding DirectMin variable" << std::endl;
414418
p_esolver->runner(ucell, 0);
419+
// check if the runner was successful
420+
if (!p_esolver->conv_esolver )
421+
{
422+
throw std::runtime_error("KS solver did not converge");
423+
}
424+
else
425+
{
426+
std::cout << "KS solver converged successfully." << std::endl;
427+
}
415428

416429
seeded = seed_variable_from_ks_solver(dynamic_cast<ESolver_KS_LCAO<double, double>*>(p_esolver),
417430
dynamic_cast<RDMFT_LCAO<double, double>*>(this->prob),
@@ -449,6 +462,7 @@ void ESolver_DirectMin_LCAO::setup_solver(UnitCell& ucell, const Input_para& inp
449462
}
450463

451464
X = std::move(initial_variable);
465+
X.Print("Initial variable for DirectMin:");
452466
}
453467

454468
// next set up the solver based on directmin_solver, sd, cg, bfgs, etc.

0 commit comments

Comments
 (0)