Skip to content

Commit

Permalink
lmp: refactor ixnode (#2971)
Browse files Browse the repository at this point in the history
The current implementation used a complex method to ensure `ixnode`
(int) within `[0, nxnodes-1]`, but why not use mod ("%") to get the same
behavior?

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Nov 7, 2023
1 parent ffbdcf8 commit a40dcaa
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions source/lmp/pair_deepmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,10 @@ void PairDeepMD::make_ttm_aparam(vector<double> &daparam) {
int ixnode = static_cast<int>(xscale * nxnodes);
int iynode = static_cast<int>(yscale * nynodes);
int iznode = static_cast<int>(zscale * nznodes);
while (ixnode > nxnodes - 1) {
ixnode -= nxnodes;
}
while (iynode > nynodes - 1) {
iynode -= nynodes;
}
while (iznode > nznodes - 1) {
iznode -= nznodes;
}
while (ixnode < 0) {
ixnode += nxnodes;
}
while (iynode < 0) {
iynode += nynodes;
}
while (iznode < 0) {
iznode += nznodes;
}
// https://stackoverflow.com/a/1907585/9567349
ixnode = ((ixnode % nxnodes) + nxnodes) % nxnodes;
iynode = ((iynode % nynodes) + nynodes) % nynodes;
iznode = ((iznode % nznodes) + nznodes) % nznodes;
daparam[ii] = T_electron[ixnode][iynode][iznode];
}
}
Expand Down

0 comments on commit a40dcaa

Please sign in to comment.