Skip to content
Open
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
1 change: 1 addition & 0 deletions source/source_esolver/esolver_double_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(
this->pelec_base->f_en.deband = this->pelec->f_en.deband;
this->pelec_base->f_en.demet = this->pelec->f_en.demet;
this->pelec_base->f_en.descf = 0.0; // set descf to 0
this->pelec_base->set_spin_constrain_energy(this->pelec->f_en.escon);
this->pelec_base->cal_energies(
2, this->inp_->imp_sol, this->inp_->sc_mag_switch, this->inp_->dft_plus_u,
this->inp_->assume_isolated); // 2 means Kohn-Sham functional
Expand Down
6 changes: 6 additions & 0 deletions source/source_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(

// 3) for DeltaSpin, calculate atomic magnetic moments
cal_mi_lcao_wrapper<TK>(iter, *this->inp_);
if (this->inp_->sc_mag_switch)
{
auto& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
const double escon = sc.cal_escon();
this->pelec->set_spin_constrain_energy(escon);
}

// call iter_finish() of ESolver_KS, where the band gap is calculated,
// eig and occ are printed, magnetization is calculated,
Expand Down
26 changes: 18 additions & 8 deletions source/source_esolver/esolver_ks_lcao_tddft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,25 @@ void ESolver_KS_LCAO_TDDFT<TR, Device>::iter_finish(
if (accept_state && last_endpoint && istep >= (this->inp_->init_wfc == "file" ? 0 : 1) && this->inp_->td_edm == 0 &&
this->inp_->td_stype != 2)
{
if (use_tensor && use_lapack)
{
module_dm::edm_tddft_lapack<Device>(
this->pv, this->dmat, this->kv, static_cast<hamilt::Hamilt<std::complex<double>> *>(this->p_hamilt));
}
else
auto* hamilt = static_cast<hamilt::Hamilt<std::complex<double>>*>(this->p_hamilt);
const auto& layout = this->pv.para_2d();
this->dmat.dm->edmk.resize(this->kv.get_nks());
for (int ik = 0; ik < this->kv.get_nks(); ++ik)
{
module_dm::edm_tddft(
this->pv, this->dmat, this->kv, static_cast<hamilt::Hamilt<std::complex<double>> *>(this->p_hamilt));
hamilt->updateHk(ik);
ModuleBase::MatrixBlock<std::complex<double>> h_mat;
ModuleBase::MatrixBlock<std::complex<double>> s_mat;
hamilt->matrix(h_mat, s_mat);
auto* dmk = this->dmat.dm->get_dmk_ptr(ik);
auto& edmk = this->dmat.dm->edmk[ik];
if (use_tensor && use_lapack)
{
module_dm::edm_tddft_lapack<Device>(layout, h_mat, s_mat, dmk, edmk);
}
else
{
module_dm::edm_tddft(layout, h_mat, s_mat, dmk, edmk);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions source/source_esolver/esolver_ks_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ void ESolver_KS_PW<T, Device>::iter_finish(
this->pelec->f_en.deband = this->pelec->cal_delta_eband(ucell);

// Call iter_finish() of ESolver_KS
if (this->inp_->sc_mag_switch)
{
auto& sc = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
const double escon = sc.cal_escon();
this->pelec->set_spin_constrain_energy(escon);
}
ESolver_KS::iter_finish(ucell, istep, iter, conv_esolver);

// D in USPP needs vloc, thus needs update when veff updated
Expand Down
7 changes: 7 additions & 0 deletions source/source_esolver/esolver_sdft_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "source_hsolver/diago_iter_assist.h"
#include "source_hsolver/diago_params.h"
#include "source_io/module_parameter/parameter.h"
#include "source_lcao/module_deltaspin/spin_constrain.h"
#include "source_pw/module_stodft/sto_dos.h"
#include "source_pw/module_stodft/sto_elecond.h"
#include "source_pw/module_stodft/sto_forces.h"
Expand Down Expand Up @@ -117,6 +118,12 @@ void ESolver_SDFT_PW<T, Device>::iter_finish(
bool &conv_esolver)
{
// call iter_finish() of ESolver_KS
if (this->inp_->sc_mag_switch)
{
auto& sc = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
const double escon = sc.cal_escon();
this->pelec->set_spin_constrain_energy(escon);
}
ESolver_KS::iter_finish(ucell, istep, iter, conv_esolver);
}

Expand Down
5 changes: 3 additions & 2 deletions source/source_estate/elecstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,10 @@ class ElecState
double get_solvent_model_Ael();
double get_solvent_model_Acav();

virtual double get_spin_constrain_energy()
/// Constraint energy (Ry), supplied after updating the atomic magnetic moments.
void set_spin_constrain_energy(const double energy)
{
return 0.0;
this->f_en.escon = energy;
}

double get_dftu_energy();
Expand Down
6 changes: 3 additions & 3 deletions source/source_estate/elecstate_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ void ElecState::cal_energies(const int type,
this->f_en.esol_cav = 0.0;
}

//! spin constrained energy
if (sc_mag_switch)
// The solver supplies the constraint energy before energy convergence and mixing.
if (!sc_mag_switch)
{
this->f_en.escon = get_spin_constrain_energy();
this->f_en.escon = 0.0;
}

// energy from DFT+U
Expand Down
16 changes: 0 additions & 16 deletions source/source_estate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "source_base/timer.h"
#include "source_estate/module_dm/dm_from_psi.h"
#include "source_hamilt/module_xc/xc_functional.h"
#include "source_lcao/module_deltaspin/spin_constrain.h"
#include "source_io/module_parameter/parameter.h"

#include "source_hamilt/module_gint/gint_interface.h"
Expand All @@ -15,21 +14,6 @@ namespace elecstate
{


template <>
double ElecStateLCAO<double>::get_spin_constrain_energy()
{
spinconstrain::SpinConstrain<double>& sc = spinconstrain::SpinConstrain<double>::getScInstance();
return sc.cal_escon();
}

template <>
double ElecStateLCAO<std::complex<double>>::get_spin_constrain_energy()
{
spinconstrain::SpinConstrain<std::complex<double>>& sc
= spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
return sc.cal_escon();
}

template <>
void ElecStateLCAO<double>::dm2rho(std::vector<double*> pexsi_DM,
std::vector<double*> edm_pexsi,
Expand Down
2 changes: 0 additions & 2 deletions source/source_estate/elecstate_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class ElecStateLCAO : public ElecState
static int out_wfc_lcao;
static bool need_psi_grid;

double get_spin_constrain_energy() override;

// use for pexsi

/**
Expand Down
8 changes: 0 additions & 8 deletions source/source_estate/elecstate_pw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "source_estate/uspp_density.h"
#include "source_hamilt/module_xc/xc_functional.h"
#include "source_io/module_parameter/parameter.h"
#include "source_lcao/module_deltaspin/spin_constrain.h"
#include "source_pw/module_pwdft/vnl_pw.h"

namespace elecstate
Expand Down Expand Up @@ -58,13 +57,6 @@ ElecStatePW<T, Device>::~ElecStatePW()
delmem_complex_op()(this->wfcr_another_spin);
}

template <typename T, typename Device>
double ElecStatePW<T, Device>::get_spin_constrain_energy()
{
spinconstrain::SpinConstrain<std::complex<double>>& sc = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
return sc.cal_escon();
}

template <typename T, typename Device>
void ElecStatePW<T, Device>::init_rho_data()
{
Expand Down
2 changes: 0 additions & 2 deletions source/source_estate/elecstate_pw.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class ElecStatePW : public ElecState

void cal_tau(const psi::Psi<T, Device>& psi) override;

double get_spin_constrain_energy() override;

//! calculate becsum for uspp
void cal_becsum(const psi::Psi<T, Device>& psi);

Expand Down
Loading
Loading