Skip to content

Commit 4d6fdb4

Browse files
author
Han Wang
committed
support assigning aparam by ttm (two-temperature model)
1 parent 123db3e commit 4d6fdb4

File tree

3 files changed

+122
-4
lines changed

3 files changed

+122
-4
lines changed

source/lmp/deepmd_fix_ttm.patch

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
diff '--color=auto' -Naur lammps-16Mar18/src/USER-MISC/fix_ttm_mod.h lammps-16Mar18.new/src/USER-MISC/fix_ttm_mod.h
2+
--- lammps-16Mar18/src/USER-MISC/fix_ttm_mod.h 2017-06-22 21:57:19.000000000 +0800
3+
+++ lammps-16Mar18.new/src/USER-MISC/fix_ttm_mod.h 2019-10-16 09:58:38.228813486 +0800
4+
@@ -21,6 +21,7 @@
5+
#define LMP_FIX_TTM_MOD_H
6+
7+
#include "fix.h"
8+
+#include <vector>
9+
10+
namespace LAMMPS_NS {
11+
12+
@@ -51,6 +52,22 @@
13+
double memory_usage();
14+
void grow_arrays(int);
15+
double compute_vector(int);
16+
+ //////////////////////////////////////////////////
17+
+ // added by deepmd-kit
18+
+ std::vector<int> get_nodes() const
19+
+ {
20+
+ std::vector<int> tmp(3);
21+
+ tmp[0] = nxnodes;
22+
+ tmp[1] = nynodes;
23+
+ tmp[2] = nznodes;
24+
+ return tmp;
25+
+ };
26+
+ double *** const get_T_electron()const
27+
+ {
28+
+ return T_electron;
29+
+ }
30+
+ // added by deepmd-kit
31+
+ //////////////////////////////////////////////////
32+
33+
private:
34+
int me;

source/lmp/pair_nnp.cpp

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "neighbor.h"
1212
#include "neigh_list.h"
1313
#include "neigh_request.h"
14+
#include "modify.h"
15+
#include "fix.h"
16+
#include "fix_ttm_mod.h"
1417

1518
#include "pair_nnp.h"
1619

@@ -116,6 +119,58 @@ make_uniform_aparam(
116119
}
117120
}
118121

122+
void PairNNP::make_ttm_aparam(
123+
#ifdef HIGH_PREC
124+
vector<double > & daparam
125+
#else
126+
vector<float > & daparam
127+
#endif
128+
)
129+
{
130+
assert(do_ttm);
131+
// get ttm_fix
132+
const FixTTMMod * ttm_fix = NULL;
133+
for (int ii = 0; ii < modify->nfix; ii++) {
134+
if (string(modify->fix[ii]->id) == ttm_fix_id){
135+
ttm_fix = dynamic_cast<FixTTMMod*>(modify->fix[ii]);
136+
}
137+
}
138+
assert(ttm_fix);
139+
// modify
140+
double **x = atom->x;
141+
int *mask = atom->mask;
142+
int nlocal = atom->nlocal;
143+
vector<int> nnodes = ttm_fix->get_nodes();
144+
int nxnodes = nnodes[0];
145+
int nynodes = nnodes[1];
146+
int nznodes = nnodes[2];
147+
double *** const T_electron = ttm_fix->get_T_electron();
148+
double dx = domain->xprd/nxnodes;
149+
double dy = domain->yprd/nynodes;
150+
double dz = domain->zprd/nynodes;
151+
// resize daparam
152+
daparam.resize(nlocal);
153+
// loop over atoms to assign aparam
154+
for (int ii = 0; ii < nlocal; ii++) {
155+
if (mask[ii] & ttm_fix->groupbit) {
156+
double xscale = (x[ii][0] - domain->boxlo[0])/domain->xprd;
157+
double yscale = (x[ii][1] - domain->boxlo[1])/domain->yprd;
158+
double zscale = (x[ii][2] - domain->boxlo[2])/domain->zprd;
159+
int ixnode = static_cast<int>(xscale*nxnodes);
160+
int iynode = static_cast<int>(yscale*nynodes);
161+
int iznode = static_cast<int>(zscale*nznodes);
162+
while (ixnode > nxnodes-1) ixnode -= nxnodes;
163+
while (iynode > nynodes-1) iynode -= nynodes;
164+
while (iznode > nznodes-1) iznode -= nznodes;
165+
while (ixnode < 0) ixnode += nxnodes;
166+
while (iynode < 0) iynode += nynodes;
167+
while (iznode < 0) iznode += nznodes;
168+
daparam[ii] = T_electron[ixnode][iynode][iznode];
169+
}
170+
}
171+
}
172+
173+
119174
PairNNP::PairNNP(LAMMPS *lmp)
120175
: Pair(lmp)
121176

@@ -134,6 +189,7 @@ PairNNP::PairNNP(LAMMPS *lmp)
134189
out_rel = 0;
135190
eps = 0.;
136191
scale = NULL;
192+
do_ttm = false;
137193

138194
// set comm size needed by this Pair
139195
comm_reverse = 1;
@@ -219,7 +275,12 @@ void PairNNP::compute(int eflag, int vflag)
219275
}
220276

221277
// uniform aparam
222-
make_uniform_aparam(daparam, aparam, nlocal);
278+
if (aparam.size() > 0){
279+
make_uniform_aparam(daparam, aparam, nlocal);
280+
}
281+
else if (do_ttm) {
282+
make_ttm_aparam(daparam);
283+
}
223284

224285
// compute
225286
bool single_model = (numb_models == 1);
@@ -525,6 +586,7 @@ is_key (const string& input)
525586
keys.push_back("out_file");
526587
keys.push_back("fparam");
527588
keys.push_back("aparam");
589+
keys.push_back("ttm");
528590
keys.push_back("atomic");
529591
keys.push_back("relative");
530592

@@ -616,6 +678,16 @@ void PairNNP::settings(int narg, char **arg)
616678
}
617679
iarg += 1 + dim_aparam ;
618680
}
681+
else if (string(arg[iarg]) == string("ttm")) {
682+
for (int ii = 0; ii < 1; ++ii){
683+
if (iarg+1+ii >= narg || is_key(arg[iarg+1+ii])) {
684+
error->all(FLERR, "invalid ttm key: should be ttm ttm_fix_id(str)");
685+
}
686+
}
687+
do_ttm = true;
688+
ttm_fix_id = arg[iarg+1];
689+
iarg += 1 + 1;
690+
}
619691
else if (string(arg[iarg]) == string("atomic")) {
620692
out_each = 1;
621693
iarg += 1;
@@ -630,7 +702,10 @@ void PairNNP::settings(int narg, char **arg)
630702
iarg += 2;
631703
}
632704
}
633-
if (out_freq < 0) error->all(FLERR,"Illegal out_freq, should be >= 0");
705+
if (out_freq < 0) error->all(FLERR,"Illegal out_freq, should be >= 0");
706+
if (do_ttm && aparam.size() > 0) {
707+
error->all(FLERR,"aparam and ttm should NOT be set simultaneously");
708+
}
634709

635710
if (comm->me == 0){
636711
if (numb_models > 1 && out_freq > 0){
@@ -667,9 +742,9 @@ void PairNNP::settings(int narg, char **arg)
667742
}
668743
cout << endl;
669744
}
670-
if (dim_aparam > 0) {
745+
if (aparam.size() > 0) {
671746
cout << pre << "using aparam(s): " ;
672-
for (int ii = 0; ii < dim_aparam; ++ii){
747+
for (int ii = 0; ii < aparam.size(); ++ii){
673748
cout << aparam[ii] << " " ;
674749
}
675750
cout << endl;

source/lmp/pair_nnp.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ private:
9191
vector<float > aparam;
9292
float eps;
9393
#endif
94+
void make_ttm_aparam(
95+
#ifdef HIGH_PREC
96+
vector<double > & dparam
97+
#else
98+
vector<float > & dparam
99+
#endif
100+
);
101+
bool do_ttm;
102+
string ttm_fix_id;
94103
};
95104

96105
}

0 commit comments

Comments
 (0)