Skip to content

Commit ed1beb8

Browse files
committed
Add function of adding compensating charge
1 parent 9063986 commit ed1beb8

File tree

10 files changed

+135
-4
lines changed

10 files changed

+135
-4
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ OBJS_ESOLVER=esolver.o\
240240

241241
OBJS_SURCHEM=H_correction_pw.o\
242242
cal_epsilon.o\
243+
surchem.o\
243244
cal_pseudo.o\
244245
cal_totn.o\
245246
cal_vcav.o\
@@ -415,7 +416,6 @@ pzt2s.o\
415416
pdtrsm.o\
416417
pzhtrsm.o\
417418

418-
419419
PDIAG_MR_0=dcopy.o\
420420
dlae2.o\
421421
dlaebz.o\

source/input.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ void Input::Default(void)
420420
sigma_k = 0.6;
421421
nc_k = 0.00037;
422422

423+
comp_q = 0.0;
424+
comp_l = 1.0;
425+
comp_center = 0.0;
426+
comp_dim = 2;
427+
423428
return;
424429
}
425430

@@ -1495,6 +1500,22 @@ bool Input::Read(const std::string &fn)
14951500
{
14961501
read_value(ifs, nc_k);
14971502
}
1503+
else if (strcmp("comp_q", word) == 0)
1504+
{
1505+
read_value(ifs, comp_q);
1506+
}
1507+
else if (strcmp("comp_l", word) == 0)
1508+
{
1509+
read_value(ifs, comp_l);
1510+
}
1511+
else if (strcmp("comp_center", word) == 0)
1512+
{
1513+
read_value(ifs, comp_center);
1514+
}
1515+
else if (strcmp("comp_dim", word) == 0)
1516+
{
1517+
read_value(ifs, comp_dim);
1518+
}
14981519
//----------------------------------------------------------------------------------
14991520
else
15001521
{

source/input.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ class Input
399399
double tau;
400400
double sigma_k;
401401
double nc_k;
402+
// gauss charge
403+
double comp_q;
404+
double comp_l;
405+
double comp_center;
406+
int comp_dim;
402407

403408
//==========================================================
404409
// variables for test only

source/input_conv.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "src_ions/ions_move_basic.h"
1515
#include "src_pw/global.h"
1616
#include "src_pw/occupy.h"
17+
#include "module_surchem/surchem.h"
1718
#ifdef __EXX
1819
#include "src_ri/exx_abfs-jle.h"
1920
#endif
@@ -501,6 +502,11 @@ void Input_Conv::Convert(void)
501502
GlobalV::tau = INPUT.tau;
502503
GlobalV::sigma_k = INPUT.sigma_k;
503504
GlobalV::nc_k = INPUT.nc_k;
505+
506+
GlobalC::solvent_model.comp_q = INPUT.comp_q;
507+
GlobalC::solvent_model.comp_l = INPUT.comp_l;
508+
GlobalC::solvent_model.comp_center = INPUT.comp_center;
509+
GlobalC::solvent_model.comp_dim = INPUT.comp_dim;
504510
ModuleBase::timer::tick("Input_Conv", "Convert");
505511
return;
506512
}

source/module_surchem/cal_totn.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,94 @@
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+
374
void 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
}

source/module_surchem/cal_vcav.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void surchem::createcavity(const UnitCell &ucell, PW_Basis &pwb, const complex<d
136136
// cavitation energy
137137
//-------------------------------------------------------------
138138

139-
double Ael = cal_Acav(ucell, pwb);
139+
// double Ael = cal_Acav(ucell, pwb);
140140

141141
// packs the real array into a complex one
142142
// to G space

source/module_surchem/cal_vel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ModuleBase::matrix surchem::cal_vel(const UnitCell &cell,
106106
}
107107

108108
// calculate Ael
109-
double Ael = cal_Ael(cell, pwb);
109+
// double Ael = cal_Ael(cell, pwb);
110110

111111
// the 2nd item of tmp_Vel
112112
eps_pot(PS_TOTN_real, Sol_phi, pwb, epsilon, epspot);

source/module_surchem/surchem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class surchem
2424
ModuleBase::matrix Vel;
2525
double qs;
2626

27+
// compensating charge params
28+
double comp_q;
29+
double comp_l;
30+
double comp_center;
31+
int comp_dim;
32+
// get atom info
2733
atom_in GetAtom;
2834

2935
void allocate(const int &nrxx, const int &nspin);

source/src_io/write_input.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ void Input::Print(const std::string &fn) const
330330
ModuleBase::GlobalFunc::OUTP(ofs, "tau", tau, "the effective surface tension parameter");
331331
ModuleBase::GlobalFunc::OUTP(ofs, "sigma_k", sigma_k, " the width of the diffuse cavity");
332332
ModuleBase::GlobalFunc::OUTP(ofs, "nc_k", nc_k, " the cut-off charge density");
333+
334+
ModuleBase::GlobalFunc::OUTP(ofs, "comp_q", comp_q, " total charge of compensating charge");
335+
ModuleBase::GlobalFunc::OUTP(ofs, "comp_l", comp_l, " total length of compensating charge");
336+
ModuleBase::GlobalFunc::OUTP(ofs, "comp_center", comp_center, " center of compensating charge on dim");
337+
ModuleBase::GlobalFunc::OUTP(ofs, "comp_dim", comp_dim, " dimension of compensating charge(x, y or z)");
333338
ofs.close();
334339
return;
335340
}

source/src_pw/potential.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ ModuleBase::matrix Potential::v_of_rho(const double *const *const rho_in, const
360360
v += GlobalC::solvent_model.v_correction(GlobalC::ucell, GlobalC::pw, GlobalV::NSPIN, rho_in);
361361

362362
// test energy outside
363-
cout << endl << "energy Outside: " << endl;
363+
cout << "energy Outside: " << endl;
364364
GlobalC::solvent_model.cal_Ael(GlobalC::ucell, GlobalC::pw);
365365
GlobalC::solvent_model.cal_Acav(GlobalC::ucell, GlobalC::pw);
366366
}

0 commit comments

Comments
 (0)