Skip to content

Commit 143e9c1

Browse files
committed
update esolver, move chargemixing to module_charge
1 parent e74565d commit 143e9c1

File tree

8 files changed

+87
-68
lines changed

8 files changed

+87
-68
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
704704
VL_in_pw.o\
705705
VNL_in_pw.o\
706706
VNL_grad_pw.o\
707+
chgmixing.o\
707708
charge.o\
708709
charge_init.o\
709710
charge_mpi.o\

source/source_esolver/esolver_ks.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#include "esolver_ks.h"
2-
3-
// To setup plane wave for electronic wave functions
4-
#include "pw_setup.h"
2+
#include "pw_setup.h" // setup plane wave
53

64
#include "source_base/timer.h"
75
#include "source_base/global_variable.h"
@@ -152,10 +150,6 @@ void ESolver_KS<T, Device>::before_all_runners(UnitCell& ucell, const Input_para
152150
this->sf.setup_structure_factor(&ucell, Pgrid, this->pw_rhod);
153151
}
154152

155-
//------------------------------------------------------------------------------
156-
//! the 5th function of ESolver_KS: hamilt2rho_single
157-
//! mohan add 2024-05-11
158-
//------------------------------------------------------------------------------
159153
template <typename T, typename Device>
160154
void ESolver_KS<T, Device>::hamilt2rho_single(UnitCell& ucell, const int istep, const int iter, const double ethr)
161155
{

source/source_esolver/esolver_ks.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
#ifndef ESOLVER_KS_H
22
#define ESOLVER_KS_H
33

4-
#include <cstring>
5-
//#include <fstream>
6-
7-
// for first-principles esolver
8-
#include "esolver_fp.h"
9-
// for plane wave basis set
10-
#include "source_basis/module_pw/pw_basis_k.h"
11-
// for k-points in Brillouin zone
12-
#include "source_cell/klist.h"
13-
// for charge mixing
14-
#include "source_estate/module_charge/charge_mixing.h"
15-
// for electronic wave functions
16-
#include "source_psi/psi.h"
17-
// for Hamiltonian
18-
#include "source_hamilt/hamilt.h"
4+
#include "esolver_fp.h" // first-principles esolver
5+
#include "source_basis/module_pw/pw_basis_k.h" // use plane wave
6+
#include "source_cell/klist.h" // use k-points in Brillouin zone
7+
#include "source_estate/module_charge/charge_mixing.h" // use charge mixing
8+
#include "source_psi/psi.h" // use electronic wave functions
9+
#include "source_hamilt/hamilt.h" // use Hamiltonian
1910

2011
namespace ModuleESolver
2112
{

source/source_esolver/esolver_ks_pw.cpp

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#include "source_base/kernels/dsp/dsp_connector.h"
2323
#endif
2424

25-
#include <chrono>
25+
//#include <chrono>
2626

2727
#include "source_pw/module_pwdft/setup_pot.h" // mohan add 20250929
2828
#include "source_estate/setup_estate_pw.h" // mohan add 20251005
2929
#include "source_io/ctrl_output_pw.h" // mohan add 20250927
30+
#include "source_estate/module_charge/chgmixing.h" // use charge mixing, mohan add 20251006
3031

3132
namespace ModuleESolver
3233
{
@@ -185,50 +186,8 @@ void ESolver_KS_PW<T, Device>::iter_init(UnitCell& ucell, const int istep, const
185186
// Call iter_init() of ESolver_KS
186187
ESolver_KS<T, Device>::iter_init(ucell, istep, iter);
187188

188-
if (iter == 1)
189-
{
190-
this->p_chgmix->init_mixing();
191-
this->p_chgmix->mixing_restart_step = PARAM.inp.scf_nmax + 1;
192-
}
193-
194-
// For mixing restart
195-
if (iter == this->p_chgmix->mixing_restart_step && PARAM.inp.mixing_restart > 0.0)
196-
{
197-
this->p_chgmix->init_mixing();
198-
this->p_chgmix->mixing_restart_count++;
199-
200-
if (PARAM.inp.dft_plus_u)
201-
{
202-
auto* dftu = ModuleDFTU::DFTU::get_instance();
203-
if (dftu->uramping > 0.01 && !dftu->u_converged())
204-
{
205-
this->p_chgmix->mixing_restart_step = PARAM.inp.scf_nmax + 1;
206-
}
207-
if (dftu->uramping > 0.01)
208-
{
209-
bool do_uramping = true;
210-
if (PARAM.inp.sc_mag_switch)
211-
{
212-
spinconstrain::SpinConstrain<std::complex<double>>& sc
213-
= spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
214-
if (!sc.mag_converged()) // skip uramping if mag not converged
215-
{
216-
do_uramping = false;
217-
}
218-
}
219-
if (do_uramping)
220-
{
221-
dftu->uramping_update(); // update U by uramping if uramping > 0.01
222-
std::cout << " U-Ramping! Current U = ";
223-
for (int i = 0; i < dftu->U0.size(); i++)
224-
{
225-
std::cout << dftu->U[i] * ModuleBase::Ry_to_eV << " ";
226-
}
227-
std::cout << " eV " << std::endl;
228-
}
229-
}
230-
}
231-
}
189+
// perform charge mixing
190+
module_charge::chgmixing(iter, this->p_chgmix, PARAM.inp);
232191

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

source/source_estate/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ list(APPEND objects
1717
module_pot/potential_new.cpp
1818
module_pot/potential_types.cpp
1919
module_pot/pot_sep.cpp
20+
module_charge/chgmixing.cpp
2021
module_charge/charge.cpp
2122
module_charge/charge_init.cpp
2223
module_charge/charge_mpi.cpp
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "source_estate/module_charge/chgmixing.h"
2+
#include "source_lcao/module_dftu/dftu.h"
3+
#include "source_lcao/module_deltaspin/spin_constrain.h"
4+
5+
void module_charge::chgmixing(const int iter, // scf iteration number
6+
Charge_Mixing* p_chgmix, // charge mixing class
7+
const Input_para& inp) // input parameters
8+
{
9+
ModuleBase::TITLE("module_charge", "setup_chgmixing");
10+
11+
if (iter == 1)
12+
{
13+
p_chgmix->init_mixing();
14+
p_chgmix->mixing_restart_step = inp.scf_nmax + 1;
15+
}
16+
17+
// For mixing restart
18+
if (iter == p_chgmix->mixing_restart_step && inp.mixing_restart > 0.0)
19+
{
20+
p_chgmix->init_mixing();
21+
p_chgmix->mixing_restart_count++;
22+
23+
if (inp.dft_plus_u)
24+
{
25+
auto* dftu = ModuleDFTU::DFTU::get_instance();
26+
if (dftu->uramping > 0.01 && !dftu->u_converged())
27+
{
28+
p_chgmix->mixing_restart_step = inp.scf_nmax + 1;
29+
}
30+
if (dftu->uramping > 0.01)
31+
{
32+
bool do_uramping = true;
33+
if (inp.sc_mag_switch)
34+
{
35+
spinconstrain::SpinConstrain<std::complex<double>>& sc
36+
= spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
37+
if (!sc.mag_converged()) // skip uramping if mag not converged
38+
{
39+
do_uramping = false;
40+
}
41+
}
42+
if (do_uramping)
43+
{
44+
dftu->uramping_update(); // update U by uramping if uramping > 0.01
45+
std::cout << " U-Ramping! Current U = ";
46+
for (int i = 0; i < dftu->U0.size(); i++)
47+
{
48+
std::cout << dftu->U[i] * ModuleBase::Ry_to_eV << " ";
49+
}
50+
std::cout << " eV " << std::endl;
51+
}
52+
}
53+
}
54+
}
55+
56+
return;
57+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef CHGMIXING_H
2+
#define CHGMIXING_H
3+
4+
#include "source_estate/module_charge/charge_mixing.h"
5+
#include "source_io/module_parameter/input_parameter.h" // use Input_para
6+
7+
namespace module_charge
8+
{
9+
10+
void chgmixing(const int iter,
11+
Charge_Mixing* p_chgmix,
12+
const Input_para& inp); // input parameters
13+
14+
}
15+
16+
17+
#endif

source/source_pw/module_pwdft/setup_pwrho.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef SETUP_PWRHO_H
22
#define SETUP_PWRHO_H
33

4-
#include "source_base/module_device/device.h" // use Device
54
#include "source_cell/unitcell.h" // use UnitCell
65
#include "source_pw/module_pwdft/structure_factor.h" // use Structure_Factor
76
#include "source_basis/module_pw/pw_basis.h" // use PW_Basis

0 commit comments

Comments
 (0)