Skip to content

Commit 836d9c5

Browse files
authored
Merge pull request #608 from deepmodeling/ABACUS_2.2.0_beta
merge linpz new code to develop branch
2 parents d4a1b5f + 1eadfb3 commit 836d9c5

40 files changed

+1473
-145
lines changed

source/Makefile.Objects

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ read_rho.o\
249249
read_atoms.o\
250250
read_cell_pseudopots.o\
251251
read_dm.o\
252+
read_txt_tools.o\
253+
read_txt_stru.o\
254+
read_txt_input_value.o\
255+
read_txt_input_item.o\
256+
read_txt_input_list.o\
257+
read_txt_input_process.o\
258+
read_txt_input_process_global.o\
259+
read_txt_input-general.o\
260+
read_txt_input-pw.o\
261+
read_txt_input-spectrum.o\
252262
write_pot.o\
253263
write_rho.o\
254264
write_rho_cube.o\

source/module_base/timer.cpp

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include<vector>
99

1010
#ifdef __MPI
11-
#include "mpi.h"
11+
#include <mpi.h>
12+
#endif
13+
14+
#ifdef _OPENMP
15+
#include <omp.h>
1216
#endif
1317

1418
namespace ModuleBase
@@ -67,7 +71,11 @@ void timer::tick(const std::string &class_name,const std::string &name)
6771
if (disabled)
6872
return;
6973

70-
Timer_One &timer_one = timer_pool[class_name][name];
74+
#ifdef _OPENMP
75+
if(!omp_get_thread_num())
76+
#endif
77+
{
78+
Timer_One &timer_one = timer_pool[class_name][name];
7179

7280
//----------------------------------------------------------
7381
// CALL MEMBER FUNCTION :
@@ -79,32 +87,33 @@ void timer::tick(const std::string &class_name,const std::string &name)
7987
// if start_flag == false, means it's the end of this counting,
8088
// so we add the time during this two 'time point' to the clock time storage.
8189
//----------------------------------------------------------
82-
if(timer_one.start_flag)
83-
{
90+
if(timer_one.start_flag)
91+
{
8492
#ifdef __MPI
85-
timer_one.cpu_start = MPI_Wtime();
93+
timer_one.cpu_start = MPI_Wtime();
8694
#else
87-
timer_one.cpu_start = cpu_time();
95+
timer_one.cpu_start = cpu_time();
8896
#endif
89-
++timer_one.calls;
90-
timer_one.start_flag = false;
91-
}
92-
else
93-
{
97+
++timer_one.calls;
98+
timer_one.start_flag = false;
99+
}
100+
else
101+
{
94102
#ifdef __MPI
95-
timer_one.cpu_second += MPI_Wtime() - timer_one.cpu_start;
103+
timer_one.cpu_second += MPI_Wtime() - timer_one.cpu_start;
96104
#else
97-
// if(class_name=="electrons"&&name=="c_bands")
98-
// {
99-
// cout<<"call times"<<timer_one.calls<<endl;
100-
// cout<<"electrons c_bands cost time:"<<endl;
101-
// cout<<cpu_time()<<"-"<<timer_one.cpu_start<<endl;
102-
// }
103-
104-
timer_one.cpu_second += (cpu_time() - timer_one.cpu_start);
105+
// if(class_name=="electrons"&&name=="c_bands")
106+
// {
107+
// cout<<"call times"<<timer_one.calls<<endl;
108+
// cout<<"electrons c_bands cost time:"<<endl;
109+
// cout<<cpu_time()<<"-"<<timer_one.cpu_start<<endl;
110+
// }
111+
112+
timer_one.cpu_second += (cpu_time() - timer_one.cpu_start);
105113
#endif
106-
timer_one.start_flag = true;
107-
}
114+
timer_one.start_flag = true;
115+
}
116+
} // end if(!omp_get_thread_num())
108117
}
109118

110119
long double timer::print_until_now(void)

source/src_external/src_test/print_tmp.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#pragma once
1+
#ifndef PRINT_TMP_H
2+
#define PRINT_TMP_H
23

34
#include<iostream>
45
#include<fstream>
@@ -42,4 +43,6 @@ void print_matrixess(const std::map<size_t,std::map<size_t,std::map<Abfs::Vector
4243
ofs<<c1.first<<"\t"<<c2.first<<"\t"<<c3.first<<std::endl;
4344
c3.second->print(ofs, 1E-10)<<std::endl;
4445
}
45-
}
46+
}
47+
48+
#endif

source/src_external/src_test/src_global/element_basis_index-test.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// DATE : 2016-06-02
44
//==========================================================
55

6-
#pragma once
7-
6+
#ifndef ELEMENT_BASIS_INDEX_TEST_H
7+
#define ELEMENT_BASIS_INDEX_TEST_H
88

99
#include <iostream>
1010
using namespace std;
@@ -41,4 +41,6 @@ static std::ostream & operator << (std::ostream & os, const ModuleBase::Element_
4141
}
4242
}
4343
return os;
44-
}
44+
}
45+
46+
#endif

source/src_io/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ add_library(
2323
print_info.cpp
2424
read_dm.cpp
2525
read_rho.cpp
26+
read_txt_tools.cpp
27+
read_txt_input_value.cpp
28+
read_txt_input_item.cpp
29+
read_txt_input_list.cpp
30+
read_txt_input_process.cpp
31+
read_txt_input_process_global.cpp
32+
read_txt_input-general.cpp
33+
read_txt_input-pw.cpp
34+
read_txt_input-spectrum.cpp
35+
read_txt_stru.cpp
2636
restart.cpp
2737
rwstream.cpp
2838
to_wannier90.cpp

source/src_io/dos.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,16 @@ void Dos::nscf_band(
347347
}
348348
MPI_Barrier(MPI_COMM_WORLD);
349349

350+
std::vector<double> klength;
351+
klength.resize(nks);
352+
klength[0] = 0.0;
350353
for(int ik=0; ik<nks; ik++)
351354
{
355+
if (ik>0)
356+
{
357+
auto delta=GlobalC::kv.kvec_c[ik]-GlobalC::kv.kvec_c[ik-1];
358+
klength[ik] = klength[ik-1] + delta.norm();
359+
}
352360
if ( GlobalV::MY_POOL == GlobalC::Pkpoints.whichpool[ik] )
353361
{
354362
const int ik_now = ik - GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL];
@@ -360,6 +368,7 @@ void Dos::nscf_band(
360368
ofs << std::setprecision(8);
361369
//start from 1
362370
ofs << ik+1;
371+
ofs << " " << klength[ik] << " ";
363372
for(int ib = 0; ib < nband; ib++)
364373
{
365374
ofs << " " << (ekb[ik_now+is*nks][ib]-fermie) * ModuleBase::Ry_to_eV;

source/src_io/numerical_basis.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,18 @@ void Numerical_Basis::output_overlap( const ModuleBase::ComplexMatrix *psi)
9595
GlobalV::ofs_running << " --------------------------------------------------------" << std::endl;
9696

9797
// search for all k-points.
98-
overlap_Q[ik] = this->cal_overlap_Q(ik, npw, psi[ik], derivative_order);
98+
overlap_Q[ik] = this->cal_overlap_Q(ik, npw, psi[ik], static_cast<double>(derivative_order));
9999
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"cal_overlap_Q");
100100

101101
// (2) generate Sq matrix if necessary.
102102
if (winput::out_spillage == 2)
103103
{
104-
overlap_Sq[ik] = this->cal_overlap_Sq( ik, npw, derivative_order );
104+
overlap_Sq[ik] = this->cal_overlap_Sq( ik, npw, static_cast<double>(derivative_order) );
105105
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running,"cal_overlap_Sq");
106106
}
107107
}
108108

109-
const ModuleBase::matrix overlap_V = this->cal_overlap_V(psi, derivative_order); // Peize Lin add 2020.04.23
109+
const ModuleBase::matrix overlap_V = this->cal_overlap_V(psi, static_cast<double>(derivative_order)); // Peize Lin add 2020.04.23
110110

111111
#ifdef __MPI
112112
for (int ik=0; ik<GlobalC::kv.nks; ik++)
@@ -139,7 +139,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(
139139
const int &ik,
140140
const int &np,
141141
const ModuleBase::ComplexMatrix &psi,
142-
const int derivative_order) const
142+
const double derivative_order) const
143143
{
144144
ModuleBase::TITLE("Numerical_Basis","cal_overlap_Q");
145145
ModuleBase::timer::tick("Numerical_Basis","cal_overlap_Q");
@@ -156,6 +156,8 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(
156156
for (int ig=0; ig<np; ig++)
157157
gk[ig] = GlobalC::wf.get_1qvec_cartesian(ik, ig);
158158

159+
const std::vector<double> gpow = Numerical_Basis::cal_gpow(gk, derivative_order);
160+
159161
const ModuleBase::realArray flq = this->cal_flq(ik, gk);
160162

161163
const ModuleBase::matrix ylm = Numerical_Basis::cal_ylm(gk);
@@ -195,7 +197,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(
195197
for (int ig=0; ig<np; ig++)
196198
{
197199
// const std::complex<double> local_tmp = lphase * sk[ig] * ylm(lm, ig) * flq[ig];
198-
const std::complex<double> local_tmp = lphase * sk[ig] * ylm(lm, ig) * flq(L,ie,ig) * pow(gk[ig].norm2(),derivative_order); // Peize Lin add for dpsi 2020.04.23
200+
const std::complex<double> local_tmp = lphase * sk[ig] * ylm(lm, ig) * flq(L,ie,ig) * gpow[ig]; // Peize Lin add for dpsi 2020.04.23
199201
overlap_tmp += conj( local_tmp ) * psi(ib, ig); // psi is bloch orbitals
200202
}
201203
overlap_Q(ib, this->mu_index[T](I, L, N, m), ie) = overlap_tmp;
@@ -214,7 +216,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Q(
214216
ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Sq(
215217
const int &ik,
216218
const int &np,
217-
const int derivative_order) const
219+
const double derivative_order) const
218220
{
219221
ModuleBase::TITLE("Numerical_Basis","cal_overlap_Sq");
220222
ModuleBase::timer::tick("Numerical_Basis","cal_overlap_Sq");
@@ -232,6 +234,8 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Sq(
232234
for (int ig=0; ig<np; ig++)
233235
gk[ig] = GlobalC::wf.get_1qvec_cartesian(ik, ig);
234236

237+
const std::vector<double> gpow = Numerical_Basis::cal_gpow(gk, derivative_order);
238+
235239
const ModuleBase::realArray flq = this->cal_flq(ik, gk);
236240

237241
const ModuleBase::matrix ylm = Numerical_Basis::cal_ylm(gk);
@@ -281,7 +285,7 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Sq(
281285

282286
std::vector<std::complex<double>> about_ig1(np, std::complex<double>(0.0,0.0));
283287
for (int ig=0; ig<np; ig++)
284-
about_ig1[ig] = conj( lphase1 * sk1[ig] * ylm(lm1, ig) ) * pow(gk[ig].norm2(),derivative_order); // Peize Lin add for dpsi 2020.04.23
288+
about_ig1[ig] = conj( lphase1 * sk1[ig] * ylm(lm1, ig) ) * gpow[ig]; // Peize Lin add for dpsi 2020.04.23
285289

286290
for (int m2=0; m2<2*l2+1; m2++) // 2.6
287291
{
@@ -330,18 +334,20 @@ ModuleBase::ComplexArray Numerical_Basis::cal_overlap_Sq(
330334
// Peize Lin add for dpsi 2020.04.23
331335
ModuleBase::matrix Numerical_Basis::cal_overlap_V(
332336
const ModuleBase::ComplexMatrix *psi,
333-
const int derivative_order)
337+
const double derivative_order)
334338
{
335339
ModuleBase::matrix overlap_V(GlobalC::kv.nks, GlobalV::NBANDS);
336340
for(int ik=0; ik<GlobalC::kv.nks; ++ik)
337341
{
342+
std::vector<ModuleBase::Vector3<double>> gk(GlobalC::kv.ngk[ik]);
343+
for (int ig=0; ig<gk.size(); ig++)
344+
gk[ig] = GlobalC::wf.get_1qvec_cartesian(ik, ig);
345+
346+
const std::vector<double> gpow = Numerical_Basis::cal_gpow(gk, derivative_order);
347+
338348
for(int ib=0; ib<GlobalV::NBANDS; ++ib)
339-
{
340349
for(int ig=0; ig<GlobalC::kv.ngk[ik]; ++ig)
341-
{
342-
overlap_V(ik,ib)+= norm(psi[ik](ib,ig)) * pow(GlobalC::wf.get_1qvec_cartesian(ik,ig).norm2(),derivative_order);
343-
}
344-
}
350+
overlap_V(ik,ib)+= norm(psi[ik](ib,ig)) * gpow[ig];
345351
}
346352
return overlap_V;
347353
}
@@ -368,6 +374,25 @@ ModuleBase::matrix Numerical_Basis::cal_ylm(const std::vector<ModuleBase::Vector
368374
return ylm;
369375
}
370376

377+
std::vector<double> Numerical_Basis::cal_gpow (const std::vector<ModuleBase::Vector3<double>> &gk, const double derivative_order)
378+
{
379+
constexpr double thr = 1E-12;
380+
std::vector<double> gpow(gk.size(), 0.0);
381+
for (int ig=0; ig<gpow.size(); ++ig)
382+
{
383+
if (derivative_order>=0)
384+
{
385+
gpow[ig] = std::pow(gk[ig].norm2(),derivative_order);
386+
}
387+
else
388+
{
389+
if (gk[ig].norm2() >= thr)
390+
gpow[ig] = std::pow(gk[ig].norm2(),derivative_order);
391+
}
392+
}
393+
return gpow;
394+
}
395+
371396
std::vector<ModuleBase::IntArray> Numerical_Basis::init_mu_index(void)
372397
{
373398
GlobalV::ofs_running << " Initialize the mu index" << std::endl;

source/src_io/numerical_basis.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ class Numerical_Basis
3434

3535
ModuleBase::ComplexArray cal_overlap_Q(
3636
const int &ik, const int &np, const ModuleBase::ComplexMatrix &psi,
37-
const int derivative_order ) const;
37+
const double derivative_order ) const;
3838

3939
ModuleBase::ComplexArray cal_overlap_Sq(
4040
const int &ik,
4141
const int &np,
42-
const int derivative_order ) const;
42+
const double derivative_order ) const;
4343

44-
static ModuleBase::matrix cal_overlap_V(const ModuleBase::ComplexMatrix *psi, const int derivative_order);
44+
static ModuleBase::matrix cal_overlap_V(const ModuleBase::ComplexMatrix *psi, const double derivative_order);
4545

4646
ModuleBase::realArray cal_flq(const int ik, const std::vector<ModuleBase::Vector3<double>> &gk) const;
4747

4848
static ModuleBase::matrix cal_ylm(const std::vector<ModuleBase::Vector3<double>> &gk);
4949

50+
static std::vector<double> cal_gpow (const std::vector<ModuleBase::Vector3<double>> &gk, const double derivative_order);
51+
5052
static void output_info(
5153
std::ofstream &ofs,
5254
const Bessel_Basis &bessel_basis);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//=======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-12-13
4+
//=======================
5+
6+
#include "read_txt_input_list.h"
7+
8+
#include "src_io/read_txt_tools.h"
9+
#include <stdexcept>
10+
11+
// for convert
12+
#include "module_base/global_variable.h"
13+
#include "src_pw/global.h"
14+
15+
namespace Read_Txt_Input
16+
{
17+
void Input_List::set_items_general()
18+
{
19+
this->output_labels.push_back("Parameters (1.General)");
20+
21+
{
22+
Input_Item item("nspin");
23+
item.default_1(1);
24+
item.annotation = "1: single spin; 2: up and down spin; 4: noncollinear spin";
25+
item.check_transform = [](Input_Item &self)
26+
{
27+
if(!Read_Txt_Tools::in_set(self.values[0].geti(), {1,2,4}))
28+
throw std::invalid_argument("nspin must be 1,2,4");
29+
};
30+
item.convert = [](const Input_Item &self)
31+
{
32+
GlobalV::NSPIN = self.values[0].geti();
33+
};
34+
this->add_item(item);
35+
}
36+
37+
{
38+
Input_Item item("ntype");
39+
item.default_1(0);
40+
item.annotation = "atom species number";
41+
item.check_transform = [](Input_Item &self)
42+
{
43+
if(self.values[0].geti()<=0)
44+
throw std::invalid_argument("ntype must > 0");
45+
};
46+
item.convert = [](const Input_Item &self)
47+
{
48+
GlobalC::ucell.ntype = self.values[0].geti();
49+
};
50+
this->add_item(item);
51+
}
52+
53+
{
54+
Input_Item item("symmetry");
55+
item.default_1(false);
56+
item.annotation = "turn symmetry on or off";
57+
item.convert = [](const Input_Item &self)
58+
{
59+
ModuleSymmetry::Symmetry::symm_flag = self.values[0].getb();
60+
};
61+
this->add_item(item);
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)