Skip to content

Commit dbf3a06

Browse files
author
wenfei-li
committed
debug : fix bug in dos output
1 parent b6e34e1 commit dbf3a06

File tree

5 files changed

+61
-208
lines changed

5 files changed

+61
-208
lines changed

source/src_io/dos.cpp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ bool Dos::calculate_dos
143143
(
144144
const int &is,
145145
const std::vector<int> &isk,
146-
const std::string &fa, //file address
146+
const std::string &fa, //file address for DOS
147+
const std::string &fa1, //file address for DOS_smearing
147148
const double &de_ev, // delta energy in ev
148149
const double &emax_ev,
149150
const double &emin_ev,// minimal energy in ev.
@@ -157,10 +158,15 @@ bool Dos::calculate_dos
157158
{
158159
ModuleBase::TITLE("Dos","calculae_dos");
159160
std::ofstream ofs;
161+
std::ofstream ofs1;
160162
if(GlobalV::MY_RANK==0)
161163
{
162164
ofs.open(fa.c_str());//make the file clear!!
165+
ofs1.open(fa1.c_str());//make the file clear!!
163166
}
167+
std::vector<double> dos;
168+
std::vector<double> ene;
169+
std::vector<double> dos2; //dos_smearing
164170

165171
#ifdef __MPI
166172
MPI_Barrier(MPI_COMM_WORLD);
@@ -179,6 +185,8 @@ bool Dos::calculate_dos
179185

180186
// mohan fixed bug 2010-1-18
181187
const int npoints = static_cast<int>(std::floor ( ( emax_ev - emin_ev ) / de_ev )) ;
188+
dos.clear();
189+
ene.clear();
182190
if(npoints <= 0)
183191
{
184192
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"npoints",npoints);
@@ -233,12 +241,53 @@ bool Dos::calculate_dos
233241
if(GlobalV::MY_RANK==0)
234242
{
235243
ofs << e_new << " " << count << std::endl;
244+
dos.push_back(count);
245+
ene.push_back(e_new);
236246
}
237247

238248
}
249+
250+
//now use Gaussian smearing to smooth the dos and write to DOS_is_smearing
251+
if(GlobalV::MY_RANK==0)
252+
{
253+
dos2.resize(dos.size()-1);
254+
255+
//double b = INPUT.b_coef;
256+
double b = sqrt(2.0)*GlobalC::en.bcoeff;
257+
for(int i=0;i<dos.size()-1;i++)
258+
{
259+
double Gauss=0.0;
260+
261+
for(int j=0;j<dos.size()-1;j++)
262+
{
263+
double de = ene[j] - ene[i];
264+
double de2 = de * de;
265+
//----------------------------------------------------------
266+
// EXPLAIN : if en
267+
//----------------------------------------------------------
268+
Gauss = exp(-de2/b/b)/sqrt(3.1415926)/b;
269+
dos2[j] += dos[i]*Gauss;
270+
}
271+
}
272+
273+
//----------------------------------------------------------
274+
// EXPLAIN : output DOS_smearing.dat
275+
//----------------------------------------------------------
276+
double sum2=0.0;
277+
for(int i=0;i<dos.size()-1;i++)
278+
{
279+
sum2 += dos2[i];
280+
ofs1 <<std::setw(20)<<ene[i]
281+
<<std::setw(20)<<dos2[i]
282+
<<std::setw(20)<<sum2<<"\n";
283+
}
284+
}
285+
286+
239287
if(GlobalV::MY_RANK==0)
240288
{
241289
ofs.close();
290+
ofs1.close();
242291
}
243292
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"number of bands",nbands);
244293
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"sum up the states", sum);

source/src_io/dos.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace Dos
99
bool calculate_dos(
1010
const int &is,
1111
const std::vector<int> &isk,
12-
const std::string &fn,// file address.
12+
const std::string &fn,// file address for DOS.
13+
const std::string &fn1,// file address for DOS_smearing.
1314
const double &de_ev, // delta energy in ev.
1415
const double &emax_ev,// maximal energy in ev.
1516
const double &emin_ev,// minimal energy in ev.

source/src_io/energy_dos.cpp

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -651,106 +651,18 @@ void energy::perform_dos(void)
651651
{
652652
std::stringstream ss;
653653
ss << GlobalV::global_out_dir << "DOS" << is+1;
654+
std::stringstream ss1;
655+
ss1 << GlobalV::global_out_dir << "DOS" << is+1 << "_smearing.dat";
654656

655657
Dos::calculate_dos(
656658
is,
657659
GlobalC::kv.isk,
658-
ss.str(),
660+
ss.str(),
661+
ss1.str(),
659662
this->dos_edelta_ev,
660663
emax,
661664
emin,
662665
GlobalC::kv.nks, GlobalC::kv.nkstot, GlobalC::kv.wk, GlobalC::wf.wg, GlobalV::NBANDS, GlobalC::wf.ekb );
663-
std::ifstream in(ss.str().c_str());
664-
if(!in)
665-
{
666-
// std::cout<<"\n Can't find file : "<< name << std::endl;
667-
// return 0;
668-
}
669-
670-
//----------------------------------------------------------
671-
// FOUND LOCAL VARIABLES :
672-
// NAME : number(number of DOS points)
673-
// NAME : nk(number of k point used)
674-
// NAME : energy(energy range,from emin_ev to emax_ev)
675-
// NAME : dos(old,count k points in the energy range)
676-
// NAME : dos2(new,count k points in the energy range)
677-
//----------------------------------------------------------
678-
int number=0;
679-
int nk=0;
680-
in >> number;
681-
in >> nk;
682-
double *energy = new double[number];
683-
double *dos = new double[number];
684-
double *dos2 = new double[number];
685-
for(int i=0 ;i<number; i++)
686-
{
687-
energy[i] = 0.0;
688-
dos[i] = 0.0;
689-
dos2[i] =0.0;
690-
}
691-
692-
for(int i=0;i<number;i++)
693-
{
694-
in >> energy[i] >> dos[i];
695-
}
696-
if(!in.eof())
697-
{
698-
//std::cout<<"\n Read Over!"<<std::endl;
699-
}
700-
in.close();
701-
702-
//----------------------------------------------------------
703-
// EXPLAIN : b is an empirical value.
704-
// please DIY b!!
705-
//----------------------------------------------------------
706-
707-
//double b = INPUT.b_coef;
708-
double b = sqrt(2.0)*bcoeff;
709-
for(int i=0;i<number;i++)
710-
{
711-
double Gauss=0.0;
712-
713-
for(int j=0;j<number;j++)
714-
{
715-
double de = energy[j] - energy[i];
716-
double de2 = de * de;
717-
//----------------------------------------------------------
718-
// EXPLAIN : if en
719-
//----------------------------------------------------------
720-
Gauss = exp(-de2/b/b)/sqrt(3.1415926)/b;
721-
dos2[j] += dos[i]*Gauss;
722-
}
723-
}
724-
725-
//----------------------------------------------------------
726-
// EXPLAIN : output DOS2.txt
727-
//----------------------------------------------------------
728-
std::stringstream sss;
729-
sss << GlobalV::global_out_dir << "DOS" << is+1 << "_smearing" << ".dat" ;
730-
std::ofstream out(sss.str().c_str());
731-
double sum2=0.0;
732-
for(int i=0;i<number;i++)
733-
{
734-
sum2 += dos2[i];
735-
// if(dos2[i]<1e-5)
736-
// {
737-
// dos2[i] = 0.00;
738-
// }
739-
out <<std::setw(20)<<energy[i]
740-
<<std::setw(20)<<dos2[i]
741-
<<std::setw(20)<<sum2<<"\n";
742-
}
743-
out.close();
744-
745-
//----------------------------------------------------------
746-
// DELETE
747-
//----------------------------------------------------------
748-
delete[] dos;
749-
delete[] dos2;
750-
delete[] energy;
751-
752-
//std::cout<<" broden spectrum over, success : ) "<<std::endl;
753-
754666
}
755667

756668

source/src_io/energy_dos_pw.cpp

Lines changed: 5 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -148,109 +148,19 @@ void energy::perform_dos_pw(void)
148148
//DOS_ispin contains not smoothed dos
149149
std::stringstream ss;
150150
ss << GlobalV::global_out_dir << "DOS" << is+1;
151+
std::stringstream ss1;
152+
ss1 << GlobalV::global_out_dir << "DOS" << is+1 << "_smearing.dat";
151153

152154
Dos::calculate_dos(
153155
is,
154156
GlobalC::kv.isk,
155-
ss.str(),
157+
ss.str(),
158+
ss1.str(),
156159
this->dos_edelta_ev,
157160
emax,
158161
emin,
159162
GlobalC::kv.nks, GlobalC::kv.nkstot, GlobalC::kv.wk, GlobalC::wf.wg, GlobalV::NBANDS, GlobalC::wf.ekb );
160-
std::ifstream in(ss.str().c_str());
161-
if(!in)
162-
{
163-
//std::cout<<"\n Can't find file : "<< name << std::endl;
164-
//return 0;
165-
}
166-
167-
//----------------------------------------------------------
168-
// FOUND LOCAL VARIABLES :
169-
// NAME : number(number of DOS points)
170-
// NAME : nk(number of k point used)
171-
// NAME : energy(energy range,from emin_ev to emax_ev)
172-
// NAME : dos(old,count k points in the energy range)
173-
// NAME : dos2(new,count k points in the energy range)
174-
//----------------------------------------------------------
175-
int number=0;
176-
int nk=0;
177-
in >> number;
178-
in >> nk;
179-
double *energy = new double[number];
180-
double *dos = new double[number];
181-
double *dos2 = new double[number];
182-
for(int i=0 ;i<number; i++)
183-
{
184-
energy[i] = 0.0;
185-
dos[i] = 0.0;
186-
dos2[i] =0.0;
187-
}
188-
189-
for(int i=0;i<number;i++)
190-
{
191-
in >> energy[i] >> dos[i];
192-
}
193-
if(!in.eof())
194-
{
195-
//std::cout<<"\n Read Over!"<<std::endl;
196-
}
197-
in.close();
198-
199-
//now use Gaussian smearing to smooth the dos and write to DOS_is_smearing
200-
201-
//----------------------------------------------------------
202-
// EXPLAIN : b is an empirical value.
203-
// please DIY b!!
204-
//----------------------------------------------------------
205-
206-
//double b = INPUT.b_coef;
207-
double b = sqrt(2.0)*bcoeff;
208-
for(int i=0;i<number;i++)
209-
{
210-
double Gauss=0.0;
211-
212-
for(int j=0;j<number;j++)
213-
{
214-
double de = energy[j] - energy[i];
215-
double de2 = de * de;
216-
//----------------------------------------------------------
217-
// EXPLAIN : if en
218-
//----------------------------------------------------------
219-
Gauss = exp(-de2/b/b)/sqrt(3.1415926)/b;
220-
dos2[j] += dos[i]*Gauss;
221-
}
222-
}
223-
224-
//----------------------------------------------------------
225-
// EXPLAIN : output DOS2.txt
226-
//----------------------------------------------------------
227-
std::stringstream sss;
228-
sss << GlobalV::global_out_dir << "DOS" << is+1 << "_smearing" << ".dat" ;
229-
std::ofstream out(sss.str().c_str());
230-
double sum2=0.0;
231-
for(int i=0;i<number;i++)
232-
{
233-
sum2 += dos2[i];
234-
// if(dos2[i]<1e-5)
235-
// {
236-
// dos2[i] = 0.00;
237-
// }
238-
out <<std::setw(20)<<energy[i]
239-
<<std::setw(20)<<dos2[i]
240-
<<std::setw(20)<<sum2<<"\n";
241-
}
242-
out.close();
243-
244-
//----------------------------------------------------------
245-
// DELETE
246-
//----------------------------------------------------------
247-
delete[] dos;
248-
delete[] dos2;
249-
delete[] energy;
250-
251-
//std::cout<<" broden spectrum over, success : ) "<<std::endl;
252-
253-
}
163+
}
254164

255165
}//out_dos=1
256166
if(this->out_band) //pengfei 2014-10-13

source/src_io/eximport.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,6 @@ class eximport
109109
const int &nband
110110
);
111111

112-
//==========================================================
113-
// MEMBER FUNCTION : calculate_dos
114-
// DO : output DOS in nscf case.
115-
// RETURN : = TRUE (seccess)
116-
// = FALSE (failure)
117-
//==========================================================
118-
bool calculate_dos
119-
(
120-
const std::string &fa, // file address.
121-
const double de_ev, // delta energy in ev
122-
const double emax_ev, // maximal energy in ev.
123-
const double emin_ev, // minimal energy in ev.
124-
const int nks, // number of k points included.
125-
const int nbands, // number of nbands included.
126-
const ModuleBase::matrix &et// store energy for each k point
127-
// and each band
128-
);
129-
130-
131112
#ifdef __MPI
132113
//==========================================================
133114
// MEMBER FUNCTION : out_charge_mpi

0 commit comments

Comments
 (0)