11#include " surchem.h"
22
3+ void add_comp_chg (const UnitCell &cell, PW_Basis &pwb, double q, double l, double center, complex <double > *NG, int dim)
4+ {
5+ // x dim
6+ if (dim == 0 )
7+ {
8+ double L = cell.a1 [0 ];
9+ q /= (cell.a2 [1 ] * cell.a3 [2 ] * l);
10+ ModuleBase::GlobalFunc::ZEROS (NG, pwb.ngmc );
11+ for (int ig = pwb.gstart ; ig < pwb.ngmc ; ig++)
12+ {
13+ double GX = pwb.get_G_cartesian_projection (ig, 0 );
14+ double GY = pwb.get_G_cartesian_projection (ig, 1 );
15+ double GZ = pwb.get_G_cartesian_projection (ig, 2 );
16+ GX = GX * 2 * ModuleBase::PI;
17+ if (GY == 0 && GZ == 0 && GX != 0 )
18+ {
19+ NG[ig] = exp (ModuleBase::NEG_IMAG_UNIT * GX * center) * complex <double >(2.0 * q * sin (GX * l / 2.0 ) / (L * GX), 0.0 );
20+ }
21+ }
22+ NG[0 ] = complex <double >(q * l / L, 0.0 );
23+ }
24+ // y dim
25+ else if (dim == 1 )
26+ {
27+ double L = cell.a2 [1 ];
28+ q /= (cell.a1 [0 ] * cell.a3 [2 ] * l);
29+ ModuleBase::GlobalFunc::ZEROS (NG, pwb.ngmc );
30+ for (int ig = pwb.gstart ; ig < pwb.ngmc ; ig++)
31+ {
32+ double GX = pwb.get_G_cartesian_projection (ig, 0 );
33+ double GY = pwb.get_G_cartesian_projection (ig, 1 );
34+ double GZ = pwb.get_G_cartesian_projection (ig, 2 );
35+ GY = GY * 2 * ModuleBase::PI;
36+ if (GX == 0 && GZ == 0 && GY != 0 )
37+ {
38+ NG[ig] = exp (ModuleBase::NEG_IMAG_UNIT * GY * center) * complex <double >(2.0 * q * sin (GY * l / 2.0 ) / (L * GY), 0.0 );
39+ }
40+ }
41+ NG[0 ] = complex <double >(q * l / L, 0.0 );
42+ }
43+ // z dim
44+ else if (dim == 2 )
45+ {
46+ double L = cell.a3 [2 ];
47+ q /= (cell.a1 [0 ] * cell.a2 [1 ] * l);
48+ ModuleBase::GlobalFunc::ZEROS (NG, pwb.ngmc );
49+ for (int ig = pwb.gstart ; ig < pwb.ngmc ; ig++)
50+ {
51+ double GX = pwb.get_G_cartesian_projection (ig, 0 );
52+ double GY = pwb.get_G_cartesian_projection (ig, 1 );
53+ double GZ = pwb.get_G_cartesian_projection (ig, 2 );
54+ GZ = GZ * 2 * ModuleBase::PI;
55+ if (GX == 0 && GY == 0 && GZ != 0 )
56+ {
57+ NG[ig] = exp (ModuleBase::NEG_IMAG_UNIT * GZ * center) * complex <double >(2.0 * q * sin (GZ * l / 2.0 ) / (L * GZ), 0.0 );
58+ }
59+ }
60+ NG[0 ] = complex <double >(q * l / L, 0.0 );
61+ }
62+ }
63+
64+ void test_sum (const UnitCell &cell, PW_Basis &pwb, double * NR)
65+ {
66+ double sum = 0.0 ;
67+ for (int i=0 ; i < pwb.nrxx ; i++)
68+ {
69+ sum += NR[i];
70+ }
71+ cout << sum * cell.omega / pwb.nrxx << endl;
72+ }
73+
374void surchem::cal_totn (const UnitCell &cell, PW_Basis &pwb,
475 const complex <double > *Porter_g, complex <double > *N,
576 complex <double > *TOTN) {
77+ /*
78+ // test compensating charge
79+ complex<double> *comp_reci = new complex<double>[pwb.ngmc];
80+ double *comp_real = new double[pwb.nrxx];
81+ add_comp_chg(cell, pwb, comp_q, comp_l, comp_center, comp_reci, comp_dim);
82+ GlobalC::UFFT.ToRealSpace(comp_reci, comp_real);
83+ for (int ir = 0; ir < pwb.nz; ir++)
84+ {
85+ cout << comp_real[ir] << endl;
86+ }
87+ cout << "sum" << endl;
88+ test_sum(cell, pwb, comp_real);
89+ delete[] comp_real;
90+ delete[] comp_reci;
91+ */
692
793 // vloc to N
894 complex <double > *vloc_g = new complex <double >[pwb.ngmc ];
@@ -23,11 +109,13 @@ void surchem::cal_totn(const UnitCell &cell, PW_Basis &pwb,
23109
24110 if (GlobalV::MY_RANK == 0 ) {
25111 N[0 ] = Porter_g[0 ];
112+ // cout << "Ng[0]" << N[0] << endl;
26113 }
27114
28115 for (int ig = 0 ; ig < pwb.ngmc ; ig++) {
29116 TOTN[ig] = N[ig] - Porter_g[ig];
30117 }
118+
31119 delete[] vloc_g;
32120 return ;
33121}
0 commit comments