Skip to content

Commit 14091c3

Browse files
author
Han Wang
committed
implement external efield in fix/dplr
1 parent b0f11a9 commit 14091c3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

source/lmp/fix_dplr.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ is_key (const string& input)
3434

3535

3636
FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
37-
:Fix(lmp, narg, arg)
37+
:Fix(lmp, narg, arg), efield(3, 0.0)
3838
{
3939
virial_flag = 1;
4040

@@ -54,6 +54,13 @@ FixDPLR::FixDPLR(LAMMPS *lmp, int narg, char **arg)
5454
model = string(arg[iarg+1]);
5555
iarg += 2;
5656
}
57+
if (string(arg[iarg]) == string("efield")) {
58+
if (iarg+3 > narg) error->all(FLERR,"Illegal fix adapt command, efield should be provided 3 float numbers");
59+
efield[0] = atof(arg[iarg+1]);
60+
efield[1] = atof(arg[iarg+2]);
61+
efield[2] = atof(arg[iarg+3]);
62+
iarg += 4;
63+
}
5764
if (string(arg[iarg]) == string("type_associate")) {
5865
int iend = iarg+1;
5966
while (iend < narg && (! is_key(arg[iend]) )) {
@@ -347,6 +354,7 @@ void FixDPLR::post_force(int vflag)
347354
int nall = nlocal + nghost;
348355
vector<FLOAT_PREC> dcoord(nall*3, 0.0), dbox(9, 0.0), dfele(nlocal*3, 0.0);
349356
vector<int> dtype(nall, 0);
357+
// set values for dcoord, dbox, dfele
350358
{
351359
int *type = atom->type;
352360
for (int ii = 0; ii < nall; ++ii){
@@ -366,9 +374,30 @@ void FixDPLR::post_force(int vflag)
366374
}
367375
}
368376
assert(dfele_.size() == nlocal * 3);
377+
// revise force according to efield
369378
for (int ii = 0; ii < nlocal*3; ++ii){
370379
dfele[ii] = dfele_[ii];
371380
}
381+
// revise force and virial according to efield
382+
double * q = atom->q;
383+
imageint *image = atom->image;
384+
double unwrap[3];
385+
double v[6];
386+
for (int ii = 0; ii < nlocal; ++ii){
387+
for (int dd = 0; dd < 3; ++dd){
388+
dfele[ii*3+dd] += q[ii] * efield[dd];
389+
}
390+
domain->unmap(x[ii],image[ii],unwrap);
391+
if (evflag) {
392+
v[0] = q[ii] * efield[0] *unwrap[0];
393+
v[1] = q[ii] * efield[1] *unwrap[1];
394+
v[2] = q[ii] * efield[2] *unwrap[2];
395+
v[3] = q[ii] * efield[0] *unwrap[1];
396+
v[4] = q[ii] * efield[0] *unwrap[2];
397+
v[5] = q[ii] * efield[1] *unwrap[2];
398+
v_tally(ii, v);
399+
}
400+
}
372401
}
373402
// lmp nlist
374403
NeighList * list = pair_nnp->list;

source/lmp/fix_dplr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace LAMMPS_NS {
4545
map<int,int > bk_type_asso;
4646
vector<FLOAT_PREC> dipole_recd;
4747
vector<double> dfcorr_buff;
48+
vector<double> efield;
4849
void get_valid_pairs(vector<pair<int,int> >& pairs);
4950
};
5051
}

0 commit comments

Comments
 (0)