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+
119174PairNNP::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;
0 commit comments