Skip to content

Commit e7c1dc1

Browse files
authored
Merge pull request #83 from PeizeLin/develop
3 updates:1. ptr->vector ; 2. elpa openmp; 3. output real space wavefunction
2 parents 35b96e6 + f3f9d2d commit e7c1dc1

File tree

18 files changed

+286
-129
lines changed

18 files changed

+286
-129
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ write_rho_dipole.o\
252252
write_HS.o\
253253
write_HS_R.o\
254254
write_dm.o\
255+
write_wfc_realspace.o\
255256
potential_libxc.o \
256257
potential_libxc_meta.o \
257258
efield.o \

source/input.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ void Input::Default(void)
253253

254254
out_potential = 0;
255255
out_wf = 0;
256+
out_wf_r = 0;
256257
out_dos = 0;
257258
out_band = 0;
258259
out_hs = 0;
@@ -1060,6 +1061,10 @@ bool Input::Read(const std::string &fn)
10601061
else if (strcmp("out_wf", word) == 0)
10611062
{
10621063
read_value(ifs, out_wf);
1064+
}
1065+
else if (strcmp("out_wf_r", word) == 0)
1066+
{
1067+
read_value(ifs, out_wf_r);
10631068
}
10641069
//mohan add 20090909
10651070
else if (strcmp("out_dos", word) == 0)
@@ -2227,6 +2232,7 @@ void Input::Bcast()
22272232

22282233
Parallel_Common::bcast_int(out_potential);
22292234
Parallel_Common::bcast_int( out_wf );
2235+
Parallel_Common::bcast_int( out_wf_r );
22302236
Parallel_Common::bcast_int( out_dos );
22312237
Parallel_Common::bcast_int( out_band );
22322238
Parallel_Common::bcast_int( out_hs );

source/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ class Input
222222
int out_dm; // output density matrix.
223223
int out_potential; // yes or no
224224
int out_wf; // 0: no; 1: txt; 2: dat
225+
int out_wf_r; // 0: no; 1: yes
225226
int out_dos; // dos calculation. mohan add 20090909
226227
int out_band; // band calculation pengfei 2014-10-13
227228
int out_hs; // output H matrix and S matrix in local basis.

source/input_conv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ void Input_Conv::Convert(void)
591591
GlobalC::CHR.nelec = INPUT.nelec;
592592
GlobalC::pot.out_potential = INPUT.out_potential;
593593
GlobalC::wf.out_wf = INPUT.out_wf;
594+
GlobalC::wf.out_wf_r = INPUT.out_wf_r;
594595
GlobalC::en.out_dos = INPUT.out_dos;
595596
GlobalC::en.out_band = INPUT.out_band;
596597
#ifdef __LCAO

source/src_io/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ add_library(
3939
write_rho.cpp
4040
write_rho_cube.cpp
4141
write_rho_dipole.cpp
42+
write_wfc_realspace.cpp
4243
)

source/src_io/dos.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ void Dos::calculate_Mulliken(const std::string &fa)
141141
bool Dos::calculate_dos
142142
(
143143
const int &is,
144-
const int *isk,
144+
const std::vector<int> &isk,
145145
const std::string &fa, //file address
146146
const double &de_ev, // delta energy in ev
147147
const double &emax_ev,
148148
const double &emin_ev,// minimal energy in ev.
149149
const int &nks,//number of k points
150150
const int &nkstot,
151-
const double *wk,//weight of k points
151+
const std::vector<double> &wk,//weight of k points
152152
const ModuleBase::matrix &wg,//weight of (kpoint,bands)
153153
const int &nbands,// number of bands
154154
double** ekb//store energy for each k point and each band

source/src_io/dos.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace Dos
66
{
77
bool calculate_dos(
88
const int &is,
9-
const int *isk,
9+
const std::vector<int> &isk,
1010
const std::string &fn,// file address.
1111
const double &de_ev, // delta energy in ev.
1212
const double &emax_ev,// maximal energy in ev.
1313
const double &emin_ev,// minimal energy in ev.
1414
const int &nks,//number of k points
1515
const int &nkstot,
16-
const double *wk,//weight of k points
16+
const std::vector<double> &wk,//weight of k points
1717
const ModuleBase::matrix &wg,//weight of (kpoint,bands)
1818
const int &nbands,// number of bands
1919
double **ekb);//store energy for each k point and each band

source/src_io/write_input.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void Input::Print(const std::string &fn)const
5959
ModuleBase::GlobalFunc::OUTP(ofs,"out_charge",out_charge,">0 output charge density for selected electron steps");
6060
ModuleBase::GlobalFunc::OUTP(ofs,"out_potential",out_potential,"output realspace potential");
6161
ModuleBase::GlobalFunc::OUTP(ofs,"out_wf",out_wf,"output wave functions");
62+
ModuleBase::GlobalFunc::OUTP(ofs,"out_wf_r",out_wf_r,"output wave functions in realspace");
6263
ModuleBase::GlobalFunc::OUTP(ofs,"out_dos",out_dos,"output energy and dos");
6364
ModuleBase::GlobalFunc::OUTP(ofs,"out_band",out_band,"output energy and band structure");
6465
ModuleBase::GlobalFunc::OUTP(ofs,"restart_save",restart_save,"print to disk every step for restart");
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-11-21
4+
//======================
5+
6+
#include "write_wfc_realspace.h"
7+
#include "src_pw/global.h"
8+
#include "module_base/tool_title.h"
9+
#include <fstream>
10+
#include <stdexcept>
11+
#include <cstdlib>
12+
13+
namespace Write_Wfc_Realspace
14+
{
15+
// write ||wfc_r|| for all k-points and all bands
16+
// Input: wfc_g[ik](ib,ig)
17+
// loop order is for(z){for(y){for(x)}}
18+
void write_wfc_realspace_1(const ModuleBase::ComplexMatrix*const wfc_g, const std::string &folder_name)
19+
{
20+
ModuleBase::TITLE("Write_Wfc_Realspace", "write_wfc_realspace_1");
21+
22+
const string outdir = GlobalV::global_out_dir + folder_name + "/";
23+
const std::string command0 = "test -d " + outdir + " || mkdir " + outdir;
24+
if(GlobalV::MY_RANK==0)
25+
system( command0.c_str() );
26+
27+
#ifdef __MPI
28+
std::vector<MPI_Request> mpi_requests;
29+
#endif
30+
for(int ik=0; ik<GlobalC::kv.nks; ++ik)
31+
{
32+
const int ik_out = (GlobalV::NSPIN!=2)
33+
? ik + GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL]
34+
: ik - GlobalC::kv.nks/2*GlobalC::kv.isk[ik] + GlobalC::kv.nkstot/2*GlobalC::kv.isk[ik] + GlobalC::Pkpoints.startk_pool[GlobalV::MY_POOL];
35+
for(int ib=0; ib<wfc_g[ik].nr; ++ib)
36+
{
37+
const std::vector<std::complex<double>> wfc_r = cal_wfc_r(wfc_g[ik], ik, ib);
38+
39+
std::vector<double> wfc_r2(wfc_r.size());
40+
for(int ir=0; ir<wfc_r2.size(); ++ir)
41+
wfc_r2[ir] = std::norm(wfc_r[ir]);
42+
43+
const std::string file_name = outdir + "wfc_realspace_"
44+
+ ModuleBase::GlobalFunc::TO_STRING(ik_out)
45+
+ "_" + ModuleBase::GlobalFunc::TO_STRING(ib);
46+
#ifdef __MPI
47+
mpi_requests.push_back({});
48+
write_charge_realspace_1(wfc_r2, file_name, mpi_requests.back());
49+
#else
50+
write_charge_realspace_1(wfc_r2, file_name);
51+
#endif
52+
}
53+
}
54+
#ifdef __MPI
55+
MPI_Waitall( mpi_requests.size(), mpi_requests.data(), MPI_STATUSES_IGNORE );
56+
#endif
57+
}
58+
// processes output pipeline:
59+
//
60+
// t0 t1 t2 t3 t4 t5 t6 t7
61+
// -------------------------------->
62+
// rank0 k0 k1 k2 k3 k4 k5
63+
// \ \ \ \ \ \
64+
// rank1 k0 k1 k2 k3 k4 k5
65+
// \ \ \ \ \ \
66+
// rank2 k0 k1 k2 k3 k4 k5
67+
68+
69+
70+
// Input: wfc_g(ib,ig)
71+
// Output: wfc_r[ir]
72+
std::vector<std::complex<double>> cal_wfc_r(const ModuleBase::ComplexMatrix &wfc_g, const int ik, const int ib)
73+
{
74+
ModuleBase::GlobalFunc::ZEROS(GlobalC::UFFT.porter, GlobalC::pw.nrxx);
75+
std::vector<std::complex<double>> wfc_r(GlobalC::pw.nrxx);
76+
for(int ig=0; ig<GlobalC::kv.ngk[ik]; ++ig)
77+
GlobalC::UFFT.porter[ GlobalC::pw.ig2fftw[GlobalC::wf.igk(ik,ig)] ] = wfc_g(ib,ig);
78+
GlobalC::pw.FFT_wfc.FFT3D(GlobalC::UFFT.porter,1);
79+
for(int ir=0; ir<GlobalC::pw.nrxx; ++ir)
80+
wfc_r[ir] = GlobalC::UFFT.porter[ir];
81+
return wfc_r;
82+
}
83+
84+
85+
86+
// Input: chg_r[ir]
87+
#ifdef __MPI
88+
void write_charge_realspace_1(const std::vector<double> &chg_r, const std::string &file_name, MPI_Request &mpi_request)
89+
#else
90+
void write_charge_realspace_1(const std::vector<double> &chg_r, const std::string &file_name)
91+
#endif
92+
{
93+
std::ofstream ofs;
94+
95+
#ifdef __MPI
96+
constexpr int mpi_tag=100;
97+
if(GlobalV::RANK_IN_POOL==0)
98+
{
99+
#endif
100+
ofs.open(file_name);
101+
102+
ofs<<"calculated by ABACUS"<<std::endl;
103+
ofs<<GlobalC::ucell.lat0_angstrom<<std::endl;
104+
ofs<<GlobalC::ucell.latvec.e11<<" "<<GlobalC::ucell.latvec.e12<<" "<<GlobalC::ucell.latvec.e13<<std::endl
105+
<<GlobalC::ucell.latvec.e21<<" "<<GlobalC::ucell.latvec.e22<<" "<<GlobalC::ucell.latvec.e23<<std::endl
106+
<<GlobalC::ucell.latvec.e31<<" "<<GlobalC::ucell.latvec.e32<<" "<<GlobalC::ucell.latvec.e33<<std::endl;
107+
108+
for(int it=0; it<GlobalC::ucell.ntype; ++it)
109+
ofs<<GlobalC::ucell.atoms[it].label<<"\t";
110+
ofs<<std::endl;
111+
for(int it=0; it<GlobalC::ucell.ntype; ++it)
112+
ofs<<GlobalC::ucell.atoms[it].na<<"\t";
113+
ofs<<std::endl;
114+
115+
ofs<<"Direct"<<std::endl;
116+
for(int it=0; it<GlobalC::ucell.ntype; ++it)
117+
for(int ia=0; ia<GlobalC::ucell.atoms[it].na; ++ia)
118+
ofs<<GlobalC::ucell.atoms[it].taud[ia].x<<" "<<GlobalC::ucell.atoms[it].taud[ia].y<<" "<<GlobalC::ucell.atoms[it].taud[ia].z<<std::endl;
119+
ofs<<std::endl;
120+
121+
ofs<<GlobalC::pw.ncx<<" "<<GlobalC::pw.ncy<<" "<<GlobalC::pw.ncz<<std::endl;
122+
#ifdef __MPI
123+
}
124+
else
125+
{
126+
char recv_tmp;
127+
MPI_Recv( &recv_tmp, 1, MPI_CHAR, GlobalV::RANK_IN_POOL-1, mpi_tag, POOL_WORLD, MPI_STATUS_IGNORE);
128+
129+
ofs.open(file_name, ofstream::app);
130+
}
131+
#endif
132+
133+
assert(GlobalC::pw.ncx * GlobalC::pw.ncy * GlobalC::pw.nczp == chg_r.size());
134+
for(int iz=0; iz<GlobalC::pw.nczp; ++iz)
135+
{
136+
for(int iy=0; iy<GlobalC::pw.ncy; ++iy)
137+
{
138+
for(int ix=0; ix<GlobalC::pw.ncx; ++ix)
139+
{
140+
const int ir = (ix*GlobalC::pw.ncy+iy)*GlobalC::pw.nczp+iz;
141+
ofs<<chg_r[ir]<<" ";
142+
}
143+
ofs<<std::endl;
144+
}
145+
}
146+
ofs.close();
147+
148+
#ifdef __MPI
149+
if(GlobalV::RANK_IN_POOL < GlobalV::NPROC_IN_POOL-1)
150+
{
151+
const char send_tmp = 'c';
152+
MPI_Isend( &send_tmp, 1, MPI_CHAR, GlobalV::RANK_IN_POOL+1, mpi_tag, POOL_WORLD, &mpi_request );
153+
}
154+
else
155+
{
156+
mpi_request = MPI_REQUEST_NULL;
157+
}
158+
#endif
159+
}
160+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//======================
2+
// AUTHOR : Peize Lin
3+
// DATE : 2021-11-21
4+
//======================
5+
6+
#ifndef WRITE_WFC_REALSPACE_H
7+
#define WRITE_WFC_REALSPACE_H
8+
9+
#include "module_base/complexmatrix.h"
10+
#include "module_base/vector3.h"
11+
#include <vector>
12+
#include <complex>
13+
#include <string>
14+
15+
#ifdef __MPI
16+
#include <mpi.h>
17+
#endif
18+
19+
namespace Write_Wfc_Realspace
20+
{
21+
// write ||wfc_r|| for all k-points and all bands
22+
// Input: wfc_g[ik](ib,ig)
23+
// loop order is for(z){for(y){for(x)}}
24+
void write_wfc_realspace_1(const ModuleBase::ComplexMatrix*const wfc_g, const std::string &folder_name);
25+
26+
// Input: wfc_g(ib,ig)
27+
// Output: wfc_r[ir]
28+
std::vector<std::complex<double>> cal_wfc_r(const ModuleBase::ComplexMatrix &wfc_g, const int ik, const int ib);
29+
30+
// Input: chg_r[ir]
31+
#ifdef __MPI
32+
void write_charge_realspace_1(const std::vector<double> &chg_r, const std::string &file_name, MPI_Request &mpi_request);
33+
#else
34+
void write_charge_realspace_1(const std::vector<double> &chg_r, const std::string &file_name);
35+
#endif
36+
}
37+
38+
#endif

0 commit comments

Comments
 (0)