Skip to content

Commit 4d89de7

Browse files
committed
update dm pointer in esolver_ks_lcao
1 parent 143e9c1 commit 4d89de7

File tree

5 files changed

+70
-23
lines changed

5 files changed

+70
-23
lines changed

source/source_esolver/esolver_ks.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -242,24 +242,16 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
242242
this->scf_nmax_flag=true;
243243
}
244244

245-
//----------------------------------------------------------------
246245
// 3) initialization of SCF iterations
247-
//----------------------------------------------------------------
248246
this->iter_init(ucell, istep, iter);
249247

250-
//----------------------------------------------------------------
251248
// 4) use Hamiltonian to obtain charge density
252-
//----------------------------------------------------------------
253249
this->hamilt2rho(ucell, istep, iter, diag_ethr);
254250

255-
//----------------------------------------------------------------
256251
// 5) finish scf iterations
257-
//----------------------------------------------------------------
258252
this->iter_finish(ucell, istep, iter, conv_esolver);
259253

260-
//----------------------------------------------------------------
261254
// 6) check convergence
262-
//----------------------------------------------------------------
263255
if (conv_esolver || this->oscillate_esolver)
264256
{
265257
this->niter = iter;
@@ -271,9 +263,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
271263
}
272264
} // end scf iterations
273265

274-
//----------------------------------------------------------------
275266
// 7) after scf
276-
//----------------------------------------------------------------
277267
this->after_scf(ucell, istep, conv_esolver);
278268

279269
ModuleBase::timer::tick(this->classname, "runner");
@@ -592,9 +582,6 @@ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bo
592582
this->kv);
593583
}
594584
}
595-
596-
597-
598585
}
599586

600587
template <typename T, typename Device>

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
523523
// call iter_init() of ESolver_KS
524524
ESolver_KS<TK>::iter_init(ucell, istep, iter);
525525

526+
elecstate::DensityMatrix<TK, double>* dm
527+
= dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
528+
526529
if (iter == 1)
527530
{
528531
this->p_chgmix->mix_reset(); // init mixing
@@ -565,8 +568,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
565568
if (PARAM.inp.mixing_dmr) // for mixing_dmr
566569
{
567570
// allocate memory for dmr_mdata
568-
const elecstate::DensityMatrix<TK, double>* dm
569-
= dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
570571
int nnr_tmp = dm->get_DMR_pointer(1)->get_nnr();
571572
this->p_chgmix->allocate_mixing_dmr(nnr_tmp);
572573
}
@@ -652,15 +653,15 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
652653
{
653654
this->exd->exx_eachiterinit(istep,
654655
ucell,
655-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
656+
*dm,
656657
this->kv,
657658
iter);
658659
}
659660
else
660661
{
661662
this->exc->exx_eachiterinit(istep,
662663
ucell,
663-
*dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM(),
664+
*dm,
664665
this->kv,
665666
iter);
666667
}
@@ -671,7 +672,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
671672
{
672673
if (istep != 0 || iter != 1)
673674
{
674-
GlobalC::dftu.set_dmr(dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM());
675+
GlobalC::dftu.set_dmr(dm);
675676
}
676677
// Calculate U and J if Yukawa potential is used
677678
GlobalC::dftu.cal_slater_UJ(ucell, this->chr.rho, this->pw_rho->nrxx);
@@ -702,7 +703,6 @@ void ESolver_KS_LCAO<TK, TR>::iter_init(UnitCell& ucell, const int istep, const
702703
// save density matrix DMR for mixing
703704
if (PARAM.inp.mixing_restart > 0 && PARAM.inp.mixing_dmr && this->p_chgmix->mixing_restart_count > 0)
704705
{
705-
elecstate::DensityMatrix<TK, double>* dm = dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
706706
dm->save_DMR();
707707
}
708708
}

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void ESolver_KS_PW<T, Device>::iter_init(UnitCell& ucell, const int istep, const
187187
ESolver_KS<T, Device>::iter_init(ucell, istep, iter);
188188

189189
// perform charge mixing
190-
module_charge::chgmixing(iter, this->p_chgmix, PARAM.inp);
190+
module_charge::chgmixing_ks_pw(iter, this->p_chgmix, PARAM.inp);
191191

192192
// mohan move harris functional to here, 2012-06-05
193193
// use 'rho(in)' and 'v_h and v_xc'(in)

source/source_estate/module_charge/chgmixing.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#include "source_lcao/module_dftu/dftu.h"
33
#include "source_lcao/module_deltaspin/spin_constrain.h"
44

5-
void module_charge::chgmixing(const int iter, // scf iteration number
5+
void module_charge::chgmixing_ks_pw(const int iter, // scf iteration number
66
Charge_Mixing* p_chgmix, // charge mixing class
77
const Input_para& inp) // input parameters
88
{
9-
ModuleBase::TITLE("module_charge", "setup_chgmixing");
9+
ModuleBase::TITLE("module_charge", "chgmixing_ks_pw");
1010

1111
if (iter == 1)
1212
{
@@ -55,3 +55,61 @@ void module_charge::chgmixing(const int iter, // scf iteration number
5555

5656
return;
5757
}
58+
59+
/*
60+
void module_charge::chgmixing_ks_lcao(const int iter, // scf iteration number
61+
Charge_Mixing* p_chgmix, // charge mixing class
62+
const Input_para& inp) // input parameters
63+
{
64+
ModuleBase::TITLE("module_charge", "chgmixing_ks_lcao");
65+
66+
if (iter == 1)
67+
{
68+
p_chgmix->mix_reset(); // init mixing
69+
p_chgmix->mixing_restart_step = inp.scf_nmax + 1;
70+
p_chgmix->mixing_restart_count = 0;
71+
// this output will be removed once the feeature is stable
72+
if (GlobalC::dftu.uramping > 0.01)
73+
{
74+
std::cout << " U-Ramping! Current U = ";
75+
for (int i = 0; i < GlobalC::dftu.U0.size(); i++)
76+
{
77+
std::cout << GlobalC::dftu.U[i] * ModuleBase::Ry_to_eV << " ";
78+
}
79+
std::cout << " eV " << std::endl;
80+
}
81+
}
82+
83+
// for mixing restart
84+
if (iter == p_chgmix->mixing_restart_step && inp.mixing_restart > 0.0)
85+
{
86+
p_chgmix->init_mixing();
87+
p_chgmix->mixing_restart_count++;
88+
if (inp.dft_plus_u)
89+
{
90+
GlobalC::dftu.uramping_update(); // update U by uramping if uramping > 0.01
91+
if (GlobalC::dftu.uramping > 0.01)
92+
{
93+
std::cout << " U-Ramping! Current U = ";
94+
for (int i = 0; i < GlobalC::dftu.U0.size(); i++)
95+
{
96+
std::cout << GlobalC::dftu.U[i] * ModuleBase::Ry_to_eV << " ";
97+
}
98+
std::cout << " eV " << std::endl;
99+
}
100+
if (GlobalC::dftu.uramping > 0.01 && !GlobalC::dftu.u_converged())
101+
{
102+
p_chgmix->mixing_restart_step = inp.scf_nmax + 1;
103+
}
104+
}
105+
if (inp.mixing_dmr) // for mixing_dmr
106+
{
107+
// allocate memory for dmr_mdata
108+
const elecstate::DensityMatrix<TK, double>* dm
109+
= dynamic_cast<const elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM();
110+
int nnr_tmp = dm->get_DMR_pointer(1)->get_nnr();
111+
p_chgmix->allocate_mixing_dmr(nnr_tmp);
112+
}
113+
}
114+
}
115+
*/

source/source_estate/module_charge/chgmixing.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
namespace module_charge
88
{
99

10-
void chgmixing(const int iter,
10+
void chgmixing_ks_pw(const int iter,
1111
Charge_Mixing* p_chgmix,
1212
const Input_para& inp); // input parameters
1313

14+
//void chgmixing_ks_lcao();
15+
1416
}
1517

1618

0 commit comments

Comments
 (0)