forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol_force.cpp
More file actions
177 lines (146 loc) · 6.79 KB
/
sol_force.cpp
File metadata and controls
177 lines (146 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "surchem.h"
#include "../module_base/timer.h"
void force_cor_one(const UnitCell &cell, ModulePW::PW_Basis* rho_basis , ModuleBase::matrix& forcesol)
{
//delta phi multiply by the derivative of nuclear charge density with respect to the positions
std::complex<double> *N = new std::complex<double>[rho_basis->npw];
std::complex<double> *vloc_at = new std::complex<double>[rho_basis->npw];
std::complex<double> *delta_phi_g = new complex<double>[rho_basis->npw];
//ModuleBase::GlobalFunc::ZEROS(delta_phi_g, rho_basis->npw);
rho_basis->real2recip(GlobalC::solvent_model.delta_phi, delta_phi_g);
//GlobalC::UFFT.ToReciSpace(GlobalC::solvent_model.delta_phi, delta_phi_g,rho_basis);
double Ael=0;double Ael1 = 0;
//ModuleBase::GlobalFunc::ZEROS(vg, ngmc);
int iat = 0;
for (int it = 0;it < cell.ntype;it++)
{
for (int ia = 0;ia < cell.atoms[it].na ; ia++)
{
for (int ig = 0; ig < rho_basis->npw; ig++)
{
complex<double> phase = exp( ModuleBase::NEG_IMAG_UNIT *ModuleBase::TWO_PI * ( rho_basis->gcar[ig] * cell.atoms[it].tau[ia]));
//vloc for each atom
vloc_at[ig] = GlobalC::ppcell.vloc(it, rho_basis->ig2igg[ig]) * phase;
if(rho_basis->ig_gge0 == ig)
{
N[ig] = GlobalC::ucell.atoms[it].zv / GlobalC::ucell.omega;
}
else
{
const double fac = ModuleBase::e2 * ModuleBase::FOUR_PI /
(cell.tpiba2 * rho_basis->gg[ig]);
N[ig] = -vloc_at[ig] / fac;
}
//force for each atom
forcesol(iat, 0) += rho_basis->gcar[ig][0] * imag(conj(delta_phi_g[ig]) * N[ig]);
forcesol(iat, 1) += rho_basis->gcar[ig][1] * imag(conj(delta_phi_g[ig]) * N[ig]);
forcesol(iat, 2) += rho_basis->gcar[ig][2] * imag(conj(delta_phi_g[ig]) * N[ig]);
}
forcesol(iat, 0) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
forcesol(iat, 1) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
forcesol(iat, 2) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
//unit Ry/Bohr
forcesol(iat, 0) *= 2 ;
forcesol(iat, 1) *= 2 ;
forcesol(iat, 2) *= 2 ;
//cout<<"Force1"<<iat<<":"<<" "<<forcesol(iat, 0)<<" "<<forcesol(iat, 1)<<" "<<forcesol(iat, 2)<<endl;
++iat;
}
}
delete[] vloc_at;
delete[] N;
delete[] delta_phi_g;
}
void force_cor_two(const UnitCell &cell, ModulePW::PW_Basis* rho_basis , ModuleBase::matrix& forcesol)
{
complex<double> *n_pseudo = new complex<double>[rho_basis->npw];
ModuleBase::GlobalFunc::ZEROS(n_pseudo,rho_basis->npw);
//GlobalC::solvent_model.gauss_charge(cell, pwb, n_pseudo);
double *Vcav_sum = new double[rho_basis->nrxx];
ModuleBase::GlobalFunc::ZEROS(Vcav_sum, rho_basis->nrxx);
std::complex<double> *Vcav_g = new complex<double>[rho_basis->npw];
std::complex<double> *Vel_g = new complex<double>[rho_basis->npw];
ModuleBase::GlobalFunc::ZEROS(Vcav_g, rho_basis->npw);
ModuleBase::GlobalFunc::ZEROS(Vel_g, rho_basis->npw);
for(int is=0; is<GlobalV::NSPIN; is++)
{
for (int ir=0; ir<rho_basis->nrxx; ir++)
{
Vcav_sum[ir] += GlobalC::solvent_model.Vcav(is, ir);
}
}
rho_basis->real2recip(Vcav_sum, Vcav_g);
rho_basis->real2recip(GlobalC::solvent_model.epspot, Vel_g);
int iat = 0;
double Ael1 = 0;
for (int it = 0;it < cell.ntype;it++)
{
double RCS = GlobalC::solvent_model.GetAtom.atom_RCS[cell.atoms[it].psd];
double sigma_rc_k = RCS / 2.5;
for (int ia = 0;ia < cell.atoms[it].na;ia++)
{
//cell.atoms[0].tau[0].z = 3.302;
//cout<<cell.atoms[it].tau[ia]<<endl;
ModuleBase::GlobalFunc::ZEROS(n_pseudo, rho_basis->npw);
for (int ig = 0; ig < rho_basis->npw; ig++)
{
// G^2
double gg = rho_basis->gg[ig];
gg = gg * cell.tpiba2;
complex<double> phase = exp( ModuleBase::NEG_IMAG_UNIT *ModuleBase::TWO_PI * ( rho_basis->gcar[ig] * cell.atoms[it].tau[ia]));
n_pseudo[ig].real((GlobalC::solvent_model.GetAtom.atom_Z[cell.atoms[it].psd] - cell.atoms[it].zv) * phase.real()
* exp(-0.5 * gg * (sigma_rc_k * sigma_rc_k)));
n_pseudo[ig].imag((GlobalC::solvent_model.GetAtom.atom_Z[cell.atoms[it].psd] - cell.atoms[it].zv) * phase.imag()
* exp(-0.5 * gg * (sigma_rc_k * sigma_rc_k)));
}
for (int ig = 0; ig < rho_basis->npw; ig++)
{
n_pseudo[ig] /= cell.omega;
}
for (int ig = 0; ig < rho_basis->npw; ig++)
{
forcesol(iat, 0) -= rho_basis->gcar[ig][0] * imag(conj(Vcav_g[ig]+Vel_g[ig]) * n_pseudo[ig]);
forcesol(iat, 1) -= rho_basis->gcar[ig][1] * imag(conj(Vcav_g[ig]+Vel_g[ig]) * n_pseudo[ig]);
forcesol(iat, 2) -= rho_basis->gcar[ig][2] * imag(conj(Vcav_g[ig]+Vel_g[ig]) * n_pseudo[ig]);
}
forcesol(iat, 0) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
forcesol(iat, 1) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
forcesol(iat, 2) *= (GlobalC::ucell.tpiba * GlobalC::ucell.omega);
//eV/Ang
forcesol(iat, 0) *= 2 ;
forcesol(iat, 1) *= 2 ;
forcesol(iat, 2) *= 2 ;
//cout<<"Force2"<<iat<<":"<<" "<<forcesol(iat, 0)<<" "<<forcesol(iat, 1)<<" "<<forcesol(iat, 2)<<endl;
++iat;
}
}
delete[] n_pseudo;
delete[] Vcav_sum;
delete[] Vcav_g;
delete[] Vel_g;
}
void surchem::cal_force_sol(const UnitCell &cell, ModulePW::PW_Basis* rho_basis , ModuleBase::matrix& forcesol)
{
ModuleBase::TITLE("surchem", "cal_force_sol");
ModuleBase::timer::tick("surchem", "cal_force_sol");
int nat = GlobalC::ucell.nat;
ModuleBase::matrix force1(nat, 3);
ModuleBase::matrix force2(nat, 3);
force_cor_one(cell, rho_basis,force1);
force_cor_two(cell, rho_basis,force2);
int iat = 0;
for (int it = 0;it < GlobalC::ucell.ntype;it++)
{
for (int ia = 0;ia < GlobalC::ucell.atoms[it].na;ia++)
{
for(int ipol = 0; ipol < 3; ipol++)
{
forcesol(iat, ipol) = 0.5*force1(iat, ipol) + force2 (iat, ipol);
}
++iat;
}
}
Parallel_Reduce::reduce_double_pool(forcesol.c, forcesol.nr * forcesol.nc);
ModuleBase::timer::tick("surchem", "cal_force_sol");
return;
}