From 9a3f90294cc4bae9d2e29898df3d033a8efb2b6e Mon Sep 17 00:00:00 2001 From: Diaz Date: Mon, 21 Jan 2019 11:50:10 -0500 Subject: [PATCH 001/122] updated comm tiled to have multi --- src/comm_tiled.cpp | 189 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 179 insertions(+), 10 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index d7d2e4725d..9805dbd6e0 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -11,6 +11,10 @@ See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Contributing author (multi) : Adrian Diaz (University of Florida) +------------------------------------------------------------------------- */ + #include #include "comm_tiled.h" #include "comm_brick.h" @@ -72,6 +76,9 @@ CommTiled::~CommTiled() memory->destroy(overlap); deallocate_swap(nswap); memory->sfree(rcbinfo); + if (mode == Comm::MULTI) { + memory->destroy(cutghostmulti); + } } /* ---------------------------------------------------------------------- @@ -80,6 +87,8 @@ CommTiled::~CommTiled() void CommTiled::init_buffers() { + sendbox_multi = NULL; + cutghostmulti = NULL; // bufextra = max size of one exchanged atom // = allowed overflow of sendbuf in exchange() // atomvec, fix reset these 2 maxexchange values if needed @@ -108,12 +117,20 @@ void CommTiled::init() { Comm::init(); + // memory for multi-style communication + int maxswap = 6; + if (mode == Comm::MULTI) { + memory->create(cutghostmulti,atom->ntypes+1,3,"comm:cutghostmulti"); + } + if (mode == Comm::SINGLE && cutghostmulti) { + memory->destroy(cutghostmulti); + } + // temporary restrictions if (triclinic) error->all(FLERR,"Cannot yet use comm_style tiled with triclinic box"); - if (mode == Comm::MULTI) - error->all(FLERR,"Cannot yet use comm_style tiled with multi-mode comm"); + } /* ---------------------------------------------------------------------- @@ -124,7 +141,7 @@ void CommTiled::init() void CommTiled::setup() { int i,j,n; - + int ntypes = atom->ntypes; // domain properties used in setup method and methods it calls dimension = domain->dimension; @@ -157,9 +174,22 @@ void CommTiled::setup() // set cutoff for comm forward and comm reverse // check that cutoff < any periodic box length - double cut = MAX(neighbor->cutneighmax,cutghostuser); + double cut; + + if (mode == Comm::MULTI) { + double *cuttype = neighbor->cuttype; + for (i = 1; i <= ntypes; i++) { + cut = 0.0; + if (cutusermulti) cut = cutusermulti[i]; + cutghostmulti[i][0] = MAX(cut,cuttype[i]); + cutghostmulti[i][1] = MAX(cut,cuttype[i]); + cutghostmulti[i][2] = MAX(cut,cuttype[i]); + } + } + cut = MAX(neighbor->cutneighmax,cutghostuser); cutghost[0] = cutghost[1] = cutghost[2] = cut; + if ((periodicity[0] && cut > prd[0]) || (periodicity[1] && cut > prd[1]) || (dimension == 3 && periodicity[2] && cut > prd[2])) @@ -261,6 +291,7 @@ void CommTiled::setup() grow_swap_send(iswap,nprocmax[iswap],oldmax); if (idir == 0) grow_swap_recv(iswap+1,nprocmax[iswap]); else grow_swap_recv(iswap-1,nprocmax[iswap]); + } // overlap how has list of noverlap procs @@ -293,8 +324,8 @@ void CommTiled::setup() // if sbox touches other proc's sub-box boundaries in lower dims, // extend sbox in those lower dims to include ghost atoms - double oboxlo[3],oboxhi[3],sbox[6]; - + double oboxlo[3],oboxhi[3],sbox[6],sbox_multi[6]; + if (mode == Comm::SINGLE) { for (i = 0; i < noverlap; i++) { pbc_flag[iswap][i] = 0; pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = @@ -342,7 +373,65 @@ void CommTiled::setup() memcpy(sendbox[iswap][i],sbox,6*sizeof(double)); } + } + else{ + for (i = 0; i < noverlap; i++) { + + + pbc_flag[iswap][i] = 0; + pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); + + if (i < noverlap1) { + sbox[0] = MAX(oboxlo[0],lo1[0]); + sbox[1] = MAX(oboxlo[1],lo1[1]); + sbox[2] = MAX(oboxlo[2],lo1[2]); + sbox[3] = MIN(oboxhi[0],hi1[0]); + sbox[4] = MIN(oboxhi[1],hi1[1]); + sbox[5] = MIN(oboxhi[2],hi1[2]); + } else { + pbc_flag[iswap][i] = 1; + if (idir == 0) pbc[iswap][i][idim] = 1; + else pbc[iswap][i][idim] = -1; + sbox[0] = MAX(oboxlo[0],lo2[0]); + sbox[1] = MAX(oboxlo[1],lo2[1]); + sbox[2] = MAX(oboxlo[2],lo2[2]); + sbox[3] = MIN(oboxhi[0],hi2[0]); + sbox[4] = MIN(oboxhi[1],hi2[1]); + sbox[5] = MIN(oboxhi[2],hi2[2]); + } + for (int itype = 1; itype <= atom->ntypes; itype++) { + sbox_multi[0] = sbox[0]; + sbox_multi[1] = sbox[1]; + sbox_multi[2] = sbox[2]; + sbox_multi[3] = sbox[3]; + sbox_multi[4] = sbox[4]; + sbox_multi[5] = sbox[5]; + if (idir == 0) { + sbox_multi[idim] = sublo[idim]; + if (i < noverlap1) sbox_multi[3+idim] = MIN(sbox_multi[3+idim]+cutghostmulti[itype][idim],subhi[idim]); + else sbox_multi[3+idim] = MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[itype][idim],subhi[idim]); + } else { + if (i < noverlap1) sbox_multi[idim] = MAX(sbox_multi[idim]-cutghostmulti[itype][idim],sublo[idim]); + else sbox_multi[idim] = MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[itype][idim],sublo[idim]); + sbox_multi[3+idim] = subhi[idim]; + } + + if (idim >= 1) { + if (sbox_multi[0] == oboxlo[0]) sbox_multi[0] -= cutghostmulti[itype][idim]; + if (sbox_multi[3] == oboxhi[0]) sbox_multi[3] += cutghostmulti[itype][idim]; + } + if (idim == 2) { + if (sbox_multi[1] == oboxlo[1]) sbox_multi[1] -= cutghostmulti[itype][idim]; + if (sbox_multi[4] == oboxhi[1]) sbox_multi[4] += cutghostmulti[itype][idim]; + } + + memcpy(sendbox_multi[iswap][i][itype],sbox_multi,6*sizeof(double)); + } + } + } iswap++; } } @@ -765,6 +854,7 @@ void CommTiled::borders() double xlo,xhi,ylo,yhi,zlo,zhi; double *bbox; double **x; + AtomVec *avec = atom->avec; // send/recv max one = max # of atoms in single send/recv for any swap @@ -790,6 +880,7 @@ void CommTiled::borders() ncountall = 0; for (m = 0; m < nsendproc[iswap]; m++) { + if (mode == Comm::SINGLE) { bbox = sendbox[iswap][m]; xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; @@ -829,6 +920,58 @@ void CommTiled::borders() smaxone = MAX(smaxone,ncount); ncountall += ncount; } + else{ + int* type=atom->type; + int itype; + ncount = 0; + + if (!bordergroup) { + for (i = 0; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + + } + } else { + ngroup = atom->nfirst; + for (i = 0; i < ngroup; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + for (i = atom->nlocal; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + } + + sendnum[iswap][m] = ncount; + smaxone = MAX(smaxone,ncount); + ncountall += ncount; + } + } smaxall = MAX(smaxall,ncountall); // send sendnum counts to procs who recv from me except self @@ -1873,7 +2016,12 @@ void CommTiled::allocate_swap(int n) pbc_flag = new int*[n]; pbc = new int**[n]; - sendbox = new double**[n]; + //if(mode == SINGLE){ + sendbox = new double**[n]; + //} + //else{ + sendbox_multi = new double***[n]; + //} maxsendlist = new int*[n]; sendlist = new int**[n]; @@ -1886,7 +2034,12 @@ void CommTiled::allocate_swap(int n) pbc_flag[i] = NULL; pbc[i] = NULL; - sendbox[i] = NULL; + //if(mode == SINGLE){ + sendbox[i] = NULL; + // } + //else{ + sendbox_multi[i] = NULL; + //} maxsendlist[i] = NULL; sendlist[i] = NULL; } @@ -1933,8 +2086,14 @@ void CommTiled::grow_swap_send(int i, int n, int nold) pbc_flag[i] = new int[n]; memory->destroy(pbc[i]); memory->create(pbc[i],n,6,"comm:pbc_flag"); + //if(mode == SINGLE){ memory->destroy(sendbox[i]); memory->create(sendbox[i],n,6,"comm:sendbox"); + //} + //else { + memory->destroy(sendbox_multi[i]); + memory->create(sendbox_multi[i],n,atom->ntypes+1,6,"comm:sendbox_multi"); + //} delete [] maxsendlist[i]; maxsendlist[i] = new int[n]; @@ -1992,7 +2151,12 @@ void CommTiled::deallocate_swap(int n) delete [] pbc_flag[i]; memory->destroy(pbc[i]); - memory->destroy(sendbox[i]); + //if(mode == Comm::SINGLE){ + memory->destroy(sendbox[i]); + // } + //else{ + memory->destroy(sendbox_multi[i]); + // } delete [] maxsendlist[i]; for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); @@ -2012,7 +2176,12 @@ void CommTiled::deallocate_swap(int n) delete [] pbc_flag; delete [] pbc; - delete [] sendbox; + //if(mode == SINGLE){ + delete [] sendbox; + // } + //else{ + delete [] sendbox_multi; + //} delete [] maxsendlist; delete [] sendlist; From 0f88513f65db23a4834e2ed1859f13f278fb2172 Mon Sep 17 00:00:00 2001 From: Diaz Date: Mon, 21 Jan 2019 12:29:31 -0500 Subject: [PATCH 002/122] updated comm tiled to have multi --- src/comm_tiled.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/comm_tiled.h b/src/comm_tiled.h index 13ecbc4b01..e5be7639ea 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -69,13 +69,14 @@ class CommTiled : public Comm { int **size_reverse_recv; // # of values to recv in each reverse swap/proc int **forward_recv_offset; // forward comm offsets in buf_recv per swap/proc int **reverse_recv_offset; // reverse comm offsets in buf_recv per swap/proc - + double **cutghostmulti; // cutghost on a per-type basis int ***sendlist; // list of atoms to send per swap/proc int **maxsendlist; // max size of send list per swap/proc int **pbc_flag; // general flag for sending atoms thru PBC int ***pbc; // dimension flags for PBC adjustments double ***sendbox; // bounding box of atoms to send per swap/proc + double ****sendbox_multi; // bounding box of atoms to send per swap/proc for multi comm // exchange comm info, proc lists do not include self @@ -147,6 +148,7 @@ class CommTiled : public Comm { void grow_swap_send(int, int, int); // grow swap arrays for send and recv void grow_swap_recv(int, int); void deallocate_swap(int); // deallocate swap arrays + }; } From c262d08e84e5430c067c8615e26d2e662305589a Mon Sep 17 00:00:00 2001 From: Adrian-Diaz <46537160+Adrian-Diaz@users.noreply.github.com> Date: Wed, 4 Dec 2019 12:32:04 -0500 Subject: [PATCH 003/122] remove comments --- src/comm_tiled.cpp | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index cef52166e7..a808d57223 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -2016,12 +2016,8 @@ void CommTiled::allocate_swap(int n) pbc_flag = new int*[n]; pbc = new int**[n]; - //if(mode == SINGLE){ - sendbox = new double**[n]; - //} - //else{ - sendbox_multi = new double***[n]; - //} + sendbox = new double**[n]; + sendbox_multi = new double***[n]; maxsendlist = new int*[n]; sendlist = new int**[n]; @@ -2034,12 +2030,8 @@ void CommTiled::allocate_swap(int n) pbc_flag[i] = NULL; pbc[i] = NULL; - //if(mode == SINGLE){ - sendbox[i] = NULL; - // } - //else{ - sendbox_multi[i] = NULL; - //} + sendbox[i] = NULL; + sendbox_multi[i] = NULL; maxsendlist[i] = NULL; sendlist[i] = NULL; } @@ -2086,14 +2078,10 @@ void CommTiled::grow_swap_send(int i, int n, int nold) pbc_flag[i] = new int[n]; memory->destroy(pbc[i]); memory->create(pbc[i],n,6,"comm:pbc_flag"); - //if(mode == SINGLE){ memory->destroy(sendbox[i]); memory->create(sendbox[i],n,6,"comm:sendbox"); - //} - //else { memory->destroy(sendbox_multi[i]); memory->create(sendbox_multi[i],n,atom->ntypes+1,6,"comm:sendbox_multi"); - //} delete [] maxsendlist[i]; maxsendlist[i] = new int[n]; @@ -2151,12 +2139,8 @@ void CommTiled::deallocate_swap(int n) delete [] pbc_flag[i]; memory->destroy(pbc[i]); - //if(mode == Comm::SINGLE){ - memory->destroy(sendbox[i]); - // } - //else{ - memory->destroy(sendbox_multi[i]); - // } + memory->destroy(sendbox[i]); + memory->destroy(sendbox_multi[i]); delete [] maxsendlist[i]; for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); @@ -2176,12 +2160,8 @@ void CommTiled::deallocate_swap(int n) delete [] pbc_flag; delete [] pbc; - //if(mode == SINGLE){ - delete [] sendbox; - // } - //else{ - delete [] sendbox_multi; - //} + delete [] sendbox; + delete [] sendbox_multi; delete [] maxsendlist; delete [] sendlist; From e982f418d31c6d63dc29658945afeeaa69f52d53 Mon Sep 17 00:00:00 2001 From: Adrian-Diaz <46537160+Adrian-Diaz@users.noreply.github.com> Date: Wed, 5 Feb 2020 13:54:56 -0500 Subject: [PATCH 004/122] remove whitespace issues --- src/comm_tiled.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index a808d57223..88a5c02c6b 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -287,7 +287,6 @@ void CommTiled::setup() grow_swap_send(iswap,nprocmax[iswap],oldmax); if (idir == 0) grow_swap_recv(iswap+1,nprocmax[iswap]); else grow_swap_recv(iswap-1,nprocmax[iswap]); - } // overlap how has list of noverlap procs @@ -372,11 +371,9 @@ void CommTiled::setup() } else{ for (i = 0; i < noverlap; i++) { - - pbc_flag[iswap][i] = 0; pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = - pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); @@ -849,7 +846,6 @@ void CommTiled::borders() double xlo,xhi,ylo,yhi,zlo,zhi; double *bbox; double **x; - AtomVec *avec = atom->avec; // send/recv max one = max # of atoms in single send/recv for any swap @@ -922,7 +918,7 @@ void CommTiled::borders() if (!bordergroup) { for (i = 0; i < nlast; i++) { - itype=type[i]; + itype=type[i]; bbox = sendbox_multi[iswap][m][itype]; xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; @@ -932,12 +928,11 @@ void CommTiled::borders() if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); sendlist[iswap][m][ncount++] = i; } - } } else { ngroup = atom->nfirst; for (i = 0; i < ngroup; i++) { - itype=type[i]; + itype=type[i]; bbox = sendbox_multi[iswap][m][itype]; xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; @@ -949,7 +944,7 @@ void CommTiled::borders() } } for (i = atom->nlocal; i < nlast; i++) { - itype=type[i]; + itype=type[i]; bbox = sendbox_multi[iswap][m][itype]; xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; From 9db34bc18e6509ce057930346cccaedbd7bc70be Mon Sep 17 00:00:00 2001 From: Steve Plimpton Date: Mon, 27 Jul 2020 16:15:41 -0600 Subject: [PATCH 005/122] cosmetic changes to CommTiled for comm multi style --- src/comm_tiled.cpp | 409 ++++++++++++++++++++++++--------------------- src/comm_tiled.h | 6 +- 2 files changed, 218 insertions(+), 197 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 88a5c02c6b..a57437d88e 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -73,9 +73,8 @@ CommTiled::~CommTiled() memory->destroy(overlap); deallocate_swap(nswap); memory->sfree(rcbinfo); - if (mode == Comm::MULTI) { - memory->destroy(cutghostmulti); - } + + if (mode == Comm::MULTI) memory->destroy(cutghostmulti); } /* ---------------------------------------------------------------------- @@ -84,8 +83,6 @@ CommTiled::~CommTiled() void CommTiled::init_buffers() { - sendbox_multi = NULL; - cutghostmulti = NULL; buf_send = buf_recv = NULL; maxsend = maxrecv = BUFMIN; grow_send(maxsend,2); @@ -98,6 +95,9 @@ void CommTiled::init_buffers() allocate_swap(nswap); rcbinfo = NULL; + + cutghostmulti = NULL; + sendbox_multi = NULL; } /* ---------------------------------------------------------------------- */ @@ -106,13 +106,10 @@ void CommTiled::init() { Comm::init(); - // memory for multi-style communication - if (mode == Comm::MULTI) { + if (mode == Comm::SINGLE && cutghostmulti) memory->destroy(cutghostmulti); + + if (mode == Comm::MULTI && !cutghostmulti) memory->create(cutghostmulti,atom->ntypes+1,3,"comm:cutghostmulti"); - } - if (mode == Comm::SINGLE && cutghostmulti) { - memory->destroy(cutghostmulti); - } int bufextra_old = bufextra; init_exchange(); @@ -122,7 +119,6 @@ void CommTiled::init() if (triclinic) error->all(FLERR,"Cannot yet use comm_style tiled with triclinic box"); - } /* ---------------------------------------------------------------------- @@ -133,7 +129,7 @@ void CommTiled::init() void CommTiled::setup() { int i,j,n; - int ntypes = atom->ntypes; + // domain properties used in setup method and methods it calls dimension = domain->dimension; @@ -144,6 +140,7 @@ void CommTiled::setup() subhi = domain->subhi; int *periodicity = domain->periodicity; + int ntypes = atom->ntypes; // set function pointers @@ -185,7 +182,6 @@ void CommTiled::setup() cutghost[0] = cutghost[1] = cutghost[2] = cut; - if ((periodicity[0] && cut > prd[0]) || (periodicity[1] && cut > prd[1]) || (dimension == 3 && periodicity[2] && cut > prd[2])) @@ -318,113 +314,132 @@ void CommTiled::setup() // = obox in other 2 dims // if sbox touches other proc's sub-box boundaries in lower dims, // extend sbox in those lower dims to include ghost atoms - + // single mode and multi mode + double oboxlo[3],oboxhi[3],sbox[6],sbox_multi[6]; + if (mode == Comm::SINGLE) { - for (i = 0; i < noverlap; i++) { - pbc_flag[iswap][i] = 0; - pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = - pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + for (i = 0; i < noverlap; i++) { + pbc_flag[iswap][i] = 0; + pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; - (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); + (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); - if (i < noverlap1) { - sbox[0] = MAX(oboxlo[0],lo1[0]); - sbox[1] = MAX(oboxlo[1],lo1[1]); - sbox[2] = MAX(oboxlo[2],lo1[2]); - sbox[3] = MIN(oboxhi[0],hi1[0]); - sbox[4] = MIN(oboxhi[1],hi1[1]); - sbox[5] = MIN(oboxhi[2],hi1[2]); - } else { - pbc_flag[iswap][i] = 1; - if (idir == 0) pbc[iswap][i][idim] = 1; - else pbc[iswap][i][idim] = -1; - sbox[0] = MAX(oboxlo[0],lo2[0]); - sbox[1] = MAX(oboxlo[1],lo2[1]); - sbox[2] = MAX(oboxlo[2],lo2[2]); - sbox[3] = MIN(oboxhi[0],hi2[0]); - sbox[4] = MIN(oboxhi[1],hi2[1]); - sbox[5] = MIN(oboxhi[2],hi2[2]); - } + if (i < noverlap1) { + sbox[0] = MAX(oboxlo[0],lo1[0]); + sbox[1] = MAX(oboxlo[1],lo1[1]); + sbox[2] = MAX(oboxlo[2],lo1[2]); + sbox[3] = MIN(oboxhi[0],hi1[0]); + sbox[4] = MIN(oboxhi[1],hi1[1]); + sbox[5] = MIN(oboxhi[2],hi1[2]); + } else { + pbc_flag[iswap][i] = 1; + if (idir == 0) pbc[iswap][i][idim] = 1; + else pbc[iswap][i][idim] = -1; + sbox[0] = MAX(oboxlo[0],lo2[0]); + sbox[1] = MAX(oboxlo[1],lo2[1]); + sbox[2] = MAX(oboxlo[2],lo2[2]); + sbox[3] = MIN(oboxhi[0],hi2[0]); + sbox[4] = MIN(oboxhi[1],hi2[1]); + sbox[5] = MIN(oboxhi[2],hi2[2]); + } + + if (idir == 0) { + sbox[idim] = sublo[idim]; + if (i < noverlap1) sbox[3+idim] = MIN(sbox[3+idim]+cut,subhi[idim]); + else sbox[3+idim] = MIN(sbox[3+idim]-prd[idim]+cut,subhi[idim]); + } else { + if (i < noverlap1) sbox[idim] = MAX(sbox[idim]-cut,sublo[idim]); + else sbox[idim] = MAX(sbox[idim]+prd[idim]-cut,sublo[idim]); + sbox[3+idim] = subhi[idim]; + } - if (idir == 0) { - sbox[idim] = sublo[idim]; - if (i < noverlap1) sbox[3+idim] = MIN(sbox[3+idim]+cut,subhi[idim]); - else sbox[3+idim] = MIN(sbox[3+idim]-prd[idim]+cut,subhi[idim]); - } else { - if (i < noverlap1) sbox[idim] = MAX(sbox[idim]-cut,sublo[idim]); - else sbox[idim] = MAX(sbox[idim]+prd[idim]-cut,sublo[idim]); - sbox[3+idim] = subhi[idim]; - } + if (idim >= 1) { + if (sbox[0] == oboxlo[0]) sbox[0] -= cut; + if (sbox[3] == oboxhi[0]) sbox[3] += cut; + } + if (idim == 2) { + if (sbox[1] == oboxlo[1]) sbox[1] -= cut; + if (sbox[4] == oboxhi[1]) sbox[4] += cut; + } - if (idim >= 1) { - if (sbox[0] == oboxlo[0]) sbox[0] -= cut; - if (sbox[3] == oboxhi[0]) sbox[3] += cut; - } - if (idim == 2) { - if (sbox[1] == oboxlo[1]) sbox[1] -= cut; - if (sbox[4] == oboxhi[1]) sbox[4] += cut; - } - - memcpy(sendbox[iswap][i],sbox,6*sizeof(double)); + memcpy(sendbox[iswap][i],sbox,6*sizeof(double)); + } } - } - else{ + + if (mode == Comm::MULTI) { for (i = 0; i < noverlap; i++) { - pbc_flag[iswap][i] = 0; - pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = - pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + pbc_flag[iswap][i] = 0; + pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; - (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); + (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); - if (i < noverlap1) { - sbox[0] = MAX(oboxlo[0],lo1[0]); - sbox[1] = MAX(oboxlo[1],lo1[1]); - sbox[2] = MAX(oboxlo[2],lo1[2]); - sbox[3] = MIN(oboxhi[0],hi1[0]); - sbox[4] = MIN(oboxhi[1],hi1[1]); - sbox[5] = MIN(oboxhi[2],hi1[2]); - } else { - pbc_flag[iswap][i] = 1; - if (idir == 0) pbc[iswap][i][idim] = 1; - else pbc[iswap][i][idim] = -1; - sbox[0] = MAX(oboxlo[0],lo2[0]); - sbox[1] = MAX(oboxlo[1],lo2[1]); - sbox[2] = MAX(oboxlo[2],lo2[2]); - sbox[3] = MIN(oboxhi[0],hi2[0]); - sbox[4] = MIN(oboxhi[1],hi2[1]); - sbox[5] = MIN(oboxhi[2],hi2[2]); - } - for (int itype = 1; itype <= atom->ntypes; itype++) { - sbox_multi[0] = sbox[0]; - sbox_multi[1] = sbox[1]; - sbox_multi[2] = sbox[2]; - sbox_multi[3] = sbox[3]; - sbox_multi[4] = sbox[4]; - sbox_multi[5] = sbox[5]; - if (idir == 0) { - sbox_multi[idim] = sublo[idim]; - if (i < noverlap1) sbox_multi[3+idim] = MIN(sbox_multi[3+idim]+cutghostmulti[itype][idim],subhi[idim]); - else sbox_multi[3+idim] = MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[itype][idim],subhi[idim]); - } else { - if (i < noverlap1) sbox_multi[idim] = MAX(sbox_multi[idim]-cutghostmulti[itype][idim],sublo[idim]); - else sbox_multi[idim] = MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[itype][idim],sublo[idim]); - sbox_multi[3+idim] = subhi[idim]; - } + if (i < noverlap1) { + sbox[0] = MAX(oboxlo[0],lo1[0]); + sbox[1] = MAX(oboxlo[1],lo1[1]); + sbox[2] = MAX(oboxlo[2],lo1[2]); + sbox[3] = MIN(oboxhi[0],hi1[0]); + sbox[4] = MIN(oboxhi[1],hi1[1]); + sbox[5] = MIN(oboxhi[2],hi1[2]); + } else { + pbc_flag[iswap][i] = 1; + if (idir == 0) pbc[iswap][i][idim] = 1; + else pbc[iswap][i][idim] = -1; + sbox[0] = MAX(oboxlo[0],lo2[0]); + sbox[1] = MAX(oboxlo[1],lo2[1]); + sbox[2] = MAX(oboxlo[2],lo2[2]); + sbox[3] = MIN(oboxhi[0],hi2[0]); + sbox[4] = MIN(oboxhi[1],hi2[1]); + sbox[5] = MIN(oboxhi[2],hi2[2]); + } + + for (int itype = 1; itype <= atom->ntypes; itype++) { + sbox_multi[0] = sbox[0]; + sbox_multi[1] = sbox[1]; + sbox_multi[2] = sbox[2]; + sbox_multi[3] = sbox[3]; + sbox_multi[4] = sbox[4]; + sbox_multi[5] = sbox[5]; + if (idir == 0) { + sbox_multi[idim] = sublo[idim]; + if (i < noverlap1) + sbox_multi[3+idim] = + MIN(sbox_multi[3+idim]+cutghostmulti[itype][idim],subhi[idim]); + else + sbox_multi[3+idim] = + MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[itype][idim], + subhi[idim]); + } else { + if (i < noverlap1) + sbox_multi[idim] = + MAX(sbox_multi[idim]-cutghostmulti[itype][idim],sublo[idim]); + else + sbox_multi[idim] = + MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[itype][idim], + sublo[idim]); + sbox_multi[3+idim] = subhi[idim]; + } + + if (idim >= 1) { + if (sbox_multi[0] == oboxlo[0]) + sbox_multi[0] -= cutghostmulti[itype][idim]; + if (sbox_multi[3] == oboxhi[0]) + sbox_multi[3] += cutghostmulti[itype][idim]; + } + if (idim == 2) { + if (sbox_multi[1] == oboxlo[1]) + sbox_multi[1] -= cutghostmulti[itype][idim]; + if (sbox_multi[4] == oboxhi[1]) + sbox_multi[4] += cutghostmulti[itype][idim]; + } - if (idim >= 1) { - if (sbox_multi[0] == oboxlo[0]) sbox_multi[0] -= cutghostmulti[itype][idim]; - if (sbox_multi[3] == oboxhi[0]) sbox_multi[3] += cutghostmulti[itype][idim]; - } - if (idim == 2) { - if (sbox_multi[1] == oboxlo[1]) sbox_multi[1] -= cutghostmulti[itype][idim]; - if (sbox_multi[4] == oboxhi[1]) sbox_multi[4] += cutghostmulti[itype][idim]; - } - - memcpy(sendbox_multi[iswap][i][itype],sbox_multi,6*sizeof(double)); - } - } + memcpy(sendbox_multi[iswap][i][itype],sbox_multi,6*sizeof(double)); + } + } } + iswap++; } } @@ -703,7 +718,7 @@ void CommTiled::reverse_comm() atoms exchanged with procs that touch sub-box in each of 3 dims send out atoms that have left my box, receive ones entering my box atoms will be lost if not inside a touching proc's box - can happen if atom moves outside of non-periodic bounary + can happen if atom moves outside of non-periodic boundary or if atom moves more than one proc away this routine called before every reneighboring for triclinic, atoms must be in lamda coords (0-1) before exchange is called @@ -864,104 +879,107 @@ void CommTiled::borders() // for x-dim swaps, check owned atoms // for yz-dim swaps, check owned and ghost atoms // store sent atom indices in sendlist for use in future timesteps - // NOTE: assume SINGLE mode, add logic for MULTI mode later - + // single mode and multi mode + x = atom->x; if (iswap % 2 == 0) nlast = atom->nlocal + atom->nghost; ncountall = 0; for (m = 0; m < nsendproc[iswap]; m++) { + if (mode == Comm::SINGLE) { - bbox = sendbox[iswap][m]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + bbox = sendbox[iswap][m]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - ncount = 0; + ncount = 0; - if (!bordergroup) { - for (i = 0; i < nlast; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + if (!bordergroup) { + for (i = 0; i < nlast; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); sendlist[iswap][m][ncount++] = i; - } - } + } + } + } else { + ngroup = atom->nfirst; + for (i = 0; i < ngroup; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + for (i = atom->nlocal; i < nlast; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + } + + sendnum[iswap][m] = ncount; + smaxone = MAX(smaxone,ncount); + ncountall += ncount; + } else { - ngroup = atom->nfirst; - for (i = 0; i < ngroup; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + + int* type=atom->type; + int itype; + ncount = 0; + + if (!bordergroup) { + for (i = 0; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); sendlist[iswap][m][ncount++] = i; - } - } - for (i = atom->nlocal; i < nlast; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } + } + } + } else { + ngroup = atom->nfirst; + for (i = 0; i < ngroup; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + for (i = atom->nlocal; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + } + + sendnum[iswap][m] = ncount; + smaxone = MAX(smaxone,ncount); + ncountall += ncount; } - - sendnum[iswap][m] = ncount; - smaxone = MAX(smaxone,ncount); - ncountall += ncount; - } - else{ - int* type=atom->type; - int itype; - ncount = 0; - - if (!bordergroup) { - for (i = 0; i < nlast; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - } else { - ngroup = atom->nfirst; - for (i = 0; i < ngroup; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - for (i = atom->nlocal; i < nlast; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - } - - sendnum[iswap][m] = ncount; - smaxone = MAX(smaxone,ncount); - ncountall += ncount; - } } + smaxall = MAX(smaxall,ncountall); // send sendnum counts to procs who recv from me except self @@ -2136,6 +2154,7 @@ void CommTiled::deallocate_swap(int n) memory->destroy(pbc[i]); memory->destroy(sendbox[i]); memory->destroy(sendbox_multi[i]); + delete [] maxsendlist[i]; for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); diff --git a/src/comm_tiled.h b/src/comm_tiled.h index 018c5b3696..416e2a5317 100644 --- a/src/comm_tiled.h +++ b/src/comm_tiled.h @@ -69,14 +69,16 @@ class CommTiled : public Comm { int **size_reverse_recv; // # of values to recv in each reverse swap/proc int **forward_recv_offset; // forward comm offsets in buf_recv per swap/proc int **reverse_recv_offset; // reverse comm offsets in buf_recv per swap/proc - double **cutghostmulti; // cutghost on a per-type basis int ***sendlist; // list of atoms to send per swap/proc int **maxsendlist; // max size of send list per swap/proc int **pbc_flag; // general flag for sending atoms thru PBC int ***pbc; // dimension flags for PBC adjustments double ***sendbox; // bounding box of atoms to send per swap/proc - double ****sendbox_multi; // bounding box of atoms to send per swap/proc for multi comm + + double **cutghostmulti; // cutghost on a per-type basis + double ****sendbox_multi; // bounding box of atoms to send + // per swap/proc for multi comm // exchange comm info, proc lists do not include self From cc0cf3b94f21572d461debef8cab5d170ebcd341 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 28 Jul 2020 20:40:57 -0400 Subject: [PATCH 006/122] consolidate USER-REAXC init error message handling. avoid snprintf and buffer --- src/USER-OMP/reaxc_init_md_omp.cpp | 111 ++++++++----------- src/USER-REAXC/reaxc_init_md.cpp | 171 +++++++++++++++-------------- 2 files changed, 134 insertions(+), 148 deletions(-) diff --git a/src/USER-OMP/reaxc_init_md_omp.cpp b/src/USER-OMP/reaxc_init_md_omp.cpp index 4ef214bf47..b0cf4a5fb8 100644 --- a/src/USER-OMP/reaxc_init_md_omp.cpp +++ b/src/USER-OMP/reaxc_init_md_omp.cpp @@ -36,6 +36,7 @@ #include "reaxc_lookup.h" #include "reaxc_tool_box.h" #include "error.h" +#include "fmt/format.h" // Functions defined in reaxc_init_md.cpp extern int Init_MPI_Datatypes(reax_system*, storage*, mpi_datatypes*, MPI_Comm, char*); @@ -55,37 +56,38 @@ int Init_ListsOMP(reax_system *system, control_params *control, int mincap = system->mincap; double safezone = system->safezone; double saferzone = system->saferzone; + LAMMPS_NS::Error *error = system->error_ptr; - bond_top = (int*) calloc( system->total_cap, sizeof(int) ); - hb_top = (int*) calloc( system->local_cap, sizeof(int) ); - Estimate_Storages( system, control, lists, - &Htop, hb_top, bond_top, &num_3body ); + bond_top = (int*) calloc(system->total_cap, sizeof(int)); + hb_top = (int*) calloc(system->local_cap, sizeof(int)); + Estimate_Storages(system, control, lists, + &Htop, hb_top, bond_top, &num_3body); if (control->hbond_cut > 0) { /* init H indexes */ total_hbonds = 0; - for( i = 0; i < system->n; ++i ) { + for(i = 0; i < system->n; ++i) { system->my_atoms[i].num_hbonds = hb_top[i]; total_hbonds += hb_top[i]; } total_hbonds = (int)(MAX(total_hbonds*saferzone,mincap*system->minhbonds)); - if( !Make_List( system->Hcap, total_hbonds, TYP_HBOND, - *lists+HBONDS ) ) { - system->error_ptr->one( FLERR, "Not enough space for hbonds list. Terminating!" ); + if(!Make_List(system->Hcap, total_hbonds, TYP_HBOND, + *lists+HBONDS)) { + error->one(FLERR, "Not enough space for hbonds list. Terminating!"); } } total_bonds = 0; - for( i = 0; i < system->N; ++i ) { + for(i = 0; i < system->N; ++i) { system->my_atoms[i].num_bonds = bond_top[i]; total_bonds += bond_top[i]; } - bond_cap = (int)(MAX( total_bonds*safezone, mincap*MIN_BONDS )); + bond_cap = (int)(MAX(total_bonds*safezone, mincap*MIN_BONDS)); - if( !Make_List( system->total_cap, bond_cap, TYP_BOND, - *lists+BONDS ) ) { - system->error_ptr->one( FLERR, "Not enough space for bonds list. Terminating!\n" ); + if(!Make_List(system->total_cap, bond_cap, TYP_BOND, + *lists+BONDS)) { + error->one(FLERR, "Not enough space for bonds list. Terminating!\n"); } int nthreads = control->nthreads; @@ -93,18 +95,18 @@ int Init_ListsOMP(reax_system *system, control_params *control, for (i = 0; i < bonds->num_intrs; ++i) bonds->select.bond_list[i].bo_data.CdboReduction = - (double*) smalloc(system->error_ptr, sizeof(double)*nthreads, "CdboReduction"); + (double*) smalloc(error, sizeof(double)*nthreads, "CdboReduction"); /* 3bodies list */ - cap_3body = (int)(MAX( num_3body*safezone, MIN_3BODIES )); - if( !Make_List( bond_cap, cap_3body, TYP_THREE_BODY, - *lists+THREE_BODIES ) ){ + cap_3body = (int)(MAX(num_3body*safezone, MIN_3BODIES)); + if(!Make_List(bond_cap, cap_3body, TYP_THREE_BODY, + *lists+THREE_BODIES)){ - system->error_ptr->one( FLERR, "Problem in initializing angles list. Terminating!" ); + error->one(FLERR, "Problem in initializing angles list. Terminating!"); } - free( hb_top ); - free( bond_top ); + free(hb_top); + free(bond_top); return SUCCESS; } @@ -112,60 +114,43 @@ int Init_ListsOMP(reax_system *system, control_params *control, /* ---------------------------------------------------------------------- */ // The only difference with the MPI-only function is calls to Init_ListsOMP and Init_Force_FunctionsOMP(). -void InitializeOMP( reax_system *system, control_params *control, +void InitializeOMP(reax_system *system, control_params *control, simulation_data *data, storage *workspace, reax_list **lists, output_controls *out_control, - mpi_datatypes *mpi_data, MPI_Comm comm ) + mpi_datatypes *mpi_data, MPI_Comm comm) { char msg[MAX_STR]; - char errmsg[512]; + LAMMPS_NS::Error *error = system->error_ptr; + if (Init_MPI_Datatypes(system,workspace,mpi_data,comm,msg) == FAILURE) + error->one(FLERR,"init_mpi_datatypes: could not create datatypes. " + "Mpi_data could not be initialized! Terminating."); - if (Init_MPI_Datatypes(system, workspace, mpi_data, comm, msg) == FAILURE) { - system->error_ptr->one( FLERR, "init_mpi_datatypes: could not create datatypes. " - "Mpi_data couldn't be initialized! Terminating."); - } + if (Init_System(system,control,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. System could not be " + "initialized! Terminating.",msg)); - if (Init_System(system, control, msg) == FAILURE) { - snprintf( errmsg, 512, "Error on: %s. " - "System could not be initialized! Terminating.", msg ); - system->error_ptr->one(FLERR, errmsg); - } + if (Init_Simulation_Data(system,control,data,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Sim_data could not be " + "initialized! Terminating.",msg)); - if (Init_Simulation_Data( system, control, data, msg ) == FAILURE) { - snprintf( errmsg, 512, "Error on: %s. " - "Sim_data couldn't be initialized! Terminating.", msg ); - system->error_ptr->one(FLERR, errmsg); - } + if (Init_Workspace(system,control,workspace,msg) == FAILURE) + error->one(FLERR,"init_workspace: not enough memory. " + "Workspace could not be initialized. Terminating."); - if (Init_Workspace( system, control, workspace, msg ) == - FAILURE) { - system->error_ptr->one(FLERR, "init_workspace: not enough memory. " - "Workspace couldn't be initialized! Terminating."); - } + if (Init_ListsOMP(system,control,data,workspace,lists,mpi_data,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. System could not be " + "initialized. Terminating.",msg)); - if (Init_ListsOMP( system, control, data, workspace, lists, mpi_data, msg ) == - FAILURE) { - snprintf( errmsg, 512, "Error on: %s. " - "System could not be initialized! Terminating.", msg ); - system->error_ptr->one(FLERR, errmsg); - } + if (Init_Output_Files(system,control,out_control,mpi_data,msg)== FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Could not open output files! " + "Terminating.",msg)); - if (Init_Output_Files(system,control,out_control,mpi_data,msg)== FAILURE) { - snprintf( errmsg, 512, "Error on: %s" - "Could not open output files! Terminating.", msg ); - system->error_ptr->one(FLERR, errmsg); - } + if (control->tabulate) + if (Init_Lookup_Tables(system,control,workspace,mpi_data,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Could not create lookup " + "table. Terminating.",msg)); - if (control->tabulate) { - if (Init_Lookup_Tables( system, control, workspace, mpi_data, msg ) == FAILURE) { - snprintf( errmsg, 512, "Error on: %s." - " Couldn't create lookup table! Terminating.", msg ); - system->error_ptr->one(FLERR, errmsg); - } - } - - - Init_Force_FunctionsOMP( control ); + Init_Force_FunctionsOMP(control); } diff --git a/src/USER-REAXC/reaxc_init_md.cpp b/src/USER-REAXC/reaxc_init_md.cpp index 73210ef029..66585dad4a 100644 --- a/src/USER-REAXC/reaxc_init_md.cpp +++ b/src/USER-REAXC/reaxc_init_md.cpp @@ -39,8 +39,9 @@ #include "reaxc_tool_box.h" #include "error.h" +#include "fmt/format.h" -int Init_System( reax_system *system, control_params *control, char * /*msg*/ ) +int Init_System(reax_system *system, control_params *control, char * /*msg*/) { int i; reax_atom *atom; @@ -51,32 +52,32 @@ int Init_System( reax_system *system, control_params *control, char * /*msg*/ ) // determine the local and total capacity - system->local_cap = MAX( (int)(system->n * safezone), mincap); - system->total_cap = MAX( (int)(system->N * safezone), mincap); + system->local_cap = MAX((int)(system->n * safezone), mincap); + system->total_cap = MAX((int)(system->N * safezone), mincap); /* estimate numH and Hcap */ system->numH = 0; if (control->hbond_cut > 0) - for( i = 0; i < system->n; ++i ) { + for(i = 0; i < system->n; ++i) { atom = &(system->my_atoms[i]); if (system->reax_param.sbp[ atom->type ].p_hbond == 1 && atom->type >= 0) atom->Hindex = system->numH++; else atom->Hindex = -1; } - system->Hcap = (int)(MAX( system->numH * saferzone, mincap )); + system->Hcap = (int)(MAX(system->numH * saferzone, mincap)); return SUCCESS; } -int Init_Simulation_Data( reax_system *system, control_params *control, - simulation_data *data, char * /*msg*/ ) +int Init_Simulation_Data(reax_system *system, control_params *control, + simulation_data *data, char * /*msg*/) { - Reset_Simulation_Data( data, control->virial ); + Reset_Simulation_Data(data, control->virial); /* initialize the timer(s) */ if (system->my_rank == MASTER_NODE) { - data->timing.start = Get_Time( ); + data->timing.start = Get_Time(); } data->step = data->prev_steps = 0; @@ -84,81 +85,82 @@ int Init_Simulation_Data( reax_system *system, control_params *control, return SUCCESS; } -void Init_Taper( control_params *control, storage *workspace ) +void Init_Taper(control_params *control, storage *workspace) { double d1, d7; double swa, swa2, swa3; double swb, swb2, swb3; + LAMMPS_NS::Error *error = control->error_ptr; swa = control->nonb_low; swb = control->nonb_cut; - if (fabs( swa ) > 0.01 && control->me == 0) - control->error_ptr->warning( FLERR, "Non-zero lower Taper-radius cutoff" ); + if (fabs(swa) > 0.01 && control->me == 0) + error->warning(FLERR, "Non-zero lower Taper-radius cutoff"); if (swb < 0) { - control->error_ptr->all(FLERR,"Negative upper Taper-radius cutoff"); + error->all(FLERR,"Negative upper Taper-radius cutoff"); } - else if( swb < 5 && control->me == 0) { + else if(swb < 5 && control->me == 0) { char errmsg[256]; - snprintf(errmsg, 256, "Very low Taper-radius cutoff: %f", swb ); - control->error_ptr->warning( FLERR, errmsg ); + snprintf(errmsg, 256, "Very low Taper-radius cutoff: %f", swb); + error->warning(FLERR, errmsg); } d1 = swb - swa; - d7 = pow( d1, 7.0 ); - swa2 = SQR( swa ); - swa3 = CUBE( swa ); - swb2 = SQR( swb ); - swb3 = CUBE( swb ); + d7 = pow(d1, 7.0); + swa2 = SQR(swa); + swa3 = CUBE(swa); + swb2 = SQR(swb); + swb3 = CUBE(swb); workspace->Tap[7] = 20.0 / d7; workspace->Tap[6] = -70.0 * (swa + swb) / d7; workspace->Tap[5] = 84.0 * (swa2 + 3.0*swa*swb + swb2) / d7; - workspace->Tap[4] = -35.0 * (swa3 + 9.0*swa2*swb + 9.0*swa*swb2 + swb3 ) / d7; - workspace->Tap[3] = 140.0 * (swa3*swb + 3.0*swa2*swb2 + swa*swb3 ) / d7; + workspace->Tap[4] = -35.0 * (swa3 + 9.0*swa2*swb + 9.0*swa*swb2 + swb3) / d7; + workspace->Tap[3] = 140.0 * (swa3*swb + 3.0*swa2*swb2 + swa*swb3) / d7; workspace->Tap[2] =-210.0 * (swa3*swb2 + swa2*swb3) / d7; workspace->Tap[1] = 140.0 * swa3 * swb3 / d7; workspace->Tap[0] = (-35.0*swa3*swb2*swb2 + 21.0*swa2*swb3*swb2 - - 7.0*swa*swb3*swb3 + swb3*swb3*swb ) / d7; + 7.0*swa*swb3*swb3 + swb3*swb3*swb) / d7; } -int Init_Workspace( reax_system *system, control_params *control, - storage *workspace, char *msg ) +int Init_Workspace(reax_system *system, control_params *control, + storage *workspace, char *msg) { int ret; - ret = Allocate_Workspace( system, control, workspace, - system->local_cap, system->total_cap, msg ); + ret = Allocate_Workspace(system, control, workspace, + system->local_cap, system->total_cap, msg); if (ret != SUCCESS) return ret; - memset( &(workspace->realloc), 0, sizeof(reallocate_data) ); - Reset_Workspace( system, workspace ); + memset(&(workspace->realloc), 0, sizeof(reallocate_data)); + Reset_Workspace(system, workspace); /* Initialize the Taper function */ - Init_Taper( control, workspace); + Init_Taper(control, workspace); return SUCCESS; } /************** setup communication data structures **************/ -int Init_MPI_Datatypes( reax_system *system, storage * /*workspace*/, - mpi_datatypes *mpi_data, MPI_Comm comm, char * /*msg*/ ) +int Init_MPI_Datatypes(reax_system *system, storage * /*workspace*/, + mpi_datatypes *mpi_data, MPI_Comm comm, char * /*msg*/) { /* setup the world */ mpi_data->world = comm; - MPI_Comm_size( comm, &(system->wsize) ); + MPI_Comm_size(comm, &(system->wsize)); return SUCCESS; } -int Init_Lists( reax_system *system, control_params *control, +int Init_Lists(reax_system *system, control_params *control, simulation_data * /*data*/, storage * /*workspace*/, reax_list **lists, - mpi_datatypes * /*mpi_data*/, char * /*msg*/ ) + mpi_datatypes * /*mpi_data*/, char * /*msg*/) { int i, total_hbonds, total_bonds, bond_cap, num_3body, cap_3body, Htop; int *hb_top, *bond_top; @@ -166,94 +168,93 @@ int Init_Lists( reax_system *system, control_params *control, int mincap = system->mincap; double safezone = system->safezone; double saferzone = system->saferzone; + LAMMPS_NS::Error *error = system->error_ptr; - bond_top = (int*) calloc( system->total_cap, sizeof(int) ); - hb_top = (int*) calloc( system->local_cap, sizeof(int) ); - Estimate_Storages( system, control, lists, + bond_top = (int*) calloc(system->total_cap, sizeof(int)); + hb_top = (int*) calloc(system->local_cap, sizeof(int)); + Estimate_Storages(system, control, lists, &Htop, hb_top, bond_top, &num_3body); if (control->hbond_cut > 0) { /* init H indexes */ total_hbonds = 0; - for( i = 0; i < system->n; ++i ) { + for(i = 0; i < system->n; ++i) { system->my_atoms[i].num_hbonds = hb_top[i]; total_hbonds += hb_top[i]; } total_hbonds = (int)(MAX(total_hbonds*saferzone,mincap*system->minhbonds)); - if( !Make_List( system->Hcap, total_hbonds, TYP_HBOND, - *lists+HBONDS ) ) { - control->error_ptr->one(FLERR, "Not enough space for hbonds list."); - } + if(!Make_List(system->Hcap, total_hbonds, TYP_HBOND, + *lists+HBONDS)) + error->one(FLERR, "Not enough space for hbonds list."); + (*lists+HBONDS)->error_ptr = system->error_ptr; } total_bonds = 0; - for( i = 0; i < system->N; ++i ) { + for(i = 0; i < system->N; ++i) { system->my_atoms[i].num_bonds = bond_top[i]; total_bonds += bond_top[i]; } - bond_cap = (int)(MAX( total_bonds*safezone, mincap*MIN_BONDS )); + bond_cap = (int)(MAX(total_bonds*safezone, mincap*MIN_BONDS)); + + if(!Make_List(system->total_cap, bond_cap, TYP_BOND, + *lists+BONDS)) + error->one(FLERR, "Not enough space for bonds list."); - if( !Make_List( system->total_cap, bond_cap, TYP_BOND, - *lists+BONDS ) ) { - control->error_ptr->one(FLERR, "Not enough space for bonds list."); - } (*lists+BONDS)->error_ptr = system->error_ptr; /* 3bodies list */ - cap_3body = (int)(MAX( num_3body*safezone, MIN_3BODIES )); - if( !Make_List( bond_cap, cap_3body, TYP_THREE_BODY, - *lists+THREE_BODIES ) ){ - control->error_ptr->one(FLERR,"Problem in initializing angles list."); - } + cap_3body = (int)(MAX(num_3body*safezone, MIN_3BODIES)); + if(!Make_List(bond_cap, cap_3body, TYP_THREE_BODY, + *lists+THREE_BODIES)) + error->one(FLERR,"Problem in initializing angles list."); + (*lists+THREE_BODIES)->error_ptr = system->error_ptr; - free( hb_top ); - free( bond_top ); + free(hb_top); + free(bond_top); return SUCCESS; } -void Initialize( reax_system *system, control_params *control, +void Initialize(reax_system *system, control_params *control, simulation_data *data, storage *workspace, reax_list **lists, output_controls *out_control, - mpi_datatypes *mpi_data, MPI_Comm comm ) + mpi_datatypes *mpi_data, MPI_Comm comm) { char msg[MAX_STR]; + LAMMPS_NS::Error *error = system->error_ptr; - if (Init_MPI_Datatypes(system, workspace, mpi_data, comm, msg) == FAILURE) { - control->error_ptr->one(FLERR,"Could not create datatypes"); - } + if (Init_MPI_Datatypes(system,workspace,mpi_data,comm,msg) == FAILURE) + error->one(FLERR,"init_mpi_datatypes: could not create datatypes. " + "Mpi_data could not be initialized! Terminating."); - if (Init_System(system, control, msg) == FAILURE) { - control->error_ptr->one(FLERR,"System could not be initialized"); - } + if (Init_System(system,control,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. System could not be " + "initialized! Terminating.",msg)); - if (Init_Simulation_Data( system, control, data, msg ) == FAILURE) { - control->error_ptr->one(FLERR,"Sim_data could not be initialized"); - } + if (Init_Simulation_Data( system,control,data,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Sim_data could not be " + "initialized! Terminating.",msg)); - if (Init_Workspace( system, control, workspace, msg ) == - FAILURE) { - control->error_ptr->one(FLERR,"Workspace could not be initialized"); - } + if (Init_Workspace( system,control,workspace,msg) == FAILURE) + error->one(FLERR,"init_workspace: not enough memory. " + "Workspace could not be initialized. Terminating."); - if (Init_Lists( system, control, data, workspace, lists, mpi_data, msg ) == - FAILURE) { - control->error_ptr->one(FLERR,"Lists could not be initialized"); - } + if (Init_Lists(system, control, data, workspace, lists, mpi_data, msg) ==FAILURE) + error->one(FLERR,fmt::format("Error on: {}. System could not be " + "initialized. Terminating.",msg)); - if (Init_Output_Files(system,control,out_control,mpi_data,msg)== FAILURE) { - control->error_ptr->one(FLERR,"Could not open output files"); - } + if (Init_Output_Files(system,control,out_control,mpi_data,msg)== FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Could not open output files! " + "Terminating.",msg)); - if (control->tabulate) { - if (Init_Lookup_Tables( system, control, workspace, mpi_data, msg ) == FAILURE) { - control->error_ptr->one(FLERR,"Lookup table could not be created"); - } - } + if (control->tabulate) + if (Init_Lookup_Tables(system,control,workspace,mpi_data,msg) == FAILURE) + error->one(FLERR,fmt::format("Error on: {}. Could not create lookup " + "table. Terminating.",msg)); - Init_Force_Functions( control ); + Init_Force_Functions(control); } From d3b5e50da325d6c55cf8ee12c14fdde247705cae Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 16:39:07 -0400 Subject: [PATCH 007/122] fix bugs in lennard/mdf pair style --- src/USER-MISC/pair_lennard_mdf.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/USER-MISC/pair_lennard_mdf.cpp b/src/USER-MISC/pair_lennard_mdf.cpp index c539bb30e2..442f30a8d7 100644 --- a/src/USER-MISC/pair_lennard_mdf.cpp +++ b/src/USER-MISC/pair_lennard_mdf.cpp @@ -259,6 +259,7 @@ double PairLJ_AB_MDF::init_one(int i, int j) lj3[i][j] = aparm[i][j]; lj4[i][j] = bparm[i][j]; + cut[j][i] = cut[i][j]; cut_inner[j][i] = cut_inner[i][j]; cut_inner_sq[j][i] = cut_inner_sq[i][j]; lj1[j][i] = lj1[i][j]; @@ -368,7 +369,7 @@ double PairLJ_AB_MDF::single(int /*i*/, int /*j*/, int itype, int jtype, dt = 30.* d*d * dd*dd * rr / dp; forcelj = forcelj*tt + philj*dt; - philj *= dt; + philj *= tt; } fforce = factor_lj*forcelj*r2inv; From 6707e64d14e7d21841a0209adb6243f0198d750a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 16:39:44 -0400 Subject: [PATCH 008/122] change class name and add write_data support with pair style lennard/mdf --- src/USER-MISC/pair_lennard_mdf.cpp | 49 ++++++++++++++++++++++-------- src/USER-MISC/pair_lennard_mdf.h | 14 +++++---- 2 files changed, 44 insertions(+), 19 deletions(-) diff --git a/src/USER-MISC/pair_lennard_mdf.cpp b/src/USER-MISC/pair_lennard_mdf.cpp index 442f30a8d7..5e7e24af67 100644 --- a/src/USER-MISC/pair_lennard_mdf.cpp +++ b/src/USER-MISC/pair_lennard_mdf.cpp @@ -32,11 +32,11 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -PairLJ_AB_MDF::PairLJ_AB_MDF(LAMMPS *lmp) : Pair(lmp) {} +PairLennardMDF::PairLennardMDF(LAMMPS *lmp) : Pair(lmp) {} /* ---------------------------------------------------------------------- */ -PairLJ_AB_MDF::~PairLJ_AB_MDF() +PairLennardMDF::~PairLennardMDF() { if (allocated) { memory->destroy(setflag); @@ -56,7 +56,7 @@ PairLJ_AB_MDF::~PairLJ_AB_MDF() /* ---------------------------------------------------------------------- */ -void PairLJ_AB_MDF::compute(int eflag, int vflag) +void PairLennardMDF::compute(int eflag, int vflag) { int i,j,ii,jj,inum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; @@ -153,7 +153,7 @@ void PairLJ_AB_MDF::compute(int eflag, int vflag) allocate all arrays ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::allocate() +void PairLennardMDF::allocate() { allocated = 1; int n = atom->ntypes; @@ -180,7 +180,7 @@ void PairLJ_AB_MDF::allocate() global settings ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::settings(int narg, char **arg) +void PairLennardMDF::settings(int narg, char **arg) { if (narg != 2) error->all(FLERR,"Illegal pair_style command"); @@ -207,7 +207,7 @@ void PairLJ_AB_MDF::settings(int narg, char **arg) set coeffs for one or more type pairs ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::coeff(int narg, char **arg) +void PairLennardMDF::coeff(int narg, char **arg) { if (narg != 4 && narg != 6) error->all(FLERR,"Incorrect args for pair coefficients"); @@ -248,7 +248,7 @@ void PairLJ_AB_MDF::coeff(int narg, char **arg) init for one type pair i,j and corresponding j,i ------------------------------------------------------------------------- */ -double PairLJ_AB_MDF::init_one(int i, int j) +double PairLennardMDF::init_one(int i, int j) { if (setflag[i][j] == 0) error->all(FLERR,"All pair coeffs are not set"); @@ -274,7 +274,7 @@ double PairLJ_AB_MDF::init_one(int i, int j) proc 0 writes to restart file ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::write_restart(FILE *fp) +void PairLennardMDF::write_restart(FILE *fp) { write_restart_settings(fp); @@ -295,7 +295,7 @@ void PairLJ_AB_MDF::write_restart(FILE *fp) proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::read_restart(FILE *fp) +void PairLennardMDF::read_restart(FILE *fp) { read_restart_settings(fp); allocate(); @@ -325,7 +325,7 @@ void PairLJ_AB_MDF::read_restart(FILE *fp) proc 0 writes to restart file ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::write_restart_settings(FILE *fp) +void PairLennardMDF::write_restart_settings(FILE *fp) { fwrite(&mix_flag,sizeof(int),1,fp); } @@ -334,7 +334,7 @@ void PairLJ_AB_MDF::write_restart_settings(FILE *fp) proc 0 reads from restart file, bcasts ------------------------------------------------------------------------- */ -void PairLJ_AB_MDF::read_restart_settings(FILE *fp) +void PairLennardMDF::read_restart_settings(FILE *fp) { int me = comm->me; if (me == 0) { @@ -343,9 +343,32 @@ void PairLJ_AB_MDF::read_restart_settings(FILE *fp) MPI_Bcast(&mix_flag,1,MPI_INT,0,world); } +/* ---------------------------------------------------------------------- + proc 0 writes to data file +------------------------------------------------------------------------- */ + +void PairLennardMDF::write_data(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + fprintf(fp,"%d %g %g\n",i,aparm[i][i],bparm[i][i]); +} + +/* ---------------------------------------------------------------------- + proc 0 writes all pairs to data file +------------------------------------------------------------------------- */ + +void PairLennardMDF::write_data_all(FILE *fp) +{ + for (int i = 1; i <= atom->ntypes; i++) + for (int j = i; j <= atom->ntypes; j++) + fprintf(fp,"%d %d %g %g %g %g\n", + i,j,aparm[i][j],bparm[i][j], + cut_inner[i][j],cut[i][j]); +} + /* ---------------------------------------------------------------------- */ -double PairLJ_AB_MDF::single(int /*i*/, int /*j*/, int itype, int jtype, +double PairLennardMDF::single(int /*i*/, int /*j*/, int itype, int jtype, double rsq, double /*factor_coul*/, double factor_lj, double &fforce) @@ -379,7 +402,7 @@ double PairLJ_AB_MDF::single(int /*i*/, int /*j*/, int itype, int jtype, /* ---------------------------------------------------------------------- */ -void *PairLJ_AB_MDF::extract(const char *str, int &dim) +void *PairLennardMDF::extract(const char *str, int &dim) { dim = 2; if (strcmp(str,"a") == 0) return (void *) aparm; diff --git a/src/USER-MISC/pair_lennard_mdf.h b/src/USER-MISC/pair_lennard_mdf.h index c4ffc80cd6..19325429ea 100644 --- a/src/USER-MISC/pair_lennard_mdf.h +++ b/src/USER-MISC/pair_lennard_mdf.h @@ -13,21 +13,21 @@ #ifdef PAIR_CLASS -PairStyle(lennard/mdf,PairLJ_AB_MDF) +PairStyle(lennard/mdf,PairLennardMDF) #else -#ifndef LMP_PAIR_LJ_AB_MDF_H -#define LMP_PAIR_LJ_AB_MDF_H +#ifndef LMP_PAIR_LENNARD_MDF_H +#define LMP_PAIR_LENNARD_MDF_H #include "pair.h" namespace LAMMPS_NS { -class PairLJ_AB_MDF : public Pair { +class PairLennardMDF : public Pair { public: - PairLJ_AB_MDF(class LAMMPS *); - virtual ~PairLJ_AB_MDF(); + PairLennardMDF(class LAMMPS *); + virtual ~PairLennardMDF(); virtual void compute(int, int); void settings(int, char **); @@ -37,6 +37,8 @@ class PairLJ_AB_MDF : public Pair { void read_restart(FILE *); void write_restart_settings(FILE *); void read_restart_settings(FILE *); + void write_data(FILE *); + void write_data_all(FILE *); double single(int, int, int, int, double, double, double, double &); void *extract(const char *, int &); From 8c849c01042af124f6e9ced02b0c59e3084ddb6d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 16:41:11 -0400 Subject: [PATCH 009/122] add test file for pair style lennard/mdf --- .../tests/mol-pair-lennard_mdf.yaml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-lennard_mdf.yaml diff --git a/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml b/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml new file mode 100644 index 0000000000..b75780b0dd --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml @@ -0,0 +1,98 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Wed Jul 29 16:33:03 202 +epsilon: 1e-12 +prerequisites: ! | + atom full + pair lennard/mdf +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: lennard/mdf 6.5 8.0 +pair_coeff: ! | + 1 1 4768.37158203125 19.53125 + 1 2 33.0002002739906 1.148916015625 + 1 3 5.189853515625 0.455625 + 1 4 22973.5604278016 42.87055906125 + 1 5 16088.5533432005 33.3863396081125 + 2 2 0.02 0.02 + 2 3 0.000633527040481567 0.0035595703125 + 2 4 294.233100455466 3.43064484 + 2 5 190.825740216415 2.57106933958137 + 3 3 4.8828125e-06 0.0003125 + 3 4 64.2866406820316 1.603579005625 + 3 5 40.0738145684046 1.17821800092827 + 4 4 92233.7203685478 85.89934592 + 4 5 66122.1953250058 67.6836765582081 + 5 5 47259.767027313 53.25022086 +extract: ! "" +natoms: 29 +init_vdwl: 608.886826631407 +init_coul: 0 +init_stress: ! |2- + 1.1501595532340364e+03 8.4498399931377435e+02 5.3493179978446233e+03 1.9073206631003094e+02 -5.4722256998409841e+02 1.0156265167829823e+03 +init_forces: ! |2 + 1 2.3205716248119748e-02 6.3247264498637448e-02 2.1672462155794558e-02 + 2 1.7785695953953416e-03 -7.6315016933434900e-03 -4.6061478106783514e-03 + 3 -4.1406742460531570e-01 1.2258759651106315e+01 8.1670672308967651e-01 + 4 -7.8008182923126306e+00 2.1840924328741669e+00 -5.5423718470808279e+00 + 5 -2.3448958816581258e+00 -3.6119309413434020e+00 1.1989013288137189e+01 + 6 -8.4697727821010929e+01 4.7621276470172569e+02 2.4211164926978136e+03 + 7 9.4748194695131090e+01 -4.8676182614583388e+02 -2.4287071008333546e+03 + 8 4.9606666544663384e-02 -1.0124796814431741e-02 1.3835454407135575e-01 + 9 -1.6809967270729500e-02 3.5972744846832404e-02 -1.2968408492055399e-02 + 10 -2.4105573261702638e+01 3.6527183553507951e+00 4.9234846276855730e+00 + 11 -2.3751168769689630e+00 -5.8599890200511693e+00 -9.6266392056711840e+00 + 12 1.3047829137810201e+01 1.0633938198160397e+01 -5.5774767421835652e+00 + 13 8.0988368446957661e+00 -3.2105917643495197e+00 -1.4830809680912457e-01 + 14 -3.3749468711004571e+00 6.8695786374183343e-01 -8.7545963681190226e+00 + 15 -2.3646583246060765e-01 8.4687094692750886e+00 3.0167535737694364e+00 + 16 6.5752851056702332e+02 -4.6624212405257379e+02 -1.7052693583177058e+03 + 17 -6.4811393234557943e+02 4.5153533332667661e+02 1.7215910357532148e+03 + 18 -4.8807845494765346e+01 -1.1659294194933142e+02 3.2038234181278256e+02 + 19 -1.5240940632714199e+02 -9.7505568105850458e+01 -1.8463595023086009e+02 + 20 2.0120268033653491e+02 2.1405935394782455e+02 -1.3571475384121879e+02 + 21 -7.1565703094766675e+01 -8.1616165466083061e+01 2.2589539403772019e+02 + 22 -1.0808844182470052e+02 -2.6193759294088157e+01 -1.6957909671801161e+02 + 23 1.7964459427251887e+02 1.0782106087332204e+02 -5.6305782597067136e+01 + 24 3.6598494828176882e+01 -2.1181268047122151e+02 1.1219379029487202e+02 + 25 -1.4851252725090720e+02 2.3908421355678481e+01 -1.2485228451502239e+02 + 26 1.1191159137780325e+02 1.8789793323484449e+02 1.2650378831856969e+01 + 27 5.1810451001013320e+01 -2.2705547076595019e+02 9.0849657423329731e+01 + 28 -1.8041305637741880e+02 7.7534084392714163e+01 -1.2206962099214840e+02 + 29 1.2861156093127474e+02 1.4952745646254431e+02 3.1215838791056235e+01 +run_vdwl: 50.3654325649429 +run_coul: 0 +run_stress: ! |2- + 2.2423561746162852e+02 1.8098594165603637e+02 2.1569623398021386e+02 1.3394797998092836e+01 3.9054517513987342e+01 2.8220540925316602e+00 +run_forces: ! |2 + 1 2.5193442060142082e-02 6.6503690074336846e-02 2.3195488606834364e-02 + 2 1.6990317185901405e-03 -7.5241416216971215e-03 -4.2329822487542860e-03 + 3 -2.9651313197309257e+01 3.8961004256560656e+01 8.7342633734819000e+00 + 4 -6.7931766820287187e+00 1.7833923938384340e+00 -4.9653883805325965e+00 + 5 -1.9803775673778827e+00 -3.1575619396201331e+00 1.0226407688568608e+01 + 6 3.7335347254274360e+01 -3.3548029227617228e+01 4.2728620649582121e+00 + 7 5.3885823996002391e-01 -3.6860516589172940e+00 -1.8541743863999837e+01 + 8 2.1188759066213489e-01 -1.6034826817740044e-01 1.4748941975747917e-01 + 9 4.2041812212206186e-03 2.5616510758399658e-02 1.0124866713187072e-02 + 10 -3.0013601624712987e+01 1.1883479333075982e+01 7.0471148016459562e-01 + 11 -1.7562108882334935e+00 -4.4777752352252875e+00 -7.3302191435541939e+00 + 12 1.2125320419614738e+01 9.3509197422035442e+00 -6.4765758668976474e+00 + 13 7.2521194028897877e+00 -2.7588786914569869e+00 -1.0596601467524230e-01 + 14 -2.7645374261619211e+00 4.3936995953736563e-01 -7.1011869577865134e+00 + 15 -4.2463018691718912e-01 8.1059551844950661e+00 3.0762909509338234e+00 + 16 2.5762075721361111e+01 -2.9654182830717197e+01 -9.4768325928545813e+00 + 17 -9.8565754859910140e+00 6.8586808627860547e+00 2.6776650615004602e+01 + 18 5.0087996131666745e+00 -3.0217475716635818e+00 3.3916685446701315e+01 + 19 -1.9102793342926901e+01 -1.2206121773899412e+01 -2.4001193794775045e+01 + 20 1.4081623428739668e+01 1.5191603478437127e+01 -9.8844498964030443e+00 + 21 -9.9353060096612431e+00 -1.2018676998693389e+01 3.8870411683239908e+01 + 22 -1.8317805824924630e+01 -4.4399492899391237e+00 -2.9440598916903120e+01 + 23 2.8242473691942649e+01 1.6470775503137673e+01 -9.4179834333324095e+00 + 24 1.2420703214265618e+01 -3.6421044879421615e+01 2.3805698983947405e+01 + 25 -3.0028534150842702e+01 5.3814046923605190e+00 -2.5773190949900478e+01 + 26 1.7605153574106566e+01 3.1032680149080115e+01 1.9588405408040199e+00 + 27 3.4728623370095133e+00 -3.8995630560776561e+01 1.1703630996134580e+01 + 28 -2.5472381375549382e+01 1.1754688150327866e+01 -1.7174760736538509e+01 + 29 2.2008922619644508e+01 2.7247449161073781e+01 5.4670599313855304e+00 +... From 2c3f9b111a4d3f78add249ec45f868edb99d8489 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 29 Jul 2020 21:36:24 -0400 Subject: [PATCH 010/122] whitespace cleanup: replace tabs and remove trailing blanks --- src/MC/fix_widom.h | 4 ++-- src/balance.cpp | 8 ++++---- src/comm_tiled.cpp | 30 +++++++++++++++--------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/MC/fix_widom.h b/src/MC/fix_widom.h index 8dd77df28c..05060e76ac 100644 --- a/src/MC/fix_widom.h +++ b/src/MC/fix_widom.h @@ -32,7 +32,7 @@ class FixWidom : public Fix { int setmask(); void init(); void pre_exchange(); - + void attempt_atomic_insertion(); void attempt_molecule_insertion(); @@ -207,7 +207,7 @@ is on. E: Cannot use fix Widom in a 2d simulation -Fix Widom is set up to run in 3d only. No 2d simulations with fix Widom +Fix Widom is set up to run in 3d only. No 2d simulations with fix Widom are allowed. E: Could not find fix Widom exclusion group ID diff --git a/src/balance.cpp b/src/balance.cpp index 8c1e7a4ed7..d6579e9199 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -573,8 +573,8 @@ int *Balance::bisection(int sortflag) int triclinic = domain->triclinic; double *boxlo,*boxhi,*prd; - - if (triclinic == 0) { + + if (triclinic == 0) { boxlo = domain->boxlo; boxhi = domain->boxhi; prd = domain->prd; @@ -587,7 +587,7 @@ int *Balance::bisection(int sortflag) // shrink-wrap simulation box around atoms for input to RCB // leads to better-shaped sub-boxes when atoms are far from box boundaries // if triclinic, do this in lamda coords - + double shrink[6],shrinkall[6]; shrink[0] = boxhi[0]; shrink[1] = boxhi[1]; shrink[2] = boxhi[2]; @@ -597,7 +597,7 @@ int *Balance::bisection(int sortflag) int nlocal = atom->nlocal; if (triclinic) domain->x2lamda(nlocal); - + for (int i = 0; i < nlocal; i++) { shrink[0] = MIN(shrink[0],x[i][0]); shrink[1] = MIN(shrink[1],x[i][1]); diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index de02823ec8..b7878ea86a 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -98,7 +98,7 @@ void CommTiled::init() Comm::init(); nswap = 2 * domain->dimension; - + int bufextra_old = bufextra; init_exchange(); if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2); @@ -192,7 +192,7 @@ void CommTiled::setup() cut = MIN(prd[0],prd[1]); if (dimension == 3) cut = MIN(cut,prd[2]); cut *= EPSILON*EPSILON; - cutghost[0] = cutghost[1] = cutghost[2] = cut; + cutghost[0] = cutghost[1] = cutghost[2] = cut; } // setup forward/reverse communication @@ -325,16 +325,16 @@ void CommTiled::setup() sbox[3] = MIN(oboxhi[0],hi1[0]); sbox[4] = MIN(oboxhi[1],hi1[1]); sbox[5] = MIN(oboxhi[2],hi1[2]); - + } else { pbc_flag[iswap][i] = 1; if (idir == 0) pbc[iswap][i][idim] = 1; else pbc[iswap][i][idim] = -1; - if (triclinic) { + if (triclinic) { if (idim == 1) pbc[iswap][i][5] = pbc[iswap][i][idim]; if (idim == 2) pbc[iswap][i][4] = pbc[iswap][i][3] = pbc[iswap][i][idim]; } - + sbox[0] = MAX(oboxlo[0],lo2[0]); sbox[1] = MAX(oboxlo[1],lo2[1]); sbox[2] = MAX(oboxlo[2],lo2[2]); @@ -346,7 +346,7 @@ void CommTiled::setup() if (idir == 0) { sbox[idim] = sublo[idim]; if (i < noverlap1) - sbox[3+idim] = MIN(sbox[3+idim]+cutghost[idim],subhi[idim]); + sbox[3+idim] = MIN(sbox[3+idim]+cutghost[idim],subhi[idim]); else sbox[3+idim] = MIN(sbox[3+idim]-prd[idim]+cutghost[idim],subhi[idim]); } else { if (i < noverlap1) sbox[idim] = MAX(sbox[idim]-cutghost[idim],sublo[idim]); @@ -370,7 +370,7 @@ void CommTiled::setup() } } - + // setup exchange communication = subset of forward/reverse comm procs // loop over dimensions // determine which procs I will exchange with in each dimension @@ -717,10 +717,10 @@ void CommTiled::exchange() buf_send[nsend++] = proc; nsend += avec->pack_exchange(i,&buf_send[nsend]); } else { - // DEBUG statment - // error->warning(FLERR,"Losing atom in CommTiled::exchange() send, " - // "likely bad dynamics"); - } + // DEBUG statment + // error->warning(FLERR,"Losing atom in CommTiled::exchange() send, " + // "likely bad dynamics"); + } avec->copy(nlocal-1,i,1); nlocal--; } else i++; @@ -769,10 +769,10 @@ void CommTiled::exchange() if (value >= lo && value < hi) { m += avec->unpack_exchange(&buf_recv[m]); continue; - } else { - // DEBUG statment - // error->warning(FLERR,"Losing atom in CommTiled::exchange() recv"); - } + } else { + // DEBUG statment + // error->warning(FLERR,"Losing atom in CommTiled::exchange() recv"); + } } m += static_cast (buf_recv[m]); } From 36f4e6789ae54a92ee26e568a35ea0dd40b5048e Mon Sep 17 00:00:00 2001 From: abhishandy Date: Thu, 30 Jul 2020 03:30:57 -0400 Subject: [PATCH 011/122] simple test for pair-born --- .../force-styles/tests/atomic-pair-born.yaml | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 unittest/force-styles/tests/atomic-pair-born.yaml diff --git a/unittest/force-styles/tests/atomic-pair-born.yaml b/unittest/force-styles/tests/atomic-pair-born.yaml new file mode 100644 index 0000000000..89c43d44e9 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-born.yaml @@ -0,0 +1,89 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Thu Jul 30 03:30:06 202 +epsilon: 5e-13 +prerequisites: ! | + pair born +pre_commands: ! "" +post_commands: ! "" +input_file: in.metal +pair_style: born 8.0 +pair_coeff: ! | + * * 6.08 0.317 2.340 24.18 11.51 +extract: ! "" +natoms: 32 +init_vdwl: 836.893711811487 +init_coul: 0 +init_stress: ! |2- + 2.1907762159508770e+03 2.1533146615415390e+03 2.1384803888060319e+03 3.1458958046100697e+01 -5.2331768978302460e+00 -1.2410855173406260e+01 +init_forces: ! |2 + 1 6.1952278656609625e+00 1.6628887543469570e+01 2.3406241273969628e+00 + 2 -7.1498478250272974e+00 -1.9650729468423989e+01 1.3392331597463706e+01 + 3 -8.4302759991532952e+00 4.5935465074977714e+01 -1.1339628764311961e+01 + 4 6.6013347699419995e+00 -2.2770126898611998e+00 -1.4793531675390774e+01 + 5 8.8132464681297229e+00 3.2091565756514420e+01 1.0510805603350610e+01 + 6 1.0484038408463748e+01 9.4085458810652689e+00 -1.1561120732403498e+00 + 7 -1.4142880457618997e+01 2.1179702223374814e+01 -1.6277650983857441e+00 + 8 -1.6212550653790164e+01 -1.5776737518534750e+01 8.2546279217585035e+00 + 9 2.2842749772666266e+00 -1.5405998927734670e+01 -6.1169286615136649e+00 + 10 -5.6088561559285921e+00 -2.9980200955395699e+01 -2.8361114533155039e+01 + 11 -1.0796936404967482e+01 -1.4085775254255909e+01 1.0322820000470387e+01 + 12 4.9935473695250936e+00 -2.0508984017848242e+01 -3.9212800338387188e-01 + 13 -3.8342965060925644e+00 5.8453344255223003e+00 -1.1781310586322938e+01 + 14 1.2960559403161112e+01 -5.7879190752621907e+00 1.6324972340830911e+01 + 15 -7.5631698457336611e+00 7.5962132139231553e+00 -7.5008652746855180e+00 + 16 2.7227909176641056e+01 -2.2159697717922022e+01 9.0018115646343890e+00 + 17 9.6743623705665449e+00 3.1763667293227797e+01 1.7437438229370321e+00 + 18 -3.3175129754412701e+01 -5.7620879906320663e+00 -1.6758037406277673e+01 + 19 -3.4363169461589663e+01 -1.6361294228706516e+01 9.5257528857146188e+00 + 20 6.3606452908246656e+00 4.8320683138296658e+00 -7.1004418004298362e+00 + 21 3.7194448979025765e+01 1.0842684015015067e+01 3.9593216918575974e-01 + 22 4.0813085193467058e-01 -2.1849731691352865e+01 -1.5393240154689587e+00 + 23 9.0194539312342243e+00 2.7646519773287814e+01 -1.8893395925821068e+01 + 24 2.7633552340313585e+01 2.1176334996344043e+01 1.9050374400981202e+01 + 25 1.8215010599705714e+01 7.8343723407555865e-01 -1.1516192459397450e+01 + 26 -9.6728258529328315e+00 -3.3921248222992517e+01 2.9174727715069260e+01 + 27 1.0237099691004113e+01 1.1774417628369038e+00 9.0059613217903767e-01 + 28 5.7207612737003188e+00 1.2091973176094161e+01 1.6885831883966489e+01 + 29 8.0920152886696819e+00 2.3976025150348377e+01 -1.0543989422319544e+00 + 30 -1.2005631838887281e+01 -6.4092999695138637e+00 -1.9850411539058847e+01 + 31 -5.5566952298732328e+00 -2.8420402803389738e+01 1.7818115115845121e+01 + 32 -4.3603353069761802e+01 -1.4618745302080386e+01 -5.8614805227083417e+00 +run_vdwl: 808.581991307929 +run_coul: 0 +run_stress: ! |2- + 2.1352577876164714e+03 2.1048336346087822e+03 2.0866093207888316e+03 1.6710708502154183e+01 -7.2805172515122214e+00 -5.1007546794256298e+00 +run_forces: ! |2 + 1 4.3996728759831116e+00 1.3617808952853350e+01 3.9365269387608910e+00 + 2 -5.8870109187129227e+00 -1.6653786974892565e+01 1.0458442718468866e+01 + 3 -2.5384607642764081e+00 2.7976453386304165e+01 -7.9538384346985778e+00 + 4 2.6011652570379979e+00 3.4444982822291809e-01 -1.4078044299688214e+01 + 5 6.2739400167978490e+00 2.3321353952206238e+01 9.8524679762955127e+00 + 6 9.7615972917437634e+00 9.8314066166309821e+00 9.1579317972042351e-01 + 7 -8.4994423410616129e+00 1.7133945132359301e+01 -2.1335415687539081e+00 + 8 -1.4401879593786829e+01 -1.0717410919398073e+01 6.2772265942246497e+00 + 9 2.4581092844990748e+00 -1.5139809581001368e+01 -6.0486224458444502e+00 + 10 5.7295535185278368e-01 -2.2473696014663325e+01 -1.8469640259236243e+01 + 11 -8.3438231201666824e+00 -1.1773385047512056e+01 8.0911869578298905e+00 + 12 5.6018202198927955e+00 -1.3190833667603776e+01 3.2425752936252150e-01 + 13 -5.1665403937031575e+00 3.8641569820964516e+00 -8.0278457568777704e+00 + 14 1.1059028830337486e+01 -3.5867141219142817e-01 8.3359673389637585e+00 + 15 -7.0225257033738311e+00 3.4315031664638429e+00 -5.9505539807290697e+00 + 16 1.5086691796848593e+01 -1.7105542466895855e+01 6.8923022058483863e+00 + 17 7.7552246185118392e+00 2.3712928096926632e+01 -1.1565629751691666e+00 + 18 -2.2415417000611026e+01 -5.6849910964810348e+00 -1.0167777125296530e+01 + 19 -2.2914820778853272e+01 -9.2271207471412673e+00 6.1677237945523231e+00 + 20 6.5866441066676380e+00 6.2266458578595580e+00 -6.7918108679194686e+00 + 21 2.5378769975471076e+01 6.5502175694342872e+00 2.7113928300966954e+00 + 22 1.4722121850540351e+00 -1.6174770388907241e+01 -3.6146790093186110e+00 + 23 3.9177677709068743e+00 1.6640247776368867e+01 -1.5217886244976798e+01 + 24 1.6292888686152281e+01 1.6539457853286358e+01 1.3246494291709737e+01 + 25 1.2399183978889422e+01 2.2450939828300065e+00 -8.4542270100046313e+00 + 26 -5.5487323330521612e+00 -2.0228255850187249e+01 1.8528693239502584e+01 + 27 7.5279483917695700e+00 -3.0072122179470506e+00 6.9304022265424459e-01 + 28 -3.8508457491974468e-01 9.5889969664907753e+00 1.3098728886480401e+01 + 29 5.7371217847825058e+00 1.5830079463104170e+01 -9.7700534543667272e-01 + 30 -7.4069396659644475e+00 -5.7323481111133043e+00 -1.2021778057070120e+01 + 31 -3.9192345419264893e+00 -2.1509286285601934e+01 1.3203747851309895e+01 + 32 -3.0432830692790130e+01 -7.8776248019003354e+00 -1.6701791747605144e+00 +... From facb2f3c27ba3c1b185ffc60f88fe9807d65b46b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Jul 2020 11:44:37 -0400 Subject: [PATCH 012/122] fix error in determining A/B parameters. outputs now match lj/mdf as expected. --- .../tests/mol-pair-lennard_mdf.yaml | 149 +++++++++--------- 1 file changed, 75 insertions(+), 74 deletions(-) diff --git a/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml b/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml index b75780b0dd..caa4e04edc 100644 --- a/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml +++ b/unittest/force-styles/tests/mol-pair-lennard_mdf.yaml @@ -1,7 +1,7 @@ --- lammps_version: 21 Jul 2020 -date_generated: Wed Jul 29 16:33:03 202 -epsilon: 1e-12 +date_generated: Thu Jul 30 11:43:01 202 +epsilon: 5e-14 prerequisites: ! | atom full pair lennard/mdf @@ -12,87 +12,88 @@ pair_style: lennard/mdf 6.5 8.0 pair_coeff: ! | 1 1 4768.37158203125 19.53125 1 2 33.0002002739906 1.148916015625 - 1 3 5.189853515625 0.455625 - 1 4 22973.5604278016 42.87055906125 + 1 3 22973.5604278016 42.87055906125 + 1 4 16088.5533432005 33.3863396081125 1 5 16088.5533432005 33.3863396081125 2 2 0.02 0.02 - 2 3 0.000633527040481567 0.0035595703125 - 2 4 294.233100455466 3.43064484 + 2 3 294.233100455466 3.43064484 + 2 4 4.8828125e-06 0.0003125 2 5 190.825740216415 2.57106933958137 - 3 3 4.8828125e-06 0.0003125 - 3 4 64.2866406820316 1.603579005625 - 3 5 40.0738145684046 1.17821800092827 - 4 4 92233.7203685478 85.89934592 - 4 5 66122.1953250058 67.6836765582081 + 3 3 92233.7203685478 85.89934592 + 3 4 66122.1953250058 67.6836765582081 + 3 5 66122.1953250058 67.6836765582081 + 4 4 47259.767027313 53.25022086 + 4 5 47259.767027313 53.25022086 5 5 47259.767027313 53.25022086 -extract: ! "" +extract: ! | + a 2 natoms: 29 -init_vdwl: 608.886826631407 +init_vdwl: 749.238128769917 init_coul: 0 init_stress: ! |2- - 1.1501595532340364e+03 8.4498399931377435e+02 5.3493179978446233e+03 1.9073206631003094e+02 -5.4722256998409841e+02 1.0156265167829823e+03 + 2.1793844857971999e+03 2.1988910807167222e+03 4.6653956464347129e+03 -7.5956623392527081e+02 2.4752218664716132e+01 6.6652254832700407e+02 init_forces: ! |2 - 1 2.3205716248119748e-02 6.3247264498637448e-02 2.1672462155794558e-02 - 2 1.7785695953953416e-03 -7.6315016933434900e-03 -4.6061478106783514e-03 - 3 -4.1406742460531570e-01 1.2258759651106315e+01 8.1670672308967651e-01 - 4 -7.8008182923126306e+00 2.1840924328741669e+00 -5.5423718470808279e+00 - 5 -2.3448958816581258e+00 -3.6119309413434020e+00 1.1989013288137189e+01 - 6 -8.4697727821010929e+01 4.7621276470172569e+02 2.4211164926978136e+03 - 7 9.4748194695131090e+01 -4.8676182614583388e+02 -2.4287071008333546e+03 - 8 4.9606666544663384e-02 -1.0124796814431741e-02 1.3835454407135575e-01 - 9 -1.6809967270729500e-02 3.5972744846832404e-02 -1.2968408492055399e-02 - 10 -2.4105573261702638e+01 3.6527183553507951e+00 4.9234846276855730e+00 - 11 -2.3751168769689630e+00 -5.8599890200511693e+00 -9.6266392056711840e+00 - 12 1.3047829137810201e+01 1.0633938198160397e+01 -5.5774767421835652e+00 - 13 8.0988368446957661e+00 -3.2105917643495197e+00 -1.4830809680912457e-01 - 14 -3.3749468711004571e+00 6.8695786374183343e-01 -8.7545963681190226e+00 - 15 -2.3646583246060765e-01 8.4687094692750886e+00 3.0167535737694364e+00 - 16 6.5752851056702332e+02 -4.6624212405257379e+02 -1.7052693583177058e+03 - 17 -6.4811393234557943e+02 4.5153533332667661e+02 1.7215910357532148e+03 - 18 -4.8807845494765346e+01 -1.1659294194933142e+02 3.2038234181278256e+02 - 19 -1.5240940632714199e+02 -9.7505568105850458e+01 -1.8463595023086009e+02 - 20 2.0120268033653491e+02 2.1405935394782455e+02 -1.3571475384121879e+02 - 21 -7.1565703094766675e+01 -8.1616165466083061e+01 2.2589539403772019e+02 - 22 -1.0808844182470052e+02 -2.6193759294088157e+01 -1.6957909671801161e+02 - 23 1.7964459427251887e+02 1.0782106087332204e+02 -5.6305782597067136e+01 - 24 3.6598494828176882e+01 -2.1181268047122151e+02 1.1219379029487202e+02 - 25 -1.4851252725090720e+02 2.3908421355678481e+01 -1.2485228451502239e+02 - 26 1.1191159137780325e+02 1.8789793323484449e+02 1.2650378831856969e+01 - 27 5.1810451001013320e+01 -2.2705547076595019e+02 9.0849657423329731e+01 - 28 -1.8041305637741880e+02 7.7534084392714163e+01 -1.2206962099214840e+02 - 29 1.2861156093127474e+02 1.4952745646254431e+02 3.1215838791056235e+01 -run_vdwl: 50.3654325649429 + 1 -2.3333456445729308e+01 2.6994541715130174e+02 3.3272836403600138e+02 + 2 1.5828554631286457e+02 1.3025008843150334e+02 -1.8629682358090739e+02 + 3 -1.3528903744071818e+02 -3.8704313350789715e+02 -1.4568978426110166e+02 + 4 -7.8711102183152653e+00 2.1350433612475337e+00 -5.5954483189689057e+00 + 5 -2.5176757267276115e+00 -4.0521510680612840e+00 1.2152704057983788e+01 + 6 -8.3190657145323701e+02 9.6394157585967673e+02 1.1509101058588756e+03 + 7 5.8203391152120780e+01 -3.3609018510471799e+02 -1.7179623897115050e+03 + 8 1.4451392646293473e+02 -1.0927476052490431e+02 3.9990594285329564e+02 + 9 7.9156945404948118e+01 8.5273009664329706e+01 3.5032175683823232e+02 + 10 5.3118875274635047e+02 -6.1040990309251686e+02 -1.8355872279721592e+02 + 11 -2.3530151263226644e+00 -5.9077525030323867e+00 -9.6590611210259372e+00 + 12 1.7527040556419166e+01 1.0633031637151417e+01 -7.9253531066396325e+00 + 13 8.0986456357509482e+00 -3.2098047359651849e+00 -1.4896595191878603e-01 + 14 -3.3852718245345126e+00 6.8637005694452435e-01 -8.7507089611400559e+00 + 15 -2.0454759617429094e-01 8.4846189340026168e+00 3.0131599324912615e+00 + 16 4.6326331422454814e+02 -3.3087729037420274e+02 -1.1893030196750653e+03 + 17 -4.5334322511776759e+02 3.1554322933650400e+02 1.2058421140909506e+03 + 18 -1.8856205920908232e-02 -3.3657380846641591e-02 3.1345559228195895e-02 + 19 3.2119183384465589e-04 -2.4442950403900178e-04 1.7531402321548882e-03 + 20 -9.9797590977484174e-04 -1.0244014514626872e-03 3.9741350958193128e-04 + 21 -7.1566239135890754e+01 -8.1615637646874490e+01 2.2589575706544480e+02 + 22 -1.0808841110845918e+02 -2.6193795811011739e+01 -1.6957912582510812e+02 + 23 1.7964463249215564e+02 1.0782103141601063e+02 -5.6305809828670455e+01 + 24 3.6591395075232896e+01 -2.1181605371471514e+02 1.1218279667490484e+02 + 25 -1.4851496073494792e+02 2.3907129094414373e+01 -1.2485640713592730e+02 + 26 1.1191134635354324e+02 1.8789782100385878e+02 1.2650134235513654e+01 + 27 5.1810629413951034e+01 -2.2705426061698427e+02 9.0848881987846823e+01 + 28 -1.8041314536249808e+02 7.7534100857114538e+01 -1.2206963127965679e+02 + 29 1.2861063445049953e+02 1.4952718810862598e+02 3.1216037810340779e+01 +run_vdwl: 146.142938771306 run_coul: 0 run_stress: ! |2- - 2.2423561746162852e+02 1.8098594165603637e+02 2.1569623398021386e+02 1.3394797998092836e+01 3.9054517513987342e+01 2.8220540925316602e+00 + 6.2607827422370826e+02 6.7185771646959927e+02 4.8484269825432062e+02 -3.1994971119380659e+02 -2.8453599030981216e+01 1.2292331223237372e+02 run_forces: ! |2 - 1 2.5193442060142082e-02 6.6503690074336846e-02 2.3195488606834364e-02 - 2 1.6990317185901405e-03 -7.5241416216971215e-03 -4.2329822487542860e-03 - 3 -2.9651313197309257e+01 3.8961004256560656e+01 8.7342633734819000e+00 - 4 -6.7931766820287187e+00 1.7833923938384340e+00 -4.9653883805325965e+00 - 5 -1.9803775673778827e+00 -3.1575619396201331e+00 1.0226407688568608e+01 - 6 3.7335347254274360e+01 -3.3548029227617228e+01 4.2728620649582121e+00 - 7 5.3885823996002391e-01 -3.6860516589172940e+00 -1.8541743863999837e+01 - 8 2.1188759066213489e-01 -1.6034826817740044e-01 1.4748941975747917e-01 - 9 4.2041812212206186e-03 2.5616510758399658e-02 1.0124866713187072e-02 - 10 -3.0013601624712987e+01 1.1883479333075982e+01 7.0471148016459562e-01 - 11 -1.7562108882334935e+00 -4.4777752352252875e+00 -7.3302191435541939e+00 - 12 1.2125320419614738e+01 9.3509197422035442e+00 -6.4765758668976474e+00 - 13 7.2521194028897877e+00 -2.7588786914569869e+00 -1.0596601467524230e-01 - 14 -2.7645374261619211e+00 4.3936995953736563e-01 -7.1011869577865134e+00 - 15 -4.2463018691718912e-01 8.1059551844950661e+00 3.0762909509338234e+00 - 16 2.5762075721361111e+01 -2.9654182830717197e+01 -9.4768325928545813e+00 - 17 -9.8565754859910140e+00 6.8586808627860547e+00 2.6776650615004602e+01 - 18 5.0087996131666745e+00 -3.0217475716635818e+00 3.3916685446701315e+01 - 19 -1.9102793342926901e+01 -1.2206121773899412e+01 -2.4001193794775045e+01 - 20 1.4081623428739668e+01 1.5191603478437127e+01 -9.8844498964030443e+00 - 21 -9.9353060096612431e+00 -1.2018676998693389e+01 3.8870411683239908e+01 - 22 -1.8317805824924630e+01 -4.4399492899391237e+00 -2.9440598916903120e+01 - 23 2.8242473691942649e+01 1.6470775503137673e+01 -9.4179834333324095e+00 - 24 1.2420703214265618e+01 -3.6421044879421615e+01 2.3805698983947405e+01 - 25 -3.0028534150842702e+01 5.3814046923605190e+00 -2.5773190949900478e+01 - 26 1.7605153574106566e+01 3.1032680149080115e+01 1.9588405408040199e+00 - 27 3.4728623370095133e+00 -3.8995630560776561e+01 1.1703630996134580e+01 - 28 -2.5472381375549382e+01 1.1754688150327866e+01 -1.7174760736538509e+01 - 29 2.2008922619644508e+01 2.7247449161073781e+01 5.4670599313855304e+00 + 1 1.2964000396689146e+01 8.0892267678816864e+01 6.0323237031964297e+01 + 2 1.8550219067108042e+01 1.4016234288534708e+01 -2.2757514465613156e+01 + 3 -2.4823731194481803e+02 1.0508770689878342e+02 8.6172340602494984e+01 + 4 -8.6006937785047128e+00 3.1744103796518282e+00 -6.2092116768831902e+00 + 5 -1.7308376426194816e+00 -2.5575752575563615e+00 1.0273464022561958e+01 + 6 1.1683409017502134e+02 -9.8726850559552091e+01 -1.4208744781635963e+02 + 7 3.8041358692158358e+00 -1.0705007215066624e+01 -4.2399446322832375e+01 + 8 -1.9935799766053112e+01 1.9886787977710259e+01 5.5348128888062327e+01 + 9 1.1205806049421172e+01 1.3198926774269228e+01 4.9879830296866828e+01 + 10 6.4812479379225579e+01 -7.6374990958105826e+01 -7.5660080738756506e+01 + 11 -6.2988692484756150e+00 -8.0952467316475403e+00 -1.6391401801081937e+01 + 12 1.4369329449673979e+01 1.2193215509952948e+01 -8.2527090649331516e+00 + 13 7.3377104327473912e+00 -2.7954976458396401e+00 -1.0299311972585752e-01 + 14 -2.7952420267096518e+00 4.3889411992317034e-01 -7.1100894724883545e+00 + 15 -3.9779622065865505e-01 8.1106030137207288e+00 3.0711098878236167e+00 + 16 5.2787474086118777e+01 -6.7733534176990759e+01 1.5088298239601448e+01 + 17 -1.4633177660642183e+01 1.0014392510695107e+01 4.0799972741104774e+01 + 18 -1.8058839496734813e-02 -3.1846480759107010e-02 2.9996583084227670e-02 + 19 2.5788523138616643e-04 -2.4689081230698301e-04 1.6839267797863844e-03 + 20 -8.8284959462040197e-04 -9.1548924391997993e-04 3.8796476197999974e-04 + 21 -9.9361952309492949e+00 -1.2017775020353746e+01 3.8871115643964693e+01 + 22 -1.8317763935337126e+01 -4.4399886451888442e+00 -2.9440610409402939e+01 + 23 2.8242484527873138e+01 1.6470730701095345e+01 -9.4179941582837472e+00 + 24 1.2413262420490618e+01 -3.6423612222048455e+01 2.3794298924499856e+01 + 25 -3.0031415092604043e+01 5.3796434394870465e+00 -2.5778439006629586e+01 + 26 1.7604732980064579e+01 3.1032191967689151e+01 1.9586447754505298e+00 + 27 3.4727551332751974e+00 -3.8994887375138603e+01 1.1702853254878343e+01 + 28 -2.5472489346144421e+01 1.1754711219486996e+01 -1.7174787246988220e+01 + 29 2.2007795730451438e+01 2.7247258188486931e+01 5.4673625160789685e+00 ... From 1ae785132c976f8d80ea7b0241951cb863c693e7 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 30 Jul 2020 12:08:15 -0400 Subject: [PATCH 013/122] Add codecov.yml --- .github/codecov.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/codecov.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000000..0ca22a0185 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,23 @@ +comment: false +coverage: + notify: + slack: + default: + url: "secret:HWZbvgtc6OD7F3v3PfrK3/rzCJvScbh69Fi1CkLwuHK0+wIBIHVR+Q5i7q6F9Ln4OChbiRGtYAEUUsT8/jmBu4qDpIi8mx746codc0z/Z3aafLd24pBrCEPLvdCfIZxqPnw3TuUgGhwmMDZf0+thg8YNUr/MbOZ7Li2L6+ZbYuA=" + threshold: 10% + only_pulls: false + branches: + - "master" + flags: + - "unit" + paths: + - "src" + status: + project: + default: + branches: + - "master" + paths: + - "src" + informational: true + patch: off From 763fa426cf227da9af5db99b3112cb1359c7a3cc Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 30 Jul 2020 12:21:40 -0400 Subject: [PATCH 014/122] Enable patch status --- .github/codecov.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index 0ca22a0185..9808bfac83 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -20,4 +20,3 @@ coverage: paths: - "src" informational: true - patch: off From 45af603c04120e63cda548a17e402ce9c2197898 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 30 Jul 2020 12:26:55 -0400 Subject: [PATCH 015/122] Make patch informational too --- .github/codecov.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/codecov.yml b/.github/codecov.yml index 9808bfac83..4645f52f7f 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -20,3 +20,10 @@ coverage: paths: - "src" informational: true + patch: + default: + branches: + - "master" + paths: + - "src" + informational: true From 814e2e9aaf5f7e4250a121094aa6276b0a05c65e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Jul 2020 23:41:24 -0400 Subject: [PATCH 016/122] turn off optimization for Clang compilers when compiling atom style tester --- unittest/formats/test_atom_styles.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/unittest/formats/test_atom_styles.cpp b/unittest/formats/test_atom_styles.cpp index 8e10fa0253..630ff1ba7f 100644 --- a/unittest/formats/test_atom_styles.cpp +++ b/unittest/formats/test_atom_styles.cpp @@ -33,6 +33,8 @@ #if !defined(_FORTIFY_SOURCE) || (_FORTIFY_SOURCE == 0) #if defined(__INTEL_COMPILER) #define _do_nothing +#elif defined(__clang__) +#pragma clang optimize off #elif defined(__GNUC__) #if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) #pragma GCC optimize("no-var-tracking-assignments", "O0") From 8cb63194aac94d5e56830f282573448f7caad74c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 30 Jul 2020 23:42:03 -0400 Subject: [PATCH 017/122] optimize utils::strmatch() by using const string reference --- src/utils.cpp | 2 +- src/utils.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 4efa35a8d1..7e1229dc0f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -82,7 +82,7 @@ using namespace LAMMPS_NS; * even with char * type variables. * Example: utils::strmatch(text, std::string("^") + charptr) */ -bool utils::strmatch(std::string text, std::string pattern) +bool utils::strmatch(const std::string &text, const std::string &pattern) { const int pos = re_match(text.c_str(),pattern.c_str()); return (pos >= 0); diff --git a/src/utils.h b/src/utils.h index abaa87ca5f..91001c0fb0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -35,7 +35,7 @@ namespace LAMMPS_NS { * \param pattern the search pattern, which may contain regexp markers * \return true if the pattern matches, false if not */ - bool strmatch(std::string text, std::string pattern); + bool strmatch(const std::string &text, const std::string &pattern); /** \brief Send message to screen and logfile, if available * @@ -148,7 +148,7 @@ namespace LAMMPS_NS { * \param line string that should be trimmed * \return new string without comment (string) */ - std::string trim_comment(const std::string & line); + std::string trim_comment(const std::string &line); /** * \brief Count words in string From 1f1263645ea4f4599d2de69fbd2dd9a8fc6b243e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 31 Jul 2020 11:03:26 -0400 Subject: [PATCH 018/122] Document warning about short communication cutoff vs. bond length based estimate --- doc/src/Errors_warnings.rst | 18 ++++++++++++++++++ src/comm.h | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/doc/src/Errors_warnings.rst b/doc/src/Errors_warnings.rst index ceccc0b74c..306c9b7b31 100644 --- a/doc/src/Errors_warnings.rst +++ b/doc/src/Errors_warnings.rst @@ -118,6 +118,24 @@ Doc page with :doc:`ERROR messages ` incorrect periodic images of atoms in interaction lists. To avoid, either use :doc:`pair style zero ` with a suitable cutoff or use :doc:`comm_modify cutoff `. +*Communication cutoff is shorter than a bond length based estimate. This may lead to errors.* + + Since LAMMPS stores topology data with individual atoms, all atoms + comprising a bond, angle, dihedral or improper must be present on any + sub-domain that "owns" the atom with the information, either as a + local or a ghost atom. The communication cutoff is what determines up + to what distance from a sub-domain boundary ghost atoms are created. + The communication cutoff is by default the largest non-bonded cutoff + plus the neighbor skin distance, but for short or non-bonded cutoffs + and/or long bonds, this may not be sufficient. This warning indicates + that there is an increased risk of a simulation stopping unexpectedly + because of Bond/Angle/Dihedral/Improper atoms missing. It can be + silenced by manually setting the communication cutoff via + :doc:`comm_modify cutoff `. However, since the + heuristic used to determine the estimate is not always accurate, it + is not changed automatically and the warning may be ignored depending + on the specific system being simulated. + *Communication cutoff is too small for SNAP micro load balancing, increased to %lf* Self-explanatory. diff --git a/src/comm.h b/src/comm.h index d308a26367..1743436e22 100644 --- a/src/comm.h +++ b/src/comm.h @@ -253,6 +253,22 @@ be generated and LAMMPS may lose atoms or use incorrect periodic images of atoms interaction lists. To avoid, either define pair style zero with a suitable cutoff or use comm_modify cutoff. +W: Communication cutoff is shorter than a bond length based estimate. This may lead to errors. + +Since LAMMPS stores topology data with individual atoms, all atoms comprising +a bond, angle, dihedral or improper must be present on any sub-domain that +"owns" the atom with the information, either as a local or a ghost atom. The +communication cutoff is what determines up to what distance from a sub-domain +boundary ghost atoms are created. The communication cutoff is by default the +largest non-bonded cutoff plus the neighbor skin distance, but for short or +non-bonded cutoffs and/or long bonds, this may not be sufficient. This warning +indicates that there is an increased risk of a simulation stopping unexpectedly +because of Bond/Angle/Dihedral/Improper atoms missing. It can be silenced by +manually setting the communication cutoff via comm_modify cutoff. However, +since the heuristic used to determine the estimate is not always accurate, it +is not changed automatically and the warning may be ignored depending on the +specific system being simulated. + UNDOCUMENTED U: OMP_NUM_THREADS environment is not set. From 729cc81f31f6d5b1bd0e7884de9bd8c6c5de9738 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 31 Jul 2020 22:16:06 -0400 Subject: [PATCH 019/122] make more use of utils::logmesg() --- src/balance.cpp | 2 +- src/change_box.cpp | 2 +- src/delete_atoms.cpp | 3 +-- src/delete_bonds.cpp | 5 ++--- src/displace_atoms.cpp | 3 ++- src/read_dump.cpp | 5 ++--- src/read_restart.cpp | 9 ++++----- src/replicate.cpp | 25 +++++++++++++------------ src/set.cpp | 4 ++-- src/write_data.cpp | 3 +-- src/write_restart.cpp | 3 +-- 11 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/balance.cpp b/src/balance.cpp index d6579e9199..49cd6ecad5 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -113,7 +113,7 @@ void Balance::command(int narg, char **arg) if (domain->box_exist == 0) error->all(FLERR,"Balance command before simulation box is defined"); - if (me == 0 && screen) fprintf(screen,"Balancing ...\n"); + if (me == 0) utils::logmesg(lmp,"Balancing ...\n"); // parse required arguments diff --git a/src/change_box.cpp b/src/change_box.cpp index f50ba23db4..ff7658a01f 100644 --- a/src/change_box.cpp +++ b/src/change_box.cpp @@ -49,7 +49,7 @@ void ChangeBox::command(int narg, char **arg) error->all(FLERR,"Change_box command before simulation box is defined"); if (narg < 2) error->all(FLERR,"Illegal change_box command"); - if (comm->me == 0 && screen) fprintf(screen,"Changing box ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"Changing box ...\n"); // group diff --git a/src/delete_atoms.cpp b/src/delete_atoms.cpp index ba8940de95..03d5d2f65d 100644 --- a/src/delete_atoms.cpp +++ b/src/delete_atoms.cpp @@ -282,8 +282,7 @@ void DeleteAtoms::delete_overlap(int narg, char **arg) int group1bit = group->bitmask[igroup1]; int group2bit = group->bitmask[igroup2]; - if (comm->me == 0 && screen) - fprintf(screen,"System init for delete_atoms ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"System init for delete_atoms ...\n"); // request a full neighbor list for use by this command diff --git a/src/delete_bonds.cpp b/src/delete_bonds.cpp index 99c0f1b951..7b9260bc52 100644 --- a/src/delete_bonds.cpp +++ b/src/delete_bonds.cpp @@ -51,11 +51,10 @@ void DeleteBonds::command(int narg, char **arg) // init entire system since comm->borders is done // comm::init needs neighbor::init needs pair::init needs kspace::init, etc - if (comm->me == 0 && screen) - fprintf(screen,"System init for delete_bonds ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"System init for delete_bonds ...\n"); lmp->init(); - if (comm->me == 0 && screen) fprintf(screen,"Deleting bonds ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"Deleting bonds ...\n"); // identify group diff --git a/src/displace_atoms.cpp b/src/displace_atoms.cpp index 748adca811..82b7bf9492 100644 --- a/src/displace_atoms.cpp +++ b/src/displace_atoms.cpp @@ -34,6 +34,7 @@ #include "math_extra.h" #include "memory.h" #include "error.h" +#include "utils.h" #include "fmt/format.h" using namespace LAMMPS_NS; @@ -68,7 +69,7 @@ void DisplaceAtoms::command(int narg, char **arg) error->all(FLERR,"Cannot displace_atoms after " "reading restart file with per-atom info"); - if (comm->me == 0 && screen) fprintf(screen,"Displacing atoms ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"Displacing atoms ...\n"); // group and style diff --git a/src/read_dump.cpp b/src/read_dump.cpp index 0426323a21..f47eda3262 100644 --- a/src/read_dump.cpp +++ b/src/read_dump.cpp @@ -120,7 +120,7 @@ void ReadDump::command(int narg, char **arg) // find the snapshot and read/bcast/process header info - if (me == 0 && screen) fprintf(screen,"Scanning dump file ...\n"); + if (me == 0) utils::logmesg(lmp,"Scanning dump file ...\n"); bigint ntimestep = seek(nstep,1); if (ntimestep < 0) @@ -135,8 +135,7 @@ void ReadDump::command(int narg, char **arg) // read in the snapshot and reset system - if (me == 0 && screen) - fprintf(screen,"Reading snapshot from dump file ...\n"); + if (me == 0) utils::logmesg(lmp,"Reading snapshot from dump file ...\n"); bigint natoms_prev = atom->natoms; atoms(); diff --git a/src/read_restart.cpp b/src/read_restart.cpp index 3bbae596d1..157992bce3 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -103,7 +103,7 @@ void ReadRestart::command(int narg, char **arg) // open single restart file or base file for multiproc case if (me == 0) { - if (screen) fprintf(screen,"Reading restart file ...\n"); + utils::logmesg(lmp,"Reading restart file ...\n"); std::string hfile = file; if (multiproc) { hfile.replace(hfile.find("%"),1,"base"); @@ -620,10 +620,9 @@ void ReadRestart::header() if (flag == VERSION) { char *version = read_string(); - if (me == 0) { - if (screen) fprintf(screen," restart file = %s, LAMMPS = %s\n", - version,universe->version); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" restart file = {}, LAMMPS = {}\n", + version,universe->version)); delete [] version; // we have no forward compatibility, thus exit with error diff --git a/src/replicate.cpp b/src/replicate.cpp index 51ef75c37b..a9c0dbf7b3 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -48,7 +48,7 @@ void Replicate::command(int narg, char **arg) int me = comm->me; int nprocs = comm->nprocs; - if (me == 0 && screen) fprintf(screen,"Replicating atoms ...\n"); + if (me == 0) utils::logmesg(lmp,"Replicating atoms ...\n"); // nrep = total # of replications @@ -349,12 +349,14 @@ void Replicate::command(int narg, char **arg) int size_buf_all = 0; MPI_Allreduce(&n, &size_buf_all, 1, MPI_INT, MPI_SUM, world); - if (me == 0 && screen) { - fmt::print(screen," bounding box image = ({} {} {}) to ({} {} {})\n", - _imagelo[0],_imagelo[1],_imagelo[2], - _imagehi[0],_imagehi[1],_imagehi[2]); - fmt::print(screen," bounding box extra memory = {:.2f} MB\n", - (double)size_buf_all*sizeof(double)/1024/1024); + if (me == 0) { + auto mesg = fmt::format(" bounding box image = ({:.8} {:.8} {:.8}) " + "to ({:.8} {:.8} {:.8})\n", + _imagelo[0],_imagelo[1],_imagelo[2], + _imagehi[0],_imagehi[1],_imagehi[2]); + mesg += fmt::format(" bounding box extra memory = {:.2f} MB\n", + (double)size_buf_all*sizeof(double)/1024/1024); + utils::logmesg(lmp,mesg); } // rnk offsets @@ -632,11 +634,10 @@ void Replicate::command(int narg, char **arg) int sum = 0; MPI_Reduce(&num_replicas_added, &sum, 1, MPI_INT, MPI_SUM, 0, world); double avg = (double) sum / nprocs; - if (me == 0 && screen) - fprintf(screen," average # of replicas added to proc = %.2f " - "out of %i (%.2f %%)\n", - avg,nx*ny*nz,avg/(nx*ny*nz)*100.0); - + if (me == 0) + utils::logmesg(lmp,fmt::format(" average # of replicas added to proc =" + " {:.2f} out of {} ({:.2f}%)\n", + avg,nx*ny*nz,avg/(nx*ny*nz)*100.0)); } else { for (int iproc = 0; iproc < nprocs; iproc++) { diff --git a/src/set.cpp b/src/set.cpp index 8527f93df7..01176f68c0 100644 --- a/src/set.cpp +++ b/src/set.cpp @@ -82,7 +82,7 @@ void Set::command(int narg, char **arg) // loop over keyword/value pairs // call appropriate routine to reset attributes - if (comm->me == 0 && screen) fprintf(screen,"Setting atom values ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"Setting atom values ...\n"); int allcount,origarg; @@ -1264,7 +1264,7 @@ void Set::topology(int keyword) // init entire system since comm->exchange is done // comm::init needs neighbor::init needs pair::init needs kspace::init, etc - if (comm->me == 0 && screen) fprintf(screen," system init for set ...\n"); + if (comm->me == 0) utils::logmesg(lmp," system init for set ...\n"); lmp->init(); if (domain->triclinic) domain->x2lamda(atom->nlocal); diff --git a/src/write_data.cpp b/src/write_data.cpp index 1ec24a99cd..511552cf69 100644 --- a/src/write_data.cpp +++ b/src/write_data.cpp @@ -105,8 +105,7 @@ void WriteData::command(int narg, char **arg) // e.g. pair hybrid coeffs, dpd ghost-atom velocity setting if (noinit == 0) { - if (comm->me == 0 && screen) - fputs("System init for write_data ...\n",screen); + if (comm->me == 0) utils::logmesg(lmp,"System init for write_data ...\n"); lmp->init(); // move atoms to new processors before writing file diff --git a/src/write_restart.cpp b/src/write_restart.cpp index 9129126aae..062add3b3c 100644 --- a/src/write_restart.cpp +++ b/src/write_restart.cpp @@ -87,8 +87,7 @@ void WriteRestart::command(int narg, char **arg) // comm::init needs neighbor::init needs pair::init needs kspace::init, etc if (noinit == 0) { - if (comm->me == 0 && screen) - fprintf(screen,"System init for write_restart ...\n"); + if (comm->me == 0) utils::logmesg(lmp,"System init for write_restart ...\n"); lmp->init(); // move atoms to new processors before writing file From 896a08883b1354cc4f623b72c039ae0160824a54 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 00:12:51 -0400 Subject: [PATCH 020/122] add a custom python script to check the completeness of tests inputs --- unittest/force-styles/CMakeLists.txt | 17 +++ unittest/force-styles/check_tests.py | 218 +++++++++++++++++++++++++++ 2 files changed, 235 insertions(+) create mode 100755 unittest/force-styles/check_tests.py diff --git a/unittest/force-styles/CMakeLists.txt b/unittest/force-styles/CMakeLists.txt index 14a53f4e3e..104d37b861 100644 --- a/unittest/force-styles/CMakeLists.txt +++ b/unittest/force-styles/CMakeLists.txt @@ -5,6 +5,23 @@ if(NOT YAML_FOUND) return() endif() +if(CMAKE_VERSION VERSION_LESS 3.12) + # adjust so we find Python 3 versions before Python 2 on old systems with old CMake + set(Python_ADDITIONAL_VERSIONS 3.8 3.7 3.6 3.5) + find_package(PythonInterp) # Deprecated since version 3.12 + if(PYTHONINTERP_FOUND) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + endif() +else() + find_package(Python COMPONENTS Interpreter) +endif() +if (Python_EXECUTABLE) + add_custom_target(check-tests + ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_tests.py + -s ${LAMMPS_SOURCE_DIR} -t ${CMAKE_CURRENT_SOURCE_DIR}/tests + COMMENT "Check completeness of force style tests") +endif() + set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/tests) add_library(style_tests STATIC yaml_writer.cpp error_stats.cpp test_config_reader.cpp test_main.cpp) target_compile_definitions(style_tests PRIVATE -DTEST_INPUT_FOLDER=${TEST_INPUT_FOLDER}) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py new file mode 100755 index 0000000000..26519a3eca --- /dev/null +++ b/unittest/force-styles/check_tests.py @@ -0,0 +1,218 @@ +#!/usr/bin/env python3 + +from __future__ import print_function +from glob import glob +from argparse import ArgumentParser +import os, re, sys + +parser = ArgumentParser(prog='check_tests.py', + description="Check force tests for completeness") + +parser.add_argument("-v", "--verbose", + action='store_const', + const=True, default=False, + help="Enable verbose output") + +parser.add_argument("-t", "--tests", + help="Path to LAMMPS test YAML format input files") +parser.add_argument("-s", "--src", + help="Path to LAMMPS sources") + +args = parser.parse_args() +verbose = args.verbose +src = args.src +tests = args.tests + +if not src: + src = os.path.join('.','..','..','src') + +if not tests: + tests = os.path.join(src,'..','unittest','force-styles','tests') + +try: + src = os.path.abspath(os.path.expanduser(src)) + tests = os.path.abspath(os.path.expanduser(tests)) +except: + parser.print_help() + sys.exit(1) + +if not os.path.isdir(src): + sys.exit("LAMMPS source path %s does not exist" % src) + +if not os.path.isdir(tests): + sys.exit("LAMMPS test inputs path %s does not exist" % tests) + +headers = glob(os.path.join(src, '*', '*.h')) +headers += glob(os.path.join(src, '*.h')) + +angle = {} +bond = {} +compute = {} +dihedral = {} +dump = {} +fix = {} +improper = {} +kspace = {} +pair = {} +total = 0 + +upper = re.compile("[A-Z]+") +gpu = re.compile("(.+)/gpu$") +intel = re.compile("(.+)/intel$") +kokkos = re.compile("(.+)/kk$") +kokkos_skip = re.compile("(.+)/kk/(host|device)$") +omp = re.compile("(.+)/omp$") +opt = re.compile("(.+)/opt$") +removed = re.compile("(.*)Deprecated$") + +def register_style(list,style,info): + if style in list.keys(): + list[style]['gpu'] += info['gpu'] + list[style]['intel'] += info['intel'] + list[style]['kokkos'] += info['kokkos'] + list[style]['omp'] += info['omp'] + list[style]['opt'] += info['opt'] + list[style]['removed'] += info['removed'] + else: + list[style] = info + +def add_suffix(list,style): + suffix = "" + if list[style]['gpu']: + suffix += 'g' + if list[style]['intel']: + suffix += 'i' + if list[style]['kokkos']: + suffix += 'k' + if list[style]['omp']: + suffix += 'o' + if list[style]['opt']: + suffix += 't' + if suffix: + return style + ' (' + suffix + ')' + else: + return style + +def check_style(file,dir,pattern,list,name,suffix=False,skip=()): + f = os.path.join(dir, file) + fp = open(f) + text = fp.read() + fp.close() + matches = re.findall(pattern,text,re.MULTILINE) + counter = 0 + for c in list.keys(): + # known undocumented aliases we need to skip + if c in skip: continue + s = c + if suffix: s = add_suffix(list,c) + if not s in matches: + if not list[c]['removed']: + print("%s style entry %s" % (name,s), + "is missing or incomplete in %s" % file) + counter += 1 + return counter + +print("Parsing style names from C++ tree in: ",src) + +for h in headers: + if verbose: print("Checking ", h) + fp = open(h) + text = fp.read() + fp.close() + matches = re.findall("(.+)Style\((.+),(.+)\)",text,re.MULTILINE) + for m in matches: + + # skip over internal styles w/o explicit documentation + style = m[1] + total += 1 + if upper.match(style): + continue + + # detect, process, and flag suffix styles: + info = { 'kokkos': 0, 'gpu': 0, 'intel': 0, \ + 'omp': 0, 'opt': 0, 'removed': 0 } + suffix = kokkos_skip.match(style) + if suffix: + continue + suffix = gpu.match(style) + if suffix: + style = suffix.groups()[0] + info['gpu'] = 1 + suffix = intel.match(style) + if suffix: + style = suffix.groups()[0] + info['intel'] = 1 + suffix = kokkos.match(style) + if suffix: + style = suffix.groups()[0] + info['kokkos'] = 1 + suffix = omp.match(style) + if suffix: + style = suffix.groups()[0] + info['omp'] = 1 + suffix = opt.match(style) + if suffix: + style = suffix.groups()[0] + info['opt'] = 1 + deprecated = removed.match(m[2]) + if deprecated: + info['removed'] = 1 + + # register style and suffix flags + if m[0] == 'Angle': + register_style(angle,style,info) + elif m[0] == 'Bond': + register_style(bond,style,info) + elif m[0] == 'Dihedral': + register_style(dihedral,style,info) + elif m[0] == 'Improper': + register_style(improper,style,info) + elif m[0] == 'KSpace': + register_style(kspace,style,info) + elif m[0] == 'Pair': + register_style(pair,style,info) + + +counter = 0 + +def check_tests(name,list,yaml,search,skip=()): + num = 0 + yaml_files = glob(os.path.join(tests, yaml)) + styles = [] + missing = [] + for y in yaml_files: + if verbose: print("Checking: ",y) + fp = open(y) + text = fp.read() + fp.close() + matches = re.findall(search,text,re.MULTILINE) + for m in matches: + styles.append(m) + for s in list.keys(): + # known undocumented aliases we need to skip + if s in skip: continue + if not s in styles: + if not list[s]['removed']: + if verbose: print("No test for %s style %s" % (name,s)) + num += 1 + missing.append(s) + total = len(list) + print("\nTests for %s styles: %d of %d" % (name,total - num, total)) + print("No tests for: ", missing) + return num + +counter += check_tests('pair',pair,'*-pair-*.yaml', + '.*pair_style:\s*(\S+).*',skip=('meam','lj/sf')) +counter += check_tests('bond',bond,'bond-*.yaml', + '.*bond_style:\s*(\S+).*') +counter += check_tests('angle',angle,'angle-*.yaml', + '.*angle_style:\s*(\S+).*') +counter += check_tests('dihedral',dihedral,'dihedral-*.yaml', + '.*dihedral_style:\s*(\S+).*') +counter += check_tests('improper',improper,'improper-*.yaml', + '.*improper_style:\s*(\S+).*') +counter += check_tests('kspace',kspace,'kspace-*.yaml', + '.*kspace_style\s*(\S+).*') + +total = len(pair)+len(bond)+len(angle)+len(dihedral)+len(improper)+len(kspace) +print("\nTotal tests missing: %d of %d" % (total - counter, total)) From 90028a3c71053a794ddada922f913e7b003ed439 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 00:43:41 -0400 Subject: [PATCH 021/122] properly handle hybrid styles when checking for missing tests --- unittest/force-styles/check_tests.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py index 26519a3eca..c65d075a4c 100755 --- a/unittest/force-styles/check_tests.py +++ b/unittest/force-styles/check_tests.py @@ -187,7 +187,12 @@ def check_tests(name,list,yaml,search,skip=()): fp.close() matches = re.findall(search,text,re.MULTILINE) for m in matches: - styles.append(m) + if m[1] == 'hybrid' or m[1] == 'hybrid/overlay': + for s in m[0].split(): + if s in list.keys(): + styles.append(s) + else: + styles.append(m[1]) for s in list.keys(): # known undocumented aliases we need to skip if s in skip: continue @@ -197,22 +202,23 @@ def check_tests(name,list,yaml,search,skip=()): num += 1 missing.append(s) total = len(list) - print("\nTests for %s styles: %d of %d" % (name,total - num, total)) + print("\nTests available for %s styles: %d of %d" + % (name,total - num, total)) print("No tests for: ", missing) return num counter += check_tests('pair',pair,'*-pair-*.yaml', - '.*pair_style:\s*(\S+).*',skip=('meam','lj/sf')) + '.*pair_style:\s*((\S+).*)?',skip=('meam','lj/sf')) counter += check_tests('bond',bond,'bond-*.yaml', - '.*bond_style:\s*(\S+).*') + '.*bond_style:\s*((\S+).*)?') counter += check_tests('angle',angle,'angle-*.yaml', - '.*angle_style:\s*(\S+).*') + '.*angle_style:\s*((\S+).*)?') counter += check_tests('dihedral',dihedral,'dihedral-*.yaml', - '.*dihedral_style:\s*(\S+).*') + '.*dihedral_style:\s*((\S+).*)?') counter += check_tests('improper',improper,'improper-*.yaml', - '.*improper_style:\s*(\S+).*') + '.*improper_style:\s*((\S+).*)?') counter += check_tests('kspace',kspace,'kspace-*.yaml', - '.*kspace_style\s*(\S+).*') + '.*kspace_style\s*((\S+).*)?') total = len(pair)+len(bond)+len(angle)+len(dihedral)+len(improper)+len(kspace) -print("\nTotal tests missing: %d of %d" % (total - counter, total)) +print("\nTotal tests missing: %d of %d" % (counter, total)) From 8eb84229bd8164104607110e57f1984570f78f86 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 05:59:44 -0400 Subject: [PATCH 022/122] passing tests for born-coul, gauss and yukawa --- .../tests/mol-pair-born_coul_dsf.yaml | 98 +++++++++++++++++++ .../tests/mol-pair-born_coul_wolf.yaml | 98 +++++++++++++++++++ .../force-styles/tests/mol-pair-gauss.yaml | 91 +++++++++++++++++ .../force-styles/tests/mol-pair-yukawa.yaml | 89 +++++++++++++++++ 4 files changed, 376 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml create mode 100644 unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml create mode 100644 unittest/force-styles/tests/mol-pair-gauss.yaml create mode 100644 unittest/force-styles/tests/mol-pair-yukawa.yaml diff --git a/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml b/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml new file mode 100644 index 0000000000..bdb35df831 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-born_coul_dsf.yaml @@ -0,0 +1,98 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Sat Aug 1 16:17:46 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair born/coul/dsf +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: born/coul/dsf 0.25 8.0 +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 +extract: ! "" +natoms: 29 +init_vdwl: 225.01325775005 +init_coul: -116.262182085427 +init_stress: ! |2- + 4.6548476353031594e+02 4.5051121181207020e+02 7.8830780607527242e+02 -1.0070292272125850e+02 3.7932502866866969e+01 1.0553864562325985e+02 +init_forces: ! |2 + 1 -4.4641074718374796e+00 6.5654664922425383e+01 8.4289201975265982e+01 + 2 4.0311842353028624e+01 3.0257535401299727e+01 -4.9096930370239420e+01 + 3 -3.3553276996952135e+01 -9.0454690885444151e+01 -3.5286204897949617e+01 + 4 -5.4326075691646452e+00 1.4750070332641836e+00 -4.1453377417337594e+00 + 5 -2.1840552105120996e+00 -2.0820945236498694e+00 7.8504362907775436e+00 + 6 -1.3458475468447563e+02 1.4573608496561206e+02 1.3350063946264041e+02 + 7 3.1172252284802044e+00 -4.3128967618489632e+01 -2.4355183830544655e+02 + 8 7.7977506904524754e+00 -8.5382231680036949e+00 6.6109004772120187e+01 + 9 1.9941491302607346e+01 1.3989277582182677e+01 8.2015176223230995e+01 + 10 9.2986332060941479e+01 -1.1563939008048585e+02 -3.3767913886593711e+01 + 11 -2.4897126629767046e+00 -2.8321358843182951e+00 -7.0356961622427345e+00 + 12 1.4309767269332680e+01 5.0245809380075501e+00 -3.2735260664726580e+00 + 13 5.5540753662653000e+00 -2.2023993732628737e+00 -3.0618787941595627e-01 + 14 -3.4645291929560251e+00 9.0208906948568557e-01 -6.1598725549849496e+00 + 15 1.6497973196839805e-01 5.7610138437210674e+00 1.0388423002469940e+00 + 16 7.5198550890136460e+01 -5.8250369682046070e+01 -1.7473483250665458e+02 + 17 -7.2047911016472369e+01 5.3986247830551847e+01 1.8071845329505265e+02 + 18 5.4865434693949500e-01 5.4795093909080101e+00 -8.4742180617754297e+00 + 19 1.9220633751034331e+00 -1.0885665726844067e+00 5.9236082764536580e+00 + 20 -2.9954564482234325e+00 -4.2803216032204601e+00 4.4747365104553127e+00 + 21 -1.6525887219216475e+01 -1.6791180321860896e+01 5.2088959037553678e+01 + 22 -2.7794558712527092e+01 -7.9035624631990213e+00 -4.0215539211939507e+01 + 23 4.3840858038837126e+01 2.5199748035048120e+01 -1.1304867969464665e+01 + 24 9.7024935924746742e+00 -4.6652912712429462e+01 2.5828050400755373e+01 + 25 -3.8034229076586556e+01 3.3184478584168566e+00 -3.1022383460045887e+01 + 26 2.7759257897664870e+01 4.3090577628647004e+01 4.5508599095678770e+00 + 27 9.4540809516248068e+00 -5.0442863407123852e+01 1.9202978230103980e+01 + 28 -4.2634181882990454e+01 1.5556514661238053e+01 -2.8124333709589369e+01 + 29 3.3595845049033741e+01 3.4856379135410293e+01 8.9087361003241199e+00 +run_vdwl: 158.434782247931 +run_coul: -114.493744545081 +run_stress: ! |2- + 3.6457599858106323e+02 3.5447775569312563e+02 5.1484466370895007e+02 -9.2184537777848647e+01 3.3327026119667003e+01 7.7318576297238295e+01 +run_forces: ! |2 + 1 3.3128565928816736e+00 5.4462232338907675e+01 5.7819825620081382e+01 + 2 2.4741711089801676e+01 1.7215897652018715e+01 -3.0619730806082021e+01 + 3 -3.0675317991144063e+01 -6.2338014537455528e+01 -2.4093764988937252e+01 + 4 -5.2186950995461077e+00 1.5388493910159622e+00 -4.0518642704153489e+00 + 5 -1.9740472219907386e+00 -1.6710869413430212e+00 7.2060846542775732e+00 + 6 -9.7531884089785336e+01 9.9793556580413593e+01 5.2098481038771901e+01 + 7 4.1240901037470978e+00 -2.6627630139738919e+01 -1.3429437375227437e+02 + 8 4.0961464557336393e+00 -1.6859216412227742e+00 5.7786048678057334e+01 + 9 1.3898962563226151e+01 6.1784815300352385e+00 5.3698406201380600e+01 + 10 6.9395067324736331e+01 -8.8387443730071126e+01 -2.9777902877382065e+01 + 11 -2.6886774410153995e+00 -2.5516346181388614e+00 -6.9603326359120121e+00 + 12 1.3657116374147838e+01 5.0998174536259011e+00 -3.8311422196898803e+00 + 13 5.2106464538019850e+00 -1.9694276886777915e+00 -3.1806000271177143e-01 + 14 -3.2502839177058052e+00 7.6870953022794242e-01 -5.2552653229769204e+00 + 15 2.5381417765419339e-03 5.5670489097503530e+00 1.0731442832077982e+00 + 16 4.7451100017037810e+01 -4.0685593584410093e+01 -9.5760224948203970e+01 + 17 -4.3207417432057618e+01 3.4918390165235508e+01 1.0330298136883876e+02 + 18 -7.8633626956610705e-02 5.1621863754062458e+00 -7.8408453675787255e+00 + 19 2.3491071350704815e+00 -8.8427683425379833e-01 5.9940920406682379e+00 + 20 -2.9045058075719248e+00 -4.1696098186895840e+00 3.9210010976007874e+00 + 21 -1.1670443819074521e+01 -1.0138720509131051e+01 3.5558210752504820e+01 + 22 -1.9698153723974421e+01 -6.0607216096940499e+00 -2.7508478755382473e+01 + 23 3.0835222734122727e+01 1.6748088264051564e+01 -7.4052523774694459e+00 + 24 9.4619363908432437e+00 -3.3810430721396280e+01 2.0200434023345363e+01 + 25 -3.0551295230862227e+01 1.9603242823861462e+00 -2.4994048576690659e+01 + 26 2.0444751175621061e+01 3.1599870621201820e+01 4.0782746097595677e+00 + 27 6.0377133407499386e+00 -3.4167133913114682e+01 1.2057831650379896e+01 + 28 -2.9188933983003132e+01 1.0118794842901607e+01 -1.8843451954617606e+01 + 29 2.3619323491389739e+01 2.4015398350159305e+01 6.7599228374505618e+00 +... diff --git a/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml b/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml new file mode 100644 index 0000000000..7d419e2da2 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-born_coul_wolf.yaml @@ -0,0 +1,98 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Sat Aug 1 16:19:43 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair born/coul/wolf +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: born/coul/wolf 0.25 8.0 +pair_coeff: ! | + 1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 141.547923828784 + 1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 4.09225030876458 + 1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 403.51858739517 + 1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 303.336540547726 + 2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 0.177172207445923 + 2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 17.5662073921955 + 2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 0.000703093129207124 + 2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 12.548008396489 + 3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 1019.38354056979 + 3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 778.254162800904 + 4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 + 5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 592.979935420722 +extract: ! "" +natoms: 29 +init_vdwl: 225.01325775005 +init_coul: -115.714526063965 +init_stress: ! |2- + 4.6548476353031594e+02 4.5051121181207009e+02 7.8830780607527208e+02 -1.0070292272125866e+02 3.7932502866866926e+01 1.0553864562325973e+02 +init_forces: ! |2 + 1 -4.4641074718374725e+00 6.5654664922425383e+01 8.4289201975265982e+01 + 2 4.0311842353028624e+01 3.0257535401299727e+01 -4.9096930370239420e+01 + 3 -3.3553276996952135e+01 -9.0454690885444151e+01 -3.5286204897949617e+01 + 4 -5.4326075691646443e+00 1.4750070332641836e+00 -4.1453377417337585e+00 + 5 -2.1840552105120996e+00 -2.0820945236498694e+00 7.8504362907775436e+00 + 6 -1.3458475468447566e+02 1.4573608496561206e+02 1.3350063946264041e+02 + 7 3.1172252284802022e+00 -4.3128967618489632e+01 -2.4355183830544655e+02 + 8 7.7977506904524718e+00 -8.5382231680036949e+00 6.6109004772120187e+01 + 9 1.9941491302607346e+01 1.3989277582182677e+01 8.2015176223230995e+01 + 10 9.2986332060941479e+01 -1.1563939008048585e+02 -3.3767913886593711e+01 + 11 -2.4897126629767046e+00 -2.8321358843182929e+00 -7.0356961622427328e+00 + 12 1.4309767269332688e+01 5.0245809380075492e+00 -3.2735260664726571e+00 + 13 5.5540753662652982e+00 -2.2023993732628724e+00 -3.0618787941595543e-01 + 14 -3.4645291929560260e+00 9.0208906948568501e-01 -6.1598725549849505e+00 + 15 1.6497973196839799e-01 5.7610138437210665e+00 1.0388423002469944e+00 + 16 7.5198550890136474e+01 -5.8250369682046085e+01 -1.7473483250665461e+02 + 17 -7.2047911016472383e+01 5.3986247830551854e+01 1.8071845329505268e+02 + 18 5.4865434693948656e-01 5.4795093909080039e+00 -8.4742180617754261e+00 + 19 1.9220633751034335e+00 -1.0885665726844067e+00 5.9236082764536597e+00 + 20 -2.9954564482234232e+00 -4.2803216032204512e+00 4.4747365104553065e+00 + 21 -1.6525887219216504e+01 -1.6791180321860907e+01 5.2088959037553671e+01 + 22 -2.7794558712527085e+01 -7.9035624631990204e+00 -4.0215539211939493e+01 + 23 4.3840858038837148e+01 2.5199748035048131e+01 -1.1304867969464670e+01 + 24 9.7024935924746885e+00 -4.6652912712429405e+01 2.5828050400755362e+01 + 25 -3.8034229076586527e+01 3.3184478584168597e+00 -3.1022383460045873e+01 + 26 2.7759257897664831e+01 4.3090577628646948e+01 4.5508599095678690e+00 + 27 9.4540809516248174e+00 -5.0442863407123866e+01 1.9202978230103987e+01 + 28 -4.2634181882990461e+01 1.5556514661238062e+01 -2.8124333709589376e+01 + 29 3.3595845049033741e+01 3.4856379135410300e+01 8.9087361003241199e+00 +run_vdwl: 158.434782247931 +run_coul: -113.929272955805 +run_stress: ! |2- + 3.6457599858106312e+02 3.5447775569312563e+02 5.1484466370894995e+02 -9.2184537777848604e+01 3.3327026119666925e+01 7.7318576297238266e+01 +run_forces: ! |2 + 1 3.3128565928816602e+00 5.4462232338907683e+01 5.7819825620081396e+01 + 2 2.4741711089801687e+01 1.7215897652018725e+01 -3.0619730806082039e+01 + 3 -3.0675317991144063e+01 -6.2338014537455528e+01 -2.4093764988937252e+01 + 4 -5.2186950995461059e+00 1.5388493910159626e+00 -4.0518642704153480e+00 + 5 -1.9740472219907386e+00 -1.6710869413430216e+00 7.2060846542775741e+00 + 6 -9.7531884089785308e+01 9.9793556580413565e+01 5.2098481038771922e+01 + 7 4.1240901037471023e+00 -2.6627630139738915e+01 -1.3429437375227437e+02 + 8 4.0961464557336074e+00 -1.6859216412227553e+00 5.7786048678057305e+01 + 9 1.3898962563226151e+01 6.1784815300352349e+00 5.3698406201380600e+01 + 10 6.9395067324736331e+01 -8.8387443730071126e+01 -2.9777902877382061e+01 + 11 -2.6886774410154004e+00 -2.5516346181388627e+00 -6.9603326359120139e+00 + 12 1.3657116374147842e+01 5.0998174536259020e+00 -3.8311422196898794e+00 + 13 5.2106464538019859e+00 -1.9694276886777924e+00 -3.1806000271177137e-01 + 14 -3.2502839177058052e+00 7.6870953022794208e-01 -5.2552653229769231e+00 + 15 2.5381417765427787e-03 5.5670489097503548e+00 1.0731442832077978e+00 + 16 4.7451100017037810e+01 -4.0685593584410100e+01 -9.5760224948203970e+01 + 17 -4.3207417432057618e+01 3.4918390165235508e+01 1.0330298136883876e+02 + 18 -7.8633626956627622e-02 5.1621863754062316e+00 -7.8408453675787255e+00 + 19 2.3491071350704971e+00 -8.8427683425378700e-01 5.9940920406682503e+00 + 20 -2.9045058075719230e+00 -4.1696098186895822e+00 3.9210010976007812e+00 + 21 -1.1670443819074549e+01 -1.0138720509131064e+01 3.5558210752504799e+01 + 22 -1.9698153723974411e+01 -6.0607216096940473e+00 -2.7508478755382452e+01 + 23 3.0835222734122745e+01 1.6748088264051574e+01 -7.4052523774694468e+00 + 24 9.4619363908432472e+00 -3.3810430721396251e+01 2.0200434023345355e+01 + 25 -3.0551295230862216e+01 1.9603242823861455e+00 -2.4994048576690645e+01 + 26 2.0444751175621047e+01 3.1599870621201791e+01 4.0782746097595632e+00 + 27 6.0377133407499528e+00 -3.4167133913114654e+01 1.2057831650379898e+01 + 28 -2.9188933983003132e+01 1.0118794842901602e+01 -1.8843451954617603e+01 + 29 2.3619323491389729e+01 2.4015398350159284e+01 6.7599228374505591e+00 +... diff --git a/unittest/force-styles/tests/mol-pair-gauss.yaml b/unittest/force-styles/tests/mol-pair-gauss.yaml new file mode 100644 index 0000000000..b5e69bcfaa --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-gauss.yaml @@ -0,0 +1,91 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Sat Aug 1 20:26:38 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair gauss +pre_commands: ! "" +post_commands: ! | + pair_modify mix geometric +input_file: in.fourmol +pair_style: gauss 8.0 +pair_coeff: ! | + 1 1 0.02 0.176 + 2 2 0.005 1.1 + 2 4 0.005 4.4 + 3 3 0.02 0.107421875 + 4 4 0.015 0.114464099895942 + 5 5 0.015 0.114464099895942 +extract: ! | + a 2 +natoms: 29 +init_vdwl: -0.386420923215596 +init_coul: 0 +init_stress: ! |- + -2.2163698035273618e-01 -2.4625537112111151e-01 -2.1305188258578470e-01 6.1866130132872003e-02 6.6571531323592207e-03 2.4462489698253043e-02 +init_forces: ! |2 + 1 6.6420790881819135e-03 -2.2656352315504419e-02 -1.1151371492916272e-02 + 2 -4.2811279269361156e-03 -6.1319457093740913e-03 3.5655172207420469e-03 + 3 1.4122450625899436e-02 -6.4669361374405238e-03 -3.4547856578885819e-03 + 4 9.2022857012287029e-03 -9.6636513433784451e-04 5.6358203169252627e-03 + 5 4.8130601322131554e-03 3.8754733051119977e-03 -9.5295063547545852e-03 + 6 1.1694684866979214e-02 -1.1545676479204194e-04 8.9573160065516636e-03 + 7 9.2903486979032928e-03 2.0412909476071818e-03 2.0895988031881762e-02 + 8 8.2241496648224888e-03 3.2282787725485093e-03 -5.5984923599097887e-03 + 9 -9.1025802092398352e-04 -2.9695228458060277e-03 -1.1310732844631449e-02 + 10 -3.3216915418810807e-03 1.5165769941583293e-02 -1.2109299141022656e-03 + 11 2.8660819158744734e-03 8.4275110632676224e-03 9.5049639732687780e-03 + 12 -2.2598101552834836e-02 -4.9601916039375389e-03 8.4003031140324341e-03 + 13 -9.4516726881566388e-03 1.4305285400726016e-03 1.5058333996407797e-03 + 14 -3.4864885985541323e-04 -1.8689531090578431e-03 1.0873765307790662e-02 + 15 -4.3507528925587919e-03 -9.8039134533324957e-03 -1.2974821049077257e-03 + 16 -1.1020969725836332e-02 1.9784791088106480e-02 -1.1275809663597147e-02 + 17 -3.3419871860029715e-03 8.2289097839403427e-03 -1.8738857919511739e-02 + 18 -4.3521806872305014e-03 -7.8656826681131678e-03 6.5687503046006051e-03 + 19 9.2492265214090606e-04 7.1711662533072390e-04 5.6458533331792311e-04 + 20 -1.0085043451939246e-03 -9.3005491274762285e-04 5.0547579022850204e-05 + 21 -1.1667863590836469e-03 4.2902548011202451e-03 -2.0499762074924696e-03 + 22 3.1557118123179237e-03 9.5184863190457439e-04 3.9782856889301653e-03 + 23 -4.4281270696133268e-03 -2.5346995221498434e-03 7.5785922268409691e-04 + 24 -3.0622009464357529e-03 1.9851728054262412e-03 -6.5546361368900791e-03 + 25 3.7063223755402488e-03 -2.7523325480129519e-04 2.6231087574901247e-03 + 26 -2.9538296443943910e-03 -4.1309366766066275e-03 -6.6793595531402768e-04 + 27 1.3703266730383692e-03 6.2247400367154799e-03 -2.6349027873549895e-03 + 28 4.1766990025931270e-03 -1.2043760854333907e-03 2.6647558305012602e-03 + 29 -3.5922837617955406e-03 -3.4710661493005325e-03 -1.0719806881093012e-03 +run_vdwl: -0.385719521571276 +run_coul: 0 +run_stress: ! |- + -2.2127965562428206e-01 -2.4542254865102489e-01 -2.1311997533750865e-01 6.1590688961780077e-02 6.4710641726297407e-03 2.3860454991976896e-02 +run_forces: ! |2 + 1 6.6339333601653496e-03 -2.2524710536472679e-02 -1.1066345716895123e-02 + 2 -4.2961292258735032e-03 -6.1061479512316179e-03 3.4551164581031772e-03 + 3 1.4098065137618113e-02 -6.5678509183120749e-03 -3.4500687443776165e-03 + 4 9.1297675704199062e-03 -9.2076983650763843e-04 5.6840784353467486e-03 + 5 4.8219769409920893e-03 3.8775965045406420e-03 -9.4999301521243983e-03 + 6 1.1609395172886160e-02 -1.6632611491897907e-04 8.8250864738019970e-03 + 7 9.2908574507960771e-03 2.0985971946703226e-03 2.0875679703349952e-02 + 8 8.2759269711901937e-03 3.2662972774544475e-03 -5.5734651879111030e-03 + 9 -8.6095270639503178e-04 -2.9570902523862082e-03 -1.1304425504033978e-02 + 10 -3.3641016068010651e-03 1.5129181364746619e-02 -1.1518357751169970e-03 + 11 2.8587329807512056e-03 8.3847827232913473e-03 9.4470919859432449e-03 + 12 -2.2597109016745633e-02 -4.9138934453695823e-03 8.5228034828072150e-03 + 13 -9.3773477120218055e-03 1.3383307270982115e-03 1.4498073944369861e-03 + 14 -3.2078148525200705e-04 -1.7694120286299623e-03 1.0809373712305968e-02 + 15 -4.3466909449344617e-03 -9.8479849482436283e-03 -1.3508873267368364e-03 + 16 -1.0974266662518333e-02 1.9734995902988880e-02 -1.1223816880544343e-02 + 17 -3.3460215145044428e-03 8.1754449563126684e-03 -1.8717672604331326e-02 + 18 -4.4353904552827620e-03 -7.9518043425390473e-03 6.6190908651599786e-03 + 19 8.6941905763071418e-04 6.7650975132080727e-04 5.6027618284191876e-04 + 20 -8.7479291857212624e-04 -8.1183654654835304e-04 2.8482497810329193e-05 + 21 -1.1799787391022290e-03 4.1795656349224598e-03 -1.9487781014492240e-03 + 22 3.1900249662174147e-03 9.9110559625285627e-04 3.9154102410000361e-03 + 23 -4.4537086142730992e-03 -2.4503511342288857e-03 7.2603134815082612e-04 + 24 -3.0597697342257743e-03 1.8858645847803469e-03 -6.4766291832782374e-03 + 25 3.7186580773971665e-03 -1.6137182737049823e-04 2.6515841867995930e-03 + 26 -2.9661843277505790e-03 -4.1377685212392670e-03 -7.6528608606584066e-04 + 27 1.3269926264425885e-03 6.2138292007353785e-03 -2.5379560415173348e-03 + 28 4.2062291078341146e-03 -1.1839109861043232e-03 2.6401605387391131e-03 + 29 -3.5767537560882274e-03 -3.4808720290122512e-03 -1.1429762022147198e-03 +... diff --git a/unittest/force-styles/tests/mol-pair-yukawa.yaml b/unittest/force-styles/tests/mol-pair-yukawa.yaml new file mode 100644 index 0000000000..bbb754afab --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-yukawa.yaml @@ -0,0 +1,89 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Sat Aug 1 18:01:12 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair yukawa +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: yukawa 2.0 8.0 +pair_coeff: ! | + 1 1 100.0 + 2 2 1.0 + 2 4 0.2 + 3 3 350.0 + 4 4 250.0 + 5 5 250.0 +extract: ! "" +natoms: 29 +init_vdwl: 12.1140092545333 +init_coul: 0 +init_stress: ! |2- + 1.5340283897676171e+01 1.5286756739439106e+01 2.0087158519042458e+01 -4.8365264950233238e+00 1.3285673835968570e+00 -4.5678403668669543e-01 +init_forces: ! |2 + 1 2.3869404989361082e-01 2.4974819612535493e+00 1.4483647655555152e+00 + 2 4.3730528059976720e-01 4.1898104214730286e-01 -4.8664683716446089e-01 + 3 -1.3109224137058761e+00 -1.3274920047212022e+00 -3.6931436509951809e-01 + 4 -3.4346983861500635e-01 2.2942122345247163e-02 -2.3551452546509499e-01 + 5 -1.8012880393025041e-01 -2.3749729580708490e-01 4.0400600035542561e-01 + 6 -2.1639702900477360e+00 1.8980939399760934e+00 1.2714184627324070e+00 + 7 -1.0936062933595951e+00 -3.0636657995642624e-01 -5.2960940290204492e+00 + 8 -3.8827955221479316e-01 3.1426728532389085e-02 2.8394041351918178e+00 + 9 1.5368263344978775e-01 2.1865490459365688e-01 8.8769541289220777e-01 + 10 1.3588450860519290e+00 -2.2806966159856401e+00 -8.1908045358117432e-01 + 11 -8.6499858141495717e-02 -2.9777398558638407e-01 -3.5092929329928163e-01 + 12 1.9044005469032417e+00 4.0834439156564895e-01 -6.5603032625832958e-01 + 13 3.3024716927088377e-01 -8.6615464001991826e-02 -2.9586981498950473e-02 + 14 -1.7682143171145703e-02 4.8159764902001065e-02 -3.9838676151917851e-01 + 15 1.7475186441612350e-01 3.8040978212159116e-01 5.4401174874445610e-02 + 16 1.5901172590935342e+00 -1.6594600995387174e+00 -2.0356076765439166e+00 + 17 -7.4058571445730048e-01 1.2831409932683097e-01 3.8350153767982564e+00 + 18 8.8747566236698133e-02 1.4330079958611378e-01 -9.6006094654911278e-02 + 19 -1.4234238386076048e-02 -9.0631458107939978e-03 -1.3174253552297375e-02 + 20 1.6425234257211201e-02 1.5552452664103624e-02 -1.5423196983825205e-03 + 21 -1.7755994496717462e-01 -2.5448522901203424e-01 6.6811268477306107e-01 + 22 -3.4551156678873390e-01 -8.7289767571394880e-02 -5.2760313654039959e-01 + 23 5.3935430069767432e-01 3.2087311244015737e-01 -1.5937976712249299e-01 + 24 1.7128322642385302e-01 -6.0775234175455051e-01 3.9943742593156972e-01 + 25 -4.6938148762176046e-01 7.5551014829863247e-02 -3.8064722986340110e-01 + 26 3.3714308699883677e-01 5.5247445857621902e-01 4.3854186832049238e-02 + 27 9.4797146110160047e-02 -6.8646247310384589e-01 2.4639304651374588e-01 + 28 -5.1616210292097298e-01 2.1221625027252755e-01 -3.4651058440874610e-01 + 29 4.1219979792460537e-01 4.6817817771676995e-01 1.0395196284048441e-01 +run_vdwl: 12.0568557171451 +run_coul: 0 +run_stress: ! |2- + 1.5330000071826197e+01 1.5239894051288136e+01 1.9897262789051808e+01 -4.7587838511570570e+00 1.3293139763213948e+00 -3.6500487827547595e-01 +run_forces: ! |2 + 1 2.4975440071812444e-01 2.4792701761727871e+00 1.4325644398779867e+00 + 2 4.3722176194250578e-01 4.2270920801895068e-01 -4.7047803648254372e-01 + 3 -1.3217795113851245e+00 -1.3237236534495787e+00 -3.7619349309100752e-01 + 4 -3.3441758497253044e-01 2.1746063589894216e-02 -2.3341724720843662e-01 + 5 -1.7902515320967879e-01 -2.3570567001146420e-01 4.0022831379592089e-01 + 6 -2.1131663779213752e+00 1.8738175513340289e+00 1.2185758983803003e+00 + 7 -1.0832597573629019e+00 -3.1214009378381086e-01 -5.1703647184513262e+00 + 8 -4.5689695827862370e-01 7.2729060242302149e-02 2.7897946190178557e+00 + 9 1.5181644796517385e-01 2.1252275080244398e-01 8.8106700117376502e-01 + 10 1.3826246193191662e+00 -2.2989979235807922e+00 -8.2945828121334308e-01 + 11 -8.4017809589640072e-02 -2.8842393883530787e-01 -3.3758871339567337e-01 + 12 1.8849845925556798e+00 4.0051218037170749e-01 -6.6606866421666999e-01 + 13 3.2520800533491434e-01 -8.1065392330917391e-02 -2.7689170375300241e-02 + 14 -1.7055234529525065e-02 4.3269029062384674e-02 -3.8697701850574379e-01 + 15 1.7869578995751320e-01 3.8596685663725833e-01 5.7300850943067409e-02 + 16 1.5804080557913573e+00 -1.6610668419278056e+00 -2.0542271263536747e+00 + 17 -7.3877483193751703e-01 1.4523777955675660e-01 3.8371392727298597e+00 + 18 8.9747195983243683e-02 1.4449283346224664e-01 -9.6968621917516526e-02 + 19 -1.3253521272585549e-02 -8.3094669208279397e-03 -1.3050917979350433e-02 + 20 1.4949572105708266e-02 1.4324580084895622e-02 -1.4930986692723782e-03 + 21 -1.8461121263224514e-01 -2.4356169781155593e-01 6.6889447440320360e-01 + 22 -3.5912054426479384e-01 -9.6623282650012576e-02 -5.3028367804642962e-01 + 23 5.6011812529580063e-01 3.1907494235924094e-01 -1.5756674673910209e-01 + 24 1.9136147522334027e-01 -6.2910044529930087e-01 4.1784800880923728e-01 + 25 -5.0574657365861708e-01 6.9048712650996977e-02 -4.1281223901052716e-01 + 26 3.5337381289277175e-01 5.8004107025814688e-01 5.7416816758216777e-02 + 27 1.0755942410536246e-01 -6.9796191232134375e-01 2.3910802875620396e-01 + 28 -5.3147795503156714e-01 2.1552315291984012e-01 -3.4983801773915779e-01 + 29 4.1477974685606378e-01 4.7639437139883750e-01 1.1453806474945682e-01 +... From 80ceff55d5952a9926dac220d18a52d2b43d164b Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 06:01:59 -0400 Subject: [PATCH 023/122] failing test for UFM, with cosmetic change in its CPP, and doc correction --- doc/src/pair_ufm.rst | 6 +- src/pair_ufm.cpp | 2 +- unittest/force-styles/tests/mol-pair-ufm.yaml | 93 +++++++++++++++++++ 3 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 unittest/force-styles/tests/mol-pair-ufm.yaml diff --git a/doc/src/pair_ufm.rst b/doc/src/pair_ufm.rst index 1e4daa874c..b03ad1e17a 100644 --- a/doc/src/pair_ufm.rst +++ b/doc/src/pair_ufm.rst @@ -94,10 +94,8 @@ of a run: **Mixing, shift, table, tail correction, restart, rRESPA info**\ : -For atom type pairs I,J and I != J, the A coefficient and cutoff -distance for this pair style can be mixed. A is always mixed via a -*geometric* rule. The cutoff is mixed according to the pair_modify -mix value. The default mix value is *geometric*\ . See the +For atom type pairs I,J and I != J, the epsilon and sigma coefficients and cutoff +distance for this pair style can be mixed. The default mix value is *geometric*\ . See the "pair_modify" command for details. This pair style support the :doc:`pair_modify ` shift option for the energy of the pair interaction. diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index dd5bd078a3..dc162bfaae 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -263,7 +263,7 @@ void PairUFM::write_restart(FILE *fp) fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); - } + } } } diff --git a/unittest/force-styles/tests/mol-pair-ufm.yaml b/unittest/force-styles/tests/mol-pair-ufm.yaml new file mode 100644 index 0000000000..a4ed9c4201 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-ufm.yaml @@ -0,0 +1,93 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 06:00:36 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair ufm +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic +input_file: in.fourmol +pair_style: ufm 8.0 +pair_coeff: ! | + 1 1 45 1 + 2 2 2.5 0.5 + 2 4 1.25 0.3 + 3 3 90 1.2 + 4 4 50 1.2 + 5 5 50 1.2 +extract: ! | + epsilon 2 + sigma 2 + scale 2 +natoms: 29 +init_vdwl: 15.9448178985075 +init_coul: 0 +init_stress: ! |2- + 2.6146863286957891e+00 3.3096167885357781e+00 1.8896692790686620e+00 -7.8103578168488674e-01 -6.3646037139141465e-01 -1.1050969820118191e+00 +init_forces: ! |2 + 1 -4.1107682568782042e-02 8.4159671159269589e-02 1.4364066878816075e-02 + 2 1.4855194550175699e-09 1.1595834852760475e-09 3.0222642548520869e-10 + 3 -8.4091235974453749e-01 8.6504468102758003e-01 5.6311502835738503e-01 + 4 -2.8369162919057533e-06 2.3093358001197420e-06 -6.8629050475239722e-06 + 5 2.8352737357564812e-06 -2.3104132057858338e-06 6.8626120453466700e-06 + 6 6.8227906787574855e-01 -7.4225150779271154e-01 -5.7924092724791576e-01 + 7 -1.0624422246648743e-02 -1.7713737837028117e-02 6.0685027629518388e-03 + 8 4.1107682568782042e-02 -8.4159671159269589e-02 -1.4364066878816075e-02 + 9 -8.4589231542866213e-09 -4.4870340991811177e-09 8.1470249958068988e-09 + 10 -1.5076237946330699e+00 -1.4818713946413264e-01 -2.7001103229334023e-01 + 11 -2.5234373282159868e-06 -4.9173823745521049e-06 2.4018562394577883e-06 + 12 1.0688406659323306e+00 1.0218751924370559e+00 -7.3324647342325111e-01 + 13 1.6247427935699038e-05 -1.1277029275365798e-05 5.4862483755923800e-06 + 14 -1.6644232300571339e-05 -1.3550601437242502e-05 -4.2100576670980872e-05 + 15 2.9288576529368216e-06 2.9749417943440398e-05 3.4204315806686696e-05 + 16 5.9741642056952804e-01 -9.9648122620779178e-01 1.0193834046071222e+00 + 17 6.0647800874562208e-05 -6.7138753522781464e-05 1.1587201951671083e-04 + 18 1.0555874350003051e-02 1.7766239964206315e-02 -6.1513369271515989e-03 + 19 -1.3385271294173110e-04 -1.1135668675472203e-04 -4.7773382101580517e-05 + 20 1.4175280871286179e-04 1.2599331309930736e-04 1.4735526784629409e-05 + 21 -3.2883236264640949e-314 -4.0183081710317287e-314 1.1784710987769653e-313 + 22 -2.0070940223656638e-04 -9.2248259523763674e-05 -8.5507042438020091e-05 + 23 2.0070940223656638e-04 9.2248259523763674e-05 8.5507042438020091e-05 + 24 2.5296422778585082e-314 -1.0640178056368574e-313 6.1834993002757979e-314 + 25 -1.4222865295220291e-04 -8.1775415336075356e-05 -7.8174976843060461e-05 + 26 1.4222865295220291e-04 8.1775415336075356e-05 7.8174976843060475e-05 + 27 1.7123386955271695e-314 -1.1695047946457333e-313 4.1453168286921200e-314 + 28 -1.5089915815236302e-04 -4.4475887332562913e-05 -7.2311197921039549e-05 + 29 1.5089915815236302e-04 4.4475887332562913e-05 7.2311197921039549e-05 +run_vdwl: 15.914861699973 +run_coul: 0 +run_stress: ! |2- + 2.5986029230420753e+00 3.2703803218300571e+00 1.8750476643208827e+00 -7.6811158158004422e-01 -6.4578984797982841e-01 -1.0961457953207117e+00 +run_forces: ! |2 + 1 -4.0285344683711741e-02 8.2721708589664378e-02 1.4050186122562973e-02 + 2 8.2524533331550006e-10 6.5064964459978354e-10 1.7834995585782599e-10 + 3 -8.3850322601506833e-01 8.6035681760410276e-01 5.5552529331530642e-01 + 4 -2.3621080627757856e-06 1.8984773073055223e-06 -5.7817438681843766e-06 + 5 2.3611663663774969e-06 -1.8990665800372113e-06 5.7815721165980424e-06 + 6 6.8338309348494286e-01 -7.3951579325775574e-01 -5.7116539020312607e-01 + 7 -1.0720959251302932e-02 -1.7896645856104468e-02 6.1253885515083562e-03 + 8 4.0285344683711741e-02 -8.2721708589664378e-02 -1.4050186122562973e-02 + 9 -1.2529030864834394e-08 -6.6015217820196229e-09 1.2066214019287245e-08 + 10 -1.4925702810659471e+00 -1.5492229055449536e-01 -2.5424719548240826e-01 + 11 -2.7825191632564174e-06 -5.3814455866493166e-06 2.6594982448938168e-06 + 12 1.0652652212470886e+00 1.0107254838122148e+00 -7.3255807711309329e-01 + 13 1.4554848679557421e-05 -1.0096970352400502e-05 4.2909309690308132e-06 + 14 -1.2196220854745091e-05 -8.1371410886308519e-06 -3.3215932875268475e-05 + 15 4.3653682037388778e-07 2.3622097172549777e-05 2.6253430848955018e-05 + 16 5.8242519234898404e-01 -9.7664421760406650e-01 1.0024453694833211e+00 + 17 5.9118312883491684e-05 -6.5197720063684263e-05 1.1296727313095274e-04 + 18 1.0666806754866611e-02 1.7959806185223737e-02 -6.2089089533038464e-03 + 19 -9.2155356734353660e-05 -7.6243764734605334e-05 -3.8917301718863713e-05 + 20 8.7189540287183314e-05 7.8281155679022087e-05 9.4704303834019288e-06 + 21 -3.3899956358599345e-314 -3.8120230525720721e-314 1.1774050158333511e-313 + 22 -1.8226187218665669e-04 -8.2023784186295039e-05 -7.6389640896495654e-05 + 23 1.8226187218665669e-04 8.2023784186295039e-05 7.6389640896495654e-05 + 24 2.8143855119790067e-314 -1.0911129688595383e-313 6.4142652183265380e-314 + 25 -1.6999302282135528e-04 -1.0050305244071937e-04 -9.5843764445722771e-05 + 26 1.6999302282135528e-04 1.0050305244071937e-04 9.5843764445722784e-05 + 27 1.9138245457764810e-314 -1.1871547879715288e-313 4.0053139644108828e-314 + 28 -1.6222449740137501e-04 -4.8434776046882793e-05 -7.8562045851869852e-05 + 29 1.6222449740137501e-04 4.8434776046882793e-05 7.8562045851869852e-05 +... From 10c0b8d90ede7798a4ec3cf75cdc2c689ad515a1 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 06:23:23 -0400 Subject: [PATCH 024/122] passing test for soft --- .../force-styles/tests/mol-pair-soft.yaml | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-soft.yaml diff --git a/unittest/force-styles/tests/mol-pair-soft.yaml b/unittest/force-styles/tests/mol-pair-soft.yaml new file mode 100644 index 0000000000..e4d08c80fd --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-soft.yaml @@ -0,0 +1,91 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 06:22:52 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair soft +pre_commands: ! "" +post_commands: ! | + pair_modify mix arithmetic +input_file: in.fourmol +pair_style: soft 8.0 +pair_coeff: ! | + 1 1 0.4 4.0 + 2 2 0.1 2.0 + 2 4 0.1 1.0 + 3 3 0.4 3.2 + 4 4 0.3 3.1 + 5 5 0.3 3.1 +extract: ! | + a 2 +natoms: 29 +init_vdwl: 1.84744817921225 +init_coul: 0 +init_stress: ! |2- + 2.6985212108047096e+00 1.8929069643988077e+00 1.7058942753638846e+00 -6.5932149182557875e-01 6.7921581099237543e-02 -3.2192722305869170e-01 +init_forces: ! |2 + 1 2.8065059411338959e-02 1.4475400640818467e-01 6.2167976642541665e-02 + 2 3.5911509159733825e-02 7.5792446542598854e-02 -1.6618358082877357e-02 + 3 -1.4978210463219779e-01 6.4481690232657984e-02 4.0565044686902113e-02 + 4 -7.6956178069581604e-02 5.6986638675930908e-03 -4.0814530409352151e-02 + 5 -4.0306591454846857e-02 -4.0167644420758424e-02 7.2397076865240495e-02 + 6 -2.7680420938296790e-01 2.5803299543823072e-02 -7.6840385376372625e-02 + 7 -2.4311862474414389e-01 6.9534442210756123e-02 -2.5757742214265328e-01 + 8 -1.4609308552009195e-01 3.5839567510574058e-02 8.7965658071998507e-02 + 9 -2.2929283546198997e-02 5.7589458497830828e-02 1.4659458498861072e-01 + 10 7.6881898642091440e-02 -2.1261632693724342e-01 2.3398538464963828e-02 + 11 -2.5548488247743126e-02 -9.5728272008179738e-02 -8.5017558264751270e-02 + 12 4.5575293493957508e-01 4.4215285128865606e-02 -1.0838174668791306e-01 + 13 8.7385440814045964e-02 1.4369146254701298e-02 -3.2854342757696768e-02 + 14 5.4238600872785710e-02 1.2802731437212927e-02 -1.1831929886630289e-01 + 15 1.2787389224046808e-01 1.0432267515211492e-01 7.7710287049113339e-04 + 16 9.3724777378964522e-02 -2.2611686804396253e-01 1.2700219209206529e-01 + 17 2.1704452138768593e-02 -8.0574301376769353e-02 1.7555546790510568e-01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 -1.5429553120582700e-02 -1.3201999530845885e-02 -3.8812356720092350e-03 + 20 1.5429553120582700e-02 1.3201999530845885e-02 3.8812356720092350e-03 + 21 -5.9237200537052750e-03 -7.4084310160892428e-03 2.2124250397136089e-02 + 22 -2.9672881568896178e-02 -1.1298549967770084e-02 -2.4947019320590125e-02 + 23 3.5596601622601455e-02 1.8706980983859325e-02 2.8227689234540335e-03 + 24 5.0712775121559053e-03 -1.9757475974717414e-02 1.1753823978318308e-02 + 25 -3.1967679147319392e-02 -7.0718964196126964e-03 -2.2042768641089366e-02 + 26 2.6896401635163485e-02 2.6829372394330111e-02 1.0288944662771058e-02 + 27 2.6771292067361979e-03 -2.1880100266431633e-02 7.4597018341065590e-03 + 28 -3.4007977163362471e-02 1.3475065504780902e-03 -1.9395024081220218e-02 + 29 3.1330847956626273e-02 2.0532593715953545e-02 1.1935322247113659e-02 +run_vdwl: 1.83829828942125 +run_coul: 0 +run_stress: ! |2- + 2.6892905229741615e+00 1.8773074522980040e+00 1.6971210837031294e+00 -6.5045070186391307e-01 7.2382715610406489e-02 -3.1681519062327174e-01 +run_forces: ! |2 + 1 2.7626736118196951e-02 1.4393320832535667e-01 6.1549716299969727e-02 + 2 3.6117855438409743e-02 7.4101092202603608e-02 -1.5982378744262574e-02 + 3 -1.4724464325147221e-01 6.3219011620168297e-02 4.0388108895068615e-02 + 4 -7.6142171668294706e-02 5.6496466639128981e-03 -4.0386869007112844e-02 + 5 -4.0845938192134723e-02 -3.9805571389576196e-02 7.1745451157293180e-02 + 6 -2.7527768022693161e-01 2.5778246462400661e-02 -7.7040603979213237e-02 + 7 -2.4250670528501000e-01 6.8897598543317229e-02 -2.5678447165959417e-01 + 8 -1.4768375175165319e-01 3.4263039142501096e-02 8.6711776256619397e-02 + 9 -2.4526067920006105e-02 5.8596447742611704e-02 1.4573287230011606e-01 + 10 7.6802510950124692e-02 -2.1164687608059429e-01 2.3118841931212428e-02 + 11 -2.6559265146753799e-02 -9.4978549234924270e-02 -8.4152147696980151e-02 + 12 4.5379546778717467e-01 4.3667011070801773e-02 -1.0853187850141469e-01 + 13 8.5243479408163791e-02 1.3932000514239925e-02 -3.1381748012984677e-02 + 14 5.1435367326329827e-02 1.3343258442794605e-02 -1.1493564124751957e-01 + 15 1.3339128203385975e-01 1.0558053320609068e-01 2.3707977032699952e-05 + 16 9.4366892717143866e-02 -2.2462180300122347e-01 1.2495235545192762e-01 + 17 2.2006631662853070e-02 -7.9908294230480917e-02 1.7497290857984224e-01 + 18 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 19 -1.3898431312129608e-02 -1.2070560777062287e-02 -3.3245364297847099e-03 + 20 1.3898431312129608e-02 1.2070560777062287e-02 3.3245364297847099e-03 + 21 -5.8721416852572598e-03 -6.8221851033155260e-03 2.1661339404847622e-02 + 22 -2.9638222891418445e-02 -1.1252824193905071e-02 -2.4457744535956755e-02 + 23 3.5510364576675703e-02 1.8075009297220598e-02 2.7964051311091332e-03 + 24 5.0213385208849031e-03 -1.9249804126643937e-02 1.1342934749424504e-02 + 25 -3.2261395726667752e-02 -7.9697928334289368e-03 -2.2443097170728836e-02 + 26 2.7240057205782847e-02 2.7219596960072874e-02 1.1100162421304330e-02 + 27 2.8815022657343505e-03 -2.1811274153260882e-02 7.0034740967186253e-03 + 28 -3.4289853071041654e-02 1.1414224698740975e-03 -1.9420628895038074e-02 + 29 3.1408350805307308e-02 2.0669851683386784e-02 1.2417154798319450e-02 +... From bb183345bb7aa96e0e802cef7f796dbe8259164b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 07:29:53 -0400 Subject: [PATCH 025/122] remove obsolete function --- unittest/force-styles/check_tests.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py index c65d075a4c..4c253df3a5 100755 --- a/unittest/force-styles/check_tests.py +++ b/unittest/force-styles/check_tests.py @@ -93,25 +93,6 @@ def add_suffix(list,style): else: return style -def check_style(file,dir,pattern,list,name,suffix=False,skip=()): - f = os.path.join(dir, file) - fp = open(f) - text = fp.read() - fp.close() - matches = re.findall(pattern,text,re.MULTILINE) - counter = 0 - for c in list.keys(): - # known undocumented aliases we need to skip - if c in skip: continue - s = c - if suffix: s = add_suffix(list,c) - if not s in matches: - if not list[c]['removed']: - print("%s style entry %s" % (name,s), - "is missing or incomplete in %s" % file) - counter += 1 - return counter - print("Parsing style names from C++ tree in: ",src) for h in headers: From 86c6efc04cc0a8d6c255626402710cd29742692f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 07:30:15 -0400 Subject: [PATCH 026/122] sort list of missing styles alphabetically --- unittest/force-styles/check_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py index 4c253df3a5..1ea9e687b5 100755 --- a/unittest/force-styles/check_tests.py +++ b/unittest/force-styles/check_tests.py @@ -185,6 +185,7 @@ def check_tests(name,list,yaml,search,skip=()): total = len(list) print("\nTests available for %s styles: %d of %d" % (name,total - num, total)) + missing.sort() print("No tests for: ", missing) return num From d241b17c8e6116787b005307c2f7b3686c96d4cb Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 07:44:32 -0400 Subject: [PATCH 027/122] remove unused setting and array --- src/OPT/pair_ufm_opt.cpp | 3 +-- src/pair_ufm.cpp | 4 ---- src/pair_ufm.h | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/OPT/pair_ufm_opt.cpp b/src/OPT/pair_ufm_opt.cpp index eabb093b18..d824d82e6c 100644 --- a/src/OPT/pair_ufm_opt.cpp +++ b/src/OPT/pair_ufm_opt.cpp @@ -58,7 +58,7 @@ void PairUFMOpt::eval() typedef struct { double x,y,z; } vec3_t; typedef struct { - double cutsq,uf1,uf2,uf3,uf4,scale,offset; + double cutsq,uf1,uf2,uf3,scale,offset; double _pad[2]; } fast_alpha_t; @@ -91,7 +91,6 @@ void PairUFMOpt::eval() a.uf1 = uf1[i+1][j+1]; a.uf2 = uf2[i+1][j+1]; a.uf3 = uf3[i+1][j+1]; - a.uf4 = uf4[i+1][j+1]; a.scale = scale[i+1][j+1]; a.offset = offset[i+1][j+1]; } diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index dc162bfaae..90a7400c60 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -53,7 +53,6 @@ PairUFM::~PairUFM() memory->destroy(uf1); memory->destroy(uf2); memory->destroy(uf3); - memory->destroy(uf4); memory->destroy(offset); } } @@ -154,7 +153,6 @@ void PairUFM::allocate() memory->create(uf1,n+1,n+1,"pair:uf1"); memory->create(uf2,n+1,n+1,"pair:uf2"); memory->create(uf3,n+1,n+1,"pair:uf3"); - memory->create(uf4,n+1,n+1,"pair:uf4"); memory->create(offset,n+1,n+1,"pair:offset"); } @@ -230,7 +228,6 @@ double PairUFM::init_one(int i, int j) uf1[i][j] = 2.0 * epsilon[i][j] / pow(sigma[i][j],2.0); uf2[i][j] = 1.0 / pow(sigma[i][j],2.0); uf3[i][j] = epsilon[i][j]; - uf4[i][j] = sigma[i][j]; if (offset_flag) { double ratio = pow(cut[i][j] / sigma[i][j],2.0); @@ -240,7 +237,6 @@ double PairUFM::init_one(int i, int j) uf1[j][i] = uf1[i][j]; uf2[j][i] = uf2[i][j]; uf3[j][i] = uf3[i][j]; - uf4[j][i] = uf4[i][j]; scale[j][i] = scale[i][j]; offset[j][i] = offset[i][j]; diff --git a/src/pair_ufm.h b/src/pair_ufm.h index e43cc7c6c3..492c0886e1 100644 --- a/src/pair_ufm.h +++ b/src/pair_ufm.h @@ -51,7 +51,7 @@ class PairUFM : public Pair { double cut_global; double **cut,**scale; double **epsilon,**sigma; - double **uf1,**uf2,**uf3,**uf4,**offset; + double **uf1,**uf2,**uf3,**offset; virtual void allocate(); }; From ad6b37d6884934e704b41a14fb11c5148a47c029 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 08:00:41 -0400 Subject: [PATCH 028/122] bug in forcelj of gauss_omp --- src/USER-OMP/pair_gauss_omp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-OMP/pair_gauss_omp.cpp b/src/USER-OMP/pair_gauss_omp.cpp index 106d520fa1..59c864afda 100644 --- a/src/USER-OMP/pair_gauss_omp.cpp +++ b/src/USER-OMP/pair_gauss_omp.cpp @@ -130,7 +130,7 @@ double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) if (rsq < cutsq[itype][jtype]) { r2inv = 1.0/rsq; - forcelj = - 2.0*a[itype][jtype]*b[itype][jtype] * rsq * + forcelj = - 2.0*a[itype][jtype]*b[itype][jtype] * sqrt(rsq) * exp(-b[itype][jtype]*rsq); fpair = factor_lj*forcelj*r2inv; From c171b2ceda7e59d80953e44710c56cb151c0eec4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 08:00:54 -0400 Subject: [PATCH 029/122] fix incomplete restart bug in pair style ufm --- src/pair_ufm.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index 90a7400c60..7d97c0f249 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -259,6 +259,7 @@ void PairUFM::write_restart(FILE *fp) fwrite(&epsilon[i][j],sizeof(double),1,fp); fwrite(&sigma[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); + fwrite(&scale[i][j],sizeof(double),1,fp); } } } @@ -283,10 +284,12 @@ void PairUFM::read_restart(FILE *fp) utils::sfread(FLERR,&epsilon[i][j],sizeof(double),1,fp,NULL,error); utils::sfread(FLERR,&sigma[i][j],sizeof(double),1,fp,NULL,error); utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error); + utils::sfread(FLERR,&scale[i][j],sizeof(double),1,fp,NULL,error); } MPI_Bcast(&epsilon[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&sigma[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); + MPI_Bcast(&scale[i][j],1,MPI_DOUBLE,0,world); } } } From 69688bbc1a02f4784f3e9bfbb37660c10b35c263 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 08:01:13 -0400 Subject: [PATCH 030/122] must initialize scale array entries when using mixed parameters --- src/pair_ufm.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pair_ufm.cpp b/src/pair_ufm.cpp index 7d97c0f249..3b94902af7 100644 --- a/src/pair_ufm.cpp +++ b/src/pair_ufm.cpp @@ -223,6 +223,7 @@ double PairUFM::init_one(int i, int j) sigma[i][i],sigma[j][j]); sigma[i][j] = mix_distance(sigma[i][i],sigma[j][j]); cut[i][j] = mix_distance(cut[i][i],cut[j][j]); + scale[i][j] = 1.0; } uf1[i][j] = 2.0 * epsilon[i][j] / pow(sigma[i][j],2.0); From f3d7f0be2d799edf5cc3bdef9ff4b7e452fbaa45 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 08:01:37 -0400 Subject: [PATCH 031/122] update test reference data for pair style ufm --- unittest/force-styles/tests/mol-pair-ufm.yaml | 124 +++++++++--------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/unittest/force-styles/tests/mol-pair-ufm.yaml b/unittest/force-styles/tests/mol-pair-ufm.yaml index a4ed9c4201..921cb38b87 100644 --- a/unittest/force-styles/tests/mol-pair-ufm.yaml +++ b/unittest/force-styles/tests/mol-pair-ufm.yaml @@ -1,6 +1,6 @@ --- lammps_version: 21 Jul 2020 -date_generated: Mon Aug 3 06:00:36 202 +date_generated: Mon Aug 3 07:56:59 202 epsilon: 5e-14 prerequisites: ! | atom full @@ -25,69 +25,69 @@ natoms: 29 init_vdwl: 15.9448178985075 init_coul: 0 init_stress: ! |2- - 2.6146863286957891e+00 3.3096167885357781e+00 1.8896692790686620e+00 -7.8103578168488674e-01 -6.3646037139141465e-01 -1.1050969820118191e+00 + 1.9732282556036175e+01 1.9835191003877362e+01 2.7171236603180098e+01 -6.0276271530964340e+00 2.5967187784084929e+00 -8.1372045900773349e-01 init_forces: ! |2 - 1 -4.1107682568782042e-02 8.4159671159269589e-02 1.4364066878816075e-02 - 2 1.4855194550175699e-09 1.1595834852760475e-09 3.0222642548520869e-10 - 3 -8.4091235974453749e-01 8.6504468102758003e-01 5.6311502835738503e-01 - 4 -2.8369162919057533e-06 2.3093358001197420e-06 -6.8629050475239722e-06 - 5 2.8352737357564812e-06 -2.3104132057858338e-06 6.8626120453466700e-06 - 6 6.8227906787574855e-01 -7.4225150779271154e-01 -5.7924092724791576e-01 - 7 -1.0624422246648743e-02 -1.7713737837028117e-02 6.0685027629518388e-03 - 8 4.1107682568782042e-02 -8.4159671159269589e-02 -1.4364066878816075e-02 - 9 -8.4589231542866213e-09 -4.4870340991811177e-09 8.1470249958068988e-09 - 10 -1.5076237946330699e+00 -1.4818713946413264e-01 -2.7001103229334023e-01 - 11 -2.5234373282159868e-06 -4.9173823745521049e-06 2.4018562394577883e-06 - 12 1.0688406659323306e+00 1.0218751924370559e+00 -7.3324647342325111e-01 - 13 1.6247427935699038e-05 -1.1277029275365798e-05 5.4862483755923800e-06 - 14 -1.6644232300571339e-05 -1.3550601437242502e-05 -4.2100576670980872e-05 - 15 2.9288576529368216e-06 2.9749417943440398e-05 3.4204315806686696e-05 - 16 5.9741642056952804e-01 -9.9648122620779178e-01 1.0193834046071222e+00 - 17 6.0647800874562208e-05 -6.7138753522781464e-05 1.1587201951671083e-04 - 18 1.0555874350003051e-02 1.7766239964206315e-02 -6.1513369271515989e-03 - 19 -1.3385271294173110e-04 -1.1135668675472203e-04 -4.7773382101580517e-05 - 20 1.4175280871286179e-04 1.2599331309930736e-04 1.4735526784629409e-05 - 21 -3.2883236264640949e-314 -4.0183081710317287e-314 1.1784710987769653e-313 - 22 -2.0070940223656638e-04 -9.2248259523763674e-05 -8.5507042438020091e-05 - 23 2.0070940223656638e-04 9.2248259523763674e-05 8.5507042438020091e-05 - 24 2.5296422778585082e-314 -1.0640178056368574e-313 6.1834993002757979e-314 - 25 -1.4222865295220291e-04 -8.1775415336075356e-05 -7.8174976843060461e-05 - 26 1.4222865295220291e-04 8.1775415336075356e-05 7.8174976843060475e-05 - 27 1.7123386955271695e-314 -1.1695047946457333e-313 4.1453168286921200e-314 - 28 -1.5089915815236302e-04 -4.4475887332562913e-05 -7.2311197921039549e-05 - 29 1.5089915815236302e-04 4.4475887332562913e-05 7.2311197921039549e-05 -run_vdwl: 15.914861699973 + 1 4.5504248628334903e-01 3.4810456499439786e+00 2.2933676689669587e+00 + 2 7.6305168829957026e-01 6.3530317978445050e-01 -8.9036825876478831e-01 + 3 -1.8690601375791762e+00 -2.1645243477399765e+00 -6.8190730045491799e-01 + 4 -4.9060182878861497e-01 6.5876976602437076e-02 -3.5503868870755761e-01 + 5 -2.0102869525213915e-01 -3.8949773372359570e-01 6.2535384203678079e-01 + 6 -2.6274409039041418e+00 2.4336497785248898e+00 1.0369661611270873e+00 + 7 -1.3560259995068289e+00 -1.2772656392333670e-01 -7.1023140339542641e+00 + 8 -6.4025705488694629e-01 1.0679865652191836e-01 4.5451315353321204e+00 + 9 2.9507058002930570e-01 3.4981430259329627e-01 1.3803472304944715e+00 + 10 1.6374694484178089e+00 -3.0558458419429053e+00 -1.3354748713256701e+00 + 11 -1.0758177441827732e-01 -3.4994788188976184e-01 -5.1197568645668567e-01 + 12 2.5492171186156019e+00 6.5886771199024263e-01 -1.0862959541524593e+00 + 13 4.7621167365961320e-01 -1.8587205385870362e-01 -1.0222940193228331e-02 + 14 -1.7603608882946584e-01 4.3504499871130406e-02 -5.0281518244465484e-01 + 15 4.5361490089936077e-02 5.1848034510437291e-01 1.5415051650370429e-01 + 16 2.1328814585282205e+00 -2.1866672606821682e+00 -2.4060706185663778e+00 + 17 -8.9999804484173351e-01 1.4743507307760853e-01 4.8534606303597769e+00 + 18 1.2106041473247691e-02 1.8842262895887824e-02 -8.5584514737465592e-03 + 19 -1.3385261603705734e-04 -1.1135664238248275e-04 -4.7773605824832037e-05 + 20 1.4175280884626526e-04 1.2599331315280051e-04 1.4735526619335452e-05 + 21 -3.0992491483280571e-01 -3.7873259082555194e-01 1.1107164955435957e+00 + 22 -5.3868102728249767e-01 -1.3058785720297120e-01 -8.4490111696627568e-01 + 23 8.4861881376462789e-01 5.0930289141035923e-01 -2.6583104815819147e-01 + 24 2.3873703064906404e-01 -1.0027550706486636e+00 5.8324803300429706e-01 + 25 -7.6174385767345199e-01 1.2255216806610444e-01 -6.4030765955815661e-01 + 26 5.2462722077066415e-01 8.8068125955598875e-01 5.9367518146113858e-02 + 27 1.6145714500530384e-01 -1.1022323446883984e+00 3.9068430664596004e-01 + 28 -8.1023255837556163e-01 3.4809165087801702e-01 -5.4818142230389000e-01 + 29 6.4875279039251865e-01 7.5412850363458084e-01 1.5750233339920508e-01 +run_vdwl: 15.8616853432207 run_coul: 0 run_stress: ! |2- - 2.5986029230420753e+00 3.2703803218300571e+00 1.8750476643208827e+00 -7.6811158158004422e-01 -6.4578984797982841e-01 -1.0961457953207117e+00 + 1.9704622560525500e+01 1.9754158723084281e+01 2.6918293581501548e+01 -5.9193995790449732e+00 2.5978531689912998e+00 -6.8056943099087752e-01 run_forces: ! |2 - 1 -4.0285344683711741e-02 8.2721708589664378e-02 1.4050186122562973e-02 - 2 8.2524533331550006e-10 6.5064964459978354e-10 1.7834995585782599e-10 - 3 -8.3850322601506833e-01 8.6035681760410276e-01 5.5552529331530642e-01 - 4 -2.3621080627757856e-06 1.8984773073055223e-06 -5.7817438681843766e-06 - 5 2.3611663663774969e-06 -1.8990665800372113e-06 5.7815721165980424e-06 - 6 6.8338309348494286e-01 -7.3951579325775574e-01 -5.7116539020312607e-01 - 7 -1.0720959251302932e-02 -1.7896645856104468e-02 6.1253885515083562e-03 - 8 4.0285344683711741e-02 -8.2721708589664378e-02 -1.4050186122562973e-02 - 9 -1.2529030864834394e-08 -6.6015217820196229e-09 1.2066214019287245e-08 - 10 -1.4925702810659471e+00 -1.5492229055449536e-01 -2.5424719548240826e-01 - 11 -2.7825191632564174e-06 -5.3814455866493166e-06 2.6594982448938168e-06 - 12 1.0652652212470886e+00 1.0107254838122148e+00 -7.3255807711309329e-01 - 13 1.4554848679557421e-05 -1.0096970352400502e-05 4.2909309690308132e-06 - 14 -1.2196220854745091e-05 -8.1371410886308519e-06 -3.3215932875268475e-05 - 15 4.3653682037388778e-07 2.3622097172549777e-05 2.6253430848955018e-05 - 16 5.8242519234898404e-01 -9.7664421760406650e-01 1.0024453694833211e+00 - 17 5.9118312883491684e-05 -6.5197720063684263e-05 1.1296727313095274e-04 - 18 1.0666806754866611e-02 1.7959806185223737e-02 -6.2089089533038464e-03 - 19 -9.2155356734353660e-05 -7.6243764734605334e-05 -3.8917301718863713e-05 - 20 8.7189540287183314e-05 7.8281155679022087e-05 9.4704303834019288e-06 - 21 -3.3899956358599345e-314 -3.8120230525720721e-314 1.1774050158333511e-313 - 22 -1.8226187218665669e-04 -8.2023784186295039e-05 -7.6389640896495654e-05 - 23 1.8226187218665669e-04 8.2023784186295039e-05 7.6389640896495654e-05 - 24 2.8143855119790067e-314 -1.0911129688595383e-313 6.4142652183265380e-314 - 25 -1.6999302282135528e-04 -1.0050305244071937e-04 -9.5843764445722771e-05 - 26 1.6999302282135528e-04 1.0050305244071937e-04 9.5843764445722784e-05 - 27 1.9138245457764810e-314 -1.1871547879715288e-313 4.0053139644108828e-314 - 28 -1.6222449740137501e-04 -4.8434776046882793e-05 -7.8562045851869852e-05 - 29 1.6222449740137501e-04 4.8434776046882793e-05 7.8562045851869852e-05 + 1 4.6903795102238893e-01 3.4471790043074155e+00 2.2640326341430215e+00 + 2 7.6427680253286634e-01 6.4702697653716934e-01 -8.6215350378922051e-01 + 3 -1.8902490585622824e+00 -2.1559409924348119e+00 -6.9086875111459189e-01 + 4 -4.7430793207488930e-01 6.2813433399308227e-02 -3.5076010872032221e-01 + 5 -1.9879364631586235e-01 -3.8501258616973499e-01 6.1824037742347249e-01 + 6 -2.5716612036374440e+00 2.4177563896101719e+00 1.0062676333138174e+00 + 7 -1.3347634312538770e+00 -1.4511347465531174e-01 -6.9675921787319837e+00 + 8 -7.1498788348429509e-01 1.5391724346667593e-01 4.4685151545430370e+00 + 9 2.9615072254263686e-01 3.3708016766855387e-01 1.3713681175110519e+00 + 10 1.6655332876219688e+00 -3.0788062316905531e+00 -1.3504181585572872e+00 + 11 -1.0306905364905536e-01 -3.3356589147782040e-01 -4.8759025549290741e-01 + 12 2.5169000137107895e+00 6.4582882727212410e-01 -1.1056167824067793e+00 + 13 4.7054556829988514e-01 -1.7465871278068992e-01 -8.8125330381007318e-03 + 14 -1.7032572507595736e-01 3.5259835099716995e-02 -4.8334906008812817e-01 + 15 4.2767520433916968e-02 5.2350958298539818e-01 1.6209825101785580e-01 + 16 2.1143962306578636e+00 -2.1840227122816378e+00 -2.4240301278985545e+00 + 17 -8.9533735300142869e-01 1.6722226177508540e-01 4.8470364684175822e+00 + 18 1.2261297596017708e-02 1.9073134618042799e-02 -8.6622912414690278e-03 + 19 -9.2155271780368733e-05 -7.6243732200517104e-05 -3.8917607684509680e-05 + 20 8.7189700241686489e-05 7.8281328511723715e-05 9.4703340946688672e-06 + 21 -3.1869976742612299e-01 -3.5843123331627225e-01 1.1070634590860970e+00 + 22 -5.5867106087024820e-01 -1.4541411463906775e-01 -8.4593741645822229e-01 + 23 8.7738409629915826e-01 5.0382698964562944e-01 -2.6114213167044648e-01 + 24 2.6498504176502491e-01 -1.0258227472014936e+00 6.0360128434208293e-01 + 25 -8.0774237261472659e-01 1.1152388846740779e-01 -6.8104225005845753e-01 + 26 5.4439728655438058e-01 9.1478096833295830e-01 7.9776496092276342e-02 + 27 1.7993245937868463e-01 -1.1162011028189709e+00 3.7656761514775627e-01 + 28 -8.3013122622639413e-01 3.5173620238034337e-01 -5.5033868810132658e-01 + 29 6.5017640134854016e-01 7.6445285630405291e-01 1.7377619360333854e-01 ... From 7e5e741ea1597bbcff7eaefb97b9360fc25ca5b8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 08:12:09 -0400 Subject: [PATCH 032/122] update code for ufm/gpu to match changes in base class where uf4 is removed --- lib/gpu/lal_ufm.cpp | 31 +++++++++++++++---------------- lib/gpu/lal_ufm.h | 23 +++++++++++------------ lib/gpu/lal_ufm_ext.cpp | 33 ++++++++++++++++----------------- src/GPU/pair_ufm_gpu.cpp | 8 ++++---- 4 files changed, 46 insertions(+), 49 deletions(-) diff --git a/lib/gpu/lal_ufm.cpp b/lib/gpu/lal_ufm.cpp index 9b7d42dec9..a86d07f340 100644 --- a/lib/gpu/lal_ufm.cpp +++ b/lib/gpu/lal_ufm.cpp @@ -10,7 +10,7 @@ This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) __________________________________________________________________________ - begin : + begin : email : pl.rodolfo@gmail.com dekoning@ifi.unicamp.br ***************************************************************************/ @@ -38,7 +38,7 @@ template UFMT::~UFM() { clear(); } - + template int UFMT::bytes_per_atom(const int max_nbors) const { return this->bytes_per_atom_atomic(max_nbors); @@ -46,9 +46,9 @@ int UFMT::bytes_per_atom(const int max_nbors) const { template int UFMT::init(const int ntypes, - double **host_cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, - double **host_uf4, double **host_offset, + double **host_cutsq, double **host_uf1, + double **host_uf2, double **host_uf3, + double **host_offset, double *host_special_lj, const int nlocal, const int nall, const int max_nbors, const int maxspecial, const double cell_size, @@ -78,11 +78,11 @@ int UFMT::init(const int ntypes, uf1.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY); this->atom->type_pack4(ntypes,lj_types,uf1,host_write,host_uf1,host_uf2, - host_cutsq); + host_cutsq); uf3.alloc(lj_types*lj_types,*(this->ucl_device),UCL_READ_ONLY); - this->atom->type_pack4(ntypes,lj_types,uf3,host_write,host_uf3,host_uf4, - host_offset); + this->atom->type_pack4(ntypes,lj_types,uf3,host_write,host_uf3,host_uf2, + host_offset); UCL_H_Vec dview; sp_lj.alloc(4,*(this->ucl_device),UCL_READ_ONLY); @@ -96,18 +96,17 @@ int UFMT::init(const int ntypes, template void UFMT::reinit(const int ntypes, double **host_cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, - double **host_uf4, double **host_offset) { + double **host_uf2, double **host_uf3, double **host_offset) { // Allocate a host write buffer for data initialization UCL_H_Vec host_write(_lj_types*_lj_types*32,*(this->ucl_device), UCL_WRITE_ONLY); - + for (int i=0; i<_lj_types*_lj_types; i++) host_write[i]=0.0; - + this->atom->type_pack4(ntypes,_lj_types,uf1,host_write,host_uf1,host_uf2, host_cutsq); - this->atom->type_pack4(ntypes,_lj_types,uf3,host_write,host_uf3,host_uf4, + this->atom->type_pack4(ntypes,_lj_types,uf3,host_write,host_uf3,host_uf2, host_offset); } @@ -145,7 +144,7 @@ void UFMT::loop(const bool _eflag, const bool _vflag) { vflag=1; else vflag=0; - + int GX=static_cast(ceil(static_cast(this->ans->inum())/ (BX/this->_threads_per_atom))); @@ -157,12 +156,12 @@ void UFMT::loop(const bool _eflag, const bool _vflag) { this->k_pair_fast.run(&this->atom->x, &uf1, &uf3, &sp_lj, &this->nbor->dev_nbor, &this->_nbor_data->begin(), &this->ans->force, &this->ans->engv, &eflag, - &vflag, &ainum, &nbor_pitch, + &vflag, &ainum, &nbor_pitch, &this->_threads_per_atom); } else { this->k_pair.set_size(GX,BX); this->k_pair.run(&this->atom->x, &uf1, &uf3, &_lj_types, &sp_lj, - &this->nbor->dev_nbor, &this->_nbor_data->begin(), + &this->nbor->dev_nbor, &this->_nbor_data->begin(), &this->ans->force, &this->ans->engv, &eflag, &vflag, &ainum, &nbor_pitch, &this->_threads_per_atom); } diff --git a/lib/gpu/lal_ufm.h b/lib/gpu/lal_ufm.h index 65ee15d5b5..14b96bcc86 100644 --- a/lib/gpu/lal_ufm.h +++ b/lib/gpu/lal_ufm.h @@ -10,7 +10,7 @@ This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) __________________________________________________________________________ - begin : + begin : email : pl.rodolfo@gmail.com dekoning@ifi.unicamp.br ***************************************************************************/ @@ -32,7 +32,7 @@ class UFM : public BaseAtomic { /** \param max_nbors initial number of rows in the neighbor matrix * \param cell_size cutoff + skin * \param gpu_split fraction of particles handled by device - * + * * Returns: * - 0 if successful * - -1 if fix gpu not found @@ -41,16 +41,15 @@ class UFM : public BaseAtomic { * - -5 Double precision is not supported on card **/ int init(const int ntypes, double **host_cutsq, double **host_uf1, double **host_uf2, double **host_uf3, - double **host_uf4, double **host_offset, double *host_special_lj, - const int nlocal, const int nall, const int max_nbors, - const int maxspecial, const double cell_size, + double **host_offset, double *host_special_lj, + const int nlocal, const int nall, const int max_nbors, + const int maxspecial, const double cell_size, const double gpu_split, FILE *screen); - + /// Send updated coeffs from host to device (to be compatible with fix adapt) - void reinit(const int ntypes, double **host_cutsq, - double **host_uf1, double **host_uf2, double **host_uf3, - double **host_uf4, double **host_offset); - + void reinit(const int ntypes, double **host_cutsq, double **host_uf1, + double **host_uf2, double **host_uf3, double **host_offset); + /// Clear all host and device data /** \note This is called at the beginning of the init() routine **/ void clear(); @@ -65,7 +64,7 @@ class UFM : public BaseAtomic { /// uf1.x = uf1, uf1.y = uf2, uf1.z = cutsq UCL_D_Vec uf1; - /// uf3.x = uf3, uf3.y = uf4, uf3.z = offset + /// uf3.x = uf3, uf3.y = uf2, uf3.z = offset UCL_D_Vec uf3; /// Special LJ values UCL_D_Vec sp_lj; @@ -73,7 +72,7 @@ class UFM : public BaseAtomic { /// If atom type constants fit in shared memory, use fast kernels bool shared_types; - /// Number of atom types + /// Number of atom types int _lj_types; private: diff --git a/lib/gpu/lal_ufm_ext.cpp b/lib/gpu/lal_ufm_ext.cpp index dd476ec3fa..12809a28fb 100644 --- a/lib/gpu/lal_ufm_ext.cpp +++ b/lib/gpu/lal_ufm_ext.cpp @@ -10,7 +10,7 @@ This file is part of the LAMMPS Accelerator Library (LAMMPS_AL) __________________________________________________________________________ - begin : + begin : email : pl.rodolfo@gmail.com dekoning@ifi.unicamp.br ***************************************************************************/ @@ -30,10 +30,10 @@ static UFM UFMLMF; // Allocate memory on host and device and copy constants to device // --------------------------------------------------------------------------- int ufml_gpu_init(const int ntypes, double **cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, double **host_uf4, - double **offset, double *special_lj, const int inum, const int nall, - const int max_nbors, const int maxspecial, const double cell_size, - int &gpu_mode, FILE *screen) { + double **host_uf2, double **host_uf3, double **offset, + double *special_lj, const int inum, const int nall, + const int max_nbors, const int maxspecial, const double cell_size, + int &gpu_mode, FILE *screen) { UFMLMF.clear(); gpu_mode=UFMLMF.device->gpu_mode(); double gpu_split=UFMLMF.device->particle_split(); @@ -57,8 +57,8 @@ int ufml_gpu_init(const int ntypes, double **cutsq, double **host_uf1, int init_ok=0; if (world_me==0) init_ok=UFMLMF.init(ntypes, cutsq, host_uf1, host_uf2, host_uf3, - host_uf4, offset, special_lj, inum, nall, 300, - maxspecial, cell_size, gpu_split, screen); + offset, special_lj, inum, nall, 300, + maxspecial, cell_size, gpu_split, screen); UFMLMF.device->world_barrier(); if (message) @@ -74,12 +74,12 @@ int ufml_gpu_init(const int ntypes, double **cutsq, double **host_uf1, fflush(screen); } if (gpu_rank==i && world_me!=0) - init_ok=UFMLMF.init(ntypes, cutsq, host_uf1, host_uf2, host_uf3, host_uf4, + init_ok=UFMLMF.init(ntypes, cutsq, host_uf1, host_uf2, host_uf3, offset, special_lj, inum, nall, 300, maxspecial, cell_size, gpu_split, screen); UFMLMF.device->gpu_barrier(); - if (message) + if (message) fprintf(screen,"Done.\n"); } if (message) @@ -94,19 +94,18 @@ int ufml_gpu_init(const int ntypes, double **cutsq, double **host_uf1, // Copy updated coeffs from host to device // --------------------------------------------------------------------------- void ufml_gpu_reinit(const int ntypes, double **cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, double **host_uf4, - double **offset) { + double **host_uf2, double **host_uf3, double **offset) { int world_me=UFMLMF.device->world_me(); int gpu_rank=UFMLMF.device->gpu_rank(); int procs_per_gpu=UFMLMF.device->procs_per_gpu(); - + if (world_me==0) - UFMLMF.reinit(ntypes, cutsq, host_uf1, host_uf2, host_uf3, host_uf4, offset); + UFMLMF.reinit(ntypes, cutsq, host_uf1, host_uf2, host_uf3, offset); UFMLMF.device->world_barrier(); - + for (int i=0; igpu_barrier(); } } @@ -125,8 +124,8 @@ int ** ufml_gpu_compute_n(const int ago, const int inum_full, return UFMLMF.compute(ago, inum_full, nall, host_x, host_type, sublo, subhi, tag, nspecial, special, eflag, vflag, eatom, vatom, host_start, ilist, jnum, cpu_time, success); -} - +} + void ufml_gpu_compute(const int ago, const int inum_full, const int nall, double **host_x, int *host_type, int *ilist, int *numj, int **firstneigh, const bool eflag, const bool vflag, diff --git a/src/GPU/pair_ufm_gpu.cpp b/src/GPU/pair_ufm_gpu.cpp index cea898b050..2b4cc2269f 100644 --- a/src/GPU/pair_ufm_gpu.cpp +++ b/src/GPU/pair_ufm_gpu.cpp @@ -43,13 +43,13 @@ using namespace LAMMPS_NS; // External functions from cuda library for atom decomposition int ufml_gpu_init(const int ntypes, double **cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, double **host_uf4, + double **host_uf2, double **host_uf3, double **offset, double *special_lj, const int nlocal, const int nall, const int max_nbors, const int maxspecial, const double cell_size, int &gpu_mode, FILE *screen); int ufml_gpu_reinit(const int ntypes, double **cutsq, double **host_uf1, - double **host_uf2, double **host_uf3, double **host_uf4, + double **host_uf2, double **host_uf3, double **offset); void ufml_gpu_clear(); @@ -166,7 +166,7 @@ void PairUFMGPU::init_style() int maxspecial=0; if (atom->molecular) maxspecial=atom->maxspecial; - int success = ufml_gpu_init(atom->ntypes+1, cutsq, uf1, uf2, uf3, uf4, + int success = ufml_gpu_init(atom->ntypes+1, cutsq, uf1, uf2, uf3, offset, force->special_lj, atom->nlocal, atom->nlocal+atom->nghost, 300, maxspecial, cell_size, gpu_mode, screen); @@ -185,7 +185,7 @@ void PairUFMGPU::reinit() { Pair::reinit(); - ufml_gpu_reinit(atom->ntypes+1, cutsq, uf1, uf2, uf3, uf4, offset); + ufml_gpu_reinit(atom->ntypes+1, cutsq, uf1, uf2, uf3, offset); } /* ---------------------------------------------------------------------- */ From 9bc1da64fbdf86646ddef57674b305e1160edfab Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 08:42:36 -0400 Subject: [PATCH 033/122] pair style gauss does not apply special_bonds --- src/USER-OMP/pair_gauss_omp.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/USER-OMP/pair_gauss_omp.cpp b/src/USER-OMP/pair_gauss_omp.cpp index 59c864afda..103a766614 100644 --- a/src/USER-OMP/pair_gauss_omp.cpp +++ b/src/USER-OMP/pair_gauss_omp.cpp @@ -80,8 +80,7 @@ template double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) { int i,j,ii,jj,jnum,itype,jtype; - double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; - double rsq,r2inv,forcelj,factor_lj; + double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair,rsq; int *ilist,*jlist,*numneigh,**firstneigh; int occ = 0; @@ -91,7 +90,6 @@ double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0]; const int * _noalias const type = atom->type; const int nlocal = atom->nlocal; - const double * _noalias const special_lj = force->special_lj; double fxtmp,fytmp,fztmp; ilist = list->ilist; @@ -113,7 +111,6 @@ double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) for (jj = 0; jj < jnum; jj++) { j = jlist[jj]; - factor_lj = special_lj[sbmask(j)]; j &= NEIGHMASK; delx = xtmp - x[j].x; @@ -129,10 +126,7 @@ double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) if (eflag_global && rsq < 0.5/b[itype][jtype]) occ++; if (rsq < cutsq[itype][jtype]) { - r2inv = 1.0/rsq; - forcelj = - 2.0*a[itype][jtype]*b[itype][jtype] * sqrt(rsq) * - exp(-b[itype][jtype]*rsq); - fpair = factor_lj*forcelj*r2inv; + fpair = -2.0*a[itype][jtype]*b[itype][jtype]*exp(-b[itype][jtype]*rsq); fxtmp += delx*fpair; fytmp += dely*fpair; @@ -143,11 +137,9 @@ double PairGaussOMP::eval(int iifrom, int iito, ThrData * const thr) f[j].z -= delz*fpair; } - if (EFLAG) { + if (EFLAG) evdwl = -(a[itype][jtype]*exp(-b[itype][jtype]*rsq) - offset[itype][jtype]); - evdwl *= factor_lj; - } if (EVFLAG) ev_tally_thr(this, i,j,nlocal,NEWTON_PAIR, evdwl,0.0,fpair,delx,dely,delz,thr); From 865e853a419cf11b156e699b4ec6749fe2b978f4 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 3 Aug 2020 10:37:45 -0400 Subject: [PATCH 034/122] Refactor check_tests.py --- unittest/force-styles/check_tests.py | 244 ++++++++++++--------------- 1 file changed, 111 insertions(+), 133 deletions(-) diff --git a/unittest/force-styles/check_tests.py b/unittest/force-styles/check_tests.py index 1ea9e687b5..9adc66044e 100755 --- a/unittest/force-styles/check_tests.py +++ b/unittest/force-styles/check_tests.py @@ -1,16 +1,13 @@ #!/usr/bin/env python3 - -from __future__ import print_function +import os, re, sys from glob import glob from argparse import ArgumentParser -import os, re, sys parser = ArgumentParser(prog='check_tests.py', description="Check force tests for completeness") parser.add_argument("-v", "--verbose", - action='store_const', - const=True, default=False, + action='store_true', help="Enable verbose output") parser.add_argument("-t", "--tests", @@ -20,30 +17,32 @@ parser.add_argument("-s", "--src", args = parser.parse_args() verbose = args.verbose -src = args.src -tests = args.tests +src_dir = args.src +tests_dir = args.tests -if not src: - src = os.path.join('.','..','..','src') +LAMMPS_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) -if not tests: - tests = os.path.join(src,'..','unittest','force-styles','tests') +if not src_dir: + src_dir = os.path.join(LAMMPS_DIR , 'src') + +if not tests_dir: + tests_dir = os.path.join(LAMMPS_DIR, 'unittest', 'force-styles', 'tests') try: - src = os.path.abspath(os.path.expanduser(src)) - tests = os.path.abspath(os.path.expanduser(tests)) + src_dir = os.path.abspath(os.path.expanduser(src_dir)) + tests_dir = os.path.abspath(os.path.expanduser(tests_dir)) except: - parser.print_help() - sys.exit(1) + parser.print_help() + sys.exit(1) -if not os.path.isdir(src): - sys.exit("LAMMPS source path %s does not exist" % src) +if not os.path.isdir(src_dir): + sys.exit(f"LAMMPS source path {src_dir} does not exist") -if not os.path.isdir(tests): - sys.exit("LAMMPS test inputs path %s does not exist" % tests) +if not os.path.isdir(tests_dir): + sys.exit(f"LAMMPS test inputs path {tests_dir} does not exist") -headers = glob(os.path.join(src, '*', '*.h')) -headers += glob(os.path.join(src, '*.h')) +headers = glob(os.path.join(src_dir, '*', '*.h')) +headers += glob(os.path.join(src_dir, '*.h')) angle = {} bond = {} @@ -54,9 +53,8 @@ fix = {} improper = {} kspace = {} pair = {} -total = 0 -upper = re.compile("[A-Z]+") +style_pattern = re.compile("(.+)Style\((.+),(.+)\)") gpu = re.compile("(.+)/gpu$") intel = re.compile("(.+)/intel$") kokkos = re.compile("(.+)/kk$") @@ -65,130 +63,110 @@ omp = re.compile("(.+)/omp$") opt = re.compile("(.+)/opt$") removed = re.compile("(.*)Deprecated$") -def register_style(list,style,info): - if style in list.keys(): - list[style]['gpu'] += info['gpu'] - list[style]['intel'] += info['intel'] - list[style]['kokkos'] += info['kokkos'] - list[style]['omp'] += info['omp'] - list[style]['opt'] += info['opt'] - list[style]['removed'] += info['removed'] +def register_style(styles, name, info): + if name in styles: + styles[name]['gpu'] += info['gpu'] + styles[name]['intel'] += info['intel'] + styles[name]['kokkos'] += info['kokkos'] + styles[name]['omp'] += info['omp'] + styles[name]['opt'] += info['opt'] + styles[name]['removed'] += info['removed'] else: - list[style] = info + styles[name] = info -def add_suffix(list,style): - suffix = "" - if list[style]['gpu']: - suffix += 'g' - if list[style]['intel']: - suffix += 'i' - if list[style]['kokkos']: - suffix += 'k' - if list[style]['omp']: - suffix += 'o' - if list[style]['opt']: - suffix += 't' - if suffix: - return style + ' (' + suffix + ')' - else: - return style +print("Parsing style names from C++ tree in: ", src_dir) -print("Parsing style names from C++ tree in: ",src) +for header in headers: + if verbose: print("Checking ", header) + with open(header) as f: + for line in f: + matches = style_pattern.findall(line) -for h in headers: - if verbose: print("Checking ", h) - fp = open(h) - text = fp.read() - fp.close() - matches = re.findall("(.+)Style\((.+),(.+)\)",text,re.MULTILINE) - for m in matches: + for m in matches: + # skip over internal styles w/o explicit documentation + style = m[1] + if style.isupper(): + continue - # skip over internal styles w/o explicit documentation - style = m[1] - total += 1 - if upper.match(style): - continue + # detect, process, and flag suffix styles: + info = { 'kokkos': 0, 'gpu': 0, 'intel': 0, \ + 'omp': 0, 'opt': 0, 'removed': 0 } + suffix = kokkos_skip.match(style) + if suffix: + continue + suffix = gpu.match(style) + if suffix: + style = suffix.groups()[0] + info['gpu'] = 1 + suffix = intel.match(style) + if suffix: + style = suffix.groups()[0] + info['intel'] = 1 + suffix = kokkos.match(style) + if suffix: + style = suffix.groups()[0] + info['kokkos'] = 1 + suffix = omp.match(style) + if suffix: + style = suffix.groups()[0] + info['omp'] = 1 + suffix = opt.match(style) + if suffix: + style = suffix.groups()[0] + info['opt'] = 1 + deprecated = removed.match(m[2]) + if deprecated: + info['removed'] = 1 - # detect, process, and flag suffix styles: - info = { 'kokkos': 0, 'gpu': 0, 'intel': 0, \ - 'omp': 0, 'opt': 0, 'removed': 0 } - suffix = kokkos_skip.match(style) - if suffix: - continue - suffix = gpu.match(style) - if suffix: - style = suffix.groups()[0] - info['gpu'] = 1 - suffix = intel.match(style) - if suffix: - style = suffix.groups()[0] - info['intel'] = 1 - suffix = kokkos.match(style) - if suffix: - style = suffix.groups()[0] - info['kokkos'] = 1 - suffix = omp.match(style) - if suffix: - style = suffix.groups()[0] - info['omp'] = 1 - suffix = opt.match(style) - if suffix: - style = suffix.groups()[0] - info['opt'] = 1 - deprecated = removed.match(m[2]) - if deprecated: - info['removed'] = 1 - - # register style and suffix flags - if m[0] == 'Angle': - register_style(angle,style,info) - elif m[0] == 'Bond': - register_style(bond,style,info) - elif m[0] == 'Dihedral': - register_style(dihedral,style,info) - elif m[0] == 'Improper': - register_style(improper,style,info) - elif m[0] == 'KSpace': - register_style(kspace,style,info) - elif m[0] == 'Pair': - register_style(pair,style,info) + # register style and suffix flags + if m[0] == 'Angle': + register_style(angle,style,info) + elif m[0] == 'Bond': + register_style(bond,style,info) + elif m[0] == 'Dihedral': + register_style(dihedral,style,info) + elif m[0] == 'Improper': + register_style(improper,style,info) + elif m[0] == 'KSpace': + register_style(kspace,style,info) + elif m[0] == 'Pair': + register_style(pair,style,info) -counter = 0 -def check_tests(name,list,yaml,search,skip=()): - num = 0 - yaml_files = glob(os.path.join(tests, yaml)) - styles = [] - missing = [] +def check_tests(name,styles,yaml,search,skip=()): + yaml_files = glob(os.path.join(tests_dir, yaml)) + tests = set() + missing = set() + search_pattern = re.compile(search) for y in yaml_files: if verbose: print("Checking: ",y) - fp = open(y) - text = fp.read() - fp.close() - matches = re.findall(search,text,re.MULTILINE) - for m in matches: - if m[1] == 'hybrid' or m[1] == 'hybrid/overlay': - for s in m[0].split(): - if s in list.keys(): - styles.append(s) - else: - styles.append(m[1]) - for s in list.keys(): + with open(y) as f: + for line in f: + matches = search_pattern.findall(line) + for m in matches: + if m[1] == 'hybrid' or m[1] == 'hybrid/overlay': + for s in m[0].split(): + if s in styles: + tests.add(s) + else: + tests.add(m[1]) + for s in styles: # known undocumented aliases we need to skip if s in skip: continue - if not s in styles: - if not list[s]['removed']: + if not s in tests: + if not styles[s]['removed']: if verbose: print("No test for %s style %s" % (name,s)) - num += 1 - missing.append(s) - total = len(list) - print("\nTests available for %s styles: %d of %d" - % (name,total - num, total)) - missing.sort() - print("No tests for: ", missing) - return num + missing.add(s) + num_missing = len(missing) + total = len(styles) + num_tests = total - num_missing + print(f"\nTests available for {name} styles: {num_tests} of {total}") + print("No tests for: ", list(missing)) + return num_missing + +counter = 0 counter += check_tests('pair',pair,'*-pair-*.yaml', '.*pair_style:\s*((\S+).*)?',skip=('meam','lj/sf')) counter += check_tests('bond',bond,'bond-*.yaml', @@ -203,4 +181,4 @@ counter += check_tests('kspace',kspace,'kspace-*.yaml', '.*kspace_style\s*((\S+).*)?') total = len(pair)+len(bond)+len(angle)+len(dihedral)+len(improper)+len(kspace) -print("\nTotal tests missing: %d of %d" % (counter, total)) +print(f"\nTotal tests missing: {counter} of {total}") From d09d40af9df483d9b600bf423a6bd8d5c710918a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 11:36:02 -0400 Subject: [PATCH 035/122] make check for alternate linke more restrictive: also check for linker binary. --- cmake/Modules/Testing.cmake | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cmake/Modules/Testing.cmake b/cmake/Modules/Testing.cmake index 29f8b61802..6d2f39b0f3 100644 --- a/cmake/Modules/Testing.cmake +++ b/cmake/Modules/Testing.cmake @@ -23,14 +23,17 @@ if(ENABLE_TESTING) OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) include(CheckCXXCompilerFlag) set(CMAKE_CUSTOM_LINKER_DEFAULT default) - check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER) - check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER) - check_cxx_compiler_flag(-fuse-ld=bfd HAVE_BFD_LINKER) - if(HAVE_LLD_LINKER) + check_cxx_compiler_flag(-fuse-ld=lld HAVE_LLD_LINKER_FLAG) + check_cxx_compiler_flag(-fuse-ld=gold HAVE_GOLD_LINKER_FLAG) + check_cxx_compiler_flag(-fuse-ld=bfd HAVE_BFD_LINKER_FLAG) + find_program(HAVE_LLD_LINKER_BIN lld ld.lld) + find_program(HAVE_GOLD_LINKER_BIN ld.gold) + find_program(HAVE_BFD_LINKER_BIN ld.bfd) + if(HAVE_LLD_LINKER_FLAG AND HAVE_LLD_LINKER_BIN) set(CMAKE_CUSTOM_LINKER_DEFAULT lld) - elseif(HAVE_GOLD_LINKER) + elseif(HAVE_GOLD_LINKER_FLAG AND HAVE_GOLD_LINKER_BIN) set(CMAKE_CUSTOM_LINKER_DEFAULT gold) - elseif(HAVE_BFD_LINKER) + elseif(HAVE_BFD_LINKER_FLAG AND HAVE_BFD_LINKER_BIN) set(CMAKE_CUSTOM_LINKER_DEFAULT bfd) endif() set(CMAKE_CUSTOM_LINKER_VALUES lld gold bfd default) From 4549493145762473079844283f1d950894d74a37 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 3 Aug 2020 13:47:40 -0400 Subject: [PATCH 036/122] Refactor check-packages.py --- doc/utils/check-packages.py | 104 +++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/doc/utils/check-packages.py b/doc/utils/check-packages.py index 52d527fd95..de64142c04 100755 --- a/doc/utils/check-packages.py +++ b/doc/utils/check-packages.py @@ -1,16 +1,14 @@ #!/usr/bin/env python3 -from __future__ import print_function +import os, re, sys from glob import glob from argparse import ArgumentParser -import os, re, sys parser = ArgumentParser(prog='check-packages.py', description="Check package table completeness") parser.add_argument("-v", "--verbose", - action='store_const', - const=True, default=False, + action='store_true', help="Enable verbose output") parser.add_argument("-d", "--doc", @@ -20,20 +18,28 @@ parser.add_argument("-s", "--src", args = parser.parse_args() verbose = args.verbose -src = args.src -doc = args.doc +src_dir = args.src +doc_dir = args.doc -if not args.src or not args.doc: - parser.print_help() - sys.exit(1) +LAMMPS_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) -if not os.path.isdir(src): - sys.exit("LAMMPS source path %s does not exist" % src) +if not src_dir: + src_dir = os.path.join(LAMMPS_DIR , 'src') -if not os.path.isdir(doc): - sys.exit("LAMMPS documentation source path %s does not exist" % doc) +if not doc_dir: + doc_dir = os.path.join(LAMMPS_DIR, 'doc', 'src') -pkgdirs = glob(os.path.join(src, '[A-Z][A-Z]*')) +if not src_dir or not doc_dir: + parser.print_help() + sys.exit(1) + +if not os.path.isdir(src_dir): + sys.exit(f"LAMMPS source path {src_dir} does not exist") + +if not os.path.isdir(doc_dir): + sys.exit(f"LAMMPS documentation source path {doc_dir} does not exist") + +pkgdirs = glob(os.path.join(src_dir, '[A-Z][A-Z]*')) dirs = re.compile(".*/([0-9A-Z-]+)$") user = re.compile("USER-.*") @@ -45,53 +51,51 @@ usrpkg = [] # folder, and is not called 'MAKE' is a package for d in pkgdirs: - pkg = dirs.match(d).group(1) - if not os.path.isdir(os.path.join(src,pkg)): continue - if pkg in ['DEPEND','MAKE','STUBS']: continue - if user.match(pkg): - usrpkg.append(pkg) - else: - stdpkg.append(pkg) + pkg = dirs.match(d).group(1) + if not os.path.isdir(os.path.join(src_dir, pkg)): continue + if pkg in ['DEPEND','MAKE','STUBS']: continue + if user.match(pkg): + usrpkg.append(pkg) + else: + stdpkg.append(pkg) -print("Found %d standard and %d user packages" % (len(stdpkg),len(usrpkg))) +print(f"Found {len(stdpkg)} standard and {len(usrpkg)} user packages") counter = 0 -fp = open(os.path.join(doc,'Packages_standard.rst')) -text = fp.read() -fp.close() -matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`',text,re.MULTILINE) + +with open(os.path.join(doc_dir, 'Packages_standard.rst')) as fp: + text = fp.read() + +matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE) for p in stdpkg: if not p in matches: - ++counter - print("Standard package %s missing in Packages_standard.rst" - % p) + counter += 1 + print(f"Standard package {p} missing in Packages_standard.rst") -fp = open(os.path.join(doc,'Packages_user.rst')) -text = fp.read() -fp.close() -matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`',text,re.MULTILINE) +with open(os.path.join(doc_dir, 'Packages_user.rst')) as fp: + text = fp.read() + +matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE) for p in usrpkg: if not p in matches: - ++counter - print("User package %s missing in Packages_user.rst" - % p) + counter += 1 + print(f"User package {p} missing in Packages_user.rst") -fp = open(os.path.join(doc,'Packages_details.rst')) -text = fp.read() -fp.close() -matches = re.findall(':ref:`([A-Z0-9]+) `',text,re.MULTILINE) +with open(os.path.join(doc_dir, 'Packages_details.rst')) as fp: + text = fp.read() + +matches = re.findall(':ref:`([A-Z0-9]+) `', text, re.MULTILINE) for p in stdpkg: - if not p in matches: - ++counter - print("Standard package %s missing in Packages_details.rst" - % p) -matches = re.findall(':ref:`(USER-[A-Z0-9]+) `',text,re.MULTILINE) + if not p in matches: + counter += 1 + print(f"Standard package {p} missing in Packages_details.rst") + +matches = re.findall(':ref:`(USER-[A-Z0-9]+) `', text, re.MULTILINE) for p in usrpkg: - if not p in matches: - ++counter - print("User package %s missing in Packages_details.rst" - % p) + if not p in matches: + counter +=1 + print(f"User package {p} missing in Packages_details.rst") if counter: - print("Found %d issue(s) with package lists" % counter) + print(f"Found {counter} issue(s) with package lists") From f9d1a914fbb257aea19e1e33617b3e679f60fdd8 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 3 Aug 2020 13:49:37 -0400 Subject: [PATCH 037/122] Update check-packages.py --- doc/utils/check-packages.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/utils/check-packages.py b/doc/utils/check-packages.py index de64142c04..339d584c59 100755 --- a/doc/utils/check-packages.py +++ b/doc/utils/check-packages.py @@ -66,7 +66,7 @@ counter = 0 with open(os.path.join(doc_dir, 'Packages_standard.rst')) as fp: text = fp.read() -matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE) +matches = set(re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE)) for p in stdpkg: if not p in matches: counter += 1 @@ -75,7 +75,7 @@ for p in stdpkg: with open(os.path.join(doc_dir, 'Packages_user.rst')) as fp: text = fp.read() -matches = re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE) +matches = set(re.findall(':ref:`([A-Z0-9-]+) <[A-Z0-9-]+>`', text, re.MULTILINE)) for p in usrpkg: if not p in matches: counter += 1 @@ -84,13 +84,13 @@ for p in usrpkg: with open(os.path.join(doc_dir, 'Packages_details.rst')) as fp: text = fp.read() -matches = re.findall(':ref:`([A-Z0-9]+) `', text, re.MULTILINE) +matches = set(re.findall(':ref:`([A-Z0-9]+) `', text, re.MULTILINE)) for p in stdpkg: if not p in matches: counter += 1 print(f"Standard package {p} missing in Packages_details.rst") -matches = re.findall(':ref:`(USER-[A-Z0-9]+) `', text, re.MULTILINE) +matches = set(re.findall(':ref:`(USER-[A-Z0-9]+) `', text, re.MULTILINE)) for p in usrpkg: if not p in matches: counter +=1 From d0be21941939e7445d9c9cc19921240806e38390 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Mon, 3 Aug 2020 14:26:55 -0400 Subject: [PATCH 038/122] Refactor check-styles.py --- doc/utils/check-styles.py | 275 +++++++++++++++++++------------------- 1 file changed, 138 insertions(+), 137 deletions(-) diff --git a/doc/utils/check-styles.py b/doc/utils/check-styles.py index 40e6109f5b..603f312e9d 100755 --- a/doc/utils/check-styles.py +++ b/doc/utils/check-styles.py @@ -1,16 +1,14 @@ #!/usr/bin/env python3 -from __future__ import print_function +import os, re, sys from glob import glob from argparse import ArgumentParser -import os, re, sys parser = ArgumentParser(prog='check-styles.py', description="Check style table completeness") parser.add_argument("-v", "--verbose", - action='store_const', - const=True, default=False, + action='store_true', help="Enable verbose output") parser.add_argument("-d", "--doc", @@ -20,21 +18,29 @@ parser.add_argument("-s", "--src", args = parser.parse_args() verbose = args.verbose -src = args.src -doc = args.doc +src_dir = args.src +doc_dir = args.doc -if not args.src or not args.doc: +LAMMPS_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) + +if not src_dir: + src_dir = os.path.join(LAMMPS_DIR , 'src') + +if not doc_dir: + doc_dir = os.path.join(LAMMPS_DIR, 'doc', 'src') + +if not src_dir or not doc_dir: parser.print_help() sys.exit(1) -if not os.path.isdir(src): - sys.exit("LAMMPS source path %s does not exist" % src) +if not os.path.isdir(src_dir): + sys.exit(f"LAMMPS source path {src_dir} does not exist") -if not os.path.isdir(doc): - sys.exit("LAMMPS documentation source path %s does not exist" % doc) +if not os.path.isdir(doc_dir): + sys.exit(f"LAMMPS documentation source path {doc_dir} does not exist") -headers = glob(os.path.join(src, '*', '*.h')) -headers += glob(os.path.join(src, '*.h')) +headers = glob(os.path.join(src_dir, '*', '*.h')) +headers += glob(os.path.join(src_dir, '*.h')) angle = {} atom = {} @@ -54,6 +60,7 @@ reader = {} region = {} total = 0 +style_pattern = re.compile(r"(.+)Style\((.+),(.+)\)") upper = re.compile("[A-Z]+") gpu = re.compile("(.+)/gpu$") intel = re.compile("(.+)/intel$") @@ -63,132 +70,125 @@ omp = re.compile("(.+)/omp$") opt = re.compile("(.+)/opt$") removed = re.compile("(.*)Deprecated$") -def register_style(list,style,info): - if style in list.keys(): - list[style]['gpu'] += info['gpu'] - list[style]['intel'] += info['intel'] - list[style]['kokkos'] += info['kokkos'] - list[style]['omp'] += info['omp'] - list[style]['opt'] += info['opt'] - list[style]['removed'] += info['removed'] +def register_style(styles, name, info): + if name in styles: + for key, value in info.items(): + styles[name][key] += value else: - list[style] = info + styles[name] = info -def add_suffix(list,style): +def add_suffix(styles, name): suffix = "" - if list[style]['gpu']: + if styles[name]['gpu']: suffix += 'g' - if list[style]['intel']: + if styles[name]['intel']: suffix += 'i' - if list[style]['kokkos']: + if styles[name]['kokkos']: suffix += 'k' - if list[style]['omp']: + if styles[name]['omp']: suffix += 'o' - if list[style]['opt']: + if styles[name]['opt']: suffix += 't' if suffix: - return style + ' (' + suffix + ')' + return f"{name} ({suffix})" else: - return style + return name + +def check_style(filename, dirname, pattern, styles, name, suffix=False, skip=set()): + with open(os.path.join(dirname, filename)) as f: + text = f.read() + + matches = re.findall(pattern, text, re.MULTILINE) -def check_style(file,dir,pattern,list,name,suffix=False,skip=()): - f = os.path.join(dir, file) - fp = open(f) - text = fp.read() - fp.close() - matches = re.findall(pattern,text,re.MULTILINE) counter = 0 - for c in list.keys(): + for c in styles: # known undocumented aliases we need to skip if c in skip: continue s = c - if suffix: s = add_suffix(list,c) + if suffix: s = add_suffix(styles, c) if not s in matches: - if not list[c]['removed']: - print("%s style entry %s" % (name,s), - "is missing or incomplete in %s" % file) + if not styles[c]['removed']: + print(f"{name} style entry {s} is missing or incomplete in {filename}") counter += 1 return counter -for h in headers: - if verbose: print("Checking ", h) - fp = open(h) - text = fp.read() - fp.close() - matches = re.findall("(.+)Style\((.+),(.+)\)",text,re.MULTILINE) - for m in matches: +for header in headers: + if verbose: print("Checking ", header) + with open(header) as f: + for line in f: + matches = style_pattern.findall(line) + for m in matches: + # skip over internal styles w/o explicit documentation + style = m[1] + total += 1 + if upper.match(style): + continue - # skip over internal styles w/o explicit documentation - style = m[1] - total += 1 - if upper.match(style): - continue + # detect, process, and flag suffix styles: + info = { 'kokkos': 0, 'gpu': 0, 'intel': 0, \ + 'omp': 0, 'opt': 0, 'removed': 0 } + suffix = kokkos_skip.match(style) + if suffix: + continue + suffix = gpu.match(style) + if suffix: + style = suffix.groups()[0] + info['gpu'] = 1 + suffix = intel.match(style) + if suffix: + style = suffix.groups()[0] + info['intel'] = 1 + suffix = kokkos.match(style) + if suffix: + style = suffix.groups()[0] + info['kokkos'] = 1 + suffix = omp.match(style) + if suffix: + style = suffix.groups()[0] + info['omp'] = 1 + suffix = opt.match(style) + if suffix: + style = suffix.groups()[0] + info['opt'] = 1 + deprecated = removed.match(m[2]) + if deprecated: + info['removed'] = 1 - # detect, process, and flag suffix styles: - info = { 'kokkos': 0, 'gpu': 0, 'intel': 0, \ - 'omp': 0, 'opt': 0, 'removed': 0 } - suffix = kokkos_skip.match(style) - if suffix: - continue - suffix = gpu.match(style) - if suffix: - style = suffix.groups()[0] - info['gpu'] = 1 - suffix = intel.match(style) - if suffix: - style = suffix.groups()[0] - info['intel'] = 1 - suffix = kokkos.match(style) - if suffix: - style = suffix.groups()[0] - info['kokkos'] = 1 - suffix = omp.match(style) - if suffix: - style = suffix.groups()[0] - info['omp'] = 1 - suffix = opt.match(style) - if suffix: - style = suffix.groups()[0] - info['opt'] = 1 - deprecated = removed.match(m[2]) - if deprecated: - info['removed'] = 1 - - # register style and suffix flags - if m[0] == 'Angle': - register_style(angle,style,info) - elif m[0] == 'Atom': - register_style(atom,style,info) - elif m[0] == 'Body': - register_style(body,style,info) - elif m[0] == 'Bond': - register_style(bond,style,info) - elif m[0] == 'Command': - register_style(command,style,info) - elif m[0] == 'Compute': - register_style(compute,style,info) - elif m[0] == 'Dihedral': - register_style(dihedral,style,info) - elif m[0] == 'Dump': - register_style(dump,style,info) - elif m[0] == 'Fix': - register_style(fix,style,info) - elif m[0] == 'Improper': - register_style(improper,style,info) - elif m[0] == 'Integrate': - register_style(integrate,style,info) - elif m[0] == 'KSpace': - register_style(kspace,style,info) - elif m[0] == 'Minimize': - register_style(minimize,style,info) - elif m[0] == 'Pair': - register_style(pair,style,info) - elif m[0] == 'Reader': - register_style(reader,style,info) - elif m[0] == 'Region': - register_style(region,style,info) - else: - print("Skipping over: ",m) + # register style and suffix flags + if m[0] == 'Angle': + register_style(angle,style,info) + elif m[0] == 'Atom': + register_style(atom,style,info) + elif m[0] == 'Body': + register_style(body,style,info) + elif m[0] == 'Bond': + register_style(bond,style,info) + elif m[0] == 'Command': + register_style(command,style,info) + elif m[0] == 'Compute': + register_style(compute,style,info) + elif m[0] == 'Dihedral': + register_style(dihedral,style,info) + elif m[0] == 'Dump': + register_style(dump,style,info) + elif m[0] == 'Fix': + register_style(fix,style,info) + elif m[0] == 'Improper': + register_style(improper,style,info) + elif m[0] == 'Integrate': + register_style(integrate,style,info) + elif m[0] == 'KSpace': + register_style(kspace,style,info) + elif m[0] == 'Minimize': + register_style(minimize,style,info) + elif m[0] == 'Pair': + register_style(pair,style,info) + elif m[0] == 'Reader': + register_style(reader,style,info) + elif m[0] == 'Region': + register_style(region,style,info) + else: + print("Skipping over: ",m) print("""Parsed style names w/o suffixes from C++ tree in %s: @@ -202,44 +202,45 @@ print("""Parsed style names w/o suffixes from C++ tree in %s: Reader styles: %3d Region styles: %3d ---------------------------------------------------- Total number of styles (including suffixes): %d""" \ - % (src, len(angle), len(atom), len(body), len(bond), \ + % (src_dir, len(angle), len(atom), len(body), len(bond), \ len(command), len(compute), len(dihedral), len(dump), \ len(fix), len(improper), len(integrate), len(kspace), \ len(minimize), len(pair), len(reader), len(region), total)) + counter = 0 -counter += check_style('Commands_all.rst',doc,":doc:`(.+) <.+>`", +counter += check_style('Commands_all.rst', doc_dir, ":doc:`(.+) <.+>`", command,'Command',suffix=False) -counter += check_style('Commands_compute.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_compute.rst', doc_dir, ":doc:`(.+) `", compute,'Compute',suffix=True) -counter += check_style('compute.rst',doc,":doc:`(.+) ` -", +counter += check_style('compute.rst', doc_dir, ":doc:`(.+) ` -", compute,'Compute',suffix=False) -counter += check_style('Commands_fix.rst',doc,":doc:`(.+) `", - fix,'Fix',skip=('python'),suffix=True) -counter += check_style('fix.rst',doc,":doc:`(.+) ` -", - fix,'Fix',skip=('python'),suffix=False) -counter += check_style('Commands_pair.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_fix.rst', doc_dir, ":doc:`(.+) `", + fix,'Fix',skip=('python', 'NEIGH_HISTORY/omp'),suffix=True) +counter += check_style('fix.rst', doc_dir, ":doc:`(.+) ` -", + fix,'Fix',skip=('python', 'NEIGH_HISTORY/omp'),suffix=False) +counter += check_style('Commands_pair.rst', doc_dir, ":doc:`(.+) `", pair,'Pair',skip=('meam','lj/sf'),suffix=True) -counter += check_style('pair_style.rst',doc,":doc:`(.+) ` -", +counter += check_style('pair_style.rst', doc_dir, ":doc:`(.+) ` -", pair,'Pair',skip=('meam','lj/sf'),suffix=False) -counter += check_style('Commands_bond.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_bond.rst', doc_dir, ":doc:`(.+) `", bond,'Bond',suffix=True) -counter += check_style('bond_style.rst',doc,":doc:`(.+) ` -", +counter += check_style('bond_style.rst', doc_dir, ":doc:`(.+) ` -", bond,'Bond',suffix=False) -counter += check_style('Commands_bond.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_bond.rst', doc_dir, ":doc:`(.+) `", angle,'Angle',suffix=True) -counter += check_style('angle_style.rst',doc,":doc:`(.+) ` -", +counter += check_style('angle_style.rst', doc_dir, ":doc:`(.+) ` -", angle,'Angle',suffix=False) -counter += check_style('Commands_bond.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_bond.rst', doc_dir, ":doc:`(.+) `", dihedral,'Dihedral',suffix=True) -counter += check_style('dihedral_style.rst',doc,":doc:`(.+) ` -", +counter += check_style('dihedral_style.rst', doc_dir, ":doc:`(.+) ` -", dihedral,'Dihedral',suffix=False) -counter += check_style('Commands_bond.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_bond.rst', doc_dir, ":doc:`(.+) `", improper,'Improper',suffix=True) -counter += check_style('improper_style.rst',doc,":doc:`(.+) ` -", +counter += check_style('improper_style.rst', doc_dir, ":doc:`(.+) ` -", improper,'Improper',suffix=False) -counter += check_style('Commands_kspace.rst',doc,":doc:`(.+) `", +counter += check_style('Commands_kspace.rst', doc_dir, ":doc:`(.+) `", kspace,'KSpace',suffix=True) if counter: From 8d406403bba4473e4fb4efd6454bbf2f6695421b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 16:07:06 -0400 Subject: [PATCH 039/122] fix typo in manual --- doc/src/pair_colloid.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/pair_colloid.rst b/doc/src/pair_colloid.rst index eb02695aec..e60a326642 100644 --- a/doc/src/pair_colloid.rst +++ b/doc/src/pair_colloid.rst @@ -77,7 +77,7 @@ The colloid-solvent interaction energy is given by \left[ 1 - \frac{\left(5 ~ a^6+45~a^4~r^2+63~a^2~r^4+15~r^6\right) \sigma^6} {15 \left(a-r\right)^6 \left( a+r \right)^6} \right], \quad r < r_c -where :math:A_{cs}` is the Hamaker constant, *a* is the radius of the colloidal +where :math:`A_{cs}` is the Hamaker constant, *a* is the radius of the colloidal particle, and :math:`r_c` is the cutoff. This formula is derived from the colloid-colloid interaction, letting one of the particle sizes go to zero. From 7ed748118e90089dd9e815447f0449825fc3a365 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 16:07:32 -0400 Subject: [PATCH 040/122] add exception for single test for colloid pair style --- unittest/force-styles/test_pair_style.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/unittest/force-styles/test_pair_style.cpp b/unittest/force-styles/test_pair_style.cpp index 6a5da31abd..f1ad5ce2e7 100644 --- a/unittest/force-styles/test_pair_style.cpp +++ b/unittest/force-styles/test_pair_style.cpp @@ -1101,9 +1101,12 @@ TEST(PairStyle, single) // The single function in EAM is different from what we assume // here, therefore we have to skip testing those pair styles. - if ((test_config.pair_style.substr(0, 3) == "eam") || + // Pair style colloid is also not compatible with this single tester + if ((test_config.pair_style.substr(0, 7) == "colloid") || + (test_config.pair_style.substr(0, 3) == "eam") || ((test_config.pair_style.substr(0, 6) == "hybrid") && - (test_config.pair_style.find("eam") != std::string::npos))) { + (test_config.pair_style.find("eam") != std::string::npos)) + ) { if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); From a6b3ee7a07155077bf1e6cdc2fd28239a0cf25d0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 16:08:13 -0400 Subject: [PATCH 041/122] fix bugs in comm style tiled with multi-cutoff --- src/comm_tiled.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 849227983a..6930ad13e8 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -90,14 +90,13 @@ void CommTiled::init_buffers() maxoverlap = 0; overlap = NULL; - - maxswap = 6; - allocate_swap(maxswap); - rcbinfo = NULL; - cutghostmulti = NULL; sendbox_multi = NULL; + + maxswap = 6; + nswap = 2*domain->dimension; + allocate_swap(maxswap); } /* ---------------------------------------------------------------------- */ From 6dcd96271881b04452a9f6230cbbe16fa01241b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 16:08:27 -0400 Subject: [PATCH 042/122] fix indentation and whitespace --- src/comm_tiled.cpp | 412 ++++++++++++++++++++++----------------------- 1 file changed, 206 insertions(+), 206 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 6930ad13e8..03cb56921a 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -73,7 +73,7 @@ CommTiled::~CommTiled() memory->destroy(overlap); deallocate_swap(maxswap); memory->sfree(rcbinfo); - + if (mode == Comm::MULTI) memory->destroy(cutghostmulti); } @@ -208,7 +208,7 @@ void CommTiled::setup() cut = MIN(prd[0],prd[1]); if (dimension == 3) cut = MIN(cut,prd[2]); cut *= EPSILON*EPSILON; - cutghost[0] = cutghost[1] = cutghost[2] = cut; + cutghost[0] = cutghost[1] = cutghost[2] = cut; } // setup forward/reverse communication @@ -325,136 +325,136 @@ void CommTiled::setup() // if sbox touches other proc's sub-box boundaries in lower dims, // extend sbox in those lower dims to include ghost atoms // single mode and multi mode - + double oboxlo[3],oboxhi[3],sbox[6],sbox_multi[6]; - + if (mode == Comm::SINGLE) { - for (i = 0; i < noverlap; i++) { - pbc_flag[iswap][i] = 0; - pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = - pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + for (i = 0; i < noverlap; i++) { + pbc_flag[iswap][i] = 0; + pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; - (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); + (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); - if (i < noverlap1) { - sbox[0] = MAX(oboxlo[0],lo1[0]); - sbox[1] = MAX(oboxlo[1],lo1[1]); - sbox[2] = MAX(oboxlo[2],lo1[2]); - sbox[3] = MIN(oboxhi[0],hi1[0]); - sbox[4] = MIN(oboxhi[1],hi1[1]); - sbox[5] = MIN(oboxhi[2],hi1[2]); - } else { - pbc_flag[iswap][i] = 1; - if (idir == 0) pbc[iswap][i][idim] = 1; - else pbc[iswap][i][idim] = -1; - sbox[0] = MAX(oboxlo[0],lo2[0]); - sbox[1] = MAX(oboxlo[1],lo2[1]); - sbox[2] = MAX(oboxlo[2],lo2[2]); - sbox[3] = MIN(oboxhi[0],hi2[0]); - sbox[4] = MIN(oboxhi[1],hi2[1]); - sbox[5] = MIN(oboxhi[2],hi2[2]); - } - - if (idir == 0) { - sbox[idim] = sublo[idim]; - if (i < noverlap1) sbox[3+idim] = MIN(sbox[3+idim]+cut,subhi[idim]); - else sbox[3+idim] = MIN(sbox[3+idim]-prd[idim]+cut,subhi[idim]); - } else { - if (i < noverlap1) sbox[idim] = MAX(sbox[idim]-cut,sublo[idim]); - else sbox[idim] = MAX(sbox[idim]+prd[idim]-cut,sublo[idim]); - sbox[3+idim] = subhi[idim]; - } + if (i < noverlap1) { + sbox[0] = MAX(oboxlo[0],lo1[0]); + sbox[1] = MAX(oboxlo[1],lo1[1]); + sbox[2] = MAX(oboxlo[2],lo1[2]); + sbox[3] = MIN(oboxhi[0],hi1[0]); + sbox[4] = MIN(oboxhi[1],hi1[1]); + sbox[5] = MIN(oboxhi[2],hi1[2]); + } else { + pbc_flag[iswap][i] = 1; + if (idir == 0) pbc[iswap][i][idim] = 1; + else pbc[iswap][i][idim] = -1; + sbox[0] = MAX(oboxlo[0],lo2[0]); + sbox[1] = MAX(oboxlo[1],lo2[1]); + sbox[2] = MAX(oboxlo[2],lo2[2]); + sbox[3] = MIN(oboxhi[0],hi2[0]); + sbox[4] = MIN(oboxhi[1],hi2[1]); + sbox[5] = MIN(oboxhi[2],hi2[2]); + } - if (idim >= 1) { - if (sbox[0] == oboxlo[0]) sbox[0] -= cut; - if (sbox[3] == oboxhi[0]) sbox[3] += cut; - } - if (idim == 2) { - if (sbox[1] == oboxlo[1]) sbox[1] -= cut; - if (sbox[4] == oboxhi[1]) sbox[4] += cut; - } + if (idir == 0) { + sbox[idim] = sublo[idim]; + if (i < noverlap1) sbox[3+idim] = MIN(sbox[3+idim]+cut,subhi[idim]); + else sbox[3+idim] = MIN(sbox[3+idim]-prd[idim]+cut,subhi[idim]); + } else { + if (i < noverlap1) sbox[idim] = MAX(sbox[idim]-cut,sublo[idim]); + else sbox[idim] = MAX(sbox[idim]+prd[idim]-cut,sublo[idim]); + sbox[3+idim] = subhi[idim]; + } - memcpy(sendbox[iswap][i],sbox,6*sizeof(double)); - } + if (idim >= 1) { + if (sbox[0] == oboxlo[0]) sbox[0] -= cut; + if (sbox[3] == oboxhi[0]) sbox[3] += cut; + } + if (idim == 2) { + if (sbox[1] == oboxlo[1]) sbox[1] -= cut; + if (sbox[4] == oboxhi[1]) sbox[4] += cut; + } + + memcpy(sendbox[iswap][i],sbox,6*sizeof(double)); + } } if (mode == Comm::MULTI) { for (i = 0; i < noverlap; i++) { - pbc_flag[iswap][i] = 0; - pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = - pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; + pbc_flag[iswap][i] = 0; + pbc[iswap][i][0] = pbc[iswap][i][1] = pbc[iswap][i][2] = + pbc[iswap][i][3] = pbc[iswap][i][4] = pbc[iswap][i][5] = 0; - (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); + (this->*box_other)(idim,idir,overlap[i],oboxlo,oboxhi); - if (i < noverlap1) { - sbox[0] = MAX(oboxlo[0],lo1[0]); - sbox[1] = MAX(oboxlo[1],lo1[1]); - sbox[2] = MAX(oboxlo[2],lo1[2]); - sbox[3] = MIN(oboxhi[0],hi1[0]); - sbox[4] = MIN(oboxhi[1],hi1[1]); - sbox[5] = MIN(oboxhi[2],hi1[2]); - } else { - pbc_flag[iswap][i] = 1; - if (idir == 0) pbc[iswap][i][idim] = 1; - else pbc[iswap][i][idim] = -1; - sbox[0] = MAX(oboxlo[0],lo2[0]); - sbox[1] = MAX(oboxlo[1],lo2[1]); - sbox[2] = MAX(oboxlo[2],lo2[2]); - sbox[3] = MIN(oboxhi[0],hi2[0]); - sbox[4] = MIN(oboxhi[1],hi2[1]); - sbox[5] = MIN(oboxhi[2],hi2[2]); - } - - for (int itype = 1; itype <= atom->ntypes; itype++) { - sbox_multi[0] = sbox[0]; - sbox_multi[1] = sbox[1]; - sbox_multi[2] = sbox[2]; - sbox_multi[3] = sbox[3]; - sbox_multi[4] = sbox[4]; - sbox_multi[5] = sbox[5]; - if (idir == 0) { - sbox_multi[idim] = sublo[idim]; - if (i < noverlap1) - sbox_multi[3+idim] = - MIN(sbox_multi[3+idim]+cutghostmulti[itype][idim],subhi[idim]); - else - sbox_multi[3+idim] = - MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[itype][idim], - subhi[idim]); - } else { - if (i < noverlap1) - sbox_multi[idim] = - MAX(sbox_multi[idim]-cutghostmulti[itype][idim],sublo[idim]); - else - sbox_multi[idim] = - MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[itype][idim], - sublo[idim]); - sbox_multi[3+idim] = subhi[idim]; - } - - if (idim >= 1) { - if (sbox_multi[0] == oboxlo[0]) - sbox_multi[0] -= cutghostmulti[itype][idim]; - if (sbox_multi[3] == oboxhi[0]) - sbox_multi[3] += cutghostmulti[itype][idim]; - } - if (idim == 2) { - if (sbox_multi[1] == oboxlo[1]) - sbox_multi[1] -= cutghostmulti[itype][idim]; - if (sbox_multi[4] == oboxhi[1]) - sbox_multi[4] += cutghostmulti[itype][idim]; - } + if (i < noverlap1) { + sbox[0] = MAX(oboxlo[0],lo1[0]); + sbox[1] = MAX(oboxlo[1],lo1[1]); + sbox[2] = MAX(oboxlo[2],lo1[2]); + sbox[3] = MIN(oboxhi[0],hi1[0]); + sbox[4] = MIN(oboxhi[1],hi1[1]); + sbox[5] = MIN(oboxhi[2],hi1[2]); + } else { + pbc_flag[iswap][i] = 1; + if (idir == 0) pbc[iswap][i][idim] = 1; + else pbc[iswap][i][idim] = -1; + sbox[0] = MAX(oboxlo[0],lo2[0]); + sbox[1] = MAX(oboxlo[1],lo2[1]); + sbox[2] = MAX(oboxlo[2],lo2[2]); + sbox[3] = MIN(oboxhi[0],hi2[0]); + sbox[4] = MIN(oboxhi[1],hi2[1]); + sbox[5] = MIN(oboxhi[2],hi2[2]); + } - memcpy(sendbox_multi[iswap][i][itype],sbox_multi,6*sizeof(double)); - } - } + for (int itype = 1; itype <= atom->ntypes; itype++) { + sbox_multi[0] = sbox[0]; + sbox_multi[1] = sbox[1]; + sbox_multi[2] = sbox[2]; + sbox_multi[3] = sbox[3]; + sbox_multi[4] = sbox[4]; + sbox_multi[5] = sbox[5]; + if (idir == 0) { + sbox_multi[idim] = sublo[idim]; + if (i < noverlap1) + sbox_multi[3+idim] = + MIN(sbox_multi[3+idim]+cutghostmulti[itype][idim],subhi[idim]); + else + sbox_multi[3+idim] = + MIN(sbox_multi[3+idim]-prd[idim]+cutghostmulti[itype][idim], + subhi[idim]); + } else { + if (i < noverlap1) + sbox_multi[idim] = + MAX(sbox_multi[idim]-cutghostmulti[itype][idim],sublo[idim]); + else + sbox_multi[idim] = + MAX(sbox_multi[idim]+prd[idim]-cutghostmulti[itype][idim], + sublo[idim]); + sbox_multi[3+idim] = subhi[idim]; + } + + if (idim >= 1) { + if (sbox_multi[0] == oboxlo[0]) + sbox_multi[0] -= cutghostmulti[itype][idim]; + if (sbox_multi[3] == oboxhi[0]) + sbox_multi[3] += cutghostmulti[itype][idim]; + } + if (idim == 2) { + if (sbox_multi[1] == oboxlo[1]) + sbox_multi[1] -= cutghostmulti[itype][idim]; + if (sbox_multi[4] == oboxhi[1]) + sbox_multi[4] += cutghostmulti[itype][idim]; + } + + memcpy(sendbox_multi[iswap][i][itype],sbox_multi,6*sizeof(double)); + } + } } - + iswap++; } } - + // setup exchange communication = subset of forward/reverse comm procs // loop over dimensions // determine which procs I will exchange with in each dimension @@ -801,10 +801,10 @@ void CommTiled::exchange() buf_send[nsend++] = proc; nsend += avec->pack_exchange(i,&buf_send[nsend]); } else { - // DEBUG statment - // error->warning(FLERR,"Losing atom in CommTiled::exchange() send, " - // "likely bad dynamics"); - } + // DEBUG statment + // error->warning(FLERR,"Losing atom in CommTiled::exchange() send, " + // "likely bad dynamics"); + } avec->copy(nlocal-1,i,1); nlocal--; } else i++; @@ -853,10 +853,10 @@ void CommTiled::exchange() if (value >= lo && value < hi) { m += avec->unpack_exchange(&buf_recv[m]); continue; - } else { - // DEBUG statment - // error->warning(FLERR,"Losing atom in CommTiled::exchange() recv"); - } + } else { + // DEBUG statment + // error->warning(FLERR,"Losing atom in CommTiled::exchange() recv"); + } } m += static_cast (buf_recv[m]); } @@ -900,7 +900,7 @@ void CommTiled::borders() // for yz-dim swaps, check owned and ghost atoms // store sent atom indices in sendlist for use in future timesteps // single mode and multi mode - + x = atom->x; if (iswap % 2 == 0) nlast = atom->nlocal + atom->nghost; @@ -909,98 +909,98 @@ void CommTiled::borders() for (m = 0; m < nsendproc[iswap]; m++) { if (mode == Comm::SINGLE) { - bbox = sendbox[iswap][m]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + bbox = sendbox[iswap][m]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - ncount = 0; + ncount = 0; - if (!bordergroup) { - for (i = 0; i < nlast; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + if (!bordergroup) { + for (i = 0; i < nlast; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); sendlist[iswap][m][ncount++] = i; - } - } - } else { - ngroup = atom->nfirst; - for (i = 0; i < ngroup; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - for (i = atom->nlocal; i < nlast; i++) { - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - } + } + } + } else { + ngroup = atom->nfirst; + for (i = 0; i < ngroup; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + for (i = atom->nlocal; i < nlast; i++) { + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + } - sendnum[iswap][m] = ncount; - smaxone = MAX(smaxone,ncount); - ncountall += ncount; + sendnum[iswap][m] = ncount; + smaxone = MAX(smaxone,ncount); + ncountall += ncount; } else { - - int* type=atom->type; - int itype; - ncount = 0; - if (!bordergroup) { - for (i = 0; i < nlast; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + int* type=atom->type; + int itype; + ncount = 0; + + if (!bordergroup) { + for (i = 0; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); sendlist[iswap][m][ncount++] = i; - } - } - } else { - ngroup = atom->nfirst; - for (i = 0; i < ngroup; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - for (i = atom->nlocal; i < nlast; i++) { - itype=type[i]; - bbox = sendbox_multi[iswap][m][itype]; - xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; - xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; - if (x[i][0] >= xlo && x[i][0] < xhi && - x[i][1] >= ylo && x[i][1] < yhi && - x[i][2] >= zlo && x[i][2] < zhi) { - if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); - sendlist[iswap][m][ncount++] = i; - } - } - } - - sendnum[iswap][m] = ncount; - smaxone = MAX(smaxone,ncount); - ncountall += ncount; + } + } + } else { + ngroup = atom->nfirst; + for (i = 0; i < ngroup; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + for (i = atom->nlocal; i < nlast; i++) { + itype=type[i]; + bbox = sendbox_multi[iswap][m][itype]; + xlo = bbox[0]; ylo = bbox[1]; zlo = bbox[2]; + xhi = bbox[3]; yhi = bbox[4]; zhi = bbox[5]; + if (x[i][0] >= xlo && x[i][0] < xhi && + x[i][1] >= ylo && x[i][1] < yhi && + x[i][2] >= zlo && x[i][2] < zhi) { + if (ncount == maxsendlist[iswap][m]) grow_list(iswap,m,ncount); + sendlist[iswap][m][ncount++] = i; + } + } + } + + sendnum[iswap][m] = ncount; + smaxone = MAX(smaxone,ncount); + ncountall += ncount; } } - + smaxall = MAX(smaxall,ncountall); // send sendnum counts to procs who recv from me except self @@ -2176,7 +2176,7 @@ void CommTiled::deallocate_swap(int n) memory->destroy(pbc[i]); memory->destroy(sendbox[i]); memory->destroy(sendbox_multi[i]); - + delete [] maxsendlist[i]; for (int j = 0; j < nprocmax[i]; j++) memory->destroy(sendlist[i][j]); From 851a22802ee2564401d7602e213a8316c9aade5e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 16:16:56 -0400 Subject: [PATCH 043/122] add tests for pair style colloid in variants in several neighbor list and comm variants this does 3 tests: - regular neighborlist binning with single cutoff communication - comm style brick with multi-cutoff neighborlists and communication - comm style tiled with multi-cutoff neighborlists and communication --- .../tests/atomic-pair-colloid.yaml | 85 +++++++++++++++++++ .../tests/atomic-pair-colloid_multi.yaml | 85 +++++++++++++++++++ .../tests/atomic-pair-colloid_tiled.yaml | 85 +++++++++++++++++++ unittest/force-styles/tests/data.colloid | 73 ++++++++++++++++ unittest/force-styles/tests/in.colloid | 16 ++++ 5 files changed, 344 insertions(+) create mode 100644 unittest/force-styles/tests/atomic-pair-colloid.yaml create mode 100644 unittest/force-styles/tests/atomic-pair-colloid_multi.yaml create mode 100644 unittest/force-styles/tests/atomic-pair-colloid_tiled.yaml create mode 100644 unittest/force-styles/tests/data.colloid create mode 100644 unittest/force-styles/tests/in.colloid diff --git a/unittest/force-styles/tests/atomic-pair-colloid.yaml b/unittest/force-styles/tests/atomic-pair-colloid.yaml new file mode 100644 index 0000000000..35e44cc54c --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-colloid.yaml @@ -0,0 +1,85 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 16:06:24 202 +epsilon: 5e-14 +prerequisites: ! | + pair colloid +pre_commands: ! | + variable units index lj +post_commands: ! | + neighbor 1.0 bin + comm_style brick + comm_modify mode single +input_file: in.colloid +pair_style: colloid 12.5 +pair_coeff: ! | + 1 1 1.0 1.0 5.0 5.0 12.5 + 1 2 5.0 1.0 5.0 0.0 7.0 + 2 2 10.0 1.0 0.0 0.0 2.5 +extract: ! "" +natoms: 27 +init_vdwl: -0.250265293649414 +init_coul: 0 +init_stress: ! |2- + 1.6693554149342897e+00 1.1752557173260264e+01 1.0084916384631697e+00 -5.5164068587184527e+00 3.4448938909043297e-01 2.8524984331506240e+00 +init_forces: ! |2 + 1 7.2698902368314028e-02 7.6228314794484830e-02 1.0726717051410481e-01 + 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 + 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 + 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 + 5 -3.6475105049685382e-02 -2.2992583864092243e-02 1.6166097759476125e-02 + 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 + 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 + 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 + 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 + 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 + 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 + 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815390e+00 + 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 + 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.2501672350519291e-02 6.8582908647593869e-03 -6.8677246013076093e-02 + 22 -2.2945818607502835e+00 1.1603382884260454e+00 -2.3594708301087310e+00 + 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 + 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 25 6.1663239781204479e-04 -2.9236784591333024e-04 3.5387752678593650e-03 + 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045051e+00 + 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 +run_vdwl: 0.0367090517931739 +run_coul: 0 +run_stress: ! |2- + 3.2547164843322682e+00 1.2822272288053410e+01 2.9381904014809601e+00 -6.5755478139675869e+00 2.3052669923975402e+00 1.5140903126232870e+00 +run_forces: ! |2 + 1 5.8196197291626200e-02 7.7034242946349835e-02 1.0456829776646272e-01 + 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 + 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 + 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 + 5 -3.3316803862839403e-02 -2.1131495092834619e-02 1.4963198384123102e-02 + 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 + 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 + 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 + 9 1.7585178109228492e+00 -4.3823551563819683e+00 -1.2468505588145766e+00 + 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 + 11 7.9839096035526878e-04 6.5881060273477888e-05 1.3840230606223551e-04 + 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 + 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 + 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 + 15 -3.4577717467029730e-03 -9.3350658134032588e-04 -1.5696623820874889e-03 + 16 5.4762334392971725e+00 -3.3427628201841180e+00 5.8008787111000641e+00 + 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 + 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 + 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.1446743356056415e-02 8.4986882092498734e-03 -7.1565549648589480e-02 + 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606380e+00 + 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 + 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 + 25 1.1778375109233723e-03 -7.1254208855309762e-05 3.8035457799329405e-03 + 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 + 27 -1.3345796635606474e-01 3.6623792481486360e-02 -5.6711027332452278e-02 +... diff --git a/unittest/force-styles/tests/atomic-pair-colloid_multi.yaml b/unittest/force-styles/tests/atomic-pair-colloid_multi.yaml new file mode 100644 index 0000000000..3ee28958b1 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-colloid_multi.yaml @@ -0,0 +1,85 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 16:06:24 202 +epsilon: 5e-14 +prerequisites: ! | + pair colloid +pre_commands: ! | + variable units index lj +post_commands: ! | + neighbor 1.0 multi + comm_style brick + comm_modify mode multi +input_file: in.colloid +pair_style: colloid 12.5 +pair_coeff: ! | + 1 1 1.0 1.0 5.0 5.0 12.5 + 1 2 5.0 1.0 5.0 0.0 7.0 + 2 2 10.0 1.0 0.0 0.0 2.5 +extract: ! "" +natoms: 27 +init_vdwl: -0.250265293649414 +init_coul: 0 +init_stress: ! |2- + 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 +init_forces: ! |2 + 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 + 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 + 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 + 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 + 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 + 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 + 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 + 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 + 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 + 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 + 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 + 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 + 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 + 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 + 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 + 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 + 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 +run_vdwl: 0.0367090517931737 +run_coul: 0 +run_stress: ! |2- + 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 +run_forces: ! |2 + 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 + 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 + 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 + 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 + 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 + 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 + 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 + 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 + 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 + 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 + 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 + 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 + 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 + 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 + 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 + 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 + 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 + 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 + 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 + 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 + 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 + 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 + 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 + 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 + 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 +... diff --git a/unittest/force-styles/tests/atomic-pair-colloid_tiled.yaml b/unittest/force-styles/tests/atomic-pair-colloid_tiled.yaml new file mode 100644 index 0000000000..5d2e3147de --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-colloid_tiled.yaml @@ -0,0 +1,85 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 16:06:24 202 +epsilon: 5e-14 +prerequisites: ! | + pair colloid +pre_commands: ! | + variable units index lj +post_commands: ! | + neighbor 1.0 multi + comm_style tiled + comm_modify mode multi +input_file: in.colloid +pair_style: colloid 12.5 +pair_coeff: ! | + 1 1 1.0 1.0 5.0 5.0 12.5 + 1 2 5.0 1.0 5.0 0.0 7.0 + 2 2 10.0 1.0 0.0 0.0 2.5 +extract: ! "" +natoms: 27 +init_vdwl: -0.250265293649414 +init_coul: 0 +init_stress: ! |2- + 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 +init_forces: ! |2 + 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 + 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 + 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 + 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 + 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 + 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 + 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 + 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 + 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 + 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 + 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 + 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 + 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 + 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 + 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 + 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 + 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 +run_vdwl: 0.0367090517931737 +run_coul: 0 +run_stress: ! |2- + 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 +run_forces: ! |2 + 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 + 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 + 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 + 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 + 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 + 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 + 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 + 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 + 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 + 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 + 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 + 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 + 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 + 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 + 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 + 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 + 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 + 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 + 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 + 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 + 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 + 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 + 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 + 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 + 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 +... diff --git a/unittest/force-styles/tests/data.colloid b/unittest/force-styles/tests/data.colloid new file mode 100644 index 0000000000..e5c87eee84 --- /dev/null +++ b/unittest/force-styles/tests/data.colloid @@ -0,0 +1,73 @@ +LAMMPS data file via write_data, version 21 Jul 2020, timestep = 5000 + +27 atoms +2 atom types + +-0.2436910920596036 13.743691092059596 xlo xhi +-0.2436910920596036 13.743691092059596 ylo yhi +-0.2436910920596036 13.743691092059596 zlo zhi + +Masses + +1 9 +2 1 + +Atoms # atomic + +21 1 8.218284363111994 3.8616496369708644 3.926644621675435 0 0 1 +14 2 3.971804908882051 12.196374430867266 11.800922980362827 1 -1 2 +4 2 12.749633950530594 0.2895775102974337 13.665118030342807 1 0 -4 +6 2 10.48479135210438 0.7314009568199128 0.20579559916130968 0 0 -1 +11 2 6.370393143436297 0.7506711988180665 11.228922122628624 -1 1 0 +16 2 1.781613249220567 9.315352564201742 13.003045928765761 1 -1 -1 +15 2 2.5907208520939946 7.092392808241224 9.564419981414446 -2 0 -1 +10 2 2.06473035593474 10.936583460926354 0.2143993310674837 1 -2 2 +17 2 10.89572436719935 1.4615862891785334 5.9966656418333475 -3 -2 0 +12 2 8.989180695332816 13.155343018320753 7.380136516456334 3 -2 -1 +23 2 9.679726091492721 5.587125576488552 0.5505405659916122 0 1 -1 +26 2 10.150200745369286 13.451068779020826 13.1305422632724 0 0 -2 +27 2 0.5854518735680864 3.3706426419449973 13.20338885987352 3 3 -4 +2 2 12.401535589626157 4.499183730038622 8.453939258351905 0 -2 0 +9 1 11.284839488845652 10.602811415241838 12.294336783300636 0 0 -1 +7 2 3.67365214779975 0.6031426192504774 3.744838163244472 -1 0 -3 +25 2 0.580286149741973 6.5570299426679615 8.204514419385035 2 -1 1 +5 2 0.4370415403230168 12.62671878288036 10.900794906743482 -3 1 -2 +20 2 0.5960686789505689 -0.03029382390167784 6.650651587937794 1 -1 -2 +3 2 2.4025882097830804 3.537273393359948 6.539574857512142 -1 1 -1 +8 2 0.2515454304433808 3.209093417679412 6.394794043739663 1 1 0 +24 2 0.8855320855058237 10.07143392738017 2.6866421503905222 0 0 0 +22 2 1.1569993715184617 9.633923152653242 12.34752906065215 -2 0 2 +1 1 11.516625939770336 4.289372112043943 11.847412277845446 -1 -1 -1 +13 2 3.4573289217000625 10.709357504995712 0.2070680620433607 -3 1 2 +18 2 8.388010639142333 4.8343459387085295 0.022914514686456666 0 2 2 +19 2 0.8904095150489832 6.178968410953466 12.739150191807628 -2 -2 1 + +Velocities + +21 0.5108629151801364 0.5071783225038178 0.038121513505701005 +14 0.04442371287433498 -0.9592694013198345 1.2892900869531516 +4 -0.2178346847645286 0.6098857389317441 -0.11034167964068448 +6 -0.1576695048262709 -1.2130499080058224 -1.532174167207837 +11 2.8099374837612547 -0.04484558137222933 -2.949735057364872 +16 -2.514269472184712 0.8600214136555172 -1.334072825855178 +15 -1.9716757999689132 0.34144027670649985 -1.289546613298351 +10 1.593221282752536 -1.4854596141900234 -0.5931052285995597 +17 0.30576221579017154 -1.7264461829362503 0.9151292837107401 +12 1.856996336103833 1.2171769820936116 0.7446116107611583 +23 0.6826664104612703 -1.2226601048696837 -0.575337461330738 +26 2.060350188652742 1.4611540801166607 -1.2802524060106233 +27 0.249900902388907 2.388571043902052 -1.8492601452320174 +2 0.2605802271656383 0.7180097106986123 0.23261242169201765 +9 -0.34764522027409256 0.3030477382656852 -0.27629534212658624 +7 -2.269133408440061 -3.1960327319813473 -0.148176086091223 +25 1.1175412259994884 -0.5507974421930979 1.1903914944413345 +5 0.20657924357863497 1.6144987892387104 -1.4640329026812684 +20 0.0590579871685183 -0.24749314593051103 -1.104019292812069 +3 -0.5186327771760407 0.5748836420503801 -1.1735732476681855 +8 -0.4437666044968981 1.7357347488421837 1.9514880021657892 +24 -0.28726920313585036 -0.13725286038541634 2.2362521378373943 +22 0.07031578857583798 2.4612824702440497 1.159670483206302 +1 -0.6115443594925424 -1.3770574953178165 0.6488398210995187 +13 -1.7087317711505776 1.2667666619290276 0.6879911689583401 +18 1.023336469072999 1.4409480361581861 0.7015199009707059 +19 1.783253733076145 -0.8055837104480024 0.5986765907881554 diff --git a/unittest/force-styles/tests/in.colloid b/unittest/force-styles/tests/in.colloid new file mode 100644 index 0000000000..69e62e6616 --- /dev/null +++ b/unittest/force-styles/tests/in.colloid @@ -0,0 +1,16 @@ +variable newton_pair index on +variable newton_bond index on +variable units index lj +variable input_dir index . +variable data_file index ${input_dir}/data.colloid +variable pair_style index 'zero 8.0' + +atom_style atomic +atom_modify map array +neigh_modify delay 2 every 2 check no +timestep 0.01 +units ${units} +newton ${newton_pair} ${newton_bond} + +pair_style ${pair_style} +read_data ${data_file} From 33aa96b1bf10536907a32df204236e64d7e0033b Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 20:07:24 -0400 Subject: [PATCH 044/122] test for buck/mdf, fixed bug in broadcasting inner cutoff, typos in doc --- doc/src/pair_buck.rst | 2 +- doc/src/pair_mdf.rst | 2 +- src/USER-MISC/pair_buck_mdf.cpp | 6 ++ .../force-styles/tests/mol-pair-buck_mdf.yaml | 100 ++++++++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 unittest/force-styles/tests/mol-pair-buck_mdf.yaml diff --git a/doc/src/pair_buck.rst b/doc/src/pair_buck.rst index 8725a9e1ee..401cd58bd9 100644 --- a/doc/src/pair_buck.rst +++ b/doc/src/pair_buck.rst @@ -151,7 +151,7 @@ commands: * cutoff2 (distance units) The second coefficient, :math:`\rho`, must be greater than zero. -The coefficients A,:math:`\rho`, and C can be written as analytical expressions +The coefficients A, :math:`\rho`, and C can be written as analytical expressions of :math:`\epsilon` and :math:`\sigma`, in analogy to the Lennard-Jones potential :ref:`(Khrapak) `. diff --git a/doc/src/pair_mdf.rst b/doc/src/pair_mdf.rst index 9cb9eaa6b2..8636802af3 100644 --- a/doc/src/pair_mdf.rst +++ b/doc/src/pair_mdf.rst @@ -40,7 +40,7 @@ Examples pair_coeff * * 1.0 1.0 pair_coeff 1 1 1.1 2.8 3.0 3.2 - pair_style buck 2.5 3.0 + pair_style buck/mdf 2.5 3.0 pair_coeff * * 100.0 1.5 200.0 pair_coeff * * 100.0 1.5 200.0 3.0 3.5 diff --git a/src/USER-MISC/pair_buck_mdf.cpp b/src/USER-MISC/pair_buck_mdf.cpp index 6339f7d135..1937aeedf7 100644 --- a/src/USER-MISC/pair_buck_mdf.cpp +++ b/src/USER-MISC/pair_buck_mdf.cpp @@ -285,6 +285,7 @@ void PairBuckMDF::write_restart(FILE *fp) fwrite(&rho[i][j],sizeof(double),1,fp); fwrite(&c[i][j],sizeof(double),1,fp); fwrite(&cut[i][j],sizeof(double),1,fp); + fwrite(&cut_inner[i][j],sizeof(double),1,fp); } } } @@ -311,11 +312,13 @@ void PairBuckMDF::read_restart(FILE *fp) utils::sfread(FLERR,&rho[i][j],sizeof(double),1,fp,NULL,error); utils::sfread(FLERR,&c[i][j],sizeof(double),1,fp,NULL,error); utils::sfread(FLERR,&cut[i][j],sizeof(double),1,fp,NULL,error); + utils::sfread(FLERR,&cut_inner[i][j],sizeof(double),1,fp,NULL,error); } MPI_Bcast(&a[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&rho[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&c[i][j],1,MPI_DOUBLE,0,world); MPI_Bcast(&cut[i][j],1,MPI_DOUBLE,0,world); + MPI_Bcast(&cut_inner[i][j],1,MPI_DOUBLE,0,world); } } } @@ -327,6 +330,7 @@ void PairBuckMDF::read_restart(FILE *fp) void PairBuckMDF::write_restart_settings(FILE *fp) { fwrite(&cut_global,sizeof(double),1,fp); + fwrite(&cut_inner_global,sizeof(double),1,fp); fwrite(&offset_flag,sizeof(int),1,fp); fwrite(&mix_flag,sizeof(int),1,fp); fwrite(&tail_flag,sizeof(int),1,fp); @@ -340,11 +344,13 @@ void PairBuckMDF::read_restart_settings(FILE *fp) { if (comm->me == 0) { utils::sfread(FLERR,&cut_global,sizeof(double),1,fp,NULL,error); + utils::sfread(FLERR,&cut_inner_global,sizeof(double),1,fp,NULL,error); utils::sfread(FLERR,&offset_flag,sizeof(int),1,fp,NULL,error); utils::sfread(FLERR,&mix_flag,sizeof(int),1,fp,NULL,error); utils::sfread(FLERR,&tail_flag,sizeof(int),1,fp,NULL,error); } MPI_Bcast(&cut_global,1,MPI_DOUBLE,0,world); + MPI_Bcast(&cut_inner_global,1,MPI_DOUBLE,0,world); MPI_Bcast(&offset_flag,1,MPI_INT,0,world); MPI_Bcast(&mix_flag,1,MPI_INT,0,world); MPI_Bcast(&tail_flag,1,MPI_INT,0,world); diff --git a/unittest/force-styles/tests/mol-pair-buck_mdf.yaml b/unittest/force-styles/tests/mol-pair-buck_mdf.yaml new file mode 100644 index 0000000000..0674c1f56b --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-buck_mdf.yaml @@ -0,0 +1,100 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 20:03:37 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair buck/mdf +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: buck/mdf 6.5 8.0 +pair_coeff: ! | + 1 1 170339.505032359 0.166879344173798 13.642356513989 + 1 2 85988.1490021027 0.116722557424471 0.80085535265993 + 1 3 169866.420176425 0.190286500706475 29.9623467274028 + 1 4 147160.913151695 0.186942613268455 23.3320434749744 + 1 5 147160.913151695 0.186942613268455 23.3320434749744 + 2 2 43972.4676803832 0.0665738276248451 0.0138732735747516 + 2 3 85535.686235147 0.140128612516736 2.39406114840173 + 2 4 45975.8370021332 0.0331639834863857 0.000214673167591639 + 2 5 74124.142292174 0.136784828511181 1.79395952625758 + 3 3 169504.649065961 0.213692863412526 60.0617510100503 + 3 4 146835.114678908 0.210349185259049 47.3225728524629 + 3 5 146835.114678908 0.210349185259049 47.3225728524629 + 4 4 127198.698386798 0.207005479340455 37.2289658745028 + 4 5 127198.698386798 0.207005479340455 37.2289658745028 + 5 5 127198.698386798 0.207005479340455 37.2289658745028 +extract: ! | + a 2 + c 2 +natoms: 29 +init_vdwl: 143.750172479889 +init_coul: 0 +init_stress: ! |2- + 2.8545976884034133e+02 2.8737056463500437e+02 4.6112835758703841e+02 -5.4336275648975430e+01 3.0319466756231911e+01 4.6620664187526550e+01 +init_forces: ! |2 + 1 -4.1623775151169555e+00 3.8386433272823908e+01 4.8752021330530219e+01 + 2 2.3627361587143497e+01 1.9437613546652713e+01 -2.7808992069327079e+01 + 3 -1.9523183463523988e+01 -5.0755464292132672e+01 -2.0167041215602033e+01 + 4 -4.2090797368144548e+00 1.1066584315991297e+00 -2.9972388697672767e+00 + 5 -1.3267826706072230e+00 -2.2204322651025663e+00 6.0778809239934031e+00 + 6 -7.1123087387748683e+01 7.7052619768181358e+01 6.6070798021478453e+01 + 7 1.0818938743625450e-01 -2.1456243768010403e+01 -1.2988779129476640e+02 + 8 2.7685557706153210e+00 -6.4055292922227114e+00 3.5054112799000308e+01 + 9 1.0385287961110039e+01 1.1200082491913735e+01 4.5981266170177641e+01 + 10 4.8483647065769190e+01 -6.2863074345822859e+01 -1.7919412685351613e+01 + 11 -1.1854581336088006e+00 -3.0186793607682243e+00 -4.9190264271625024e+00 + 12 8.7531866758949892e+00 4.0319784496217750e+00 -3.6939594183275126e+00 + 13 4.4340053941471904e+00 -1.7594770981988275e+00 -8.0345378469635742e-02 + 14 -1.8210424913812684e+00 3.6741934665079351e-01 -4.6918123727015333e+00 + 15 -1.0513516741244620e-01 4.6130035923795170e+00 1.6347265243446252e+00 + 16 4.1042300521196935e+01 -3.2293527205761428e+01 -9.0261475177059907e+01 + 17 -3.6114860006015803e+01 2.4604268415609937e+01 9.8841340163463499e+01 + 18 -1.8825765982480234e-02 -3.1986826093735314e-02 2.8598555002578602e-02 + 19 2.6246126725284639e-04 -1.3985991770179971e-04 1.2500135502022498e-03 + 20 -7.4158628864573635e-04 -7.5372669545694228e-04 2.6948946623672683e-04 + 21 -1.0785489161434048e+01 -1.2742891547555134e+01 3.6432159976717223e+01 + 22 -1.7555580076314030e+01 -4.2541303797868011e+00 -2.7543135747499065e+01 + 23 2.8333539309671401e+01 1.7005761819019146e+01 -8.8808401648973057e+00 + 24 6.9230215474812358e+00 -3.3463347678609331e+01 1.8600721086131170e+01 + 25 -2.4509700105485905e+01 3.9444178844087432e+00 -2.0606959962131530e+01 + 26 1.7575837949428792e+01 2.9510208924646768e+01 1.9863422163776494e+00 + 27 6.6487363315433221e+00 -3.6337564791281956e+01 1.3616115657254987e+01 + 28 -2.7672094503404313e+01 1.1892775106158119e+01 -1.8723460085236635e+01 + 29 2.1029505808433630e+01 2.4450001388294194e+01 5.1038879408118385e+00 +run_vdwl: 120.390339444037 +run_coul: 0 +run_stress: ! |2- + 2.5557076115460899e+02 2.5949083036036279e+02 3.7924820713448941e+02 -5.4331912086309863e+01 2.7329510888117166e+01 4.1741880429358943e+01 +run_forces: ! |2 + 1 -9.5106296778717858e-01 3.5350903139580076e+01 3.9457788501955015e+01 + 2 1.8087885768281200e+01 1.4881431751248465e+01 -2.0866803303326282e+01 + 3 -1.9025510717853550e+01 -4.1963958840837172e+01 -1.6664478809553827e+01 + 4 -3.9859941166892718e+00 1.0788502407049387e+00 -2.9029954145128887e+00 + 5 -1.2023709090005723e+00 -2.0086881004005659e+00 5.6818744816238880e+00 + 6 -6.0409708693069774e+01 6.4308051724265454e+01 4.2296795072550239e+01 + 7 9.3619774012754076e-01 -1.7314182498123468e+01 -9.7141371175003627e+01 + 8 8.4374815617239507e-01 -3.2803127898386091e+00 3.3704959962345320e+01 + 9 8.3054223919475838e+00 8.6081913218743473e+00 3.6111642806027483e+01 + 10 4.2561464320368003e+01 -5.5914107881428244e+01 -1.7451016581627673e+01 + 11 -1.1800067991818264e+00 -2.7475271110814830e+00 -4.5818283809538558e+00 + 12 8.4354686158616836e+00 3.9901659185061922e+00 -4.1473570573211056e+00 + 13 4.1920571556670385e+00 -1.5869395008460414e+00 -6.2699936272915119e-02 + 14 -1.6199433911252872e+00 2.6217248188321979e-01 -4.1331654538138283e+00 + 15 -2.0331708492334666e-01 4.5411734718704624e+00 1.7063124925553061e+00 + 16 3.3204345703794395e+01 -2.7557620088049639e+01 -6.8101198549810292e+01 + 17 -2.7956867632127889e+01 1.9379723739082340e+01 7.7078799406759330e+01 + 18 -1.8736484154392354e-02 -3.1832301275527011e-02 2.8465565812628272e-02 + 19 1.9235280815687152e-04 -1.9937323111483010e-04 1.2555083173809050e-03 + 20 -6.5720491792300236e-04 -6.8003272156836258e-04 2.7292955437743918e-04 + 21 -9.1337929183030120e+00 -9.9740199991125511e+00 2.9985651190373691e+01 + 22 -1.4775515115956688e+01 -3.7890888804029199e+00 -2.2670105420722507e+01 + 23 2.3901606557704575e+01 1.3772050192861254e+01 -7.3071673474361880e+00 + 24 7.5921777719466190e+00 -2.9274214151414398e+01 1.7211122387283904e+01 + 25 -2.2853224935112188e+01 3.3601440486173679e+00 -1.9347511864642978e+01 + 26 1.5250008770356276e+01 2.5905305780853841e+01 2.1161920651718211e+00 + 27 5.7138512823990517e+00 -3.0278816202265425e+01 1.0694975152036214e+01 + 28 -2.2862795498173114e+01 9.8830391808041718e+00 -1.5214428418290540e+01 + 29 1.7155077880941484e+01 2.0400984758876589e+01 4.5160201909218829e+00 +... From 0db1c66b039c728b3d788880f81e800035d44fae Mon Sep 17 00:00:00 2001 From: Adrian-Diaz Date: Mon, 3 Aug 2020 20:16:20 -0400 Subject: [PATCH 045/122] triclinic compatibility --- src/comm_tiled.cpp | 40 ++++++--- .../atomic-pair-colloid_multi_triclinic.yaml | 86 +++++++++++++++++++ 2 files changed, 115 insertions(+), 11 deletions(-) create mode 100644 unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 03cb56921a..893d0f23d8 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -113,11 +113,6 @@ void CommTiled::init() int bufextra_old = bufextra; init_exchange(); if (bufextra > bufextra_old) grow_send(maxsend+bufextra,2); - - // temporary restrictions - - if (triclinic) - error->all(FLERR,"Cannot yet use comm_style tiled with triclinic box"); } /* ---------------------------------------------------------------------- @@ -132,15 +127,23 @@ void CommTiled::setup() // domain properties used in setup method and methods it calls dimension = domain->dimension; - prd = domain->prd; - boxlo = domain->boxlo; - boxhi = domain->boxhi; - sublo = domain->sublo; - subhi = domain->subhi; - int *periodicity = domain->periodicity; int ntypes = atom->ntypes; + if (triclinic == 0) { + prd = domain->prd; + boxlo = domain->boxlo; + boxhi = domain->boxhi; + sublo = domain->sublo; + subhi = domain->subhi; + } else { + prd = domain->prd_lamda; + boxlo = domain->boxlo_lamda; + boxhi = domain->boxhi_lamda; + sublo = domain->sublo_lamda; + subhi = domain->subhi_lamda; + } + // set function pointers if (layout != Comm::LAYOUT_TILED) { @@ -189,6 +192,13 @@ void CommTiled::setup() cutghost[1] = cut * length1; length2 = h_inv[2]; cutghost[2] = cut * length2; + if (mode == Comm::MULTI){ + for (i = 1; i <= ntypes; i++) { + cutghostmulti[i][0] *= length0; + cutghostmulti[i][1] *= length1; + cutghostmulti[i][2] *= length2; + } + } } if ((periodicity[0] && cutghost[0] > prd[0]) || @@ -347,6 +357,10 @@ void CommTiled::setup() pbc_flag[iswap][i] = 1; if (idir == 0) pbc[iswap][i][idim] = 1; else pbc[iswap][i][idim] = -1; + if (triclinic) { + if (idim == 1) pbc[iswap][i][5] = pbc[iswap][i][idim]; + if (idim == 2) pbc[iswap][i][4] = pbc[iswap][i][3] = pbc[iswap][i][idim]; + } sbox[0] = MAX(oboxlo[0],lo2[0]); sbox[1] = MAX(oboxlo[1],lo2[1]); sbox[2] = MAX(oboxlo[2],lo2[2]); @@ -397,6 +411,10 @@ void CommTiled::setup() pbc_flag[iswap][i] = 1; if (idir == 0) pbc[iswap][i][idim] = 1; else pbc[iswap][i][idim] = -1; + if (triclinic) { + if (idim == 1) pbc[iswap][i][5] = pbc[iswap][i][idim]; + if (idim == 2) pbc[iswap][i][4] = pbc[iswap][i][3] = pbc[iswap][i][idim]; + } sbox[0] = MAX(oboxlo[0],lo2[0]); sbox[1] = MAX(oboxlo[1],lo2[1]); sbox[2] = MAX(oboxlo[2],lo2[2]); diff --git a/unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml b/unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml new file mode 100644 index 0000000000..8d6a237162 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 16:06:24 202 +epsilon: 5e-11 +prerequisites: ! | + pair colloid +pre_commands: ! | + variable units index lj +post_commands: ! | + neighbor 1.0 multi + comm_style brick + comm_modify mode multi + change_box all triclinic +input_file: in.colloid +pair_style: colloid 12.5 +pair_coeff: ! | + 1 1 1.0 1.0 5.0 5.0 12.5 + 1 2 5.0 1.0 5.0 0.0 7.0 + 2 2 10.0 1.0 0.0 0.0 2.5 +extract: ! "" +natoms: 27 +init_vdwl: -0.250265293649414 +init_coul: 0 +init_stress: ! |2- + 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 +init_forces: ! |2 + 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 + 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 + 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 + 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 + 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 + 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 + 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 + 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 + 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 + 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 + 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 + 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 + 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 + 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 + 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 + 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 + 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 +run_vdwl: 0.0367090517931737 +run_coul: 0 +run_stress: ! |2- + 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 +run_forces: ! |2 + 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 + 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 + 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 + 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 + 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 + 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 + 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 + 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 + 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 + 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 + 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 + 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 + 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 + 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 + 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 + 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 + 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 + 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 + 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 + 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 + 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 + 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 + 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 + 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 + 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 +... From de828fceafa7aa23ce9b65e491023c05fe3b708d Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 20:48:11 -0400 Subject: [PATCH 046/122] test for cosine/squared --- .../tests/mol-pair-cosine_squared.yaml | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-cosine_squared.yaml diff --git a/unittest/force-styles/tests/mol-pair-cosine_squared.yaml b/unittest/force-styles/tests/mol-pair-cosine_squared.yaml new file mode 100644 index 0000000000..ca126203bd --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-cosine_squared.yaml @@ -0,0 +1,98 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 20:46:36 202 +epsilon: 5e-14 +prerequisites: ! | + atom full + pair cosine/squared +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +pair_style: cosine/squared 8.0 +pair_coeff: ! | + 1 1 0.02 2.80615512077343 6.25 wca + 1 2 0.01 1.9643085845414 4.375 + 1 3 0.02 3.19901683768171 7.125 wca + 1 4 0.0173205080756888 3.14289373526624 7 wca + 1 5 0.0173205080756888 3.14289373526624 7 wca + 2 2 0.005 1.12246204830937 2.5 wca + 2 3 0.01 2.35717030144968 5.25 wca + 2 4 0.005 0.561231024154687 1.25 wca + 2 5 0.00866025403784439 2.30104719903421 5.125 wca + 3 3 0.02 3.59187855458999 wca + 3 4 0.0173205080756888 3.53575545217453 7.875 wca + 3 5 0.0173205080756888 3.53575545217453 7.875 + 4 4 0.015 3.47963234975906 7.75 wca + 4 5 0.015 3.47963234975906 7.75 wca + 5 5 0.015 3.47963234975906 7.75 wca +extract: ! "" +natoms: 29 +init_vdwl: 743.463090276839 +init_coul: 0 +init_stress: ! |2- + 2.1615191386773317e+03 2.1833503580687548e+03 4.6304037820363574e+03 -7.5575560824755155e+02 1.6895783707398664e+01 6.6358284339784689e+02 +init_forces: ! |2 + 1 -2.3329022081476449e+01 2.6992842685624959e+02 3.3272330534500645e+02 + 2 1.5828736263760558e+02 1.3024841197748106e+02 -1.8629415637216283e+02 + 3 -1.4542889594788969e+02 -3.8847535524587693e+02 -1.3923064678402602e+02 + 4 -6.3904517215596396e-02 -5.2798715649958680e-02 -5.4165273652241559e-02 + 5 -1.7095757265662631e-01 -4.3920987156044811e-01 1.6225984662307766e-01 + 6 -8.3190467433390165e+02 9.6394063779339410e+02 1.1509096361607592e+03 + 7 5.8199535653327224e+01 -3.3609847795404386e+02 -1.7179587637669722e+03 + 8 1.4451245131105273e+02 -1.0927798346835793e+02 3.9991128748155791e+02 + 9 7.9161294099509263e+01 8.5267804683808123e+01 3.5031393741204874e+02 + 10 5.2880587000195203e+02 -6.1626859702258218e+02 -1.9317373233135118e+02 + 11 1.8952689551789748e-02 -3.6450410348181445e-02 -3.3396200051671127e-02 + 12 2.2035159898428315e+01 1.6590483801640513e+01 -1.3818830456546248e+01 + 13 -7.8051328155993444e-03 -2.7011243112010194e-03 -2.9982254825017089e-04 + 14 -5.5569171518692114e-03 -3.1316520318879762e-03 1.0073763915512332e-02 + 15 9.3956142822199072e-03 1.1152407709318191e-02 -4.5084021402007016e-03 + 16 4.6325614229460302e+02 -3.3086684917432308e+02 -1.1893020922871999e+03 + 17 -4.5334256247808645e+02 3.1554466546539931e+02 1.2058468663158430e+03 + 18 -7.5859879013200010e-03 -2.5114623847467463e-02 2.3921871449112828e-02 + 19 -1.1200701803994876e-03 -2.7710305580492499e-03 9.1685676624970961e-03 + 20 -2.5429910657975129e-03 -1.8881653563463095e-03 1.3146114386773950e-03 + 21 -7.1583952136835748e+01 -8.1596430861608582e+01 2.2591118334556461e+02 + 22 -1.0808797226522465e+02 -2.6193860493159715e+01 -1.6957922788467434e+02 + 23 1.7964455476428947e+02 1.0782071800475833e+02 -5.6306135218067304e+01 + 24 3.6589016132940543e+01 -2.1183732293677465e+02 1.1216016732332183e+02 + 25 -1.4851479548373814e+02 2.3905963729458676e+01 -1.2485730213205329e+02 + 26 1.1190938946001918e+02 1.8789684375277903e+02 1.2648102455468822e+01 + 27 5.1824366297393510e+01 -2.2703801913974428e+02 9.0836214781190961e+01 + 28 -1.8041288881401439e+02 7.7534058664543707e+01 -1.2206933806761211e+02 + 29 1.2861074587519965e+02 1.4952779475291308e+02 3.1215155717207590e+01 +run_vdwl: 138.84942616973 +run_coul: 0 +run_stress: ! |2- + 6.0136495846745959e+02 6.4995379171192496e+02 4.4475273022545485e+02 -3.1112386858484194e+02 -3.8009536720666702e+01 1.1540848783367785e+02 +run_forces: ! |2 + 1 1.3042154705346858e+01 8.0539904184860575e+01 6.0051447572075141e+01 + 2 1.8554316294662915e+01 1.4018577318380505e+01 -2.2755279352656078e+01 + 3 -2.5324783988415788e+02 1.0110410533211522e+02 8.7528442607718034e+01 + 4 -3.1809660168349504e-02 -2.9491971926033152e-02 -2.8716284896025381e-02 + 5 -1.3134256417056422e-01 -3.4400226320027077e-01 1.1098031453974591e-01 + 6 1.1180852439110377e+02 -9.3599360558085635e+01 -1.3909061025984050e+02 + 7 3.8005994053101322e+00 -1.0712738979126327e+01 -4.2380800195414281e+01 + 8 -1.8783668075963579e+01 1.8908456129170442e+01 5.5074604837454501e+01 + 9 1.1196856732765058e+01 1.3206239484542412e+01 4.9873499745541842e+01 + 10 5.7965329924045115e+01 -8.3681759892771666e+01 -9.1665713246054210e+01 + 11 1.3671615245526030e-02 -2.5204645899117618e-02 -2.6347907195008107e-02 + 12 1.8108990545723650e+01 1.7512000634737458e+01 -1.2075917323361118e+01 + 13 -5.8213794872194876e-03 -3.2451580623202463e-03 -6.3493288084304797e-04 + 14 -5.7939768065234064e-03 -3.1571165821108705e-03 1.0479945975082779e-02 + 15 1.3062052018860064e-02 1.4052867528740513e-02 -7.1561812543424388e-03 + 16 5.2367855810691822e+01 -6.6912813000960085e+01 1.4594377909777540e+01 + 17 -1.4633796486592749e+01 1.0018854994891072e+01 4.0794380526150178e+01 + 18 -7.7947805595989725e-03 -2.5197372022914562e-02 2.4146653203441139e-02 + 19 -9.1635211634190947e-04 -2.3212580299985489e-03 8.8815289457890041e-03 + 20 -2.3872690758600574e-03 -1.8164416505834064e-03 1.1047554549732644e-03 + 21 -9.9508590154574730e+00 -1.2000590725923971e+01 3.8883052797020682e+01 + 22 -1.8316449775420068e+01 -4.4398813533025958e+00 -2.9440297227159924e+01 + 23 2.8241464838542413e+01 1.6469765778370956e+01 -9.4184978256053515e+00 + 24 1.2412523684255213e+01 -3.6443308440388385e+01 2.3773749179572128e+01 + 25 -3.0030497348451107e+01 5.3791965267018789e+00 -2.5777972255019399e+01 + 26 1.7601898030125380e+01 3.1030277597742348e+01 1.9565163453989600e+00 + 27 3.4853021063422780e+00 -3.8980356049683181e+01 1.1690463271668129e+01 + 28 -2.5472026590932217e+01 1.1754820471432726e+01 -1.7174321002767144e+01 + 29 2.2008453023180525e+01 2.7248993907140910e+01 5.4661360036080850e+00 +... From a921c44a4f650021bf57656497d3b581642a8ff5 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 20:48:37 -0400 Subject: [PATCH 047/122] fix bug in writing data --- src/USER-MISC/pair_cosine_squared.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/USER-MISC/pair_cosine_squared.cpp b/src/USER-MISC/pair_cosine_squared.cpp index 7f3f6259d4..b9a1817737 100644 --- a/src/USER-MISC/pair_cosine_squared.cpp +++ b/src/USER-MISC/pair_cosine_squared.cpp @@ -323,8 +323,11 @@ void PairCosineSquared::read_restart_settings(FILE *fp) void PairCosineSquared::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) - fprintf(fp, "%d %g %g %g %d\n", i, epsilon[i][i], sigma[i][i], - cut[i][i], wcaflag[i][i]); + { + fprintf(fp, "%d %g %g %g", i, epsilon[i][i], sigma[i][i], cut[i][i]); + if (wcaflag[i][i]) fprintf(fp, " wca"); + fprintf(fp, "\n"); + } } /* ---------------------------------------------------------------------- @@ -335,8 +338,11 @@ void PairCosineSquared::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) - fprintf(fp, "%d %d %g %g %g %d\n", i, j, epsilon[i][j], sigma[i][j], - cut[i][j], wcaflag[i][j]); + { + fprintf(fp, "%d %d %g %g %g", i, j, epsilon[i][j], sigma[i][j], cut[i][j]); + if (wcaflag[i][j]) fprintf(fp, " wca"); + fprintf(fp, "\n"); + } } /* ---------------------------------------------------------------------- */ From 6bc65dc14c55f02d43fc8ba54a9a3d2285606617 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Mon, 3 Aug 2020 20:49:02 -0400 Subject: [PATCH 048/122] reference typos in doc --- doc/src/pair_cosine_squared.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/pair_cosine_squared.rst b/doc/src/pair_cosine_squared.rst index a8cf206135..42e48a6641 100644 --- a/doc/src/pair_cosine_squared.rst +++ b/doc/src/pair_cosine_squared.rst @@ -54,7 +54,7 @@ between two point particles, where (:math:`\sigma, -\epsilon`) is the location of the (rightmost) minimum of the potential, as explained in the syntax section above. -This potential was first used in (Cooke)_#CKD for a coarse-grained lipid +This potential was first used in :ref:`(Cooke) ` for a coarse-grained lipid membrane model. It is generally very useful as a non-specific interaction potential because it is fully adjustable in depth and width while joining the minimum at (sigma, -epsilon) and zero at (cutoff, 0) @@ -63,7 +63,7 @@ energy calculations etc. This evidently requires *cutoff* to be larger than *sigma*\ . If the *wca* option is used then a Weeks-Chandler-Andersen potential -(Weeks)_#WCA is added to the above specified cosine-squared potential, +:ref:`(Weeks) ` is added to the above specified cosine-squared potential, specifically the following: .. math:: From d89a047461a6624d868f77b9d53444915870ab65 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 22:08:06 -0400 Subject: [PATCH 049/122] Simplify write data code --- src/USER-MISC/pair_cosine_squared.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/USER-MISC/pair_cosine_squared.cpp b/src/USER-MISC/pair_cosine_squared.cpp index b9a1817737..ff0d763b2d 100644 --- a/src/USER-MISC/pair_cosine_squared.cpp +++ b/src/USER-MISC/pair_cosine_squared.cpp @@ -323,11 +323,8 @@ void PairCosineSquared::read_restart_settings(FILE *fp) void PairCosineSquared::write_data(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) - { - fprintf(fp, "%d %g %g %g", i, epsilon[i][i], sigma[i][i], cut[i][i]); - if (wcaflag[i][i]) fprintf(fp, " wca"); - fprintf(fp, "\n"); - } + fprintf(fp, "%d %g %g %g %s\n", i, epsilon[i][i], sigma[i][i], cut[i][i], + (wcaflag[i][i] ? "wca" : "")); } /* ---------------------------------------------------------------------- @@ -338,11 +335,8 @@ void PairCosineSquared::write_data_all(FILE *fp) { for (int i = 1; i <= atom->ntypes; i++) for (int j = i; j <= atom->ntypes; j++) - { - fprintf(fp, "%d %d %g %g %g", i, j, epsilon[i][j], sigma[i][j], cut[i][j]); - if (wcaflag[i][j]) fprintf(fp, " wca"); - fprintf(fp, "\n"); - } + fprintf(fp, "%d %d %g %g %g %s\n", i, j, epsilon[i][j], sigma[i][j], + cut[i][j], (wcaflag[i][j] ? "wca" : "")); } /* ---------------------------------------------------------------------- */ From ea900b3482602fab893675d4f8f0d16e9b0a987e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 22:17:04 -0400 Subject: [PATCH 050/122] add test input template for tiled with triclinic and multi-cutoff --- ...aml => atomic-pair-colloid_multi_tri.yaml} | 0 .../tests/atomic-pair-colloid_tiled_tri.yaml | 86 +++++++++++++++++++ 2 files changed, 86 insertions(+) rename unittest/force-styles/tests/{atomic-pair-colloid_multi_triclinic.yaml => atomic-pair-colloid_multi_tri.yaml} (100%) create mode 100644 unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml diff --git a/unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml b/unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml similarity index 100% rename from unittest/force-styles/tests/atomic-pair-colloid_multi_triclinic.yaml rename to unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml diff --git a/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml b/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml new file mode 100644 index 0000000000..d49b93ac0d --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 16:06:24 202 +epsilon: 5e-14 +prerequisites: ! | + pair colloid +pre_commands: ! | + variable units index lj +post_commands: ! | + neighbor 1.0 multi + comm_style tiled + comm_modify mode multi + change_box all triclinic +input_file: in.colloid +pair_style: colloid 12.5 +pair_coeff: ! | + 1 1 1.0 1.0 5.0 5.0 12.5 + 1 2 5.0 1.0 5.0 0.0 7.0 + 2 2 10.0 1.0 0.0 0.0 2.5 +extract: ! "" +natoms: 27 +init_vdwl: -0.250265293649414 +init_coul: 0 +init_stress: ! |2- + 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 +init_forces: ! |2 + 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 + 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 + 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 + 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 + 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 + 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 + 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 + 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 + 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 + 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 + 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 + 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 + 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 + 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 + 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 + 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 + 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 +run_vdwl: 0.0367090517931737 +run_coul: 0 +run_stress: ! |2- + 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 +run_forces: ! |2 + 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 + 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 + 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 + 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 + 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 + 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 + 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 + 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 + 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 + 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 + 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 + 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 + 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 + 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 + 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 + 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 + 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 + 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 + 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 + 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 + 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 + 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 + 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 + 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 + 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 +... From 89d85436f10ad40ee24d5d7f28d08389a55efb08 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 22:42:18 -0400 Subject: [PATCH 051/122] update reference data for triclinic case --- .../tests/atomic-pair-colloid_multi_tri.yaml | 90 +++++++++---------- .../tests/atomic-pair-colloid_tiled_tri.yaml | 90 +++++++++---------- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml b/unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml index 8d6a237162..0ef29011c8 100644 --- a/unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml +++ b/unittest/force-styles/tests/atomic-pair-colloid_multi_tri.yaml @@ -1,7 +1,7 @@ --- lammps_version: 21 Jul 2020 -date_generated: Mon Aug 3 16:06:24 202 -epsilon: 5e-11 +date_generated: Mon Aug 3 22:40:52 202 +epsilon: 5e-13 prerequisites: ! | pair colloid pre_commands: ! | @@ -22,65 +22,65 @@ natoms: 27 init_vdwl: -0.250265293649414 init_coul: 0 init_stress: ! |2- - 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 + 1.6693554149342911e+00 1.1752557173260259e+01 1.0084916384631786e+00 -5.5164068587184580e+00 3.4448938909043375e-01 2.8524984331506325e+00 init_forces: ! |2 - 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 1 7.2698902368313792e-02 7.6228314794484928e-02 1.0726717051410495e-01 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 - 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 6 5.4769180740244731e-04 -2.4426732691233955e-02 -3.6444902428179146e-02 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 - 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 - 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 - 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 - 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 8 6.2576206692511894e-03 1.1942031910109575e-03 8.5598267089392129e-04 + 9 1.8304752931477772e+00 -4.3380838069003751e+00 -1.2763141904695217e+00 + 10 1.0456768773213966e-01 -2.8797785965171449e-02 -1.0768387599117872e-02 + 11 7.4457152913473068e-04 5.3043528596594895e-05 1.1848179655097051e-04 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 - 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 - 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 13 -1.1259391902077470e-01 1.6396787556459836e-02 -9.0455786475091167e-04 + 14 -2.4411189619188755e-04 -5.8284002050384791e-05 1.8046434825690706e-05 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 - 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815390e+00 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 - 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 18 1.0304762560041145e-01 7.8062023784307155e-03 1.9257495383127543e-02 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 - 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 - 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 - 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 21 4.2501672350519284e-02 6.8582908647593982e-03 -6.8677246013076107e-02 + 22 -2.2945818607502835e+00 1.1603382884260451e+00 -2.3594708301087310e+00 + 23 2.5606115583434334e-02 -1.0270997331622238e-01 -1.1451933998746676e-01 + 24 -8.0648597970214874e-04 1.1943689027481719e-04 -9.8441554909815452e-04 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 -run_vdwl: 0.0367090517931737 +run_vdwl: 0.0367090517931635 run_coul: 0 run_stress: ! |2- - 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 + 3.2547164843321998e+00 1.2822272288053016e+01 2.9381904014809583e+00 -6.5755478139674493e+00 2.3052669923975677e+00 1.5140903126232053e+00 run_forces: ! |2 - 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 - 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 - 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 - 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 - 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 - 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 - 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 - 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 - 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 - 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 - 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 - 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 - 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 - 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 - 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 - 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 - 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 - 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 - 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 1 5.8196197291626575e-02 7.7034242946349710e-02 1.0456829776646283e-01 + 2 -4.1552988555246369e-02 -1.1540194679885474e-02 1.5467509805429086e-01 + 3 -6.6558201800471888e-03 -9.8090417095619570e-04 -4.5870088099424298e-04 + 4 -1.6184658518487716e-02 -1.2048418808706531e-02 -1.2190156970179285e-02 + 5 -3.3316803862839500e-02 -2.1131495092834723e-02 1.4963198384123161e-02 + 6 4.7038346343351856e-04 -3.0307837184768479e-02 -4.3608938525025828e-02 + 7 1.0396652127649044e-03 7.5317021954245870e-04 4.1930480907775929e-05 + 8 6.4423457305213851e-03 1.1468835414812505e-03 6.8526191116135909e-04 + 9 1.7585178109228026e+00 -4.3823551563818404e+00 -1.2468505588145364e+00 + 10 1.3392700382201883e-01 -2.9471624976996413e-02 -9.0915578208389941e-03 + 11 7.9839096035526651e-04 6.5881060273478051e-05 1.3840230606223500e-04 + 12 1.8540711168999979e-04 3.9935505493719320e-04 1.2187452986588761e-04 + 13 -1.4075050026169872e-01 1.8204883476184680e-02 -2.0674384501958849e-03 + 14 -2.4452271394244732e-04 -5.7393635529214925e-05 1.6908863929994199e-05 + 15 -3.4577717467029808e-03 -9.3350658134032805e-04 -1.5696623820874909e-03 + 16 5.4762334392971521e+00 -3.3427628201841029e+00 5.8008787111000384e+00 + 17 -1.7123087875076739e-02 1.5861563712562882e-02 -1.3049347364948762e-02 + 18 1.1434938302418579e-01 8.6112942994289246e-03 2.0292892978925857e-02 + 19 -3.8092989065812349e-02 -1.9963855292591714e-02 -9.8568020007968171e-03 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 - 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 - 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 - 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 - 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 - 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 - 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 + 21 4.1446743356056477e-02 8.4986882092497468e-03 -7.1565549648589286e-02 + 22 -5.5269240273286080e+00 3.3665609275390400e+00 -5.7932229791606122e+00 + 23 1.5450935830291862e-02 -1.0557581147017453e-01 -1.1539704280712934e-01 + 24 -7.5222270706101790e-04 1.1318969997713260e-04 -9.2841932954143699e-04 + 25 1.1778375109233756e-03 -7.1254208855309979e-05 3.8035457799329474e-03 + 26 -1.6497221843622341e+00 4.4233264004280688e+00 1.2763820593322264e+00 + 27 -1.3345796635606499e-01 3.6623792481486409e-02 -5.6711027332452466e-02 ... diff --git a/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml b/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml index d49b93ac0d..25c84a5938 100644 --- a/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml +++ b/unittest/force-styles/tests/atomic-pair-colloid_tiled_tri.yaml @@ -1,7 +1,7 @@ --- lammps_version: 21 Jul 2020 -date_generated: Mon Aug 3 16:06:24 202 -epsilon: 5e-14 +date_generated: Mon Aug 3 22:40:52 202 +epsilon: 5e-13 prerequisites: ! | pair colloid pre_commands: ! | @@ -22,65 +22,65 @@ natoms: 27 init_vdwl: -0.250265293649414 init_coul: 0 init_stress: ! |2- - 1.6693554149342913e+00 1.1752557173260270e+01 1.0084916384631617e+00 -5.5164068587184527e+00 3.4448938909043431e-01 2.8524984331506258e+00 + 1.6693554149342911e+00 1.1752557173260259e+01 1.0084916384631786e+00 -5.5164068587184580e+00 3.4448938909043375e-01 2.8524984331506325e+00 init_forces: ! |2 - 1 7.2698902368314056e-02 7.6228314794484775e-02 1.0726717051410484e-01 + 1 7.2698902368313792e-02 7.6228314794484928e-02 1.0726717051410495e-01 2 -4.1487528743785314e-02 -9.8021436494101673e-03 1.5709289685835706e-01 3 -6.4514052467860251e-03 -1.0256365723614392e-03 -6.5497018575823654e-04 4 -1.5879716299045554e-02 -1.3313626328419375e-02 -1.1960220488237115e-02 5 -3.6475105049685402e-02 -2.2992583864092257e-02 1.6166097759476136e-02 - 6 5.4769180740248721e-04 -2.4426732691233789e-02 -3.6444902428178980e-02 + 6 5.4769180740244731e-04 -2.4426732691233955e-02 -3.6444902428179146e-02 7 1.2006858444817004e-03 8.6089326153587114e-04 4.8033026817420977e-05 - 8 6.2576206692511894e-03 1.1942031910109577e-03 8.5598267089392085e-04 - 9 1.8304752931477772e+00 -4.3380838069003760e+00 -1.2763141904695217e+00 - 10 1.0456768773213965e-01 -2.8797785965171453e-02 -1.0768387599117879e-02 - 11 7.4457152913473112e-04 5.3043528596594623e-05 1.1848179655097060e-04 + 8 6.2576206692511894e-03 1.1942031910109575e-03 8.5598267089392129e-04 + 9 1.8304752931477772e+00 -4.3380838069003751e+00 -1.2763141904695217e+00 + 10 1.0456768773213966e-01 -2.8797785965171449e-02 -1.0768387599117872e-02 + 11 7.4457152913473068e-04 5.3043528596594895e-05 1.1848179655097051e-04 12 1.8275344545112628e-04 4.1948901318387846e-04 9.8529270880004928e-05 - 13 -1.1259391902077470e-01 1.6396787556459839e-02 -9.0455786475091124e-04 - 14 -2.4411189619188785e-04 -5.8284002050384879e-05 1.8046434825690733e-05 + 13 -1.1259391902077470e-01 1.6396787556459836e-02 -9.0455786475091167e-04 + 14 -2.4411189619188755e-04 -5.8284002050384791e-05 1.8046434825690706e-05 15 -2.9421019290851403e-03 -7.4831176382853144e-04 -1.2326238660052020e-03 - 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815386e+00 + 16 2.2461127490925330e+00 -1.1352527056039741e+00 2.3679980564815390e+00 17 -1.8842133286566962e-02 1.7091738246445273e-02 -1.4247568288438442e-02 - 18 1.0304762560041125e-01 7.8062023784307467e-03 1.9257495383127633e-02 + 18 1.0304762560041145e-01 7.8062023784307155e-03 1.9257495383127543e-02 19 -4.3351162132476757e-02 -2.2995928402219718e-02 -1.1392806036292676e-02 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 21 4.2501672350519284e-02 6.8582908647593938e-03 -6.8677246013076107e-02 - 22 -2.2945818607502839e+00 1.1603382884260454e+00 -2.3594708301087310e+00 - 23 2.5606115583434265e-02 -1.0270997331622232e-01 -1.1451933998746673e-01 - 24 -8.0648597970214809e-04 1.1943689027481706e-04 -9.8441554909815322e-04 + 21 4.2501672350519284e-02 6.8582908647593982e-03 -6.8677246013076107e-02 + 22 -2.2945818607502835e+00 1.1603382884260451e+00 -2.3594708301087310e+00 + 23 2.5606115583434334e-02 -1.0270997331622238e-01 -1.1451933998746676e-01 + 24 -8.0648597970214874e-04 1.1943689027481719e-04 -9.8441554909815452e-04 25 6.1663239781204458e-04 -2.9236784591333030e-04 3.5387752678593654e-03 26 -1.7197958284241512e+00 4.3707144027711022e+00 1.2977194913045054e+00 27 -1.4110864281012736e-01 4.2418795982941855e-02 -6.2606997884263993e-02 -run_vdwl: 0.0367090517931737 +run_vdwl: 0.0367090517931635 run_coul: 0 run_stress: ! |2- - 3.2547164843322691e+00 1.2822272288053391e+01 2.9381904014809663e+00 -6.5755478139675931e+00 2.3052669923975411e+00 1.5140903126232879e+00 + 3.2547164843321998e+00 1.2822272288053016e+01 2.9381904014809583e+00 -6.5755478139674493e+00 2.3052669923975677e+00 1.5140903126232053e+00 run_forces: ! |2 - 1 5.8196197291625715e-02 7.7034242946349946e-02 1.0456829776646254e-01 - 2 -4.1552988555246327e-02 -1.1540194679885485e-02 1.5467509805429100e-01 - 3 -6.6558201800471870e-03 -9.8090417095619679e-04 -4.5870088099424396e-04 - 4 -1.6184658518487705e-02 -1.2048418808706472e-02 -1.2190156970179262e-02 - 5 -3.3316803862839438e-02 -2.1131495092834646e-02 1.4963198384123119e-02 - 6 4.7038346343352116e-04 -3.0307837184768524e-02 -4.3608938525025766e-02 - 7 1.0396652127649081e-03 7.5317021954246196e-04 4.1930480907776011e-05 - 8 6.4423457305213877e-03 1.1468835414812518e-03 6.8526191116136061e-04 - 9 1.7585178109228492e+00 -4.3823551563819700e+00 -1.2468505588145766e+00 - 10 1.3392700382201897e-01 -2.9471624976996433e-02 -9.0915578208389906e-03 - 11 7.9839096035526857e-04 6.5881060273478105e-05 1.3840230606223543e-04 - 12 1.8540711169000120e-04 3.9935505493718929e-04 1.2187452986589205e-04 - 13 -1.4075050026169886e-01 1.8204883476184704e-02 -2.0674384501958810e-03 - 14 -2.4452271394244688e-04 -5.7393635529214755e-05 1.6908863929994165e-05 - 15 -3.4577717467029726e-03 -9.3350658134032599e-04 -1.5696623820874889e-03 - 16 5.4762334392971725e+00 -3.3427628201841184e+00 5.8008787111000641e+00 - 17 -1.7123087875076635e-02 1.5861563712562771e-02 -1.3049347364948664e-02 - 18 1.1434938302418582e-01 8.6112942994291432e-03 2.0292892978926169e-02 - 19 -3.8092989065812294e-02 -1.9963855292591683e-02 -9.8568020007968223e-03 + 1 5.8196197291626575e-02 7.7034242946349710e-02 1.0456829776646283e-01 + 2 -4.1552988555246369e-02 -1.1540194679885474e-02 1.5467509805429086e-01 + 3 -6.6558201800471888e-03 -9.8090417095619570e-04 -4.5870088099424298e-04 + 4 -1.6184658518487716e-02 -1.2048418808706531e-02 -1.2190156970179285e-02 + 5 -3.3316803862839500e-02 -2.1131495092834723e-02 1.4963198384123161e-02 + 6 4.7038346343351856e-04 -3.0307837184768479e-02 -4.3608938525025828e-02 + 7 1.0396652127649044e-03 7.5317021954245870e-04 4.1930480907775929e-05 + 8 6.4423457305213851e-03 1.1468835414812505e-03 6.8526191116135909e-04 + 9 1.7585178109228026e+00 -4.3823551563818404e+00 -1.2468505588145364e+00 + 10 1.3392700382201883e-01 -2.9471624976996413e-02 -9.0915578208389941e-03 + 11 7.9839096035526651e-04 6.5881060273478051e-05 1.3840230606223500e-04 + 12 1.8540711168999979e-04 3.9935505493719320e-04 1.2187452986588761e-04 + 13 -1.4075050026169872e-01 1.8204883476184680e-02 -2.0674384501958849e-03 + 14 -2.4452271394244732e-04 -5.7393635529214925e-05 1.6908863929994199e-05 + 15 -3.4577717467029808e-03 -9.3350658134032805e-04 -1.5696623820874909e-03 + 16 5.4762334392971521e+00 -3.3427628201841029e+00 5.8008787111000384e+00 + 17 -1.7123087875076739e-02 1.5861563712562882e-02 -1.3049347364948762e-02 + 18 1.1434938302418579e-01 8.6112942994289246e-03 2.0292892978925857e-02 + 19 -3.8092989065812349e-02 -1.9963855292591714e-02 -9.8568020007968171e-03 20 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 21 4.1446743356056415e-02 8.4986882092498717e-03 -7.1565549648589466e-02 - 22 -5.5269240273286284e+00 3.3665609275390551e+00 -5.7932229791606371e+00 - 23 1.5450935830291834e-02 -1.0557581147017484e-01 -1.1539704280712981e-01 - 24 -7.5222270706101302e-04 1.1318969997713211e-04 -9.2841932954143037e-04 - 25 1.1778375109233736e-03 -7.1254208855308434e-05 3.8035457799329383e-03 - 26 -1.6497221843622811e+00 4.4233264004281976e+00 1.2763820593322663e+00 - 27 -1.3345796635606427e-01 3.6623792481486235e-02 -5.6711027332452084e-02 + 21 4.1446743356056477e-02 8.4986882092497468e-03 -7.1565549648589286e-02 + 22 -5.5269240273286080e+00 3.3665609275390400e+00 -5.7932229791606122e+00 + 23 1.5450935830291862e-02 -1.0557581147017453e-01 -1.1539704280712934e-01 + 24 -7.5222270706101790e-04 1.1318969997713260e-04 -9.2841932954143699e-04 + 25 1.1778375109233756e-03 -7.1254208855309979e-05 3.8035457799329474e-03 + 26 -1.6497221843622341e+00 4.4233264004280688e+00 1.2763820593322264e+00 + 27 -1.3345796635606499e-01 3.6623792481486409e-02 -5.6711027332452466e-02 ... From c2ed04052907fb8665e23a0dd0e9559405c44e24 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 22:49:21 -0400 Subject: [PATCH 052/122] simplify --- src/comm_tiled.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/comm_tiled.cpp b/src/comm_tiled.cpp index 893d0f23d8..79a8f3ab7d 100644 --- a/src/comm_tiled.cpp +++ b/src/comm_tiled.cpp @@ -46,6 +46,11 @@ CommTiled::CommTiled(LAMMPS *lmp) : Comm(lmp) style = 1; layout = Comm::LAYOUT_UNIFORM; pbc_flag = NULL; + buf_send = NULL; + buf_recv = NULL; + overlap = NULL; + rcbinfo = NULL; + cutghostmulti = NULL; init_buffers(); } @@ -73,8 +78,7 @@ CommTiled::~CommTiled() memory->destroy(overlap); deallocate_swap(maxswap); memory->sfree(rcbinfo); - - if (mode == Comm::MULTI) memory->destroy(cutghostmulti); + memory->destroy(cutghostmulti); } /* ---------------------------------------------------------------------- @@ -105,9 +109,8 @@ void CommTiled::init() { Comm::init(); - if (mode == Comm::SINGLE && cutghostmulti) memory->destroy(cutghostmulti); - - if (mode == Comm::MULTI && !cutghostmulti) + memory->destroy(cutghostmulti); + if (mode == Comm::MULTI) memory->create(cutghostmulti,atom->ntypes+1,3,"comm:cutghostmulti"); int bufextra_old = bufextra; From 4e46c0aef4d704249344c71a231372df2c863f76 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 23:02:29 -0400 Subject: [PATCH 053/122] add missing born/coul/long variant using tabulation --- .../tests/mol-pair-born_coul_table_cs.yaml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-born_coul_table_cs.yaml diff --git a/unittest/force-styles/tests/mol-pair-born_coul_table_cs.yaml b/unittest/force-styles/tests/mol-pair-born_coul_table_cs.yaml new file mode 100644 index 0000000000..2efbaa0d17 --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-born_coul_table_cs.yaml @@ -0,0 +1,104 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:01:29 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair born/coul/long/cs + kspace ewald +pre_commands: ! "" +post_commands: ! | + pair_modify table 16 + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify compute no +input_file: in.fourmol +pair_style: born/coul/long/cs 8.0 +pair_coeff: ! "1 1 2.51937098847838 0.148356076521964 1.82166848001002 29.0375806150613 + 141.547923828784 \n1 2 2.87560097202631 0.103769845319212 1.18949647259382 1.7106306969663 + 4.09225030876458 \n1 3 2.73333746288062 0.169158133709025 2.06291417638668 63.7180294456725 + 403.51858739517 \n1 4 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 + 303.336540547726 \n1 5 2.51591531388789 0.166186965980131 2.01659390849669 49.622913109061 + 303.336540547726 \n2 2 1.0594557710255 0.281261664467988 0.314884389172266 0.271080184997071 + 0.177172207445923 \n2 3 2.12127488295383 0.124576922646243 1.46526793359105 5.10367785279284 + 17.5662073921955 \n2 4 0.523836115049206 0.140093804714855 0.262040872137659 0.00432916334694855 + 0.000703093129207124 \n2 5 2.36887234111228 0.121604450909563 1.39946581861656 3.82529730669145 + 12.548008396489 \n3 3 2.81831917530019 0.189944649028137 2.31041576143228 127.684271782117 + 1019.38354056979 \n3 4 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 + 778.254162800904 \n3 5 2.5316180773506 0.186976803503293 2.26748506873271 100.602835334624 + 778.254162800904 \n4 4 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 + 592.979935420722 \n4 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 + 592.979935420722 \n5 5 2.63841820292211 0.184008285863681 2.19742633928911 79.1465822481912 + 592.979935420722 \n" +extract: ! | + cut_coul 0 +natoms: 29 +init_vdwl: 225.013257749962 +init_coul: 225.821984927182 +init_stress: ! |2- + 4.6612535625392223e+02 4.5192055444711946e+02 7.9054321026840489e+02 -1.0129681203253186e+02 3.7655451167028815e+01 1.0478181459526597e+02 +init_forces: ! |2 + 1 -4.2744171995291200e+00 6.5642049804715057e+01 8.4068013672777155e+01 + 2 4.0209527054590872e+01 3.0391860097447168e+01 -4.8931506055848843e+01 + 3 -3.3540726546558716e+01 -9.0449991459008160e+01 -3.5301559106720546e+01 + 4 -5.4885786039716677e+00 1.4626415089572660e+00 -4.0890600022047829e+00 + 5 -2.2350692696076688e+00 -2.1239945832175642e+00 7.8825542300878579e+00 + 6 -1.3482330357706749e+02 1.4551263564508565e+02 1.3402990144793662e+02 + 7 3.2821833942167022e+00 -4.2934248972448188e+01 -2.4388196078229467e+02 + 8 7.8570433339101591e+00 -8.2133390712202736e+00 6.5769497957263397e+01 + 9 1.9839979052896229e+01 1.3822694649422328e+01 8.2044395343559273e+01 + 10 9.3004048017983607e+01 -1.1568985543733307e+02 -3.3734440281173242e+01 + 11 -2.4562224334558551e+00 -2.9027342373792737e+00 -6.9791136678084067e+00 + 12 1.4141624566026227e+01 5.2480390959728984e+00 -3.4118155597270396e+00 + 13 5.5944703623716618e+00 -2.2564548462311267e+00 -2.8118816287021392e-01 + 14 -3.3931147380056803e+00 8.3034742626630687e-01 -6.1327534306612552e+00 + 15 2.1513224229068897e-01 5.7084758703545893e+00 1.0852112214827847e+00 + 16 7.5247047780629714e+01 -5.8376867982950195e+01 -1.7489363873408669e+02 + 17 -7.2022975653132946e+01 5.4112669923453062e+01 1.8109984221090852e+02 + 18 3.5544765059221800e-01 4.7678957109253099e+00 -7.8535241427322164e+00 + 19 1.9896136259819237e+00 -7.2222882870608585e-01 5.5228269214075212e+00 + 20 -2.9131654353716931e+00 -3.9874541061789577e+00 4.1258302234457789e+00 + 21 -1.6536116783325870e+01 -1.7262823342184745e+01 5.2560386651291260e+01 + 22 -2.7766851624962559e+01 -7.7369191155269332e+00 -4.0489986551383495e+01 + 23 4.3884346040036966e+01 2.5418133861326432e+01 -1.1563360040889810e+01 + 24 9.7879302105559187e+00 -4.7514662492120735e+01 2.6203574236090979e+01 + 25 -3.8118683101718617e+01 3.6915827459256549e+00 -3.1203297458536532e+01 + 26 2.7765734167841497e+01 4.3564040916174591e+01 4.3785230272041078e+00 + 27 9.7332884809348705e+00 -5.1358738629501516e+01 1.9618779693342940e+01 + 28 -4.2804259382932656e+01 1.6023914430085185e+01 -2.8346203528536542e+01 + 29 3.3466068368781215e+01 3.5333331417895330e+01 8.7040706686759854e+00 +run_vdwl: 158.33589406052 +run_coul: 227.519616203199 +run_stress: ! |2- + 3.6506610142382198e+02 3.5585432196398307e+02 5.1680854242642044e+02 -9.2985868616835177e+01 3.2903389766521045e+01 7.6473484219988137e+01 +run_forces: ! |2 + 1 3.4740137122325940e+00 5.4427031477546514e+01 5.7644049810271660e+01 + 2 2.4668394006494108e+01 1.7380374422568075e+01 -3.0485717186930390e+01 + 3 -3.0671694194688300e+01 -6.2331979212361382e+01 -2.4103728809060588e+01 + 4 -5.2737304857458360e+00 1.5284955928957380e+00 -3.9921020143568069e+00 + 5 -2.0255502655412516e+00 -1.7100705193238788e+00 7.2330110746998724e+00 + 6 -9.7881004917114424e+01 9.9614230606340129e+01 5.2490653321805482e+01 + 7 4.2990285326590163e+00 -2.6421621180728582e+01 -1.3451140836832613e+02 + 8 4.2808110486564885e+00 -1.4375951474610740e+00 5.7456664336142353e+01 + 9 1.3778432911071590e+01 6.0184713878678728e+00 5.3704104527341073e+01 + 10 6.9397553151684576e+01 -8.8421946603081096e+01 -2.9728906298815073e+01 + 11 -2.6530111544007715e+00 -2.6254011528391357e+00 -6.9016420719866858e+00 + 12 1.3488997494690972e+01 5.3096597788660667e+00 -3.9761000038075451e+00 + 13 5.2476618246843048e+00 -2.0217253969516493e+00 -2.9021853056035080e-01 + 14 -3.1782541836839560e+00 6.9912061140625337e-01 -5.2298944690262426e+00 + 15 5.1522252095229384e-02 5.5229852065671130e+00 1.1243213270377830e+00 + 16 4.7485121131117580e+01 -4.0801417892954383e+01 -9.5835978095106611e+01 + 17 -4.3156227647458110e+01 3.5026673322355016e+01 1.0362037387690761e+02 + 18 -2.8012872173427644e-01 4.4055348930819980e+00 -7.2872470347236336e+00 + 19 2.4156852945869032e+00 -4.9849041715282327e-01 5.6276372347324282e+00 + 20 -2.8096179678915001e+00 -3.8549753374075713e+00 3.5986537839123063e+00 + 21 -1.1657126725063907e+01 -1.0584980409994705e+01 3.5967714751480528e+01 + 22 -1.9631687853001058e+01 -5.8903303709644561e+00 -2.7738970022953254e+01 + 23 3.0820812352804918e+01 1.6933499181982242e+01 -7.6539279665433311e+00 + 24 9.5662818501205109e+00 -3.4566226551842625e+01 2.0565441879541613e+01 + 25 -3.0571279410409204e+01 2.3365486317254778e+00 -2.5139482149253311e+01 + 26 2.0369330645008652e+01 3.1959194195493058e+01 3.8804233038006255e+00 + 27 6.2843935712978904e+00 -3.5026318882468502e+01 1.2415958172673916e+01 + 28 -2.9249621303753152e+01 1.0572624422891584e+01 -1.8990200158235847e+01 + 29 2.3410895051280438e+01 2.4458635343944739e+01 6.5365157793386128e+00 +... From ef8b619840f75d114f441296992e3493a5e012b6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 23:21:54 -0400 Subject: [PATCH 054/122] fix missing support for nozforce in ewald/omp --- src/USER-OMP/ewald_omp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/USER-OMP/ewald_omp.cpp b/src/USER-OMP/ewald_omp.cpp index fd776e46a6..f4473a6633 100644 --- a/src/USER-OMP/ewald_omp.cpp +++ b/src/USER-OMP/ewald_omp.cpp @@ -155,7 +155,7 @@ void EwaldOMP::compute(int eflag, int vflag) const double fac = qscale*q[i]; f[i][0] += fac*ek[i][0]; f[i][1] += fac*ek[i][1]; - f[i][2] += fac*ek[i][2]; + if (slabflag != 2) f[i][2] += fac*ek[i][2]; } // global energy @@ -222,7 +222,7 @@ void EwaldOMP::compute(int eflag, int vflag) virial[5] = v5 * qscale; } - if (slabflag) slabcorr(); + if (slabflag == 1) slabcorr(); } /* ---------------------------------------------------------------------- */ From 83519290e7e445c81958b3577dc804a3218e6874 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 23:28:19 -0400 Subject: [PATCH 055/122] add kspace tests with slab correction and pppm/stagger --- .../tests/kspace-ewald_nozforce.yaml | 92 +++++++++++++++++++ .../force-styles/tests/kspace-ewald_slab.yaml | 92 +++++++++++++++++++ .../tests/kspace-pppm_nozforce.yaml | 90 ++++++++++++++++++ .../force-styles/tests/kspace-pppm_slab.yaml | 90 ++++++++++++++++++ .../tests/kspace-pppm_stagger.yaml | 88 ++++++++++++++++++ .../tests/kspace-pppm_tip4p_nozforce.yaml | 92 +++++++++++++++++++ .../tests/kspace-pppm_tip4p_slab.yaml | 92 +++++++++++++++++++ 7 files changed, 636 insertions(+) create mode 100644 unittest/force-styles/tests/kspace-ewald_nozforce.yaml create mode 100644 unittest/force-styles/tests/kspace-ewald_slab.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_nozforce.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_slab.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_stagger.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_tip4p_nozforce.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml diff --git a/unittest/force-styles/tests/kspace-ewald_nozforce.yaml b/unittest/force-styles/tests/kspace-ewald_nozforce.yaml new file mode 100644 index 0000000000..c0ddcf9d25 --- /dev/null +++ b/unittest/force-styles/tests/kspace-ewald_nozforce.yaml @@ -0,0 +1,92 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:14:07 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace ewald +pre_commands: ! | + boundary p p f +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 0 + pair_modify compute no + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab nozforce +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.2206771887658943e-01 8.2092716641334329e-02 0.0000000000000000e+00 + 2 2.1693903829318817e-01 -2.7927861552229305e-01 0.0000000000000000e+00 + 3 -3.4431684378643801e-02 -9.3072637218381445e-03 0.0000000000000000e+00 + 4 1.6297859881038013e-01 2.8852601805448030e-02 0.0000000000000000e+00 + 5 1.6019985134449477e-01 7.5436361467604754e-02 0.0000000000000000e+00 + 6 5.6481531228200665e-01 4.1679985765871463e-01 0.0000000000000000e+00 + 7 -3.4209721978750263e-01 -3.9984396831970670e-01 0.0000000000000000e+00 + 8 -1.4129044569095472e-01 -6.1689555678793007e-01 0.0000000000000000e+00 + 9 1.8222478940751916e-01 3.2011243047943372e-01 0.0000000000000000e+00 + 10 -5.1661247919076315e-02 1.1067475077169277e-01 0.0000000000000000e+00 + 11 -8.4669875945943968e-02 1.5095743463211175e-01 0.0000000000000000e+00 + 12 4.5741440577763515e-01 -4.2654712552449048e-01 0.0000000000000000e+00 + 13 -1.5597032418106432e-01 1.1611461366044702e-01 0.0000000000000000e+00 + 14 -1.7228226924755827e-01 1.3656996830861831e-01 0.0000000000000000e+00 + 15 -1.3781820350751567e-01 8.5592039476758322e-02 0.0000000000000000e+00 + 16 -3.4310225376566400e-01 4.3356489402218990e-01 0.0000000000000000e+00 + 17 1.3398758000490049e-01 -4.1297852445140776e-01 0.0000000000000000e+00 + 18 7.3018610540764362e-01 1.5461055670151038e+00 0.0000000000000000e+00 + 19 -2.5925238656641114e-01 -7.7445922519024368e-01 0.0000000000000000e+00 + 20 -3.9378990654178680e-01 -7.0329956300491681e-01 0.0000000000000000e+00 + 21 5.1865366949828340e-01 5.4317145701042313e-01 0.0000000000000000e+00 + 22 -2.9464392578389154e-01 -1.2315564069397771e-01 0.0000000000000000e+00 + 23 -2.8787383348123141e-01 -2.9290360518755271e-01 0.0000000000000000e+00 + 24 6.2598634622894167e-02 1.7443480404415288e+00 0.0000000000000000e+00 + 25 1.2975379714426077e-01 -7.0440473186448149e-01 0.0000000000000000e+00 + 26 -2.2233830537492869e-01 -9.7471462858413116e-01 0.0000000000000000e+00 + 27 -8.5924682160715782e-01 1.6508884428561106e+00 0.0000000000000000e+00 + 28 5.7108983323284834e-01 -9.1775706639800869e-01 0.0000000000000000e+00 + 29 4.1169480682986315e-01 -8.0573566099654348e-01 0.0000000000000000e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0922198207275216e-01 8.3299374769207374e-02 0.0000000000000000e+00 + 2 2.0313997125119648e-01 -2.8559662507968914e-01 0.0000000000000000e+00 + 3 -3.4169529669450076e-02 -9.1320476095310878e-03 0.0000000000000000e+00 + 4 1.6415735470196405e-01 2.7630906100053938e-02 0.0000000000000000e+00 + 5 1.5801741050662524e-01 7.5219480567487992e-02 0.0000000000000000e+00 + 6 5.5924732284848488e-01 4.1159692353723032e-01 0.0000000000000000e+00 + 7 -3.4278065443293276e-01 -4.0379989711671849e-01 0.0000000000000000e+00 + 8 -1.2932327988973355e-01 -6.1414548453877604e-01 0.0000000000000000e+00 + 9 1.7224295378348622e-01 3.1583564204538828e-01 0.0000000000000000e+00 + 10 -5.3287915345397070e-02 1.1165778094386405e-01 0.0000000000000000e+00 + 11 -8.6512483505532381e-02 1.5455497998789855e-01 0.0000000000000000e+00 + 12 4.6260824709191073e-01 -4.2658119411285045e-01 0.0000000000000000e+00 + 13 -1.5764562974893831e-01 1.1682487185077797e-01 0.0000000000000000e+00 + 14 -1.7358231824085660e-01 1.3774426850511587e-01 0.0000000000000000e+00 + 15 -1.3804091748748470e-01 8.4301227071595833e-02 0.0000000000000000e+00 + 16 -3.5428477826991744e-01 4.4004208038718706e-01 0.0000000000000000e+00 + 17 1.4336979258817731e-01 -4.0685018683212876e-01 0.0000000000000000e+00 + 18 7.7410627953828881e-01 1.6016860432757520e+00 0.0000000000000000e+00 + 19 -2.7106489742044282e-01 -7.9223413845691382e-01 0.0000000000000000e+00 + 20 -4.2043235259953632e-01 -7.3414545899552996e-01 0.0000000000000000e+00 + 21 5.2066128136749024e-01 4.5609238431952892e-01 0.0000000000000000e+00 + 22 -2.9124694813290708e-01 -8.0658431270677095e-02 0.0000000000000000e+00 + 23 -2.8864262412198810e-01 -2.5712303806367826e-01 0.0000000000000000e+00 + 24 7.6818103390669135e-02 1.6938501771318075e+00 0.0000000000000000e+00 + 25 1.1774898875879186e-01 -6.8178289845849072e-01 0.0000000000000000e+00 + 26 -2.2401379838848151e-01 -9.4803798767516445e-01 0.0000000000000000e+00 + 27 -8.6795336552829527e-01 1.6456749267345261e+00 0.0000000000000000e+00 + 28 5.7535731007479385e-01 -9.1129108719960294e-01 0.0000000000000000e+00 + 29 4.1472845895276644e-01 -8.0463259181767532e-01 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/kspace-ewald_slab.yaml b/unittest/force-styles/tests/kspace-ewald_slab.yaml new file mode 100644 index 0000000000..db3df7e338 --- /dev/null +++ b/unittest/force-styles/tests/kspace-ewald_slab.yaml @@ -0,0 +1,92 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:13:06 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace ewald +pre_commands: ! | + boundary p p f +post_commands: ! | + pair_modify mix arithmetic + pair_modify table 0 + pair_modify compute no + kspace_style ewald 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab 3.0 +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.3361753409266011e-01 7.2474050630486397e-02 -6.4892582168941204e-01 + 2 2.2165421230159843e-01 -2.7138675475622931e-01 4.4457208586650132e-01 + 3 -3.4462492700023370e-02 -9.4931581561452788e-03 -1.6711339189600608e-02 + 4 1.6009467653921222e-01 2.9594196149645171e-02 8.5910075300645775e-02 + 5 1.6281154846043450e-01 7.6523848827386901e-02 1.2400830089289680e-01 + 6 5.6482815940123376e-01 4.1388410715112561e-01 2.8179415394244917e-01 + 7 -3.2347418968868985e-01 -3.8985992716544621e-01 -5.8912235651112477e-01 + 8 -1.5697672190959872e-01 -6.1072935315288612e-01 -5.4342135647690193e-01 + 9 2.0036414047167639e-01 3.1834021781947897e-01 6.2895476343064571e-01 + 10 -4.8718325250782540e-02 1.0867974111969349e-01 1.1812338716397977e-01 + 11 -8.1947442204853740e-02 1.4701736521312425e-01 1.3219906208471702e-01 + 12 4.4443345101739523e-01 -4.1951797407500613e-01 -4.8455970153751715e-01 + 13 -1.5091465015529718e-01 1.1319749135622954e-01 1.9844251818681755e-01 + 14 -1.6824697215186588e-01 1.3301143412013644e-01 1.8777190897285814e-01 + 15 -1.3378178085909101e-01 8.5124374218749618e-02 1.5833739770846003e-01 + 16 -3.1204295604225468e-01 4.1843152851912041e-01 1.4963263649359766e+00 + 17 8.5511143393385391e-02 -3.9838711770989677e-01 -1.7490848000302388e+00 + 18 6.9767841561183264e-01 1.4639305171423875e+00 -3.0981283271233360e+00 + 19 -2.6697437980225314e-01 -7.2857256379977620e-01 1.6659099083426288e+00 + 20 -3.5571914072318572e-01 -6.3987749489841428e-01 1.5765048845575460e+00 + 21 4.4008649447955778e-01 6.1604386171178460e-01 -2.6905997408022140e+00 + 22 -2.3908793489681074e-01 -1.7899897276005095e-01 1.3460104136165247e+00 + 23 -2.4624199934626004e-01 -3.2941875813690191e-01 1.3107547628013068e+00 + 24 -3.9796432380874887e-02 1.6972667611172640e+00 -1.9461999021646923e+00 + 25 1.8342452954779850e-01 -6.8606343405120163e-01 1.0350282338917181e+00 + 26 -1.8860502022248327e-01 -9.6009532237242456e-01 9.2299303243823538e-01 + 27 -8.8701614364017456e-01 1.6758866889894808e+00 -2.3733465293128266e+00 + 28 5.6438686171708552e-01 -9.2660913774932463e-01 1.2668162312477351e+00 + 29 4.4235048312594993e-01 -8.2039621530239382e-01 1.1596423894562287e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.1961230445122764e-01 7.3575054602555187e-02 -5.8782096428192632e-01 + 2 2.0737787805944638e-01 -2.7767027752058837e-01 4.0659266771773472e-01 + 3 -3.4157183789806395e-02 -9.2872029558395599e-03 -1.3999532798838633e-02 + 4 1.6119110046521443e-01 2.8213855094480825e-02 7.5084865228924047e-02 + 5 1.6033190269875908e-01 7.6208487852502046e-02 1.1132609100506854e-01 + 6 5.5816641477874607e-01 4.0764127470290545e-01 2.0735398759101753e-01 + 7 -3.2378703810724269e-01 -3.9319841391731630e-01 -5.2600192619734398e-01 + 8 -1.4329109288808964e-01 -6.0719216040848112e-01 -4.7011357224994710e-01 + 9 1.8940418938467887e-01 3.1356657181921910e-01 5.8144817743273647e-01 + 10 -5.0661801622413370e-02 1.0963746206085294e-01 1.0771935003720641e-01 + 11 -8.4219594563415601e-02 1.5068732481535566e-01 1.2086035128812209e-01 + 12 4.5058066316352680e-01 -4.1965300997537580e-01 -4.4232729500288048e-01 + 13 -1.5285664247459638e-01 1.1407805589048045e-01 1.8500838861223956e-01 + 14 -1.6987452549004867e-01 1.3423386493466799e-01 1.7560310176136040e-01 + 15 -1.3422814848275488e-01 8.3779612871949335e-02 1.4301817966786870e-01 + 16 -3.2542370126003872e-01 4.2440677047308406e-01 1.4335299477840748e+00 + 17 9.6856707559469610e-02 -3.9089156801277541e-01 -1.6845244027602280e+00 + 18 7.4327290959697911e-01 1.5227435820791153e+00 -2.9781652275623647e+00 + 19 -2.7839567210225469e-01 -7.4881016624168151e-01 1.6126171023084344e+00 + 20 -3.8359735553826746e-01 -6.7326569047148088e-01 1.5161210715596880e+00 + 21 4.4499838541358216e-01 5.2614861393462908e-01 -2.5742849592390571e+00 + 22 -2.3781939875175795e-01 -1.3417062095022572e-01 1.2921387941874185e+00 + 23 -2.4865386687420440e-01 -2.9204348870999131e-01 1.2536524910607787e+00 + 24 -2.7009830231122915e-02 1.6399415444568417e+00 -1.8553269783213893e+00 + 25 1.7085514123353013e-01 -6.6072824112130302e-01 9.8605585674205232e-01 + 26 -1.8797937383041033e-01 -9.2896608996524477e-01 8.7828261535355356e-01 + 27 -8.9321057146686433e-01 1.6735627941182389e+00 -2.2616319987044329e+00 + 28 5.6823371983147408e-01 -9.2136775625072376e-01 1.2081850450570102e+00 + 29 4.4350908973911252e-01 -8.2118018320585484e-01 1.0995987727231249e+00 +... diff --git a/unittest/force-styles/tests/kspace-pppm_nozforce.yaml b/unittest/force-styles/tests/kspace-pppm_nozforce.yaml new file mode 100644 index 0000000000..df7202d008 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_nozforce.yaml @@ -0,0 +1,90 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:24:33 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace pppm +pre_commands: ! | + boundary p p f +post_commands: ! | + pair_modify compute no + kspace_style pppm 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab nozforce +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.2239274535568314e-01 8.2051545744881466e-02 0.0000000000000000e+00 + 2 2.1712968366442176e-01 -2.7928074334318026e-01 0.0000000000000000e+00 + 3 -3.4442019165638028e-02 -9.3084265599194874e-03 0.0000000000000000e+00 + 4 1.6298334373562443e-01 2.8852998088186425e-02 0.0000000000000000e+00 + 5 1.6024289196964533e-01 7.5428818157230709e-02 0.0000000000000000e+00 + 6 5.6503043686117405e-01 4.1669523647698320e-01 0.0000000000000000e+00 + 7 -3.4224573570118516e-01 -3.9969025602522534e-01 0.0000000000000000e+00 + 8 -1.4133104801408738e-01 -6.1685378954692482e-01 0.0000000000000000e+00 + 9 1.8219762821810317e-01 3.2009822401929577e-01 0.0000000000000000e+00 + 10 -5.1688860353236589e-02 1.1069131959908671e-01 0.0000000000000000e+00 + 11 -8.4689878918105269e-02 1.5099315110947911e-01 0.0000000000000000e+00 + 12 4.5754413540574290e-01 -4.2644798683690410e-01 0.0000000000000000e+00 + 13 -1.5596780753830558e-01 1.1607584778590280e-01 0.0000000000000000e+00 + 14 -1.7231427615749528e-01 1.3653099035839830e-01 0.0000000000000000e+00 + 15 -1.3787738509698347e-01 8.5569383216123673e-02 0.0000000000000000e+00 + 16 -3.4322564010548312e-01 4.3371633953160166e-01 0.0000000000000000e+00 + 17 1.3414272886699793e-01 -4.1322529572771644e-01 0.0000000000000000e+00 + 18 7.3073447759345089e-01 1.5456517688814524e+00 0.0000000000000000e+00 + 19 -2.5943625025418654e-01 -7.7424664728587522e-01 0.0000000000000000e+00 + 20 -3.9409193260988501e-01 -7.0311103001458264e-01 0.0000000000000000e+00 + 21 5.1856078926614546e-01 5.4286369838352699e-01 0.0000000000000000e+00 + 22 -2.9453203152655405e-01 -1.2298517567747463e-01 0.0000000000000000e+00 + 23 -2.8798525475710529e-01 -2.9277384277527774e-01 0.0000000000000000e+00 + 24 6.2753212217437501e-02 1.7443957830145815e+00 0.0000000000000000e+00 + 25 1.2986161832727383e-01 -7.0443921770565177e-01 0.0000000000000000e+00 + 26 -2.2254044464386455e-01 -9.7470640011041609e-01 0.0000000000000000e+00 + 27 -8.5917998510192983e-01 1.6512375326941557e+00 0.0000000000000000e+00 + 28 5.7118802253451917e-01 -9.1790362039827855e-01 0.0000000000000000e+00 + 29 4.1157232663919069e-01 -8.0588020505345637e-01 0.0000000000000000e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0954907726477938e-01 8.3266274086806424e-02 0.0000000000000000e+00 + 2 2.0332862442923574e-01 -2.8560926630911393e-01 0.0000000000000000e+00 + 3 -3.4180100439200709e-02 -9.1333128910097757e-03 0.0000000000000000e+00 + 4 1.6416273635882703e-01 2.7631304876496857e-02 0.0000000000000000e+00 + 5 1.5806172624970691e-01 7.5212624428037639e-02 0.0000000000000000e+00 + 6 5.5946099238073066e-01 4.1150228804962435e-01 0.0000000000000000e+00 + 7 -3.4292666609060812e-01 -4.0365422819208752e-01 0.0000000000000000e+00 + 8 -1.2935715162980371e-01 -6.1411220397702304e-01 0.0000000000000000e+00 + 9 1.7221009231114509e-01 3.1582795971570582e-01 0.0000000000000000e+00 + 10 -5.3316283432011259e-02 1.1167476867088882e-01 0.0000000000000000e+00 + 11 -8.6533198364341299e-02 1.5459024385220929e-01 0.0000000000000000e+00 + 12 4.6273802703029476e-01 -4.2648610299718331e-01 0.0000000000000000e+00 + 13 -1.5764223135321295e-01 1.1678705787372101e-01 0.0000000000000000e+00 + 14 -1.7361459296268739e-01 1.3770681956928760e-01 0.0000000000000000e+00 + 15 -1.3810098450786729e-01 8.4279550007386225e-02 0.0000000000000000e+00 + 16 -3.5440964031504807e-01 4.4019245309368626e-01 0.0000000000000000e+00 + 17 1.4352828836775777e-01 -4.0709487891749191e-01 0.0000000000000000e+00 + 18 7.7465198064383789e-01 1.6012407184552440e+00 0.0000000000000000e+00 + 19 -2.7124771942286441e-01 -7.9202301391814001e-01 0.0000000000000000e+00 + 20 -4.2073039292256903e-01 -7.3396062844822219e-01 0.0000000000000000e+00 + 21 5.2055303834890487e-01 4.5578891562948592e-01 0.0000000000000000e+00 + 22 -2.9112480004984048e-01 -8.0490171289320595e-02 0.0000000000000000e+00 + 23 -2.8874806785341345e-01 -2.5699483797836481e-01 0.0000000000000000e+00 + 24 7.6980429336623218e-02 1.6939065179875408e+00 0.0000000000000000e+00 + 25 1.1784596545050058e-01 -6.8182668665977952e-01 0.0000000000000000e+00 + 26 -2.2421345945684157e-01 -9.4803070477566309e-01 0.0000000000000000e+00 + 27 -8.6789609111614596e-01 1.6460227641663672e+00 0.0000000000000000e+00 + 28 5.7545985907402075e-01 -9.1143688682325297e-01 0.0000000000000000e+00 + 29 4.1460869719965082e-01 -8.0477733728583611e-01 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/kspace-pppm_slab.yaml b/unittest/force-styles/tests/kspace-pppm_slab.yaml new file mode 100644 index 0000000000..063d317582 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_slab.yaml @@ -0,0 +1,90 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:24:38 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace pppm +pre_commands: ! | + boundary p p f +post_commands: ! | + pair_modify compute no + kspace_style pppm 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab 3.0 +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.3380089109820561e-01 7.2155327343076003e-02 -6.4995839884901041e-01 + 2 2.2185875322484680e-01 -2.7128145328928288e-01 4.4430819530383792e-01 + 3 -3.4467324963324927e-02 -9.4865187299486200e-03 -1.6672239517974551e-02 + 4 1.6001651340716752e-01 2.9558378059627823e-02 8.5693214116608518e-02 + 5 1.6275100459619232e-01 7.6584006595777354e-02 1.2426528547390091e-01 + 6 5.6490439308440110e-01 4.1320657922974241e-01 2.7969819009892993e-01 + 7 -3.2367295633243265e-01 -3.8927137728925648e-01 -5.8776997741605808e-01 + 8 -1.5718470301667112e-01 -6.1033502770849668e-01 -5.4107853000878603e-01 + 9 2.0039925806920936e-01 3.1831970411992333e-01 6.2952234063424251e-01 + 10 -4.8738273906586992e-02 1.0865586922557076e-01 1.1775613894975115e-01 + 11 -8.2016811808923964e-02 1.4705711427078272e-01 1.3222050669232832e-01 + 12 4.4462097407419726e-01 -4.1918666631706625e-01 -4.8442606160131380e-01 + 13 -1.5093249187778054e-01 1.1313415612898116e-01 1.9846286553786163e-01 + 14 -1.6836223571387490e-01 1.3293343676637576e-01 1.8754446270275082e-01 + 15 -1.3379188301418798e-01 8.5032543358977100e-02 1.5811485446172857e-01 + 16 -3.1188777394243405e-01 4.1810936604072857e-01 1.4965062866755092e+00 + 17 8.5493835186739420e-02 -3.9854229885979447e-01 -1.7493312561847554e+00 + 18 6.9867589966244481e-01 1.4639420783061876e+00 -3.0965163500459525e+00 + 19 -2.6716338145739799e-01 -7.2846039701536602e-01 1.6650917698795229e+00 + 20 -3.5626553189229609e-01 -6.3995561812940094e-01 1.5756477837397369e+00 + 21 4.4025893611471584e-01 6.1567027909101457e-01 -2.6895268769090324e+00 + 22 -2.3889778528890587e-01 -1.7883117923219155e-01 1.3448477070501001e+00 + 23 -2.4658613617888409e-01 -3.2932960799757210e-01 1.3101915149971659e+00 + 24 -3.9382183770453862e-02 1.6979935777765853e+00 -1.9453129091460315e+00 + 25 1.8341768936664590e-01 -6.8620803816262377e-01 1.0348790372420780e+00 + 26 -1.8898331950766731e-01 -9.6045905422358080e-01 9.2263060162261723e-01 + 27 -8.8703295030819751e-01 1.6763273768328995e+00 -2.3730343634314357e+00 + 28 5.6447523083760187e-01 -9.2688575759254921e-01 1.2664350211061197e+00 + 29 4.4229414645406306e-01 -8.2044679859911973e-01 1.1598111868255623e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.1980382702370276e-01 7.3258075304451956e-02 -5.8884448723158389e-01 + 2 2.0758813947304111e-01 -2.7757108805185410e-01 4.0635600067945321e-01 + 3 -3.4162269342231516e-02 -9.2810719986610134e-03 -1.3960803397804172e-02 + 4 1.6111410168417928e-01 2.8178491439087572e-02 7.4872176103915430e-02 + 5 1.6027339196041890e-01 7.6270070662830550e-02 1.1158329890147675e-01 + 6 5.5824056669963773e-01 4.0698687751960405e-01 2.0526733430432356e-01 + 7 -3.2398437786476353e-01 -3.9262045586651578e-01 -5.2466373103793285e-01 + 8 -1.4349016762576552e-01 -6.0681600869661745e-01 -4.6778484753127247e-01 + 9 1.8943028615740204e-01 3.1355946051200367e-01 5.8202255534962255e-01 + 10 -5.0682328587717741e-02 1.0961451557690000e-01 1.0735294596712240e-01 + 11 -8.4288978483479590e-02 1.5072850462851256e-01 1.2088127897329901e-01 + 12 4.5076807790973977e-01 -4.1932945491541757e-01 -4.4219745743275551e-01 + 13 -1.5287203679376454e-01 1.1401561919320395e-01 1.8502790735060520e-01 + 14 -1.6998846314430652e-01 1.3415927884910950e-01 1.7537521527696448e-01 + 15 -1.3423922829745591e-01 8.3691443402437365e-02 1.4278856303472770e-01 + 16 -3.2526936190980171e-01 4.2408124226172134e-01 1.4337375304794979e+00 + 17 9.6846304115079843e-02 -3.9104740733329563e-01 -1.6848062309194085e+00 + 18 7.4425878177027538e-01 1.5227615755558004e+00 -2.9766061468893517e+00 + 19 -2.7858940546526562e-01 -7.4870903686235446e-01 1.6118351494098533e+00 + 20 -3.8413421032359651e-01 -6.7334443114621845e-01 1.5152763453466962e+00 + 21 4.4515061502690262e-01 5.2577042821115849e-01 -2.5732230168224519e+00 + 22 -2.3762513779500216e-01 -1.3400179724368511e-01 1.2909924316971939e+00 + 23 -2.4898516961698239e-01 -2.9194672275828559e-01 1.2530985642393218e+00 + 24 -2.6593815203818413e-02 1.6406769074122960e+00 -1.8544569335844177e+00 + 25 1.7083608172105313e-01 -6.6089022431384736e-01 9.8590534016646236e-01 + 26 -1.8834656537880107e-01 -9.2932512613827800e-01 8.7793044793919206e-01 + 27 -8.9324096844002610e-01 1.6739957225114674e+00 -2.2613266808654351e+00 + 28 5.6833293449309008e-01 -9.2164016708225627e-01 1.2078156319956979e+00 + 29 4.4345703028566219e-01 -8.2122522063329662e-01 1.0997516184969873e+00 +... diff --git a/unittest/force-styles/tests/kspace-pppm_stagger.yaml b/unittest/force-styles/tests/kspace-pppm_stagger.yaml new file mode 100644 index 0000000000..61df71617b --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_stagger.yaml @@ -0,0 +1,88 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:27:35 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace pppm/stagger +pre_commands: ! "" +post_commands: ! | + pair_modify compute no + kspace_style pppm/stagger 1.0e-6 + kspace_modify gewald 0.3 +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.2227715900845750e-01 8.1950519891037896e-02 2.1568864750376832e-01 + 2 2.1709329984201631e-01 -2.7910826043908610e-01 -1.3501796562404628e-01 + 3 -3.4431410110235108e-02 -9.3026609475793179e-03 1.9970153652663108e-02 + 4 1.6294612553322482e-01 2.8820208915782589e-02 -7.8041537992552090e-02 + 5 1.6018614143950777e-01 7.5432356753115826e-02 -3.7722588054429150e-02 + 6 5.6492988309033354e-01 4.1696814706534630e-01 -6.7673476362799612e-01 + 7 -3.4216205471660566e-01 -4.0009165524095192e-01 3.9325085501474977e-01 + 8 -1.4121658810415072e-01 -6.1694926607232958e-01 3.3967088097622000e-01 + 9 1.8213420211015810e-01 3.2023550501078568e-01 5.0865716213608053e-02 + 10 -5.1659753410710330e-02 1.1063713004312387e-01 -1.4434062323990951e-02 + 11 -8.4675426404111437e-02 1.5093767469541053e-01 -3.9273222694910556e-02 + 12 4.5743278086428246e-01 -4.2657803621344026e-01 3.4765791147615285e-02 + 13 -1.5598326968651899e-01 1.1609333380277490e-01 2.6827585674639255e-02 + 14 -1.7229830712699734e-01 1.3660265515995373e-01 1.0364293545061238e-02 + 15 -1.3779624948415931e-01 8.5611514314178239e-02 -1.4417936578185790e-02 + 16 -3.4309620718952316e-01 4.3358259515061448e-01 5.3264911488862143e-01 + 17 1.3394866253126306e-01 -4.1287506953147796e-01 -7.8819987038465467e-01 + 18 7.3032854805187175e-01 1.5459002190369358e+00 -1.3876618467094484e+00 + 19 -2.5946241349817661e-01 -7.7450328984918526e-01 7.7107291114413901e-01 + 20 -3.9364379163465191e-01 -7.0318115064463305e-01 7.3145133273582563e-01 + 21 5.1854207039779388e-01 5.4316140431986648e-01 -1.1630561612460866e+00 + 22 -2.9474924657955082e-01 -1.2314722330232061e-01 5.8311514555951505e-01 + 23 -2.8773056143507980e-01 -2.9281856868591627e-01 5.5619506923778372e-01 + 24 6.2752036539684239e-02 1.7441478631220706e+00 -2.7849000426516041e-01 + 25 1.2955239352175907e-01 -7.0427160638100861e-01 2.2582608971039136e-01 + 26 -2.2227598237037974e-01 -9.7470415379148345e-01 7.4514829391794934e-02 + 27 -8.5917766336431800e-01 1.6506499588643100e+00 -9.3704596621935576e-01 + 28 5.7091533654326099e-01 -9.1760299361767794e-01 5.4073727763352530e-01 + 29 4.1187460365847078e-01 -8.0559715142821642e-01 4.4313023169089372e-01 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0888488962950285e-01 8.3430404180325907e-02 2.3883070350075583e-01 + 2 2.0290231222263222e-01 -2.8552521628160221e-01 -1.4795322214007761e-01 + 3 -3.4147227596864727e-02 -9.1044423234983921e-03 2.1050772312966981e-02 + 4 1.6403639693437871e-01 2.7510909903057143e-02 -8.1700222473303191e-02 + 5 1.5793837855428028e-01 7.5134684921661865e-02 -4.3070400148934276e-02 + 6 5.5874989482134696e-01 4.1097082705147381e-01 -7.0880717747024347e-01 + 7 -3.4244419763693645e-01 -4.0336810330768602e-01 4.1416013762933518e-01 + 8 -1.2867011168103898e-01 -6.1360944335177758e-01 3.7373621646565264e-01 + 9 1.7179361391284365e-01 3.1570434896702448e-01 2.9166730933101400e-02 + 10 -5.3386439917058298e-02 1.1157104966535075e-01 -1.9069019877901452e-02 + 11 -8.6641568612711800e-02 1.5447778751280100e-01 -4.3302035139313286e-02 + 12 4.6277613291799979e-01 -4.2640261166652782e-01 5.4642934467963714e-02 + 13 -1.5768096764682599e-01 1.1678927823658505e-01 2.0726708870285715e-02 + 14 -1.7362409264878331e-01 1.3769878891777848e-01 5.6914483198930487e-03 + 15 -1.3804334923445472e-01 8.4232584350085404e-02 -2.2242211531143450e-02 + 16 -3.5505453326610353e-01 4.4007379281236625e-01 5.1108930583976653e-01 + 17 1.4393262437860022e-01 -4.0681625150263201e-01 -7.6550494257092949e-01 + 18 7.7411316765167837e-01 1.6013845677120058e+00 -1.3406161587038208e+00 + 19 -2.7109483507409249e-01 -7.9220736692047411e-01 7.5606765561780620e-01 + 20 -4.2022391372143653e-01 -7.3398564926630305e-01 7.0862056036484811e-01 + 21 5.2066744810063004e-01 4.5601151336785911e-01 -1.1109669200204870e+00 + 22 -2.9131419157235938e-01 -8.0660148622295896e-02 5.6037505807873789e-01 + 23 -2.8851937111607945e-01 -2.5707916023569388e-01 5.3115241105748146e-01 + 24 7.7132406285747662e-02 1.6936935947231240e+00 -2.6197671637095088e-01 + 25 1.1739827770831035e-01 -6.8172720908194795e-01 2.1292828073010400e-01 + 26 -2.2399952098390596e-01 -9.4806186651755442e-01 6.5237310702708273e-02 + 27 -8.6781949013350235e-01 1.6453631212617197e+00 -8.8867885380482659e-01 + 28 5.7526918079966904e-01 -9.1110567278710985e-01 5.1441520143469011e-01 + 29 4.1483886618353916e-01 -8.0439411171811659e-01 4.1599644392583446e-01 +... diff --git a/unittest/force-styles/tests/kspace-pppm_tip4p_nozforce.yaml b/unittest/force-styles/tests/kspace-pppm_tip4p_nozforce.yaml new file mode 100644 index 0000000000..a2fbf98742 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_tip4p_nozforce.yaml @@ -0,0 +1,92 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:30:43 202 +epsilon: 2e-13 +prerequisites: ! | + atom full + pair tip4p/long + kspace pppm/tip4p +pre_commands: ! | + variable newton_pair delete + variable newton_pair index on + boundary p p f +post_commands: ! | + pair_modify compute no + kspace_style pppm/tip4p 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab nozforce +input_file: in.fourmol +pair_style: tip4p/long 5 2 5 1 0.15 10.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.0659134677314954e-01 6.3236387648241049e-02 0.0000000000000000e+00 + 2 2.1133683960973745e-01 -2.6863101617815471e-01 0.0000000000000000e+00 + 3 -3.2007450377182521e-02 -8.5824787767274768e-03 0.0000000000000000e+00 + 4 1.6015900323129503e-01 2.0046662556320961e-02 0.0000000000000000e+00 + 5 1.4373116828850599e-01 6.8642461915548458e-02 0.0000000000000000e+00 + 6 4.5048678956625748e-01 4.3413340867398648e-01 0.0000000000000000e+00 + 7 -2.6428461189109337e-01 -4.1576174966615725e-01 0.0000000000000000e+00 + 8 1.1921051999659532e-02 -6.6503918133869055e-01 0.0000000000000000e+00 + 9 7.1395916732501286e-02 3.4478312678448186e-01 0.0000000000000000e+00 + 10 -7.2960414851980515e-02 1.2459882570790733e-01 0.0000000000000000e+00 + 11 -1.0864385068999977e-01 1.7076025996515692e-01 0.0000000000000000e+00 + 12 4.8652542445346686e-01 -4.7999566127101656e-01 0.0000000000000000e+00 + 13 -1.5505219503345941e-01 1.3668728881541059e-01 0.0000000000000000e+00 + 14 -1.7702961002752693e-01 1.4726459116336785e-01 0.0000000000000000e+00 + 15 -1.4813444730152320e-01 1.0169696956939388e-01 0.0000000000000000e+00 + 16 -4.8967391063528742e-01 5.2911039562682749e-01 0.0000000000000000e+00 + 17 2.9812723898590610e-01 -4.4985167893831207e-01 0.0000000000000000e+00 + 18 7.5295016829067707e-01 1.5809149798801962e+00 0.0000000000000000e+00 + 19 -2.6581236047254825e-01 -7.9371904002643301e-01 0.0000000000000000e+00 + 20 -4.0051255403603270e-01 -7.3079579085126212e-01 0.0000000000000000e+00 + 21 2.7191955094066944e-01 2.3592012427573444e-01 0.0000000000000000e+00 + 22 -1.5281287443492195e-01 1.7047539507905031e-02 0.0000000000000000e+00 + 23 -1.6433850795141611e-01 -1.6112835784404433e-01 0.0000000000000000e+00 + 24 1.6352022150194268e-01 1.0183892035491851e+00 0.0000000000000000e+00 + 25 9.7603553846683441e-02 -3.6007435676382482e-01 0.0000000000000000e+00 + 26 -2.5590716685041681e-01 -6.1961187252360139e-01 0.0000000000000000e+00 + 27 -5.8419070747836588e-01 8.8702468383613242e-01 0.0000000000000000e+00 + 28 4.3685554856863890e-01 -5.0281523811716922e-01 0.0000000000000000e+00 + 29 2.2141953278896287e-01 -4.2425048718040281e-01 0.0000000000000000e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -4.9283366697424219e-01 6.7509803271427735e-02 0.0000000000000000e+00 + 2 1.9729546519138016e-01 -2.7636937693778246e-01 0.0000000000000000e+00 + 3 -3.1764479665281724e-02 -8.3565189135967523e-03 0.0000000000000000e+00 + 4 1.6115065870137332e-01 1.8822872782323252e-02 0.0000000000000000e+00 + 5 1.4176429590430786e-01 6.8176243111408491e-02 0.0000000000000000e+00 + 6 4.4629743731897220e-01 4.2854923981812915e-01 0.0000000000000000e+00 + 7 -2.6520596143491332e-01 -4.2004918709246636e-01 0.0000000000000000e+00 + 8 2.1443830084821366e-02 -6.6185221349632251e-01 0.0000000000000000e+00 + 9 6.3353882717635993e-02 3.4000152174552384e-01 0.0000000000000000e+00 + 10 -7.4145873579962537e-02 1.2535995705540501e-01 0.0000000000000000e+00 + 11 -1.0997129715759803e-01 1.7388751392531543e-01 0.0000000000000000e+00 + 12 4.9122130074125170e-01 -4.7920873468718922e-01 0.0000000000000000e+00 + 13 -1.5656460878422412e-01 1.3686280506804901e-01 0.0000000000000000e+00 + 14 -1.7836956322523681e-01 1.4835007830468047e-01 0.0000000000000000e+00 + 15 -1.4837153768194108e-01 1.0017874975385921e-01 0.0000000000000000e+00 + 16 -4.9666159718867298e-01 5.3388893317928054e-01 0.0000000000000000e+00 + 17 3.0328295505737091e-01 -4.4489564059306502e-01 0.0000000000000000e+00 + 18 7.9599319663460444e-01 1.6331931351893643e+00 0.0000000000000000e+00 + 19 -2.7776782365391656e-01 -8.0990246877135663e-01 0.0000000000000000e+00 + 20 -4.2649788848127296e-01 -7.5958251159474921e-01 0.0000000000000000e+00 + 21 2.7391850612082885e-01 1.8476557598354837e-01 0.0000000000000000e+00 + 22 -1.5079422770362008e-01 4.2490216111271656e-02 0.0000000000000000e+00 + 23 -1.6541483158667528e-01 -1.4165127004594436e-01 0.0000000000000000e+00 + 24 1.7076915929729478e-01 9.9271765454153926e-01 0.0000000000000000e+00 + 25 8.7256141071843568e-02 -3.4913406699191918e-01 0.0000000000000000e+00 + 26 -2.5360473736671924e-01 -6.0469118519185039e-01 0.0000000000000000e+00 + 27 -5.8767102571338559e-01 8.8378784057344151e-01 0.0000000000000000e+00 + 28 4.3822292844883004e-01 -4.9861224527564257e-01 0.0000000000000000e+00 + 29 2.2366936290714734e-01 -4.2423672082268232e-01 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml b/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml new file mode 100644 index 0000000000..035267fa99 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_tip4p_slab.yaml @@ -0,0 +1,92 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:30:38 202 +epsilon: 2e-13 +prerequisites: ! | + atom full + pair tip4p/long + kspace pppm/tip4p +pre_commands: ! | + variable newton_pair delete + variable newton_pair index on + boundary p p f +post_commands: ! | + pair_modify compute no + kspace_style pppm/tip4p 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify slab 3.0 +input_file: in.fourmol +pair_style: tip4p/long 5 2 5 1 0.15 10.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.1875059319876482e-01 5.1660852898514097e-02 -5.7568746684221916e-01 + 2 2.1689992534273889e-01 -2.6058788219741147e-01 4.1798750467672274e-01 + 3 -3.2123603964927645e-02 -8.8740124548059782e-03 -1.3836110655816162e-02 + 4 1.5801256389492813e-01 2.1126659375654909e-02 7.8030101326860571e-02 + 5 1.4630529362834138e-01 7.0541031372980123e-02 1.0367534136208822e-01 + 6 4.5271336509733173e-01 4.3434073283904712e-01 1.9672609182540585e-01 + 7 -2.5202832073509374e-01 -4.0972860647817611e-01 -5.1025448731009770e-01 + 8 -2.7733728801934087e-03 -6.6285305944413486e-01 -4.2259182161309783e-01 + 9 8.7284510947996261e-02 3.4644067741232221e-01 5.2649415280028289e-01 + 10 -7.0358238250045405e-02 1.2324438068757468e-01 9.7430764543568638e-02 + 11 -1.0611397012429427e-01 1.6778028608628817e-01 1.0243492986761592e-01 + 12 4.7522165036946828e-01 -4.7569230861934814e-01 -3.7620104501978141e-01 + 13 -1.5084555220571103e-01 1.3477824777242514e-01 1.5530580320476042e-01 + 14 -1.7331931611645846e-01 1.4489217533438961e-01 1.5187450400216165e-01 + 15 -1.4457383479163205e-01 1.0191957555196750e-01 1.2647045003724980e-01 + 16 -4.6380086833284712e-01 5.1725747136642608e-01 1.3944164623658954e+00 + 17 2.5830539911922701e-01 -4.4001348824516739e-01 -1.6368568925682263e+00 + 18 7.1711828509507158e-01 1.5135594083235546e+00 -3.0000511375094279e+00 + 19 -2.6526242862377652e-01 -7.5615232036394919e-01 1.6174668711138471e+00 + 20 -3.6412116833354524e-01 -6.8003985707517800e-01 1.5219834320490606e+00 + 21 2.1913962201245335e-01 2.8436767546323427e-01 -1.5830999741451532e+00 + 22 -1.1342236771135741e-01 -2.1501547367331550e-02 8.1828468024256407e-01 + 23 -1.3904196539005109e-01 -1.8302644136991242e-01 7.6537752144201421e-01 + 24 9.9781913572244155e-02 9.7885535038983940e-01 -1.2668572125502537e+00 + 25 1.3435697022842072e-01 -3.4498868790162351e-01 6.9488200140438949e-01 + 26 -2.4062268840602163e-01 -6.1062269338471520e-01 5.8807795407966368e-01 + 27 -6.0379577180174060e-01 9.0922264678215248e-01 -1.6721200413729438e+00 + 28 4.2997465966368542e-01 -5.0965848067708741e-01 9.0674794598209418e-01 + 29 2.4583990189455251e-01 -4.3624778607752923e-01 7.9388967726077175e-01 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0354821726811139e-01 5.5967846131381935e-02 -5.1985966695336350e-01 + 2 2.0222486815064800e-01 -2.6827509138693428e-01 3.8174919658879292e-01 + 3 -3.1827569249092247e-02 -8.6118627137726084e-03 -1.1373445003762840e-02 + 4 1.5884510347610806e-01 1.9754860539942493e-02 6.8025846474256690e-02 + 5 1.4401187575283883e-01 6.9928630801443029e-02 9.2658665634254483e-02 + 6 4.4757511852983761e-01 4.2745385614446446e-01 1.2847050232720492e-01 + 7 -2.5262128248313159e-01 -4.1322519150847548e-01 -4.5142442746491723e-01 + 8 7.8668596525731087e-03 -6.5836225310240626e-01 -3.5751093292782843e-01 + 9 7.8606817422723047e-02 3.4074009853801468e-01 4.8592767822570571e-01 + 10 -7.1715830727829805e-02 1.2387945822813282e-01 8.8253410001734311e-02 + 11 -1.0768356090563561e-01 1.7087075095931867e-01 9.2378379692929419e-02 + 12 4.8042014088476770e-01 -4.7452461053388789e-01 -3.3912039294236951e-01 + 13 -1.5249102711632326e-01 1.3493433497263962e-01 1.4388497485065629e-01 + 14 -1.7486786117504285e-01 1.4592040512192123e-01 1.4102485981181104e-01 + 15 -1.4490740376759367e-01 1.0021404392401717e-01 1.1275703958375444e-01 + 16 -4.7182047286026119e-01 5.2091789992423199e-01 1.3402111830145120e+00 + 17 2.6451183057843936e-01 -4.3324675568171989e-01 -1.5822695555453863e+00 + 18 7.6153366131732314e-01 1.5679688830295708e+00 -2.8820913963693444e+00 + 19 -2.7709505739544776e-01 -7.7394339602668338e-01 1.5650790746108196e+00 + 20 -3.9117632343532288e-01 -7.1056069742775840e-01 1.4625309334873893e+00 + 21 2.2289308101459848e-01 2.3168859506651321e-01 -1.5087148284954559e+00 + 22 -1.1285725823795631e-01 5.2592648174756979e-03 7.8339690235084547e-01 + 23 -1.4106022560010598e-01 -1.6271731633631403e-01 7.2870145507787210e-01 + 24 1.0567507776161272e-01 9.4863518705455885e-01 -1.2119574136930193e+00 + 25 1.2332508864360726e-01 -3.3234902843161318e-01 6.6369683402887292e-01 + 26 -2.3610725689732170e-01 -5.9227409253955976e-01 5.6153342732297529e-01 + 27 -6.0550030290005896e-01 9.0785621304206510e-01 -1.6001786116251175e+00 + 28 4.3104584110072031e-01 -5.0620710007808045e-01 8.6898263429887912e-01 + 29 2.4674428573343818e-01 -4.3769293252848607e-01 7.5523767363729677e-01 +... From b21737574450e02b0432e3409f4a9a4e6a8e86c8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 3 Aug 2020 23:43:59 -0400 Subject: [PATCH 056/122] add tests with AD instead of IK --- .../force-styles/tests/kspace-pppm_ad.yaml | 89 +++++++++++++++++ .../force-styles/tests/kspace-pppm_cg_ad.yaml | 93 +++++++++++++++++ .../tests/kspace-pppm_disp_ad.yaml | 99 +++++++++++++++++++ 3 files changed, 281 insertions(+) create mode 100644 unittest/force-styles/tests/kspace-pppm_ad.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_cg_ad.yaml create mode 100644 unittest/force-styles/tests/kspace-pppm_disp_ad.yaml diff --git a/unittest/force-styles/tests/kspace-pppm_ad.yaml b/unittest/force-styles/tests/kspace-pppm_ad.yaml new file mode 100644 index 0000000000..2c86e3e09c --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_ad.yaml @@ -0,0 +1,89 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:41:05 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace pppm +pre_commands: ! "" +post_commands: ! | + pair_modify compute no + kspace_style pppm 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify diff ad +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.2190552483240504e-01 8.2215660125449910e-02 2.1562510687635308e-01 + 2 2.1688492922158006e-01 -2.7925754494210148e-01 -1.3475851711075856e-01 + 3 -3.4433780539372766e-02 -9.3080401397713161e-03 1.9946515121537497e-02 + 4 1.6298363144871159e-01 2.8852574995354187e-02 -7.7991973020595448e-02 + 5 1.6020080634095873e-01 7.5444652671782991e-02 -3.7755259818804385e-02 + 6 5.6477072987817123e-01 4.1662939458948800e-01 -6.7626554141135908e-01 + 7 -3.4225036495285266e-01 -3.9975321844717421e-01 3.9309446284614519e-01 + 8 -1.4147017312863627e-01 -6.1703403264688339e-01 3.3918069668674772e-01 + 9 1.8232198380374839e-01 3.2014912718177990e-01 5.0759587052937802e-02 + 10 -5.1657897166574047e-02 1.1069981259090211e-01 -1.4453578529580773e-02 + 11 -8.4673206429331058e-02 1.5094729097074927e-01 -3.9280952977654118e-02 + 12 4.5740376190440463e-01 -4.2661352934770252e-01 3.4598069576133893e-02 + 13 -1.5597055294038675e-01 1.1610500483923950e-01 2.6864655811928758e-02 + 14 -1.7227861422280979e-01 1.3657106446192188e-01 1.0362233925080433e-02 + 15 -1.3780327920314928e-01 8.5582114730635261e-02 -1.4351270198922383e-02 + 16 -3.4323156212151129e-01 4.3357019531694702e-01 5.3239325221806300e-01 + 17 1.3402214386771832e-01 -4.1305079865155553e-01 -7.8800470348767349e-01 + 18 7.3014951850334719e-01 1.5462800166860855e+00 -1.3880551411655564e+00 + 19 -2.5908782420113941e-01 -7.7455581497150594e-01 7.7125030861538357e-01 + 20 -3.9391369036316565e-01 -7.0342769415374096e-01 7.3132018323692538e-01 + 21 5.1910913958843041e-01 5.4313103019469455e-01 -1.1628229618860246e+00 + 22 -2.9473410777301406e-01 -1.2311564595211141e-01 5.8336226019074866e-01 + 23 -2.8782785670419653e-01 -2.9274193967355583e-01 5.5604399887687406e-01 + 24 6.2322817487943091e-02 1.7445317328698158e+00 -2.7815756488577065e-01 + 25 1.2981924994005456e-01 -7.0432397581382311e-01 2.2595768386921172e-01 + 26 -2.2236541834270865e-01 -9.7444382994819789e-01 7.4657003819541226e-02 + 27 -8.5888765373480247e-01 1.6510887259944620e+00 -9.3669589163422240e-01 + 28 5.7120372216050941e-01 -9.1801674838950753e-01 5.4086807462233377e-01 + 29 4.1158865003556910e-01 -8.0556698320749920e-01 4.4319718513097422e-01 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0851035689707347e-01 8.3696555043868248e-02 2.3876103578012289e-01 + 2 2.0269500296160084e-01 -2.8566084530493419e-01 -1.4768980230715259e-01 + 3 -3.4149549824842813e-02 -9.1096255360812017e-03 2.1027124878922020e-02 + 4 1.6407322665447230e-01 2.7543237880400185e-02 -8.1650381125245516e-02 + 5 1.5795307453619775e-01 7.5146642808884764e-02 -4.3102318836215306e-02 + 6 5.5858655824964387e-01 4.1062166071688444e-01 -7.0833320830121149e-01 + 7 -3.4252896722559306e-01 -4.0301916145464445e-01 4.1400582326311725e-01 + 8 -1.2891789242336010e-01 -6.1369656246734849e-01 3.7324458574304409e-01 + 9 1.7198056029026496e-01 3.1561822993733335e-01 2.9064184554255378e-02 + 10 -5.3384756870646026e-02 1.1163429145031226e-01 -1.9088184643301136e-02 + 11 -8.6639665929675702e-02 1.5448768096869939e-01 -4.3306360587871774e-02 + 12 4.6274725673167144e-01 -4.2644123215982821e-01 5.4479106601223251e-02 + 13 -1.5766900006413620e-01 1.1680271709764924e-01 2.0763662244827025e-02 + 14 -1.7360426441134205e-01 1.3767109040914424e-01 5.6888469695047074e-03 + 15 -1.3805221342682228e-01 8.4201012576434475e-02 -2.2177896561252766e-02 + 16 -3.5518996943169867e-01 4.4006867240492986e-01 5.1082655547890199e-01 + 17 1.4400857876322506e-01 -4.0699830909162821e-01 -7.6530886527820341e-01 + 18 7.7393165302423195e-01 1.6017507072615027e+00 -1.3409853624530406e+00 + 19 -2.7071818390746438e-01 -7.9223345352994712e-01 7.5621073676474493e-01 + 20 -4.2049840596814830e-01 -7.3420774282105383e-01 7.0848870900832073e-01 + 21 5.2122509312530685e-01 4.5597505930162413e-01 -1.1107261761660470e+00 + 22 -2.9128515790641207e-01 -8.0613672237653297e-02 5.6064446348032770e-01 + 23 -2.8861393156712373e-01 -2.5701868264885419e-01 5.3100694843604468e-01 + 24 7.6698855685783468e-02 1.6940933642215197e+00 -2.6162067912782094e-01 + 25 1.1767506627649887e-01 -6.8175455522281470e-01 2.1303383143101082e-01 + 26 -2.2407094233551839e-01 -9.4780669819062580e-01 6.5351553291355655e-02 + 27 -8.6753518072936853e-01 1.6458040748756146e+00 -8.8831962627355365e-01 + 28 5.7555739921439630e-01 -9.1151110474305508e-01 5.1452525143161265e-01 + 29 4.1455128111018325e-01 -8.0436495399115582e-01 4.1605616735204209e-01 +... diff --git a/unittest/force-styles/tests/kspace-pppm_cg_ad.yaml b/unittest/force-styles/tests/kspace-pppm_cg_ad.yaml new file mode 100644 index 0000000000..8a287554c3 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_cg_ad.yaml @@ -0,0 +1,93 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:43:09 202 +epsilon: 7.5e-14 +prerequisites: ! | + atom full + pair coul/long + kspace pppm/cg +pre_commands: ! "" +post_commands: ! | + set atom 22*23 charge 0.0 + set atom 25*26 charge 0.0 + set atom 28*29 charge 0.0 + set type 5 charge 0.0 + pair_modify compute no + kspace_style pppm/cg 1.0e-6 + kspace_modify gewald 0.3 + kspace_modify diff ad +input_file: in.fourmol +pair_style: coul/long 8.0 +pair_coeff: ! | + * * +extract: ! "" +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -2.6243178547330953e-01 6.3481415744192735e-02 2.5755647326324360e-01 + 2 7.2210306482009740e-02 -2.6365981923162723e-01 -7.6027292130687638e-02 + 3 -2.0410037459139996e-02 -7.8518193670713866e-03 1.6906150414195745e-02 + 4 1.3915939229173485e-01 2.2627880620035581e-03 -4.0378935516435163e-02 + 5 7.8194018232840473e-02 5.8018701824568544e-02 -6.0263079331701309e-02 + 6 1.6117380184714480e-02 5.4780294941511365e-01 -5.9899597328599008e-01 + 7 7.4101754686267826e-02 -5.2984781742029785e-01 2.8761020474946458e-01 + 8 5.1696693743970212e-01 -8.4212250878844264e-01 3.9221247456711178e-01 + 9 -2.8721021186708934e-01 3.8853963166022182e-01 -8.8596376680957767e-02 + 10 -1.4114521953136006e-01 1.7100290143827235e-01 -2.1016604342927257e-02 + 11 -1.9796849846116105e-01 2.3800148938029006e-01 -6.9177818209839537e-02 + 12 5.9813035207327492e-01 -6.6558955035566358e-01 1.8078261589424297e-01 + 13 -1.4431391318097339e-01 2.1118780974471676e-01 -3.8048223733437046e-02 + 14 -2.1061674466119099e-01 1.9831789008632270e-01 -4.3961390702224316e-02 + 15 -1.8504976371730819e-01 1.4558081062791889e-01 -6.3685012045141168e-02 + 16 -8.7051562745567046e-01 8.0821464233176477e-01 7.4012194259013098e-01 + 17 6.8535736961229954e-01 -5.4356979603996858e-01 -9.1540971121486203e-01 + 18 9.0628015391123562e-01 1.6156882887934720e+00 -1.6719002721702105e+00 + 19 -3.2803933630115273e-01 -8.1632886577080033e-01 9.6629656175889733e-01 + 20 -4.4051767499796984e-01 -7.7815834293134811e-01 8.4540747288240947e-01 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -2.5238704269472467e-01 7.8109211236903411e-02 2.7457188012725731e-01 + 2 6.0166369258509753e-02 -2.7716302738274262e-01 -9.2325064750280558e-02 + 3 -2.0385750922143300e-02 -7.4115877582968974e-03 1.7722890079036057e-02 + 4 1.4010060016714171e-01 6.0554873231484431e-04 -4.4104260665722553e-02 + 5 7.7634465932595223e-02 5.6659926777584954e-02 -6.2492580122084383e-02 + 6 1.7944902202958236e-02 5.4047287556800272e-01 -6.2633356849966371e-01 + 7 7.0852335155610874e-02 -5.3347310633932465e-01 3.1198393100321459e-01 + 8 5.1912517816057102e-01 -8.3998158661101896e-01 4.1406757404703964e-01 + 9 -2.8949000164711225e-01 3.8553253341622445e-01 -9.6305549372637009e-02 + 10 -1.4125869237555647e-01 1.7153881404366969e-01 -2.4242770071896243e-02 + 11 -1.9815473720125482e-01 2.3999400069516061e-01 -7.2815946513521052e-02 + 12 6.0163746584149269e-01 -6.6340909699241479e-01 1.9267169670190931e-01 + 13 -1.4511305617362821e-01 2.1000483109499868e-01 -4.0927860608506568e-02 + 14 -2.1225498826978989e-01 1.9909434532945869e-01 -4.7459613845167378e-02 + 15 -1.8579004711594502e-01 1.4355184618295208e-01 -6.8567243355705687e-02 + 16 -8.6801454850825788e-01 8.1287960974078244e-01 7.2658360126751365e-01 + 17 6.8293240110629350e-01 -5.4626838358807861e-01 -9.0618127747183086e-01 + 18 9.4712184031094371e-01 1.6607763074495554e+00 -1.6014316953147449e+00 + 19 -3.4093603676695722e-01 -8.2820215278068332e-01 9.3655513006566982e-01 + 20 -4.6542073867597039e-01 -8.0237046056720795e-01 8.0842931457880551e-01 + 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 25 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 26 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 27 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 28 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 29 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +... diff --git a/unittest/force-styles/tests/kspace-pppm_disp_ad.yaml b/unittest/force-styles/tests/kspace-pppm_disp_ad.yaml new file mode 100644 index 0000000000..2a0ebb1a32 --- /dev/null +++ b/unittest/force-styles/tests/kspace-pppm_disp_ad.yaml @@ -0,0 +1,99 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Mon Aug 3 23:45:21 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + pair lj/long/coul/long + kspace pppm/disp +pre_commands: ! "" +post_commands: ! | + pair_modify compute no + kspace_style pppm/disp 1.0e-5 + kspace_modify gewald 0.3 + kspace_modify force/disp/real 0.001 + kspace_modify force/disp/kspace 0.005 + kspace_modify diff ad +input_file: in.fourmol +pair_style: lj/long/coul/long long long 8.0 +pair_coeff: ! | + 1 1 0.02 2.5 + 2 2 0.005 1.0 + 2 4 0.005 0.5 + 3 3 0.02 3.2 + 4 4 0.015 3.1 + 5 5 0.015 3.1 +extract: ! | + epsilon 2 + sigma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 0 +init_coul: 0 +init_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +init_forces: ! |2 + 1 -5.2063665240580304e-01 8.3117174771044994e-02 2.1710553061105919e-01 + 2 2.1601827260236847e-01 -2.8016528049927236e-01 -1.3591952614670588e-01 + 3 -3.4432215176582161e-02 -9.2969634192587840e-03 1.9961232370677446e-02 + 4 1.6306726209806033e-01 2.8786549069047165e-02 -7.8208050743167903e-02 + 5 1.6009445181310883e-01 7.5390408181996160e-02 -3.8094767180636785e-02 + 6 5.6298151562100762e-01 4.1542447598654658e-01 -6.7791198174917133e-01 + 7 -3.4300451974980500e-01 -3.9964506991054849e-01 3.9320824352606026e-01 + 8 -1.4142515692900004e-01 -6.1660561002020808e-01 3.3900672595857140e-01 + 9 1.8213225561965096e-01 3.2051754859596393e-01 4.8853859046917199e-02 + 10 -5.1723639442303203e-02 1.1066301783222390e-01 -1.4630807761208302e-02 + 11 -8.4678058369544423e-02 1.5112790273586052e-01 -3.8738044897580211e-02 + 12 4.5699904505903677e-01 -4.2669026930667636e-01 3.4269645808188268e-02 + 13 -1.5598835969251931e-01 1.1631509525063176e-01 2.7153412789879639e-02 + 14 -1.7221337203050516e-01 1.3669712677783563e-01 1.0369878812339910e-02 + 15 -1.3782779344391230e-01 8.5593474649625828e-02 -1.4720273031405258e-02 + 16 -3.4369316088907587e-01 4.3346685868907336e-01 5.3236256256457959e-01 + 17 1.3538278753205454e-01 -4.1462545726541405e-01 -7.8796138998558574e-01 + 18 7.3415233880806918e-01 1.5438361926483080e+00 -1.3966000629331021e+00 + 19 -2.6063767988527092e-01 -7.7482774729450687e-01 7.7091062731972437e-01 + 20 -3.9385562601055984e-01 -7.0172487075387224e-01 7.3370273486582926e-01 + 21 5.1733050331473385e-01 5.4559610538894554e-01 -1.1689506336009874e+00 + 22 -2.9387190573339306e-01 -1.2189007494364081e-01 5.8134095059864566e-01 + 23 -2.8706798326024441e-01 -2.9348783341522749e-01 5.5777413375150087e-01 + 24 6.6457368022480215e-02 1.7439494242325981e+00 -2.7726651502712907e-01 + 25 1.2870877789543181e-01 -7.0262682838938462e-01 2.2742569486907904e-01 + 26 -2.2250574243712537e-01 -9.7585470988712553e-01 7.4660935648110785e-02 + 27 -8.5844122383306787e-01 1.6509125140839234e+00 -9.3102293070927045e-01 + 28 5.7189426742634641e-01 -9.1541730629929896e-01 5.3936973405364341e-01 + 29 4.1117277680741127e-01 -8.0575703425866285e-01 4.4334214960702872e-01 +run_vdwl: 0 +run_coul: 0 +run_stress: ! |2- + 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 +run_forces: ! |2 + 1 -5.0724598451125813e-01 8.4605906369026526e-02 2.4023539149455228e-01 + 2 2.0183966461590086e-01 -2.8652609887043412e-01 -1.4881116802703487e-01 + 3 -3.4147445391883309e-02 -9.0985418694004179e-03 2.1042515097089792e-02 + 4 1.6416134037391608e-01 2.7477073712338231e-02 -8.1855695266502687e-02 + 5 1.5784365489264773e-01 7.5090836947964298e-02 -4.3440014022451554e-02 + 6 5.5681646945073815e-01 4.0940181912948942e-01 -7.1003391670312455e-01 + 7 -3.4329815357999571e-01 -4.0290748897004808e-01 4.1415876123613821e-01 + 8 -1.2888712765002303e-01 -6.1329574858632774e-01 3.7309574020498021e-01 + 9 1.7178353039292121e-01 3.1601173898527257e-01 2.7141518403095730e-02 + 10 -5.3449155548040729e-02 1.1159998980917359e-01 -1.9268569826734024e-02 + 11 -8.6642220167132120e-02 1.5467188146362182e-01 -4.2774265441850812e-02 + 12 4.6235239432856173e-01 -4.2652828743106036e-01 5.4131651032430401e-02 + 13 -1.5768561343589776e-01 1.1701385898496135e-01 2.1050787714544144e-02 + 14 -1.7354096508181352e-01 1.3780484347028346e-01 5.7024298471180790e-03 + 15 -1.3806854613337141e-01 8.4207238294398579e-02 -2.2556652594670781e-02 + 16 -3.5565033729310813e-01 4.3996598309257018e-01 5.1071457472743487e-01 + 17 1.4535098395259033e-01 -4.0858029554870284e-01 -7.6531543239893896e-01 + 18 7.7795133365898461e-01 1.5992575494701202e+00 -1.3495042526783001e+00 + 19 -2.7225702249513323e-01 -7.9245427732289586e-01 7.5607852632115080e-01 + 20 -4.2043594981468596e-01 -7.3261035203161751e-01 7.1087835856347847e-01 + 21 5.1948646341798976e-01 4.5851140631741866e-01 -1.1167896092963290e+00 + 22 -2.9052480659030144e-01 -7.9491449232363828e-02 5.5868278913981273e-01 + 23 -2.8785397967498427e-01 -2.5762428267824639e-01 5.3272370781608880e-01 + 24 8.0806567629280387e-02 1.6935240826607170e+00 -2.6086970148264382e-01 + 25 1.1647619572965967e-01 -6.8024758153127540e-01 2.1445540659082424e-01 + 26 -2.2418447745919995e-01 -9.4911802200180651e-01 6.5472960110187495e-02 + 27 -8.6711854896855400e-01 1.6456499265079672e+00 -8.8271588128156575e-01 + 28 5.7625556131334965e-01 -9.0893365323015285e-01 5.1303862930349953e-01 + 29 4.1417479755849967e-01 -8.0454472919014908e-01 4.1621524549683497e-01 +... From f407db6198b2c6b7d7fb76e1c6961f42433194a3 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Aug 2020 00:11:14 -0400 Subject: [PATCH 057/122] add test for lj/cut/tip4p/cut --- .../tests/mol-pair-lj_cut_tip4p_cut.yaml | 95 +++++++++++++++++++ .../tests/mol-pair-lj_cut_tip4p_long.yaml | 1 + .../tests/mol-pair-lj_cut_tip4p_table.yaml | 1 + 3 files changed, 97 insertions(+) create mode 100644 unittest/force-styles/tests/mol-pair-lj_cut_tip4p_cut.yaml diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_cut.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_cut.yaml new file mode 100644 index 0000000000..3c550f4a7d --- /dev/null +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_cut.yaml @@ -0,0 +1,95 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 00:08:57 202 +epsilon: 1e-13 +prerequisites: ! | + atom full + pair lj/cut/tip4p/cut +pre_commands: ! | + variable newton_pair delete + variable newton_pair index on +post_commands: ! | + pair_modify mix arithmetic +input_file: in.fourmol +pair_style: lj/cut/tip4p/cut 5 2 5 1 0.15 10.0 +pair_coeff: ! | + 1 1 0.02 2.5 + 2 2 0.0 1.0 + 2 4 0.005 0.5 + 3 3 0.02 3.2 + 4 4 0.015 3.1 + 5 5 0.015 3.1 +extract: ! | + epsilon 2 + sigma 2 + cut_coul 0 +natoms: 29 +init_vdwl: 584.670383161597 +init_coul: -128.977932168035 +init_stress: ! |2- + 1.4231788668968429e+03 1.6927574767724261e+03 3.8078398168257504e+03 -1.0764787790650696e+03 -2.0803003943962983e+02 7.2362441321593531e+02 +init_forces: ! |2 + 1 1.3685076237497921e+02 3.9938821720012220e+02 1.4670208005238968e+02 + 2 9.0831848103278351e-02 -3.3313499027414042e+00 -1.2979093715118299e+00 + 3 -1.4545919698213564e+02 -3.8860035342587304e+02 -1.3922529274243627e+02 + 4 2.0451930122273901e-01 1.9998707505206059e-01 -1.9241529187480502e-01 + 5 -4.0641917540788286e-01 6.8305809252357585e-01 -8.1657240858196867e-02 + 6 -8.3005254010483441e+02 9.6027302935298758e+02 1.1479396193868151e+03 + 7 5.7965799397930574e+01 -3.3542576215961554e+02 -1.7140610309344002e+03 + 8 2.2225178154228578e+02 -1.9967111112394331e+01 7.5267414307456966e+02 + 9 1.6389055151637297e+00 -5.6390633543953870e+00 1.5311382036446766e+00 + 10 5.2847373884576496e+02 -6.1581374394089164e+02 -1.9338541651113385e+02 + 11 -1.0650139622803310e+00 1.3236640560743722e+00 -5.2793717146291574e-01 + 12 2.5409781942525186e+01 1.5668165489039685e+01 -1.2455369942020832e+01 + 13 -3.8402453550913235e-01 1.8207125947890837e-01 -1.7705990497731289e-01 + 14 -1.2512809595558640e+00 5.7459561642481449e-01 -2.8979110225243121e-01 + 15 2.0365418860293560e-01 -1.2414160528552476e-01 -9.9240093291718068e-01 + 16 4.6129519562627820e+02 -3.2953707101679004e+02 -1.1861891151002549e+03 + 17 -4.5520722245183856e+02 3.2122612632014523e+02 1.1988324451177598e+03 + 18 1.0743707732075643e-01 4.7708085939928919e+00 -8.4413424342163204e+00 + 19 1.7141655109952687e+00 -1.6053719639650721e+00 6.5795299293212599e+00 + 20 -3.3084525007896382e+00 -5.6180547380703150e+00 4.8413072040789036e+00 + 21 9.3280739780820443e-01 3.1537173825438378e+00 -7.8568349917788334e+00 + 22 3.7050652612958657e+00 1.4003826804296502e+00 5.0400300091900805e+00 + 23 -6.8171671139915162e+00 -4.4579919295941908e+00 2.3028567081889286e+00 + 24 -8.7255143168850235e-01 7.8448375432859114e+00 -3.8112987366481188e+00 + 25 5.0290773121564376e+00 -9.4339583438843400e-01 4.1845154167803242e+00 + 26 -4.6561811432502953e+00 -7.1621093380192180e+00 -6.6864416050653208e-01 + 27 -1.0468877328824875e+00 9.2905066770498319e+00 -3.6991349617673341e+00 + 28 8.5365856050054738e+00 -2.4636423220451302e+00 4.2276358718634395e+00 + 29 -3.8831706532739356e+00 -5.2900046950811053e+00 -1.5026494435836046e+00 +run_vdwl: 102.201551627136 +run_coul: -113.741038555643 +run_stress: ! |2- + 4.0014600129344200e+02 4.7040479159512131e+02 2.6187982187362940e+02 -3.3090359512659597e+02 -8.0167395608208707e+01 1.2621079474133124e+02 +run_forces: ! |2 + 1 3.1753236607870527e+01 8.3621965560621064e+01 3.0316315705469126e+01 + 2 1.4286521816346817e-01 -2.2824033053781676e+00 -7.5551028598716607e-01 + 3 -2.3574844485150459e+02 9.7602108049923189e+01 8.4388085098137793e+01 + 4 -8.8996147506143097e-02 3.2157993972313093e-01 -2.6834896820998838e-01 + 5 -5.1176916574565534e-01 6.2243255603457825e-01 3.0305994432614902e-01 + 6 1.0988105846786355e+02 -9.6340673534605699e+01 -1.2877648279860219e+02 + 7 4.4591402242519891e+00 -1.1562262283680836e+01 -3.8449891020868478e+01 + 8 -1.8500965167232737e+00 3.2142650056503392e+01 1.0393367138995389e+02 + 9 1.6031489636542831e+00 -6.7043927734105306e+00 9.3597428383141301e-01 + 10 3.9843477308596469e+01 -6.6883715988133289e+01 -8.8591575899663255e+01 + 11 -1.2251023797384710e+00 1.4050643967343674e+00 -8.2053525232354940e-01 + 12 2.1038151524680664e+01 1.6333275303649856e+01 -1.0224098598118850e+01 + 13 -3.5460666553890013e-01 3.4985635732495085e-01 -2.8587446855444615e-01 + 14 -1.5532009832170448e+00 6.6724072634342102e-01 -4.7736439663808239e-01 + 15 1.8618156771424255e-01 -1.8742423255956700e-01 -1.0508719656263246e+00 + 16 5.0203980325375476e+01 -6.4427827617601864e+01 1.3348341161221096e+01 + 17 -1.7324426977223428e+01 1.5943360667512028e+01 3.6242060039458565e+01 + 18 -5.1241102539663741e-01 4.6504778154450488e+00 -7.5635987942225089e+00 + 19 2.1299065183839345e+00 -1.7007859776984058e+00 6.5142740712969927e+00 + 20 -3.2615904151011352e+00 -5.6090817211786161e+00 4.2429891830803017e+00 + 21 8.0725664470101466e-01 3.0937836217001409e+00 -7.2913744396245024e+00 + 22 3.9626147738858628e+00 1.5703953178352748e+00 4.8509809061089939e+00 + 23 -7.0701622215717324e+00 -4.4624511069210673e+00 2.0542173473160599e+00 + 24 -9.5073882777578100e-01 8.5254907477746880e+00 -5.0322651147010440e+00 + 25 5.5723193594212104e+00 -7.0640302764433882e-01 4.4527213493097140e+00 + 26 -4.8649545576039950e+00 -7.4562686931111752e+00 -1.0189291230630704e+00 + 27 -1.5560829938132452e+00 9.3812896556818455e+00 -3.7919414490477714e+00 + 28 8.9221125088199820e+00 -2.5727956403610084e+00 4.4191995401320501e+00 + 29 -3.6328662849226316e+00 -5.3344848705224015e+00 -1.6032274443909087e+00 +... diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml index 5843fceb67..7b334554b3 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_long.yaml @@ -5,6 +5,7 @@ epsilon: 1e-13 prerequisites: ! | atom full pair lj/cut/tip4p/long + kspace pppm/tip4p pre_commands: ! | variable newton_pair delete variable newton_pair index on diff --git a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_table.yaml b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_table.yaml index e422b1bd1c..cab2e7c3c1 100644 --- a/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_table.yaml +++ b/unittest/force-styles/tests/mol-pair-lj_cut_tip4p_table.yaml @@ -5,6 +5,7 @@ epsilon: 5e-13 prerequisites: ! | atom full pair lj/cut/tip4p/long + kspace pppm/tip4p pre_commands: ! | variable newton_pair delete variable newton_pair index on From eed71135066537305b98982301e4b97b02b406ab Mon Sep 17 00:00:00 2001 From: abhishandy Date: Tue, 4 Aug 2020 01:57:23 -0400 Subject: [PATCH 058/122] tests for fene, fene/expand --- unittest/force-styles/tests/bond-fene.yaml | 89 +++++++++++++++++++ .../force-styles/tests/bond-fene_expand.yaml | 87 ++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 unittest/force-styles/tests/bond-fene.yaml create mode 100644 unittest/force-styles/tests/bond-fene_expand.yaml diff --git a/unittest/force-styles/tests/bond-fene.yaml b/unittest/force-styles/tests/bond-fene.yaml new file mode 100644 index 0000000000..8084639b57 --- /dev/null +++ b/unittest/force-styles/tests/bond-fene.yaml @@ -0,0 +1,89 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 01:02:57 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + bond fene +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +bond_style: fene +bond_coeff: ! | + 1 250 3 0.022 1.5 + 2 300 2.2 0.005 1.1 + 3 350 2.6 0.022 1.3 + 4 650 2.4 0.015 1.2 + 5 450 2 0.018 1 +equilibrium: 5 1.455 1.067 1.261 1.164 0.97 +extract: ! | + kappa 1 + r0 1 +natoms: 29 +init_energy: 7104.90048646724 +init_stress: ! |- + -4.9948251498286945e+03 -4.7340263125122983e+03 -6.8013808554851912e+03 -2.4245897042972433e+02 -6.6838292208179359e+02 -4.4352973682370884e+02 +init_forces: ! |2 + 1 1.5227919896222070e+02 -3.0529148584155752e+02 -6.3433757085556704e+02 + 2 -3.5333212194097899e+02 -2.9076506256617409e+02 4.1586183920727922e+02 + 3 1.0548620599418425e+02 2.2401883218533629e+02 1.4601385800824934e+02 + 4 3.5529689728963973e+02 -9.9603814743905076e+01 2.5209226476030145e+02 + 5 7.9696321149555558e+01 1.2247168409058740e+02 -4.0693965981450441e+02 + 6 1.0156075873076483e+02 -1.8365313608907709e+02 -5.1600872665290922e+02 + 7 -3.9992946369286209e+01 2.0513600565491416e+02 1.0234223464258143e+03 + 8 1.2657095794694379e+02 2.3239830998331399e+01 1.4918069506630005e+02 + 9 -1.2774905058939335e+02 -1.3759356528861915e+02 -5.6533381886943391e+02 + 10 5.3103772000875210e+01 2.0657439846843420e+02 -1.1013675426805511e+02 + 11 9.0033181313434426e+01 2.2302015951970537e+02 3.6593115492799160e+02 + 12 -7.9635294863700679e+01 -2.2570363606274100e+01 -5.6505670790779703e+01 + 13 -4.2188119294251698e+02 1.6689184252144125e+02 7.9292867795856647e+00 + 14 1.6122460170616077e+02 -3.2807068730473944e+01 4.1810732482274386e+02 + 15 1.1075486503536453e+01 -4.2557143575117459e+02 -1.5165859011579349e+02 + 16 -5.8426910673782959e+02 5.8489645259934196e+02 6.4541575932130058e+02 + 17 3.7053233184639009e+02 -2.5839327342083652e+02 -9.8303373795252321e+02 + 18 8.8468045396808748e+00 1.6544767458407111e+02 -6.9977416747130690e+02 + 19 3.6787485473148814e+02 2.3534638924853024e+02 4.4566956860384897e+02 + 20 -3.7672165927116902e+02 -4.0079406383260135e+02 2.5410459886745790e+02 + 21 1.7516048660156611e+02 2.2119569760719207e+02 -6.6542077353469892e+02 + 22 3.2434577178814351e+02 7.8602128234402713e+01 5.0886237049122559e+02 + 23 -4.9950625838970961e+02 -2.9979782584159477e+02 1.5655840304347336e+02 + 24 -1.5673836242352741e+02 5.9154321746725043e+02 -3.5572196180021797e+02 + 25 4.6452174308266660e+02 -7.4781269439732029e+01 3.9051471040056515e+02 + 26 -3.0778338065913920e+02 -5.1676194802751843e+02 -3.4792748600347160e+01 + 27 -7.4105937747798123e+01 6.5722929360523858e+02 -2.2054278458154329e+02 + 28 4.6683896868291521e+02 -2.0062608322401542e+02 3.1586777609755433e+02 + 29 -3.9273303093511709e+02 -4.5660321038122316e+02 -9.5324991516011053e+01 +run_energy: 5895.10592527992 +run_stress: ! |2- + 1.1088505355432175e+04 3.5546088807250653e+03 3.2557814341123790e+03 7.2697015624401502e+03 5.4631672295275903e+03 1.4581760347047191e+03 +run_forces: ! |2 + 1 -1.8918162240225552e+03 -2.4388259927986478e+03 1.2428342729121759e+03 + 2 1.7096002197927919e+03 1.9511234141048665e+03 -1.3725721715298373e+03 + 3 2.7313834789169664e+02 3.5422765758244850e+01 -1.1094964910147857e+02 + 4 2.1401194399739109e+02 -3.6777103788174806e+01 1.5669227887798993e+02 + 5 5.3629985194030354e+01 8.1439316351700484e+01 -2.0956985423585593e+02 + 6 6.2674742087151415e+01 -2.5967590880066624e+01 1.7984763969593359e+01 + 7 -9.5248521397931647e+00 1.1551743847716996e+02 6.2378465431559289e+02 + 8 -3.8149362366999259e+02 -5.1575575737774238e+02 -2.3534731433259367e+03 + 9 3.5568858489555208e+02 4.2994067924873264e+02 1.8565803434051006e+03 + 10 2.4500352533964872e+01 2.3865414593146343e+02 1.3571152956401585e+02 + 11 5.5954132376702262e+01 1.4656975631105090e+02 2.0410359108303498e+02 + 12 -1.4338526173170575e+02 -1.1459273840299397e+02 7.7668777386394311e+01 + 13 -2.4673916116616911e+02 8.4546345963916679e+01 1.0436889165915075e+00 + 14 7.8938191353083695e+01 -1.6856068960303688e+01 2.2141061403549966e+02 + 15 4.3611789176560203e+00 -2.3298539886534661e+02 -9.0757103956575861e+01 + 16 -2.8107598012312189e+02 3.5792138783125625e+02 6.5665942155710695e+01 + 17 1.2153742381331742e+02 -5.9374598905125616e+01 -4.6615853447201522e+02 + 18 1.3993981705833403e+03 5.1766795224034945e+02 3.4778975684492984e+03 + 19 -3.4385661364340335e+03 -2.5545468247867943e+03 -2.8293267196853612e+03 + 20 2.0391679658506932e+03 2.0368788725464449e+03 -6.4857084876393731e+02 + 21 -1.4666708084950656e+03 -1.3837988607988614e+03 4.2478287232452421e+03 + 22 -3.7136423340535798e+03 -1.2988077068535936e+03 -3.8937522841854202e+03 + 23 5.1803131425486454e+03 2.6826065676524549e+03 -3.5407643905982195e+02 + 24 1.6167688018980316e+03 -4.2244379331940263e+03 2.8509543001632555e+03 + 25 -5.4920460574729777e+03 -5.7767130079019933e+02 -4.1476257918441115e+03 + 26 3.8752772555749461e+03 4.8021092339842253e+03 1.2966714916808558e+03 + 27 7.6070725632903213e+02 -4.2646888736392593e+03 1.3495821840825786e+03 + 28 -4.7134055707433517e+03 8.7271793467099371e+02 -2.7949802044610983e+03 + 29 3.9526983144143196e+03 3.3919709389682653e+03 1.4453980203785197e+03 +... diff --git a/unittest/force-styles/tests/bond-fene_expand.yaml b/unittest/force-styles/tests/bond-fene_expand.yaml new file mode 100644 index 0000000000..c1c1897ea6 --- /dev/null +++ b/unittest/force-styles/tests/bond-fene_expand.yaml @@ -0,0 +1,87 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 01:30:26 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + bond fene/expand +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +bond_style: fene/expand +bond_coeff: ! | + 1 250 3 0.022 1.5 0.1 + 2 300 2.2 0.005 1.1 0.05 + 3 350 2.6 0.022 1.3 0.06 + 4 650 2.4 0.015 1.2 0.15 + 5 450 2 0.018 1 0.09 +equilibrium: 5 1.555 1.117 1.321 1.314 1.06 +extract: ! "" +natoms: 29 +init_energy: 5926.02085912429 +init_stress: ! |- + -4.4174665507749878e+03 -4.2320578947897247e+03 -5.8644836994169109e+03 -1.6285898653137428e+02 -6.2814567943242105e+02 -3.6789143362234518e+02 +init_forces: ! |2 + 1 1.1734049764139522e+02 -3.0190531876638829e+02 -5.5924886655475916e+02 + 2 -3.0338793892892926e+02 -2.4966485515072475e+02 3.5707895897833311e+02 + 3 8.6337765803746919e+01 2.1824885827384793e+02 1.4243576569530256e+02 + 4 3.2928631926522041e+02 -9.2312017898254155e+01 2.3363709227801814e+02 + 5 7.3853610106887004e+01 1.1349301793976872e+02 -3.7710602621884311e+02 + 6 9.9755387154140266e+01 -1.5692886435416480e+02 -3.6617373010647697e+02 + 7 -3.2371902307081911e+01 1.6604534893247492e+02 8.2839928600070050e+02 + 8 1.0863225890716882e+02 1.2059236672467080e+01 9.9915298260117481e+01 + 9 -1.0955181209668024e+02 -1.1799402297446608e+02 -4.8480473248875199e+02 + 10 3.1792583111935983e+01 1.9105821312376960e+02 -1.0617603979013819e+02 + 11 8.3437406033160357e+01 2.0668184031667889e+02 3.3912326442866924e+02 + 12 -6.2798497540802188e+01 -1.0419127297857926e+01 -5.9651645366487685e+01 + 13 -3.9100175614142086e+02 1.5467625626168228e+02 7.3489055867664232e+00 + 14 1.4942282071021322e+02 -3.0405562780521535e+01 3.8750150518888478e+02 + 15 1.0264803381927134e+01 -3.9442123933385597e+02 -1.4055776314853728e+02 + 16 -4.9125994576900973e+02 5.0116852701296921e+02 4.9484702172230777e+02 + 17 3.0024840066812880e+02 -2.0938028997742512e+02 -7.9656829446510562e+02 + 18 7.3299985851217571e+00 1.4180715212492288e+02 -6.0080966628840451e+02 + 19 3.1594372314945184e+02 2.0212366649314311e+02 3.8275652980382358e+02 + 20 -3.2327372173457360e+02 -3.4393081861806598e+02 2.1805313648458096e+02 + 21 1.5020092270899937e+02 1.8976271005915342e+02 -5.7105575222002676e+02 + 22 2.7836938453072452e+02 6.7460185896018544e+01 4.3673054254276570e+02 + 23 -4.2857030723972389e+02 -2.5722289595517196e+02 1.3432520967726109e+02 + 24 -1.3467334054508910e+02 5.0754541726570164e+02 -3.0535902364924596e+02 + 25 3.9873542407199579e+02 -6.4190625361937720e+01 3.3520938680842625e+02 + 26 -2.6406208352690669e+02 -4.4335479190376390e+02 -2.9850363159180311e+01 + 27 -6.3329315340599010e+01 5.6398417998805996e+02 -1.8910602077885551e+02 + 28 4.0041383936090841e+02 -1.7207959413995059e+02 2.7092388905417050e+02 + 29 -3.3708452402030940e+02 -3.9190458584810938e+02 -8.1817868275314979e+01 +run_energy: 5970.39207741535 +run_stress: ! |2- + 1.6208867736373519e+04 6.7948579600320027e+03 7.1305695826795391e+03 9.7633828322861664e+03 7.2600321463915925e+03 1.5447157157420643e+03 +run_forces: ! |2 + 1 -2.4528067899599305e+03 -2.9341498758694834e+03 1.8474502628810092e+03 + 2 2.2849953443131358e+03 2.4832132528641532e+03 -1.9734041065370207e+03 + 3 2.4645121926310981e+02 5.6107471210645315e+01 -8.6795186329367851e+01 + 4 1.9616286871603430e+02 -3.4646936665248838e+01 1.4521984946881906e+02 + 5 4.4786043366163092e+01 7.0355159622163413e+01 -1.8206446229257014e+02 + 6 6.3014259396422148e+01 -2.3443604305372531e+01 7.3335878209082523e+01 + 7 -7.5439226250126969e+00 8.8159986346211809e+01 4.7619146069988375e+02 + 8 -5.2794374027797267e+02 -6.7850905833180059e+02 -3.0044325103852425e+03 + 9 5.0875826270523237e+02 5.9895242277843204e+02 2.5707270877003639e+03 + 10 2.2692333933019427e+01 2.2468607061589762e+02 1.0652917744563030e+02 + 11 4.9524433239219128e+01 1.3194159227606778e+02 1.8593459451158319e+02 + 12 -1.2924900910837812e+02 -1.0786813076932702e+02 7.2902771957494465e+01 + 13 -2.2563078857895891e+02 7.9098261816218340e+01 5.9928622881036187e-01 + 14 7.1714363938493051e+01 -1.4069611756278411e+01 1.9685384363446633e+02 + 15 5.3227157848209936e+00 -2.1039435001417377e+02 -8.2608217922982035e+01 + 16 -1.9602835424600102e+02 2.9522300430908854e+02 -1.8289236857613002e+02 + 17 4.5780760140603689e+01 -2.4655654127193632e+01 -1.6354736069382949e+02 + 18 1.4538209315245763e+03 1.8016876637042560e+02 5.1960640192178516e+03 + 19 -4.4445174898483028e+03 -3.2140466357034707e+03 -4.0221471271913274e+03 + 20 2.9906965583237265e+03 3.0338778693330451e+03 -1.1739168920265240e+03 + 21 -1.6853486613016630e+03 -1.8034506859630817e+03 5.9502858979499688e+03 + 22 -4.4700832926138246e+03 -1.4721556143241976e+03 -5.1672896924006909e+03 + 23 6.1554319539154876e+03 3.2756063002872793e+03 -7.8299620554927776e+02 + 24 2.0293017347310815e+03 -5.5779536635571512e+03 3.7011650252507684e+03 + 25 -6.3683824848081467e+03 -2.5625161247114107e+02 -4.9590463888100294e+03 + 26 4.3390807500770652e+03 5.8342052760282922e+03 1.2578813635592610e+03 + 27 6.4608153662309178e+02 -5.9696003016405839e+03 1.7149735844085783e+03 + 28 -5.5676765991366801e+03 1.3628574542763808e+03 -3.3980237947784067e+03 + 29 4.9215950625135883e+03 4.6067428473642030e+03 1.6830502103698284e+03 +... From feadfaf9bec683f90263b85439261ee84202d555 Mon Sep 17 00:00:00 2001 From: abhishandy Date: Tue, 4 Aug 2020 02:15:11 -0400 Subject: [PATCH 059/122] unit tests for angle-class2/p6, angle-cross and angle-mm3 --- .../force-styles/tests/angle-class2_p6.yaml | 93 +++++++++++++++++++ unittest/force-styles/tests/angle-cross.yaml | 86 +++++++++++++++++ unittest/force-styles/tests/angle-mm3.yaml | 86 +++++++++++++++++ 3 files changed, 265 insertions(+) create mode 100644 unittest/force-styles/tests/angle-class2_p6.yaml create mode 100644 unittest/force-styles/tests/angle-cross.yaml create mode 100644 unittest/force-styles/tests/angle-mm3.yaml diff --git a/unittest/force-styles/tests/angle-class2_p6.yaml b/unittest/force-styles/tests/angle-class2_p6.yaml new file mode 100644 index 0000000000..8cc8903b16 --- /dev/null +++ b/unittest/force-styles/tests/angle-class2_p6.yaml @@ -0,0 +1,93 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 01:47:32 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + angle class2/p6 +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +angle_style: class2/p6 +angle_coeff: ! | + 1 110.1 75.0 5.2 1.0 0.06 0.002 + 2 111.0 45.0 2.0 0.5 0.05 0.001 + 3 120.0 50.0 3.0 1.1 0.07 0.003 + 4 108.5 90.0 4.0 0.1 0.04 0.0 + * bb 0.0 1.0 1.0 + 2 bb 10.0 1.5 1.5 + 3 bb 15.0 1.2 1.2 + * ba 0.0 0.0 1.5 1.5 + 1 ba 20.0 0.0 1.5 1.5 + 3 ba 10.0 10.0 1.5 1.5 + 4 ba 0.0 20.0 1.5 1.5 +equilibrium: 4 1.9216075064457565 1.9373154697137058 2.0943951023931953 1.8936822384138474 +extract: ! "" +natoms: 29 +init_energy: 45.6314933281677 +init_stress: ! |2- + 1.0380655176146684e+02 -8.5598294304262993e+01 1.0547225768036336e+01 9.3533997442530406e+01 -3.0452940351933222e+01 1.6213985364060386e+00 +init_forces: ! |2 + 1 4.7202230480286410e+01 9.2446782757168116e+00 -2.1892853730747078e+01 + 2 -1.7062799943363016e+00 -1.3815333539761287e+01 -1.1109218053986506e+01 + 3 -1.0819442137600223e+01 4.2755643579721415e+01 4.0131978148937151e+01 + 4 -1.6107331786015202e+01 -2.0450833016170897e+01 1.2394698445624217e+01 + 5 -4.1996775288710353e+01 -4.1451276926607711e+01 -1.7536151963373868e+01 + 6 5.6640330905804802e+01 -1.3581373316126099e+01 -3.9714075413905050e+01 + 7 -1.8054191673295325e+01 1.6982840171711775e+01 1.5587849314106879e+00 + 8 -1.0524752828621686e+01 -1.5572494690475857e+01 8.4307006012653105e+01 + 9 -1.4606116746275049e+01 1.7088845087132931e+01 3.5265010989798085e+00 + 10 -9.2183983294618042e+00 2.5308833813269260e+01 -6.6220570658369539e+01 + 11 -2.0536178089795960e+01 -7.0922505905966320e+00 7.5061958159305702e+00 + 12 -2.8507497680541416e-01 -6.5761946491161325e+00 -7.8131884119322699e+00 + 13 3.1055913097859396e+00 8.1431291943766322e+00 -1.2597770427903274e+00 + 14 1.6321556949530393e+01 -6.4737931388147860e+00 -6.0969371866598241e+00 + 15 1.2014697273266693e+01 -4.7819939276460772e+00 1.5497663357748195e+01 + 16 9.3845137052789855e+00 9.2380146356987876e+00 6.9332800900251534e+00 + 17 -8.1437877303591466e-01 1.0335590376878656e+00 -2.1333543954444023e-01 + 18 4.7908727278799290e-01 1.6800089017686126e+00 -5.5268872325673559e+00 + 19 -2.0533806022955741e+00 -2.3525963295672678e+00 2.1320669593942387e+00 + 20 1.5742933295075812e+00 6.7258742779865532e-01 3.3948202731731172e+00 + 21 3.9487365123921143e+00 4.3175299645965666e+00 -1.1481914586060437e+01 + 22 -6.5477065825321858e+00 -4.1918674696341007e+00 3.4304242277121499e+00 + 23 2.5989700701400715e+00 -1.2566249496246629e-01 8.0514903583482873e+00 + 24 -8.4094044796366130e-01 4.6838059399926504e+00 -2.5056978760993669e+00 + 25 -1.3589398825660985e+00 -3.2194809423072277e+00 2.1726605118393005e-01 + 26 2.1998803305297598e+00 -1.4643249976854225e+00 2.2884318249154370e+00 + 27 -1.3120258888530634e-01 2.3248353691437700e+00 -7.0687277351935407e-01 + 28 -7.9798149292664289e-01 -1.3623377973865247e+00 -7.5274691862757134e-02 + 29 9.2918408181194923e-01 -9.6249757175724537e-01 7.8214746538211122e-01 +run_energy: 34.7710021802843 +run_stress: ! |2- + 8.2597971291479197e+01 -7.3165155099119787e+01 1.3819523382589331e+01 6.3916255789759887e+01 -3.2786246459555542e+01 -1.4139108343887937e+01 +run_forces: ! |2 + 1 3.7927352066617843e+01 1.1345578955697578e+01 -1.1972223392594877e+01 + 2 -2.2530151861588221e+00 -1.6730752730321111e+01 -1.3830028934174075e+01 + 3 -1.2808202999545058e+01 2.6810537449420028e+01 3.2101813074628957e+01 + 4 -1.1543428890097667e+01 -1.2065890478079011e+01 1.2118876491850669e+01 + 5 -3.4452953998071493e+01 -3.1526645749475254e+01 -1.7061508583515799e+01 + 6 5.3124061789690046e+01 -9.8153932766364225e+00 -3.3413445953998050e+01 + 7 -1.5837451909202500e+01 1.5464636644079322e+01 2.9907535647605528e+00 + 8 -1.2642499501331814e+01 -1.6827520447502955e+01 6.6128157110851689e+01 + 9 -1.2422527130616468e+01 1.5140727744495180e+01 3.1927309477457397e+00 + 10 -4.5699146984782653e+00 1.9876544474852427e+01 -5.0445553641851191e+01 + 11 -2.0546856915215699e+01 -4.0805919057130202e+00 6.3990200309451364e+00 + 12 1.6674386786922035e+00 -7.8898622136347321e+00 -4.6576734932525898e+00 + 13 1.3787930022897750e+00 3.6786663373190747e+00 8.0453816384512500e-01 + 14 1.4612585031889664e+01 8.9625154966459952e-01 -5.0334305413899969e+00 + 15 8.6954127506719381e+00 -2.6866238831447746e+00 7.8777491997152982e+00 + 16 1.0980388209061257e+01 6.6689588413014143e+00 5.5514416401958968e+00 + 17 -1.3091803001949562e+00 1.7413786876776518e+00 -7.5121568376248682e-01 + 18 -2.9253358583708966e-01 -1.0692065548636447e+00 3.5574890018854184e+00 + 19 1.2218057581339843e+00 1.4528878155123350e+00 -1.4511972583726351e+00 + 20 -9.2927217229689463e-01 -3.8368126064869040e-01 -2.1062917435127830e+00 + 21 7.2982725828986472e-01 7.4575588184549157e-01 -2.1049033311678720e+00 + 22 -1.1629872272200477e+00 -7.2090321482023068e-01 6.5350175240989561e-01 + 23 4.3315996893018294e-01 -2.4852667025260865e-02 1.4514015787579764e+00 + 24 2.1047126507496655e-01 -1.2182537322525984e+00 6.3301122830056489e-01 + 25 3.4461102790155146e-01 8.3416579486254627e-01 -4.7213083696926589e-02 + 26 -5.5508229297651801e-01 3.8408793739005220e-01 -5.8579814460363833e-01 + 27 -4.0872631407944005e-02 3.4985032920658937e-01 -1.0933719986668670e-01 + 28 -9.5501418324631770e-02 -2.0817696111033340e-01 -1.8145761309987267e-03 + 29 1.3637404973257578e-01 -1.4167336809625597e-01 1.1115177599768543e-01 +... diff --git a/unittest/force-styles/tests/angle-cross.yaml b/unittest/force-styles/tests/angle-cross.yaml new file mode 100644 index 0000000000..57802cd94d --- /dev/null +++ b/unittest/force-styles/tests/angle-cross.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 02:05:46 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + angle cross +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +angle_style: cross +angle_coeff: ! | + 1 200.0 80.0 75.0 0.95 1.30 107.0 + 2 540.0 120.0 125.0 1.25 1.15 109.5 + 3 100.0 150.0 120.0 1.45 1.35 98.2 + 4 250.0 90.0 110.0 1.05 1.20 99.9 +equilibrium: 4 1.8675022996339325 1.911135530933791 1.7139133254584316 1.7435839227423353 +extract: ! "" +natoms: 29 +init_energy: -138.932277153618 +init_stress: ! |- + -4.2805178950841434e+02 -6.8931627675603272e+02 -1.3391464673179194e+03 1.7315796064284473e+02 -4.7373177498509804e+01 -1.2493656046964837e+02 +init_forces: ! |2 + 1 4.1261771156832864e+01 -3.9901180365329722e+01 -5.8374199387912931e+01 + 2 -3.6935073144563262e+01 -4.1436803276575638e+01 3.1801084962114309e+01 + 3 -3.2573818619875419e+02 -6.6500679467513812e+00 1.4291055848554771e+02 + 4 2.6997608680775113e+02 -7.2399407558115584e+01 1.5603217496050598e+02 + 5 9.0142725537811359e+01 8.3784243775028855e+01 -3.1041619931467909e+02 + 6 7.0518354707600892e+01 -3.5688408606101547e+01 -1.9863264840396582e+01 + 7 -3.1099772047202357e+01 4.2191781474751821e+01 8.0541672920710511e+01 + 8 -3.3291691525631649e+01 1.1421233563604184e+02 4.5145975856099867e+01 + 9 -2.0097568628798609e+01 -2.8949808125067534e+01 -9.9834623873123718e+01 + 10 -1.8926705389391168e+02 -2.9499473880339724e+02 -1.9126304362253541e+02 + 11 1.0871064004892659e+02 1.9947452100760881e+02 3.3898316466944209e+02 + 12 1.6577321129406224e+02 2.3860689874372537e+02 -1.1277910127691004e+02 + 13 -1.3827402271990965e+02 2.9192785722581753e+01 1.5604081681362711e+01 + 14 3.2683184972651915e+01 -2.7370682688527136e+01 1.4257278340569977e+02 + 15 -1.3704545056389415e+01 -2.1010776334000127e+02 -5.4827359766131927e+01 + 16 -1.6260788071214986e+01 5.4319222370483033e+01 3.0878888817764548e+01 + 17 2.5602726760738861e+01 -4.2829280203544968e+00 -1.3711259367755784e+02 + 18 4.4382898505726800e+01 3.8575853540595062e+01 8.4942962936193993e+00 + 19 -4.0669070046367011e+01 -3.0398559842419200e+01 -2.9790776450486824e+01 + 20 -3.7138284593597923e+00 -8.1772936981758662e+00 2.1296480156867425e+01 + 21 4.8125944561078576e+01 2.1993457392981661e+01 2.1164315021860890e+01 + 22 -4.3995064087630098e+01 -1.6036579945545959e+01 -4.0751411025849421e+01 + 23 -4.1308804734484790e+00 -5.9568774474356996e+00 1.9587096003988531e+01 + 24 4.4750995566613383e+01 2.8951721466978508e+01 2.3322963994109926e+01 + 25 -4.8220422931020614e+01 -9.2520584071419378e+00 -3.3809259662730113e+01 + 26 3.4694273644072284e+00 -1.9699663059836571e+01 1.0486295668620187e+01 + 27 4.7585743845211717e+01 1.8785871750636648e+01 2.1506067119647888e+01 + 28 -4.9785651292999155e+01 1.9503981519706528e+00 -2.8387090726034970e+01 + 29 2.1999074477874405e+00 -2.0736269902607301e+01 6.8810236063870809e+00 +run_energy: -889.986798682076 +run_stress: ! |2- + 6.2032360151200282e+02 5.2404271480687089e+02 -7.9766346305103582e+02 1.8788017500161166e+02 -3.3065243080514335e+02 -1.9541086664451404e+02 +run_forces: ! |2 + 1 1.2410095526751289e+02 7.7107736904240781e+01 -4.4093648318567098e+01 + 2 -4.4510271992921041e+01 -4.5619512048781388e+01 4.1046404593008859e+01 + 3 -7.1737120871520744e+02 1.1731035280496367e+02 3.1906281222623056e+02 + 4 2.9648870407307368e+02 -7.6538903731607789e+01 1.6140330965017336e+02 + 5 1.0026655172616390e+02 8.7788729411632005e+01 -3.4300001131890929e+02 + 6 3.4849367490473037e+02 -2.8205577430636208e+02 -2.5719791408224165e+02 + 7 -4.5693333755656603e+01 5.8517091234287307e+01 9.5255349706311947e+01 + 8 -1.5567919750483691e+02 3.5623689847871810e+02 2.5733162917382754e+02 + 9 -2.0241139553713793e+01 -4.5633636920096777e+01 -1.4136212461520404e+02 + 10 -5.0563564520435619e+02 -8.9458027939934959e+02 -5.1224441958153523e+02 + 11 9.9129502224764863e+01 2.4918320141218032e+02 5.3289039476810501e+02 + 12 5.4675965939691775e+02 7.2245181913254692e+02 -2.6073823924297500e+02 + 13 -1.6843077637066705e+02 2.0930840623941872e+01 1.3253648491547258e+01 + 14 3.6029135878922879e+01 -4.0482344788499539e+01 1.5508129105553371e+02 + 15 1.6546004038532232e+00 -2.7170978973512308e+02 -8.7945682620661728e+01 + 16 7.6285319212612194e+01 -2.2584716543975293e+01 2.1686618269540631e+02 + 17 2.8353470008807250e+01 -1.0321712528715462e+01 -1.4560898258005068e+02 + 18 5.0761083509487648e+01 4.5876997617787652e+01 4.1461514924504499e+00 + 19 -3.6248289725249840e+01 -2.7244416085659807e+01 -2.7471372147322061e+01 + 20 -1.4512793784237811e+01 -1.8632581532127848e+01 2.3325220654871611e+01 + 21 6.2092747177666155e+01 2.9035902409181922e+01 1.9655639900605195e+01 + 22 -4.4008555668269942e+01 -1.5835759606379121e+01 -4.1366741507205347e+01 + 23 -1.8084191509396216e+01 -1.3200142802802802e+01 2.1711101606600153e+01 + 24 5.2569537785929668e+01 4.0844673040252673e+01 2.5893306272073922e+01 + 25 -5.0354690954148325e+01 -1.0776153112111967e+01 -3.5642125276776859e+01 + 26 -2.2148468317813421e+00 -3.0068519928140702e+01 9.7488190047029395e+00 + 27 5.7654772845660396e+01 2.5751879999227995e+01 2.5827764093646238e+01 + 28 -5.1108879214123533e+01 3.5861424927109447e+00 -2.9419298155615849e+01 + 29 -6.5458936315368632e+00 -2.9338022491938940e+01 3.5915340619696101e+00 +... diff --git a/unittest/force-styles/tests/angle-mm3.yaml b/unittest/force-styles/tests/angle-mm3.yaml new file mode 100644 index 0000000000..a4c4d97316 --- /dev/null +++ b/unittest/force-styles/tests/angle-mm3.yaml @@ -0,0 +1,86 @@ +--- +lammps_version: 21 Jul 2020 +date_generated: Tue Aug 4 02:07:04 202 +epsilon: 2.5e-13 +prerequisites: ! | + atom full + angle mm3 +pre_commands: ! "" +post_commands: ! "" +input_file: in.fourmol +angle_style: mm3 +angle_coeff: ! | + 1 75.0 110.1 + 2 45.0 111.0 + 3 50.0 120.0 + 4 100.0 108.5 +equilibrium: 4 1.9216075064457565 1.9373154697137058 2.0943951023931953 1.8936822384138474 +extract: ! "" +natoms: 29 +init_energy: 44.7246154856262 +init_stress: ! |2- + 9.6483539484715649e+01 -7.3120175237333171e+01 -2.3363364247382489e+01 9.6221737253953165e+01 -3.1311135458252558e+01 -1.7557146927751806e+01 +init_forces: ! |2 + 1 4.4689184239622811e+01 1.4410850488342223e+01 -4.9896003676738601e+01 + 2 -1.0347123094666624e+00 -8.3778135595728997e+00 -6.7367868738801651e+00 + 3 4.6051547598378484e+00 7.6238656099244039e+01 8.0924821901641337e+01 + 4 -1.3879556638976471e+01 -2.5509672482964671e+01 9.4826500118368635e+00 + 5 -4.8662433133193005e+01 -7.2269667876505977e+01 -3.1280325044276090e+01 + 6 4.2630030017502165e+01 -1.4584975822585262e+01 -2.8437404960316339e+01 + 7 -1.8500794405118786e+01 1.6518275777933866e+01 -4.0339107370898475e+00 + 8 -1.4191729253133266e+01 -3.4864230574246292e+01 7.5918883739362883e+01 + 9 -1.5796555588594202e+01 1.6195942437882501e+01 -3.7228001790677689e-01 + 10 1.8322429576874946e+01 5.9405823367322235e+01 -6.9720265077692162e+01 + 11 -2.5541108989280865e+01 -1.1403183226794766e+01 1.3233874660940693e+01 + 12 -6.6849905958062745e+00 -1.4573899088230753e+01 -7.9431956449961731e+00 + 13 2.6386638124624522e+00 6.6821772047683305e+00 -2.5200611835550557e-01 + 14 1.7062014144274453e+01 -9.5655590628320333e+00 -7.3297792370284753e+00 + 15 1.2590362179775433e+01 -6.6233814314601647e+00 1.9505432098849852e+01 + 16 2.5818882071551919e-01 1.0357871783493341e+01 5.8369792597804713e+00 + 17 1.4958533625039077e+00 -2.0372140337937137e+00 1.0993157158679869e+00 + 18 1.6336476139296607e-01 1.7071567478868546e+00 -6.9281945549275328e+00 + 19 -2.0002819887482959e+00 -2.4919453319891600e+00 2.9670497500280750e+00 + 20 1.8369172273553298e+00 7.8478858410230534e-01 3.9611448048994573e+00 + 21 3.6622530369381416e+00 4.5845356902040812e+00 -1.3701042411933230e+01 + 22 -6.5214087195934987e+00 -4.4462929914148557e+00 4.8435089311126376e+00 + 23 2.8591556826553570e+00 -1.3824269878922513e-01 8.8575334808205923e+00 + 24 -1.3449587561612431e+00 5.2279343877424056e+00 -3.1125116049354911e+00 + 25 -1.0788495447525834e+00 -3.6145543163951412e+00 5.9113806641683375e-01 + 26 2.4238083009138265e+00 -1.6133800713472644e+00 2.5213735385186573e+00 + 27 -2.9077025434585668e-01 2.3869960050754981e+00 -8.1309006692665386e-01 + 28 -6.3578646910720737e-01 -1.4272199888098533e+00 3.3154199570463894e-02 + 29 9.2655672345306406e-01 -9.5977601626564502e-01 7.7993586735619003e-01 +run_energy: 28.5216147491206 +run_stress: ! |2- + 6.8461353854478219e+01 -7.0950008061963530e+01 2.4886542074852920e+00 5.5870749189169125e+01 -2.7667972182039183e+01 -1.6996023033360832e+01 +run_forces: ! |2 + 1 3.0380072332525348e+01 1.3814126903880505e+01 -2.0438184527799478e+01 + 2 -1.5896758508862501e+00 -1.3186713957024102e+01 -1.0957750561693299e+01 + 3 1.0173706748711790e+00 3.4749452305760151e+01 4.6613519883555128e+01 + 4 -1.0383808658739017e+01 -1.3092365246467571e+01 1.0237776620551353e+01 + 5 -3.4745343543018002e+01 -3.8258698544781538e+01 -2.3605370769960434e+01 + 6 4.0787323590543807e+01 -1.0201577912271816e+01 -2.3948461973825886e+01 + 7 -1.6198436571694629e+01 1.4913874197821972e+01 -3.4306120590974016e+00 + 8 -1.3465852437235963e+01 -3.0185469919264790e+01 6.0837800511112157e+01 + 9 -1.2716454112122053e+01 1.3041502725150096e+01 -5.8377443421772757e-01 + 10 1.7027475118237291e+01 4.5315690176362438e+01 -5.1379767191696686e+01 + 11 -2.2855844833833256e+01 -5.5494228294778045e+00 1.0138888484515970e+01 + 12 -4.4269952322579140e+00 -1.7470425947183756e+01 -4.6317953693609208e+00 + 13 7.6465435292114470e-01 2.0155421267026603e+00 1.9370658422010325e+00 + 14 1.4672307445518555e+01 1.0427182317397055e-01 -5.4211481924917226e+00 + 15 7.7515783031017698e+00 -3.5744171309510042e+00 9.8109367651667689e+00 + 16 3.4121913655913687e+00 8.3565191811471671e+00 4.3979250745677350e+00 + 17 5.6943805647662382e-01 -7.9188795257658329e-01 4.2295189847340964e-01 + 18 -1.1595207714960087e-01 -8.8592994767285993e-01 3.4666075636248141e+00 + 19 9.7283502868341010e-01 1.2392405135742253e+00 -1.5222371111054831e+00 + 20 -8.5688295153380922e-01 -3.5331056590136534e-01 -1.9443704525193310e+00 + 21 5.6171987735395690e-01 6.5254583338821914e-01 -2.0741987744859971e+00 + 22 -9.5527937700173116e-01 -6.2942572231870320e-01 7.5223417657219804e-01 + 23 3.9355949964777426e-01 -2.3120111069515975e-02 1.3219645979137991e+00 + 24 4.1742703452645963e-01 -1.5999295770543851e+00 9.4277327946116163e-01 + 25 3.0228085645331310e-01 1.1016277327143633e+00 -1.8312389454553685e-01 + 26 -7.1970789097977272e-01 4.9830184434002178e-01 -7.5964938491562473e-01 + 27 -1.3855386687371539e-02 1.0525039239171710e-01 -3.3763622025640205e-02 + 28 -2.6899771291758752e-02 -6.2914938974737530e-02 5.4695029730642344e-04 + 29 4.0755157979130291e-02 -4.2335453416979571e-02 3.3216671728333778e-02 +... From f9539f9ca670ffaf2752d305e9584390b8af2479 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Aug 2020 07:08:55 -0400 Subject: [PATCH 060/122] remove unused code --- src/USER-MISC/pair_ilp_graphene_hbn.cpp | 3 +-- src/USER-MISC/pair_kolmogorov_crespi_full.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/USER-MISC/pair_ilp_graphene_hbn.cpp b/src/USER-MISC/pair_ilp_graphene_hbn.cpp index b2f659e0f4..106d02dd48 100644 --- a/src/USER-MISC/pair_ilp_graphene_hbn.cpp +++ b/src/USER-MISC/pair_ilp_graphene_hbn.cpp @@ -686,7 +686,7 @@ void PairILPGrapheneHBN::calc_FRep(int eflag, int /* vflag */) void PairILPGrapheneHBN::ILP_neigh() { - int i,j,ii,jj,n,allnum,inum,jnum,itype,jtype; + int i,j,ii,jj,n,allnum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *ilist,*jlist,*numneigh,**firstneigh; int *neighptr; @@ -702,7 +702,6 @@ void PairILPGrapheneHBN::ILP_neigh() ILP_firstneigh = (int **) memory->smalloc(maxlocal*sizeof(int *),"ILPGrapheneHBN:firstneigh"); } - inum = list->inum; allnum = list->inum + list->gnum; ilist = list->ilist; numneigh = list->numneigh; diff --git a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp index 8590e7097e..9627cbc08a 100644 --- a/src/USER-MISC/pair_kolmogorov_crespi_full.cpp +++ b/src/USER-MISC/pair_kolmogorov_crespi_full.cpp @@ -690,7 +690,7 @@ void PairKolmogorovCrespiFull::calc_FRep(int eflag, int /* vflag */) void PairKolmogorovCrespiFull::KC_neigh() { - int i,j,ii,jj,n,allnum,inum,jnum,itype,jtype; + int i,j,ii,jj,n,allnum,jnum,itype,jtype; double xtmp,ytmp,ztmp,delx,dely,delz,rsq; int *ilist,*jlist,*numneigh,**firstneigh; int *neighptr; @@ -707,7 +707,6 @@ void PairKolmogorovCrespiFull::KC_neigh() "KolmogorovCrespiFull:firstneigh"); } - inum = list->inum; allnum = list->inum + list->gnum; ilist = list->ilist; numneigh = list->numneigh; From 357716ec4c4ffff64fcacbcd49c3912fffcfcad9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Aug 2020 07:17:12 -0400 Subject: [PATCH 061/122] correctly check of mu and torque flags as those data structures are always accessed. --- src/DIPOLE/pair_lj_long_dipole_long.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/DIPOLE/pair_lj_long_dipole_long.cpp b/src/DIPOLE/pair_lj_long_dipole_long.cpp index 481191534f..3f383defea 100644 --- a/src/DIPOLE/pair_lj_long_dipole_long.cpp +++ b/src/DIPOLE/pair_lj_long_dipole_long.cpp @@ -232,9 +232,7 @@ void PairLJLongDipoleLong::init_style() if (!atom->q_flag && (ewald_order&(1<<1))) error->all(FLERR, "Invoking coulombic in pair style lj/long/dipole/long requires atom attribute q"); - if (!atom->mu && (ewald_order&(1<<3))) - error->all(FLERR,"Pair lj/long/dipole/long requires atom attributes mu, torque"); - if (!atom->torque && (ewald_order&(1<<3))) + if (!atom->mu_flag || !atom->torque_flag) error->all(FLERR,"Pair lj/long/dipole/long requires atom attributes mu, torque"); neighbor->request(this,instance_me); From e860779fa0d87a91ac25adc9b7a388e133d0c59b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 4 Aug 2020 07:17:28 -0400 Subject: [PATCH 062/122] formatting update --- src/DIPOLE/pair_lj_long_dipole_long.cpp | 31 +++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/DIPOLE/pair_lj_long_dipole_long.cpp b/src/DIPOLE/pair_lj_long_dipole_long.cpp index 3f383defea..7dc596eccb 100644 --- a/src/DIPOLE/pair_lj_long_dipole_long.cpp +++ b/src/DIPOLE/pair_lj_long_dipole_long.cpp @@ -489,18 +489,18 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) if (eflag) ecoul = G0*B0+G1*B1+G2*B2; if (ni > 0) { // adj part, eqn 2.13 force_coul -= (f = qqrd2e*(1.0-special_coul[ni])/r)*( - (3.0*G1+15.0*G2*r2inv)*r2inv+G0)*r2inv; + (3.0*G1+15.0*G2*r2inv)*r2inv+G0)*r2inv; if (eflag) ecoul -= f*((G1+3.0*G2*r2inv)*r2inv+G0); B1 -= f*r2inv; } B0 = mudj+qj*B1; B3 = -qi*B1+mudi; // position independent - if (ni > 0) B0 -= f*3.0*mudj*r2inv*r2inv/B2; - if (ni > 0) B3 -= f*3.0*mudi*r2inv*r2inv/B2; + if (ni > 0) B0 -= f*3.0*mudj*r2inv*r2inv/B2; + if (ni > 0) B3 -= f*3.0*mudi*r2inv*r2inv/B2; force_d[0] = B0*mui[0]+B3*muj[0]; // force contribs force_d[1] = B0*mui[1]+B3*muj[1]; force_d[2] = B0*mui[2]+B3*muj[2]; - if (ni > 0) { + if (ni > 0) { ti[0] -= f*(3.0*mudj*r2inv*r2inv*d[0]/B2+(qj*r2inv*d[0]-muj[0]*r2inv)); ti[1] -= f*(3.0*mudj*r2inv*r2inv*d[1]/B2+(qj*r2inv*d[1]-muj[1]*r2inv)); ti[2] -= f*(3.0*mudj*r2inv*r2inv*d[2]/B2+(qj*r2inv*d[2]-muj[2]*r2inv)); @@ -509,7 +509,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) tj[1] -= f*(3.0*mudi*r2inv*r2inv*d[1]/B2-(qi*r2inv*d[1]+mui[1]*r2inv)); tj[2] -= f*(3.0*mudi*r2inv*r2inv*d[2]/B2-(qi*r2inv*d[2]+mui[2]*r2inv)); } - } + } } // table real space } else { force_coul = ecoul = 0.0; @@ -525,31 +525,27 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) force_lj = (rn*=rn)*lj1i[typej]-g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq; if (eflag) evdwl = rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2; - } - else { // special case + } else { // special case double f = special_lj[ni], t = rn*(1.0-f); force_lj = f*(rn *= rn)*lj1i[typej]- g8*(((6.0*a2+6.0)*a2+3.0)*a2+1.0)*x2*rsq+t*lj2i[typej]; if (eflag) evdwl = - f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; + f*rn*lj3i[typej]-g6*((a2+1.0)*a2+0.5)*x2+t*lj4i[typej]; } - } - else { // cut lj + } else { // cut lj double rn = r2inv*r2inv*r2inv; if (ni < 0) { force_lj = rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]; - } - else { // special case + } else { // special case double f = special_lj[ni]; force_lj = f*rn*(rn*lj1i[typej]-lj2i[typej]); if (eflag) evdwl = f*( - rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); + rn*(rn*lj3i[typej]-lj4i[typej])-offseti[typej]); } } force_lj *= r2inv; - } - else force_lj = evdwl = 0.0; + } else force_lj = evdwl = 0.0; fpair = force_coul+force_lj; // force if (newton_pair || j < nlocal) { @@ -564,8 +560,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) tqj[0] += muj[1]*tj[2]-muj[2]*tj[1]; tqj[1] += muj[2]*tj[0]-muj[0]*tj[2]; tqj[2] += muj[0]*tj[1]-muj[1]*tj[0]; - } - else { + } else { fi[0] += fx = d[0]*fpair+force_d[0]; // force fi[1] += fy = d[1]*fpair+force_d[1]; fi[2] += fz = d[2]*fpair+force_d[2]; @@ -575,7 +570,7 @@ void PairLJLongDipoleLong::compute(int eflag, int vflag) } if (evflag) ev_tally_xyz(i,j,nlocal,newton_pair, - evdwl,ecoul,fx,fy,fz,d[0],d[1],d[2]); + evdwl,ecoul,fx,fy,fz,d[0],d[1],d[2]); } } From ed566bf6af0d9d8a489ec3a9df78659daedd4c74 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 4 Aug 2020 12:16:26 -0500 Subject: [PATCH 063/122] First set of changes for Kokkos HIP --- src/KOKKOS/angle_charmm_kokkos.cpp | 2 +- src/KOKKOS/angle_class2_kokkos.cpp | 2 +- src/KOKKOS/angle_cosine_kokkos.cpp | 2 +- src/KOKKOS/angle_harmonic_kokkos.cpp | 2 +- src/KOKKOS/bond_class2_kokkos.cpp | 2 +- src/KOKKOS/bond_fene_kokkos.cpp | 2 +- src/KOKKOS/bond_harmonic_kokkos.cpp | 2 +- src/KOKKOS/compute_coord_atom_kokkos.cpp | 2 +- .../compute_orientorder_atom_kokkos.cpp | 2 +- src/KOKKOS/compute_temp_kokkos.cpp | 2 +- src/KOKKOS/dihedral_charmm_kokkos.cpp | 2 +- src/KOKKOS/dihedral_class2_kokkos.cpp | 2 +- src/KOKKOS/dihedral_harmonic_kokkos.cpp | 2 +- src/KOKKOS/dihedral_opls_kokkos.cpp | 2 +- src/KOKKOS/fft3d_kokkos.cpp | 2 +- src/KOKKOS/fftdata_kokkos.h | 4 ++-- src/KOKKOS/fix_dpd_energy_kokkos.cpp | 2 +- src/KOKKOS/fix_enforce2d_kokkos.cpp | 2 +- src/KOKKOS/fix_eos_table_rx_kokkos.cpp | 2 +- src/KOKKOS/fix_freeze_kokkos.cpp | 2 +- src/KOKKOS/fix_gravity_kokkos.cpp | 2 +- src/KOKKOS/fix_langevin_kokkos.cpp | 2 +- src/KOKKOS/fix_momentum_kokkos.cpp | 2 +- src/KOKKOS/fix_neigh_history_kokkos.cpp | 2 +- src/KOKKOS/fix_nh_kokkos.cpp | 2 +- src/KOKKOS/fix_nph_kokkos.cpp | 2 +- src/KOKKOS/fix_npt_kokkos.cpp | 2 +- src/KOKKOS/fix_nve_kokkos.cpp | 2 +- src/KOKKOS/fix_nve_sphere_kokkos.cpp | 2 +- src/KOKKOS/fix_nvt_kokkos.cpp | 2 +- src/KOKKOS/fix_qeq_reax_kokkos.cpp | 2 +- src/KOKKOS/fix_rx_kokkos.cpp | 2 +- src/KOKKOS/fix_setforce_kokkos.cpp | 2 +- src/KOKKOS/fix_shardlow_kokkos.cpp | 2 +- src/KOKKOS/fix_wall_lj93_kokkos.cpp | 2 +- src/KOKKOS/fix_wall_reflect_kokkos.cpp | 2 +- src/KOKKOS/gridcomm_kokkos.cpp | 2 +- src/KOKKOS/improper_class2_kokkos.cpp | 2 +- src/KOKKOS/improper_harmonic_kokkos.cpp | 2 +- src/KOKKOS/kissfft_kokkos.cpp | 2 +- src/KOKKOS/kokkos.cpp | 8 +++---- src/KOKKOS/kokkos_type.h | 23 +++++++++++++++++-- src/KOKKOS/nbin_kokkos.cpp | 2 +- src/KOKKOS/nbin_ssa_kokkos.cpp | 2 +- src/KOKKOS/neigh_bond_kokkos.cpp | 2 +- src/KOKKOS/neigh_list_kokkos.cpp | 2 +- src/KOKKOS/npair_copy_kokkos.cpp | 2 +- src/KOKKOS/npair_halffull_kokkos.cpp | 2 +- src/KOKKOS/npair_kokkos.cpp | 2 +- src/KOKKOS/npair_skip_kokkos.cpp | 2 +- src/KOKKOS/npair_ssa_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_buck_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_debye_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_dsf_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_coul_wolf_kokkos.cpp | 2 +- src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp | 2 +- src/KOKKOS/pair_eam_alloy_kokkos.cpp | 2 +- src/KOKKOS/pair_eam_fs_kokkos.cpp | 2 +- src/KOKKOS/pair_eam_kokkos.cpp | 2 +- src/KOKKOS/pair_exp6_rx_kokkos.cpp | 6 ++--- src/KOKKOS/pair_gran_hooke_history_kokkos.cpp | 2 +- src/KOKKOS/pair_kokkos.h | 2 +- ..._lj_charmm_coul_charmm_implicit_kokkos.cpp | 2 +- .../pair_lj_charmm_coul_charmm_kokkos.cpp | 2 +- .../pair_lj_charmm_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp | 2 +- .../pair_lj_class2_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_class2_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_cut_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_expand_kokkos.cpp | 2 +- .../pair_lj_gromacs_coul_gromacs_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_gromacs_kokkos.cpp | 2 +- src/KOKKOS/pair_lj_sdk_kokkos.cpp | 2 +- src/KOKKOS/pair_morse_kokkos.cpp | 2 +- src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp | 2 +- src/KOKKOS/pair_reaxc_kokkos.cpp | 2 +- src/KOKKOS/pair_snap_kokkos.cpp | 2 +- src/KOKKOS/pair_snap_kokkos_impl.h | 2 +- src/KOKKOS/pair_sw_kokkos.cpp | 2 +- src/KOKKOS/pair_table_kokkos.cpp | 2 +- src/KOKKOS/pair_table_rx_kokkos.cpp | 2 +- src/KOKKOS/pair_tersoff_kokkos.cpp | 2 +- src/KOKKOS/pair_tersoff_mod_kokkos.cpp | 2 +- src/KOKKOS/pair_tersoff_zbl_kokkos.cpp | 2 +- src/KOKKOS/pair_vashishta_kokkos.cpp | 2 +- src/KOKKOS/pair_yukawa_kokkos.cpp | 2 +- src/KOKKOS/pair_zbl_kokkos.cpp | 2 +- src/KOKKOS/pppm_kokkos.cpp | 4 ++-- src/KOKKOS/pppm_kokkos.h | 2 +- src/KOKKOS/rand_pool_wrap_kokkos.h | 2 +- src/KOKKOS/region_block_kokkos.cpp | 2 +- src/KOKKOS/remap_kokkos.cpp | 2 +- src/KOKKOS/sna_kokkos_impl.h | 8 +++---- 101 files changed, 131 insertions(+), 112 deletions(-) diff --git a/src/KOKKOS/angle_charmm_kokkos.cpp b/src/KOKKOS/angle_charmm_kokkos.cpp index 8d7a4d23d6..288e5a475b 100644 --- a/src/KOKKOS/angle_charmm_kokkos.cpp +++ b/src/KOKKOS/angle_charmm_kokkos.cpp @@ -446,7 +446,7 @@ void AngleCharmmKokkos::ev_tally(EV_FLOAT &ev, const int i, const in namespace LAMMPS_NS { template class AngleCharmmKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class AngleCharmmKokkos; #endif } diff --git a/src/KOKKOS/angle_class2_kokkos.cpp b/src/KOKKOS/angle_class2_kokkos.cpp index 50d7391ec5..ebb016b31b 100644 --- a/src/KOKKOS/angle_class2_kokkos.cpp +++ b/src/KOKKOS/angle_class2_kokkos.cpp @@ -597,7 +597,7 @@ void AngleClass2Kokkos::ev_tally(EV_FLOAT &ev, const int i, const in namespace LAMMPS_NS { template class AngleClass2Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class AngleClass2Kokkos; #endif } diff --git a/src/KOKKOS/angle_cosine_kokkos.cpp b/src/KOKKOS/angle_cosine_kokkos.cpp index afb955694d..960988b3b5 100644 --- a/src/KOKKOS/angle_cosine_kokkos.cpp +++ b/src/KOKKOS/angle_cosine_kokkos.cpp @@ -386,7 +386,7 @@ void AngleCosineKokkos::ev_tally(EV_FLOAT &ev, const int i, const in namespace LAMMPS_NS { template class AngleCosineKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class AngleCosineKokkos; #endif } diff --git a/src/KOKKOS/angle_harmonic_kokkos.cpp b/src/KOKKOS/angle_harmonic_kokkos.cpp index 4500e9b313..bc08ff4b65 100644 --- a/src/KOKKOS/angle_harmonic_kokkos.cpp +++ b/src/KOKKOS/angle_harmonic_kokkos.cpp @@ -404,7 +404,7 @@ void AngleHarmonicKokkos::ev_tally(EV_FLOAT &ev, const int i, const namespace LAMMPS_NS { template class AngleHarmonicKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class AngleHarmonicKokkos; #endif } diff --git a/src/KOKKOS/bond_class2_kokkos.cpp b/src/KOKKOS/bond_class2_kokkos.cpp index 514c80ddfb..88504608f6 100644 --- a/src/KOKKOS/bond_class2_kokkos.cpp +++ b/src/KOKKOS/bond_class2_kokkos.cpp @@ -365,7 +365,7 @@ void BondClass2Kokkos::ev_tally(EV_FLOAT &ev, const int &i, const in namespace LAMMPS_NS { template class BondClass2Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class BondClass2Kokkos; #endif } diff --git a/src/KOKKOS/bond_fene_kokkos.cpp b/src/KOKKOS/bond_fene_kokkos.cpp index 864873343d..e6aa27649f 100644 --- a/src/KOKKOS/bond_fene_kokkos.cpp +++ b/src/KOKKOS/bond_fene_kokkos.cpp @@ -400,7 +400,7 @@ void BondFENEKokkos::ev_tally(EV_FLOAT &ev, const int &i, const int namespace LAMMPS_NS { template class BondFENEKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class BondFENEKokkos; #endif } diff --git a/src/KOKKOS/bond_harmonic_kokkos.cpp b/src/KOKKOS/bond_harmonic_kokkos.cpp index 4e2a5aaa05..ee1b58c91f 100644 --- a/src/KOKKOS/bond_harmonic_kokkos.cpp +++ b/src/KOKKOS/bond_harmonic_kokkos.cpp @@ -339,7 +339,7 @@ void BondHarmonicKokkos::ev_tally(EV_FLOAT &ev, const int &i, const namespace LAMMPS_NS { template class BondHarmonicKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class BondHarmonicKokkos; #endif } diff --git a/src/KOKKOS/compute_coord_atom_kokkos.cpp b/src/KOKKOS/compute_coord_atom_kokkos.cpp index d91bf5a82a..90bd151b2d 100644 --- a/src/KOKKOS/compute_coord_atom_kokkos.cpp +++ b/src/KOKKOS/compute_coord_atom_kokkos.cpp @@ -243,7 +243,7 @@ void ComputeCoordAtomKokkos::operator()(TagComputeCoordAtom; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class ComputeCoordAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp index fa613ad699..cda8f72250 100644 --- a/src/KOKKOS/compute_orientorder_atom_kokkos.cpp +++ b/src/KOKKOS/compute_orientorder_atom_kokkos.cpp @@ -737,7 +737,7 @@ void ComputeOrientOrderAtomKokkos::check_team_size_for(int inum, int namespace LAMMPS_NS { template class ComputeOrientOrderAtomKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class ComputeOrientOrderAtomKokkos; #endif } diff --git a/src/KOKKOS/compute_temp_kokkos.cpp b/src/KOKKOS/compute_temp_kokkos.cpp index f5547d0200..0e7fe25540 100644 --- a/src/KOKKOS/compute_temp_kokkos.cpp +++ b/src/KOKKOS/compute_temp_kokkos.cpp @@ -154,7 +154,7 @@ void ComputeTempKokkos::operator()(TagComputeTempVector, cons namespace LAMMPS_NS { template class ComputeTempKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class ComputeTempKokkos; #endif } diff --git a/src/KOKKOS/dihedral_charmm_kokkos.cpp b/src/KOKKOS/dihedral_charmm_kokkos.cpp index 64ab79c305..0d8256f306 100644 --- a/src/KOKKOS/dihedral_charmm_kokkos.cpp +++ b/src/KOKKOS/dihedral_charmm_kokkos.cpp @@ -789,7 +789,7 @@ void DihedralCharmmKokkos::ev_tally(EVM_FLOAT &evm, const int i, con namespace LAMMPS_NS { template class DihedralCharmmKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class DihedralCharmmKokkos; #endif } diff --git a/src/KOKKOS/dihedral_class2_kokkos.cpp b/src/KOKKOS/dihedral_class2_kokkos.cpp index adda9c56a9..371af44e9a 100644 --- a/src/KOKKOS/dihedral_class2_kokkos.cpp +++ b/src/KOKKOS/dihedral_class2_kokkos.cpp @@ -1131,7 +1131,7 @@ void DihedralClass2Kokkos::ev_tally(EV_FLOAT &ev, const int i1, cons namespace LAMMPS_NS { template class DihedralClass2Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class DihedralClass2Kokkos; #endif } diff --git a/src/KOKKOS/dihedral_harmonic_kokkos.cpp b/src/KOKKOS/dihedral_harmonic_kokkos.cpp index 15e459f0d5..408fa276e4 100644 --- a/src/KOKKOS/dihedral_harmonic_kokkos.cpp +++ b/src/KOKKOS/dihedral_harmonic_kokkos.cpp @@ -530,7 +530,7 @@ void DihedralHarmonicKokkos::ev_tally(EV_FLOAT &ev, const int i1, co namespace LAMMPS_NS { template class DihedralHarmonicKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class DihedralHarmonicKokkos; #endif } diff --git a/src/KOKKOS/dihedral_opls_kokkos.cpp b/src/KOKKOS/dihedral_opls_kokkos.cpp index cc3cb321c0..309d617f0a 100644 --- a/src/KOKKOS/dihedral_opls_kokkos.cpp +++ b/src/KOKKOS/dihedral_opls_kokkos.cpp @@ -535,7 +535,7 @@ void DihedralOPLSKokkos::ev_tally(EV_FLOAT &ev, const int i1, const namespace LAMMPS_NS { template class DihedralOPLSKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class DihedralOPLSKokkos; #endif } diff --git a/src/KOKKOS/fft3d_kokkos.cpp b/src/KOKKOS/fft3d_kokkos.cpp index 04dd343af6..e49d780040 100644 --- a/src/KOKKOS/fft3d_kokkos.cpp +++ b/src/KOKKOS/fft3d_kokkos.cpp @@ -905,7 +905,7 @@ void FFT3dKokkos::fft_3d_1d_only_kokkos(typename FFT_AT::t_FFT_DATA_ namespace LAMMPS_NS { template class FFT3dKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FFT3dKokkos; #endif } diff --git a/src/KOKKOS/fftdata_kokkos.h b/src/KOKKOS/fftdata_kokkos.h index e68e888805..51c444c2a3 100644 --- a/src/KOKKOS/fftdata_kokkos.h +++ b/src/KOKKOS/fftdata_kokkos.h @@ -52,7 +52,7 @@ typedef double FFT_SCALAR; // CUFFT or KISSFFT, thus undefine all other // FFTs here, since they may be valid in fft3d.cpp -#if defined(KOKKOS_ENABLE_CUDA) +#ifdef KOKKOS_ENABLE_CUDA # if defined(FFT_FFTW) # undef FFT_FFTW # endif @@ -164,7 +164,7 @@ typedef tdual_int_64::t_dev_um t_int_64_um; }; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template <> struct FFTArrayTypes { diff --git a/src/KOKKOS/fix_dpd_energy_kokkos.cpp b/src/KOKKOS/fix_dpd_energy_kokkos.cpp index 20579a6dc5..6549430131 100644 --- a/src/KOKKOS/fix_dpd_energy_kokkos.cpp +++ b/src/KOKKOS/fix_dpd_energy_kokkos.cpp @@ -85,7 +85,7 @@ void FixDPDenergyKokkos::final_integrate() namespace LAMMPS_NS { template class FixDPDenergyKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixDPDenergyKokkos; #endif } diff --git a/src/KOKKOS/fix_enforce2d_kokkos.cpp b/src/KOKKOS/fix_enforce2d_kokkos.cpp index fca3cedb13..cc8314a00f 100644 --- a/src/KOKKOS/fix_enforce2d_kokkos.cpp +++ b/src/KOKKOS/fix_enforce2d_kokkos.cpp @@ -163,7 +163,7 @@ void FixEnforce2DKokkos::post_force_item( int i ) const namespace LAMMPS_NS { template class FixEnforce2DKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixEnforce2DKokkos; #endif } diff --git a/src/KOKKOS/fix_eos_table_rx_kokkos.cpp b/src/KOKKOS/fix_eos_table_rx_kokkos.cpp index 89561c9a92..21ee54df28 100644 --- a/src/KOKKOS/fix_eos_table_rx_kokkos.cpp +++ b/src/KOKKOS/fix_eos_table_rx_kokkos.cpp @@ -560,7 +560,7 @@ void FixEOStableRXKokkos::create_kokkos_tables() namespace LAMMPS_NS { template class FixEOStableRXKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixEOStableRXKokkos; #endif } diff --git a/src/KOKKOS/fix_freeze_kokkos.cpp b/src/KOKKOS/fix_freeze_kokkos.cpp index fb0c3841e6..f09ef28813 100644 --- a/src/KOKKOS/fix_freeze_kokkos.cpp +++ b/src/KOKKOS/fix_freeze_kokkos.cpp @@ -118,7 +118,7 @@ void FixFreezeKokkos::operator()(const int i, OriginalForce &origina namespace LAMMPS_NS { template class FixFreezeKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixFreezeKokkos; #endif } diff --git a/src/KOKKOS/fix_gravity_kokkos.cpp b/src/KOKKOS/fix_gravity_kokkos.cpp index e74595e598..4f8b57365e 100644 --- a/src/KOKKOS/fix_gravity_kokkos.cpp +++ b/src/KOKKOS/fix_gravity_kokkos.cpp @@ -115,7 +115,7 @@ void FixGravityKokkos::operator()(TagFixGravityMass, const int i, do namespace LAMMPS_NS { template class FixGravityKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixGravityKokkos; #endif } diff --git a/src/KOKKOS/fix_langevin_kokkos.cpp b/src/KOKKOS/fix_langevin_kokkos.cpp index 244b20ea18..a8cc072ffc 100644 --- a/src/KOKKOS/fix_langevin_kokkos.cpp +++ b/src/KOKKOS/fix_langevin_kokkos.cpp @@ -909,7 +909,7 @@ void FixLangevinKokkos::cleanup_copy() namespace LAMMPS_NS { template class FixLangevinKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixLangevinKokkos; #endif } diff --git a/src/KOKKOS/fix_momentum_kokkos.cpp b/src/KOKKOS/fix_momentum_kokkos.cpp index 2d4911bfda..9c9d6cb1cd 100644 --- a/src/KOKKOS/fix_momentum_kokkos.cpp +++ b/src/KOKKOS/fix_momentum_kokkos.cpp @@ -199,7 +199,7 @@ void FixMomentumKokkos::end_of_step() namespace LAMMPS_NS { template class FixMomentumKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixMomentumKokkos; #endif } diff --git a/src/KOKKOS/fix_neigh_history_kokkos.cpp b/src/KOKKOS/fix_neigh_history_kokkos.cpp index 8c33f6f2c3..848940c4b7 100644 --- a/src/KOKKOS/fix_neigh_history_kokkos.cpp +++ b/src/KOKKOS/fix_neigh_history_kokkos.cpp @@ -343,7 +343,7 @@ int FixNeighHistoryKokkos::unpack_exchange(int nlocal, double *buf) namespace LAMMPS_NS { template class FixNeighHistoryKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNeighHistoryKokkos; #endif } diff --git a/src/KOKKOS/fix_nh_kokkos.cpp b/src/KOKKOS/fix_nh_kokkos.cpp index 578f2f5c70..46993994b1 100644 --- a/src/KOKKOS/fix_nh_kokkos.cpp +++ b/src/KOKKOS/fix_nh_kokkos.cpp @@ -735,7 +735,7 @@ void FixNHKokkos::pre_exchange() namespace LAMMPS_NS { template class FixNHKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNHKokkos; #endif } diff --git a/src/KOKKOS/fix_nph_kokkos.cpp b/src/KOKKOS/fix_nph_kokkos.cpp index 3830860fd7..d667e29221 100644 --- a/src/KOKKOS/fix_nph_kokkos.cpp +++ b/src/KOKKOS/fix_nph_kokkos.cpp @@ -71,7 +71,7 @@ FixNPHKokkos::FixNPHKokkos(LAMMPS *lmp, int narg, char **arg) : namespace LAMMPS_NS { template class FixNPHKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNPHKokkos; #endif } diff --git a/src/KOKKOS/fix_npt_kokkos.cpp b/src/KOKKOS/fix_npt_kokkos.cpp index 5b751c9e4d..47b3da4efe 100644 --- a/src/KOKKOS/fix_npt_kokkos.cpp +++ b/src/KOKKOS/fix_npt_kokkos.cpp @@ -71,7 +71,7 @@ FixNPTKokkos::FixNPTKokkos(LAMMPS *lmp, int narg, char **arg) : namespace LAMMPS_NS { template class FixNPTKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNPTKokkos; #endif } diff --git a/src/KOKKOS/fix_nve_kokkos.cpp b/src/KOKKOS/fix_nve_kokkos.cpp index f94b68dbce..3198557ee7 100644 --- a/src/KOKKOS/fix_nve_kokkos.cpp +++ b/src/KOKKOS/fix_nve_kokkos.cpp @@ -172,7 +172,7 @@ void FixNVEKokkos::cleanup_copy() namespace LAMMPS_NS { template class FixNVEKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNVEKokkos; #endif } diff --git a/src/KOKKOS/fix_nve_sphere_kokkos.cpp b/src/KOKKOS/fix_nve_sphere_kokkos.cpp index 95945a858f..13d9fef69c 100644 --- a/src/KOKKOS/fix_nve_sphere_kokkos.cpp +++ b/src/KOKKOS/fix_nve_sphere_kokkos.cpp @@ -149,7 +149,7 @@ void FixNVESphereKokkos::final_integrate_item(const int i) const namespace LAMMPS_NS { template class FixNVESphereKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNVESphereKokkos; #endif } diff --git a/src/KOKKOS/fix_nvt_kokkos.cpp b/src/KOKKOS/fix_nvt_kokkos.cpp index 66165dd7bc..013095abc0 100644 --- a/src/KOKKOS/fix_nvt_kokkos.cpp +++ b/src/KOKKOS/fix_nvt_kokkos.cpp @@ -52,7 +52,7 @@ FixNVTKokkos::FixNVTKokkos(LAMMPS *lmp, int narg, char **arg) : namespace LAMMPS_NS { template class FixNVTKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixNVTKokkos; #endif } diff --git a/src/KOKKOS/fix_qeq_reax_kokkos.cpp b/src/KOKKOS/fix_qeq_reax_kokkos.cpp index d0aedd5fc2..c7159d2637 100644 --- a/src/KOKKOS/fix_qeq_reax_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reax_kokkos.cpp @@ -1524,7 +1524,7 @@ int FixQEqReaxKokkos::unpack_exchange(int nlocal, double *buf) namespace LAMMPS_NS { template class FixQEqReaxKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixQEqReaxKokkos; #endif } diff --git a/src/KOKKOS/fix_rx_kokkos.cpp b/src/KOKKOS/fix_rx_kokkos.cpp index 2ec3e3a77c..0f7739cd67 100644 --- a/src/KOKKOS/fix_rx_kokkos.cpp +++ b/src/KOKKOS/fix_rx_kokkos.cpp @@ -2275,7 +2275,7 @@ void FixRxKokkos::unpack_reverse_comm(int n, int *list, double *buf) namespace LAMMPS_NS { template class FixRxKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixRxKokkos; #endif } diff --git a/src/KOKKOS/fix_setforce_kokkos.cpp b/src/KOKKOS/fix_setforce_kokkos.cpp index 4763f04e70..da516f5ba2 100644 --- a/src/KOKKOS/fix_setforce_kokkos.cpp +++ b/src/KOKKOS/fix_setforce_kokkos.cpp @@ -184,7 +184,7 @@ void FixSetForceKokkos::operator()(TagFixSetForceNonConstant, const namespace LAMMPS_NS { template class FixSetForceKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixSetForceKokkos; #endif } diff --git a/src/KOKKOS/fix_shardlow_kokkos.cpp b/src/KOKKOS/fix_shardlow_kokkos.cpp index c6ad47501a..c44294b2ff 100644 --- a/src/KOKKOS/fix_shardlow_kokkos.cpp +++ b/src/KOKKOS/fix_shardlow_kokkos.cpp @@ -800,7 +800,7 @@ double FixShardlowKokkos::memory_usage() namespace LAMMPS_NS { template class FixShardlowKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixShardlowKokkos; #endif } diff --git a/src/KOKKOS/fix_wall_lj93_kokkos.cpp b/src/KOKKOS/fix_wall_lj93_kokkos.cpp index 61346144c8..4acf16c15b 100644 --- a/src/KOKKOS/fix_wall_lj93_kokkos.cpp +++ b/src/KOKKOS/fix_wall_lj93_kokkos.cpp @@ -98,7 +98,7 @@ void FixWallLJ93Kokkos::wall_particle_item(int i, value_type ewall) namespace LAMMPS_NS { template class FixWallLJ93Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixWallLJ93Kokkos; #endif } diff --git a/src/KOKKOS/fix_wall_reflect_kokkos.cpp b/src/KOKKOS/fix_wall_reflect_kokkos.cpp index ba104d19a9..a5bd6e6e6c 100644 --- a/src/KOKKOS/fix_wall_reflect_kokkos.cpp +++ b/src/KOKKOS/fix_wall_reflect_kokkos.cpp @@ -107,7 +107,7 @@ void FixWallReflectKokkos::operator()(TagFixWallReflectPostIntegrate namespace LAMMPS_NS { template class FixWallReflectKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class FixWallReflectKokkos; #endif } diff --git a/src/KOKKOS/gridcomm_kokkos.cpp b/src/KOKKOS/gridcomm_kokkos.cpp index bdf816b647..024428366e 100644 --- a/src/KOKKOS/gridcomm_kokkos.cpp +++ b/src/KOKKOS/gridcomm_kokkos.cpp @@ -652,7 +652,7 @@ double GridCommKokkos::memory_usage() namespace LAMMPS_NS { template class GridCommKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class GridCommKokkos; #endif } diff --git a/src/KOKKOS/improper_class2_kokkos.cpp b/src/KOKKOS/improper_class2_kokkos.cpp index fcc9592b19..320caecc83 100644 --- a/src/KOKKOS/improper_class2_kokkos.cpp +++ b/src/KOKKOS/improper_class2_kokkos.cpp @@ -1126,7 +1126,7 @@ void ImproperClass2Kokkos::ev_tally(EV_FLOAT &ev, const int i1, cons namespace LAMMPS_NS { template class ImproperClass2Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class ImproperClass2Kokkos; #endif } diff --git a/src/KOKKOS/improper_harmonic_kokkos.cpp b/src/KOKKOS/improper_harmonic_kokkos.cpp index 6f2969722a..124e56120b 100644 --- a/src/KOKKOS/improper_harmonic_kokkos.cpp +++ b/src/KOKKOS/improper_harmonic_kokkos.cpp @@ -477,7 +477,7 @@ void ImproperHarmonicKokkos::ev_tally(EV_FLOAT &ev, const int i1, co namespace LAMMPS_NS { template class ImproperHarmonicKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class ImproperHarmonicKokkos; #endif } diff --git a/src/KOKKOS/kissfft_kokkos.cpp b/src/KOKKOS/kissfft_kokkos.cpp index 5cfb3aa64c..ac8b1ef9cc 100644 --- a/src/KOKKOS/kissfft_kokkos.cpp +++ b/src/KOKKOS/kissfft_kokkos.cpp @@ -14,7 +14,7 @@ namespace LAMMPS_NS { template class KissFFTKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class KissFFTKokkos; #endif } diff --git a/src/KOKKOS/kokkos.cpp b/src/KOKKOS/kokkos.cpp index f54df5cb76..a19b53a75b 100644 --- a/src/KOKKOS/kokkos.cpp +++ b/src/KOKKOS/kokkos.cpp @@ -100,8 +100,8 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) } else if (strcmp(arg[iarg],"g") == 0 || strcmp(arg[iarg],"gpus") == 0) { -#ifndef KOKKOS_ENABLE_CUDA - error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA"); +#if !defined(KOKKOS_ENABLE_CUDA) && !defined(KOKKOS_ENABLE_HIP) + error->all(FLERR,"GPUs are requested but Kokkos has not been compiled for CUDA or HIP"); #endif if (iarg+2 > narg) error->all(FLERR,"Invalid Kokkos command-line args"); ngpus = atoi(arg[iarg+1]); @@ -164,9 +164,9 @@ KokkosLMP::KokkosLMP(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) if (logfile) fprintf(logfile," will use up to %d GPU(s) per node\n",ngpus); } -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU if (ngpus <= 0) - error->all(FLERR,"Kokkos has been compiled for CUDA but no GPUs are requested"); + error->all(FLERR,"Kokkos has been compiled for CUDA or HIP but no GPUs are requested"); #endif #ifndef KOKKOS_ENABLE_SERIAL diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 3bd8ac3f1e..54488f790d 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -29,6 +29,10 @@ enum{FULL=1u,HALFTHREAD=2u,HALF=4u}; #define ISFINITE(x) std::isfinite(x) #endif +#if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP) +#define LMP_KOKKOS_GPU +#endif + #define MAX_TYPES_STACKPARAMS 12 #define NeighClusterSize 8 @@ -186,6 +190,7 @@ template<> struct ExecutionSpaceFromDevice { static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Host; }; + #ifdef KOKKOS_ENABLE_CUDA template<> struct ExecutionSpaceFromDevice { @@ -193,6 +198,13 @@ struct ExecutionSpaceFromDevice { }; #endif +#if defined(KOKKOS_ENABLE_HIP) +template<> +struct ExecutionSpaceFromDevice { + static const LAMMPS_NS::ExecutionSpace space = LAMMPS_NS::Device; +}; +#endif + // Determine memory traits for force array // Do atomic trait when running HALFTHREAD neighbor list style @@ -221,6 +233,13 @@ struct AtomicDup { }; #endif +#if defined(KOKKOS_ENABLE_HIP) +template<> +struct AtomicDup { + enum {value = Kokkos::Experimental::ScatterAtomic}; +}; +#endif + #ifdef LMP_KOKKOS_USE_ATOMICS #ifdef KOKKOS_ENABLE_OPENMP @@ -753,7 +772,7 @@ typedef tdual_neighbors_2d::t_dev_const_randomread t_neighbors_2d_randomread; }; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template <> struct ArrayTypes { @@ -1087,7 +1106,7 @@ typedef SNAComplex SNAcomplex; #define ISFINITE(x) std::isfinite(x) #endif -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU #define LAMMPS_LAMBDA [=] __device__ #else #define LAMMPS_LAMBDA [=] diff --git a/src/KOKKOS/nbin_kokkos.cpp b/src/KOKKOS/nbin_kokkos.cpp index 5fc3a89732..9b41dc1bff 100644 --- a/src/KOKKOS/nbin_kokkos.cpp +++ b/src/KOKKOS/nbin_kokkos.cpp @@ -147,7 +147,7 @@ void NBinKokkos::binatomsItem(const int &i) const namespace LAMMPS_NS { template class NBinKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NBinKokkos; #endif } diff --git a/src/KOKKOS/nbin_ssa_kokkos.cpp b/src/KOKKOS/nbin_ssa_kokkos.cpp index 0e46f7fc61..2d9411e707 100644 --- a/src/KOKKOS/nbin_ssa_kokkos.cpp +++ b/src/KOKKOS/nbin_ssa_kokkos.cpp @@ -298,7 +298,7 @@ void NBinSSAKokkos::sortBin( namespace LAMMPS_NS { template class NBinSSAKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NBinSSAKokkos; #endif } diff --git a/src/KOKKOS/neigh_bond_kokkos.cpp b/src/KOKKOS/neigh_bond_kokkos.cpp index 34858ff1e1..b815a084fb 100644 --- a/src/KOKKOS/neigh_bond_kokkos.cpp +++ b/src/KOKKOS/neigh_bond_kokkos.cpp @@ -1305,7 +1305,7 @@ void NeighBondKokkos::update_domain_variables() namespace LAMMPS_NS { template class NeighBondKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NeighBondKokkos; #endif } diff --git a/src/KOKKOS/neigh_list_kokkos.cpp b/src/KOKKOS/neigh_list_kokkos.cpp index afaf0dd1b8..ab0cec15aa 100644 --- a/src/KOKKOS/neigh_list_kokkos.cpp +++ b/src/KOKKOS/neigh_list_kokkos.cpp @@ -52,7 +52,7 @@ void NeighListKokkos::grow(int nmax) namespace LAMMPS_NS { template class NeighListKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NeighListKokkos; #endif } diff --git a/src/KOKKOS/npair_copy_kokkos.cpp b/src/KOKKOS/npair_copy_kokkos.cpp index 016d68400f..98f4b29c1c 100644 --- a/src/KOKKOS/npair_copy_kokkos.cpp +++ b/src/KOKKOS/npair_copy_kokkos.cpp @@ -122,7 +122,7 @@ void NPairCopyKokkos::copy_to_cpu(NeighList *list) namespace LAMMPS_NS { template class NPairCopyKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NPairCopyKokkos; #endif } diff --git a/src/KOKKOS/npair_halffull_kokkos.cpp b/src/KOKKOS/npair_halffull_kokkos.cpp index 754a5ca010..b109010935 100644 --- a/src/KOKKOS/npair_halffull_kokkos.cpp +++ b/src/KOKKOS/npair_halffull_kokkos.cpp @@ -123,7 +123,7 @@ void NPairHalffullKokkos::operator()(TagNPairHalffullCompute, namespace LAMMPS_NS { template class NPairHalffullKokkos; template class NPairHalffullKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NPairHalffullKokkos; template class NPairHalffullKokkos; #endif diff --git a/src/KOKKOS/npair_kokkos.cpp b/src/KOKKOS/npair_kokkos.cpp index 0a2d05096c..66daccc981 100644 --- a/src/KOKKOS/npair_kokkos.cpp +++ b/src/KOKKOS/npair_kokkos.cpp @@ -1154,7 +1154,7 @@ template class NPairKokkos; template class NPairKokkos; template class NPairKokkos; template class NPairKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NPairKokkos; template class NPairKokkos; template class NPairKokkos; diff --git a/src/KOKKOS/npair_skip_kokkos.cpp b/src/KOKKOS/npair_skip_kokkos.cpp index bb393c9b95..13080a9580 100644 --- a/src/KOKKOS/npair_skip_kokkos.cpp +++ b/src/KOKKOS/npair_skip_kokkos.cpp @@ -147,7 +147,7 @@ void NPairSkipKokkos::operator()(TagNPairSkipCountLocal, const int & namespace LAMMPS_NS { template class NPairSkipKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NPairSkipKokkos; #endif } diff --git a/src/KOKKOS/npair_ssa_kokkos.cpp b/src/KOKKOS/npair_ssa_kokkos.cpp index b6d03e1445..6f7342d77a 100644 --- a/src/KOKKOS/npair_ssa_kokkos.cpp +++ b/src/KOKKOS/npair_ssa_kokkos.cpp @@ -753,7 +753,7 @@ void NPairSSAKokkosExecute::build_ghosts_onePhase(int workPhase) con namespace LAMMPS_NS { template class NPairSSAKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class NPairSSAKokkos; #endif } diff --git a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp index 46c5ee82cb..a6af4708d5 100644 --- a/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_buck_coul_cut_kokkos.cpp @@ -352,7 +352,7 @@ double PairBuckCoulCutKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairBuckCoulCutKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairBuckCoulCutKokkos; #endif } diff --git a/src/KOKKOS/pair_buck_coul_long_kokkos.cpp b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp index 29aca38a77..cdf3b0a6c1 100644 --- a/src/KOKKOS/pair_buck_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_buck_coul_long_kokkos.cpp @@ -515,7 +515,7 @@ double PairBuckCoulLongKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairBuckCoulLongKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairBuckCoulLongKokkos; #endif } diff --git a/src/KOKKOS/pair_buck_kokkos.cpp b/src/KOKKOS/pair_buck_kokkos.cpp index 04ebd6608b..71f63a9f92 100644 --- a/src/KOKKOS/pair_buck_kokkos.cpp +++ b/src/KOKKOS/pair_buck_kokkos.cpp @@ -264,7 +264,7 @@ double PairBuckKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairBuckKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairBuckKokkos; #endif } diff --git a/src/KOKKOS/pair_coul_cut_kokkos.cpp b/src/KOKKOS/pair_coul_cut_kokkos.cpp index 2e3f76463d..2047286181 100644 --- a/src/KOKKOS/pair_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_coul_cut_kokkos.cpp @@ -270,7 +270,7 @@ double PairCoulCutKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairCoulCutKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairCoulCutKokkos; #endif } diff --git a/src/KOKKOS/pair_coul_debye_kokkos.cpp b/src/KOKKOS/pair_coul_debye_kokkos.cpp index a544a5fb8d..cddfc63b4d 100644 --- a/src/KOKKOS/pair_coul_debye_kokkos.cpp +++ b/src/KOKKOS/pair_coul_debye_kokkos.cpp @@ -313,7 +313,7 @@ double PairCoulDebyeKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairCoulDebyeKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairCoulDebyeKokkos; #endif } diff --git a/src/KOKKOS/pair_coul_dsf_kokkos.cpp b/src/KOKKOS/pair_coul_dsf_kokkos.cpp index 62e205d8fd..11ca10c7be 100644 --- a/src/KOKKOS/pair_coul_dsf_kokkos.cpp +++ b/src/KOKKOS/pair_coul_dsf_kokkos.cpp @@ -414,7 +414,7 @@ int PairCoulDSFKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairCoulDSFKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairCoulDSFKokkos; #endif } diff --git a/src/KOKKOS/pair_coul_long_kokkos.cpp b/src/KOKKOS/pair_coul_long_kokkos.cpp index c1f630a7a1..123763ea29 100644 --- a/src/KOKKOS/pair_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_coul_long_kokkos.cpp @@ -464,7 +464,7 @@ double PairCoulLongKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairCoulLongKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairCoulLongKokkos; #endif } diff --git a/src/KOKKOS/pair_coul_wolf_kokkos.cpp b/src/KOKKOS/pair_coul_wolf_kokkos.cpp index 907d088348..3bbb32a125 100644 --- a/src/KOKKOS/pair_coul_wolf_kokkos.cpp +++ b/src/KOKKOS/pair_coul_wolf_kokkos.cpp @@ -416,7 +416,7 @@ int PairCoulWolfKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairCoulWolfKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairCoulWolfKokkos; #endif } diff --git a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp index 61d2707888..f4dc0e867c 100644 --- a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp +++ b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp @@ -788,7 +788,7 @@ int PairDPDfdtEnergyKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairDPDfdtEnergyKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairDPDfdtEnergyKokkos; #endif } diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.cpp b/src/KOKKOS/pair_eam_alloy_kokkos.cpp index bea1b28544..96a07628e8 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.cpp +++ b/src/KOKKOS/pair_eam_alloy_kokkos.cpp @@ -1223,7 +1223,7 @@ void PairEAMAlloyKokkos::file2array_alloy() namespace LAMMPS_NS { template class PairEAMAlloyKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairEAMAlloyKokkos; #endif } diff --git a/src/KOKKOS/pair_eam_fs_kokkos.cpp b/src/KOKKOS/pair_eam_fs_kokkos.cpp index 978883ab58..4f3302b455 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.cpp +++ b/src/KOKKOS/pair_eam_fs_kokkos.cpp @@ -1233,7 +1233,7 @@ void PairEAMFSKokkos::file2array_fs() namespace LAMMPS_NS { template class PairEAMFSKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairEAMFSKokkos; #endif } diff --git a/src/KOKKOS/pair_eam_kokkos.cpp b/src/KOKKOS/pair_eam_kokkos.cpp index 99a0756610..f0ac646b6b 100644 --- a/src/KOKKOS/pair_eam_kokkos.cpp +++ b/src/KOKKOS/pair_eam_kokkos.cpp @@ -896,7 +896,7 @@ void PairEAMKokkos::ev_tally(EV_FLOAT &ev, const int &i, const int & namespace LAMMPS_NS { template class PairEAMKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairEAMKokkos; #endif } diff --git a/src/KOKKOS/pair_exp6_rx_kokkos.cpp b/src/KOKKOS/pair_exp6_rx_kokkos.cpp index 8c98e32d5b..a41ef0e6d1 100644 --- a/src/KOKKOS/pair_exp6_rx_kokkos.cpp +++ b/src/KOKKOS/pair_exp6_rx_kokkos.cpp @@ -232,7 +232,7 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) } else Kokkos::parallel_for(Kokkos::RangePolicy(0,np_total),*this); -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU Kokkos::parallel_for(Kokkos::RangePolicy(0,np_total),*this); #else int errorFlag = 0; @@ -277,7 +277,7 @@ void PairExp6rxKokkos::compute(int eflag_in, int vflag_in) EV_FLOAT ev; -#ifdef KOKKOS_ENABLE_CUDA // Use atomics +#ifdef LMP_KOKKOS_GPU // Use atomics if (neighflag == HALF) { if (newton_pair) { @@ -2654,7 +2654,7 @@ int PairExp6rxKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairExp6rxKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairExp6rxKokkos; #endif } diff --git a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp index bc5eb30845..07ef629e77 100644 --- a/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp +++ b/src/KOKKOS/pair_gran_hooke_history_kokkos.cpp @@ -585,7 +585,7 @@ void PairGranHookeHistoryKokkos::ev_tally_xyz_atom(EV_FLOAT &ev, int namespace LAMMPS_NS { template class PairGranHookeHistoryKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairGranHookeHistoryKokkos; #endif } diff --git a/src/KOKKOS/pair_kokkos.h b/src/KOKKOS/pair_kokkos.h index 2934ddf621..06458948ef 100644 --- a/src/KOKKOS/pair_kokkos.h +++ b/src/KOKKOS/pair_kokkos.h @@ -720,7 +720,7 @@ int GetTeamSize(FunctorStyle& functor, int inum, int reduce_flag, int team_size, else team_size_max = Kokkos::TeamPolicy<>(inum,Kokkos::AUTO).team_size_max(functor,Kokkos::ParallelForTag()); -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU if(team_size*vector_length > team_size_max) team_size = team_size_max/vector_length; #else diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp index 3996f49c29..c8c6e54a5f 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_implicit_kokkos.cpp @@ -520,7 +520,7 @@ double PairLJCharmmCoulCharmmImplicitKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCharmmCoulCharmmImplicitKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCharmmCoulCharmmImplicitKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp index 44ba78fa7d..62adc84ab0 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_charmm_kokkos.cpp @@ -522,7 +522,7 @@ double PairLJCharmmCoulCharmmKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCharmmCoulCharmmKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCharmmCoulCharmmKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp index 35724c7061..4c122773d7 100644 --- a/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_charmm_coul_long_kokkos.cpp @@ -529,7 +529,7 @@ double PairLJCharmmCoulLongKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCharmmCoulLongKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCharmmCoulLongKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp index b8c72d7b88..4317029ab9 100644 --- a/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_coul_cut_kokkos.cpp @@ -355,7 +355,7 @@ double PairLJClass2CoulCutKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJClass2CoulCutKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJClass2CoulCutKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp index 1e01a275a4..51193bf692 100644 --- a/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_coul_long_kokkos.cpp @@ -510,7 +510,7 @@ double PairLJClass2CoulLongKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJClass2CoulLongKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJClass2CoulLongKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_class2_kokkos.cpp b/src/KOKKOS/pair_lj_class2_kokkos.cpp index 5bac4c8140..a0d2fba581 100644 --- a/src/KOKKOS/pair_lj_class2_kokkos.cpp +++ b/src/KOKKOS/pair_lj_class2_kokkos.cpp @@ -282,7 +282,7 @@ double PairLJClass2Kokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJClass2Kokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJClass2Kokkos; #endif } diff --git a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp index e2b57e8df7..ebfb484836 100644 --- a/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_cut_kokkos.cpp @@ -347,7 +347,7 @@ double PairLJCutCoulCutKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCutCoulCutKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCutCoulCutKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp index bc8369fd65..0e5b5999cd 100644 --- a/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_debye_kokkos.cpp @@ -376,7 +376,7 @@ double PairLJCutCoulDebyeKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCutCoulDebyeKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCutCoulDebyeKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp index feb6a58136..8690859cd8 100644 --- a/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_dsf_kokkos.cpp @@ -369,7 +369,7 @@ double PairLJCutCoulDSFKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCutCoulDSFKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCutCoulDSFKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp index 595f018857..8cbfe03597 100644 --- a/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_coul_long_kokkos.cpp @@ -510,7 +510,7 @@ double PairLJCutCoulLongKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCutCoulLongKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCutCoulLongKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_cut_kokkos.cpp b/src/KOKKOS/pair_lj_cut_kokkos.cpp index 5eb0a5b91a..8294d62f68 100644 --- a/src/KOKKOS/pair_lj_cut_kokkos.cpp +++ b/src/KOKKOS/pair_lj_cut_kokkos.cpp @@ -278,7 +278,7 @@ double PairLJCutKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJCutKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJCutKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_expand_kokkos.cpp b/src/KOKKOS/pair_lj_expand_kokkos.cpp index 0409eda401..93385b7c70 100644 --- a/src/KOKKOS/pair_lj_expand_kokkos.cpp +++ b/src/KOKKOS/pair_lj_expand_kokkos.cpp @@ -287,7 +287,7 @@ double PairLJExpandKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJExpandKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJExpandKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp index de475fbc99..fa9ca453a8 100644 --- a/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_coul_gromacs_kokkos.cpp @@ -509,7 +509,7 @@ double PairLJGromacsCoulGromacsKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJGromacsCoulGromacsKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJGromacsCoulGromacsKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp index fa2ab64ece..ed1e38a346 100644 --- a/src/KOKKOS/pair_lj_gromacs_kokkos.cpp +++ b/src/KOKKOS/pair_lj_gromacs_kokkos.cpp @@ -341,7 +341,7 @@ double PairLJGromacsKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJGromacsKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJGromacsKokkos; #endif } diff --git a/src/KOKKOS/pair_lj_sdk_kokkos.cpp b/src/KOKKOS/pair_lj_sdk_kokkos.cpp index 70d04385d0..8b228f2c01 100644 --- a/src/KOKKOS/pair_lj_sdk_kokkos.cpp +++ b/src/KOKKOS/pair_lj_sdk_kokkos.cpp @@ -317,7 +317,7 @@ double PairLJSDKKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairLJSDKKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairLJSDKKokkos; #endif } diff --git a/src/KOKKOS/pair_morse_kokkos.cpp b/src/KOKKOS/pair_morse_kokkos.cpp index 16d4d8a0a3..ba6e9ba97d 100644 --- a/src/KOKKOS/pair_morse_kokkos.cpp +++ b/src/KOKKOS/pair_morse_kokkos.cpp @@ -295,7 +295,7 @@ double PairMorseKokkos::init_one(int i, int j) namespace LAMMPS_NS { template class PairMorseKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairMorseKokkos; #endif } diff --git a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp index edf8bb38ae..ca609f72b7 100644 --- a/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp +++ b/src/KOKKOS/pair_multi_lucy_rx_kokkos.cpp @@ -987,7 +987,7 @@ void PairMultiLucyRXKokkos::settings(int narg, char **arg) namespace LAMMPS_NS { template class PairMultiLucyRXKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairMultiLucyRXKokkos; #endif } diff --git a/src/KOKKOS/pair_reaxc_kokkos.cpp b/src/KOKKOS/pair_reaxc_kokkos.cpp index 2fdaddcf8d..201167f992 100644 --- a/src/KOKKOS/pair_reaxc_kokkos.cpp +++ b/src/KOKKOS/pair_reaxc_kokkos.cpp @@ -3958,7 +3958,7 @@ void PairReaxCKokkos::operator()(PairReaxFindBondSpecies, const int } template class PairReaxCKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairReaxCKokkos; #endif } diff --git a/src/KOKKOS/pair_snap_kokkos.cpp b/src/KOKKOS/pair_snap_kokkos.cpp index 76d6aa5462..baccd0476a 100644 --- a/src/KOKKOS/pair_snap_kokkos.cpp +++ b/src/KOKKOS/pair_snap_kokkos.cpp @@ -16,7 +16,7 @@ namespace LAMMPS_NS { template class PairSNAPKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairSNAPKokkos; #endif } diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 35da0e8502..74bc26ef17 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -296,7 +296,7 @@ void PairSNAPKokkos::compute(int eflag_in, int vflag_in) } } else { // GPU -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU //PreUi { int vector_length = vector_length_default; diff --git a/src/KOKKOS/pair_sw_kokkos.cpp b/src/KOKKOS/pair_sw_kokkos.cpp index 4ca75ebd2e..4b5e9eafe2 100644 --- a/src/KOKKOS/pair_sw_kokkos.cpp +++ b/src/KOKKOS/pair_sw_kokkos.cpp @@ -967,7 +967,7 @@ void PairSWKokkos::ev_tally3_atom(EV_FLOAT &ev, const int &i, namespace LAMMPS_NS { template class PairSWKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairSWKokkos; #endif } diff --git a/src/KOKKOS/pair_table_kokkos.cpp b/src/KOKKOS/pair_table_kokkos.cpp index b2aaaf1566..721deb84f3 100644 --- a/src/KOKKOS/pair_table_kokkos.cpp +++ b/src/KOKKOS/pair_table_kokkos.cpp @@ -530,7 +530,7 @@ void PairTableKokkos::cleanup_copy() { namespace LAMMPS_NS { template class PairTableKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairTableKokkos; #endif diff --git a/src/KOKKOS/pair_table_rx_kokkos.cpp b/src/KOKKOS/pair_table_rx_kokkos.cpp index 2b066d7633..0efef97eb5 100644 --- a/src/KOKKOS/pair_table_rx_kokkos.cpp +++ b/src/KOKKOS/pair_table_rx_kokkos.cpp @@ -1297,7 +1297,7 @@ void PairTableRXKokkos::cleanup_copy() { namespace LAMMPS_NS { template class PairTableRXKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairTableRXKokkos; #endif diff --git a/src/KOKKOS/pair_tersoff_kokkos.cpp b/src/KOKKOS/pair_tersoff_kokkos.cpp index 134431aa44..910e8da4f3 100644 --- a/src/KOKKOS/pair_tersoff_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_kokkos.cpp @@ -1282,7 +1282,7 @@ int PairTersoffKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairTersoffKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairTersoffKokkos; #endif } diff --git a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp index ceb1ed1383..d51983bfc8 100644 --- a/src/KOKKOS/pair_tersoff_mod_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_mod_kokkos.cpp @@ -1285,7 +1285,7 @@ int PairTersoffMODKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairTersoffMODKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairTersoffMODKokkos; #endif } diff --git a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp index c7a08772c8..9c8bb6e1a5 100644 --- a/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_tersoff_zbl_kokkos.cpp @@ -1381,7 +1381,7 @@ int PairTersoffZBLKokkos::sbmask(const int& j) const { namespace LAMMPS_NS { template class PairTersoffZBLKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairTersoffZBLKokkos; #endif } diff --git a/src/KOKKOS/pair_vashishta_kokkos.cpp b/src/KOKKOS/pair_vashishta_kokkos.cpp index 1d46fe3cd2..47ffe64105 100644 --- a/src/KOKKOS/pair_vashishta_kokkos.cpp +++ b/src/KOKKOS/pair_vashishta_kokkos.cpp @@ -942,7 +942,7 @@ void PairVashishtaKokkos::ev_tally3_atom(EV_FLOAT &ev, const int &i, namespace LAMMPS_NS { template class PairVashishtaKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairVashishtaKokkos; #endif } diff --git a/src/KOKKOS/pair_yukawa_kokkos.cpp b/src/KOKKOS/pair_yukawa_kokkos.cpp index 5b641791d3..71236c807c 100644 --- a/src/KOKKOS/pair_yukawa_kokkos.cpp +++ b/src/KOKKOS/pair_yukawa_kokkos.cpp @@ -290,7 +290,7 @@ compute_evdwl(const F_FLOAT& rsq, const int& i, const int&j, namespace LAMMPS_NS { template class PairYukawaKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairYukawaKokkos; #endif } diff --git a/src/KOKKOS/pair_zbl_kokkos.cpp b/src/KOKKOS/pair_zbl_kokkos.cpp index 5e4ec398d9..8b583a75f7 100644 --- a/src/KOKKOS/pair_zbl_kokkos.cpp +++ b/src/KOKKOS/pair_zbl_kokkos.cpp @@ -423,7 +423,7 @@ void PairZBLKokkos::cleanup_copy() { namespace LAMMPS_NS { template class PairZBLKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PairZBLKokkos; #endif } diff --git a/src/KOKKOS/pppm_kokkos.cpp b/src/KOKKOS/pppm_kokkos.cpp index 8a87773816..743f2daec9 100644 --- a/src/KOKKOS/pppm_kokkos.cpp +++ b/src/KOKKOS/pppm_kokkos.cpp @@ -1627,7 +1627,7 @@ void PPPMKokkos::make_rho() nlocal = atomKK->nlocal; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU copymode = 1; Kokkos::parallel_for(Kokkos::RangePolicy(0,nlocal),*this); copymode = 0; @@ -3051,7 +3051,7 @@ double PPPMKokkos::memory_usage() namespace LAMMPS_NS { template class PPPMKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class PPPMKokkos; #endif } diff --git a/src/KOKKOS/pppm_kokkos.h b/src/KOKKOS/pppm_kokkos.h index 847a2f807f..56cd6f5140 100644 --- a/src/KOKKOS/pppm_kokkos.h +++ b/src/KOKKOS/pppm_kokkos.h @@ -31,7 +31,7 @@ KSpaceStyle(pppm/kk/host,PPPMKokkos) // fix up FFT defines for KOKKOS with CUDA -#if defined(KOKKOS_ENABLE_CUDA) +#ifdef KOKKOS_ENABLE_CUDA # if defined(FFT_FFTW) # undef FFT_FFTW # endif diff --git a/src/KOKKOS/rand_pool_wrap_kokkos.h b/src/KOKKOS/rand_pool_wrap_kokkos.h index c1461c5216..9124d8e9e7 100644 --- a/src/KOKKOS/rand_pool_wrap_kokkos.h +++ b/src/KOKKOS/rand_pool_wrap_kokkos.h @@ -50,7 +50,7 @@ class RandPoolWrap : protected Pointers { KOKKOS_INLINE_FUNCTION RandWrap get_state() const { -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU error->all(FLERR,"Cannot use Marsaglia RNG with GPUs"); #endif diff --git a/src/KOKKOS/region_block_kokkos.cpp b/src/KOKKOS/region_block_kokkos.cpp index b28230290e..da3122bd34 100644 --- a/src/KOKKOS/region_block_kokkos.cpp +++ b/src/KOKKOS/region_block_kokkos.cpp @@ -163,7 +163,7 @@ void RegBlockKokkos::rotate(double &x, double &y, double &z, double namespace LAMMPS_NS { template class RegBlockKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class RegBlockKokkos; #endif } diff --git a/src/KOKKOS/remap_kokkos.cpp b/src/KOKKOS/remap_kokkos.cpp index 604b438a89..2894009887 100644 --- a/src/KOKKOS/remap_kokkos.cpp +++ b/src/KOKKOS/remap_kokkos.cpp @@ -529,7 +529,7 @@ void RemapKokkos::remap_3d_destroy_plan_kokkos(struct remap_plan_3d_ namespace LAMMPS_NS { template class RemapKokkos; -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU template class RemapKokkos; #endif } diff --git a/src/KOKKOS/sna_kokkos_impl.h b/src/KOKKOS/sna_kokkos_impl.h index b017751c60..93d8347c5e 100644 --- a/src/KOKKOS/sna_kokkos_impl.h +++ b/src/KOKKOS/sna_kokkos_impl.h @@ -237,7 +237,7 @@ void SNAKokkos::grow_rij(int newnatom, int newnmax) element = t_sna_2i("sna:rcutij",natom,nmax); dedr = t_sna_3d("sna:dedr",natom,nmax,3); -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU if (std::is_same::value) { // dummy allocation ulisttot = t_sna_3c_ll("sna:ulisttot",1,1,1); @@ -269,7 +269,7 @@ void SNAKokkos::grow_rij(int newnatom, int newnmax) ylist_pack_im = t_sna_4d_ll("sna:ylist_pack_im",1,1,1,1); dulist = t_sna_4c3_ll("sna:dulist",idxu_max,natom,nmax); -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU } #endif } @@ -2029,7 +2029,7 @@ double SNAKokkos::memory_usage() bytes += jdimpq*jdimpq * sizeof(double); // pqarray bytes += idxcg_max * sizeof(double); // cglist -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU if (std::is_same::value) { int natom_pad = ((natom + 32 - 1) / 32) * 32; // for AoSoA layouts @@ -2055,7 +2055,7 @@ double SNAKokkos::memory_usage() bytes += natom * idxu_max * nelements * sizeof(double) * 2; // ylist bytes += natom * nmax * idxu_max * 3 * sizeof(double) * 2; // dulist -#ifdef KOKKOS_ENABLE_CUDA +#ifdef LMP_KOKKOS_GPU } #endif From 63cbbf96059e877ecd2de3f6446f33e14d5fdc6a Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Tue, 4 Aug 2020 13:17:57 -0400 Subject: [PATCH 064/122] Upgrade embedded fmt library to v7.0.2 --- src/fmt/chrono.h | 128 +-- src/fmt/color.h | 72 +- src/fmt/compile.h | 292 ++++-- src/fmt/core.h | 980 ++++++++++-------- src/fmt/format-inl.h | 178 ++-- src/fmt/format.h | 2276 +++++++++++++++++++++-------------------- src/fmt/locale.h | 32 +- src/fmt/os.h | 70 +- src/fmt/ostream.h | 21 +- src/fmt/printf.h | 147 +-- src/fmt/ranges.h | 71 +- src/fmtlib_format.cpp | 165 +-- src/fmtlib_os.cpp | 25 +- 13 files changed, 2357 insertions(+), 2100 deletions(-) diff --git a/src/fmt/chrono.h b/src/fmt/chrono.h index 421d464ad8..e70b8053a6 100644 --- a/src/fmt/chrono.h +++ b/src/fmt/chrono.h @@ -48,7 +48,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) { // From fits in To without any problem. } else { // From does not always fit in To, resort to a dynamic check. - if (from < T::min() || from > T::max()) { + if (from < (T::min)() || from > (T::max)()) { // outside range. ec = 1; return {}; @@ -74,7 +74,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) { if (F::is_signed && !T::is_signed) { // From may be negative, not allowed! - if (fmt::internal::is_negative(from)) { + if (fmt::detail::is_negative(from)) { ec = 1; return {}; } @@ -84,7 +84,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) { // yes, From always fits in To. } else { // from may not fit in To, we have to do a dynamic check - if (from > static_cast(T::max())) { + if (from > static_cast((T::max)())) { ec = 1; return {}; } @@ -97,7 +97,7 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) { // yes, From always fits in To. } else { // from may not fit in To, we have to do a dynamic check - if (from > static_cast(T::max())) { + if (from > static_cast((T::max)())) { // outside range. ec = 1; return {}; @@ -141,7 +141,7 @@ FMT_CONSTEXPR To safe_float_conversion(const From from, int& ec) { // catch the only happy case if (std::isfinite(from)) { - if (from >= T::lowest() && from <= T::max()) { + if (from >= T::lowest() && from <= (T::max)()) { return static_cast(from); } // not within range. @@ -195,12 +195,13 @@ To safe_duration_cast(std::chrono::duration from, } // multiply with Factor::num without overflow or underflow if (Factor::num != 1) { - const auto max1 = internal::max_value() / Factor::num; + const auto max1 = detail::max_value() / Factor::num; if (count > max1) { ec = 1; return {}; } - const auto min1 = std::numeric_limits::min() / Factor::num; + const auto min1 = + (std::numeric_limits::min)() / Factor::num; if (count < min1) { ec = 1; return {}; @@ -269,7 +270,7 @@ To safe_duration_cast(std::chrono::duration from, // multiply with Factor::num without overflow or underflow if (Factor::num != 1) { - constexpr auto max1 = internal::max_value() / + constexpr auto max1 = detail::max_value() / static_cast(Factor::num); if (count > max1) { ec = 1; @@ -306,12 +307,12 @@ To safe_duration_cast(std::chrono::duration from, // Usage: f FMT_NOMACRO() #define FMT_NOMACRO -namespace internal { +namespace detail { inline null<> localtime_r FMT_NOMACRO(...) { return null<>(); } inline null<> localtime_s(...) { return null<>(); } inline null<> gmtime_r(...) { return null<>(); } inline null<> gmtime_s(...) { return null<>(); } -} // namespace internal +} // namespace detail // Thread-safe replacement for std::localtime inline std::tm localtime(std::time_t time) { @@ -322,22 +323,22 @@ inline std::tm localtime(std::time_t time) { dispatcher(std::time_t t) : time_(t) {} bool run() { - using namespace fmt::internal; + using namespace fmt::detail; return handle(localtime_r(&time_, &tm_)); } bool handle(std::tm* tm) { return tm != nullptr; } - bool handle(internal::null<>) { - using namespace fmt::internal; + bool handle(detail::null<>) { + using namespace fmt::detail; return fallback(localtime_s(&tm_, &time_)); } bool fallback(int res) { return res == 0; } #if !FMT_MSC_VER - bool fallback(internal::null<>) { - using namespace fmt::internal; + bool fallback(detail::null<>) { + using namespace fmt::detail; std::tm* tm = std::localtime(&time_); if (tm) tm_ = *tm; return tm != nullptr; @@ -359,21 +360,21 @@ inline std::tm gmtime(std::time_t time) { dispatcher(std::time_t t) : time_(t) {} bool run() { - using namespace fmt::internal; + using namespace fmt::detail; return handle(gmtime_r(&time_, &tm_)); } bool handle(std::tm* tm) { return tm != nullptr; } - bool handle(internal::null<>) { - using namespace fmt::internal; + bool handle(detail::null<>) { + using namespace fmt::detail; return fallback(gmtime_s(&tm_, &time_)); } bool fallback(int res) { return res == 0; } #if !FMT_MSC_VER - bool fallback(internal::null<>) { + bool fallback(detail::null<>) { std::tm* tm = std::gmtime(&time_); if (tm) tm_ = *tm; return tm != nullptr; @@ -386,17 +387,17 @@ inline std::tm gmtime(std::time_t time) { return gt.tm_; } -namespace internal { -inline std::size_t strftime(char* str, std::size_t count, const char* format, - const std::tm* time) { +namespace detail { +inline size_t strftime(char* str, size_t count, const char* format, + const std::tm* time) { return std::strftime(str, count, format, time); } -inline std::size_t strftime(wchar_t* str, std::size_t count, - const wchar_t* format, const std::tm* time) { +inline size_t strftime(wchar_t* str, size_t count, const wchar_t* format, + const std::tm* time) { return std::wcsftime(str, count, format, time); } -} // namespace internal +} // namespace detail template struct formatter { template @@ -405,7 +406,7 @@ template struct formatter { if (it != ctx.end() && *it == ':') ++it; auto end = it; while (end != ctx.end() && *end != '}') ++end; - tm_format.reserve(internal::to_unsigned(end - it + 1)); + tm_format.reserve(detail::to_unsigned(end - it + 1)); tm_format.append(it, end); tm_format.push_back('\0'); return end; @@ -414,11 +415,10 @@ template struct formatter { template auto format(const std::tm& tm, FormatContext& ctx) -> decltype(ctx.out()) { basic_memory_buffer buf; - std::size_t start = buf.size(); + size_t start = buf.size(); for (;;) { - std::size_t size = buf.capacity() - start; - std::size_t count = - internal::strftime(&buf[start], size, &tm_format[0], &tm); + size_t size = buf.capacity() - start; + size_t count = detail::strftime(&buf[start], size, &tm_format[0], &tm); if (count != 0) { buf.resize(start + count); break; @@ -430,7 +430,7 @@ template struct formatter { // https://github.com/fmtlib/fmt/issues/367 break; } - const std::size_t MIN_GROWTH = 10; + const size_t MIN_GROWTH = 10; buf.reserve(buf.capacity() + (size > MIN_GROWTH ? size : MIN_GROWTH)); } return std::copy(buf.begin(), buf.end(), ctx.out()); @@ -439,7 +439,7 @@ template struct formatter { basic_memory_buffer tm_format; }; -namespace internal { +namespace detail { template FMT_CONSTEXPR const char* get_units() { return nullptr; } @@ -768,19 +768,25 @@ OutputIt format_duration_value(OutputIt out, Rep val, int precision) { return format_to(out, std::is_floating_point::value ? fp_f : format, val); } +template +OutputIt copy_unit(string_view unit, OutputIt out, Char) { + return std::copy(unit.begin(), unit.end(), out); +} + +template +OutputIt copy_unit(string_view unit, OutputIt out, wchar_t) { + // This works when wchar_t is UTF-32 because units only contain characters + // that have the same representation in UTF-16 and UTF-32. + utf8_to_utf16 u(unit); + return std::copy(u.c_str(), u.c_str() + u.size(), out); +} template OutputIt format_duration_unit(OutputIt out) { - if (const char* unit = get_units()) { - string_view s(unit); - if (const_check(std::is_same())) { - utf8_to_utf16 u(s); - return std::copy(u.c_str(), u.c_str() + u.size(), out); - } - return std::copy(s.begin(), s.end(), out); - } + if (const char* unit = get_units()) + return copy_unit(string_view(unit), out, Char()); const Char num_f[] = {'[', '{', '}', ']', 's', 0}; - if (Period::den == 1) return format_to(out, num_f, Period::num); + if (const_check(Period::den == 1)) return format_to(out, num_f, Period::num); const Char num_def_f[] = {'[', '{', '}', '/', '{', '}', ']', 's', 0}; return format_to(out, num_def_f, Period::num, Period::den); } @@ -874,9 +880,9 @@ struct chrono_formatter { if (isnan(value)) return write_nan(); uint32_or_64_or_128_t n = to_unsigned(to_nonnegative_int(value, max_value())); - int num_digits = internal::count_digits(n); + int num_digits = detail::count_digits(n); if (width > num_digits) out = std::fill_n(out, width - num_digits, '0'); - out = format_decimal(out, n, num_digits); + out = format_decimal(out, n, num_digits).end; } void write_nan() { std::copy_n("nan", 3, out); } @@ -1004,14 +1010,14 @@ struct chrono_formatter { out = format_duration_unit(out); } }; -} // namespace internal +} // namespace detail template struct formatter, Char> { private: basic_format_specs specs; int precision; - using arg_ref_type = internal::arg_ref; + using arg_ref_type = detail::arg_ref; arg_ref_type width_ref; arg_ref_type precision_ref; mutable basic_string_view format_str; @@ -1032,7 +1038,7 @@ struct formatter, Char> { return arg_ref_type(arg_id); } - FMT_CONSTEXPR arg_ref_type make_arg_ref(internal::auto_id) { + FMT_CONSTEXPR arg_ref_type make_arg_ref(detail::auto_id) { return arg_ref_type(context.next_arg_id()); } @@ -1062,17 +1068,17 @@ struct formatter, Char> { auto begin = ctx.begin(), end = ctx.end(); if (begin == end || *begin == '}') return {begin, begin}; spec_handler handler{*this, ctx, format_str}; - begin = internal::parse_align(begin, end, handler); + begin = detail::parse_align(begin, end, handler); if (begin == end) return {begin, begin}; - begin = internal::parse_width(begin, end, handler); + begin = detail::parse_width(begin, end, handler); if (begin == end) return {begin, begin}; if (*begin == '.') { if (std::is_floating_point::value) - begin = internal::parse_precision(begin, end, handler); + begin = detail::parse_precision(begin, end, handler); else handler.on_error("precision not allowed for this argument type"); } - end = parse_chrono_format(begin, end, internal::chrono_format_checker()); + end = parse_chrono_format(begin, end, detail::chrono_format_checker()); return {begin, end}; } @@ -1083,7 +1089,7 @@ struct formatter, Char> { -> decltype(ctx.begin()) { auto range = do_parse(ctx); format_str = basic_string_view( - &*range.begin, internal::to_unsigned(range.end - range.begin)); + &*range.begin, detail::to_unsigned(range.end - range.begin)); return range.end; } @@ -1094,23 +1100,21 @@ struct formatter, Char> { // is not specified. basic_memory_buffer buf; auto out = std::back_inserter(buf); - using range = internal::output_range; - internal::basic_writer w(range(ctx.out())); - internal::handle_dynamic_spec(specs.width, - width_ref, ctx); - internal::handle_dynamic_spec( - precision, precision_ref, ctx); + detail::handle_dynamic_spec(specs.width, width_ref, + ctx); + detail::handle_dynamic_spec(precision, + precision_ref, ctx); if (begin == end || *begin == '}') { - out = internal::format_duration_value(out, d.count(), precision); - internal::format_duration_unit(out); + out = detail::format_duration_value(out, d.count(), precision); + detail::format_duration_unit(out); } else { - internal::chrono_formatter f( + detail::chrono_formatter f( ctx, out, d); f.precision = precision; parse_chrono_format(begin, end, f); } - w.write(buf.data(), buf.size(), specs); - return w.out(); + return detail::write( + ctx.out(), basic_string_view(buf.data(), buf.size()), specs); } }; diff --git a/src/fmt/color.h b/src/fmt/color.h index 96d9ab6b43..b65f892afc 100644 --- a/src/fmt/color.h +++ b/src/fmt/color.h @@ -198,7 +198,7 @@ struct rgb { uint8_t b; }; -namespace internal { +namespace detail { // color is a struct of either a rgb color or a terminal color. struct color_type { @@ -221,7 +221,7 @@ struct color_type { uint32_t rgb_color; } value; }; -} // namespace internal +} // namespace detail // Experimental text formatting support. class text_style { @@ -298,11 +298,11 @@ class text_style { FMT_CONSTEXPR bool has_emphasis() const FMT_NOEXCEPT { return static_cast(ems) != 0; } - FMT_CONSTEXPR internal::color_type get_foreground() const FMT_NOEXCEPT { + FMT_CONSTEXPR detail::color_type get_foreground() const FMT_NOEXCEPT { FMT_ASSERT(has_foreground(), "no foreground specified for this style"); return foreground_color; } - FMT_CONSTEXPR internal::color_type get_background() const FMT_NOEXCEPT { + FMT_CONSTEXPR detail::color_type get_background() const FMT_NOEXCEPT { FMT_ASSERT(has_background(), "no background specified for this style"); return background_color; } @@ -313,7 +313,7 @@ class text_style { private: FMT_CONSTEXPR text_style(bool is_foreground, - internal::color_type text_color) FMT_NOEXCEPT + detail::color_type text_color) FMT_NOEXCEPT : set_foreground_color(), set_background_color(), ems() { @@ -326,23 +326,23 @@ class text_style { } } - friend FMT_CONSTEXPR_DECL text_style fg(internal::color_type foreground) + friend FMT_CONSTEXPR_DECL text_style fg(detail::color_type foreground) FMT_NOEXCEPT; - friend FMT_CONSTEXPR_DECL text_style bg(internal::color_type background) + friend FMT_CONSTEXPR_DECL text_style bg(detail::color_type background) FMT_NOEXCEPT; - internal::color_type foreground_color; - internal::color_type background_color; + detail::color_type foreground_color; + detail::color_type background_color; bool set_foreground_color; bool set_background_color; emphasis ems; }; -FMT_CONSTEXPR text_style fg(internal::color_type foreground) FMT_NOEXCEPT { +FMT_CONSTEXPR text_style fg(detail::color_type foreground) FMT_NOEXCEPT { return text_style(/*is_foreground=*/true, foreground); } -FMT_CONSTEXPR text_style bg(internal::color_type background) FMT_NOEXCEPT { +FMT_CONSTEXPR text_style bg(detail::color_type background) FMT_NOEXCEPT { return text_style(/*is_foreground=*/false, background); } @@ -350,21 +350,21 @@ FMT_CONSTEXPR text_style operator|(emphasis lhs, emphasis rhs) FMT_NOEXCEPT { return text_style(lhs) | rhs; } -namespace internal { +namespace detail { template struct ansi_color_escape { - FMT_CONSTEXPR ansi_color_escape(internal::color_type text_color, + FMT_CONSTEXPR ansi_color_escape(detail::color_type text_color, const char* esc) FMT_NOEXCEPT { // If we have a terminal color, we need to output another escape code // sequence. if (!text_color.is_rgb) { - bool is_background = esc == internal::data::background_color; + bool is_background = esc == detail::data::background_color; uint32_t value = text_color.value.term_color; // Background ASCII codes are the same as the foreground ones but with // 10 more. if (is_background) value += 10u; - std::size_t index = 0; + size_t index = 0; buffer[index++] = static_cast('\x1b'); buffer[index++] = static_cast('['); @@ -398,7 +398,7 @@ template struct ansi_color_escape { if (em_bits & static_cast(emphasis::strikethrough)) em_codes[3] = 9; - std::size_t index = 0; + size_t index = 0; for (int i = 0; i < 4; ++i) { if (!em_codes[i]) continue; buffer[index++] = static_cast('\x1b'); @@ -429,14 +429,14 @@ template struct ansi_color_escape { template FMT_CONSTEXPR ansi_color_escape make_foreground_color( - internal::color_type foreground) FMT_NOEXCEPT { - return ansi_color_escape(foreground, internal::data::foreground_color); + detail::color_type foreground) FMT_NOEXCEPT { + return ansi_color_escape(foreground, detail::data::foreground_color); } template FMT_CONSTEXPR ansi_color_escape make_background_color( - internal::color_type background) FMT_NOEXCEPT { - return ansi_color_escape(background, internal::data::background_color); + detail::color_type background) FMT_NOEXCEPT { + return ansi_color_escape(background, detail::data::background_color); } template @@ -455,11 +455,11 @@ inline void fputs(const wchar_t* chars, FILE* stream) FMT_NOEXCEPT { } template inline void reset_color(FILE* stream) FMT_NOEXCEPT { - fputs(internal::data::reset_color, stream); + fputs(detail::data::reset_color, stream); } template <> inline void reset_color(FILE* stream) FMT_NOEXCEPT { - fputs(internal::data::wreset_color, stream); + fputs(detail::data::wreset_color, stream); } template @@ -476,33 +476,31 @@ void vformat_to(basic_memory_buffer& buf, const text_style& ts, bool has_style = false; if (ts.has_emphasis()) { has_style = true; - auto emphasis = internal::make_emphasis(ts.get_emphasis()); + auto emphasis = detail::make_emphasis(ts.get_emphasis()); buf.append(emphasis.begin(), emphasis.end()); } if (ts.has_foreground()) { has_style = true; - auto foreground = - internal::make_foreground_color(ts.get_foreground()); + auto foreground = detail::make_foreground_color(ts.get_foreground()); buf.append(foreground.begin(), foreground.end()); } if (ts.has_background()) { has_style = true; - auto background = - internal::make_background_color(ts.get_background()); + auto background = detail::make_background_color(ts.get_background()); buf.append(background.begin(), background.end()); } - internal::vformat_to(buf, format_str, args); - if (has_style) internal::reset_color(buf); + detail::vformat_to(buf, format_str, args); + if (has_style) detail::reset_color(buf); } -} // namespace internal +} // namespace detail template > void vprint(std::FILE* f, const text_style& ts, const S& format, basic_format_args> args) { basic_memory_buffer buf; - internal::vformat_to(buf, ts, to_string_view(format), args); + detail::vformat_to(buf, ts, to_string_view(format), args); buf.push_back(Char(0)); - internal::fputs(buf.data(), f); + detail::fputs(buf.data(), f); } /** @@ -513,10 +511,10 @@ void vprint(std::FILE* f, const text_style& ts, const S& format, "Elapsed time: {0:.2f} seconds", 1.23); */ template ::value)> + FMT_ENABLE_IF(detail::is_string::value)> void print(std::FILE* f, const text_style& ts, const S& format_str, const Args&... args) { - internal::check_format_string(format_str); + detail::check_format_string(format_str); using context = buffer_context>; format_arg_store as{args...}; vprint(f, ts, format_str, basic_format_args(as)); @@ -530,7 +528,7 @@ void print(std::FILE* f, const text_style& ts, const S& format_str, "Elapsed time: {0:.2f} seconds", 1.23); */ template ::value)> + FMT_ENABLE_IF(detail::is_string::value)> void print(const text_style& ts, const S& format_str, const Args&... args) { return print(stdout, ts, format_str, args...); } @@ -540,7 +538,7 @@ inline std::basic_string vformat( const text_style& ts, const S& format_str, basic_format_args>> args) { basic_memory_buffer buf; - internal::vformat_to(buf, ts, to_string_view(format_str), args); + detail::vformat_to(buf, ts, to_string_view(format_str), args); return fmt::to_string(buf); } @@ -560,7 +558,7 @@ template > inline std::basic_string format(const text_style& ts, const S& format_str, const Args&... args) { return vformat(ts, to_string_view(format_str), - internal::make_args_checked(format_str, args...)); + detail::make_args_checked(format_str, args...)); } FMT_END_NAMESPACE diff --git a/src/fmt/compile.h b/src/fmt/compile.h index e4b12f349e..d7e6449ebb 100644 --- a/src/fmt/compile.h +++ b/src/fmt/compile.h @@ -13,7 +13,33 @@ #include "format.h" FMT_BEGIN_NAMESPACE -namespace internal { +namespace detail { + +// A compile-time string which is compiled into fast formatting code. +class compiled_string {}; + +template +struct is_compiled_string : std::is_base_of {}; + +/** + \rst + Converts a string literal *s* into a format string that will be parsed at + compile time and converted into efficient formatting code. Requires C++17 + ``constexpr if`` compiler support. + + **Example**:: + + // Converts 42 into std::string using the most efficient method and no + // runtime format string processing. + std::string s = fmt::format(FMT_COMPILE("{}"), 42); + \endrst + */ +#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string) + +template +const T& first(const T& value, const Tail&...) { + return value; +} // Part of a compiled format string. It can be either literal text or a // replacement field. @@ -62,13 +88,15 @@ template struct part_counter { if (begin != end) ++num_parts; } - FMT_CONSTEXPR void on_arg_id() { ++num_parts; } - FMT_CONSTEXPR void on_arg_id(int) { ++num_parts; } - FMT_CONSTEXPR void on_arg_id(basic_string_view) { ++num_parts; } + FMT_CONSTEXPR int on_arg_id() { return ++num_parts, 0; } + FMT_CONSTEXPR int on_arg_id(int) { return ++num_parts, 0; } + FMT_CONSTEXPR int on_arg_id(basic_string_view) { + return ++num_parts, 0; + } - FMT_CONSTEXPR void on_replacement_field(const Char*) {} + FMT_CONSTEXPR void on_replacement_field(int, const Char*) {} - FMT_CONSTEXPR const Char* on_format_specs(const Char* begin, + FMT_CONSTEXPR const Char* on_format_specs(int, const Char* begin, const Char* end) { // Find the matching brace. unsigned brace_counter = 0; @@ -116,25 +144,28 @@ class format_string_compiler : public error_handler { handler_(part::make_text({begin, to_unsigned(end - begin)})); } - FMT_CONSTEXPR void on_arg_id() { + FMT_CONSTEXPR int on_arg_id() { part_ = part::make_arg_index(parse_context_.next_arg_id()); + return 0; } - FMT_CONSTEXPR void on_arg_id(int id) { + FMT_CONSTEXPR int on_arg_id(int id) { parse_context_.check_arg_id(id); part_ = part::make_arg_index(id); + return 0; } - FMT_CONSTEXPR void on_arg_id(basic_string_view id) { + FMT_CONSTEXPR int on_arg_id(basic_string_view id) { part_ = part::make_arg_name(id); + return 0; } - FMT_CONSTEXPR void on_replacement_field(const Char* ptr) { + FMT_CONSTEXPR void on_replacement_field(int, const Char* ptr) { part_.arg_id_end = ptr; handler_(part_); } - FMT_CONSTEXPR const Char* on_format_specs(const Char* begin, + FMT_CONSTEXPR const Char* on_format_specs(int, const Char* begin, const Char* end) { auto repl = typename part::replacement(); dynamic_specs_handler> handler( @@ -160,23 +191,24 @@ FMT_CONSTEXPR void compile_format_string(basic_string_view format_str, format_string_compiler(format_str, handler)); } -template +template void format_arg( - basic_format_parse_context& parse_ctx, + basic_format_parse_context& parse_ctx, Context& ctx, Id arg_id) { - ctx.advance_to( - visit_format_arg(arg_formatter(ctx, &parse_ctx), ctx.arg(arg_id))); + ctx.advance_to(visit_format_arg( + arg_formatter(ctx, &parse_ctx), + ctx.arg(arg_id))); } // vformat_to is defined in a subnamespace to prevent ADL. namespace cf { -template -auto vformat_to(Range out, CompiledFormat& cf, basic_format_args args) - -> typename Context::iterator { +template +auto vformat_to(OutputIt out, CompiledFormat& cf, + basic_format_args args) -> typename Context::iterator { using char_type = typename Context::char_type; basic_format_parse_context parse_ctx( to_string_view(cf.format_str_)); - Context ctx(out.begin(), args); + Context ctx(out, args); const auto& parts = cf.parts(); for (auto part_it = std::begin(parts); part_it != std::end(parts); @@ -197,12 +229,12 @@ auto vformat_to(Range out, CompiledFormat& cf, basic_format_args args) case format_part_t::kind::arg_index: advance_to(parse_ctx, part.arg_id_end); - internal::format_arg(parse_ctx, ctx, value.arg_index); + detail::format_arg(parse_ctx, ctx, value.arg_index); break; case format_part_t::kind::arg_name: advance_to(parse_ctx, part.arg_id_end); - internal::format_arg(parse_ctx, ctx, value.str); + detail::format_arg(parse_ctx, ctx, value.str); break; case format_part_t::kind::replacement: { @@ -226,7 +258,9 @@ auto vformat_to(Range out, CompiledFormat& cf, basic_format_args args) advance_to(parse_ctx, part.arg_id_end); ctx.advance_to( - visit_format_arg(arg_formatter(ctx, nullptr, &specs), arg)); + visit_format_arg(arg_formatter( + ctx, nullptr, &specs), + arg)); break; } } @@ -240,7 +274,7 @@ struct basic_compiled_format {}; template struct compiled_format_base : basic_compiled_format { using char_type = char_t; - using parts_container = std::vector>; + using parts_container = std::vector>; parts_container compiled_parts; @@ -305,7 +339,7 @@ struct compiled_format_base::value>> const parts_container& parts() const { static FMT_CONSTEXPR_DECL const auto compiled_parts = compile_to_parts( - internal::to_string_view(S())); + detail::to_string_view(S())); return compiled_parts.data; } }; @@ -318,8 +352,8 @@ class compiled_format : private compiled_format_base { private: basic_string_view format_str_; - template - friend auto cf::vformat_to(Range out, CompiledFormat& cf, + template + friend auto cf::vformat_to(OutputIt out, CompiledFormat& cf, basic_format_args args) -> typename Context::iterator; @@ -359,8 +393,7 @@ template struct text { template OutputIt format(OutputIt out, const Args&...) const { - // TODO: reserve - return copy_str(data.begin(), data.end(), out); + return write(out, data); } }; @@ -373,33 +406,6 @@ constexpr text make_text(basic_string_view s, size_t pos, return {{&s[pos], size}}; } -template , int> = 0> -OutputIt format_default(OutputIt out, T value) { - // TODO: reserve - format_int fi(value); - return std::copy(fi.data(), fi.data() + fi.size(), out); -} - -template -OutputIt format_default(OutputIt out, double value) { - writer w(out); - w.write(value); - return w.out(); -} - -template -OutputIt format_default(OutputIt out, Char value) { - *out++ = value; - return out; -} - -template -OutputIt format_default(OutputIt out, const Char* value) { - auto length = std::char_traits::length(value); - return copy_str(value, value + length, out); -} - // A replacement field that refers to argument N. template struct field { using char_type = Char; @@ -408,13 +414,30 @@ template struct field { OutputIt format(OutputIt out, const Args&... args) const { // This ensures that the argument type is convertile to `const T&`. const T& arg = get(args...); - return format_default(out, arg); + return write(out, arg); } }; template struct is_compiled_format> : std::true_type {}; +// A replacement field that refers to argument N and has format specifiers. +template struct spec_field { + using char_type = Char; + mutable formatter fmt; + + template + OutputIt format(OutputIt out, const Args&... args) const { + // This ensures that the argument type is convertile to `const T&`. + const T& arg = get(args...); + basic_format_context ctx(out, {}); + return fmt.format(arg, ctx); + } +}; + +template +struct is_compiled_format> : std::true_type {}; + template struct concat { L lhs; R rhs; @@ -450,7 +473,8 @@ constexpr auto compile_format_string(S format_str); template constexpr auto parse_tail(T head, S format_str) { - if constexpr (POS != to_string_view(format_str).size()) { + if constexpr (POS != + basic_string_view(format_str).size()) { constexpr auto tail = compile_format_string(format_str); if constexpr (std::is_same, unknown_format>()) @@ -462,6 +486,21 @@ constexpr auto parse_tail(T head, S format_str) { } } +template struct parse_specs_result { + formatter fmt; + size_t end; +}; + +template +constexpr parse_specs_result parse_specs(basic_string_view str, + size_t pos) { + str.remove_prefix(pos); + auto ctx = basic_format_parse_context(str); + auto f = formatter(); + auto end = f.parse(ctx); + return {f, pos + (end - str.data()) + 1}; +} + // Compiles a non-empty format string and returns the compiled representation // or unknown_format() on unrecognized input. template @@ -475,12 +514,13 @@ constexpr auto compile_format_string(S format_str) { return parse_tail(make_text(str, POS, 1), format_str); } else if constexpr (str[POS + 1] == '}') { using type = get_type; - if constexpr (std::is_same::value) { - return parse_tail(field(), - format_str); - } else { - return unknown_format(); - } + return parse_tail(field(), + format_str); + } else if constexpr (str[POS + 1] == ':') { + using type = get_type; + constexpr auto result = parse_specs(str, POS + 2); + return parse_tail( + spec_field{result.fmt}, format_str); } else { return unknown_format(); } @@ -494,100 +534,130 @@ constexpr auto compile_format_string(S format_str) { format_str); } } -#endif // __cpp_if_constexpr -} // namespace internal -#if FMT_USE_CONSTEXPR -# ifdef __cpp_if_constexpr template ::value)> + FMT_ENABLE_IF(is_compile_string::value || + detail::is_compiled_string::value)> constexpr auto compile(S format_str) { constexpr basic_string_view str = format_str; if constexpr (str.size() == 0) { - return internal::make_text(str, 0, 0); + return detail::make_text(str, 0, 0); } else { constexpr auto result = - internal::compile_format_string, 0, 0>( + detail::compile_format_string, 0, 0>( format_str); if constexpr (std::is_same, - internal::unknown_format>()) { - return internal::compiled_format(to_string_view(format_str)); + detail::unknown_format>()) { + return detail::compiled_format(to_string_view(format_str)); } else { return result; } } } - -template ::value)> -std::basic_string format(const CompiledFormat& cf, const Args&... args) { - basic_memory_buffer buffer; - cf.format(std::back_inserter(buffer), args...); - return to_string(buffer); -} - -template ::value)> -OutputIt format_to(OutputIt out, const CompiledFormat& cf, - const Args&... args) { - return cf.format(out, args...); -} -# else +#else template ::value)> -constexpr auto compile(S format_str) -> internal::compiled_format { - return internal::compiled_format(to_string_view(format_str)); +constexpr auto compile(S format_str) -> detail::compiled_format { + return detail::compiled_format(to_string_view(format_str)); } -# endif // __cpp_if_constexpr -#endif // FMT_USE_CONSTEXPR +#endif // __cpp_if_constexpr // Compiles the format string which must be a string literal. template auto compile(const Char (&format_str)[N]) - -> internal::compiled_format { - return internal::compiled_format( + -> detail::compiled_format { + return detail::compiled_format( basic_string_view(format_str, N - 1)); } +} // namespace detail + +// DEPRECATED! use FMT_COMPILE instead. +template +FMT_DEPRECATED auto compile(const Args&... args) + -> decltype(detail::compile(args...)) { + return detail::compile(args...); +} + +#if FMT_USE_CONSTEXPR +# ifdef __cpp_if_constexpr template ::value)> -std::basic_string format(const CompiledFormat& cf, const Args&... args) { + FMT_ENABLE_IF(detail::is_compiled_format::value)> +FMT_INLINE std::basic_string format(const CompiledFormat& cf, + const Args&... args) { basic_memory_buffer buffer; - using range = buffer_range; - using context = buffer_context; - internal::cf::vformat_to(range(buffer), cf, - make_format_args(args...)); + detail::buffer& base = buffer; + cf.format(std::back_inserter(base), args...); return to_string(buffer); } template ::value)> +OutputIt format_to(OutputIt out, const CompiledFormat& cf, + const Args&... args) { + return cf.format(out, args...); +} +# endif // __cpp_if_constexpr +#endif // FMT_USE_CONSTEXPR + +template ::value)> +std::basic_string format(const CompiledFormat& cf, const Args&... args) { + basic_memory_buffer buffer; + using context = buffer_context; + detail::buffer& base = buffer; + detail::cf::vformat_to(std::back_inserter(base), cf, + make_format_args(args...)); + return to_string(buffer); +} + +template ::value)> +FMT_INLINE std::basic_string format(const S&, + Args&&... args) { + constexpr basic_string_view str = S(); + if (str.size() == 2 && str[0] == '{' && str[1] == '}') + return fmt::to_string(detail::first(args...)); + constexpr auto compiled = detail::compile(S()); + return format(compiled, std::forward(args)...); +} + +template ::value)> OutputIt format_to(OutputIt out, const CompiledFormat& cf, const Args&... args) { using char_type = typename CompiledFormat::char_type; - using range = internal::output_range; using context = format_context_t; - return internal::cf::vformat_to(range(out), cf, - make_format_args(args...)); + return detail::cf::vformat_to(out, cf, + make_format_args(args...)); } -template ::value)> +template ::value)> +OutputIt format_to(OutputIt out, const S&, const Args&... args) { + constexpr auto compiled = detail::compile(S()); + return format_to(out, compiled, args...); +} + +template < + typename OutputIt, typename CompiledFormat, typename... Args, + FMT_ENABLE_IF(detail::is_output_iterator::value&& std::is_base_of< + detail::basic_compiled_format, CompiledFormat>::value)> format_to_n_result format_to_n(OutputIt out, size_t n, const CompiledFormat& cf, const Args&... args) { auto it = - format_to(internal::truncating_iterator(out, n), cf, args...); + format_to(detail::truncating_iterator(out, n), cf, args...); return {it.base(), it.count()}; } template -std::size_t formatted_size(const CompiledFormat& cf, const Args&... args) { - return format_to(internal::counting_iterator(), cf, args...).count(); +size_t formatted_size(const CompiledFormat& cf, const Args&... args) { + return format_to(detail::counting_iterator(), cf, args...).count(); } FMT_END_NAMESPACE diff --git a/src/fmt/core.h b/src/fmt/core.h index 0e0824f5fe..40c4ddb077 100644 --- a/src/fmt/core.h +++ b/src/fmt/core.h @@ -18,8 +18,45 @@ #include // The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 60201 +#define FMT_VERSION 70002 +#ifdef __clang__ +# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) +#else +# define FMT_CLANG_VERSION 0 +#endif + +#if defined(__GNUC__) && !defined(__clang__) +# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) +#else +# define FMT_GCC_VERSION 0 +#endif + +#if defined(__INTEL_COMPILER) +# define FMT_ICC_VERSION __INTEL_COMPILER +#else +# define FMT_ICC_VERSION 0 +#endif + +#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) +# define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION +#else +# define FMT_HAS_GXX_CXX11 0 +#endif + +#ifdef __NVCC__ +# define FMT_NVCC __NVCC__ +#else +# define FMT_NVCC 0 +#endif + +#ifdef _MSC_VER +# define FMT_MSC_VER _MSC_VER +# define FMT_SUPPRESS_MSC_WARNING(n) __pragma(warning(suppress : n)) +#else +# define FMT_MSC_VER 0 +# define FMT_SUPPRESS_MSC_WARNING(n) +#endif #ifdef __has_feature # define FMT_HAS_FEATURE(x) __has_feature(x) #else @@ -27,7 +64,7 @@ #endif #if defined(__has_include) && !defined(__INTELLISENSE__) && \ - !(defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1600) + !(FMT_ICC_VERSION && FMT_ICC_VERSION < 1600) # define FMT_HAS_INCLUDE(x) __has_include(x) #else # define FMT_HAS_INCLUDE(x) 0 @@ -45,43 +82,13 @@ #define FMT_HAS_CPP17_ATTRIBUTE(attribute) \ (__cplusplus >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute)) -#ifdef __clang__ -# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) -#else -# define FMT_CLANG_VERSION 0 -#endif - -#if defined(__GNUC__) && !defined(__clang__) -# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -#else -# define FMT_GCC_VERSION 0 -#endif - -#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) -# define FMT_HAS_GXX_CXX11 FMT_GCC_VERSION -#else -# define FMT_HAS_GXX_CXX11 0 -#endif - -#ifdef __NVCC__ -# define FMT_NVCC __NVCC__ -#else -# define FMT_NVCC 0 -#endif - -#ifdef _MSC_VER -# define FMT_MSC_VER _MSC_VER -#else -# define FMT_MSC_VER 0 -#endif - // Check if relaxed C++14 constexpr is supported. // GCC doesn't allow throw in constexpr until version 6 (bug 67371). #ifndef FMT_USE_CONSTEXPR # define FMT_USE_CONSTEXPR \ (FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VER >= 1910 || \ (FMT_GCC_VERSION >= 600 && __cplusplus >= 201402L)) && \ - !FMT_NVCC + !FMT_NVCC && !FMT_ICC_VERSION #endif #if FMT_USE_CONSTEXPR # define FMT_CONSTEXPR constexpr @@ -141,14 +148,6 @@ # define FMT_NORETURN #endif -#ifndef FMT_MAYBE_UNUSED -# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused) -# define FMT_MAYBE_UNUSED [[maybe_unused]] -# else -# define FMT_MAYBE_UNUSED -# endif -#endif - #ifndef FMT_DEPRECATED # if FMT_HAS_CPP14_ATTRIBUTE(deprecated) || FMT_MSC_VER >= 1900 # define FMT_DEPRECATED [[deprecated]] @@ -164,12 +163,20 @@ #endif // Workaround broken [[deprecated]] in the Intel, PGI and NVCC compilers. -#if defined(__INTEL_COMPILER) || defined(__PGI) || FMT_NVCC +#if FMT_ICC_VERSION || defined(__PGI) || FMT_NVCC # define FMT_DEPRECATED_ALIAS #else # define FMT_DEPRECATED_ALIAS FMT_DEPRECATED #endif +#ifndef FMT_INLINE +# if FMT_GCC_VERSION || FMT_CLANG_VERSION +# define FMT_INLINE inline __attribute__((always_inline)) +# else +# define FMT_INLINE inline +# endif +#endif + #ifndef FMT_BEGIN_NAMESPACE # if FMT_HAS_FEATURE(cxx_inline_namespaces) || FMT_GCC_VERSION >= 404 || \ FMT_MSC_VER >= 1900 @@ -181,39 +188,29 @@ # define FMT_INLINE_NAMESPACE namespace # define FMT_END_NAMESPACE \ } \ - using namespace v6; \ + using namespace v7; \ } # endif # define FMT_BEGIN_NAMESPACE \ namespace fmt { \ - FMT_INLINE_NAMESPACE v6 { + FMT_INLINE_NAMESPACE v7 { #endif #if !defined(FMT_HEADER_ONLY) && defined(_WIN32) -# if FMT_MSC_VER -# define FMT_NO_W4275 __pragma(warning(suppress : 4275)) -# else -# define FMT_NO_W4275 -# endif -# define FMT_CLASS_API FMT_NO_W4275 +# define FMT_CLASS_API FMT_SUPPRESS_MSC_WARNING(4275) # ifdef FMT_EXPORT # define FMT_API __declspec(dllexport) +# define FMT_EXTERN_TEMPLATE_API FMT_API +# define FMT_EXPORTED # elif defined(FMT_SHARED) # define FMT_API __declspec(dllimport) # define FMT_EXTERN_TEMPLATE_API FMT_API # endif -#endif -#ifndef FMT_CLASS_API +#else # define FMT_CLASS_API #endif #ifndef FMT_API -# if FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_API __attribute__((visibility("default"))) -# define FMT_EXTERN_TEMPLATE_API FMT_API -# define FMT_INSTANTIATION_DEF_API -# else -# define FMT_API -# endif +# define FMT_API #endif #ifndef FMT_EXTERN_TEMPLATE_API # define FMT_EXTERN_TEMPLATE_API @@ -270,14 +267,11 @@ struct monostate {}; // to workaround a bug in MSVC 2019 (see #1140 and #1186). #define FMT_ENABLE_IF(...) enable_if_t<(__VA_ARGS__), int> = 0 -namespace internal { +namespace detail { // A helper function to suppress bogus "conditional expression is constant" // warnings. -template FMT_CONSTEXPR T const_check(T value) { return value; } - -// A workaround for gcc 4.8 to make void_t work in a SFINAE context. -template struct void_t_impl { using type = void; }; +template constexpr T const_check(T value) { return value; } FMT_NORETURN FMT_API void assert_fail(const char* file, int line, const char* message); @@ -290,7 +284,7 @@ FMT_NORETURN FMT_API void assert_fail(const char* file, int line, # define FMT_ASSERT(condition, message) \ ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \ ? (void)0 \ - : ::fmt::internal::assert_fail(__FILE__, __LINE__, (message))) + : ::fmt::detail::assert_fail(__FILE__, __LINE__, (message))) # endif #endif @@ -324,7 +318,7 @@ FMT_CONSTEXPR typename std::make_unsigned::type to_unsigned(Int value) { return static_cast::type>(value); } -constexpr unsigned char micro[] = "\u00B5"; +FMT_SUPPRESS_MSC_WARNING(4566) constexpr unsigned char micro[] = "\u00B5"; template constexpr bool is_unicode() { return FMT_UNICODE || sizeof(Char) != 1 || @@ -336,10 +330,11 @@ using char8_type = char8_t; #else enum char8_type : unsigned char {}; #endif -} // namespace internal +} // namespace detail -template -using void_t = typename internal::void_t_impl::type; +#ifdef FMT_USE_INTERNAL +namespace internal = detail; // DEPRECATED +#endif /** An implementation of ``std::basic_string_view`` for pre-C++17. It provides a @@ -354,14 +349,13 @@ template class basic_string_view { size_t size_; public: - using char_type FMT_DEPRECATED_ALIAS = Char; using value_type = Char; using iterator = const Char*; - FMT_CONSTEXPR basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} + constexpr basic_string_view() FMT_NOEXCEPT : data_(nullptr), size_(0) {} /** Constructs a string reference object from a C string and a size. */ - FMT_CONSTEXPR basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT + constexpr basic_string_view(const Char* s, size_t count) FMT_NOEXCEPT : data_(s), size_(count) {} @@ -384,22 +378,21 @@ template class basic_string_view { : data_(s.data()), size_(s.size()) {} - template < - typename S, - FMT_ENABLE_IF(std::is_same>::value)> + template >::value)> FMT_CONSTEXPR basic_string_view(S s) FMT_NOEXCEPT : data_(s.data()), size_(s.size()) {} /** Returns a pointer to the string data. */ - FMT_CONSTEXPR const Char* data() const { return data_; } + constexpr const Char* data() const { return data_; } /** Returns the string size. */ - FMT_CONSTEXPR size_t size() const { return size_; } + constexpr size_t size() const { return size_; } - FMT_CONSTEXPR iterator begin() const { return data_; } - FMT_CONSTEXPR iterator end() const { return data_ + size_; } + constexpr iterator begin() const { return data_; } + constexpr iterator end() const { return data_ + size_; } - FMT_CONSTEXPR const Char& operator[](size_t pos) const { return data_[pos]; } + constexpr const Char& operator[](size_t pos) const { return data_[pos]; } FMT_CONSTEXPR void remove_prefix(size_t n) { data_ += n; @@ -438,16 +431,11 @@ template class basic_string_view { using string_view = basic_string_view; using wstring_view = basic_string_view; -#ifndef __cpp_char8_t -// char8_t is deprecated; use char instead. -using char8_t FMT_DEPRECATED_ALIAS = internal::char8_type; -#endif - /** Specifies if ``T`` is a character type. Can be specialized by users. */ template struct is_char : std::false_type {}; template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; -template <> struct is_char : std::true_type {}; +template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; template <> struct is_char : std::true_type {}; @@ -484,14 +472,13 @@ inline basic_string_view to_string_view(basic_string_view s) { } template >::value)> -inline basic_string_view to_string_view( - internal::std_string_view s) { + FMT_ENABLE_IF(!std::is_empty>::value)> +inline basic_string_view to_string_view(detail::std_string_view s) { return s; } // A base class for compile-time strings. It is defined in the fmt namespace to -// make formatting functions visible via ADL, e.g. format(fmt("{}"), 42). +// make formatting functions visible via ADL, e.g. format(FMT_STRING("{}"), 42). struct compile_string {}; template @@ -502,9 +489,9 @@ constexpr basic_string_view to_string_view(const S& s) { return s; } -namespace internal { +namespace detail { void to_string_view(...); -using fmt::v6::to_string_view; +using fmt::v7::to_string_view; // Specifies whether S is a string type convertible to fmt::basic_string_view. // It should be a constexpr function but MSVC 2017 fails to compile it in @@ -520,16 +507,16 @@ template struct char_t_impl::value>> { }; struct error_handler { - FMT_CONSTEXPR error_handler() = default; - FMT_CONSTEXPR error_handler(const error_handler&) = default; + constexpr error_handler() = default; + constexpr error_handler(const error_handler&) = default; // This function is intentionally not constexpr to give a compile-time error. FMT_NORETURN FMT_API void on_error(const char* message); }; -} // namespace internal +} // namespace detail /** String's character type. */ -template using char_t = typename internal::char_t_impl::type; +template using char_t = typename detail::char_t_impl::type; /** \rst @@ -547,7 +534,7 @@ template using char_t = typename internal::char_t_impl::type; +-----------------------+-------------------------------------+ \endrst */ -template +template class basic_format_parse_context : private ErrorHandler { private: basic_string_view format_str_; @@ -557,26 +544,24 @@ class basic_format_parse_context : private ErrorHandler { using char_type = Char; using iterator = typename basic_string_view::iterator; - explicit FMT_CONSTEXPR basic_format_parse_context( - basic_string_view format_str, ErrorHandler eh = ErrorHandler()) + explicit constexpr basic_format_parse_context( + basic_string_view format_str, ErrorHandler eh = {}) : ErrorHandler(eh), format_str_(format_str), next_arg_id_(0) {} /** Returns an iterator to the beginning of the format string range being parsed. */ - FMT_CONSTEXPR iterator begin() const FMT_NOEXCEPT { - return format_str_.begin(); - } + constexpr iterator begin() const FMT_NOEXCEPT { return format_str_.begin(); } /** Returns an iterator past the end of the format string range being parsed. */ - FMT_CONSTEXPR iterator end() const FMT_NOEXCEPT { return format_str_.end(); } + constexpr iterator end() const FMT_NOEXCEPT { return format_str_.end(); } /** Advances the begin iterator to ``it``. */ FMT_CONSTEXPR void advance_to(iterator it) { - format_str_.remove_prefix(internal::to_unsigned(it - begin())); + format_str_.remove_prefix(detail::to_unsigned(it - begin())); } /** @@ -584,6 +569,8 @@ class basic_format_parse_context : private ErrorHandler { the next argument index and switches to the automatic indexing. */ FMT_CONSTEXPR int next_arg_id() { + // Don't check if the argument id is valid to avoid overhead and because it + // will be checked during formatting anyway. if (next_arg_id_ >= 0) return next_arg_id_++; on_error("cannot switch from manual to automatic argument indexing"); return 0; @@ -606,20 +593,15 @@ class basic_format_parse_context : private ErrorHandler { ErrorHandler::on_error(message); } - FMT_CONSTEXPR ErrorHandler error_handler() const { return *this; } + constexpr ErrorHandler error_handler() const { return *this; } }; using format_parse_context = basic_format_parse_context; using wformat_parse_context = basic_format_parse_context; -template -using basic_parse_context FMT_DEPRECATED_ALIAS = - basic_format_parse_context; -using parse_context FMT_DEPRECATED_ALIAS = basic_format_parse_context; -using wparse_context FMT_DEPRECATED_ALIAS = basic_format_parse_context; - template class basic_format_arg; template class basic_format_args; +template class dynamic_format_arg_store; // A formatter for objects of type T. template @@ -628,43 +610,44 @@ struct formatter { formatter() = delete; }; -template -struct FMT_DEPRECATED convert_to_int - : bool_constant::value && - std::is_convertible::value> {}; - // Specifies if T has an enabled formatter specialization. A type can be // formattable even if it doesn't have a formatter e.g. via a conversion. template using has_formatter = std::is_constructible>; -namespace internal { +namespace detail { -/** A contiguous memory buffer with an optional growing ability. */ +/** + \rst + A contiguous memory buffer with an optional growing ability. It is an internal + class and shouldn't be used directly, only via `~fmt::basic_memory_buffer`. + \endrst + */ template class buffer { private: T* ptr_; - std::size_t size_; - std::size_t capacity_; + size_t size_; + size_t capacity_; protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. - buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} + FMT_SUPPRESS_MSC_WARNING(26495) + buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} - buffer(T* p = nullptr, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT + buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT : ptr_(p), size_(sz), capacity_(cap) {} /** Sets the buffer data and capacity. */ - void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT { + void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT { ptr_ = buf_data; capacity_ = buf_capacity; } /** Increases the buffer capacity to hold at least *capacity* elements. */ - virtual void grow(std::size_t capacity) = 0; + virtual void grow(size_t capacity) = 0; public: using value_type = T; @@ -681,10 +664,10 @@ template class buffer { const T* end() const FMT_NOEXCEPT { return ptr_ + size_; } /** Returns the size of this buffer. */ - std::size_t size() const FMT_NOEXCEPT { return size_; } + size_t size() const FMT_NOEXCEPT { return size_; } /** Returns the capacity of this buffer. */ - std::size_t capacity() const FMT_NOEXCEPT { return capacity_; } + size_t capacity() const FMT_NOEXCEPT { return capacity_; } /** Returns a pointer to the buffer data. */ T* data() FMT_NOEXCEPT { return ptr_; } @@ -695,7 +678,7 @@ template class buffer { /** Resizes the buffer. If T is a POD type new elements may not be initialized. */ - void resize(std::size_t new_size) { + void resize(size_t new_size) { reserve(new_size); size_ = new_size; } @@ -704,7 +687,7 @@ template class buffer { void clear() { size_ = 0; } /** Reserves space to store at least *capacity* elements. */ - void reserve(std::size_t new_capacity) { + void reserve(size_t new_capacity) { if (new_capacity > capacity_) grow(new_capacity); } @@ -729,7 +712,7 @@ class container_buffer : public buffer { Container& container_; protected: - void grow(std::size_t capacity) FMT_OVERRIDE { + void grow(size_t capacity) FMT_OVERRIDE { container_.resize(capacity); this->set(&container_[0], capacity); } @@ -760,12 +743,78 @@ template using has_fallback_formatter = std::is_constructible>; -template struct named_arg_base; -template struct named_arg; +struct view {}; + +template struct named_arg : view { + const Char* name; + const T& value; + named_arg(const Char* n, const T& v) : name(n), value(v) {} +}; + +template struct named_arg_info { + const Char* name; + int id; +}; + +template +struct arg_data { + // args_[0].named_args points to named_args_ to avoid bloating format_args. + T args_[1 + (NUM_ARGS != 0 ? NUM_ARGS : 1)]; + named_arg_info named_args_[NUM_NAMED_ARGS]; + + template + arg_data(const U&... init) : args_{T(named_args_, NUM_NAMED_ARGS), init...} {} + arg_data(const arg_data& other) = delete; + const T* args() const { return args_ + 1; } + named_arg_info* named_args() { return named_args_; } +}; + +template +struct arg_data { + T args_[NUM_ARGS != 0 ? NUM_ARGS : 1]; + + template + FMT_INLINE arg_data(const U&... init) : args_{init...} {} + FMT_INLINE const T* args() const { return args_; } + FMT_INLINE std::nullptr_t named_args() { return nullptr; } +}; + +template +inline void init_named_args(named_arg_info*, int, int) {} + +template +void init_named_args(named_arg_info* named_args, int arg_count, + int named_arg_count, const T&, const Tail&... args) { + init_named_args(named_args, arg_count + 1, named_arg_count, args...); +} + +template +void init_named_args(named_arg_info* named_args, int arg_count, + int named_arg_count, const named_arg& arg, + const Tail&... args) { + named_args[named_arg_count++] = {arg.name, arg_count}; + init_named_args(named_args, arg_count + 1, named_arg_count, args...); +} + +template +FMT_INLINE void init_named_args(std::nullptr_t, int, int, const Args&...) {} + +template struct is_named_arg : std::false_type {}; + +template +struct is_named_arg> : std::true_type {}; + +template constexpr size_t count() { return B ? 1 : 0; } +template constexpr size_t count() { + return (B1 ? 1 : 0) + count(); +} + +template constexpr size_t count_named_args() { + return count::value...>(); +} enum class type { none_type, - named_arg_type, // Integer types should go first, int_type, uint_type, @@ -796,7 +845,6 @@ struct type_constant : std::integral_constant {}; struct type_constant \ : std::integral_constant {} -FMT_TYPE_CONSTANT(const named_arg_base&, named_arg_type); FMT_TYPE_CONSTANT(int, int_type); FMT_TYPE_CONSTANT(unsigned, uint_type); FMT_TYPE_CONSTANT(long long, long_long_type); @@ -812,26 +860,28 @@ FMT_TYPE_CONSTANT(const Char*, cstring_type); FMT_TYPE_CONSTANT(basic_string_view, string_type); FMT_TYPE_CONSTANT(const void*, pointer_type); -FMT_CONSTEXPR bool is_integral_type(type t) { - FMT_ASSERT(t != type::named_arg_type, "invalid argument type"); +constexpr bool is_integral_type(type t) { return t > type::none_type && t <= type::last_integer_type; } -FMT_CONSTEXPR bool is_arithmetic_type(type t) { - FMT_ASSERT(t != type::named_arg_type, "invalid argument type"); +constexpr bool is_arithmetic_type(type t) { return t > type::none_type && t <= type::last_numeric_type; } template struct string_value { const Char* data; - std::size_t size; + size_t size; +}; + +template struct named_arg_value { + const named_arg_info* data; + size_t size; }; template struct custom_value { - using parse_context = basic_format_parse_context; + using parse_context = typename Context::parse_context_type; const void* value; - void (*format)(const void* arg, - typename Context::parse_context_type& parse_ctx, Context& ctx); + void (*format)(const void* arg, parse_context& parse_ctx, Context& ctx); }; // A formatting argument value. @@ -854,28 +904,30 @@ template class value { const void* pointer; string_value string; custom_value custom; - const named_arg_base* named_arg; + named_arg_value named_args; }; - FMT_CONSTEXPR value(int val = 0) : int_value(val) {} - FMT_CONSTEXPR value(unsigned val) : uint_value(val) {} - value(long long val) : long_long_value(val) {} - value(unsigned long long val) : ulong_long_value(val) {} - value(int128_t val) : int128_value(val) {} - value(uint128_t val) : uint128_value(val) {} - value(float val) : float_value(val) {} - value(double val) : double_value(val) {} - value(long double val) : long_double_value(val) {} - value(bool val) : bool_value(val) {} - value(char_type val) : char_value(val) {} - value(const char_type* val) { string.data = val; } - value(basic_string_view val) { + constexpr FMT_INLINE value(int val = 0) : int_value(val) {} + constexpr FMT_INLINE value(unsigned val) : uint_value(val) {} + FMT_INLINE value(long long val) : long_long_value(val) {} + FMT_INLINE value(unsigned long long val) : ulong_long_value(val) {} + FMT_INLINE value(int128_t val) : int128_value(val) {} + FMT_INLINE value(uint128_t val) : uint128_value(val) {} + FMT_INLINE value(float val) : float_value(val) {} + FMT_INLINE value(double val) : double_value(val) {} + FMT_INLINE value(long double val) : long_double_value(val) {} + FMT_INLINE value(bool val) : bool_value(val) {} + FMT_INLINE value(char_type val) : char_value(val) {} + FMT_INLINE value(const char_type* val) { string.data = val; } + FMT_INLINE value(basic_string_view val) { string.data = val.data(); string.size = val.size(); } - value(const void* val) : pointer(val) {} + FMT_INLINE value(const void* val) : pointer(val) {} + FMT_INLINE value(const named_arg_info* args, size_t size) + : named_args{args, size} {} - template value(const T& val) { + template FMT_INLINE value(const T& val) { custom.value = &val; // Get the formatter type through the context to allow different contexts // have different extension points, e.g. `formatter` for `format` and @@ -886,8 +938,6 @@ template class value { fallback_formatter>>; } - value(const named_arg_base& val) { named_arg = &val; } - private: // Formats an argument of a custom type, such as a user-defined class. template @@ -973,6 +1023,14 @@ template struct arg_mapper { static_assert(std::is_same::value, "invalid string type"); return reinterpret_cast(val); } + FMT_CONSTEXPR const char* map(signed char* val) { + const auto* const_val = val; + return map(const_val); + } + FMT_CONSTEXPR const char* map(unsigned char* val) { + const auto* const_val = val; + return map(const_val); + } FMT_CONSTEXPR const void* map(void* val) { return val; } FMT_CONSTEXPR const void* map(const void* val) { return val; } @@ -1004,11 +1062,9 @@ template struct arg_mapper { } template - FMT_CONSTEXPR const named_arg_base& map( - const named_arg& val) { - auto arg = make_arg(val.value); - std::memcpy(val.data, &arg, sizeof(arg)); - return val; + FMT_CONSTEXPR auto map(const named_arg& val) + -> decltype(std::declval().map(val.value)) { + return map(val.value); } int map(...) { @@ -1028,23 +1084,22 @@ using mapped_type_constant = type_constant().map(std::declval())), typename Context::char_type>; -enum { packed_arg_bits = 5 }; +enum { packed_arg_bits = 4 }; // Maximum number of arguments with packed types. -enum { max_packed_args = 63 / packed_arg_bits }; +enum { max_packed_args = 62 / packed_arg_bits }; enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; - -template class arg_map; -} // namespace internal +enum : unsigned long long { has_named_args_bit = 1ULL << 62 }; +} // namespace detail // A formatting argument. It is a trivially copyable/constructible type to // allow storage in basic_memory_buffer. template class basic_format_arg { private: - internal::value value_; - internal::type type_; + detail::value value_; + detail::type type_; template - friend FMT_CONSTEXPR basic_format_arg internal::make_arg( + friend FMT_CONSTEXPR basic_format_arg detail::make_arg( const T& value); template @@ -1053,14 +1108,20 @@ template class basic_format_arg { -> decltype(vis(0)); friend class basic_format_args; - friend class internal::arg_map; + friend class dynamic_format_arg_store; using char_type = typename Context::char_type; + template + friend struct detail::arg_data; + + basic_format_arg(const detail::named_arg_info* args, size_t size) + : value_(args, size) {} + public: class handle { public: - explicit handle(internal::custom_value custom) : custom_(custom) {} + explicit handle(detail::custom_value custom) : custom_(custom) {} void format(typename Context::parse_context_type& parse_ctx, Context& ctx) const { @@ -1068,19 +1129,19 @@ template class basic_format_arg { } private: - internal::custom_value custom_; + detail::custom_value custom_; }; - FMT_CONSTEXPR basic_format_arg() : type_(internal::type::none_type) {} + constexpr basic_format_arg() : type_(detail::type::none_type) {} - FMT_CONSTEXPR explicit operator bool() const FMT_NOEXCEPT { - return type_ != internal::type::none_type; + constexpr explicit operator bool() const FMT_NOEXCEPT { + return type_ != detail::type::none_type; } - internal::type type() const { return type_; } + detail::type type() const { return type_; } - bool is_integral() const { return internal::is_integral_type(type_); } - bool is_arithmetic() const { return internal::is_arithmetic_type(type_); } + bool is_integral() const { return detail::is_integral_type(type_); } + bool is_arithmetic() const { return detail::is_arithmetic_type(type_); } }; /** @@ -1091,92 +1152,73 @@ template class basic_format_arg { \endrst */ template -FMT_CONSTEXPR auto visit_format_arg(Visitor&& vis, - const basic_format_arg& arg) - -> decltype(vis(0)) { +FMT_CONSTEXPR_DECL FMT_INLINE auto visit_format_arg( + Visitor&& vis, const basic_format_arg& arg) -> decltype(vis(0)) { using char_type = typename Context::char_type; switch (arg.type_) { - case internal::type::none_type: + case detail::type::none_type: break; - case internal::type::named_arg_type: - FMT_ASSERT(false, "invalid argument type"); - break; - case internal::type::int_type: + case detail::type::int_type: return vis(arg.value_.int_value); - case internal::type::uint_type: + case detail::type::uint_type: return vis(arg.value_.uint_value); - case internal::type::long_long_type: + case detail::type::long_long_type: return vis(arg.value_.long_long_value); - case internal::type::ulong_long_type: + case detail::type::ulong_long_type: return vis(arg.value_.ulong_long_value); #if FMT_USE_INT128 - case internal::type::int128_type: + case detail::type::int128_type: return vis(arg.value_.int128_value); - case internal::type::uint128_type: + case detail::type::uint128_type: return vis(arg.value_.uint128_value); #else - case internal::type::int128_type: - case internal::type::uint128_type: + case detail::type::int128_type: + case detail::type::uint128_type: break; #endif - case internal::type::bool_type: + case detail::type::bool_type: return vis(arg.value_.bool_value); - case internal::type::char_type: + case detail::type::char_type: return vis(arg.value_.char_value); - case internal::type::float_type: + case detail::type::float_type: return vis(arg.value_.float_value); - case internal::type::double_type: + case detail::type::double_type: return vis(arg.value_.double_value); - case internal::type::long_double_type: + case detail::type::long_double_type: return vis(arg.value_.long_double_value); - case internal::type::cstring_type: + case detail::type::cstring_type: return vis(arg.value_.string.data); - case internal::type::string_type: + case detail::type::string_type: return vis(basic_string_view(arg.value_.string.data, arg.value_.string.size)); - case internal::type::pointer_type: + case detail::type::pointer_type: return vis(arg.value_.pointer); - case internal::type::custom_type: + case detail::type::custom_type: return vis(typename basic_format_arg::handle(arg.value_.custom)); } return vis(monostate()); } -namespace internal { -// A map from argument names to their values for named arguments. -template class arg_map { - private: - using char_type = typename Context::char_type; +// Checks whether T is a container with contiguous storage. +template struct is_contiguous : std::false_type {}; +template +struct is_contiguous> : std::true_type {}; +template +struct is_contiguous> : std::true_type {}; - struct entry { - basic_string_view name; - basic_format_arg arg; - }; +namespace detail { - entry* map_; - unsigned size_; +template +struct is_back_insert_iterator : std::false_type {}; +template +struct is_back_insert_iterator> + : std::true_type {}; - void push_back(value val) { - const auto& named = *val.named_arg; - map_[size_] = {named.name, named.template deserialize()}; - ++size_; - } - - public: - arg_map(const arg_map&) = delete; - void operator=(const arg_map&) = delete; - arg_map() : map_(nullptr), size_(0) {} - void init(const basic_format_args& args); - ~arg_map() { delete[] map_; } - - basic_format_arg find(basic_string_view name) const { - // The list is unsorted, so just return the first matching name. - for (entry *it = map_, *end = map_ + size_; it != end; ++it) { - if (it->name == name) return it->arg; - } - return {}; - } -}; +template +struct is_contiguous_back_insert_iterator : std::false_type {}; +template +struct is_contiguous_back_insert_iterator> + : is_contiguous {}; // A type-erased reference to an std::locale to avoid heavy include. class locale_ref { @@ -1224,10 +1266,14 @@ inline basic_format_arg make_arg(const T& value) { } template struct is_reference_wrapper : std::false_type {}; - template struct is_reference_wrapper> : std::true_type {}; +template const T& unwrap(const T& v) { return v; } +template const T& unwrap(const std::reference_wrapper& v) { + return static_cast(v); +} + class dynamic_arg_list { // Workaround for clang's -Wweak-vtables. Unlike for regular classes, for // templates it doesn't complain about inability to deduce single translation @@ -1252,14 +1298,14 @@ class dynamic_arg_list { public: template const T& push(const Arg& arg) { - auto node = std::unique_ptr>(new typed_node(arg)); - auto& value = node->value; - node->next = std::move(head_); - head_ = std::move(node); + auto new_node = std::unique_ptr>(new typed_node(arg)); + auto& value = new_node->value; + new_node->next = std::move(head_); + head_ = std::move(new_node); return value; } }; -} // namespace internal +} // namespace detail // Formatting context. template class basic_format_context { @@ -1270,8 +1316,7 @@ template class basic_format_context { private: OutputIt out_; basic_format_args args_; - internal::arg_map map_; - internal::locale_ref loc_; + detail::locale_ref loc_; public: using iterator = OutputIt; @@ -1287,34 +1332,38 @@ template class basic_format_context { */ basic_format_context(OutputIt out, basic_format_args ctx_args, - internal::locale_ref loc = internal::locale_ref()) + detail::locale_ref loc = detail::locale_ref()) : out_(out), args_(ctx_args), loc_(loc) {} format_arg arg(int id) const { return args_.get(id); } + format_arg arg(basic_string_view name) { return args_.get(name); } + int arg_id(basic_string_view name) { return args_.get_id(name); } + const basic_format_args& args() const { return args_; } - // Checks if manual indexing is used and returns the argument with the - // specified name. - format_arg arg(basic_string_view name); - - internal::error_handler error_handler() { return {}; } + detail::error_handler error_handler() { return {}; } void on_error(const char* message) { error_handler().on_error(message); } // Returns an iterator to the beginning of the output range. iterator out() { return out_; } // Advances the begin iterator to ``it``. - void advance_to(iterator it) { out_ = it; } + void advance_to(iterator it) { + if (!detail::is_back_insert_iterator()) out_ = it; + } - internal::locale_ref locale() { return loc_; } + detail::locale_ref locale() { return loc_; } }; template using buffer_context = - basic_format_context>, - Char>; + basic_format_context>, Char>; using format_context = buffer_context; using wformat_context = buffer_context; +// Workaround a bug in gcc: https://stackoverflow.com/q/62767544/471164. +#define FMT_BUFFER_CONTEXT(Char) \ + basic_format_context>, Char> + /** \rst An array of references to arguments. It can be implicitly converted into @@ -1331,29 +1380,35 @@ class format_arg_store { private: static const size_t num_args = sizeof...(Args); - static const bool is_packed = num_args < internal::max_packed_args; + static const size_t num_named_args = detail::count_named_args(); + static const bool is_packed = num_args <= detail::max_packed_args; - using value_type = conditional_t, + using value_type = conditional_t, basic_format_arg>; - // If the arguments are not packed, add one more element to mark the end. - value_type data_[num_args + (num_args == 0 ? 1 : 0)]; + detail::arg_data + data_; friend class basic_format_args; - public: - static constexpr unsigned long long types = - is_packed ? internal::encode_types() - : internal::is_unpacked_bit | num_args; + static constexpr unsigned long long desc = + (is_packed ? detail::encode_types() + : detail::is_unpacked_bit | num_args) | + (num_named_args != 0 + ? static_cast(detail::has_named_args_bit) + : 0); + public: format_arg_store(const Args&... args) : #if FMT_GCC_VERSION && FMT_GCC_VERSION < 409 basic_format_args(*this), #endif - data_{internal::make_arg< + data_{detail::make_arg< is_packed, Context, - internal::mapped_type_constant::value>(args)...} { + detail::mapped_type_constant::value>(args)...} { + detail::init_named_args(data_.named_args(), 0, 0, args...); } }; @@ -1373,8 +1428,24 @@ inline format_arg_store make_format_args( /** \rst - A dynamic version of `fmt::format_arg_store<>`. - It's equipped with a storage to potentially temporary objects which lifetime + Returns a named argument to be used in a formatting function. It should only + be used in a call to a formatting function. + + **Example**:: + + fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23)); + \endrst + */ +template +inline detail::named_arg arg(const Char* name, const T& arg) { + static_assert(!detail::is_named_arg(), "nested named arguments"); + return {name, arg}; +} + +/** + \rst + A dynamic version of `fmt::format_arg_store`. + It's equipped with a storage to potentially temporary objects which lifetimes could be shorter than the format arguments object. It can be implicitly converted into `~fmt::basic_format_args` for passing @@ -1392,49 +1463,73 @@ class dynamic_format_arg_store using char_type = typename Context::char_type; template struct need_copy { - static constexpr internal::type mapped_type = - internal::mapped_type_constant::value; + static constexpr detail::type mapped_type = + detail::mapped_type_constant::value; enum { - value = !(internal::is_reference_wrapper::value || + value = !(detail::is_reference_wrapper::value || std::is_same>::value || - std::is_same>::value || - (mapped_type != internal::type::cstring_type && - mapped_type != internal::type::string_type && - mapped_type != internal::type::custom_type && - mapped_type != internal::type::named_arg_type)) + std::is_same>::value || + (mapped_type != detail::type::cstring_type && + mapped_type != detail::type::string_type && + mapped_type != detail::type::custom_type)) }; }; template - using stored_type = conditional_t::value, + using stored_type = conditional_t::value, std::basic_string, T>; // Storage of basic_format_arg must be contiguous. std::vector> data_; + std::vector> named_info_; // Storage of arguments not fitting into basic_format_arg must grow // without relocation because items in data_ refer to it. - internal::dynamic_arg_list dynamic_args_; + detail::dynamic_arg_list dynamic_args_; friend class basic_format_args; unsigned long long get_types() const { - return internal::is_unpacked_bit | data_.size(); + return detail::is_unpacked_bit | data_.size() | + (named_info_.empty() + ? 0ULL + : static_cast(detail::has_named_args_bit)); + } + + const basic_format_arg* data() const { + return named_info_.empty() ? data_.data() : data_.data() + 1; } template void emplace_arg(const T& arg) { - data_.emplace_back(internal::make_arg(arg)); + data_.emplace_back(detail::make_arg(arg)); + } + + template + void emplace_arg(const detail::named_arg& arg) { + if (named_info_.empty()) { + constexpr const detail::named_arg_info* zero_ptr{nullptr}; + data_.insert(data_.begin(), {zero_ptr, 0}); + } + data_.emplace_back(detail::make_arg(detail::unwrap(arg.value))); + auto pop_one = [](std::vector>* data) { + data->pop_back(); + }; + std::unique_ptr>, decltype(pop_one)> + guard{&data_, pop_one}; + named_info_.push_back({arg.name, static_cast(data_.size() - 2u)}); + data_[0].value_.named_args = {named_info_.data(), named_info_.size()}; + guard.release(); } public: /** \rst - Adds an argument into the dynamic store for later passing to a formating + Adds an argument into the dynamic store for later passing to a formatting function. - Note that custom types and string types (but not string views!) are copied - into the store with dynamic memory (in addition to resizing vector). + Note that custom types and string types (but not string views) are copied + into the store dynamically allocating memory if necessary. **Example**:: @@ -1446,25 +1541,78 @@ class dynamic_format_arg_store \endrst */ template void push_back(const T& arg) { - static_assert( - !std::is_base_of, T>::value, - "named arguments are not supported yet"); - if (internal::const_check(need_copy::value)) + if (detail::const_check(need_copy::value)) emplace_arg(dynamic_args_.push>(arg)); else - emplace_arg(arg); + emplace_arg(detail::unwrap(arg)); } /** + \rst Adds a reference to the argument into the dynamic store for later passing to - a formating function. + a formatting function. Supports named arguments wrapped in + ``std::reference_wrapper`` via ``std::ref()``/``std::cref()``. + + **Example**:: + + fmt::dynamic_format_arg_store store; + char str[] = "1234567890"; + store.push_back(std::cref(str)); + int a1_val{42}; + auto a1 = fmt::arg("a1_", a1_val); + store.push_back(std::cref(a1)); + + // Changing str affects the output but only for string and custom types. + str[0] = 'X'; + + std::string result = fmt::vformat("{} and {a1_}"); + assert(result == "X234567890 and 42"); + \endrst */ template void push_back(std::reference_wrapper arg) { static_assert( - need_copy::value, + detail::is_named_arg::type>::value || + need_copy::value, "objects of built-in types and string views are always copied"); emplace_arg(arg.get()); } + + /** + Adds named argument into the dynamic store for later passing to a formatting + function. ``std::reference_wrapper`` is supported to avoid copying of the + argument. + */ + template + void push_back(const detail::named_arg& arg) { + const char_type* arg_name = + dynamic_args_.push>(arg.name).c_str(); + if (detail::const_check(need_copy::value)) { + emplace_arg( + fmt::arg(arg_name, dynamic_args_.push>(arg.value))); + } else { + emplace_arg(fmt::arg(arg_name, arg.value)); + } + } + + /** Erase all elements from the store */ + void clear() { + data_.clear(); + named_info_.clear(); + dynamic_args_ = detail::dynamic_arg_list(); + } + + /** + \rst + Reserves space to store at least *new_cap* arguments including + *new_cap_named* named arguments. + \endrst + */ + void reserve(size_t new_cap, size_t new_cap_named) { + FMT_ASSERT(new_cap >= new_cap_named, + "Set of arguments includes set of named arguments"); + data_.reserve(new_cap); + named_info_.reserve(new_cap_named); + } }; /** @@ -1483,49 +1631,40 @@ template class basic_format_args { using format_arg = basic_format_arg; private: - // To reduce compiled code size per formatting function call, types of first - // max_packed_args arguments are passed in the types_ field. - unsigned long long types_; + // A descriptor that contains information about formatting arguments. + // If the number of arguments is less or equal to max_packed_args then + // argument types are passed in the descriptor. This reduces binary code size + // per formatting function call. + unsigned long long desc_; union { - // If the number of arguments is less than max_packed_args, the argument - // values are stored in values_, otherwise they are stored in args_. - // This is done to reduce compiled code size as storing larger objects + // If is_packed() returns true then argument values are stored in values_; + // otherwise they are stored in args_. This is done to improve cache + // locality and reduce compiled code size since storing larger objects // may require more code (at least on x86-64) even if the same amount of // data is actually copied to stack. It saves ~10% on the bloat test. - const internal::value* values_; + const detail::value* values_; const format_arg* args_; }; - bool is_packed() const { return (types_ & internal::is_unpacked_bit) == 0; } - - internal::type type(int index) const { - int shift = index * internal::packed_arg_bits; - unsigned int mask = (1 << internal::packed_arg_bits) - 1; - return static_cast((types_ >> shift) & mask); + bool is_packed() const { return (desc_ & detail::is_unpacked_bit) == 0; } + bool has_named_args() const { + return (desc_ & detail::has_named_args_bit) != 0; } - friend class internal::arg_map; - - void set_data(const internal::value* values) { values_ = values; } - void set_data(const format_arg* args) { args_ = args; } - - format_arg do_get(int index) const { - format_arg arg; - if (!is_packed()) { - auto num_args = max_size(); - if (index < num_args) arg = args_[index]; - return arg; - } - if (index > internal::max_packed_args) return arg; - arg.type_ = type(index); - if (arg.type_ == internal::type::none_type) return arg; - internal::value& val = arg.value_; - val = values_[index]; - return arg; + detail::type type(int index) const { + int shift = index * detail::packed_arg_bits; + unsigned int mask = (1 << detail::packed_arg_bits) - 1; + return static_cast((desc_ >> shift) & mask); } + basic_format_args(unsigned long long desc, + const detail::value* values) + : desc_(desc), values_(values) {} + basic_format_args(unsigned long long desc, const format_arg* args) + : desc_(desc), args_(args) {} + public: - basic_format_args() : types_(0) {} + basic_format_args() : desc_(0) {} /** \rst @@ -1533,10 +1672,8 @@ template class basic_format_args { \endrst */ template - basic_format_args(const format_arg_store& store) - : types_(store.types) { - set_data(store.data_); - } + FMT_INLINE basic_format_args(const format_arg_store& store) + : basic_format_args(store.desc, store.data_.args()) {} /** \rst @@ -1544,10 +1681,8 @@ template class basic_format_args { `~fmt::dynamic_format_arg_store`. \endrst */ - basic_format_args(const dynamic_format_arg_store& store) - : types_(store.get_types()) { - set_data(store.data_.data()); - } + FMT_INLINE basic_format_args(const dynamic_format_arg_store& store) + : basic_format_args(store.get_types(), store.data()) {} /** \rst @@ -1555,22 +1690,42 @@ template class basic_format_args { \endrst */ basic_format_args(const format_arg* args, int count) - : types_(internal::is_unpacked_bit | internal::to_unsigned(count)) { - set_data(args); - } + : basic_format_args(detail::is_unpacked_bit | detail::to_unsigned(count), + args) {} - /** Returns the argument at specified index. */ - format_arg get(int index) const { - format_arg arg = do_get(index); - if (arg.type_ == internal::type::named_arg_type) - arg = arg.value_.named_arg->template deserialize(); + /** Returns the argument with the specified id. */ + format_arg get(int id) const { + format_arg arg; + if (!is_packed()) { + if (id < max_size()) arg = args_[id]; + return arg; + } + if (id >= detail::max_packed_args) return arg; + arg.type_ = type(id); + if (arg.type_ == detail::type::none_type) return arg; + arg.value_ = values_[id]; return arg; } + template format_arg get(basic_string_view name) const { + int id = get_id(name); + return id >= 0 ? get(id) : format_arg(); + } + + template int get_id(basic_string_view name) const { + if (!has_named_args()) return {}; + const auto& named_args = + (is_packed() ? values_[-1] : args_[-1].value_).named_args; + for (size_t i = 0; i < named_args.size; ++i) { + if (named_args.data[i].name == name) return named_args.data[i].id; + } + return -1; + } + int max_size() const { - unsigned long long max_packed = internal::max_packed_args; + unsigned long long max_packed = detail::max_packed_args; return static_cast(is_packed() ? max_packed - : types_ & ~internal::is_unpacked_bit); + : desc_ & ~detail::is_unpacked_bit); } }; @@ -1578,93 +1733,48 @@ template class basic_format_args { // It is a separate type rather than an alias to make symbols readable. struct format_args : basic_format_args { template - format_args(Args&&... args) - : basic_format_args(static_cast(args)...) {} + FMT_INLINE format_args(const Args&... args) : basic_format_args(args...) {} }; struct wformat_args : basic_format_args { - template - wformat_args(Args&&... args) - : basic_format_args(static_cast(args)...) {} + using basic_format_args::basic_format_args; }; -template struct is_contiguous : std::false_type {}; - -template -struct is_contiguous> : std::true_type {}; - -template -struct is_contiguous> : std::true_type {}; - -namespace internal { - -template -struct is_contiguous_back_insert_iterator : std::false_type {}; -template -struct is_contiguous_back_insert_iterator> - : is_contiguous {}; - -template struct named_arg_base { - basic_string_view name; - - // Serialized value. - mutable char data[sizeof(basic_format_arg>)]; - - named_arg_base(basic_string_view nm) : name(nm) {} - - template basic_format_arg deserialize() const { - basic_format_arg arg; - std::memcpy(&arg, data, sizeof(basic_format_arg)); - return arg; - } -}; - -struct view {}; - -template -struct named_arg : view, named_arg_base { - const T& value; - - named_arg(basic_string_view name, const T& val) - : named_arg_base(name), value(val) {} -}; +namespace detail { +// Reports a compile-time error if S is not a valid format string. template ::value)> -inline void check_format_string(const S&) { -#if defined(FMT_ENFORCE_COMPILE_STRING) +FMT_INLINE void check_format_string(const S&) { +#ifdef FMT_ENFORCE_COMPILE_STRING static_assert(is_compile_string::value, - "FMT_ENFORCE_COMPILE_STRING requires all format strings to " - "utilize FMT_STRING() or fmt()."); + "FMT_ENFORCE_COMPILE_STRING requires all format strings to use " + "FMT_STRING."); #endif } template ::value)> void check_format_string(S); -template struct bool_pack; -template -using all_true = - std::is_same, bool_pack>; - template > inline format_arg_store, remove_reference_t...> make_args_checked(const S& format_str, const remove_reference_t&... args) { - static_assert( - all_true<(!std::is_base_of>::value || - !std::is_reference::value)...>::value, - "passing views as lvalues is disallowed"); + static_assert(count<(std::is_base_of>::value && + std::is_reference::value)...>() == 0, + "passing views as lvalues is disallowed"); check_format_string(format_str); return {args...}; } -template +template ::value)> std::basic_string vformat( basic_string_view format_str, basic_format_args>> args); +FMT_API std::string vformat(string_view format_str, format_args args); + template -typename buffer_context::iterator vformat_to( +typename FMT_BUFFER_CONTEXT(Char)::iterator vformat_to( buffer& buf, basic_string_view format_str, - basic_format_args>> args); + basic_format_args)> args); template ::value)> @@ -1674,58 +1784,38 @@ FMT_API void vprint_mojibake(std::FILE*, string_view, format_args); #ifndef _WIN32 inline void vprint_mojibake(std::FILE*, string_view, format_args) {} #endif -} // namespace internal - -/** - \rst - Returns a named argument to be used in a formatting function. It should only - be used in a call to a formatting function. - - **Example**:: - - fmt::print("Elapsed time: {s:.2f} seconds", fmt::arg("s", 1.23)); - \endrst - */ -template > -inline internal::named_arg arg(const S& name, const T& arg) { - static_assert(internal::is_string::value, ""); - return {name, arg}; -} - -// Disable nested named arguments, e.g. ``arg("a", arg("b", 42))``. -template -void arg(S, internal::named_arg) = delete; +} // namespace detail /** Formats a string and writes the output to ``out``. */ // GCC 8 and earlier cannot handle std::back_insert_iterator with // vformat_to(...) overload, so SFINAE on iterator type instead. -template , - FMT_ENABLE_IF( - internal::is_contiguous_back_insert_iterator::value)> +template < + typename OutputIt, typename S, typename Char = char_t, + FMT_ENABLE_IF(detail::is_contiguous_back_insert_iterator::value)> OutputIt vformat_to( OutputIt out, const S& format_str, basic_format_args>> args) { - using container = remove_reference_t; - internal::container_buffer buf((internal::get_container(out))); - internal::vformat_to(buf, to_string_view(format_str), args); + auto& c = detail::get_container(out); + detail::container_buffer> buf(c); + detail::vformat_to(buf, to_string_view(format_str), args); return out; } template ::value&& internal::is_string::value)> + is_contiguous::value&& detail::is_string::value)> inline std::back_insert_iterator format_to( std::back_insert_iterator out, const S& format_str, Args&&... args) { return vformat_to(out, to_string_view(format_str), - internal::make_args_checked(format_str, args...)); + detail::make_args_checked(format_str, args...)); } template > -inline std::basic_string vformat( +FMT_INLINE std::basic_string vformat( const S& format_str, basic_format_args>> args) { - return internal::vformat(to_string_view(format_str), args); + return detail::vformat(to_string_view(format_str), args); } /** @@ -1741,10 +1831,9 @@ inline std::basic_string vformat( // Pass char_t as a default template parameter instead of using // std::basic_string> to reduce the symbol size. template > -inline std::basic_string format(const S& format_str, Args&&... args) { - return internal::vformat( - to_string_view(format_str), - internal::make_args_checked(format_str, args...)); +FMT_INLINE std::basic_string format(const S& format_str, Args&&... args) { + const auto& vargs = detail::make_args_checked(format_str, args...); + return detail::vformat(to_string_view(format_str), vargs); } FMT_API void vprint(string_view, format_args); @@ -1763,12 +1852,10 @@ FMT_API void vprint(std::FILE*, string_view, format_args); */ template > inline void print(std::FILE* f, const S& format_str, Args&&... args) { - return internal::is_unicode() - ? vprint(f, to_string_view(format_str), - internal::make_args_checked(format_str, args...)) - : internal::vprint_mojibake( - f, to_string_view(format_str), - internal::make_args_checked(format_str, args...)); + const auto& vargs = detail::make_args_checked(format_str, args...); + return detail::is_unicode() + ? vprint(f, to_string_view(format_str), vargs) + : detail::vprint_mojibake(f, to_string_view(format_str), vargs); } /** @@ -1784,12 +1871,11 @@ inline void print(std::FILE* f, const S& format_str, Args&&... args) { */ template > inline void print(const S& format_str, Args&&... args) { - return internal::is_unicode() - ? vprint(to_string_view(format_str), - internal::make_args_checked(format_str, args...)) - : internal::vprint_mojibake( - stdout, to_string_view(format_str), - internal::make_args_checked(format_str, args...)); + const auto& vargs = detail::make_args_checked(format_str, args...); + return detail::is_unicode() + ? vprint(to_string_view(format_str), vargs) + : detail::vprint_mojibake(stdout, to_string_view(format_str), + vargs); } FMT_END_NAMESPACE diff --git a/src/fmt/format-inl.h b/src/fmt/format-inl.h index f632714d81..d8c9c8a5ee 100644 --- a/src/fmt/format-inl.h +++ b/src/fmt/format-inl.h @@ -15,6 +15,7 @@ #include #include // for std::memmove #include +#include #include "format.h" #if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) @@ -22,8 +23,16 @@ #endif #ifdef _WIN32 +# if !defined(NOMINMAX) && !defined(WIN32_LEAN_AND_MEAN) +# define NOMINMAX +# define WIN32_LEAN_AND_MEAN +# include +# undef WIN32_LEAN_AND_MEAN +# undef NOMINMAX +# else +# include +# endif # include -# include #endif #ifdef _MSC_VER @@ -33,15 +42,19 @@ // Dummy implementations of strerror_r and strerror_s called if corresponding // system functions are not available. -inline fmt::internal::null<> strerror_r(int, char*, ...) { return {}; } -inline fmt::internal::null<> strerror_s(char*, std::size_t, ...) { return {}; } +inline fmt::detail::null<> strerror_r(int, char*, ...) { return {}; } +inline fmt::detail::null<> strerror_s(char*, size_t, ...) { return {}; } FMT_BEGIN_NAMESPACE -namespace internal { +namespace detail { FMT_FUNC void assert_fail(const char* file, int line, const char* message) { - print(stderr, "{}:{}: assertion failed: {}", file, line, message); - std::abort(); + // Use unchecked std::fprintf to avoid triggering another assertion when + // writing to stderr fails + std::fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message); + // Chosen instead of std::abort to satisfy Clang in CUDA mode during device + // code pass. + std::terminate(); } #ifndef _MSC_VER @@ -67,14 +80,14 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) { // other - failure // Buffer should be at least of size 1. FMT_FUNC int safe_strerror(int error_code, char*& buffer, - std::size_t buffer_size) FMT_NOEXCEPT { + size_t buffer_size) FMT_NOEXCEPT { FMT_ASSERT(buffer != nullptr && buffer_size != 0, "invalid buffer"); class dispatcher { private: int error_code_; char*& buffer_; - std::size_t buffer_size_; + size_t buffer_size_; // A noop assignment operator to avoid bogus warnings. void operator=(const dispatcher&) {} @@ -97,7 +110,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer, // Handle the case when strerror_r is not available. FMT_MAYBE_UNUSED - int handle(internal::null<>) { + int handle(detail::null<>) { return fallback(strerror_s(buffer_, buffer_size_, error_code_)); } @@ -111,7 +124,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer, #if !FMT_MSC_VER // Fallback to strerror if strerror_r and strerror_s are not available. - int fallback(internal::null<>) { + int fallback(detail::null<>) { errno = 0; buffer_ = strerror(error_code_); return errno; @@ -119,7 +132,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer, #endif public: - dispatcher(int err_code, char*& buf, std::size_t buf_size) + dispatcher(int err_code, char*& buf, size_t buf_size) : error_code_(err_code), buffer_(buf), buffer_size_(buf_size) {} int run() { return handle(strerror_r(error_code_, buffer_, buffer_size_)); } @@ -127,7 +140,7 @@ FMT_FUNC int safe_strerror(int error_code, char*& buffer, return dispatcher(error_code, buffer, buffer_size).run(); } -FMT_FUNC void format_error_code(internal::buffer& out, int error_code, +FMT_FUNC void format_error_code(detail::buffer& out, int error_code, string_view message) FMT_NOEXCEPT { // Report error code making sure that the output fits into // inline_buffer_size to avoid dynamic memory allocation and potential @@ -136,20 +149,17 @@ FMT_FUNC void format_error_code(internal::buffer& out, int error_code, static const char SEP[] = ": "; static const char ERROR_STR[] = "error "; // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. - std::size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; + size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; auto abs_value = static_cast>(error_code); - if (internal::is_negative(error_code)) { + if (detail::is_negative(error_code)) { abs_value = 0 - abs_value; ++error_code_size; } - error_code_size += internal::to_unsigned(internal::count_digits(abs_value)); - internal::writer w(out); - if (message.size() <= inline_buffer_size - error_code_size) { - w.write(message); - w.write(SEP); - } - w.write(ERROR_STR); - w.write(error_code); + error_code_size += detail::to_unsigned(detail::count_digits(abs_value)); + auto it = std::back_inserter(out); + if (message.size() <= inline_buffer_size - error_code_size) + format_to(it, "{}{}", message, SEP); + format_to(it, "{}{}", ERROR_STR, error_code); assert(out.size() <= inline_buffer_size); } @@ -168,10 +178,10 @@ FMT_FUNC void fwrite_fully(const void* ptr, size_t size, size_t count, size_t written = std::fwrite(ptr, size, count, stream); if (written < count) FMT_THROW(system_error(errno, "cannot write to file")); } -} // namespace internal +} // namespace detail #if !defined(FMT_STATIC_THOUSANDS_SEPARATOR) -namespace internal { +namespace detail { template locale_ref::locale_ref(const Locale& loc) : locale_(&loc) { @@ -194,18 +204,16 @@ template FMT_FUNC Char decimal_point_impl(locale_ref loc) { return std::use_facet>(loc.get()) .decimal_point(); } -} // namespace internal +} // namespace detail #else template -FMT_FUNC std::string internal::grouping_impl(locale_ref) { +FMT_FUNC std::string detail::grouping_impl(locale_ref) { return "\03"; } -template -FMT_FUNC Char internal::thousands_sep_impl(locale_ref) { +template FMT_FUNC Char detail::thousands_sep_impl(locale_ref) { return FMT_STATIC_THOUSANDS_SEPARATOR; } -template -FMT_FUNC Char internal::decimal_point_impl(locale_ref) { +template FMT_FUNC Char detail::decimal_point_impl(locale_ref) { return '.'; } #endif @@ -222,9 +230,9 @@ FMT_FUNC void system_error::init(int err_code, string_view format_str, base = std::runtime_error(to_string(buffer)); } -namespace internal { +namespace detail { -template <> FMT_FUNC int count_digits<4>(internal::fallback_uintptr n) { +template <> FMT_FUNC int count_digits<4>(detail::fallback_uintptr n) { // fallback_uintptr is always stored in little endian. int i = static_cast(sizeof(void*)) - 1; while (i > 0 && n.value[i] == 0) --i; @@ -233,12 +241,27 @@ template <> FMT_FUNC int count_digits<4>(internal::fallback_uintptr n) { } template -const char basic_data::digits[] = - "0001020304050607080910111213141516171819" - "2021222324252627282930313233343536373839" - "4041424344454647484950515253545556575859" - "6061626364656667686970717273747576777879" - "8081828384858687888990919293949596979899"; +const typename basic_data::digit_pair basic_data::digits[] = { + {'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, + {'0', '5'}, {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, + {'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'}, {'1', '4'}, + {'1', '5'}, {'1', '6'}, {'1', '7'}, {'1', '8'}, {'1', '9'}, + {'2', '0'}, {'2', '1'}, {'2', '2'}, {'2', '3'}, {'2', '4'}, + {'2', '5'}, {'2', '6'}, {'2', '7'}, {'2', '8'}, {'2', '9'}, + {'3', '0'}, {'3', '1'}, {'3', '2'}, {'3', '3'}, {'3', '4'}, + {'3', '5'}, {'3', '6'}, {'3', '7'}, {'3', '8'}, {'3', '9'}, + {'4', '0'}, {'4', '1'}, {'4', '2'}, {'4', '3'}, {'4', '4'}, + {'4', '5'}, {'4', '6'}, {'4', '7'}, {'4', '8'}, {'4', '9'}, + {'5', '0'}, {'5', '1'}, {'5', '2'}, {'5', '3'}, {'5', '4'}, + {'5', '5'}, {'5', '6'}, {'5', '7'}, {'5', '8'}, {'5', '9'}, + {'6', '0'}, {'6', '1'}, {'6', '2'}, {'6', '3'}, {'6', '4'}, + {'6', '5'}, {'6', '6'}, {'6', '7'}, {'6', '8'}, {'6', '9'}, + {'7', '0'}, {'7', '1'}, {'7', '2'}, {'7', '3'}, {'7', '4'}, + {'7', '5'}, {'7', '6'}, {'7', '7'}, {'7', '8'}, {'7', '9'}, + {'8', '0'}, {'8', '1'}, {'8', '2'}, {'8', '3'}, {'8', '4'}, + {'8', '5'}, {'8', '6'}, {'8', '7'}, {'8', '8'}, {'8', '9'}, + {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, + {'9', '5'}, {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}}; template const char basic_data::hex_digits[] = "0123456789abcdef"; @@ -317,6 +340,10 @@ const char basic_data::background_color[] = "\x1b[48;2;"; template const char basic_data::reset_color[] = "\x1b[0m"; template const wchar_t basic_data::wreset_color[] = L"\x1b[0m"; template const char basic_data::signs[] = {0, '-', '+', ' '}; +template +const char basic_data::left_padding_shifts[] = {31, 31, 0, 1, 0}; +template +const char basic_data::right_padding_shifts[] = {0, 31, 0, 1, 0}; template struct bits { static FMT_CONSTEXPR_DECL const int value = @@ -576,9 +603,10 @@ class bigint { void operator=(const bigint&) = delete; void assign(const bigint& other) { - bigits_.resize(other.bigits_.size()); + auto size = other.bigits_.size(); + bigits_.resize(size); auto data = other.bigits_.data(); - std::copy(data, data + other.bigits_.size(), bigits_.data()); + std::copy(data, data + size, make_checked(bigits_.data(), size)); exp_ = other.exp_; } @@ -594,7 +622,7 @@ class bigint { int num_bigits() const { return static_cast(bigits_.size()) + exp_; } - bigint& operator<<=(int shift) { + FMT_NOINLINE bigint& operator<<=(int shift) { assert(shift >= 0); exp_ += shift / bigit_bits; shift %= bigit_bits; @@ -1125,7 +1153,7 @@ int snprintf_float(T value, int precision, float_specs specs, precision = (precision >= 0 ? precision : 6) - 1; // Build the format string. - enum { max_format_size = 7 }; // Ths longest format is "%#.*Le". + enum { max_format_size = 7 }; // The longest format is "%#.*Le". char format[max_format_size]; char* format_ptr = format; *format_ptr++ = '%'; @@ -1145,13 +1173,13 @@ int snprintf_float(T value, int precision, float_specs specs, for (;;) { auto begin = buf.data() + offset; auto capacity = buf.capacity() - offset; -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +#ifdef FMT_FUZZ if (precision > 100000) throw std::runtime_error( "fuzz mode - avoid large allocation inside snprintf"); #endif // Suppress the warning about a nonliteral format string. - // Cannot use auto becase of a bug in MinGW (#1532). + // Cannot use auto because of a bug in MinGW (#1532). int (*snprintf_ptr)(char*, size_t, const char*, ...) = FMT_SNPRINTF; int result = precision >= 0 ? snprintf_ptr(begin, capacity, format, precision, value) @@ -1268,14 +1296,14 @@ FMT_FUNC const char* utf8_decode(const char* buf, uint32_t* c, int* e) { return next; } -} // namespace internal +} // namespace detail -template <> struct formatter { +template <> struct formatter { format_parse_context::iterator parse(format_parse_context& ctx) { return ctx.begin(); } - format_context::iterator format(const internal::bigint& n, + format_context::iterator format(const detail::bigint& n, format_context& ctx) { auto out = ctx.out(); bool first = true; @@ -1289,12 +1317,12 @@ template <> struct formatter { out = format_to(out, "{:08x}", value); } if (n.exp_ > 0) - out = format_to(out, "p{}", n.exp_ * internal::bigint::bigit_bits); + out = format_to(out, "p{}", n.exp_ * detail::bigint::bigit_bits); return out; } }; -FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { +FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) { auto transcode = [this](const char* p) { auto cp = uint32_t(); auto error = 0; @@ -1325,7 +1353,7 @@ FMT_FUNC internal::utf8_to_utf16::utf8_to_utf16(string_view s) { buffer_.push_back(0); } -FMT_FUNC void format_system_error(internal::buffer& out, int error_code, +FMT_FUNC void format_system_error(detail::buffer& out, int error_code, string_view message) FMT_NOEXCEPT { FMT_TRY { memory_buffer buf; @@ -1333,12 +1361,9 @@ FMT_FUNC void format_system_error(internal::buffer& out, int error_code, for (;;) { char* system_message = &buf[0]; int result = - internal::safe_strerror(error_code, system_message, buf.size()); + detail::safe_strerror(error_code, system_message, buf.size()); if (result == 0) { - internal::writer w(out); - w.write(message); - w.write(": "); - w.write(system_message); + format_to(std::back_inserter(out), "{}: {}", message, system_message); return; } if (result != ERANGE) @@ -1350,7 +1375,7 @@ FMT_FUNC void format_system_error(internal::buffer& out, int error_code, format_error_code(out, error_code, message); } -FMT_FUNC void internal::error_handler::on_error(const char* message) { +FMT_FUNC void detail::error_handler::on_error(const char* message) { FMT_THROW(format_error(message)); } @@ -1359,14 +1384,39 @@ FMT_FUNC void report_system_error(int error_code, report_error(format_system_error, error_code, message); } +struct stringifier { + template FMT_INLINE std::string operator()(T value) const { + return to_string(value); + } + std::string operator()(basic_format_arg::handle h) const { + memory_buffer buf; + detail::buffer& base = buf; + format_parse_context parse_ctx({}); + format_context format_ctx(std::back_inserter(base), {}, {}); + h.format(parse_ctx, format_ctx); + return to_string(buf); + } +}; + +FMT_FUNC std::string detail::vformat(string_view format_str, format_args args) { + if (format_str.size() == 2 && equal2(format_str.data(), "{}")) { + auto arg = args.get(0); + if (!arg) error_handler().on_error("argument not found"); + return visit_format_arg(stringifier(), arg); + } + memory_buffer buffer; + detail::vformat_to(buffer, format_str, args); + return to_string(buffer); +} + FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { memory_buffer buffer; - internal::vformat_to(buffer, format_str, - basic_format_args>(args)); + detail::vformat_to(buffer, format_str, + basic_format_args>(args)); #ifdef _WIN32 auto fd = _fileno(f); if (_isatty(fd)) { - internal::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size())); + detail::utf8_to_utf16 u16(string_view(buffer.data(), buffer.size())); auto written = DWORD(); if (!WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), u16.c_str(), static_cast(u16.size()), &written, @@ -1376,16 +1426,16 @@ FMT_FUNC void vprint(std::FILE* f, string_view format_str, format_args args) { return; } #endif - internal::fwrite_fully(buffer.data(), 1, buffer.size(), f); + detail::fwrite_fully(buffer.data(), 1, buffer.size(), f); } #ifdef _WIN32 // Print assuming legacy (non-Unicode) encoding. -FMT_FUNC void internal::vprint_mojibake(std::FILE* f, string_view format_str, - format_args args) { +FMT_FUNC void detail::vprint_mojibake(std::FILE* f, string_view format_str, + format_args args) { memory_buffer buffer; - internal::vformat_to(buffer, format_str, - basic_format_args>(args)); + detail::vformat_to(buffer, format_str, + basic_format_args>(args)); fwrite_fully(buffer.data(), 1, buffer.size(), f); } #endif diff --git a/src/fmt/format.h b/src/fmt/format.h index 645e0630cd..b1ba07136f 100644 --- a/src/fmt/format.h +++ b/src/fmt/format.h @@ -43,10 +43,6 @@ #include "core.h" -#ifdef FMT_DEPRECATED_INCLUDE_OS -# include "os.h" -#endif - #ifdef __INTEL_COMPILER # define FMT_ICC_VERSION __INTEL_COMPILER #elif defined(__ICL) @@ -74,9 +70,10 @@ #endif #if __cplusplus == 201103L || __cplusplus == 201402L -# if defined(__clang__) && !defined(__INTEL_COMPILER) +# if defined(__clang__) # define FMT_FALLTHROUGH [[clang::fallthrough]] -# elif FMT_GCC_VERSION >= 700 && !defined(__PGI) && !defined(__INTEL_COMPILER) +# elif FMT_GCC_VERSION >= 700 && !defined(__PGI) && \ + (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520) # define FMT_FALLTHROUGH [[gnu::fallthrough]] # else # define FMT_FALLTHROUGH @@ -88,20 +85,28 @@ # define FMT_FALLTHROUGH #endif +#ifndef FMT_MAYBE_UNUSED +# if FMT_HAS_CPP17_ATTRIBUTE(maybe_unused) +# define FMT_MAYBE_UNUSED [[maybe_unused]] +# else +# define FMT_MAYBE_UNUSED +# endif +#endif + #ifndef FMT_THROW # if FMT_EXCEPTIONS # if FMT_MSC_VER || FMT_NVCC FMT_BEGIN_NAMESPACE -namespace internal { +namespace detail { template inline void do_throw(const Exception& x) { // Silence unreachable code warnings in MSVC and NVCC because these // are nearly impossible to fix in a generic code. volatile bool b = true; if (b) throw x; } -} // namespace internal +} // namespace detail FMT_END_NAMESPACE -# define FMT_THROW(x) internal::do_throw(x) +# define FMT_THROW(x) detail::do_throw(x) # else # define FMT_THROW(x) throw x # endif @@ -123,11 +128,10 @@ FMT_END_NAMESPACE #endif #ifndef FMT_USE_USER_DEFINED_LITERALS -// For Intel and NVIDIA compilers both they and the system gcc/msc support UDLs. -# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 407 || \ - FMT_MSC_VER >= 1900) && \ - (!(FMT_ICC_VERSION || FMT_CUDA_VERSION) || FMT_ICC_VERSION >= 1500 || \ - FMT_CUDA_VERSION >= 700) +// EDG based compilers (Intel, NVIDIA, Elbrus, etc), GCC and MSVC support UDLs. +# if (FMT_HAS_FEATURE(cxx_user_literals) || FMT_GCC_VERSION >= 407 || \ + FMT_MSC_VER >= 1900) && \ + (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= /* UDL feature */ 480) # define FMT_USE_USER_DEFINED_LITERALS 1 # else # define FMT_USE_USER_DEFINED_LITERALS 0 @@ -135,12 +139,11 @@ FMT_END_NAMESPACE #endif #ifndef FMT_USE_UDL_TEMPLATE -// EDG front end based compilers (icc, nvcc) and GCC < 6.4 do not propertly +// EDG frontend based compilers (icc, nvcc, etc) and GCC < 6.4 do not properly // support UDL templates and GCC >= 9 warns about them. -# if FMT_USE_USER_DEFINED_LITERALS && FMT_ICC_VERSION == 0 && \ - FMT_CUDA_VERSION == 0 && \ - ((FMT_GCC_VERSION >= 604 && FMT_GCC_VERSION <= 900 && \ - __cplusplus >= 201402L) || \ +# if FMT_USE_USER_DEFINED_LITERALS && \ + (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 501) && \ + ((FMT_GCC_VERSION >= 604 && __cplusplus >= 201402L) || \ FMT_CLANG_VERSION >= 304) # define FMT_USE_UDL_TEMPLATE 1 # else @@ -176,7 +179,7 @@ FMT_END_NAMESPACE # include // _BitScanReverse, _BitScanReverse64 FMT_BEGIN_NAMESPACE -namespace internal { +namespace detail { // Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. # ifndef __clang__ # pragma intrinsic(_BitScanReverse) @@ -189,10 +192,10 @@ inline uint32_t clz(uint32_t x) { // Static analysis complains about using uninitialized data // "r", but the only way that can happen is if "x" is 0, // which the callers guarantee to not happen. -# pragma warning(suppress : 6102) + FMT_SUPPRESS_MSC_WARNING(6102) return 31 - r; } -# define FMT_BUILTIN_CLZ(n) internal::clz(n) +# define FMT_BUILTIN_CLZ(n) detail::clz(n) # if defined(_WIN64) && !defined(__clang__) # pragma intrinsic(_BitScanReverse64) @@ -214,26 +217,21 @@ inline uint32_t clzll(uint64_t x) { // Static analysis complains about using uninitialized data // "r", but the only way that can happen is if "x" is 0, // which the callers guarantee to not happen. -# pragma warning(suppress : 6102) + FMT_SUPPRESS_MSC_WARNING(6102) return 63 - r; } -# define FMT_BUILTIN_CLZLL(n) internal::clzll(n) -} // namespace internal +# define FMT_BUILTIN_CLZLL(n) detail::clzll(n) +} // namespace detail FMT_END_NAMESPACE #endif // Enable the deprecated numeric alignment. -#ifndef FMT_NUMERIC_ALIGN -# define FMT_NUMERIC_ALIGN 1 -#endif - -// Enable the deprecated percent specifier. -#ifndef FMT_DEPRECATED_PERCENT -# define FMT_DEPRECATED_PERCENT 0 +#ifndef FMT_DEPRECATED_NUMERIC_ALIGN +# define FMT_DEPRECATED_NUMERIC_ALIGN 0 #endif FMT_BEGIN_NAMESPACE -namespace internal { +namespace detail { // An equivalent of `*reinterpret_cast(&source)` that doesn't have // undefined behavior (e.g. due to type aliasing). @@ -285,14 +283,31 @@ template constexpr T max_value() { template constexpr int num_bits() { return std::numeric_limits::digits; } +// std::numeric_limits::digits may return 0 for 128-bit ints. +template <> constexpr int num_bits() { return 128; } +template <> constexpr int num_bits() { return 128; } template <> constexpr int num_bits() { return static_cast(sizeof(void*) * std::numeric_limits::digits); } +FMT_INLINE void assume(bool condition) { + (void)condition; +#if FMT_HAS_BUILTIN(__builtin_assume) + __builtin_assume(condition); +#endif +} + +// A workaround for gcc 4.8 to make void_t work in a SFINAE context. +template struct void_t_impl { using type = void; }; + +template +using void_t = typename detail::void_t_impl::type; + // An approximation of iterator_t for pre-C++20 systems. template using iterator_t = decltype(std::begin(std::declval())); +template using sentinel_t = decltype(std::end(std::declval())); // Detect the iterator category of *any* given type in a SFINAE-friendly way. // Unfortunately, older implementations of std::iterator_traits are not safe @@ -339,25 +354,39 @@ inline typename Container::value_type* get_data(Container& c) { #if defined(_SECURE_SCL) && _SECURE_SCL // Make a checked iterator to avoid MSVC warnings. template using checked_ptr = stdext::checked_array_iterator; -template checked_ptr make_checked(T* p, std::size_t size) { +template checked_ptr make_checked(T* p, size_t size) { return {p, size}; } #else template using checked_ptr = T*; -template inline T* make_checked(T* p, std::size_t) { return p; } +template inline T* make_checked(T* p, size_t) { return p; } #endif template ::value)> -inline checked_ptr reserve( - std::back_insert_iterator& it, std::size_t n) { +#if FMT_CLANG_VERSION +__attribute__((no_sanitize("undefined"))) +#endif +inline checked_ptr +reserve(std::back_insert_iterator it, size_t n) { Container& c = get_container(it); - std::size_t size = c.size(); + size_t size = c.size(); c.resize(size + n); return make_checked(get_data(c) + size, n); } +template inline Iterator& reserve(Iterator& it, size_t) { + return it; +} + +template ::value)> +inline std::back_insert_iterator base_iterator( + std::back_insert_iterator& it, + checked_ptr) { + return it; +} + template -inline Iterator& reserve(Iterator& it, std::size_t) { +inline Iterator base_iterator(Iterator, Iterator it) { return it; } @@ -365,7 +394,7 @@ inline Iterator& reserve(Iterator& it, std::size_t) { // discards them. class counting_iterator { private: - std::size_t count_; + size_t count_; public: using iterator_category = std::output_iterator_tag; @@ -380,7 +409,7 @@ class counting_iterator { counting_iterator() : count_(0) {} - std::size_t count() const { return count_; } + size_t count() const { return count_; } counting_iterator& operator++() { ++count_; @@ -399,10 +428,10 @@ class counting_iterator { template class truncating_iterator_base { protected: OutputIt out_; - std::size_t limit_; - std::size_t count_; + size_t limit_; + size_t count_; - truncating_iterator_base(OutputIt out, std::size_t limit) + truncating_iterator_base(OutputIt out, size_t limit) : out_(out), limit_(limit), count_(0) {} public: @@ -415,7 +444,7 @@ template class truncating_iterator_base { truncating_iterator_base; // Mark iterator as checked. OutputIt base() const { return out_; } - std::size_t count() const { return count_; } + size_t count() const { return count_; } }; // An output iterator that truncates the output and counts the number of objects @@ -433,7 +462,7 @@ class truncating_iterator public: using value_type = typename truncating_iterator_base::value_type; - truncating_iterator(OutputIt out, std::size_t limit) + truncating_iterator(OutputIt out, size_t limit) : truncating_iterator_base(out, limit) {} truncating_iterator& operator++() { @@ -456,7 +485,7 @@ template class truncating_iterator : public truncating_iterator_base { public: - truncating_iterator(OutputIt out, std::size_t limit) + truncating_iterator(OutputIt out, size_t limit) : truncating_iterator_base(out, limit) {} template truncating_iterator& operator=(T val) { @@ -469,22 +498,6 @@ class truncating_iterator truncating_iterator& operator*() { return *this; } }; -// A range with the specified output iterator and value type. -template -class output_range { - private: - OutputIt it_; - - public: - using value_type = T; - using iterator = OutputIt; - struct sentinel {}; - - explicit output_range(OutputIt it) : it_(it) {} - OutputIt begin() const { return it_; } - sentinel end() const { return {}; } // Sentinel is not used yet. -}; - template inline size_t count_code_points(basic_string_view s) { return s.size(); @@ -523,8 +536,6 @@ inline size_t code_point_index(basic_string_view s, size_t n) { return s.size(); } -inline char8_type to_char8_t(char c) { return static_cast(c); } - template using needs_conversion = bool_constant< std::is_same::value_type, @@ -540,7 +551,8 @@ OutputIt copy_str(InputIt begin, InputIt end, OutputIt it) { template ::value)> OutputIt copy_str(InputIt begin, InputIt end, OutputIt it) { - return std::transform(begin, end, it, to_char8_t); + return std::transform(begin, end, it, + [](char c) { return static_cast(c); }); } #ifndef FMT_USE_GRISU @@ -555,43 +567,13 @@ template constexpr bool use_grisu() { template template void buffer::append(const U* begin, const U* end) { - std::size_t new_size = size_ + to_unsigned(end - begin); + size_t new_size = size_ + to_unsigned(end - begin); reserve(new_size); - std::uninitialized_copy(begin, end, make_checked(ptr_, capacity_) + size_); + std::uninitialized_copy(begin, end, + make_checked(ptr_ + size_, capacity_ - size_)); size_ = new_size; } -} // namespace internal - -// A range with an iterator appending to a buffer. -template -class buffer_range : public internal::output_range< - std::back_insert_iterator>, T> { - public: - using iterator = std::back_insert_iterator>; - using internal::output_range::output_range; - buffer_range(internal::buffer& buf) - : internal::output_range(std::back_inserter(buf)) {} -}; - -class FMT_DEPRECATED u8string_view - : public basic_string_view { - public: - u8string_view(const char* s) - : basic_string_view( - reinterpret_cast(s)) {} - u8string_view(const char* s, size_t count) FMT_NOEXCEPT - : basic_string_view( - reinterpret_cast(s), count) {} -}; - -#if FMT_USE_USER_DEFINED_LITERALS -inline namespace literals { -FMT_DEPRECATED inline basic_string_view operator"" _u( - const char* s, std::size_t n) { - return {reinterpret_cast(s), n}; -} -} // namespace literals -#endif +} // namespace detail // The number of characters to store in the basic_memory_buffer object itself // to avoid dynamic memory allocation. @@ -626,27 +608,30 @@ enum { inline_buffer_size = 500 }; The output can be converted to an ``std::string`` with ``to_string(out)``. \endrst */ -template > -class basic_memory_buffer : private Allocator, public internal::buffer { +class basic_memory_buffer : public detail::buffer { private: T store_[SIZE]; + // Don't inherit from Allocator avoid generating type_info for it. + Allocator alloc_; + // Deallocate memory allocated by the buffer. void deallocate() { T* data = this->data(); - if (data != store_) Allocator::deallocate(data, this->capacity()); + if (data != store_) alloc_.deallocate(data, this->capacity()); } protected: - void grow(std::size_t size) FMT_OVERRIDE; + void grow(size_t size) FMT_OVERRIDE; public: using value_type = T; using const_reference = const T&; explicit basic_memory_buffer(const Allocator& alloc = Allocator()) - : Allocator(alloc) { + : alloc_(alloc) { this->set(store_, SIZE); } ~basic_memory_buffer() FMT_OVERRIDE { deallocate(); } @@ -654,14 +639,13 @@ class basic_memory_buffer : private Allocator, public internal::buffer { private: // Move data from other to this buffer. void move(basic_memory_buffer& other) { - Allocator &this_alloc = *this, &other_alloc = other; - this_alloc = std::move(other_alloc); + alloc_ = std::move(other.alloc_); T* data = other.data(); - std::size_t size = other.size(), capacity = other.capacity(); + size_t size = other.size(), capacity = other.capacity(); if (data == other.store_) { this->set(store_, capacity); std::uninitialized_copy(other.store_, other.store_ + size, - internal::make_checked(store_, capacity)); + detail::make_checked(store_, capacity)); } else { this->set(data, capacity); // Set pointer to the inline array so that delete is not called @@ -693,32 +677,37 @@ class basic_memory_buffer : private Allocator, public internal::buffer { } // Returns a copy of the allocator associated with this buffer. - Allocator get_allocator() const { return *this; } + Allocator get_allocator() const { return alloc_; } }; -template -void basic_memory_buffer::grow(std::size_t size) { -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if (size > 1000) throw std::runtime_error("fuzz mode - won't grow that much"); +template +void basic_memory_buffer::grow(size_t size) { +#ifdef FMT_FUZZ + if (size > 5000) throw std::runtime_error("fuzz mode - won't grow that much"); #endif - std::size_t old_capacity = this->capacity(); - std::size_t new_capacity = old_capacity + old_capacity / 2; + size_t old_capacity = this->capacity(); + size_t new_capacity = old_capacity + old_capacity / 2; if (size > new_capacity) new_capacity = size; T* old_data = this->data(); - T* new_data = std::allocator_traits::allocate(*this, new_capacity); + T* new_data = + std::allocator_traits::allocate(alloc_, new_capacity); // The following code doesn't throw, so the raw pointer above doesn't leak. std::uninitialized_copy(old_data, old_data + this->size(), - internal::make_checked(new_data, new_capacity)); + detail::make_checked(new_data, new_capacity)); this->set(new_data, new_capacity); // deallocate must not throw according to the standard, but even if it does, // the buffer already uses the new storage and will deallocate it in // destructor. - if (old_data != store_) Allocator::deallocate(old_data, old_capacity); + if (old_data != store_) alloc_.deallocate(old_data, old_capacity); } using memory_buffer = basic_memory_buffer; using wmemory_buffer = basic_memory_buffer; +template +struct is_contiguous> : std::true_type { +}; + /** A formatting error such as invalid format string. */ FMT_CLASS_API class FMT_API format_error : public std::runtime_error { @@ -733,7 +722,7 @@ class FMT_API format_error : public std::runtime_error { ~format_error() FMT_NOEXCEPT FMT_OVERRIDE; }; -namespace internal { +namespace detail { // Returns true if value is negative, false otherwise. // Same as `value < 0` but doesn't produce warnings if T is an unsigned type. @@ -757,8 +746,8 @@ FMT_CONSTEXPR bool is_supported_floating_point(T) { // represent all values of T. template using uint32_or_64_or_128_t = conditional_t< - std::numeric_limits::digits <= 32, uint32_t, - conditional_t::digits <= 64, uint64_t, uint128_t>>; + num_bits() <= 32, uint32_t, + conditional_t() <= 64, uint64_t, uint128_t>>; // Static data is placed in this class template for the header-only config. template struct FMT_EXTERN_TEMPLATE_API basic_data { @@ -767,16 +756,22 @@ template struct FMT_EXTERN_TEMPLATE_API basic_data { static const uint64_t zero_or_powers_of_10_64[]; static const uint64_t pow10_significands[]; static const int16_t pow10_exponents[]; - static const char digits[]; + // GCC generates slightly better code for pairs than chars. + using digit_pair = char[2]; + static const digit_pair digits[]; static const char hex_digits[]; static const char foreground_color[]; static const char background_color[]; static const char reset_color[5]; static const wchar_t wreset_color[5]; static const char signs[]; + static const char left_padding_shifts[5]; + static const char right_padding_shifts[5]; }; +#ifndef FMT_EXPORTED FMT_EXTERN template struct basic_data; +#endif // This is a struct rather than an alias to avoid shadowing warnings in gcc. struct data : basic_data<> {}; @@ -834,7 +829,7 @@ template inline int count_digits(UInt n) { return num_digits; } -template <> int count_digits<4>(internal::fallback_uintptr n); +template <> int count_digits<4>(detail::fallback_uintptr n); #if FMT_GCC_VERSION || FMT_CLANG_VERSION # define FMT_ALWAYS_INLINE inline __attribute__((always_inline)) @@ -850,6 +845,12 @@ inline int count_digits(uint32_t n) { } #endif +template constexpr int digits10() FMT_NOEXCEPT { + return std::numeric_limits::digits10; +} +template <> constexpr int digits10() FMT_NOEXCEPT { return 38; } +template <> constexpr int digits10() FMT_NOEXCEPT { return 38; } + template FMT_API std::string grouping_impl(locale_ref loc); template inline std::string grouping(locale_ref loc) { return grouping_impl(loc); @@ -874,57 +875,61 @@ template <> inline wchar_t decimal_point(locale_ref loc) { return decimal_point_impl(loc); } -// Formats a decimal unsigned integer value writing into buffer. -// add_thousands_sep is called after writing each char to add a thousands -// separator if necessary. -template -inline Char* format_decimal(Char* buffer, UInt value, int num_digits, - F add_thousands_sep) { - FMT_ASSERT(num_digits >= 0, "invalid digit count"); - buffer += num_digits; - Char* end = buffer; +// Compares two characters for equality. +template bool equal2(const Char* lhs, const char* rhs) { + return lhs[0] == rhs[0] && lhs[1] == rhs[1]; +} +inline bool equal2(const char* lhs, const char* rhs) { + return memcmp(lhs, rhs, 2) == 0; +} + +// Copies two characters from src to dst. +template void copy2(Char* dst, const char* src) { + *dst++ = static_cast(*src++); + *dst = static_cast(*src); +} +inline void copy2(char* dst, const char* src) { memcpy(dst, src, 2); } + +template struct format_decimal_result { + Iterator begin; + Iterator end; +}; + +// Formats a decimal unsigned integer value writing into out pointing to a +// buffer of specified size. The caller must ensure that the buffer is large +// enough. +template +inline format_decimal_result format_decimal(Char* out, UInt value, + int size) { + FMT_ASSERT(size >= count_digits(value), "invalid digit count"); + out += size; + Char* end = out; while (value >= 100) { // Integer division is slow so do it for a group of two digits instead // of for every digit. The idea comes from the talk by Alexandrescu // "Three Optimization Tips for C++". See speed-test for a comparison. - auto index = static_cast((value % 100) * 2); + out -= 2; + copy2(out, data::digits[value % 100]); value /= 100; - *--buffer = static_cast(data::digits[index + 1]); - add_thousands_sep(buffer); - *--buffer = static_cast(data::digits[index]); - add_thousands_sep(buffer); } if (value < 10) { - *--buffer = static_cast('0' + value); - return end; + *--out = static_cast('0' + value); + return {out, end}; } - auto index = static_cast(value * 2); - *--buffer = static_cast(data::digits[index + 1]); - add_thousands_sep(buffer); - *--buffer = static_cast(data::digits[index]); - return end; + out -= 2; + copy2(out, data::digits[value]); + return {out, end}; } -template constexpr int digits10() FMT_NOEXCEPT { - return std::numeric_limits::digits10; -} -template <> constexpr int digits10() FMT_NOEXCEPT { return 38; } -template <> constexpr int digits10() FMT_NOEXCEPT { return 38; } - -template -inline Iterator format_decimal(Iterator out, UInt value, int num_digits, - F add_thousands_sep) { - FMT_ASSERT(num_digits >= 0, "invalid digit count"); +template >::value)> +inline format_decimal_result format_decimal(Iterator out, UInt value, + int num_digits) { // Buffer should be large enough to hold all digits (<= digits10 + 1). enum { max_size = digits10() + 1 }; Char buffer[2 * max_size]; - auto end = format_decimal(buffer, value, num_digits, add_thousands_sep); - return internal::copy_str(buffer, end, out); -} - -template -inline It format_decimal(It out, UInt value, int num_digits) { - return format_decimal(out, value, num_digits, [](Char*) {}); + auto end = format_decimal(buffer, value, num_digits).end; + return {out, detail::copy_str(buffer, end, out)}; } template @@ -942,7 +947,7 @@ inline Char* format_uint(Char* buffer, UInt value, int num_digits, } template -Char* format_uint(Char* buffer, internal::fallback_uintptr n, int num_digits, +Char* format_uint(Char* buffer, detail::fallback_uintptr n, int num_digits, bool = false) { auto char_digits = std::numeric_limits::digits / 4; int start = (num_digits + char_digits - 1) / char_digits - 1; @@ -968,7 +973,7 @@ inline It format_uint(It out, UInt value, int num_digits, bool upper = false) { // Buffer should be large enough to hold all digits (digits / BASE_BITS + 1). char buffer[num_bits() / BASE_BITS + 1]; format_uint(buffer, value, num_digits, upper); - return internal::copy_str(buffer, buffer + num_digits, out); + return detail::copy_str(buffer, buffer + num_digits, out); } // A converter from UTF-8 to UTF-16. @@ -1019,7 +1024,7 @@ template struct fill_t { return fill; } }; -} // namespace internal +} // namespace detail // We cannot use enum classes as bit fields because of a gcc bug // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414. @@ -1041,7 +1046,7 @@ template struct basic_format_specs { align_t align : 4; sign_t sign : 3; bool alt : 1; // Alternate form ('#'). - internal::fill_t fill; + detail::fill_t fill; constexpr basic_format_specs() : width(0), @@ -1050,12 +1055,12 @@ template struct basic_format_specs { align(align::none), sign(sign::none), alt(false), - fill(internal::fill_t::make()) {} + fill(detail::fill_t::make()) {} }; using format_specs = basic_format_specs; -namespace internal { +namespace detail { // A floating-point presentation format. enum class float_format : unsigned char { @@ -1071,7 +1076,6 @@ struct float_specs { sign_t sign : 8; bool upper : 1; bool locale : 1; - bool percent : 1; bool binary32 : 1; bool use_grisu : 1; bool showpoint : 1; @@ -1087,12 +1091,12 @@ template It write_exponent(int exp, It it) { *it++ = static_cast('+'); } if (exp >= 100) { - const char* top = data::digits + (exp / 100) * 2; + const char* top = data::digits[exp / 100]; if (exp >= 1000) *it++ = static_cast(top[0]); *it++ = static_cast(top[1]); exp %= 100; } - const char* d = data::digits + exp * 2; + const char* d = data::digits[exp]; *it++ = static_cast(d[0]); *it++ = static_cast(d[1]); return it; @@ -1134,8 +1138,8 @@ template class float_writer { *it++ = static_cast('0'); return it; } -#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION - if (num_zeros > 1000) +#ifdef FMT_FUZZ + if (num_zeros > 5000) throw std::runtime_error("fuzz mode - avoiding excessive cpu use"); #endif it = std::fill_n(it, num_zeros, static_cast('0')); @@ -1198,11 +1202,10 @@ template class float_writer { } size_t size() const { return size_; } - size_t width() const { return size(); } - template void operator()(It&& it) { + template It operator()(It it) const { if (specs_.sign) *it++ = static_cast(data::signs[specs_.sign]); - it = prettify(it); + return prettify(it); } }; @@ -1235,10 +1238,15 @@ FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) { case 'o': handler.on_oct(); break; +#ifdef FMT_DEPRECATED_N_SPECIFIER case 'n': +#endif case 'L': handler.on_num(); break; + case 'c': + handler.on_chr(); + break; default: handler.on_error(); } @@ -1274,19 +1282,16 @@ FMT_CONSTEXPR float_specs parse_float_type_spec( result.format = float_format::fixed; result.showpoint |= specs.precision != 0; break; -#if FMT_DEPRECATED_PERCENT - case '%': - result.format = float_format::fixed; - result.percent = true; - break; -#endif case 'A': result.upper = true; FMT_FALLTHROUGH; case 'a': result.format = float_format::hex; break; +#ifdef FMT_DEPRECATED_N_SPECIFIER case 'n': +#endif + case 'L': result.locale = true; break; default: @@ -1335,6 +1340,7 @@ template class int_type_checker : private ErrorHandler { FMT_CONSTEXPR void on_bin() {} FMT_CONSTEXPR void on_oct() {} FMT_CONSTEXPR void on_num() {} + FMT_CONSTEXPR void on_chr() {} FMT_CONSTEXPR void on_error() { ErrorHandler::on_error("invalid type specifier"); @@ -1366,38 +1372,6 @@ class cstring_type_checker : public ErrorHandler { FMT_CONSTEXPR void on_pointer() {} }; -template -void arg_map::init(const basic_format_args& args) { - if (map_) return; - map_ = new entry[internal::to_unsigned(args.max_size())]; - if (args.is_packed()) { - for (int i = 0;; ++i) { - internal::type arg_type = args.type(i); - if (arg_type == internal::type::none_type) return; - if (arg_type == internal::type::named_arg_type) - push_back(args.values_[i]); - } - } - for (int i = 0, n = args.max_size(); i < n; ++i) { - auto type = args.args_[i].type_; - if (type == internal::type::named_arg_type) push_back(args.args_[i].value_); - } -} - -template struct nonfinite_writer { - sign_t sign; - const char* str; - static constexpr size_t str_size = 3; - - size_t size() const { return str_size + (sign ? 1 : 0); } - size_t width() const { return size(); } - - template void operator()(It&& it) const { - if (sign) *it++ = static_cast(data::signs[sign]); - it = copy_str(str, str + str_size, it); - } -}; - template FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t& fill) { auto fill_size = fill.size(); @@ -1406,375 +1380,470 @@ FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t& fill) { return it; } -// This template provides operations for formatting and writing data into a -// character range. -template class basic_writer { - public: - using char_type = typename Range::value_type; - using iterator = typename Range::iterator; - using format_specs = basic_format_specs; +// Writes the output of f, padded according to format specifications in specs. +// size: output size in code units. +// width: output display width in (terminal) column positions. +template +inline OutputIt write_padded(OutputIt out, + const basic_format_specs& specs, size_t size, + size_t width, const F& f) { + static_assert(align == align::left || align == align::right, ""); + unsigned spec_width = to_unsigned(specs.width); + size_t padding = spec_width > width ? spec_width - width : 0; + auto* shifts = align == align::left ? data::left_padding_shifts + : data::right_padding_shifts; + size_t left_padding = padding >> shifts[specs.align]; + auto it = reserve(out, size + padding * specs.fill.size()); + it = fill(it, left_padding, specs.fill); + it = f(it); + it = fill(it, padding - left_padding, specs.fill); + return base_iterator(out, it); +} - private: - iterator out_; // Output iterator. - locale_ref locale_; +template +inline OutputIt write_padded(OutputIt out, + const basic_format_specs& specs, size_t size, + const F& f) { + return write_padded(out, specs, size, size, f); +} - // Attempts to reserve space for n extra characters in the output range. - // Returns a pointer to the reserved range or a reference to out_. - auto reserve(std::size_t n) -> decltype(internal::reserve(out_, n)) { - return internal::reserve(out_, n); - } +template +OutputIt write_bytes(OutputIt out, string_view bytes, + const basic_format_specs& specs) { + using iterator = remove_reference_t; + return write_padded(out, specs, bytes.size(), [bytes](iterator it) { + const char* data = bytes.data(); + return copy_str(data, data + bytes.size(), it); + }); +} - template struct padded_int_writer { - size_t size_; - string_view prefix; - char_type fill; - std::size_t padding; - F f; +// Data for write_int that doesn't depend on output iterator type. It is used to +// avoid template code bloat. +template struct write_int_data { + size_t size; + size_t padding; - size_t size() const { return size_; } - size_t width() const { return size_; } - - template void operator()(It&& it) const { - if (prefix.size() != 0) - it = copy_str(prefix.begin(), prefix.end(), it); - it = std::fill_n(it, padding, fill); - f(it); - } - }; - - // Writes an integer in the format - // - // where are written by f(it). - template - void write_int(int num_digits, string_view prefix, format_specs specs, F f) { - std::size_t size = prefix.size() + to_unsigned(num_digits); - char_type fill = specs.fill[0]; - std::size_t padding = 0; + write_int_data(int num_digits, string_view prefix, + const basic_format_specs& specs) + : size(prefix.size() + to_unsigned(num_digits)), padding(0) { if (specs.align == align::numeric) { - auto unsiged_width = to_unsigned(specs.width); - if (unsiged_width > size) { - padding = unsiged_width - size; - size = unsiged_width; + auto width = to_unsigned(specs.width); + if (width > size) { + padding = width - size; + size = width; } } else if (specs.precision > num_digits) { size = prefix.size() + to_unsigned(specs.precision); padding = to_unsigned(specs.precision - num_digits); - fill = static_cast('0'); } - if (specs.align == align::none) specs.align = align::right; - write_padded(specs, padded_int_writer{size, prefix, fill, padding, f}); + } +}; + +// Writes an integer in the format +// +// where are written by f(it). +template +OutputIt write_int(OutputIt out, int num_digits, string_view prefix, + const basic_format_specs& specs, F f) { + auto data = write_int_data(num_digits, prefix, specs); + using iterator = remove_reference_t; + return write_padded(out, specs, data.size, [=](iterator it) { + if (prefix.size() != 0) + it = copy_str(prefix.begin(), prefix.end(), it); + it = std::fill_n(it, data.padding, static_cast('0')); + return f(it); + }); +} + +template +OutputIt write(OutputIt out, basic_string_view s, + const basic_format_specs& specs) { + auto data = s.data(); + auto size = s.size(); + if (specs.precision >= 0 && to_unsigned(specs.precision) < size) + size = code_point_index(s, to_unsigned(specs.precision)); + auto width = specs.width != 0 + ? count_code_points(basic_string_view(data, size)) + : 0; + using iterator = remove_reference_t; + return write_padded(out, specs, size, width, [=](iterator it) { + return copy_str(data, data + size, it); + }); +} + +// The handle_int_type_spec handler that writes an integer. +template struct int_writer { + OutputIt out; + locale_ref locale; + const basic_format_specs& specs; + UInt abs_value; + char prefix[4]; + unsigned prefix_size; + + using iterator = + remove_reference_t(), 0))>; + + string_view get_prefix() const { return string_view(prefix, prefix_size); } + + template + int_writer(OutputIt output, locale_ref loc, Int value, + const basic_format_specs& s) + : out(output), + locale(loc), + specs(s), + abs_value(static_cast(value)), + prefix_size(0) { + static_assert(std::is_same, UInt>::value, ""); + if (is_negative(value)) { + prefix[0] = '-'; + ++prefix_size; + abs_value = 0 - abs_value; + } else if (specs.sign != sign::none && specs.sign != sign::minus) { + prefix[0] = specs.sign == sign::plus ? '+' : ' '; + ++prefix_size; + } } - // Writes a decimal integer. - template void write_decimal(Int value) { - auto abs_value = static_cast>(value); - bool negative = is_negative(value); - // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer. - if (negative) abs_value = ~abs_value + 1; + void on_dec() { + auto num_digits = count_digits(abs_value); + out = write_int( + out, num_digits, get_prefix(), specs, [this, num_digits](iterator it) { + return format_decimal(it, abs_value, num_digits).end; + }); + } + + void on_hex() { + if (specs.alt) { + prefix[prefix_size++] = '0'; + prefix[prefix_size++] = specs.type; + } + int num_digits = count_digits<4>(abs_value); + out = write_int(out, num_digits, get_prefix(), specs, + [this, num_digits](iterator it) { + return format_uint<4, Char>(it, abs_value, num_digits, + specs.type != 'x'); + }); + } + + void on_bin() { + if (specs.alt) { + prefix[prefix_size++] = '0'; + prefix[prefix_size++] = static_cast(specs.type); + } + int num_digits = count_digits<1>(abs_value); + out = write_int(out, num_digits, get_prefix(), specs, + [this, num_digits](iterator it) { + return format_uint<1, Char>(it, abs_value, num_digits); + }); + } + + void on_oct() { + int num_digits = count_digits<3>(abs_value); + if (specs.alt && specs.precision <= num_digits && abs_value != 0) { + // Octal prefix '0' is counted as a digit, so only add it if precision + // is not greater than the number of digits. + prefix[prefix_size++] = '0'; + } + out = write_int(out, num_digits, get_prefix(), specs, + [this, num_digits](iterator it) { + return format_uint<3, Char>(it, abs_value, num_digits); + }); + } + + enum { sep_size = 1 }; + + void on_num() { + std::string groups = grouping(locale); + if (groups.empty()) return on_dec(); + auto sep = thousands_sep(locale); + if (!sep) return on_dec(); int num_digits = count_digits(abs_value); - auto&& it = reserve((negative ? 1 : 0) + static_cast(num_digits)); - if (negative) *it++ = static_cast('-'); - it = format_decimal(it, abs_value, num_digits); - } - - // The handle_int_type_spec handler that writes an integer. - template struct int_writer { - using unsigned_type = uint32_or_64_or_128_t; - - basic_writer& writer; - const Specs& specs; - unsigned_type abs_value; - char prefix[4]; - unsigned prefix_size; - - string_view get_prefix() const { return string_view(prefix, prefix_size); } - - int_writer(basic_writer& w, Int value, const Specs& s) - : writer(w), - specs(s), - abs_value(static_cast(value)), - prefix_size(0) { - if (is_negative(value)) { - prefix[0] = '-'; - ++prefix_size; - abs_value = 0 - abs_value; - } else if (specs.sign != sign::none && specs.sign != sign::minus) { - prefix[0] = specs.sign == sign::plus ? '+' : ' '; - ++prefix_size; - } + int size = num_digits, n = num_digits; + std::string::const_iterator group = groups.cbegin(); + while (group != groups.cend() && n > *group && *group > 0 && + *group != max_value()) { + size += sep_size; + n -= *group; + ++group; } - - struct dec_writer { - unsigned_type abs_value; - int num_digits; - - template void operator()(It&& it) const { - it = internal::format_decimal(it, abs_value, num_digits); - } - }; - - void on_dec() { - int num_digits = count_digits(abs_value); - writer.write_int(num_digits, get_prefix(), specs, - dec_writer{abs_value, num_digits}); - } - - struct hex_writer { - int_writer& self; - int num_digits; - - template void operator()(It&& it) const { - it = format_uint<4, char_type>(it, self.abs_value, num_digits, - self.specs.type != 'x'); - } - }; - - void on_hex() { - if (specs.alt) { - prefix[prefix_size++] = '0'; - prefix[prefix_size++] = specs.type; - } - int num_digits = count_digits<4>(abs_value); - writer.write_int(num_digits, get_prefix(), specs, - hex_writer{*this, num_digits}); - } - - template struct bin_writer { - unsigned_type abs_value; - int num_digits; - - template void operator()(It&& it) const { - it = format_uint(it, abs_value, num_digits); - } - }; - - void on_bin() { - if (specs.alt) { - prefix[prefix_size++] = '0'; - prefix[prefix_size++] = static_cast(specs.type); - } - int num_digits = count_digits<1>(abs_value); - writer.write_int(num_digits, get_prefix(), specs, - bin_writer<1>{abs_value, num_digits}); - } - - void on_oct() { - int num_digits = count_digits<3>(abs_value); - if (specs.alt && specs.precision <= num_digits && abs_value != 0) { - // Octal prefix '0' is counted as a digit, so only add it if precision - // is not greater than the number of digits. - prefix[prefix_size++] = '0'; - } - writer.write_int(num_digits, get_prefix(), specs, - bin_writer<3>{abs_value, num_digits}); - } - - enum { sep_size = 1 }; - - struct num_writer { - unsigned_type abs_value; - int size; - const std::string& groups; - char_type sep; - - template void operator()(It&& it) const { - basic_string_view s(&sep, sep_size); - // Index of a decimal digit with the least significant digit having - // index 0. - int digit_index = 0; - std::string::const_iterator group = groups.cbegin(); - it = format_decimal( - it, abs_value, size, - [this, s, &group, &digit_index](char_type*& buffer) { - if (*group <= 0 || ++digit_index % *group != 0 || - *group == max_value()) - return; - if (group + 1 != groups.cend()) { - digit_index = 0; - ++group; - } - buffer -= s.size(); - std::uninitialized_copy(s.data(), s.data() + s.size(), - make_checked(buffer, s.size())); - }); - } - }; - - void on_num() { - std::string groups = grouping(writer.locale_); - if (groups.empty()) return on_dec(); - auto sep = thousands_sep(writer.locale_); - if (!sep) return on_dec(); - int num_digits = count_digits(abs_value); - int size = num_digits; - std::string::const_iterator group = groups.cbegin(); - while (group != groups.cend() && num_digits > *group && *group > 0 && - *group != max_value()) { - size += sep_size; - num_digits -= *group; + if (group == groups.cend()) size += sep_size * ((n - 1) / groups.back()); + char digits[40]; + format_decimal(digits, abs_value, num_digits); + basic_memory_buffer buffer; + size += prefix_size; + buffer.resize(size); + basic_string_view s(&sep, sep_size); + // Index of a decimal digit with the least significant digit having index 0. + int digit_index = 0; + group = groups.cbegin(); + auto p = buffer.data() + size; + for (int i = num_digits - 1; i >= 0; --i) { + *--p = static_cast(digits[i]); + if (*group <= 0 || ++digit_index % *group != 0 || + *group == max_value()) + continue; + if (group + 1 != groups.cend()) { + digit_index = 0; ++group; } - if (group == groups.cend()) - size += sep_size * ((num_digits - 1) / groups.back()); - writer.write_int(size, get_prefix(), specs, - num_writer{abs_value, size, groups, sep}); + p -= s.size(); + std::uninitialized_copy(s.data(), s.data() + s.size(), + make_checked(p, s.size())); } + if (prefix_size != 0) p[-1] = static_cast('-'); + write(out, basic_string_view(buffer.data(), buffer.size()), specs); + } - FMT_NORETURN void on_error() { - FMT_THROW(format_error("invalid type specifier")); - } + void on_chr() { *out++ = static_cast(abs_value); } + + FMT_NORETURN void on_error() { + FMT_THROW(format_error("invalid type specifier")); + } +}; + +template +OutputIt write_nonfinite(OutputIt out, bool isinf, + const basic_format_specs& specs, + const float_specs& fspecs) { + auto str = + isinf ? (fspecs.upper ? "INF" : "inf") : (fspecs.upper ? "NAN" : "nan"); + constexpr size_t str_size = 3; + auto sign = fspecs.sign; + auto size = str_size + (sign ? 1 : 0); + using iterator = remove_reference_t; + return write_padded(out, specs, size, [=](iterator it) { + if (sign) *it++ = static_cast(data::signs[sign]); + return copy_str(str, str + str_size, it); + }); +} + +template ::value)> +OutputIt write(OutputIt out, T value, basic_format_specs specs, + locale_ref loc = {}) { + if (const_check(!is_supported_floating_point(value))) return out; + float_specs fspecs = parse_float_type_spec(specs); + fspecs.sign = specs.sign; + if (std::signbit(value)) { // value < 0 is false for NaN so use signbit. + fspecs.sign = sign::minus; + value = -value; + } else if (fspecs.sign == sign::minus) { + fspecs.sign = sign::none; + } + + if (!std::isfinite(value)) + return write_nonfinite(out, std::isinf(value), specs, fspecs); + + if (specs.align == align::numeric && fspecs.sign) { + auto it = reserve(out, 1); + *it++ = static_cast(data::signs[fspecs.sign]); + out = base_iterator(out, it); + fspecs.sign = sign::none; + if (specs.width != 0) --specs.width; + } + + memory_buffer buffer; + if (fspecs.format == float_format::hex) { + if (fspecs.sign) buffer.push_back(data::signs[fspecs.sign]); + snprintf_float(promote_float(value), specs.precision, fspecs, buffer); + return write_bytes(out, {buffer.data(), buffer.size()}, specs); + } + int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6; + if (fspecs.format == float_format::exp) { + if (precision == max_value()) + FMT_THROW(format_error("number is too big")); + else + ++precision; + } + if (const_check(std::is_same())) fspecs.binary32 = true; + fspecs.use_grisu = use_grisu(); + int exp = format_float(promote_float(value), precision, fspecs, buffer); + fspecs.precision = precision; + Char point = + fspecs.locale ? decimal_point(loc) : static_cast('.'); + float_writer w(buffer.data(), static_cast(buffer.size()), exp, + fspecs, point); + return write_padded(out, specs, w.size(), w); +} + +template ::value)> +OutputIt write(OutputIt out, T value) { + if (const_check(!is_supported_floating_point(value))) return out; + auto fspecs = float_specs(); + if (std::signbit(value)) { // value < 0 is false for NaN so use signbit. + fspecs.sign = sign::minus; + value = -value; + } + + auto specs = basic_format_specs(); + if (!std::isfinite(value)) + return write_nonfinite(out, std::isinf(value), specs, fspecs); + + memory_buffer buffer; + int precision = -1; + if (const_check(std::is_same())) fspecs.binary32 = true; + fspecs.use_grisu = use_grisu(); + int exp = format_float(promote_float(value), precision, fspecs, buffer); + fspecs.precision = precision; + float_writer w(buffer.data(), static_cast(buffer.size()), exp, + fspecs, static_cast('.')); + return base_iterator(out, w(reserve(out, w.size()))); +} + +template +OutputIt write_char(OutputIt out, Char value, + const basic_format_specs& specs) { + using iterator = remove_reference_t; + return write_padded(out, specs, 1, [=](iterator it) { + *it++ = value; + return it; + }); +} + +template +OutputIt write_ptr(OutputIt out, UIntPtr value, + const basic_format_specs* specs) { + int num_digits = count_digits<4>(value); + auto size = to_unsigned(num_digits) + size_t(2); + using iterator = remove_reference_t; + auto write = [=](iterator it) { + *it++ = static_cast('0'); + *it++ = static_cast('x'); + return format_uint<4, Char>(it, value, num_digits); }; + return specs ? write_padded(out, *specs, size, write) + : base_iterator(out, write(reserve(out, size))); +} - template struct str_writer { - const Char* s; - size_t size_; +template struct is_integral : std::is_integral {}; +template <> struct is_integral : std::true_type {}; +template <> struct is_integral : std::true_type {}; - size_t size() const { return size_; } - size_t width() const { - return count_code_points(basic_string_view(s, size_)); - } +template +OutputIt write(OutputIt out, monostate) { + FMT_ASSERT(false, ""); + return out; +} - template void operator()(It&& it) const { - it = copy_str(s, s + size_, it); - } - }; +template ::value)> +OutputIt write(OutputIt out, string_view value) { + auto it = reserve(out, value.size()); + it = copy_str(value.begin(), value.end(), it); + return base_iterator(out, it); +} - struct bytes_writer { - string_view bytes; +template +OutputIt write(OutputIt out, basic_string_view value) { + auto it = reserve(out, value.size()); + it = std::copy(value.begin(), value.end(), it); + return base_iterator(out, it); +} - size_t size() const { return bytes.size(); } - size_t width() const { return bytes.size(); } +template ::value && + !std::is_same::value && + !std::is_same::value)> +OutputIt write(OutputIt out, T value) { + auto abs_value = static_cast>(value); + bool negative = is_negative(value); + // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer. + if (negative) abs_value = ~abs_value + 1; + int num_digits = count_digits(abs_value); + auto it = reserve(out, (negative ? 1 : 0) + static_cast(num_digits)); + if (negative) *it++ = static_cast('-'); + it = format_decimal(it, abs_value, num_digits).end; + return base_iterator(out, it); +} - template void operator()(It&& it) const { - const char* data = bytes.data(); - it = copy_str(data, data + size(), it); - } - }; +template +OutputIt write(OutputIt out, bool value) { + return write(out, string_view(value ? "true" : "false")); +} - template struct pointer_writer { - UIntPtr value; - int num_digits; +template +OutputIt write(OutputIt out, Char value) { + auto it = reserve(out, 1); + *it++ = value; + return base_iterator(out, it); +} - size_t size() const { return to_unsigned(num_digits) + 2; } - size_t width() const { return size(); } +template +OutputIt write(OutputIt out, const Char* value) { + if (!value) { + FMT_THROW(format_error("string pointer is null")); + } else { + auto length = std::char_traits::length(value); + out = write(out, basic_string_view(value, length)); + } + return out; +} - template void operator()(It&& it) const { - *it++ = static_cast('0'); - *it++ = static_cast('x'); - it = format_uint<4, char_type>(it, value, num_digits); - } - }; +template +OutputIt write(OutputIt out, const void* value) { + return write_ptr(out, to_uintptr(value), nullptr); +} +template +auto write(OutputIt out, const T& value) -> typename std::enable_if< + mapped_type_constant>::value == + type::custom_type, + OutputIt>::type { + basic_format_context ctx(out, {}, {}); + return formatter().format(value, ctx); +} + +// An argument visitor that formats the argument and writes it via the output +// iterator. It's a class and not a generic lambda for compatibility with C++11. +template struct default_arg_formatter { + using context = basic_format_context; + + OutputIt out; + basic_format_args args; + locale_ref loc; + + template OutputIt operator()(T value) { + return write(out, value); + } + + OutputIt operator()(typename basic_format_arg::handle handle) { + basic_format_parse_context parse_ctx({}); + basic_format_context format_ctx(out, args, loc); + handle.format(parse_ctx, format_ctx); + return format_ctx.out(); + } +}; + +template +class arg_formatter_base { public: - explicit basic_writer(Range out, locale_ref loc = locale_ref()) - : out_(out.begin()), locale_(loc) {} + using iterator = OutputIt; + using char_type = Char; + using format_specs = basic_format_specs; - iterator out() const { return out_; } + private: + iterator out_; + locale_ref locale_; + format_specs* specs_; - // Writes a value in the format - // - // where is written by f(it). - template void write_padded(const format_specs& specs, F&& f) { - // User-perceived width (in code points). - unsigned width = to_unsigned(specs.width); - size_t size = f.size(); // The number of code units. - size_t num_code_points = width != 0 ? f.width() : size; - if (width <= num_code_points) return f(reserve(size)); - size_t padding = width - num_code_points; - size_t fill_size = specs.fill.size(); - auto&& it = reserve(size + padding * fill_size); - if (specs.align == align::right) { - it = fill(it, padding, specs.fill); - f(it); - } else if (specs.align == align::center) { - std::size_t left_padding = padding / 2; - it = fill(it, left_padding, specs.fill); - f(it); - it = fill(it, padding - left_padding, specs.fill); - } else { - f(it); - it = fill(it, padding, specs.fill); - } + // Attempts to reserve space for n extra characters in the output range. + // Returns a pointer to the reserved range or a reference to out_. + auto reserve(size_t n) -> decltype(detail::reserve(out_, n)) { + return detail::reserve(out_, n); } - void write(int value) { write_decimal(value); } - void write(long value) { write_decimal(value); } - void write(long long value) { write_decimal(value); } + using reserve_iterator = remove_reference_t(), 0))>; - void write(unsigned value) { write_decimal(value); } - void write(unsigned long value) { write_decimal(value); } - void write(unsigned long long value) { write_decimal(value); } - -#if FMT_USE_INT128 - void write(int128_t value) { write_decimal(value); } - void write(uint128_t value) { write_decimal(value); } -#endif - - template - void write_int(T value, const Spec& spec) { - handle_int_type_spec(spec.type, int_writer(*this, value, spec)); - } - - template ::value)> - void write(T value, format_specs specs = {}) { - if (const_check(!is_supported_floating_point(value))) { - return; - } - float_specs fspecs = parse_float_type_spec(specs); - fspecs.sign = specs.sign; - if (std::signbit(value)) { // value < 0 is false for NaN so use signbit. - fspecs.sign = sign::minus; - value = -value; - } else if (fspecs.sign == sign::minus) { - fspecs.sign = sign::none; - } - - if (!std::isfinite(value)) { - auto str = std::isinf(value) ? (fspecs.upper ? "INF" : "inf") - : (fspecs.upper ? "NAN" : "nan"); - return write_padded(specs, nonfinite_writer{fspecs.sign, str}); - } - - if (specs.align == align::none) { - specs.align = align::right; - } else if (specs.align == align::numeric) { - if (fspecs.sign) { - auto&& it = reserve(1); - *it++ = static_cast(data::signs[fspecs.sign]); - fspecs.sign = sign::none; - if (specs.width != 0) --specs.width; - } - specs.align = align::right; - } - - memory_buffer buffer; - if (fspecs.format == float_format::hex) { - if (fspecs.sign) buffer.push_back(data::signs[fspecs.sign]); - snprintf_float(promote_float(value), specs.precision, fspecs, buffer); - write_padded(specs, str_writer{buffer.data(), buffer.size()}); - return; - } - int precision = specs.precision >= 0 || !specs.type ? specs.precision : 6; - if (fspecs.format == float_format::exp) { - if (precision == max_value()) - FMT_THROW(format_error("number is too big")); - else - ++precision; - } - if (const_check(std::is_same())) fspecs.binary32 = true; - fspecs.use_grisu = use_grisu(); - if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) value *= 100; - int exp = format_float(promote_float(value), precision, fspecs, buffer); - if (const_check(FMT_DEPRECATED_PERCENT) && fspecs.percent) { - buffer.push_back('%'); - --exp; // Adjust decimal place position. - } - fspecs.precision = precision; - char_type point = fspecs.locale ? decimal_point(locale_) - : static_cast('.'); - write_padded(specs, float_writer(buffer.data(), - static_cast(buffer.size()), - exp, fspecs, point)); + template void write_int(T value, const format_specs& spec) { + using uint_type = uint32_or_64_or_128_t; + int_writer w(out_, locale_, value, spec); + handle_int_type_spec(spec.type, w); + out_ = w.out; } void write(char value) { @@ -1782,198 +1851,151 @@ template class basic_writer { *it++ = value; } - template ::value)> - void write(Char value) { - auto&& it = reserve(1); - *it++ = value; + template ::value)> + void write(Ch value) { + out_ = detail::write(out_, value); } void write(string_view value) { auto&& it = reserve(value.size()); - it = copy_str(value.begin(), value.end(), it); + it = copy_str(value.begin(), value.end(), it); } void write(wstring_view value) { - static_assert(std::is_same::value, ""); + static_assert(std::is_same::value, ""); auto&& it = reserve(value.size()); it = std::copy(value.begin(), value.end(), it); } - template - void write(const Char* s, std::size_t size, const format_specs& specs) { - write_padded(specs, str_writer{s, size}); + template + void write(const Ch* s, size_t size, const format_specs& specs) { + auto width = specs.width != 0 + ? count_code_points(basic_string_view(s, size)) + : 0; + out_ = write_padded(out_, specs, size, width, [=](reserve_iterator it) { + return copy_str(s, s + size, it); + }); } - template - void write(basic_string_view s, const format_specs& specs = {}) { - const Char* data = s.data(); - std::size_t size = s.size(); - if (specs.precision >= 0 && to_unsigned(specs.precision) < size) - size = code_point_index(s, to_unsigned(specs.precision)); - write(data, size, specs); - } - - void write_bytes(string_view bytes, const format_specs& specs) { - write_padded(specs, bytes_writer{bytes}); - } - - template - void write_pointer(UIntPtr value, const format_specs* specs) { - int num_digits = count_digits<4>(value); - auto pw = pointer_writer{value, num_digits}; - if (!specs) return pw(reserve(to_unsigned(num_digits) + 2)); - format_specs specs_copy = *specs; - if (specs_copy.align == align::none) specs_copy.align = align::right; - write_padded(specs_copy, pw); - } -}; - -using writer = basic_writer>; - -template struct is_integral : std::is_integral {}; -template <> struct is_integral : std::true_type {}; -template <> struct is_integral : std::true_type {}; - -template -class arg_formatter_base { - public: - using char_type = typename Range::value_type; - using iterator = typename Range::iterator; - using format_specs = basic_format_specs; - - private: - using writer_type = basic_writer; - writer_type writer_; - format_specs* specs_; - - struct char_writer { - char_type value; - - size_t size() const { return 1; } - size_t width() const { return 1; } - - template void operator()(It&& it) const { *it++ = value; } - }; - - void write_char(char_type value) { - if (specs_) - writer_.write_padded(*specs_, char_writer{value}); - else - writer_.write(value); + template + void write(basic_string_view s, const format_specs& specs = {}) { + out_ = detail::write(out_, s, specs); } void write_pointer(const void* p) { - writer_.write_pointer(internal::to_uintptr(p), specs_); - } - - protected: - writer_type& writer() { return writer_; } - FMT_DEPRECATED format_specs* spec() { return specs_; } - format_specs* specs() { return specs_; } - iterator out() { return writer_.out(); } - - void write(bool value) { - string_view sv(value ? "true" : "false"); - specs_ ? writer_.write(sv, *specs_) : writer_.write(sv); - } - - void write(const char_type* value) { - if (!value) { - FMT_THROW(format_error("string pointer is null")); - } else { - auto length = std::char_traits::length(value); - basic_string_view sv(value, length); - specs_ ? writer_.write(sv, *specs_) : writer_.write(sv); - } - } - - public: - arg_formatter_base(Range r, format_specs* s, locale_ref loc) - : writer_(r, loc), specs_(s) {} - - iterator operator()(monostate) { - FMT_ASSERT(false, "invalid argument type"); - return out(); - } - - template ::value)> - iterator operator()(T value) { - if (specs_) - writer_.write_int(value, *specs_); - else - writer_.write(value); - return out(); - } - - iterator operator()(char_type value) { - internal::handle_char_specs( - specs_, char_spec_handler(*this, static_cast(value))); - return out(); - } - - iterator operator()(bool value) { - if (specs_ && specs_->type) return (*this)(value ? 1 : 0); - write(value != 0); - return out(); - } - - template ::value)> - iterator operator()(T value) { - if (const_check(is_supported_floating_point(value))) - writer_.write(value, specs_ ? *specs_ : format_specs()); - else - FMT_ASSERT(false, "unsupported float argument type"); - return out(); + out_ = write_ptr(out_, to_uintptr(p), specs_); } struct char_spec_handler : ErrorHandler { arg_formatter_base& formatter; - char_type value; + Char value; - char_spec_handler(arg_formatter_base& f, char_type val) + char_spec_handler(arg_formatter_base& f, Char val) : formatter(f), value(val) {} void on_int() { - if (formatter.specs_) - formatter.writer_.write_int(value, *formatter.specs_); - else - formatter.writer_.write(value); + // char is only formatted as int if there are specs. + formatter.write_int(static_cast(value), *formatter.specs_); + } + void on_char() { + if (formatter.specs_) + formatter.out_ = write_char(formatter.out_, value, *formatter.specs_); + else + formatter.write(value); } - void on_char() { formatter.write_char(value); } }; - struct cstring_spec_handler : internal::error_handler { + struct cstring_spec_handler : error_handler { arg_formatter_base& formatter; - const char_type* value; + const Char* value; - cstring_spec_handler(arg_formatter_base& f, const char_type* val) + cstring_spec_handler(arg_formatter_base& f, const Char* val) : formatter(f), value(val) {} void on_string() { formatter.write(value); } void on_pointer() { formatter.write_pointer(value); } }; - iterator operator()(const char_type* value) { - if (!specs_) return write(value), out(); - internal::handle_cstring_type_spec(specs_->type, - cstring_spec_handler(*this, value)); - return out(); + protected: + iterator out() { return out_; } + format_specs* specs() { return specs_; } + + void write(bool value) { + if (specs_) + write(string_view(value ? "true" : "false"), *specs_); + else + out_ = detail::write(out_, value); } - iterator operator()(basic_string_view value) { - if (specs_) { - internal::check_string_type_spec(specs_->type, internal::error_handler()); - writer_.write(value, *specs_); + void write(const Char* value) { + if (!value) { + FMT_THROW(format_error("string pointer is null")); } else { - writer_.write(value); + auto length = std::char_traits::length(value); + basic_string_view sv(value, length); + specs_ ? write(sv, *specs_) : write(sv); } - return out(); + } + + public: + arg_formatter_base(OutputIt out, format_specs* s, locale_ref loc) + : out_(out), locale_(loc), specs_(s) {} + + iterator operator()(monostate) { + FMT_ASSERT(false, "invalid argument type"); + return out_; + } + + template ::value)> + FMT_INLINE iterator operator()(T value) { + if (specs_) + write_int(value, *specs_); + else + out_ = detail::write(out_, value); + return out_; + } + + iterator operator()(Char value) { + handle_char_specs(specs_, + char_spec_handler(*this, static_cast(value))); + return out_; + } + + iterator operator()(bool value) { + if (specs_ && specs_->type) return (*this)(value ? 1 : 0); + write(value != 0); + return out_; + } + + template ::value)> + iterator operator()(T value) { + auto specs = specs_ ? *specs_ : format_specs(); + if (const_check(is_supported_floating_point(value))) + out_ = detail::write(out_, value, specs, locale_); + else + FMT_ASSERT(false, "unsupported float argument type"); + return out_; + } + + iterator operator()(const Char* value) { + if (!specs_) return write(value), out_; + handle_cstring_type_spec(specs_->type, cstring_spec_handler(*this, value)); + return out_; + } + + iterator operator()(basic_string_view value) { + if (specs_) { + check_string_type_spec(specs_->type, error_handler()); + write(value, *specs_); + } else { + write(value); + } + return out_; } iterator operator()(const void* value) { - if (specs_) - check_pointer_type_spec(specs_->type, internal::error_handler()); + if (specs_) check_pointer_type_spec(specs_->type, error_handler()); write_pointer(value); - return out(); + return out_; } }; @@ -2109,7 +2131,7 @@ template class specs_setter { template class numeric_specs_checker { public: - FMT_CONSTEXPR numeric_specs_checker(ErrorHandler& eh, internal::type arg_type) + FMT_CONSTEXPR numeric_specs_checker(ErrorHandler& eh, detail::type arg_type) : error_handler_(eh), arg_type_(arg_type) {} FMT_CONSTEXPR void require_numeric_argument() { @@ -2132,18 +2154,24 @@ template class numeric_specs_checker { private: ErrorHandler& error_handler_; - internal::type arg_type_; + detail::type arg_type_; }; // A format specifier handler that checks if specifiers are consistent with the // argument type. template class specs_checker : public Handler { + private: + numeric_specs_checker checker_; + + // Suppress an MSVC warning about using this in initializer list. + FMT_CONSTEXPR Handler& error_handler() { return *this; } + public: - FMT_CONSTEXPR specs_checker(const Handler& handler, internal::type arg_type) - : Handler(handler), checker_(*this, arg_type) {} + FMT_CONSTEXPR specs_checker(const Handler& handler, detail::type arg_type) + : Handler(handler), checker_(error_handler(), arg_type) {} FMT_CONSTEXPR specs_checker(const specs_checker& other) - : Handler(other), checker_(*this, other.arg_type_) {} + : Handler(other), checker_(error_handler(), other.arg_type_) {} FMT_CONSTEXPR void on_align(align_t align) { if (align == align::numeric) checker_.require_numeric_argument(); @@ -2176,9 +2204,6 @@ template class specs_checker : public Handler { } FMT_CONSTEXPR void end_precision() { checker_.check_precision(); } - - private: - numeric_specs_checker checker_; }; template