Skip to content

Commit 6013183

Browse files
committed
update the DOS name, update the output frequency of DOS for LCAO, not for PW yet
1 parent 0c46162 commit 6013183

File tree

9 files changed

+77
-72
lines changed

9 files changed

+77
-72
lines changed

source/module_esolver/esolver.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,20 +272,23 @@ ESolver* init_esolver(const Input_para& inp, UnitCell& ucell)
272272
// force and stress is not needed currently,
273273
// they will be supported after the analytical gradient
274274
// of LR-TDDFT is implemented.
275-
// after_all_runners() is for output, it is not needed here.
276275
std::cout << " PREPARING FOR EXCITED STATES." << std::endl;
277276
// initialize the 2nd ESolver_LR at the temporary pointer
278277
ModuleESolver::ESolver* p_esolver_lr = nullptr;
279-
if (PARAM.globalv.gamma_only_local)
280-
p_esolver_lr = new LR::ESolver_LR<double, double>(
281-
std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<double, double>*>(p_esolver)),
282-
inp,
283-
ucell);
278+
if (PARAM.globalv.gamma_only_local)
279+
{
280+
p_esolver_lr = new LR::ESolver_LR<double, double>(
281+
std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<double, double>*>(p_esolver)),
282+
inp,
283+
ucell);
284+
}
284285
else
285-
p_esolver_lr = new LR::ESolver_LR<std::complex<double>, double>(
286-
std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<std::complex<double>, double>*>(p_esolver)),
287-
inp,
288-
ucell);
286+
{
287+
p_esolver_lr = new LR::ESolver_LR<std::complex<double>, double>(
288+
std::move(*dynamic_cast<ModuleESolver::ESolver_KS_LCAO<std::complex<double>, double>*>(p_esolver)),
289+
inp,
290+
ucell);
291+
}
289292
// clean the 1st ESolver_KS and swap the pointer
290293
ModuleESolver::clean_esolver(p_esolver, false); // do not call Cblacs_exit, remain it for the 2nd ESolver
291294
return p_esolver_lr;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "esolver_ks_lcao.h"
22

3-
#include "module_io/write_dos_lcao.h" // write DOS and PDOS
43
#include "module_io/write_proj_band_lcao.h" // projcted band structure
54

65
#include "module_base/formatter.h"
@@ -385,12 +384,6 @@ void ESolver_KS_LCAO<TK, TR>::cal_stress(UnitCell& ucell, ModuleBase::matrix& st
385384
ModuleBase::timer::tick("ESolver_KS_LCAO", "cal_stress");
386385
}
387386

388-
//------------------------------------------------------------------------------
389-
//! the 8th function of ESolver_KS_LCAO: after_all_runners
390-
//! mohan add 2024-05-11
391-
//------------------------------------------------------------------------------
392-
393-
394387
template <typename TK, typename TR>
395388
void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
396389
{
@@ -401,30 +394,12 @@ void ESolver_KS_LCAO<TK, TR>::after_all_runners(UnitCell& ucell)
401394

402395
const int nspin0 = (PARAM.inp.nspin == 2) ? 2 : 1;
403396

404-
// 4) write projected band structure
397+
// 1) write projected band structure
405398
if (PARAM.inp.out_proj_band)
406399
{
407400
ModuleIO::write_proj_band_lcao(this->psi, this->pv, this->pelec, this->kv, ucell, this->p_hamilt);
408401
}
409402

410-
// 5) print out density of states (DOS)
411-
if (PARAM.inp.out_dos)
412-
{
413-
ModuleIO::write_dos_lcao(this->psi,
414-
this->p_hamilt,
415-
this->pv,
416-
ucell,
417-
*(this->pelec->klist),
418-
PARAM.inp.nbands,
419-
this->pelec->eferm,
420-
this->pelec->ekb,
421-
this->pelec->wg,
422-
PARAM.inp.dos_edelta_ev,
423-
PARAM.inp.dos_scale,
424-
PARAM.inp.dos_sigma,
425-
GlobalV::ofs_running);
426-
}
427-
428403
// out ldos
429404
if (PARAM.inp.out_ldos[0])
430405
{

source/module_io/cal_dos.cpp

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ void ModuleIO::prepare_dos(std::ofstream& ofs_running,
9393
}
9494

9595
bool ModuleIO::cal_dos(const int& is, // index for spin
96-
const std::string& file_dos, // file address for DOS
97-
const std::string& file_smear, // file address for DOS_smearing
96+
const std::string& fn, // file name for DOS
9897
const double& de_ev, // delta energy in ev
9998
const double& emax_ev, // maximal energy in eV
10099
const double& emin_ev, // minimal energy in ev.
@@ -115,15 +114,16 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
115114

116115
if (GlobalV::MY_RANK == 0)
117116
{
118-
ofs_dos.open(file_dos.c_str());
119-
ofs_smear.open(file_smear.c_str());
117+
ofs_dos.open(fn.c_str());
120118
}
121119

122120
std::vector<double> dos;
123121
std::vector<double> ene;
122+
std::vector<double> sum_elec;
124123
std::vector<double> dos_smear; // dos_smearing
125124
dos.clear();
126125
ene.clear();
126+
sum_elec.clear();
127127
dos_smear.clear();
128128

129129
#ifdef __MPI
@@ -154,25 +154,22 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
154154
ofs_dos << npoints << " # number of points" << std::endl;
155155
ofs_dos << "#" << std::setw(14) << "energy"
156156
<< std::setw(15) << "elec_states"
157+
<< std::setw(15) << "sum_states"
158+
<< std::setw(15) << "states_smear"
157159
<< std::setw(15) << "sum_states" << std::endl;
158-
159-
ofs_smear << npoints << " # number of points" << std::endl;
160-
ofs_smear << "#" << std::setw(14) << "energy"
161-
<< std::setw(15) << "states_smear"
162-
<< std::setw(15) << "sum_states" << std::endl;
163160
}
164161

165162
std::vector<double> e_mod(npoints, 0.0);
166163

167164
double sum = 0.0;
168-
double e_new = emin_ev;
165+
double curr_energy = emin_ev;
169166
double e_old = 0.0;
170167

171-
while (e_new < emax_ev)
168+
while (curr_energy < emax_ev)
172169
{
173170
double nstates = 0.0;
174-
e_old = e_new;
175-
e_new += de_ev;
171+
e_old = curr_energy;
172+
curr_energy += de_ev;
176173

177174
// nks is the number of k-points in the 'pool'
178175
for (int ik = 0; ik < nks; ik++)
@@ -183,9 +180,9 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
183180
// band index
184181
for (int ib = 0; ib < nbands; ib++)
185182
{
186-
// compare et and e_old(e_new) in ev unit.
183+
// compare et and e_old(curr_energy) in ev unit.
187184
if (ekb(ik, ib) * ModuleBase::Ry_to_eV >= e_old
188-
&& ekb(ik, ib) * ModuleBase::Ry_to_eV < e_new)
185+
&& ekb(ik, ib) * ModuleBase::Ry_to_eV < curr_energy)
189186
{
190187
nstates += wk[ik] * nkstot;
191188
}
@@ -202,12 +199,9 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
202199
sum += nstates;
203200
if (GlobalV::MY_RANK == 0)
204201
{
205-
ofs_dos << std::setw(15) << e_new
206-
<< std::setw(15) << nstates
207-
<< std::setw(15) << sum
208-
<< std::endl;
209202
dos.push_back(nstates);
210-
ene.push_back(e_new);
203+
ene.push_back(curr_energy);
204+
sum_elec.push_back(sum);
211205
}
212206
}
213207

@@ -236,7 +230,9 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
236230
{
237231
sum2 += dos_smear[i] * de_ev;
238232

239-
ofs_smear << std::setw(15) << ene[i]
233+
ofs_dos << std::setw(15) << ene[i]
234+
<< std::setw(15) << dos[i]
235+
<< std::setw(15) << sum_elec[i]
240236
<< std::setw(15) << dos_smear[i]
241237
<< std::setw(15) << sum2 << std::endl;
242238
}
@@ -245,7 +241,6 @@ bool ModuleIO::cal_dos(const int& is, // index for spin
245241
if (GlobalV::MY_RANK == 0)
246242
{
247243
ofs_dos.close();
248-
ofs_smear.close();
249244
}
250245

251246
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "Number of bands", nbands);

source/module_io/cal_dos.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace ModuleIO
2020

2121
bool cal_dos(const int &is,
2222
const std::string &fn,// file address for DOS.
23-
const std::string &fn1,// file address for DOS_smearing.
2423
const double &de_ev, // delta energy in ev.
2524
const double &emax_ev,// maximal energy in ev.
2625
const double &emin_ev,// minimal energy in ev.

source/module_io/ctrl_output_lcao.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" // use hamilt::HamiltLCAO<TK, TR>
66
#include "module_hamilt_general/hamilt.h" // use Hamilt<T>
77

8+
// functions
9+
#include "module_io/write_dos_lcao.h" // use ModuleIO::write_dos_lcao()
810
#include "module_io/write_dmr.h" // use ModuleIO::write_dmr()
911
#include "module_io/io_dmk.h" // use ModuleIO::write_dmk()
1012
#include "module_io/write_HS.h" // use ModuleIO::write_hsk()
@@ -65,6 +67,28 @@ void ctrl_output_lcao(UnitCell& ucell,
6567
const int nspin = PARAM.inp.nspin;
6668
const std::string global_out_dir = PARAM.globalv.global_out_dir;
6769

70+
//------------------------------------------------------------------
71+
// print out density of states (DOS)
72+
//------------------------------------------------------------------
73+
if (PARAM.inp.out_dos)
74+
{
75+
ModuleIO::write_dos_lcao(psi,
76+
p_hamilt,
77+
pv,
78+
ucell,
79+
kv,
80+
PARAM.inp.nbands,
81+
pelec->eferm,
82+
pelec->ekb,
83+
pelec->wg,
84+
PARAM.inp.dos_edelta_ev,
85+
PARAM.inp.dos_scale,
86+
PARAM.inp.dos_sigma,
87+
out_app_flag,
88+
istep,
89+
GlobalV::ofs_running);
90+
}
91+
6892
//------------------------------------------------------------------
6993
//! 1) Output density matrix DM(R)
7094
//------------------------------------------------------------------

source/module_io/test/cal_dos_test.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ class DosTest : public ::testing::Test
2828

2929
TEST_F(DosTest,Dos)
3030
{
31-
//is,fa,fa1,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
31+
//is,fa,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
3232
DosPrepare dosp = DosPrepare(0,"DOS1.dat","DOS1_smear.dat",0.005,18,-6,0.07,36,36,8);
3333
dosp.set_isk();
3434
dosp.read_wk();
3535
dosp.read_istate_info();
3636
EXPECT_EQ(dosp.is,0);
3737
ModuleIO::cal_dos(dosp.is,
3838
dosp.fa,
39-
dosp.fa1,
4039
dosp.de_ev,
4140
dosp.emax_ev,
4241
dosp.emin_ev,
@@ -76,7 +75,7 @@ TEST_F(DosTest,Dos)
7675

7776
TEST_F(DosTest,DosW1)
7877
{
79-
//is,fa,fa1,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
78+
//is,fa,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
8079
DosPrepare dosp = DosPrepare(0,"DOS1.dat","DOS1_smear.dat",-0.005,18,-6,0.07,36,36,8);
8180
dosp.set_isk();
8281
dosp.read_wk();
@@ -86,7 +85,6 @@ TEST_F(DosTest,DosW1)
8685
GlobalV::ofs_warning.open("warning1.log");
8786
EXPECT_NO_THROW(ModuleIO::cal_dos(dosp.is,
8887
dosp.fa,
89-
dosp.fa1,
9088
dosp.de_ev,
9189
dosp.emax_ev,
9290
dosp.emin_ev,
@@ -118,7 +116,7 @@ TEST_F(DosTest,DosW1)
118116

119117
TEST_F(DosTest,DosW2)
120118
{
121-
//is,fa,fa1,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
119+
//is,fa,de_ev,emax_ev,emin_ev,bcoeff,nks,nkstot,nbands
122120
DosPrepare dosp = DosPrepare(0,"DOS1.dat","DOS1_smear.dat",0.005,-6,18,0.07,36,36,8);
123121
dosp.set_isk();
124122
dosp.read_wk();
@@ -127,7 +125,6 @@ TEST_F(DosTest,DosW2)
127125
GlobalV::ofs_warning.open("warning2.log");
128126
EXPECT_NO_THROW(ModuleIO::cal_dos(dosp.is,
129127
dosp.fa,
130-
dosp.fa1,
131128
dosp.de_ev,
132129
dosp.emax_ev,
133130
dosp.emin_ev,

source/module_io/write_dos_lcao.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ void write_dos_lcao(
2222
const double& dos_edelta_ev,
2323
const double& dos_scale,
2424
const double& bcoeff,
25+
const bool out_app_flag,
26+
const int istep,
2527
std::ofstream &ofs_running)
2628
{
2729
ModuleBase::TITLE("ModuleIO", "write_dos_lcao");
@@ -45,13 +47,18 @@ void write_dos_lcao(
4547
for (int is = 0; is < nspin0; ++is)
4648
{
4749
std::stringstream ss;
48-
ss << PARAM.globalv.global_out_dir << "dos" << is + 1 << ".txt";
49-
std::stringstream ss1;
50-
ss1 << PARAM.globalv.global_out_dir << "dos" << is + 1 << "_smear.txt";
50+
51+
ss << PARAM.globalv.global_out_dir << "doss" << is + 1;
52+
53+
if(istep>=0)
54+
{
55+
ss << "g" << istep+1;
56+
}
57+
58+
ss << "_nao.txt";
5159

5260
ModuleIO::cal_dos(is,
5361
ss.str(),
54-
ss1.str(),
5562
dos_edelta_ev,
5663
emax,
5764
emin,
@@ -111,6 +118,8 @@ template void write_dos_lcao(
111118
const double& dos_edelta_ev,
112119
const double& dos_scale,
113120
const double& bcoeff,
121+
const bool out_app_flag,
122+
const int istep,
114123
std::ofstream &ofs_running);
115124

116125

@@ -127,6 +136,8 @@ template void write_dos_lcao(
127136
const double& dos_edelta_ev,
128137
const double& dos_scale,
129138
const double& bcoeff,
139+
const bool out_app_flag,
140+
const int istep,
130141
std::ofstream &ofs_running);
131142

132143
}

source/module_io/write_dos_lcao.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ namespace ModuleIO
2828
const double& dos_edelta_ev, // Delta energy
2929
const double& dos_scale,
3030
const double& bcoeff,
31+
const bool out_app_flag,
32+
const int istep,
3133
std::ofstream &ofs_running);
3234
}
3335
#endif

source/module_io/write_dos_pw.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ void ModuleIO::write_dos_pw(
3737
{
3838
// DOS_ispin contains not smoothed dos
3939
std::stringstream ss;
40-
ss << PARAM.globalv.global_out_dir << "DOS" << is + 1 << ".dat";
40+
ss << PARAM.globalv.global_out_dir << "doss" << is + 1 << "_pw.txt";
4141

4242
std::stringstream ss1;
43-
ss1 << PARAM.globalv.global_out_dir << "DOS" << is + 1 << "_smear.dat";
43+
ss1 << PARAM.globalv.global_out_dir << "doss" << is + 1 << "s_pw.txt";
4444

4545
ModuleBase::GlobalFunc::OUT(ofs_running, "DOS file", ss.str());
4646

4747
ModuleIO::cal_dos(is,
4848
ss.str(),
49-
ss1.str(),
5049
dos_edelta_ev,
5150
emax,
5251
emin,

0 commit comments

Comments
 (0)