Skip to content

Commit

Permalink
Refactor: refactor hsolver-lcao func (#5148)
Browse files Browse the repository at this point in the history
* refactor hsolver-lcao func

* remove useless value in hsolver_lcaopw
  • Loading branch information
haozhihan committed Sep 24, 2024
1 parent 6212f84 commit b083759
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 267 deletions.
210 changes: 112 additions & 98 deletions source/module_esolver/esolver_ks_lcao.cpp

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions source/module_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
//--------------temporary----------------------------
#include "module_base/blas_connector.h"
#include "module_base/global_function.h"
#include "module_base/scalapack_connector.h"
#include "module_base/lapack_connector.h"
#include "module_base/scalapack_connector.h"
#include "module_elecstate/module_charge/symmetry_rho.h"
#include "module_elecstate/occupy.h"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need divide_HS_in_frag
Expand Down Expand Up @@ -73,34 +73,34 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell&
GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, pw_rho);

// 3) initialize the electronic states for TDDFT
if (this->pelec == nullptr) {
this->pelec = new elecstate::ElecStateLCAO_TDDFT(
&this->chr,
&kv,
kv.get_nks(),
&this->GK, // mohan add 2024-04-01
this->pw_rho,
pw_big);
if (this->pelec == nullptr)
{
this->pelec = new elecstate::ElecStateLCAO_TDDFT(&this->chr,
&kv,
kv.get_nks(),
&this->GK, // mohan add 2024-04-01
this->pw_rho,
pw_big);
}

// 4) read the local orbitals and construct the interpolation tables.
// initialize the pv
LCAO_domain::init_basis_lcao(this->pv,
inp.onsite_radius,
inp.lcao_ecut,
inp.lcao_dk,
inp.lcao_dr,
inp.lcao_rmax,
ucell,
LCAO_domain::init_basis_lcao(this->pv,
inp.onsite_radius,
inp.lcao_ecut,
inp.lcao_dk,
inp.lcao_dr,
inp.lcao_rmax,
ucell,
two_center_bundle_,
orb_);

// 5) allocate H and S matrices according to computational resources
LCAO_domain::divide_HS_in_frag(PARAM.globalv.gamma_only_local, this->pv, kv.get_nks(), orb_);


// 6) initialize Density Matrix
dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->init_DM(&kv, &this->pv, PARAM.inp.nspin);
dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)
->init_DM(&kv, &this->pv, PARAM.inp.nspin);

// 8) initialize the charge density
this->pelec->charge->allocate(PARAM.inp.nspin);
Expand Down Expand Up @@ -169,7 +169,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(const int istep, const int iter, cons
if (this->psi != nullptr)
{
hsolver::HSolverLCAO<std::complex<double>> hsolver_lcao_obj(&this->pv, PARAM.inp.ks_solver);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec_td, PARAM.inp.ks_solver, false);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec_td, false);
}
}
// else
Expand Down Expand Up @@ -255,28 +255,28 @@ void ESolver_KS_LCAO_TDDFT::update_pot(const int istep, const int iter)
if (PARAM.inp.out_mat_hs[0])
{
ModuleIO::save_mat(istep,
h_mat.p,
GlobalV::NLOCAL,
bit,
PARAM.inp.out_mat_hs[1],
1,
PARAM.inp.out_app_flag,
"H",
"data-" + std::to_string(ik),
this->pv,
GlobalV::DRANK);
h_mat.p,
GlobalV::NLOCAL,
bit,
PARAM.inp.out_mat_hs[1],
1,
PARAM.inp.out_app_flag,
"H",
"data-" + std::to_string(ik),
this->pv,
GlobalV::DRANK);

ModuleIO::save_mat(istep,
s_mat.p,
GlobalV::NLOCAL,
bit,
PARAM.inp.out_mat_hs[1],
1,
PARAM.inp.out_app_flag,
"S",
"data-" + std::to_string(ik),
this->pv,
GlobalV::DRANK);
s_mat.p,
GlobalV::NLOCAL,
bit,
PARAM.inp.out_mat_hs[1],
1,
PARAM.inp.out_app_flag,
"S",
"data-" + std::to_string(ik),
this->pv,
GlobalV::DRANK);
}
}
}
Expand Down Expand Up @@ -416,8 +416,8 @@ void ESolver_KS_LCAO_TDDFT::after_scf(const int istep)
}
if (TD_Velocity::out_current == true)
{
elecstate::DensityMatrix<std::complex<double>, double>* tmp_DM =
dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->get_DM();
elecstate::DensityMatrix<std::complex<double>, double>* tmp_DM
= dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec)->get_DM();

ModuleIO::write_current(istep,
this->psi,
Expand Down
2 changes: 1 addition & 1 deletion source/module_esolver/lcao_nscf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void ESolver_KS_LCAO<TK, TR>::nscf() {
// istep becomes istep-1, this should be fixed in future
int istep = 0;
hsolver::HSolverLCAO<TK> hsolver_lcao_obj(&(this->pv), PARAM.inp.ks_solver);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, PARAM.inp.ks_solver, true);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, true);

time_t time_finish = std::time(nullptr);
ModuleBase::GlobalFunc::OUT_TIME("cal_bands", time_start, time_finish);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void SpinConstrain<std::complex<double>, base_device::DEVICE_CPU>::cal_mw_from_l

// diagonalization without update charge
hsolver::HSolverLCAO<std::complex<double>> hsolver_lcao_obj(this->ParaV, this->KS_SOLVER);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, this->KS_SOLVER, true);
hsolver_lcao_obj.solve(this->p_hamilt, this->psi[0], this->pelec, true);

elecstate::ElecStateLCAO<std::complex<double>>* pelec_lcao
= dynamic_cast<elecstate::ElecStateLCAO<std::complex<double>>*>(this->pelec);
Expand Down
Loading

0 comments on commit b083759

Please sign in to comment.