1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2008 The Regents of the University of California
4 //
5 // This file is part of Qbox
6 //
7 // Qbox is distributed under the terms of the GNU General Public License
8 // as published by the Free Software Foundation, either version 2 of
9 // the License, or (at your option) any later version.
10 // See the file COPYING in the root directory of this distribution
11 // or <http://www.gnu.org/licenses/>.
12 //
13 ////////////////////////////////////////////////////////////////////////////////
14 //
15 // testChargeDensity.cpp
16 //
17 ////////////////////////////////////////////////////////////////////////////////
18
19 #include "MPIdata.h"
20 #include "Context.h"
21 #include "Wavefunction.h"
22 #include "ChargeDensity.h"
23 #include "SlaterDet.h"
24 #include "FourierTransform.h"
25 #include "Timer.h"
26
27 #include <iostream>
28 #include <iomanip>
29 #include <cassert>
30 using namespace std;
31
32 #include <mpi.h>
33
main(int argc,char ** argv)34 int main(int argc, char **argv)
35 {
36 MPI_Init(&argc,&argv);
37 {
38 // use:
39 // testChargeDensity a0 a1 a2 b0 b1 b2 c0 c1 c2 ecut nel nkp nkspin
40 // ngb nstb nkpb nspb
41 if ( argc != 18 )
42 {
43 cout << "use: testChargeDensity a0 a1 a2 b0 b1 b2 c0 c1 c2 "
44 << "ecut nel nkp nspin ngb nstb nkpb nspb"
45 << endl;
46 return 1;
47 }
48 D3vector a(atof(argv[1]),atof(argv[2]),atof(argv[3]));
49 D3vector b(atof(argv[4]),atof(argv[5]),atof(argv[6]));
50 D3vector c(atof(argv[7]),atof(argv[8]),atof(argv[9]));
51 UnitCell cell(a,b,c);
52 cout << " volume: " << cell.volume() << endl;
53 double ecut = atof(argv[10]);
54 int nel = atoi(argv[11]);
55 int nkp = atoi(argv[12]);
56 int nspin = atoi(argv[13]);
57 int ngb = atoi(argv[14]);
58 int nstb = atoi(argv[15]);
59 int nkpb = atoi(argv[16]);
60 int nspb = atoi(argv[17]);
61
62 MPIdata::set(ngb,nstb,nkpb,nspb);
63 cout << MPIdata::rank() << ": ngb=" << ngb << " nstb=" << nstb
64 << " nkpb=" << nkpb << " nspb=" << nspb << endl;
65 cout << MPIdata::rank() << ": igb=" << MPIdata::igb()
66 << " istb=" << MPIdata::istb()
67 << " ikpb=" << MPIdata::ikpb()
68 << " ispb=" << MPIdata::ispb() << endl;
69
70 Context sd_ctxt(MPIdata::sd_comm(),ngb,nstb);
71 Wavefunction wf(sd_ctxt);
72
73 Timer tm;
74
75 tm.reset(); tm.start();
76 wf.resize(cell,cell,ecut);
77 tm.stop();
78 cout << " wf.resize: CPU/Real: "
79 << tm.cpu() << " / " << tm.real() << endl;
80
81 tm.reset(); tm.start();
82 wf.set_nel(nel);
83 tm.stop();
84 cout << " wf.set_nel: CPU/Real: "
85 << tm.cpu() << " / " << tm.real() << endl;
86
87 tm.reset(); tm.start();
88 wf.set_nspin(nspin);
89 tm.stop();
90 cout << " wf.set_nspin: CPU/Real: "
91 << tm.cpu() << " / " << tm.real() << endl;
92
93 for ( int ikp = 1; ikp < nkp; ikp++ )
94 {
95 wf.add_kpoint(D3vector((0.5*(ikp))/(nkp-1),0,0),1.0);
96 }
97
98 wf.info(cout,"wavefunction");
99
100 tm.reset();
101 tm.start();
102 wf.randomize(0.1);
103 tm.stop();
104 cout << " wf.randomize: CPU/Real: "
105 << tm.cpu() << " / " << tm.real() << endl;
106
107 tm.reset();
108 tm.start();
109 wf.gram();
110 cout << " wf.gram: CPU/Real: "
111 << tm.cpu() << " / " << tm.real() << endl;
112
113 wf.update_occ(0.0);
114
115 // compute charge density in real space
116 Timer tmrho;
117 tmrho.reset();
118 tmrho.start();
119 cout << " ChargeDensity::ctor..." << endl;
120 ChargeDensity cd(wf);
121 tmrho.stop();
122 cout << " ChargeDensity::ctor: CPU/Real: "
123 << tmrho.cpu() << " / " << tmrho.real() << endl;
124
125 tmrho.reset();
126 tmrho.start();
127 cout << " ChargeDensity::update_density..." << endl;
128 cd.update_density();
129 tmrho.stop();
130 cout << " ChargeDensity::update_density: CPU/Real: "
131 << tmrho.cpu() << " / " << tmrho.real() << endl;
132
133 cout << cd;
134
135 tmrho.reset();
136 tmrho.start();
137 cout << " ChargeDensity::update_rhor..." << endl;
138 cd.update_rhor();
139 tmrho.stop();
140 cout << " ChargeDensity::update_rhor: CPU/Real: "
141 << tmrho.cpu() << " / " << tmrho.real() << endl;
142
143 cout << cd;
144 }
145 MPI_Finalize();
146 }
147