Skip to content

Commit 9c82378

Browse files
committed
Refactor: format the code
1 parent 5597fd4 commit 9c82378

File tree

11 files changed

+394
-350
lines changed

11 files changed

+394
-350
lines changed
Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,68 @@
1-
#include "src_lcao/local_orbital_charge.h"
2-
#include "module_psi/psi.h"
31
#include "module_base/timer.h"
2+
#include "module_psi/psi.h"
3+
#include "src_lcao/local_orbital_charge.h"
44

55
/// transformation from 2d block density matrix to grid points for one k point
66
void Local_Orbital_Charge::dm2dToGrid(const psi::Psi<double>& dm2d, double** dm_grid)
77
{
8-
ModuleBase::timer::tick("Local_Orbital_Charge","dm_2dTOgrid");
8+
ModuleBase::timer::tick("Local_Orbital_Charge", "dm_2dTOgrid");
99

1010
#ifdef __MPI
1111
// put data from dm_gamma[ik] to sender index
12-
int nNONZERO=0;
13-
for(int i=0; i<this->sender_size; ++i)
12+
int nNONZERO = 0;
13+
for (int i = 0; i < this->sender_size; ++i)
1414
{
15-
const int idx=this->sender_2D_index[i];
16-
const int icol=idx%GlobalV::NLOCAL;
17-
const int irow=(idx-icol)/GlobalV::NLOCAL;
15+
const int idx = this->sender_2D_index[i];
16+
const int icol = idx % GlobalV::NLOCAL;
17+
const int irow = (idx - icol) / GlobalV::NLOCAL;
1818
// sender_buffer[i]=wfc_dm_2d.dm_gamma(ik, irow, icol);
19-
this->sender_buffer[i]=dm2d(icol,irow); // sender_buffer is clomun major,
20-
// so the row and column index should be switched
21-
if(this->sender_buffer[i]!=0) ++nNONZERO;
19+
this->sender_buffer[i] = dm2d(icol, irow); // sender_buffer is clomun major,
20+
// so the row and column index should be switched
21+
if (this->sender_buffer[i] != 0)
22+
++nNONZERO;
2223
}
2324

24-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of non-zero elements in sender_buffer",nNONZERO);
25-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"sender_size",this->sender_size);
26-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"last sender_buffer",this->sender_buffer[this->sender_size-1]);
25+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of non-zero elements in sender_buffer", nNONZERO);
26+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "sender_size", this->sender_size);
27+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "last sender_buffer", this->sender_buffer[this->sender_size - 1]);
2728

2829
// transform data via MPI_Alltoallv
29-
MPI_Alltoallv(this->sender_buffer, this->sender_size_process, this->sender_displacement_process, MPI_DOUBLE,
30-
this->receiver_buffer, this->receiver_size_process, this->receiver_displacement_process, MPI_DOUBLE, this->ParaV->comm_2D);
30+
MPI_Alltoallv(this->sender_buffer,
31+
this->sender_size_process,
32+
this->sender_displacement_process,
33+
MPI_DOUBLE,
34+
this->receiver_buffer,
35+
this->receiver_size_process,
36+
this->receiver_displacement_process,
37+
MPI_DOUBLE,
38+
this->ParaV->comm_2D);
3139

3240
// put data from receiver buffer to dm_grid[ik]
33-
nNONZERO=0;
34-
for(int i=0; i<this->receiver_size; ++i)
41+
nNONZERO = 0;
42+
for (int i = 0; i < this->receiver_size; ++i)
3543
{
36-
const int idx=this->receiver_local_index[i];
37-
const int icol=idx%this->lgd_now;
38-
const int irow=(idx-icol)/this->lgd_now;
39-
dm_grid[irow][icol]=this->receiver_buffer[i];
40-
if(this->receiver_buffer[i]!=0) ++nNONZERO;
44+
const int idx = this->receiver_local_index[i];
45+
const int icol = idx % this->lgd_now;
46+
const int irow = (idx - icol) / this->lgd_now;
47+
dm_grid[irow][icol] = this->receiver_buffer[i];
48+
if (this->receiver_buffer[i] != 0)
49+
++nNONZERO;
4150
}
4251

43-
44-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of non-zero elements in receiver_buffer",nNONZERO);
45-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"receiver_size",this->receiver_size);
46-
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"last receiver_buffer",receiver_buffer[this->receiver_size-1]);
52+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "number of non-zero elements in receiver_buffer", nNONZERO);
53+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "receiver_size", this->receiver_size);
54+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "last receiver_buffer", receiver_buffer[this->receiver_size - 1]);
4755
#else
48-
for(int irow=0;irow<dm2d.get_nbasis();++irow)
49-
{
50-
for(int icol=0;icol<dm2d.get_nbands();++icol)
56+
for (int irow = 0; irow < dm2d.get_nbasis(); ++irow)
5157
{
52-
dm_grid[irow][icol] = dm2d(icol, irow);
58+
for (int icol = 0; icol < dm2d.get_nbands(); ++icol)
59+
{
60+
dm_grid[irow][icol] = dm2d(icol, irow);
61+
}
5362
}
54-
}
5563

5664
#endif
5765

58-
ModuleBase::timer::tick("Local_Orbital_Charge","dm_2dTOgrid");
59-
return;
66+
ModuleBase::timer::tick("Local_Orbital_Charge", "dm_2dTOgrid");
67+
return;
6068
}

source/module_elecstate/elecstate.cpp

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#include "elecstate.h"
2-
#include "src_pw/occupy.h"
2+
33
#include "module_base/global_variable.h"
44
#include "module_base/tool_title.h"
5-
#include "src_pw/global.h"
65
#include "src_parallel/parallel_reduce.h"
6+
#include "src_pw/global.h"
7+
#include "src_pw/occupy.h"
78

89
namespace elecstate
910
{
1011

1112
const double* ElecState::getRho(int spin) const
1213
{
13-
//hamilt::MatrixBlock<double> temp{&(this->charge->rho[spin][0]), 1, this->charge->nrxx}; // this->chr->get_nspin(), this->chr->get_nrxx()};
14+
// hamilt::MatrixBlock<double> temp{&(this->charge->rho[spin][0]), 1, this->charge->nrxx}; //
15+
// this->chr->get_nspin(), this->chr->get_nrxx()};
1416
return &(this->charge->rho[spin][0]);
1517
}
1618

@@ -23,7 +25,7 @@ void ElecState::calculate_weights(void)
2325
// std::cout << " tetrahedron_method = " << use_tetrahedron_method << std::endl;
2426
// std::cout << " fixed_occupations = " << fixed_occupations << std::endl;
2527
double** ekb_tmp = new double*[this->ekb.nr];
26-
for(int i=0; i<this->ekb.nr; ++i)
28+
for (int i = 0; i < this->ekb.nr; ++i)
2729
{
2830
ekb_tmp[i] = &(this->ekb(i, 0));
2931
}
@@ -40,37 +42,37 @@ void ElecState::calculate_weights(void)
4042
if (GlobalV::TWO_EFERMI)
4143
{
4244
Occupy::iweights(GlobalC::kv.nks,
43-
GlobalC::kv.wk,
44-
nbands,
45-
GlobalC::ucell.magnet.get_nelup(),
46-
ekb_tmp,
47-
GlobalC::en.ef_up,
48-
this->wg,
49-
0,
50-
GlobalC::kv.isk);
45+
GlobalC::kv.wk,
46+
nbands,
47+
GlobalC::ucell.magnet.get_nelup(),
48+
ekb_tmp,
49+
GlobalC::en.ef_up,
50+
this->wg,
51+
0,
52+
GlobalC::kv.isk);
5153
Occupy::iweights(GlobalC::kv.nks,
52-
GlobalC::kv.wk,
53-
nbands,
54-
GlobalC::ucell.magnet.get_neldw(),
55-
ekb_tmp,
56-
GlobalC::en.ef_dw,
57-
this->wg,
58-
1,
59-
GlobalC::kv.isk);
54+
GlobalC::kv.wk,
55+
nbands,
56+
GlobalC::ucell.magnet.get_neldw(),
57+
ekb_tmp,
58+
GlobalC::en.ef_dw,
59+
this->wg,
60+
1,
61+
GlobalC::kv.isk);
6062
// ef = ( ef_up + ef_dw ) / 2.0_dp need??? mohan add 2012-04-16
6163
}
6264
else
6365
{
6466
// -1 means don't need to consider spin.
6567
Occupy::iweights(GlobalC::kv.nks,
66-
GlobalC::kv.wk,
67-
nbands,
68-
GlobalC::CHR.nelec,
69-
ekb_tmp,
70-
this->ef,
71-
this->wg,
72-
-1,
73-
GlobalC::kv.isk);
68+
GlobalC::kv.wk,
69+
nbands,
70+
GlobalC::CHR.nelec,
71+
ekb_tmp,
72+
this->ef,
73+
this->wg,
74+
-1,
75+
GlobalC::kv.isk);
7476
}
7577
}
7678
else if (Occupy::use_tetrahedron_method)
@@ -79,7 +81,7 @@ void ElecState::calculate_weights(void)
7981
// if(my_rank == 0)
8082
// {
8183
// tweights(GlobalC::kv.nkstot, nspin, nbands, GlobalC::CHR.nelec, ntetra,tetra, GlobalC::wf.et,
82-
//this->ef, this->wg);
84+
// this->ef, this->wg);
8385
// }
8486
}
8587
else if (Occupy::use_gaussian_broadening)
@@ -188,63 +190,63 @@ void ElecState::calculate_weights(void)
188190

189191
double ElecState::eBandK(const int& ik)
190192
{
191-
ModuleBase::TITLE("ElecStatePW","eBandK");
193+
ModuleBase::TITLE("ElecStatePW", "eBandK");
192194
double eband_k = 0.0;
193-
for (int ibnd = 0;ibnd < this->ekb.nc; ibnd++)
194-
{
195+
for (int ibnd = 0; ibnd < this->ekb.nc; ibnd++)
196+
{
195197
eband_k += this->ekb(ik, ibnd) * this->wg(ik, ibnd);
196198
}
197199
return eband_k;
198200
}
199201

200-
void ElecState::print_band(const int &ik, const int &printe, const int &iter)
202+
void ElecState::print_band(const int& ik, const int& printe, const int& iter)
201203
{
202-
//check the band energy.
204+
// check the band energy.
203205
bool wrong = false;
204206
int nbands = this->ekb.nc;
205-
for(int ib=0; ib<nbands; ++ib)
206-
{
207-
if( abs( this->ekb(ik, ib) ) > 1.0e10)
208-
{
209-
GlobalV::ofs_warning << " ik=" << ik+1 << " ib=" << ib+1 << " " << this->ekb(ik, ib) << " Ry" << std::endl;
210-
wrong = true;
211-
}
212-
}
213-
if(wrong)
207+
for (int ib = 0; ib < nbands; ++ib)
214208
{
215-
ModuleBase::WARNING_QUIT("Threshold_Elec::print_eigenvalue","Eigenvalues are too large!");
209+
if (abs(this->ekb(ik, ib)) > 1.0e10)
210+
{
211+
GlobalV::ofs_warning << " ik=" << ik + 1 << " ib=" << ib + 1 << " " << this->ekb(ik, ib) << " Ry"
212+
<< std::endl;
213+
wrong = true;
214+
}
215+
}
216+
if (wrong)
217+
{
218+
ModuleBase::WARNING_QUIT("Threshold_Elec::print_eigenvalue", "Eigenvalues are too large!");
216219
}
217220

218-
219-
220-
if(GlobalV::MY_RANK==0)
221-
{
222-
//if( GlobalV::DIAGO_TYPE == "selinv" ) xiaohui modify 2013-09-02
223-
if(GlobalV::KS_SOLVER=="selinv") //xiaohui add 2013-09-02
224-
{
225-
GlobalV::ofs_running << " No eigenvalues are available for selected inversion methods." << std::endl;
226-
}
227-
else
228-
{
229-
if( printe>0 && ((iter+1) % printe == 0))
230-
{
231-
// NEW_PART("ENERGY BANDS (Rydberg), (eV)");
232-
GlobalV::ofs_running << std::setprecision(6);
233-
GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << GlobalV::CURRENT_SPIN+1 << " K-point=" << ik+1 << std::endl;
234-
GlobalV::ofs_running << std::setiosflags(ios::showpoint);
235-
for(int ib=0;ib<nbands;ib++)
236-
{
237-
GlobalV::ofs_running << " "<< std::setw(6) << ib+1
238-
<< std::setw(15) << this->ekb(ik, ib) * ModuleBase::Ry_to_eV;
239-
// for the first electron iteration, we don't have the energy
240-
// spectrum, so we can't get the occupations.
241-
GlobalV::ofs_running << std::setw(15) << this->wg(ik,ib);
242-
GlobalV::ofs_running << std::endl;
243-
}
244-
}
245-
}
246-
}
247-
return;
221+
if (GlobalV::MY_RANK == 0)
222+
{
223+
// if( GlobalV::DIAGO_TYPE == "selinv" ) xiaohui modify 2013-09-02
224+
if (GlobalV::KS_SOLVER == "selinv") // xiaohui add 2013-09-02
225+
{
226+
GlobalV::ofs_running << " No eigenvalues are available for selected inversion methods." << std::endl;
227+
}
228+
else
229+
{
230+
if (printe > 0 && ((iter + 1) % printe == 0))
231+
{
232+
// NEW_PART("ENERGY BANDS (Rydberg), (eV)");
233+
GlobalV::ofs_running << std::setprecision(6);
234+
GlobalV::ofs_running << " Energy (eV) & Occupations for spin=" << GlobalV::CURRENT_SPIN + 1
235+
<< " K-point=" << ik + 1 << std::endl;
236+
GlobalV::ofs_running << std::setiosflags(ios::showpoint);
237+
for (int ib = 0; ib < nbands; ib++)
238+
{
239+
GlobalV::ofs_running << " " << std::setw(6) << ib + 1 << std::setw(15)
240+
<< this->ekb(ik, ib) * ModuleBase::Ry_to_eV;
241+
// for the first electron iteration, we don't have the energy
242+
// spectrum, so we can't get the occupations.
243+
GlobalV::ofs_running << std::setw(15) << this->wg(ik, ib);
244+
GlobalV::ofs_running << std::endl;
245+
}
246+
}
247+
}
248+
}
249+
return;
248250
}
249251

250252
} // namespace elecstate

source/module_elecstate/elecstate.h

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,61 @@ namespace elecstate
1010
class ElecState
1111
{
1212
public:
13-
virtual void init(
14-
Charge *chg_in, //pointer for class Charge
15-
int nk_in, //number of k points
16-
int nb_in) //number of bands
13+
virtual void init(Charge *chg_in, // pointer for class Charge
14+
int nk_in, // number of k points
15+
int nb_in) // number of bands
1716
{
18-
this->charge = chg_in;
19-
this->ekb.create(nk_in, nb_in);
20-
this->wg.create(nk_in, nb_in);
17+
this->charge = chg_in;
18+
this->ekb.create(nk_in, nb_in);
19+
this->wg.create(nk_in, nb_in);
2120
}
2221

2322
// return current electronic density rho, as a input for constructing Hamiltonian
24-
virtual const double* getRho(int spin) const;
23+
virtual const double *getRho(int spin) const;
2524

2625
// calculate electronic charge density on grid points or density matrix in real space
2726
// the consequence charge density rho saved into rho_out, preparing for charge mixing.
28-
virtual void psiToRho(const psi::Psi<std::complex<double>> &psi){ return; }
29-
virtual void psiToRho(const psi::Psi<double> &psi){ return; }
30-
//virtual void updateRhoK(const psi::Psi<std::complex<double>> &psi) = 0;
31-
//virtual void updateRhoK(const psi::Psi<double> &psi)=0
27+
virtual void psiToRho(const psi::Psi<std::complex<double>> &psi)
28+
{
29+
return;
30+
}
31+
virtual void psiToRho(const psi::Psi<double> &psi)
32+
{
33+
return;
34+
}
35+
// virtual void updateRhoK(const psi::Psi<std::complex<double>> &psi) = 0;
36+
// virtual void updateRhoK(const psi::Psi<double> &psi)=0
3237

3338
// update charge density for next scf step
3439
// in this function, 1. input rho for construct Hamilt and 2. calculated rho from Psi will mix to 3. new charge
3540
// density rho among these rho,
3641
// 1. input rho would be store to file for restart
3742
// 2. calculated rho should be near with input rho when convergence has achieved
3843
// 3. new rho should be input rho for next scf step.
39-
virtual void getNewRho(){return;}
44+
virtual void getNewRho()
45+
{
46+
return;
47+
}
4048

41-
//calculate wg from ekb
49+
// calculate wg from ekb
4250
void calculate_weights(void);
4351

44-
Charge* charge;
45-
//energy for sum of electrons
52+
Charge *charge;
53+
// energy for sum of electrons
4654
double eband = 0.0;
47-
//Fermi energy
55+
// Fermi energy
4856
double ef = 0.0;
4957

5058
// band energy at each k point, each band.
51-
ModuleBase::matrix ekb;
59+
ModuleBase::matrix ekb;
5260
// occupation weight for each k-point and band
53-
ModuleBase::matrix wg;
61+
ModuleBase::matrix wg;
5462

5563
protected:
5664
// calculate ebands for each k point
57-
double eBandK(const int& ik);
65+
double eBandK(const int &ik);
5866

59-
//print and check for band energy and occupations
67+
// print and check for band energy and occupations
6068
void print_band(const int &ik, const int &printe, const int &iter);
6169
};
6270

0 commit comments

Comments
 (0)