Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Remove the inheritance relationship between hsolverLCAO/hsolverLIP and hsolver #4960

Merged
merged 2 commits into from
Aug 14, 2024
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
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(const Input_para& inp, UnitCell
// 10) initialize the HSolver
if (this->phsol == nullptr)
{
this->phsol = new hsolver::HSolverLCAO<TK>(&(this->pv), GlobalV::KS_SOLVER);
this->phsol = new hsolver::HSolver<TK>();
}

// 11) inititlize the charge density
Expand Down
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ESolver_KS_LCAO_TDDFT::before_all_runners(const Input_para& inp, UnitCell&
// 7) initialize Hsolver
if (this->phsol == nullptr)
{
this->phsol = new hsolver::HSolverLCAO<std::complex<double>>(&this->pv, GlobalV::KS_SOLVER);
this->phsol = new hsolver::HSolver<std::complex<double>>();
}

// 8) initialize the charge density
Expand Down
5 changes: 2 additions & 3 deletions source/module_esolver/esolver_ks_lcaopw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ namespace ModuleESolver
template <typename T>
void ESolver_KS_LIP<T>::allocate_hsolver()
{
this->phsol = new hsolver::HSolverLIP<T>(this->pw_wfc);
this->phsol = new hsolver::HSolver<T>();
}
template <typename T>
void ESolver_KS_LIP<T>::deallocate_hsolver()
{
if (this->phsol != nullptr)
{
std::cout << "test" << std::endl;
delete reinterpret_cast<hsolver::HSolverLIP<T>*>(this->phsol);
delete (this->phsol);
this->phsol = nullptr;
}
}
Expand Down
27 changes: 0 additions & 27 deletions source/module_hsolver/hsolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,6 @@ class HSolver
public:
HSolver() {};

// solve Hamiltonian to electronic density in ElecState
virtual void solve(hamilt::Hamilt<T, Device>* phm,
psi::Psi<T, Device>& ppsi,
elecstate::ElecState* pes,
const std::string method,
const bool skip_charge)
{
return;
}

virtual void solve(hamilt::Hamilt<T, Device>* phm,
psi::Psi<T, Device>& ppsi,
elecstate::ElecState* pes,
ModulePW::PW_Basis_K* wfc_basis,
Stochastic_WF& stowf,
const int istep,
const int iter,
const std::string method,
const int scf_iter_in,
const bool need_subspace_in,
const int diag_iter_max_in,
const double pw_diag_thr_in,
const bool skip_charge)
{
return;
}

// set diagethr according to drho (for lcao and lcao-in-pw, we suppose the error is zero and we set diagethr to 0)
virtual Real set_diagethr(Real diag_ethr_in, const int istep, const int iter, const Real drho)
{
Expand Down
19 changes: 10 additions & 9 deletions source/module_hsolver/hsolver_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ namespace hsolver
{

template <typename T, typename Device = base_device::DEVICE_CPU>
class HSolverLCAO : public HSolver<T, Device>
class HSolverLCAO
{
public:
HSolverLCAO(const Parallel_Orbitals* ParaV_in, std::string method_in)
: ParaV(ParaV_in), method(method_in)
{};
HSolverLCAO(const Parallel_Orbitals* ParaV_in, std::string method_in) : ParaV(ParaV_in), method(method_in) {};

void solve(hamilt::Hamilt<T>* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, const std::string method_in, const bool skip_charge) override;
void solve(hamilt::Hamilt<T>* pHamilt,
psi::Psi<T>& psi,
elecstate::ElecState* pes,
const std::string method_in,
const bool skip_charge);

static std::vector<int> out_mat_hs; // mohan add 2010-09-02
static int out_mat_hsR; // LiuXh add 2019-07-16
static int out_mat_hsR; // LiuXh add 2019-07-16
static int out_mat_t;
static int out_mat_dh;

Expand All @@ -29,7 +31,6 @@ class HSolverLCAO : public HSolver<T, Device>

void parakSolve(hamilt::Hamilt<T>* pHamilt, psi::Psi<T>& psi, elecstate::ElecState* pes, int kpar);


bool is_first_scf = true;

using Real = typename GetTypeReal<T>::type;
Expand All @@ -50,13 +51,13 @@ template <typename T, typename Device>
int HSolverLCAO<T, Device>::out_mat_dh = 0;

template <typename T>
inline T my_conj(T value)
inline T my_conj(T value)
{
return value;
}

template <>
inline std::complex<double> my_conj(std::complex<double> value)
inline std::complex<double> my_conj(std::complex<double> value)
{
return std::conj(value);
}
Expand Down
2 changes: 1 addition & 1 deletion source/module_hsolver/hsolver_lcaopw.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace hsolver {

// LCAO-in-PW does not support GPU now.
template <typename T>
class HSolverLIP : public HSolver<T, base_device::DEVICE_CPU>
class HSolverLIP
{
private:
// Note GetTypeReal<T>::type will
Expand Down
2 changes: 1 addition & 1 deletion source/module_hsolver/hsolver_pw_sdft.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HSolverPW_SDFT : public HSolverPW<std::complex<double>>
const bool need_subspace_in,
const int diag_iter_max_in,
const double pw_diag_thr_in,
const bool skip_charge) override;
const bool skip_charge);

virtual double set_diagethr(double diag_ethr_in, const int istep, const int iter, const double drho) override;

Expand Down
Loading