From 4f8e6274790fcc5eb66ed3cb289b9b75bf3daac5 Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 8 Sep 2020 13:16:45 -0600 Subject: [PATCH 01/43] QEq refactor --- src/KOKKOS/fix_qeq_reax_kokkos.cpp | 31 +++-- src/USER-OMP/fix_qeq_reax_omp.cpp | 144 +++++------------------ src/USER-REAXC/fix_qeq_reax.cpp | 178 ++++++++++------------------- src/USER-REAXC/fix_qeq_reax.h | 4 +- 4 files changed, 109 insertions(+), 248 deletions(-) diff --git a/src/KOKKOS/fix_qeq_reax_kokkos.cpp b/src/KOKKOS/fix_qeq_reax_kokkos.cpp index eac044da28..a71b52e0f1 100644 --- a/src/KOKKOS/fix_qeq_reax_kokkos.cpp +++ b/src/KOKKOS/fix_qeq_reax_kokkos.cpp @@ -112,7 +112,7 @@ void FixQEqReaxKokkos::init() ("FixQEqReax::params",ntypes+1); params = k_params.template view(); - for (n = 1; n <= ntypes; n++) { + for (int n = 1; n <= ntypes; n++) { k_params.h_view(n).chi = chi[n]; k_params.h_view(n).eta = eta[n]; k_params.h_view(n).gamma = gamma[n]; @@ -351,34 +351,35 @@ void FixQEqReaxKokkos::allocate_array() if (atom->nmax > nmax) { nmax = atom->nmax; - k_o = DAT::tdual_ffloat_1d("qeq/kk:h_o",nmax); + k_o = DAT::tdual_ffloat_1d("qeq/kk:o",nmax); d_o = k_o.template view(); h_o = k_o.h_view; - d_Hdia_inv = typename AT::t_ffloat_1d("qeq/kk:h_Hdia_inv",nmax); + d_Hdia_inv = typename AT::t_ffloat_1d("qeq/kk:Hdia_inv",nmax); - d_b_s = typename AT::t_ffloat_1d("qeq/kk:h_b_s",nmax); + d_b_s = typename AT::t_ffloat_1d("qeq/kk:b_s",nmax); - d_b_t = typename AT::t_ffloat_1d("qeq/kk:h_b_t",nmax); + d_b_t = typename AT::t_ffloat_1d("qeq/kk:b_t",nmax); - k_s = DAT::tdual_ffloat_1d("qeq/kk:h_s",nmax); + k_s = DAT::tdual_ffloat_1d("qeq/kk:s",nmax); d_s = k_s.template view(); h_s = k_s.h_view; - k_t = DAT::tdual_ffloat_1d("qeq/kk:h_t",nmax); + k_t = DAT::tdual_ffloat_1d("qeq/kk:t",nmax); d_t = k_t.template view(); h_t = k_t.h_view; - d_p = typename AT::t_ffloat_1d("qeq/kk:h_p",nmax); + d_p = typename AT::t_ffloat_1d("qeq/kk:p",nmax); - d_r = typename AT::t_ffloat_1d("qeq/kk:h_r",nmax); + d_r = typename AT::t_ffloat_1d("qeq/kk:r",nmax); - k_d = DAT::tdual_ffloat_1d("qeq/kk:h_d",nmax); + k_d = DAT::tdual_ffloat_1d("qeq/kk:d",nmax); d_d = k_d.template view(); h_d = k_d.h_view; } // init_storage + FixQEqReaxKokkosZeroFunctor zero_functor(this); Kokkos::parallel_for(ignum,zero_functor); @@ -779,8 +780,7 @@ void FixQEqReaxKokkos::cg_solve1() F_FLOAT sig_new = dot_sqr; int loop; - const int loopmax = 200; - for (loop = 1; (loop < loopmax) && (sqrt(sig_new)/b_norm > tolerance); loop++) { + for (loop = 1; (loop < imax) && (sqrt(sig_new)/b_norm > tolerance); loop++) { // comm->forward_comm_fix(this); //Dist_vector( d ); pack_flag = 1; @@ -848,7 +848,7 @@ void FixQEqReaxKokkos::cg_solve1() Kokkos::parallel_for(inum,vecsum2_functor); } - if (loop >= loopmax && comm->me == 0) { + if (loop >= imax && comm->me == 0) { char str[128]; sprintf(str,"Fix qeq/reax cg_solve1 convergence failed after %d iterations " "at " BIGINT_FORMAT " step: %f",loop,update->ntimestep,sqrt(sig_new)/b_norm); @@ -918,8 +918,7 @@ void FixQEqReaxKokkos::cg_solve2() F_FLOAT sig_new = dot_sqr; int loop; - const int loopmax = 200; - for (loop = 1; (loop < loopmax) && (sqrt(sig_new)/b_norm > tolerance); loop++) { + for (loop = 1; (loop < imax) && (sqrt(sig_new)/b_norm > tolerance); loop++) { // comm->forward_comm_fix(this); //Dist_vector( d ); pack_flag = 1; @@ -987,7 +986,7 @@ void FixQEqReaxKokkos::cg_solve2() Kokkos::parallel_for(inum,vecsum2_functor); } - if (loop >= loopmax && comm->me == 0) { + if (loop >= imax && comm->me == 0) { char str[128]; sprintf(str,"Fix qeq/reax cg_solve2 convergence failed after %d iterations " "at " BIGINT_FORMAT " step: %f",loop,update->ntimestep,sqrt(sig_new)/b_norm); diff --git a/src/USER-OMP/fix_qeq_reax_omp.cpp b/src/USER-OMP/fix_qeq_reax_omp.cpp index ef0f918cbf..92c1b73e13 100644 --- a/src/USER-OMP/fix_qeq_reax_omp.cpp +++ b/src/USER-OMP/fix_qeq_reax_omp.cpp @@ -63,8 +63,6 @@ using namespace FixConst; FixQEqReaxOMP::FixQEqReaxOMP(LAMMPS *lmp, int narg, char **arg) : FixQEqReax(lmp, narg, arg) { - if (narg<8 || narg>9) error->all(FLERR,"Illegal fix qeq/reax/omp command"); - b_temp = NULL; // ASPC: Kolafa, J. Comp. Chem., 25(3), 335 (2003) @@ -85,6 +83,11 @@ FixQEqReaxOMP::~FixQEqReaxOMP() void FixQEqReaxOMP::post_constructor() { + grow_arrays(atom->nmax); + for (int i = 0; i < atom->nmax; i++) + for (int j = 0; j < nprev; ++j) + s_hist[i][j] = t_hist[i][j] = 0; + pertype_parameters(pertype_option); } @@ -148,7 +151,6 @@ void FixQEqReaxOMP::init() void FixQEqReaxOMP::compute_H() { - int inum, *ilist, *numneigh, **firstneigh; double SMALL = 0.0001; int *type = atom->type; @@ -156,17 +158,6 @@ void FixQEqReaxOMP::compute_H() double **x = atom->x; int *mask = atom->mask; - if (reaxc) { - inum = reaxc->list->inum; - ilist = reaxc->list->ilist; - numneigh = reaxc->list->numneigh; - firstneigh = reaxc->list->firstneigh; - } else { - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - } int ai, num_nbrs; // sumscan of the number of neighbors per atom to determine the offsets @@ -175,7 +166,7 @@ void FixQEqReaxOMP::compute_H() num_nbrs = 0; - for (int itr_i = 0; itr_i < inum; ++itr_i) { + for (int itr_i = 0; itr_i < nn; ++itr_i) { ai = ilist[itr_i]; H.firstnbr[ai] = num_nbrs; num_nbrs += numneigh[ai]; @@ -197,7 +188,7 @@ void FixQEqReaxOMP::compute_H() #if defined(_OPENMP) #pragma omp for schedule(guided) #endif - for (int ii = 0; ii < inum; ii++) { + for (int ii = 0; ii < nn; ii++) { int i = ilist[ii]; if (mask[i] & groupbit) { jlist = firstneigh[i]; @@ -214,7 +205,7 @@ void FixQEqReaxOMP::compute_H() flag = 0; if (r_sqr <= SQR(swb)) { - if (j < n) flag = 1; + if (j < atom->nlocal) flag = 1; else if (tag[i] < tag[j]) flag = 1; else if (tag[i] == tag[j]) { if (dz > SMALL) flag = 1; @@ -251,11 +242,6 @@ void FixQEqReaxOMP::compute_H() void FixQEqReaxOMP::init_storage() { - int NN; - - if (reaxc) NN = reaxc->list->inum + reaxc->list->gnum; - else NN = list->inum + list->gnum; - #if defined(_OPENMP) #pragma omp parallel for schedule(static) #endif @@ -284,8 +270,21 @@ void FixQEqReaxOMP::pre_force(int /* vflag */) if (update->ntimestep % nevery) return; if (comm->me == 0) t_start = MPI_Wtime(); - n = atom->nlocal; - N = atom->nlocal + atom->nghost; + int n = atom->nlocal; + + if (reaxc) { + nn = reaxc->list->inum; + NN = reaxc->list->inum + reaxc->list->gnum; + ilist = reaxc->list->ilist; + numneigh = reaxc->list->numneigh; + firstneigh = reaxc->list->firstneigh; + } else { + nn = list->inum; + NN = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + } // grow arrays if necessary // need to be atom->nmax in length @@ -365,16 +364,7 @@ void FixQEqReaxOMP::init_matvec() /* fill-in H matrix */ compute_H(); - int nn,i; - int *ilist; - - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } + int i; // Should really be more careful with initialization and first (aspc_order+2) MD steps if (do_aspc) { @@ -450,24 +440,12 @@ void FixQEqReaxOMP::init_matvec() int FixQEqReaxOMP::CG( double *b, double *x) { - int i, imax; + int i; double alpha, beta, b_norm; double sig_old, sig_new; double my_buf[2], buf[2]; - int nn; - int *ilist; - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } - - imax = 200; - pack_flag = 1; sparse_matvec( &H, x, q ); comm->reverse_comm_fix( this); //Coll_Vector( q ); @@ -579,8 +557,7 @@ void FixQEqReaxOMP::sparse_matvec( sparse_matrix *A, double *x, double *b) #endif { int i, j, itr_j; - int nn, NN, ii; - int *ilist; + int ii; int nthreads = comm->nthreads; #if defined(_OPENMP) int tid = omp_get_thread_num(); @@ -588,16 +565,6 @@ void FixQEqReaxOMP::sparse_matvec( sparse_matrix *A, double *x, double *b) int tid = 0; #endif - if (reaxc) { - nn = reaxc->list->inum; - NN = reaxc->list->inum + reaxc->list->gnum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - NN = list->inum + list->gnum; - ilist = list->ilist; - } - #if defined(_OPENMP) #pragma omp for schedule(dynamic,50) #endif @@ -655,17 +622,6 @@ void FixQEqReaxOMP::calculate_Q() int i; double *q = atom->q; - int nn; - int *ilist; - - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } - double tmp1, tmp2; tmp1 = tmp2 = 0.0; #if defined(_OPENMP) @@ -718,10 +674,6 @@ void FixQEqReaxOMP::vector_sum( double* dest, double c, double* v, double d, double* y, int k) { int i; - int *ilist; - - if (reaxc) ilist = reaxc->list->ilist; - else ilist = list->ilist; #if defined(_OPENMP) #pragma omp parallel for schedule(static) private(i) @@ -737,10 +689,6 @@ void FixQEqReaxOMP::vector_sum( double* dest, double c, double* v, void FixQEqReaxOMP::vector_add( double* dest, double c, double* v, int k) { int i; - int *ilist; - - if (reaxc) ilist = reaxc->list->ilist; - else ilist = list->ilist; #if defined(_OPENMP) #pragma omp parallel for schedule(static) private(i) @@ -765,24 +713,12 @@ int FixQEqReaxOMP::dual_CG( double *b1, double *b2, double *x1, double *x2) startTimeBase = MPI_Wtime(); #endif - int i, imax; + int i; double alpha_s, alpha_t, beta_s, beta_t, b_norm_s, b_norm_t; double sig_old_s, sig_old_t, sig_new_s, sig_new_t; double my_buf[4], buf[4]; - int nn; - int *ilist; - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } - - imax = 200; - pack_flag = 5; // forward 2x d and reverse 2x q dual_sparse_matvec( &H, x1, x2, q ); comm->reverse_comm_fix(this); //Coll_Vector( q ); @@ -975,8 +911,7 @@ void FixQEqReaxOMP::dual_sparse_matvec( sparse_matrix *A, double *x1, double *x2 #endif { int i, j, itr_j; - int nn, NN, ii; - int *ilist; + int ii; int indxI, indxJ; int nthreads = comm->nthreads; @@ -986,16 +921,6 @@ void FixQEqReaxOMP::dual_sparse_matvec( sparse_matrix *A, double *x1, double *x2 int tid = 0; #endif - if (reaxc) { - nn = reaxc->list->inum; - NN = reaxc->list->inum + reaxc->list->gnum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - NN = list->inum + list->gnum; - ilist = list->ilist; - } - #if defined(_OPENMP) #pragma omp for schedule(dynamic,50) #endif @@ -1077,8 +1002,7 @@ void FixQEqReaxOMP::dual_sparse_matvec( sparse_matrix *A, double *x, double *b ) #endif { int i, j, itr_j; - int nn, NN, ii; - int *ilist; + int ii; int indxI, indxJ; int nthreads = comm->nthreads; @@ -1088,16 +1012,6 @@ void FixQEqReaxOMP::dual_sparse_matvec( sparse_matrix *A, double *x, double *b ) int tid = 0; #endif - if (reaxc) { - nn = reaxc->list->inum; - NN = reaxc->list->inum + reaxc->list->gnum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - NN = list->inum + list->gnum; - ilist = list->ilist; - } - #if defined(_OPENMP) #pragma omp for schedule(dynamic,50) #endif diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 4a61cfa03b..28270b562a 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -62,9 +62,7 @@ static const char cite_fix_qeq_reax[] = FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), pertype_option(NULL) { - if (lmp->citeme) lmp->citeme->add(cite_fix_qeq_reax); - - if (narg<8 || narg>9) error->all(FLERR,"Illegal fix qeq/reax command"); + if (narg<8 || narg>11) error->all(FLERR,"Illegal fix qeq/reax command"); nevery = utils::inumeric(FLERR,arg[3],false,lmp); if (nevery <= 0) error->all(FLERR,"Illegal fix qeq/reax command"); @@ -79,14 +77,23 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : // dual CG support only available for USER-OMP variant // check for compatibility is in Fix::post_constructor() dual_enabled = 0; - if (narg == 9) { - if (strcmp(arg[8],"dual") == 0) dual_enabled = 1; - else error->all(FLERR,"Illegal fix qeq/reax command"); + imax = 200; + + int iarg = 8; + while (iarg < narg) { + if (strcmp(arg[iarg],"dual") == 0) dual_enabled = 1; + else if (strcmp(arg[iarg],"imax") == 0) { + if (iarg+1 > narg-1) + error->all(FLERR,"Illegal fix qeq/reax command"); + imax = force->numeric(FLERR,arg[iarg+1]); + iarg++; + } else error->all(FLERR,"Illegal fix qeq/reax command"); + iarg++; } shld = NULL; - n = n_cap = 0; - N = nmax = 0; + nn = n_cap = 0; + NN = nmax = 0; m_fill = m_cap = 0; pack_flag = 0; s = NULL; @@ -123,11 +130,7 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : reaxc = (PairReaxC *) force->pair_match("^reax/c",0); s_hist = t_hist = NULL; - grow_arrays(atom->nmax); atom->add_callback(0); - for (int i = 0; i < atom->nmax; i++) - for (int j = 0; j < nprev; ++j) - s_hist[i][j] = t_hist[i][j] = 0; } /* ---------------------------------------------------------------------- */ @@ -161,6 +164,13 @@ FixQEqReax::~FixQEqReax() void FixQEqReax::post_constructor() { + if (lmp->citeme) lmp->citeme->add(cite_fix_qeq_reax); + + grow_arrays(atom->nmax); + for (int i = 0; i < atom->nmax; i++) + for (int j = 0; j < nprev; ++j) + s_hist[i][j] = t_hist[i][j] = 0; + pertype_parameters(pertype_option); if (dual_enabled) error->all(FLERR,"Dual keyword only supported with fix qeq/reax/omp"); @@ -287,8 +297,7 @@ void FixQEqReax::reallocate_storage() void FixQEqReax::allocate_matrix() { - int i,ii,inum,m; - int *ilist, *numneigh; + int i,ii,n,m; int mincap; double safezone; @@ -306,18 +315,8 @@ void FixQEqReax::allocate_matrix() // determine the total space for the H matrix - if (reaxc) { - inum = reaxc->list->inum; - ilist = reaxc->list->ilist; - numneigh = reaxc->list->numneigh; - } else { - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - } - m = 0; - for (ii = 0; ii < inum; ii++) { + for (ii = 0; ii < nn; ii++) { i = ilist[ii]; m += numneigh[i]; } @@ -432,6 +431,20 @@ void FixQEqReax::init_taper() void FixQEqReax::setup_pre_force(int vflag) { + if (reaxc) { + nn = reaxc->list->inum; + NN = reaxc->list->inum + reaxc->list->gnum; + ilist = reaxc->list->ilist; + numneigh = reaxc->list->numneigh; + firstneigh = reaxc->list->firstneigh; + } else { + nn = list->inum; + NN = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + } + deallocate_storage(); allocate_storage(); @@ -495,8 +508,21 @@ void FixQEqReax::pre_force(int /*vflag*/) if (update->ntimestep % nevery) return; if (comm->me == 0) t_start = MPI_Wtime(); - n = atom->nlocal; - N = atom->nlocal + atom->nghost; + int n = atom->nlocal; + + if (reaxc) { + nn = reaxc->list->inum; + NN = reaxc->list->inum + reaxc->list->gnum; + ilist = reaxc->list->ilist; + numneigh = reaxc->list->numneigh; + firstneigh = reaxc->list->firstneigh; + } else { + nn = list->inum; + NN = list->inum + list->gnum; + ilist = list->ilist; + numneigh = list->numneigh; + firstneigh = list->firstneigh; + } // grow arrays if necessary // need to be atom->nmax in length @@ -540,16 +566,7 @@ void FixQEqReax::init_matvec() /* fill-in H matrix */ compute_H(); - int nn, ii, i; - int *ilist; - - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } + int ii, i; for (ii = 0; ii < nn; ++ii) { i = ilist[ii]; @@ -578,7 +595,7 @@ void FixQEqReax::init_matvec() void FixQEqReax::compute_H() { - int inum, jnum, *ilist, *jlist, *numneigh, **firstneigh; + int jnum; int i, j, ii, jj, flag; double dx, dy, dz, r_sqr; const double SMALL = 0.0001; @@ -588,22 +605,10 @@ void FixQEqReax::compute_H() double **x = atom->x; int *mask = atom->mask; - if (reaxc) { - inum = reaxc->list->inum; - ilist = reaxc->list->ilist; - numneigh = reaxc->list->numneigh; - firstneigh = reaxc->list->firstneigh; - } else { - inum = list->inum; - ilist = list->ilist; - numneigh = list->numneigh; - firstneigh = list->firstneigh; - } - // fill in the H matrix m_fill = 0; r_sqr = 0; - for (ii = 0; ii < inum; ii++) { + for (ii = 0; ii < nn; ii++) { i = ilist[ii]; if (mask[i] & groupbit) { jlist = firstneigh[i]; @@ -621,7 +626,7 @@ void FixQEqReax::compute_H() flag = 0; if (r_sqr <= SQR(swb)) { - if (j < n) flag = 1; + if (j < atom->nlocal) flag = 1; else if (tag[i] < tag[j]) flag = 1; else if (tag[i] == tag[j]) { if (dz > SMALL) flag = 1; @@ -676,21 +681,11 @@ double FixQEqReax::calculate_H( double r, double gamma) int FixQEqReax::CG( double *b, double *x) { - int i, j, imax; + int i, j; double tmp, alpha, beta, b_norm; double sig_old, sig_new; - int nn, jj; - int *ilist; - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } - - imax = 200; + int jj; pack_flag = 1; sparse_matvec( &H, x, q); @@ -748,18 +743,7 @@ int FixQEqReax::CG( double *b, double *x) void FixQEqReax::sparse_matvec( sparse_matrix *A, double *x, double *b) { int i, j, itr_j; - int nn, NN, ii; - int *ilist; - - if (reaxc) { - nn = reaxc->list->inum; - NN = reaxc->list->inum + reaxc->list->gnum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - NN = list->inum + list->gnum; - ilist = list->ilist; - } + int ii; for (ii = 0; ii < nn; ++ii) { i = ilist[ii]; @@ -794,16 +778,7 @@ void FixQEqReax::calculate_Q() double u, s_sum, t_sum; double *q = atom->q; - int nn, ii; - int *ilist; - - if (reaxc) { - nn = reaxc->list->inum; - ilist = reaxc->list->ilist; - } else { - nn = list->inum; - ilist = list->ilist; - } + int ii; s_sum = parallel_vector_acc( s, nn); t_sum = parallel_vector_acc( t, nn); @@ -988,12 +963,6 @@ double FixQEqReax::parallel_norm( double *v, int n) double my_sum, norm_sqr; int ii; - int *ilist; - - if (reaxc) - ilist = reaxc->list->ilist; - else - ilist = list->ilist; my_sum = 0.0; norm_sqr = 0.0; @@ -1016,12 +985,6 @@ double FixQEqReax::parallel_dot( double *v1, double *v2, int n) double my_dot, res; int ii; - int *ilist; - - if (reaxc) - ilist = reaxc->list->ilist; - else - ilist = list->ilist; my_dot = 0.0; res = 0.0; @@ -1044,12 +1007,6 @@ double FixQEqReax::parallel_vector_acc( double *v, int n) double my_acc, res; int ii; - int *ilist; - - if (reaxc) - ilist = reaxc->list->ilist; - else - ilist = list->ilist; my_acc = 0.0; res = 0.0; @@ -1070,12 +1027,6 @@ void FixQEqReax::vector_sum( double* dest, double c, double* v, double d, double* y, int k) { int kk; - int *ilist; - - if (reaxc) - ilist = reaxc->list->ilist; - else - ilist = list->ilist; for (--k; k>=0; --k) { kk = ilist[k]; @@ -1089,12 +1040,6 @@ void FixQEqReax::vector_sum( double* dest, double c, double* v, void FixQEqReax::vector_add( double* dest, double c, double* v, int k) { int kk; - int *ilist; - - if (reaxc) - ilist = reaxc->list->ilist; - else - ilist = list->ilist; for (--k; k>=0; --k) { kk = ilist[k]; @@ -1102,3 +1047,4 @@ void FixQEqReax::vector_add( double* dest, double c, double* v, int k) dest[kk] += c * v[kk]; } } + diff --git a/src/USER-REAXC/fix_qeq_reax.h b/src/USER-REAXC/fix_qeq_reax.h index 96a174b908..5658167aca 100644 --- a/src/USER-REAXC/fix_qeq_reax.h +++ b/src/USER-REAXC/fix_qeq_reax.h @@ -57,12 +57,13 @@ class FixQEqReax : public Fix { protected: int nevery,reaxflag; - int n, N, m_fill; + int nn, NN, m_fill; int n_cap, nmax, m_cap; int pack_flag; int nlevels_respa; class NeighList *list; class PairReaxC *reaxc; + int *ilist, *jlist, *numneigh, **firstneigh; double swa, swb; // lower/upper Taper cutoff radius double Tap[8]; // Taper function @@ -94,6 +95,7 @@ class FixQEqReax : public Fix { //CG storage double *p, *q, *r, *d; + int imax; //GMRES storage //double *g,*y; From 1273179d03941f43505ead10354518edb12f852e Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Tue, 8 Sep 2020 13:42:25 -0600 Subject: [PATCH 02/43] Fix compile error --- src/USER-REAXC/fix_qeq_reax.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 28270b562a..8e6e114861 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -85,7 +85,7 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : else if (strcmp(arg[iarg],"imax") == 0) { if (iarg+1 > narg-1) error->all(FLERR,"Illegal fix qeq/reax command"); - imax = force->numeric(FLERR,arg[iarg+1]); + imax = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg++; } else error->all(FLERR,"Illegal fix qeq/reax command"); iarg++; From 3d37fd05f4bedbc01dfaf210efbcfc9c9b4de797 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 10 Sep 2020 16:14:18 -0400 Subject: [PATCH 03/43] disable caching - for now - to avoid bad side effects from sphinx-tabs --- doc/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/Makefile b/doc/Makefile index d96b523915..61875cbaae 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -41,7 +41,10 @@ HAS_PDFLATEX = YES endif -SPHINXEXTRA = -j $(shell $(PYTHON) -c 'import multiprocessing;print(multiprocessing.cpu_count())') $(shell test -f $(BUILDDIR)/doxygen/xml/run.stamp && printf -- "-E") +#SPHINXEXTRA = -j $(shell $(PYTHON) -c 'import multiprocessing;print(multiprocessing.cpu_count())') $(shell test -f $(BUILDDIR)/doxygen/xml/run.stamp && printf -- "-E") + +# temporarily disable caching so that the hack for the sphinx-tabs extensions to get proper non-html output works +SPHINXEXTRA = -E -j $(shell $(PYTHON) -c 'import multiprocessing;print(multiprocessing.cpu_count())') # grab list of sources from doxygen config file. # we only want to use explicitly listed files. From 0d5f68bc309c2ac145a6a51f99f0e3fb278f6ed8 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 10 Sep 2020 16:14:53 -0400 Subject: [PATCH 04/43] make "new in" and "changed in" leads boldface --- doc/utils/sphinx-config/_static/css/lammps.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/utils/sphinx-config/_static/css/lammps.css b/doc/utils/sphinx-config/_static/css/lammps.css index d2aa8a975d..2efb1246b3 100644 --- a/doc/utils/sphinx-config/_static/css/lammps.css +++ b/doc/utils/sphinx-config/_static/css/lammps.css @@ -14,3 +14,7 @@ display: block; margin-bottom: 0.405em; } + +.versionmodified { + font-weight: bold; +} From 4452109b60696c08da1482d6dfa750145cd92739 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 10 Sep 2020 16:15:03 -0400 Subject: [PATCH 05/43] address spelling issue --- doc/utils/sphinx-config/false_positives.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index e3cf7b78ce..b13d7a3ff3 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1003,6 +1003,7 @@ formatarg formulae Forschungszentrum Fortran +fortran Fosado fourier fp From ded57ba7495de6f7efccc8ee14fa92be722c8061 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 10 Sep 2020 16:16:58 -0400 Subject: [PATCH 06/43] move test to avoid issues with indentation from having tabs follow directly a list-table --- doc/src/Build_extras.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/src/Build_extras.rst b/doc/src/Build_extras.rst index 79e38ab2b4..7d778ada3d 100644 --- a/doc/src/Build_extras.rst +++ b/doc/src/Build_extras.rst @@ -373,8 +373,8 @@ More information on Kokkos can be found on the Available Architecture settings ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -These are the possible choices for the Kokkos architecture ID as of -version 3.2 of the Kokkos library. They must be specified in uppercase. +These are the possible choices for the Kokkos architecture ID. +They must be specified in uppercase. .. list-table:: :header-rows: 0 @@ -486,6 +486,8 @@ version 3.2 of the Kokkos library. They must be specified in uppercase. - GPU - Intel GPUs Gen9+ +This list was last updated for version 3.2 of the Kokkos library. + .. tabs:: .. tab:: Basic CMake build settings: From 612f1d7ce3aab4be067c9047c934d728523acc17 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Sep 2020 17:49:06 -0400 Subject: [PATCH 07/43] fix typo --- doc/src/Build_settings.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/src/Build_settings.rst b/doc/src/Build_settings.rst index d8ac39a0c1..600bd084ec 100644 --- a/doc/src/Build_settings.rst +++ b/doc/src/Build_settings.rst @@ -228,9 +228,9 @@ LAMMPS system size restrictions - :math:`2^{63}` steps (= :math:`9.223 \cdot 10^{18}`) - :math:`2^{31}` steps (= :math:`2.147 \cdot 10^9`) * - Atom ID values - - :math:`1 \le i \le 2^{31} (= 2.147 \dot 10^9)` + - :math:`1 \le i \le 2^{31} (= 2.147 \cdot 10^9)` - :math:`1 \le i \le 2^{63} (= 9.223 \cdot 10^{18})` - - :math:`1 \le i \le 2^{31} (= 2.147 \dot 10^9)` + - :math:`1 \le i \le 2^{31} (= 2.147 \cdot 10^9)` * - Image flag values - :math:`-512 \le i \le 511` - :math:`- 1\,048\,576 \le i \le 1\,048\,575` From bc1b876a3d72f12a010ef29e5be21a8356c6c9cd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 11 Sep 2020 19:29:17 -0400 Subject: [PATCH 08/43] make fix widom errors and test output consistent with the fix name capitalization --- src/MC/fix_widom.cpp | 76 ++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/MC/fix_widom.cpp b/src/MC/fix_widom.cpp index 94b2481742..6055ae8442 100644 --- a/src/MC/fix_widom.cpp +++ b/src/MC/fix_widom.cpp @@ -62,10 +62,10 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : local_gas_list(NULL), molcoords(NULL), molq(NULL), molimage(NULL), random_equal(NULL) { - if (narg < 8) error->all(FLERR,"Illegal fix Widom command"); + if (narg < 8) error->all(FLERR,"Illegal fix widom command"); if (atom->molecular == 2) - error->all(FLERR,"Fix Widom does not (yet) work with atom_style template"); + error->all(FLERR,"Fix widom does not (yet) work with atom_style template"); dynamic_group_allow = 1; @@ -86,11 +86,11 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : seed = utils::inumeric(FLERR,arg[6],false,lmp); insertion_temperature = utils::numeric(FLERR,arg[7],false,lmp); - if (nevery <= 0) error->all(FLERR,"Illegal fix Widom command"); - if (ninsertions < 0) error->all(FLERR,"Illegal fix Widom command"); - if (seed <= 0) error->all(FLERR,"Illegal fix Widom command"); + if (nevery <= 0) error->all(FLERR,"Illegal fix widom command"); + if (ninsertions < 0) error->all(FLERR,"Illegal fix widom command"); + if (seed <= 0) error->all(FLERR,"Illegal fix widom command"); if (insertion_temperature < 0.0) - error->all(FLERR,"Illegal fix Widom command"); + error->all(FLERR,"Illegal fix widom command"); // read options from end of input line @@ -106,9 +106,9 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : region_zlo = region_zhi = 0.0; if (regionflag) { if (domain->regions[iregion]->bboxflag == 0) - error->all(FLERR,"Fix Widom region does not support a bounding box"); + error->all(FLERR,"Fix widom region does not support a bounding box"); if (domain->regions[iregion]->dynamic_check()) - error->all(FLERR,"Fix Widom region cannot be dynamic"); + error->all(FLERR,"Fix widom region cannot be dynamic"); region_xlo = domain->regions[iregion]->extent_xlo; region_xhi = domain->regions[iregion]->extent_xhi; @@ -120,7 +120,7 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : if (region_xlo < domain->boxlo[0] || region_xhi > domain->boxhi[0] || region_ylo < domain->boxlo[1] || region_yhi > domain->boxhi[1] || region_zlo < domain->boxlo[2] || region_zhi > domain->boxhi[2]) - error->all(FLERR,"Fix Widom region extends outside simulation box"); + error->all(FLERR,"Fix widom region extends outside simulation box"); // estimate region volume using MC trials @@ -146,22 +146,22 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : if (exchmode == EXCHMOL) { if (onemols[imol]->xflag == 0) - error->all(FLERR,"Fix Widom molecule must have coordinates"); + error->all(FLERR,"Fix widom molecule must have coordinates"); if (onemols[imol]->typeflag == 0) - error->all(FLERR,"Fix Widom molecule must have atom types"); + error->all(FLERR,"Fix widom molecule must have atom types"); if (nwidom_type != 0) - error->all(FLERR,"Atom type must be zero in fix Widom mol command"); + error->all(FLERR,"Atom type must be zero in fix widom mol command"); if (onemols[imol]->qflag == 1 && atom->q == NULL) - error->all(FLERR,"Fix Widom molecule has charges, but atom style does not"); + error->all(FLERR,"Fix widom molecule has charges, but atom style does not"); if (atom->molecular == 2 && onemols != atom->avec->onemols) - error->all(FLERR,"Fix Widom molecule template ID must be same " + error->all(FLERR,"Fix widom molecule template ID must be same " "as atom_style template ID"); onemols[imol]->check_attributes(0); } if (charge_flag && atom->q == NULL) - error->all(FLERR,"Fix Widom atom has charge, but atom style does not"); + error->all(FLERR,"Fix widom atom has charge, but atom style does not"); // setup of array of coordinates for molecule insertion @@ -186,7 +186,7 @@ FixWidom::FixWidom(LAMMPS *lmp, int narg, char **arg) : void FixWidom::options(int narg, char **arg) { - if (narg < 0) error->all(FLERR,"Illegal fix Widom command"); + if (narg < 0) error->all(FLERR,"Illegal fix widom command"); // defaults @@ -208,29 +208,29 @@ void FixWidom::options(int narg, char **arg) int iarg = 0; while (iarg < narg) { if (strcmp(arg[iarg],"mol") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix Widom command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); imol = atom->find_molecule(arg[iarg+1]); if (imol == -1) - error->all(FLERR,"Molecule template ID for fix Widom does not exist"); + error->all(FLERR,"Molecule template ID for fix widom does not exist"); if (atom->molecules[imol]->nset > 1 && comm->me == 0) error->warning(FLERR,"Molecule template for " - "fix Widom has multiple molecules"); + "fix widom has multiple molecules"); exchmode = EXCHMOL; onemols = atom->molecules; nmol = onemols[imol]->nset; iarg += 2; } else if (strcmp(arg[iarg],"region") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix Widom command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); iregion = domain->find_region(arg[iarg+1]); if (iregion == -1) - error->all(FLERR,"Region ID for fix Widom does not exist"); + error->all(FLERR,"Region ID for fix widom does not exist"); int n = strlen(arg[iarg+1]) + 1; idregion = new char[n]; strcpy(idregion,arg[iarg+1]); regionflag = 1; iarg += 2; } else if (strcmp(arg[iarg],"charge") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix Widom command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); charge = utils::numeric(FLERR,arg[iarg+1],false,lmp); charge_flag = true; iarg += 2; @@ -238,10 +238,10 @@ void FixWidom::options(int narg, char **arg) full_flag = true; iarg += 1; } else if (strcmp(arg[iarg],"intra_energy") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal fix Widom command"); + if (iarg+2 > narg) error->all(FLERR,"Illegal fix widom command"); energy_intra = utils::numeric(FLERR,arg[iarg+1],false,lmp); iarg += 2; - } else error->all(FLERR,"Illegal fix Widom command"); + } else error->all(FLERR,"Illegal fix widom command"); } } @@ -291,7 +291,7 @@ void FixWidom::init() ) { full_flag = true; if (comm->me == 0) - error->warning(FLERR,"Fix Widom using full_energy option"); + error->warning(FLERR,"Fix widom using full_energy option"); } } @@ -299,7 +299,7 @@ void FixWidom::init() if (exchmode == EXCHATOM) { if (nwidom_type <= 0 || nwidom_type > atom->ntypes) - error->all(FLERR,"Invalid atom type in fix Widom command"); + error->all(FLERR,"Invalid atom type in fix widom command"); } // if molecules are exchanged or moved, check for unset mol IDs @@ -314,17 +314,17 @@ void FixWidom::init() MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); if (flagall && comm->me == 0) error->all(FLERR, - "All mol IDs should be set for fix Widom group atoms"); + "All mol IDs should be set for fix widom group atoms"); } if (exchmode == EXCHMOL) if (atom->molecule_flag == 0 || !atom->tag_enable || !atom->map_style) error->all(FLERR, - "Fix Widom molecule command requires that " + "Fix widom molecule command requires that " "atoms have molecule attributes"); if (domain->dimension == 2) - error->all(FLERR,"Cannot use fix Widom in a 2d simulation"); + error->all(FLERR,"Cannot use fix widom in a 2d simulation"); // create a new group for interaction exclusions // used for attempted atom or molecule deletions @@ -387,7 +387,7 @@ void FixWidom::init() } else gas_mass = atom->mass[nwidom_type]; if (gas_mass <= 0.0) - error->all(FLERR,"Illegal fix Widom gas mass <= 0"); + error->all(FLERR,"Illegal fix widom gas mass <= 0"); // check that no deletable atoms are in atom->firstgroup // deleting such an atom would not leave firstgroup atoms first @@ -404,7 +404,7 @@ void FixWidom::init() MPI_Allreduce(&flag,&flagall,1,MPI_INT,MPI_SUM,world); if (flagall) - error->all(FLERR,"Cannot do Widom on atoms in atom_modify first group"); + error->all(FLERR,"Cannot use fix widom on atoms in atom_modify first group"); } // compute beta @@ -417,7 +417,7 @@ void FixWidom::init() // full_flag on molecules on more than one processor. // Print error if this is the current mode if (full_flag && (exchmode == EXCHMOL) && comm->nprocs > 1) - error->all(FLERR,"fix Widom does currently not support full_energy option with molecules on more than 1 MPI process."); + error->all(FLERR,"fix widom does currently not support full_energy option with molecules on more than 1 MPI process."); } @@ -535,7 +535,7 @@ void FixWidom::attempt_atomic_insertion() if (triclinic == 0) { domain->remap(coord); if (!domain->inside(coord)) - error->one(FLERR,"Fix Widom put atom outside box"); + error->one(FLERR,"Fix widom put atom outside box"); if (coord[0] >= sublo[0] && coord[0] < subhi[0] && coord[1] >= sublo[1] && coord[1] < subhi[1] && coord[2] >= sublo[2] && coord[2] < subhi[2]) proc_flag = 1; @@ -648,7 +648,7 @@ void FixWidom::attempt_molecule_insertion() xtmp[2] = molcoords[i][2]; domain->remap(xtmp); if (!domain->inside(xtmp)) - error->one(FLERR,"Fix Widom put atom outside box"); + error->one(FLERR,"Fix widom put atom outside box"); procflag[i] = false; if (triclinic == 0) { @@ -737,7 +737,7 @@ void FixWidom::attempt_atomic_insertion_full() if (triclinic == 0) { domain->remap(coord); if (!domain->inside(coord)) - error->one(FLERR,"Fix Widom put atom outside box"); + error->one(FLERR,"Fix widom put atom outside box"); if (coord[0] >= sublo[0] && coord[0] < subhi[0] && coord[1] >= sublo[1] && coord[1] < subhi[1] && coord[2] >= sublo[2] && coord[2] < subhi[2]) proc_flag = 1; @@ -803,7 +803,7 @@ void FixWidom::attempt_molecule_insertion_full() MPI_Allreduce(&maxmol,&maxmol_all,1,MPI_LMP_TAGINT,MPI_MAX,world); maxmol_all++; if (maxmol_all >= MAXTAGINT) - error->all(FLERR,"Fix Widom ran out of available molecule IDs"); + error->all(FLERR,"Fix widom ran out of available molecule IDs"); int insertion_molecule = maxmol_all; tagint maxtag = 0; @@ -883,7 +883,7 @@ void FixWidom::attempt_molecule_insertion_full() imageint imagetmp = imagezero; domain->remap(xtmp,imagetmp); if (!domain->inside(xtmp)) - error->one(FLERR,"Fix Widom put atom outside box"); + error->one(FLERR,"Fix widom put atom outside box"); int proc_flag = 0; if (triclinic == 0) { @@ -904,7 +904,7 @@ void FixWidom::attempt_molecule_insertion_full() atom->image[m] = imagetmp; atom->molecule[m] = insertion_molecule; if (maxtag_all+i+1 >= MAXTAGINT) - error->all(FLERR,"Fix Widom ran out of available atom IDs"); + error->all(FLERR,"Fix widom ran out of available atom IDs"); atom->tag[m] = maxtag_all + i + 1; atom->v[m][0] = 0; atom->v[m][1] = 0; From 4a8d6016e412049e012359310c7d7da37478547c Mon Sep 17 00:00:00 2001 From: Stan Moore Date: Fri, 11 Sep 2020 22:49:44 -0600 Subject: [PATCH 09/43] Update docs --- doc/src/fix_qeq_reax.rst | 8 ++++++-- src/USER-REAXC/fix_qeq_reax.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/src/fix_qeq_reax.rst b/doc/src/fix_qeq_reax.rst index 47dca86401..512c596b4d 100644 --- a/doc/src/fix_qeq_reax.rst +++ b/doc/src/fix_qeq_reax.rst @@ -21,6 +21,7 @@ Syntax * tolerance = precision to which charges will be equilibrated * params = reax/c or a filename * args = *dual* (optional) +* args = *maxiter value* (optional) Examples """""""" @@ -28,7 +29,7 @@ Examples .. code-block:: LAMMPS fix 1 all qeq/reax 1 0.0 10.0 1.0e-6 reax/c - fix 1 all qeq/reax 1 0.0 10.0 1.0e-6 param.qeq + fix 1 all qeq/reax 1 0.0 10.0 1.0e-6 param.qeq maxiter 500 Description """"""""""" @@ -69,6 +70,9 @@ The optional *dual* keyword allows to perform the optimization of the S and T matrices in parallel. This is only supported for the *qeq/reax/omp* style. Otherwise they are processed separately. +The optional *maxiter* keyword allows changing the max number +of iterations in the linear solver. The default value is 200. + Restart, fix_modify, output, run start/stop, minimize info """"""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -102,7 +106,7 @@ Related commands Default """"""" -none +maxiter 200 ---------- diff --git a/src/USER-REAXC/fix_qeq_reax.cpp b/src/USER-REAXC/fix_qeq_reax.cpp index 8e6e114861..fea8b39f54 100644 --- a/src/USER-REAXC/fix_qeq_reax.cpp +++ b/src/USER-REAXC/fix_qeq_reax.cpp @@ -82,7 +82,7 @@ FixQEqReax::FixQEqReax(LAMMPS *lmp, int narg, char **arg) : int iarg = 8; while (iarg < narg) { if (strcmp(arg[iarg],"dual") == 0) dual_enabled = 1; - else if (strcmp(arg[iarg],"imax") == 0) { + else if (strcmp(arg[iarg],"maxiter") == 0) { if (iarg+1 > narg-1) error->all(FLERR,"Illegal fix qeq/reax command"); imax = utils::numeric(FLERR,arg[iarg+1],false,lmp); From 16d2fef5ade6c17ee5efccc80c1cb9a08db54761 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 11:06:20 -0400 Subject: [PATCH 10/43] add check that shrinkwrap boundaries are not use when reading a data file while a MSM kspace style is defined --- src/read_data.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/read_data.cpp b/src/read_data.cpp index 2a6801b3a5..c80432f098 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -294,8 +294,11 @@ void ReadData::command(int narg, char **arg) // error checks - if (domain->dimension == 2 && domain->zperiodic == 0) + if ((domain->dimension == 2) && (domain->zperiodic == 0)) error->all(FLERR,"Cannot run 2d simulation with nonperiodic Z dimension"); + if ((domain->nonperiodic == 2) && utils::strmatch(force->kspace_style,"^msm")) + error->all(FLERR,"Reading a data file with shrinkwrap boundaries is " + "not compatible with a MSM KSpace style"); if (domain->box_exist && !addflag) error->all(FLERR,"Cannot read_data without add keyword " "after simulation box is defined"); From d7500c3e5abb9fa4242d4bc9106182b82335f796 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 11:09:33 -0400 Subject: [PATCH 11/43] MSM output format tweaks --- src/KSPACE/msm.cpp | 6 +++--- src/KSPACE/msm_cg.cpp | 2 +- src/USER-OMP/msm_cg_omp.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index d0f4d38686..2b025fbe3e 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -206,9 +206,9 @@ void MSM::init() if (me == 0) { std::string mesg = fmt::format(" 3d grid size/proc = {}\n", ngrid_max); - mesg += fmt::format(" estimated absolute RMS force accuracy = {:.8g}\n", + mesg += fmt::format(" estimated absolute RMS force accuracy = {:.8}\n", estimated_error); - mesg += fmt::format(" estimated relative force accuracy = {:.8g}\n", + mesg += fmt::format(" estimated relative force accuracy = {:.8}\n", estimated_error/two_charge_force); mesg += fmt::format(" grid = {} {} {}\n",nx_msm[0],ny_msm[0],nz_msm[0]); mesg += fmt::format(" order = {}\n",order); @@ -1077,7 +1077,7 @@ void MSM::set_grid_global() if (me == 0) error->warning(FLERR,fmt::format("Adjusting Coulombic cutoff for " - "MSM, new cutoff = {}", cutoff)); + "MSM, new cutoff = {:.8}", cutoff)); } if (triclinic == 0) { diff --git a/src/KSPACE/msm_cg.cpp b/src/KSPACE/msm_cg.cpp index 79d33b869d..bbd940f762 100644 --- a/src/KSPACE/msm_cg.cpp +++ b/src/KSPACE/msm_cg.cpp @@ -133,7 +133,7 @@ void MSMCG::compute(int eflag, int vflag) / static_cast(atom->natoms); if (me == 0) - utils::logmesg(lmp,fmt::format(" MSM/cg optimization cutoff: {:.8g}\n" + utils::logmesg(lmp,fmt::format(" MSM/cg optimization cutoff: {:.8}\n" " Total charged atoms: {:.1f}%\n" " Min/max charged atoms/proc: {:.1f}%" " {:.1f}%\n",smallq, diff --git a/src/USER-OMP/msm_cg_omp.cpp b/src/USER-OMP/msm_cg_omp.cpp index c42aa8e0c1..976ea83610 100644 --- a/src/USER-OMP/msm_cg_omp.cpp +++ b/src/USER-OMP/msm_cg_omp.cpp @@ -137,7 +137,7 @@ void MSMCGOMP::compute(int eflag, int vflag) / static_cast(atom->natoms); if (me == 0) - utils::logmesg(MSM::lmp,fmt::format(" MSM/cg optimization cutoff: {:.8g}\n" + utils::logmesg(MSM::lmp,fmt::format(" MSM/cg optimization cutoff: {:.8}\n" " Total charged atoms: {:.1f}%\n" " Min/max charged atoms/proc: {:.1f}%" " {:.1f}%\n",smallq, From 3368eb79d843265d1a35570fb4f9965beae5de22 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 11:10:12 -0400 Subject: [PATCH 12/43] fix issue with local variable shadowing a global variable --- src/KSPACE/msm.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index 2b025fbe3e..2634b7633c 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -1028,6 +1028,7 @@ void MSM::set_grid_global() int flag = 0; int xlevels,ylevels,zlevels; + xlevels = ylevels = zlevels = 1; while (!factorable(nx_max,flag,xlevels)) { double k = log(nx_max)/log(2.0); @@ -1432,16 +1433,15 @@ void MSM::setup_grid() return 1 if yes, 0 if no ------------------------------------------------------------------------- */ -int MSM::factorable(int n, int &flag, int &levels) +int MSM::factorable(int n, int &flag, int &nlevels) { int i; - levels = 1; while (n > 1) { for (i = 0; i < nfactors; i++) { if (n % factors[i] == 0) { n /= factors[i]; - levels++; + nlevels++; break; } } From 69962b4de5b92c656b801e3bb08aaa1efec7b38d Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 11:10:38 -0400 Subject: [PATCH 13/43] add test for MSM kspace without periodic boundaries --- .../force-styles/tests/kspace-msm_nopbc.yaml | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 unittest/force-styles/tests/kspace-msm_nopbc.yaml diff --git a/unittest/force-styles/tests/kspace-msm_nopbc.yaml b/unittest/force-styles/tests/kspace-msm_nopbc.yaml new file mode 100644 index 0000000000..99bbd2ae97 --- /dev/null +++ b/unittest/force-styles/tests/kspace-msm_nopbc.yaml @@ -0,0 +1,90 @@ +--- +lammps_version: 24 Aug 2020 +date_generated: Sat Sep 12 10:33:36 202 +epsilon: 5e-11 +prerequisites: ! | + atom full + pair coul/msm + kspace msm +pre_commands: ! | + boundary f f f +post_commands: ! | + pair_modify compute no + kspace_style msm 1.0e-4 + kspace_modify cutoff/adjust no + kspace_modify pressure/scalar no # required for USER-OMP with msm +input_file: in.fourmol +pair_style: coul/msm 12.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 -1.0766173668302007e-01 3.3042340827626349e-01 -2.9550761278746868e-01 + 2 1.4576263044966863e-02 -2.2187776206184587e-01 2.1317727080129803e-01 + 3 -6.2277085668426338e-03 1.1652138650558974e-02 -1.3297461972937180e-02 + 4 2.8786238443846923e-02 -4.5768542246633188e-02 4.9349101662676420e-02 + 5 4.2979655856763686e-02 -5.4082950850616152e-02 5.4543059350179231e-02 + 6 4.0963202143681071e-02 -2.5177829287287617e-01 4.4685026134973971e-01 + 7 4.3752018459624321e-02 2.0781332786234075e-01 -4.5927449533997905e-01 + 8 1.7902097598623774e-02 2.1086807165304489e-01 -4.6243455927005356e-01 + 9 2.0355019954072114e-03 -1.5827691071752098e-01 2.7862824718724422e-01 + 10 -1.9772220824436811e-02 -2.2139108764682804e-02 7.8260376067917345e-02 + 11 -2.9153388383640691e-02 -2.2889984975802833e-02 1.0317906039578388e-01 + 12 1.2922943535921338e-01 9.7734055402007608e-02 -3.1908212769200051e-01 + 13 -5.4703693507262792e-02 -2.6149394426322036e-02 1.0994484599179440e-01 + 14 -4.2988225876533809e-02 -3.0099007171320122e-02 1.0262933028641755e-01 + 15 -3.7590864461845237e-02 -4.4176544191975885e-02 1.0017383244998040e-01 + 16 -1.9816142648538662e-01 -1.0441860078884198e-01 5.3904854977591932e-01 + 17 1.1181429866686794e-01 1.2719867318944633e-01 -4.3015678280050906e-01 + 18 3.1502200306647382e-01 4.1974825623470402e-01 -6.7479886734843464e-01 + 19 -1.6689905496966348e-01 -1.8680268140244130e-01 3.1219145983138630e-01 + 20 -1.5445789535736368e-01 -1.7976356547462513e-01 3.0246182814337153e-01 + 21 4.5519486932419828e-01 2.3683712353345862e-01 -8.7807403931732608e-01 + 22 -2.2220599724324458e-01 -1.2571032291855247e-01 3.9771867786752363e-01 + 23 -1.9325477274003933e-01 -1.2333786894453987e-01 4.0830652757809321e-01 + 24 -1.8286999844561756e-02 8.1021886775407503e-01 -3.7126337318324748e-01 + 25 5.5726795149239679e-02 -3.9672045025447300e-01 2.0847896698971494e-01 + 26 -2.7814896742372048e-02 -4.2032861857567699e-01 1.8697109800153439e-01 + 27 -5.3163776317893185e-01 2.5116155120314121e-01 -4.1286599443776800e-01 + 28 2.9735002262617338e-01 -1.6009440605268385e-01 2.2070546856483822e-01 + 29 2.5561709605369254e-01 -1.2916627825090182e-01 2.0454030119394306e-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 -1.0348864007239668e-01 3.2761800817797082e-01 -2.7223154925249687e-01 + 2 1.1547721105281426e-02 -2.2227221129297944e-01 1.9829831292225819e-01 + 3 -6.1369788686855553e-03 1.1473670690755385e-02 -1.2235119385263003e-02 + 4 2.8809534480886322e-02 -4.5070713784827680e-02 4.5263724656363712e-02 + 5 4.2323185781698226e-02 -5.2976717776467216e-02 4.9736627529403242e-02 + 6 3.8194733647326694e-02 -2.4587855825158134e-01 4.1856615868672892e-01 + 7 4.5246314631942265e-02 2.0099417967365288e-01 -4.3512916657147588e-01 + 8 2.2478550451619471e-02 2.0362301286740869e-01 -4.3516590120465981e-01 + 9 -1.4178329999306901e-03 -1.5368030392367521e-01 2.6080100301013964e-01 + 10 -2.0495450209946312e-02 -2.0851530662446178e-02 7.4319850349891012e-02 + 11 -3.0029358892398838e-02 -2.0702279983167187e-02 9.8520949030575691e-02 + 12 1.3289689675296273e-01 9.3775108342107519e-02 -3.0419584939008770e-01 + 13 -5.5922486140088226e-02 -2.4843666409380370e-02 1.0515381624429042e-01 + 14 -4.4208019862361184e-02 -2.8633675987750289e-02 9.8140924300998925e-02 + 15 -3.8534805055538454e-02 -4.3447767456428393e-02 9.5052177465633700e-02 + 16 -2.0197663776900704e-01 -9.6067608908760441e-02 5.1267317994067874e-01 + 17 1.1536172816123620e-01 1.2150176721849106e-01 -4.0576909205923889e-01 + 18 3.2654836490027450e-01 4.3181659922436294e-01 -6.4631937847140064e-01 + 19 -1.7012391318923387e-01 -1.9294196901436866e-01 3.0171461650625692e-01 + 20 -1.6090393021018687e-01 -1.8797301084913640e-01 2.9016061976069074e-01 + 21 4.6464803590088510e-01 2.0966755173124815e-01 -8.4865286121979111e-01 + 22 -2.2714234064511640e-01 -1.1056430229170305e-01 3.8599855632265567e-01 + 23 -1.9865351580467286e-01 -1.1110079780224448e-01 3.9440435138483038e-01 + 24 -1.1755770692492392e-02 7.9361803570205403e-01 -3.4523386783293764e-01 + 25 5.0411795551073120e-02 -3.8916839645964540e-01 1.9278646898979940e-01 + 26 -2.9733815594164319e-02 -4.1142305819442143e-01 1.7495936527287648e-01 + 27 -5.2243746980854566e-01 2.4806539986837281e-01 -3.8666209074075969e-01 + 28 2.9308687168280761e-01 -1.5702803664966208e-01 2.0612286277862657e-01 + 29 2.5153793410884945e-01 -1.2745488321867574e-01 1.8930202039662150e-01 +... From eda04dac984f585ca0ede9f4c79b119e480abc30 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 15:13:23 -0400 Subject: [PATCH 14/43] update conventions and guidelines about C++ standard and requirements --- .github/CONTRIBUTING.md | 1 + doc/github-development-workflow.md | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index b61a753518..60fe82d86c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -67,6 +67,7 @@ How quickly your contribution will be integrated depends largely on how much eff Here is a checklist of steps you need to follow to submit a single file or user package for our consideration. Following these steps will save both you and us time. See existing files in packages in the source directory for examples. If you are uncertain, please ask on the lammps-users mailing list. +* C++ source code must be compatible with the C++-11 standard. Packages may require a later standard, if justified. * All source files you provide must compile with the most current version of LAMMPS with multiple configurations. In particular you need to test compiling LAMMPS from scratch with `-DLAMMPS_BIGBIG` set in addition to the default `-DLAMMPS_SMALLBIG` setting. Your code will need to work correctly in serial and in parallel using MPI. * For consistency with the rest of LAMMPS and especially, if you want your contribution(s) to be added to main LAMMPS code or one of its standard packages, it needs to be written in a style compatible with other LAMMPS source files. This means: 2-character indentation per level, no tabs, no trailing whitespace, no lines over 80 characters. I/O is done via the C-style stdio library, style class header files should not import any system headers, STL containers should be avoided in headers, and forward declarations used where possible or needed. All added code should be placed into the LAMMPS_NS namespace or a sub-namespace; global or static variables should be avoided, as they conflict with the modular nature of LAMMPS and the C++ class structure. There MUST NOT be any "using namespace XXX;" statements in headers. In the implementation file (.cpp) system includes should be placed in angular brackets (<>) and for c-library functions the C++ style header files should be included ( instead of , or instead of ). This all is so the developers can more easily understand, integrate, and maintain your contribution and reduce conflicts with other parts of LAMMPS. This basically means that the code accesses data structures, performs its operations, and is formatted similar to other LAMMPS source files, including the use of the error class for error and warning messages. * Source, style name, and documentation file should follow the following naming convention: style names should be lowercase and words separated by a forward slash; for a new fix style 'foo/bar', the class should be named FixFooBar, the name of the source files should be 'fix_foo_bar.h' and 'fix_foo_bar.cpp' and the corresponding documentation should be in a file 'fix_foo_bar.rst'. diff --git a/doc/github-development-workflow.md b/doc/github-development-workflow.md index fd38c983a2..a7d41dd32a 100644 --- a/doc/github-development-workflow.md +++ b/doc/github-development-workflow.md @@ -136,7 +136,8 @@ Here are some items to check: * string.h -> cstring * time.h -> ctime * Do NOT replace (as they are C++-11): `inttypes.h` and `stdint.h`. - * Code should follow the C++-98 standard. C++-11 is only accepted + * Code must follow the C++-11 standard. C++98-only is no longer accepted + * Code should use `nullptr` instead of `NULL` where applicable. in individual special purpose packages * indentation is 2 spaces per level * there should be NO tabs and no trailing whitespace (review the "checkstyle" test on pull requests) @@ -145,6 +146,8 @@ Here are some items to check: Forward declarations should be used instead when possible. * iostreams should be avoided. LAMMPS uses stdio from the C-library. * use of STL in headers and class definitions should be avoided. + exception is , but it won't need to be explicitly included + since pointers.h already includes it. so std::string can be used directly. * there MUST NOT be any "using namespace XXX;" statements in headers. * static class members should be avoided at all cost. * anything storing atom IDs should be using `tagint` and not `int`. @@ -152,6 +155,8 @@ Here are some items to check: compiling LAMMPS with `-DLAMMPS_BIGBIG`. * when including both `lmptype.h` (and using defines or macros from it) and `mpi.h`, `lmptype.h` must be included first. + * see https://github.com/lammps/lammps/blob/master/doc/include-file-conventions.md + for general include file conventions and best practices * when pair styles are added, check if settings for flags like `single_enable`, `writedata`, `reinitflag`, `manybody_flag` and others are correctly set and supported. From da0cdb0de42bcd06c6367a719402d7a4303b49fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 19:06:30 -0400 Subject: [PATCH 15/43] update formatting of keyword summary --- doc/src/fix_qeq_reax.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/src/fix_qeq_reax.rst b/doc/src/fix_qeq_reax.rst index 512c596b4d..8752888c4c 100644 --- a/doc/src/fix_qeq_reax.rst +++ b/doc/src/fix_qeq_reax.rst @@ -20,8 +20,14 @@ Syntax * cutlo,cuthi = lo and hi cutoff for Taper radius * tolerance = precision to which charges will be equilibrated * params = reax/c or a filename -* args = *dual* (optional) -* args = *maxiter value* (optional) +* one or more keywords or keyword/value pairs may be appended + + .. parsed-literal:: + + keyword = *dual* or *maxiter* + *dual* = process S and T matrix in parallel (only for qeq/reax/omp) + *maxiter* N = limit the number of iterations to *N* + Examples """""""" From b702298e83ba964a5ef479fe7a8ce63f9543c51e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 12 Sep 2020 19:06:58 -0400 Subject: [PATCH 16/43] fix typo --- doc/src/fix_nh.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/fix_nh.rst b/doc/src/fix_nh.rst index 84b497dc3f..988a147abe 100644 --- a/doc/src/fix_nh.rst +++ b/doc/src/fix_nh.rst @@ -51,7 +51,7 @@ Syntax *couple* = *none* or *xyz* or *xy* or *yz* or *xz* *tchain* value = N N = length of thermostat chain (1 = single thermostat) - *pchain* values = N + *pchain* value = N N length of thermostat chain on barostat (0 = no thermostat) *mtk* value = *yes* or *no* = add in MTK adjustment term or not *tloop* value = M From 5a0623595b73c1a9fd12dd9153d14ff58eca3a81 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 16:46:13 -0400 Subject: [PATCH 17/43] make char * argument of lammps_get_thermo() const --- src/library.cpp | 4 ++-- src/library.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 0e0c4070ea..4f02e95621 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -594,7 +594,7 @@ double lammps_get_natoms(void *handle) { LAMMPS *lmp = (LAMMPS *) handle; - double natoms = static_cast (lmp->atom->natoms); + double natoms = static_cast(lmp->atom->natoms); if (natoms > 9.0e15) return 0; // TODO:XXX why not -1? return natoms; } @@ -616,7 +616,7 @@ a double, so it can also return information that is computed on-the-fly. * \param keyword string with the name of the thermo keyword * \return value of the requested thermo property or 0.0 */ -double lammps_get_thermo(void *handle, char *keyword) +double lammps_get_thermo(void *handle, const char *keyword) { LAMMPS *lmp = (LAMMPS *) handle; double dval = 0.0; diff --git a/src/library.h b/src/library.h index f5a02502e7..ebbe1464df 100644 --- a/src/library.h +++ b/src/library.h @@ -100,7 +100,7 @@ void lammps_commands_string(void *handle, const char *str); int lammps_version(void *handle); int lammps_get_mpi_comm(void* handle); double lammps_get_natoms(void *handle); -double lammps_get_thermo(void *handle, char *keyword); +double lammps_get_thermo(void *handle, const char *keyword); void lammps_extract_box(void *handle, double *boxlo, double *boxhi, double *xy, double *yz, double *xz, From 39255da6aed07f8d3457e9adfc9a1e1c0a102e2c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 16:46:59 -0400 Subject: [PATCH 18/43] use common main function that allows handling of common command line flags. --- unittest/c-library/CMakeLists.txt | 14 +-- .../c-library/test_library_properties.cpp | 88 +++++++++++++------ unittest/c-library/test_main.cpp | 59 +++++++++++++ unittest/c-library/test_main.h | 33 +++++++ 4 files changed, 160 insertions(+), 34 deletions(-) create mode 100644 unittest/c-library/test_main.cpp create mode 100644 unittest/c-library/test_main.h diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 90c57f1fa7..7bbac4c430 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -1,13 +1,13 @@ -add_executable(test_library_open test_library_open.cpp) -target_link_libraries(test_library_open PRIVATE lammps GTest::GTest GTest::GTestMain) +add_executable(test_library_open test_library_open.cpp test_main.cpp) +target_link_libraries(test_library_open PRIVATE lammps GTest::GTest GTest::GMock) add_test(LibraryOpen test_library_open) -add_executable(test_library_commands test_library_commands.cpp) -target_link_libraries(test_library_commands PRIVATE lammps GTest::GTest GTest::GTestMain) +add_executable(test_library_commands test_library_commands.cpp test_main.cpp) +target_link_libraries(test_library_commands PRIVATE lammps GTest::GTest GTest::GMock) add_test(LibraryCommands test_library_commands) -add_executable(test_library_properties test_library_properties.cpp) -target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GTestMain) +add_executable(test_library_properties test_library_properties.cpp test_main.cpp) +target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GMock) +target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) add_test(LibraryProperties test_library_properties) - diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 5e8c410cce..030ff96795 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -1,53 +1,87 @@ // unit tests for checking and changing simulation properties through the library interface -#include "library.h" #include "lammps.h" +#include "library.h" #include +#include "gmock/gmock.h" #include "gtest/gtest.h" -const char *demo_input[] = { - "region box block 0 $x 0 2 0 2", - "create_box 1 box", - "create_atoms 1 single 1.0 1.0 ${zpos}" }; -const char *cont_input[] = { - "create_atoms 1 single &", - "0.2 0.1 0.1" }; +#include "test_main.h" -class LAMMPS_properties : public ::testing::Test -{ +#define STRINGIFY(val) XSTR(val) +#define XSTR(val) #val + +using ::testing::HasSubstr; +using ::testing::StartsWith; + +class LAMMPS_properties : public ::testing::Test { protected: void *lmp; - LAMMPS_properties() {}; - ~LAMMPS_properties() override {}; + std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); + + LAMMPS_properties(){}; + ~LAMMPS_properties() override{}; + + void SetUp() override + { + const char *args[] = {"LAMMPS_test", "-log", "none", + "-echo", "screen", "-nocite", + "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; - void SetUp() override { - const char *args[] = {"LAMMPS_test", "-log", "none", - "-echo", "screen", "-nocite" }; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - lmp = lammps_open_no_mpi(argc, argv, NULL); + lmp = lammps_open_no_mpi(argc, argv, NULL); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS ("); + if (verbose) std::cout << output; + EXPECT_THAT(output, StartsWith("LAMMPS (")); } - void TearDown() override { + void TearDown() override + { ::testing::internal::CaptureStdout(); lammps_close(lmp); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; lmp = nullptr; } }; -TEST_F(LAMMPS_properties, get_mpi_comm) { - int f_comm = lammps_get_mpi_comm(lmp); - if (lammps_config_has_mpi_support()) - EXPECT_GE(f_comm,0); - else - EXPECT_EQ(f_comm,-1); +TEST_F(LAMMPS_properties, version) +{ + EXPECT_GE(20200824, lammps_version(lmp)); }; -TEST_F(LAMMPS_properties, box) { +TEST_F(LAMMPS_properties, get_mpi_comm) +{ + int f_comm = lammps_get_mpi_comm(lmp); + if (lammps_config_has_mpi_support()) + EXPECT_GE(f_comm, 0); + else + EXPECT_EQ(f_comm, -1); +}; + +TEST_F(LAMMPS_properties, natoms) +{ + std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, input.c_str()); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 29); +}; + +TEST_F(LAMMPS_properties, thermo) +{ + std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, input.c_str()); + lammps_command(lmp, "run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_thermo(lmp, "step"), 2); + EXPECT_EQ(lammps_get_thermo(lmp, "atoms"), 29); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0); }; diff --git a/unittest/c-library/test_main.cpp b/unittest/c-library/test_main.cpp new file mode 100644 index 0000000000..f32e222e1e --- /dev/null +++ b/unittest/c-library/test_main.cpp @@ -0,0 +1,59 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "test_main.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include + +// whether to print verbose output (i.e. not capturing LAMMPS screen output). +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 1) { + return 1; + } + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = LAMMPS_NS::utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + int iarg = 1; + while (iarg < argc) { + if (strcmp(argv[iarg], "-v") == 0) { + verbose = true; + ++iarg; + } else { + std::cerr << "unknown option: " << argv[iarg] << "\n\n"; + MPI_Finalize(); + return 1; + } + } + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/c-library/test_main.h b/unittest/c-library/test_main.h new file mode 100644 index 0000000000..ac9bc0d26a --- /dev/null +++ b/unittest/c-library/test_main.h @@ -0,0 +1,33 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef TEST_MAIN_H +#define TEST_MAIN_H + +extern bool verbose; + +#define EXPECT_FP_LE_WITH_EPS(val1, val2, eps) \ + do { \ + const double diff = fabs(val1 - val2); \ + const double div = std::min(fabs(val1), fabs(val2)); \ + const double err = (div == 0.0) ? diff : diff / div; \ + EXPECT_PRED_FORMAT2(::testing::DoubleLE, err, eps); \ + } while (0); + +#endif + +#if defined _WIN32 +static const char PATH_SEP = '\\'; +#else +static const char PATH_SEP = '/'; +#endif From fcb38354dc76c02bc0a9b74554bcca6759dffd1e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 16:47:29 -0400 Subject: [PATCH 19/43] import adapted example input deck --- unittest/c-library/data.fourmol | 210 ++++++++++++++++++++++++++++++++ unittest/c-library/in.fourmol | 25 ++++ 2 files changed, 235 insertions(+) create mode 100644 unittest/c-library/data.fourmol create mode 100644 unittest/c-library/in.fourmol diff --git a/unittest/c-library/data.fourmol b/unittest/c-library/data.fourmol new file mode 100644 index 0000000000..386ad81c49 --- /dev/null +++ b/unittest/c-library/data.fourmol @@ -0,0 +1,210 @@ +LAMMPS data file via write_data, version 5 May 2020, timestep = 0 + +29 atoms +5 atom types +24 bonds +5 bond types +30 angles +4 angle types +31 dihedrals +5 dihedral types +2 impropers +2 improper types + + -6.024572 8.975428 xlo xhi + -7.692866 7.307134 ylo yhi + -8.086924 6.913076 zlo zhi + +Masses + +1 12.0107 +2 4.00794 +3 14.0067 +4 15.9994 +5 15.9994 + +Pair Coeffs # zero + +1 +2 +3 +4 +5 + +Bond Coeffs # zero + +1 1.5 +2 1.1 +3 1.3 +4 1.2 +5 1 + +Angle Coeffs # zero + +1 110.1 +2 111 +3 120 +4 108.5 + +Atoms # full + +10 2 1 7.0000000000000007e-02 2.0185283555536988e+00 -1.4283966846517357e+00 -9.6733527271133024e-01 0 0 0 +11 2 2 8.9999999999999997e-02 1.7929780509347666e+00 -1.9871047540768743e+00 -1.8840626643185674e+00 0 0 0 +12 2 1 -2.7000000000000002e-01 3.0030247876861225e+00 -4.8923319967572748e-01 -1.6188658531537248e+00 0 0 0 +13 2 2 8.9999999999999997e-02 4.0447273787895934e+00 -9.0131998547446246e-01 -1.6384447268320836e+00 0 0 0 +14 2 2 8.9999999999999997e-02 2.6033152817257075e+00 -4.0789761505963579e-01 -2.6554413538823063e+00 0 0 0 +2 1 2 3.1000000000000000e-01 3.0197083955402204e-01 2.9515239068888608e+00 -8.5689735572907566e-01 0 0 0 +3 1 1 -2.0000000000000000e-02 -6.9435377880558602e-01 1.2440473127136711e+00 -6.2233801468892025e-01 0 0 0 +4 1 2 8.9999999999999997e-02 -1.5771614164685133e+00 1.4915333140468066e+00 -1.2487126845040522e+00 0 0 0 +6 1 1 5.1000000000000001e-01 2.9412607937706009e-01 2.2719282656652909e-01 -1.2843094067857870e+00 0 0 0 +7 1 4 -5.1000000000000001e-01 3.4019871062879609e-01 -9.1277350075786561e-03 -2.4633113224304561e+00 0 0 0 +19 3 2 4.2359999999999998e-01 1.5349125211132961e+00 2.6315969880333707e+00 -4.2472859440220647e+00 0 0 0 +15 2 2 8.9999999999999997e-02 2.9756315249791303e+00 5.6334269722969288e-01 -1.2437650754599008e+00 0 0 0 +18 3 4 -8.4719999999999995e-01 2.1384791188033843e+00 3.0177261773770208e+00 -3.5160827596876225e+00 0 0 0 +20 3 2 4.2359999999999998e-01 2.7641167828863153e+00 3.6833419064000221e+00 -3.9380850623312638e+00 0 0 0 +8 2 3 -4.6999999999999997e-01 1.1641187171852805e+00 -4.8375305955385234e-01 -6.7659823767368688e-01 0 0 0 +9 2 2 3.1000000000000000e-01 1.3777459838125838e+00 -2.5366338669522998e-01 2.6877644730326306e-01 0 0 0 +16 2 1 5.1000000000000001e-01 2.6517554244980306e+00 -2.3957110424978438e+00 3.2908335999178327e-02 0 0 0 +17 2 4 -5.1000000000000001e-01 2.2309964792710639e+00 -2.1022918943319384e+00 1.1491948328949437e+00 0 0 0 +1 1 3 -4.6999999999999997e-01 -2.7993683669226832e-01 2.4726588069312840e+00 -1.7200860244148433e-01 0 0 0 +5 1 2 8.9999999999999997e-02 -8.9501761359359255e-01 9.3568128743071344e-01 4.0227731871484346e-01 0 0 0 +21 4 5 -8.4719999999999995e-01 4.9064454390208301e+00 -4.0751205255383196e+00 -3.6215576073601046e+00 0 0 0 +22 4 2 4.2359999999999998e-01 4.3687453488627543e+00 -4.2054270536772504e+00 -4.4651491269372565e+00 0 0 0 +23 4 2 4.2359999999999998e-01 5.7374928154769504e+00 -3.5763355905184966e+00 -3.8820297194230728e+00 0 0 0 +24 5 5 -8.4719999999999995e-01 2.0684115301174013e+00 3.1518221747664397e+00 3.1554242678474576e+00 0 0 0 +25 5 2 4.2359999999999998e-01 1.2998381073113014e+00 3.2755513587518097e+00 2.5092990173114837e+00 0 0 0 +26 5 2 4.2359999999999998e-01 2.5807438597688113e+00 4.0120175892854135e+00 3.2133398379059099e+00 0 0 0 +27 6 5 -8.4719999999999995e-01 -1.9613581876744359e+00 -4.3556300596085160e+00 2.1101467673534788e+00 0 0 0 +28 6 2 4.2359999999999998e-01 -2.7406520384725965e+00 -4.0207251278130975e+00 1.5828689861678511e+00 0 0 0 +29 6 2 4.2359999999999998e-01 -1.3108232656499081e+00 -3.5992986322410760e+00 2.2680459788743503e+00 0 0 0 + +Velocities + +1 7.7867804888392077e-04 5.8970331623292821e-04 -2.2179517633030531e-04 +2 2.7129529964126462e-03 4.6286427111164284e-03 3.5805549693846352e-03 +3 -1.2736791029204805e-03 1.6108674226414498e-03 -3.3618185901550799e-04 +4 -9.2828595122009308e-04 -1.2537885319521818e-03 -4.1204974953432108e-03 +5 -1.1800848061603740e-03 7.5424401975844038e-04 6.9023177964912290e-05 +6 -3.0914004879905335e-04 1.2755385764678133e-03 7.9574303350202582e-04 +7 -1.1037894966874103e-04 -7.6764845099077425e-04 -7.7217630460203659e-04 +8 3.9060281273221989e-04 -8.1444231918053418e-04 1.5134641148324972e-04 +9 1.2475530960659720e-03 -2.6608454451432528e-03 1.1117602907112732e-03 +10 4.5008983776042893e-04 4.9530197647538077e-04 -2.3336234361093645e-04 +11 -3.6977669078869707e-04 -1.5289071951960539e-03 -2.9176389881837113e-03 +12 1.0850834530183159e-03 -6.4965897903201833e-04 -1.2971152622619948e-03 +13 4.0754559196230639e-03 3.5043502394946119e-03 -7.8324487687854666e-04 +14 -1.3837220448746613e-04 -4.0656048637594394e-03 -3.9333461173944500e-03 +15 -4.3301707382721859e-03 -3.1802661664634938e-03 3.2037919043360571e-03 +16 -9.6715751018414326e-05 -5.0016572678960377e-04 1.4945658875149626e-03 +17 6.5692180538157174e-04 3.6635779995305095e-04 8.3495414466050911e-04 +18 -6.0936815808025862e-04 -9.3774557532468582e-04 -3.3558072507805731e-04 +19 -6.9919768291957119e-04 -3.6060777270430031e-03 4.2833405289822791e-03 +20 4.7777805013736515e-03 5.1003745845520452e-03 1.8002873923729241e-03 +21 -9.5568188553430398e-04 1.6594630943762931e-04 -1.8199788009966615e-04 +22 -3.3137518957653462e-03 -2.8683968287936054e-03 3.6384389958326871e-03 +23 2.4209481134686401e-04 -4.5457709985051130e-03 2.7663581642115042e-03 +24 2.5447450568861086e-04 4.8412447786110117e-04 -4.8021914527341357e-04 +25 4.3722771097312743e-03 -4.5184411669545515e-03 2.5200952006556795e-03 +26 -1.9250110555001179e-03 -3.0342169883610837e-03 3.5062814567984532e-03 +27 -2.6510179146429716e-04 3.6306203629019116e-04 -5.6235585400647747e-04 +28 -2.3068708109787484e-04 -8.5663070212203200e-04 2.1302563179109169e-03 +29 -2.5054744388303732e-03 -1.6773997805290820e-04 2.8436699761004796e-03 + +Bonds + +1 5 1 2 +2 3 1 3 +3 2 3 4 +4 2 3 5 +5 1 3 6 +6 3 6 8 +7 4 6 7 +8 5 8 9 +9 3 8 10 +10 2 10 11 +11 1 10 12 +12 1 10 16 +13 2 12 13 +14 2 12 14 +15 2 12 15 +16 4 16 17 +17 5 18 19 +18 5 18 20 +19 5 21 22 +20 5 21 23 +21 5 24 25 +22 5 24 26 +23 5 27 28 +24 5 27 29 + +Angles + +1 4 2 1 3 +2 4 1 3 5 +3 4 1 3 4 +4 4 1 3 6 +5 4 4 3 5 +6 2 5 3 6 +7 2 4 3 6 +8 3 3 6 7 +9 3 3 6 8 +10 3 7 6 8 +11 2 6 8 9 +12 2 9 8 10 +13 3 6 8 10 +14 2 8 10 11 +15 3 8 10 16 +16 2 11 10 12 +17 1 12 10 16 +18 1 8 10 12 +19 2 11 10 16 +20 2 10 12 15 +21 2 10 12 14 +22 2 10 12 13 +23 4 13 12 15 +24 4 13 12 14 +25 4 14 12 15 +26 4 10 16 17 +27 1 19 18 20 +28 1 22 21 23 +29 1 25 24 26 +30 1 28 27 29 + +Dihedrals + +1 2 2 1 3 6 +2 2 2 1 3 4 +3 3 2 1 3 5 +4 1 1 3 6 8 +5 1 1 3 6 7 +6 5 4 3 6 8 +7 5 4 3 6 7 +8 5 5 3 6 8 +9 5 5 3 6 7 +10 4 3 6 8 9 +11 3 3 6 8 10 +12 3 7 6 8 9 +13 4 7 6 8 10 +14 2 6 8 10 12 +15 2 6 8 10 16 +16 2 6 8 10 11 +17 2 9 8 10 12 +18 4 9 8 10 16 +19 5 9 8 10 11 +20 5 8 10 12 13 +21 1 8 10 12 14 +22 5 8 10 12 15 +23 4 8 10 16 17 +24 5 11 10 12 13 +25 5 11 10 12 14 +26 5 11 10 12 15 +27 2 11 10 16 17 +28 2 12 10 16 17 +29 5 16 10 12 13 +30 5 16 10 12 14 +31 5 16 10 12 15 + +Impropers + +1 1 6 3 8 7 +2 2 8 6 10 9 diff --git a/unittest/c-library/in.fourmol b/unittest/c-library/in.fourmol new file mode 100644 index 0000000000..6ef2a19167 --- /dev/null +++ b/unittest/c-library/in.fourmol @@ -0,0 +1,25 @@ +variable units index real +variable input_dir index . +variable data_file index ${input_dir}/data.fourmol +variable pair_style index 'zero 8.0' +variable bond_style index zero +variable angle_style index zero +variable dihedral_style index zero +variable improper_style index zero + +atom_style full +atom_modify map array +neigh_modify delay 2 every 2 check no +timestep 0.1 +units ${units} + +pair_style ${pair_style} +bond_style ${bond_style} +angle_style ${angle_style} +dihedral_style ${dihedral_style} +improper_style ${improper_style} + +read_data ${data_file} +dihedral_coeff * +improper_coeff * + From de49325c0f11fbf3553486dcb1ebcd020466eef2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 16:48:00 -0400 Subject: [PATCH 20/43] add properties example --- doc/src/pg_lib_properties.rst | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/doc/src/pg_lib_properties.rst b/doc/src/pg_lib_properties.rst index cdc7617d91..65ce9cf940 100644 --- a/doc/src/pg_lib_properties.rst +++ b/doc/src/pg_lib_properties.rst @@ -2,8 +2,8 @@ Retrieving or setting LAMMPS system properties ============================================== The library interface allows to extract different kinds of information -about the active simulation instance and also to modify some of them. -This allows to combine MD simulation steps with other processing and +about the active simulation instance and also to modify some of it. +This enables combining MD simulation steps with other processing and simulation methods computed in the calling code or another code that is coupled to LAMMPS via the library interface. In some cases the data returned is direct reference to the original data inside LAMMPS cast @@ -14,6 +14,34 @@ is the per-processor **local** data and indexed accordingly. These arrays can change sizes and order at every neighbor list rebuild and atom sort event as atoms are migrating between sub-domains. +.. code-block:: C + + #include "library.h" + #include + + int main(int argc, char **argv) + { + void *handle; + int i; + + handle = lammps_open_no_mpi(0, NULL, NULL); + lammps_file(handle,"in.sysinit"); + printf("running simulation with %g atoms\n", + lammps_get_natoms(handle)); + + lammps_command(handle,"run 1000 post no"); + + for (i=0; i < 10; ++i) { + lammps_command(handle,"run 100 pre no post no"); + printf("PE = %g\nKE = %g\n", + lammps_get_thermo(handle,"pe"), + lammps_get_thermo(handle,"ke")); + } + lammps_close(handle); + return 0; + } + + ----------------------- .. doxygenfunction:: lammps_version From a2fc33b419a6db1b933fc3b1825bd187363e714c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 17:00:26 -0400 Subject: [PATCH 21/43] update c-library tests --- unittest/c-library/test_library_commands.cpp | 122 +++++++++-------- unittest/c-library/test_library_open.cpp | 123 ++++++++++-------- .../c-library/test_library_properties.cpp | 2 +- 3 files changed, 138 insertions(+), 109 deletions(-) diff --git a/unittest/c-library/test_library_commands.cpp b/unittest/c-library/test_library_commands.cpp index 8cd2200f8a..c9633301fc 100644 --- a/unittest/c-library/test_library_commands.cpp +++ b/unittest/c-library/test_library_commands.cpp @@ -1,103 +1,121 @@ // unit tests for issuing command to a LAMMPS instance through the library interface -#include "library.h" #include "lammps.h" +#include "library.h" #include +#include "gmock/gmock.h" #include "gtest/gtest.h" -const char *demo_input[] = { - "region box block 0 $x 0 2 0 2", - "create_box 1 box", - "create_atoms 1 single 1.0 1.0 ${zpos}" }; -const char *cont_input[] = { - "create_atoms 1 single &", - "0.2 0.1 0.1" }; +#include "test_main.h" -class LAMMPS_commands : public ::testing::Test -{ +using ::testing::HasSubstr; +using ::testing::StartsWith; + +const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box", + "create_atoms 1 single 1.0 1.0 ${zpos}"}; +const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"}; + +class LAMMPS_commands : public ::testing::Test { protected: void *lmp; - LAMMPS_commands() {}; - ~LAMMPS_commands() override {}; + LAMMPS_commands(){}; + ~LAMMPS_commands() override{}; + + void SetUp() override + { + const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite", + "-var", "x", "2", "-var", "zpos", "1.5"}; - void SetUp() override { - const char *args[] = {"LAMMPS_test", - "-log", "none", - "-echo", "screen", - "-nocite", "-var","x","2", - "-var", "zpos", "1.5"}; char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); - lmp = lammps_open_no_mpi(argc, argv, NULL); + lmp = lammps_open_no_mpi(argc, argv, NULL); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS ("); + if (verbose) std::cout << output; + EXPECT_THAT(output, StartsWith("LAMMPS (")); } - void TearDown() override { + void TearDown() override + { ::testing::internal::CaptureStdout(); lammps_close(lmp); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; lmp = nullptr; } }; -TEST_F(LAMMPS_commands, from_file) { +TEST_F(LAMMPS_commands, from_file) +{ FILE *fp; const char demo_file[] = "in.test"; const char cont_file[] = "in.cont"; - fp = fopen(demo_file,"w"); - for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) { - fputs(demo_input[i],fp); - fputc('\n',fp); + fp = fopen(demo_file, "w"); + for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { + fputs(demo_input[i], fp); + fputc('\n', fp); } fclose(fp); - fp = fopen(cont_file,"w"); - for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) { - fputs(cont_input[i],fp); - fputc('\n',fp); + fp = fopen(cont_file, "w"); + for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { + fputs(cont_input[i], fp); + fputc('\n', fp); } fclose(fp); - EXPECT_EQ(lammps_get_natoms(lmp),0); - lammps_file(lmp,demo_file); - lammps_file(lmp,cont_file); - EXPECT_EQ(lammps_get_natoms(lmp),2); + EXPECT_EQ(lammps_get_natoms(lmp), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, demo_file); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 1); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, cont_file); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 2); unlink(demo_file); unlink(cont_file); }; -TEST_F(LAMMPS_commands, from_line) { - EXPECT_EQ(lammps_get_natoms(lmp),0); - for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) { - lammps_command(lmp,demo_input[i]); +TEST_F(LAMMPS_commands, from_line) +{ + EXPECT_EQ(lammps_get_natoms(lmp), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { + lammps_command(lmp, demo_input[i]); } - EXPECT_EQ(lammps_get_natoms(lmp),1); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 1); }; -TEST_F(LAMMPS_commands, from_list) { - EXPECT_EQ(lammps_get_natoms(lmp),0); - lammps_commands_list(lmp,sizeof(demo_input)/sizeof(char *),demo_input); - lammps_commands_list(lmp,sizeof(cont_input)/sizeof(char *),cont_input); - EXPECT_EQ(lammps_get_natoms(lmp),2); +TEST_F(LAMMPS_commands, from_list) +{ + EXPECT_EQ(lammps_get_natoms(lmp), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_commands_list(lmp, sizeof(demo_input) / sizeof(char *), demo_input); + lammps_commands_list(lmp, sizeof(cont_input) / sizeof(char *), cont_input); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 2); }; -TEST_F(LAMMPS_commands, from_string) { +TEST_F(LAMMPS_commands, from_string) +{ std::string cmds(""); - for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) { + for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { cmds += demo_input[i]; cmds += "\n"; } - for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) { + for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) { cmds += cont_input[i]; cmds += "\n"; } - EXPECT_EQ(lammps_get_natoms(lmp),0); - lammps_commands_string(lmp,cmds.c_str()); - EXPECT_EQ(lammps_get_natoms(lmp),2); + EXPECT_EQ(lammps_get_natoms(lmp), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_commands_string(lmp, cmds.c_str()); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_get_natoms(lmp), 2); }; diff --git a/unittest/c-library/test_library_open.cpp b/unittest/c-library/test_library_open.cpp index 16d25eca13..a948295017 100644 --- a/unittest/c-library/test_library_open.cpp +++ b/unittest/c-library/test_library_open.cpp @@ -1,21 +1,29 @@ -// unit tests for the LAMMPS base class +// unit tests creating LAMMPS instances via the library interface -#include "library.h" #include "lammps.h" +#include "library.h" +#include // for stdin, stdout #include -#include // for stdin, stdout #include +#include "gmock/gmock.h" #include "gtest/gtest.h" -TEST(lammps_open, null_args) { +#include "test_main.h" + +using ::testing::HasSubstr; +using ::testing::StartsWith; + +TEST(lammps_open, null_args) +{ ::testing::internal::CaptureStdout(); - void *handle = lammps_open(0,NULL, MPI_COMM_WORLD, NULL); + void *handle = lammps_open(0, NULL, MPI_COMM_WORLD, NULL); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS"); - int mpi_init=0; + EXPECT_THAT(output, StartsWith("LAMMPS (")); + if (verbose) std::cout << output; + int mpi_init = 0; MPI_Initialized(&mpi_init); - EXPECT_GT(mpi_init,0); + EXPECT_GT(mpi_init, 0); LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; EXPECT_EQ(lmp->world, MPI_COMM_WORLD); EXPECT_EQ(lmp->infile, stdin); @@ -24,25 +32,26 @@ TEST(lammps_open, null_args) { ::testing::internal::CaptureStdout(); lammps_close(handle); output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; } -TEST(lammps_open, with_args) { - const char *args[] = {"liblammps", - "-log", "none", - "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); +TEST(lammps_open, with_args) +{ + const char *args[] = {"liblammps", "-log", "none", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); // MPI is already initialized MPI_Comm mycomm; MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm); ::testing::internal::CaptureStdout(); void *alt_ptr; - void *handle = lammps_open(argc, argv, mycomm, &alt_ptr); + void *handle = lammps_open(argc, argv, mycomm, &alt_ptr); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS"); - EXPECT_EQ(handle,alt_ptr); + EXPECT_THAT(output, StartsWith("LAMMPS (")); + if (verbose) std::cout << output; + EXPECT_EQ(handle, alt_ptr); LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; // MPI STUBS uses no real communicators @@ -60,24 +69,24 @@ TEST(lammps_open, with_args) { ::testing::internal::CaptureStdout(); lammps_close(handle); output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; } -TEST(lammps_open, with_kokkos) { +TEST(lammps_open, with_kokkos) +{ if (!LAMMPS_NS::LAMMPS::is_installed_pkg("KOKKOS")) GTEST_SKIP(); - const char *args[] = {"liblammps", - "-k", "on", "t", "2", - "-sf", "kk", - "-log", "none" }; - char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + const char *args[] = {"liblammps", "-k", "on", "t", "2", "-sf", "kk", "-log", "none"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); void *alt_ptr; - void *handle = lammps_open(argc, argv, MPI_COMM_WORLD, &alt_ptr); + void *handle = lammps_open(argc, argv, MPI_COMM_WORLD, &alt_ptr); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS"); - EXPECT_EQ(handle,alt_ptr); + EXPECT_THAT(output, StartsWith("LAMMPS (")); + if (verbose) std::cout << output; + EXPECT_EQ(handle, alt_ptr); LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; EXPECT_EQ(lmp->world, MPI_COMM_WORLD); @@ -91,23 +100,22 @@ TEST(lammps_open, with_kokkos) { ::testing::internal::CaptureStdout(); lammps_close(handle); output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; } -TEST(lammps_open_no_mpi, no_screen) { - const char *args[] = {"liblammps", - "-log", "none", - "-screen", "none", - "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); +TEST(lammps_open_no_mpi, no_screen) +{ + const char *args[] = {"liblammps", "-log", "none", "-screen", "none", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); void *alt_ptr; - void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr); + void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.c_str(),""); - EXPECT_EQ(handle,alt_ptr); + EXPECT_STREQ(output.c_str(), ""); + EXPECT_EQ(handle, alt_ptr); LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; EXPECT_EQ(lmp->world, MPI_COMM_WORLD); @@ -125,22 +133,21 @@ TEST(lammps_open_no_mpi, no_screen) { EXPECT_STREQ(output.c_str(), ""); } -TEST(lammps_open_no_mpi, with_omp) { +TEST(lammps_open_no_mpi, with_omp) +{ if (!LAMMPS_NS::LAMMPS::is_installed_pkg("USER-OMP")) GTEST_SKIP(); - const char *args[] = {"liblammps", - "-pk", "omp", "2", "neigh", "no", - "-sf", "omp", - "-log", "none", - "-nocite"}; - char **argv = (char **)args; - int argc = sizeof(args)/sizeof(char *); + const char *args[] = {"liblammps", "-pk", "omp", "2", "neigh", "no", + "-sf", "omp", "-log", "none", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); ::testing::internal::CaptureStdout(); void *alt_ptr; - void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr); + void *handle = lammps_open_no_mpi(argc, argv, &alt_ptr); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS"); - EXPECT_EQ(handle,alt_ptr); + EXPECT_THAT(output, StartsWith("LAMMPS (")); + if (verbose) std::cout << output; + EXPECT_EQ(handle, alt_ptr); LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; EXPECT_EQ(lmp->world, MPI_COMM_WORLD); @@ -155,18 +162,21 @@ TEST(lammps_open_no_mpi, with_omp) { ::testing::internal::CaptureStdout(); lammps_close(handle); output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; } -TEST(lammps_open_fortran, no_args) { +TEST(lammps_open_fortran, no_args) +{ // MPI is already initialized MPI_Comm mycomm; MPI_Comm_split(MPI_COMM_WORLD, 0, 1, &mycomm); int fcomm = MPI_Comm_c2f(mycomm); ::testing::internal::CaptureStdout(); - void *handle = lammps_open_fortran(0, NULL, fcomm); + void *handle = lammps_open_fortran(0, NULL, fcomm); std::string output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS"); + EXPECT_THAT(output, StartsWith("LAMMPS (")); + if (verbose) std::cout << output; LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle; // MPI STUBS uses no real communicators @@ -182,5 +192,6 @@ TEST(lammps_open_fortran, no_args) { ::testing::internal::CaptureStdout(); lammps_close(handle); output = ::testing::internal::GetCapturedStdout(); - EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:"); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; } diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 030ff96795..b279a11fdb 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -1,7 +1,7 @@ // unit tests for checking and changing simulation properties through the library interface -#include "lammps.h" #include "library.h" +#include "lammps.h" #include #include "gmock/gmock.h" From 96a5585d65d3b66d66f3da6e48767c0bacfa35f0 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 17:12:11 -0400 Subject: [PATCH 22/43] use more const char pointers --- src/atom.cpp | 2 +- src/atom.h | 2 +- src/library.cpp | 15 ++++++++------- src/library.h | 12 ++++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/atom.cpp b/src/atom.cpp index 49ff262764..f28237cf74 100644 --- a/src/atom.cpp +++ b/src/atom.cpp @@ -2508,7 +2508,7 @@ length of the data area, and a short description. Typically the name of the pointer variable returned * \return pointer to the requested data cast to ``void *`` or NULL */ -void *Atom::extract(char *name) +void *Atom::extract(const char *name) { // -------------------------------------------------------------------- // 4th customization section: customize by adding new variable name diff --git a/src/atom.h b/src/atom.h index 21b9c06f8c..728d420596 100644 --- a/src/atom.h +++ b/src/atom.h @@ -331,7 +331,7 @@ class Atom : protected Pointers { virtual void sync_modify(ExecutionSpace, unsigned int, unsigned int) {} - void *extract(char *); + void *extract(const char *); inline int* get_map_array() {return map_array;}; inline int get_map_size() {return map_tag_max+1;}; diff --git a/src/library.cpp b/src/library.cpp index 4f02e95621..5773a677c1 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -69,7 +69,7 @@ using namespace LAMMPS_NS; #ifdef LAMMPS_EXCEPTIONS #define BEGIN_CAPTURE \ - Error * error = lmp->error; \ + Error *error = lmp->error; \ try #define END_CAPTURE \ @@ -807,7 +807,7 @@ recognized, the function returns -1. Please also see :cpp:func:`lammps_extract_ * \param keyword string with the name of the thermo keyword * \return value of the queried setting or -1 if unknown */ -int lammps_extract_setting(void * handle, char *keyword) +int lammps_extract_setting(void *handle, const char *keyword) { LAMMPS *lmp = (LAMMPS *) handle; @@ -1073,7 +1073,7 @@ to be either an ``int`` or an ``int64_t``. This is selected at * \return pointer (cast to ``void *``) to the location of the requested property. NULL if name is not known. */ -void *lammps_extract_global(void *handle, char *name) +void *lammps_extract_global(void *handle, const char *name) { LAMMPS *lmp = (LAMMPS *) handle; @@ -1165,7 +1165,7 @@ of the :cpp:func:`Atom::extract() ` function. * \return pointer (cast to ``void *``) to the location of the * requested data or ``NULL`` if not found. */ -void *lammps_extract_atom(void *handle, char *name) +void *lammps_extract_atom(void *handle, const char *name) { LAMMPS *lmp = (LAMMPS *) handle; return lmp->atom->extract(name); @@ -3792,7 +3792,7 @@ Valid categories are: *atom*\ , *integrate*\ , *minimize*\ , * \param name name of the style * \return 1 if included, 0 if not. */ -int lammps_has_style(void * handle, char * category, char * name) { +int lammps_has_style(void *handle, const char *category, const char *name) { LAMMPS *lmp = (LAMMPS *) handle; Info info(lmp); return info.has_style(category, name) ? 0 : 1; @@ -3813,7 +3813,7 @@ categories. * \param category category of styles * \return number of styles in category */ -int lammps_style_count(void * handle, char * category) { +int lammps_style_count(void *handle, const char *category) { LAMMPS *lmp = (LAMMPS *) handle; Info info(lmp); return info.get_available_styles(category).size(); @@ -3839,7 +3839,8 @@ Please see :cpp:func:`lammps_has_style` for a list of valid categories. * \param buf_size size of the provided string buffer * \return 1 if successful, otherwise 0 */ -int lammps_style_name(void* handle, char * category, int idx, char * buffer, int buf_size) { +int lammps_style_name(void *handle, const char *category, int idx, + const char *buffer, int buf_size) { LAMMPS *lmp = (LAMMPS *) handle; Info info(lmp); auto styles = info.get_available_styles(category); diff --git a/src/library.h b/src/library.h index ebbe1464df..1147cc4d9a 100644 --- a/src/library.h +++ b/src/library.h @@ -108,9 +108,9 @@ void lammps_extract_box(void *handle, double *boxlo, double *boxhi, void lammps_reset_box(void *handle, double *boxlo, double *boxhi, double xy, double yz, double xz); -int lammps_extract_setting(void *handle, char *keyword); -void *lammps_extract_global(void *handle, char *name); -void *lammps_extract_atom(void *handle, char *name); +int lammps_extract_setting(void *handle, const char *keyword); +void *lammps_extract_global(void *handle, const char *name); +void *lammps_extract_atom(void *handle, const char *name); #if !defined(LAMMPS_BIGBIG) int lammps_create_atoms(void *handle, int n, int *id, int *type, @@ -161,9 +161,9 @@ int lammps_config_has_jpeg_support(); int lammps_config_has_ffmpeg_support(); int lammps_config_has_exceptions(); -int lammps_has_style(void *, char *, char *); -int lammps_style_count(void *, char *); -int lammps_style_name(void *, char *, int, char *, int); +int lammps_has_style(void *, const char *, const char *); +int lammps_style_count(void *, const char *); +int lammps_style_name(void *, const char *, int, const char *, int); /* ---------------------------------------------------------------------- * Library functions for accessing neighbor lists From 2438f38afc50f9ee68bbae208b67b891ebbed069 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 17:12:21 -0400 Subject: [PATCH 23/43] skip test if atom style is missing --- unittest/c-library/test_library_properties.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index b279a11fdb..4d79b4feca 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -74,6 +74,7 @@ TEST_F(LAMMPS_properties, natoms) TEST_F(LAMMPS_properties, thermo) { + if (!lammps_has_style(lmp,"atom","full")) GTEST_SKIP(); std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); From cc86214fe2a49a82527a0498a0dd5ac1cb1ad7f2 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 13 Sep 2020 17:20:29 -0400 Subject: [PATCH 24/43] take back too eager change --- src/library.cpp | 2 +- src/library.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 5773a677c1..c6c34a529f 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3840,7 +3840,7 @@ Please see :cpp:func:`lammps_has_style` for a list of valid categories. * \return 1 if successful, otherwise 0 */ int lammps_style_name(void *handle, const char *category, int idx, - const char *buffer, int buf_size) { + char *buffer, int buf_size) { LAMMPS *lmp = (LAMMPS *) handle; Info info(lmp); auto styles = info.get_available_styles(category); diff --git a/src/library.h b/src/library.h index 1147cc4d9a..6c01be7867 100644 --- a/src/library.h +++ b/src/library.h @@ -163,7 +163,7 @@ int lammps_config_has_exceptions(); int lammps_has_style(void *, const char *, const char *); int lammps_style_count(void *, const char *); -int lammps_style_name(void *, const char *, int, const char *, int); +int lammps_style_name(void *, const char *, int, char *, int); /* ---------------------------------------------------------------------- * Library functions for accessing neighbor lists From 3655919c7c837a06a8731da9387d6da2ae1dae77 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 09:09:22 -0400 Subject: [PATCH 25/43] tweak minimize summary output format --- src/finish.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/finish.cpp b/src/finish.cpp index 3bfe3a7bbf..c48027feaf 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -202,12 +202,12 @@ void Finish::end(int flag) update->minimize->einitial, update->minimize->eprevious, update->minimize->efinal); - mesg += fmt::format(" Force two-norm initial, final = {} {}\n", + mesg += fmt::format(" Force two-norm initial, final = {:.8} {:.8}\n", update->minimize->fnorm2_init,update->minimize->fnorm2_final); - mesg += fmt::format(" Force max component initial, final = {} {}\n", + mesg += fmt::format(" Force max component initial, final = {:.8} {:.8}\n", update->minimize->fnorminf_init, update->minimize->fnorminf_final); - mesg += fmt::format(" Final line search alpha, max atom move = {} {}\n", + mesg += fmt::format(" Final line search alpha, max atom move = {:.8} {:.8}\n", update->minimize->alpha_final, update->minimize->alpha_final* update->minimize->fnorminf_final); From a5740d75cf055cc614e3d27ffff19a0cd3b96d7a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 09:27:49 -0400 Subject: [PATCH 26/43] add missing option --- doc/src/min_modify.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/min_modify.rst b/doc/src/min_modify.rst index e541571b7b..731d2ace62 100644 --- a/doc/src/min_modify.rst +++ b/doc/src/min_modify.rst @@ -19,7 +19,7 @@ Syntax max = maximum distance for line search to move (distance units) *line* value = *backtrack* or *quadratic* or *forcezero* or *spin_cubic* or *spin_none* backtrack,quadratic,forcezero,spin_cubic,spin_none = style of linesearch to use - *norm* value = *two* or *max* + *norm* value = *two* or *inf* or *max* two = Euclidean two-norm (length of 3N vector) inf = max force component across all 3-vectors max = max force norm across all 3-vectors From 155e7de8598f3e070a26a172eb14abb3c9d72850 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 12:16:53 -0400 Subject: [PATCH 27/43] fix bug in lammps_has_style() --- src/library.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index c6c34a529f..66a937148d 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3788,14 +3788,14 @@ Valid categories are: *atom*\ , *integrate*\ , *minimize*\ , \endverbatim * * \param handle pointer to a previously created LAMMPS instance cast to ``void *``. - * \param category category of the style - * \param name name of the style - * \return 1 if included, 0 if not. + * \param category category of the style + * \param name name of the style + * \return 1 if included, 0 if not. */ int lammps_has_style(void *handle, const char *category, const char *name) { LAMMPS *lmp = (LAMMPS *) handle; Info info(lmp); - return info.has_style(category, name) ? 0 : 1; + return info.has_style(category, name) ? 1 : 0; } /* ---------------------------------------------------------------------- */ From f4601235c934fdcca03e47ebcf77261e6d9bf62f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 12:17:24 -0400 Subject: [PATCH 28/43] add tests for lammps configuration introspection via library interface --- unittest/c-library/CMakeLists.txt | 19 +++++++ unittest/c-library/test_library_config.cpp | 61 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 unittest/c-library/test_library_config.cpp diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 7bbac4c430..704447643a 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -11,3 +11,22 @@ add_executable(test_library_properties test_library_properties.cpp test_main.cpp target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest::GMock) target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) add_test(LibraryProperties test_library_properties) + +set(PKG_COUNT 0) +foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) + if(PKG_${PKG}) + MATH(EXPR PKG_COUNT "${PKG_COUNT}+1") + endif() +endforeach() + +if(PKG_MANYBODY) + set(HAS_MANYBODY 1) +else() + set(HAS_MANYBODY 0) +endif() + +add_executable(test_library_config test_library_config.cpp test_main.cpp) +target_link_libraries(test_library_config PRIVATE lammps GTest::GTest GTest::GMock) +target_compile_definitions(test_library_config PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR} + -DNUM_LAMMPS_PACKAGES=${PKG_COUNT} -DLAMMPS_HAS_MANYBODY=${HAS_MANYBODY}) +add_test(LibraryConfig test_library_config) diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp new file mode 100644 index 0000000000..9356e3f035 --- /dev/null +++ b/unittest/c-library/test_library_config.cpp @@ -0,0 +1,61 @@ +// unit tests for checking LAMMPS configuration settings through the library interface + +#include "library.h" +#include "lammps.h" +#include + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "test_main.h" + +#define STRINGIFY(val) XSTR(val) +#define XSTR(val) #val + +using ::testing::HasSubstr; +using ::testing::StartsWith; + +class LAMMPS_config : public ::testing::Test { +protected: + void *lmp; + std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); + + LAMMPS_config(){}; + ~LAMMPS_config() override{}; + + void SetUp() override + { + const char *args[] = {"LAMMPS_test", "-log", "none", + "-echo", "screen", "-nocite", + "-var", "input_dir", STRINGIFY(TEST_INPUT_FOLDER)}; + + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + + ::testing::internal::CaptureStdout(); + lmp = lammps_open_no_mpi(argc, argv, NULL); + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + EXPECT_THAT(output, StartsWith("LAMMPS (")); + } + void TearDown() override + { + ::testing::internal::CaptureStdout(); + lammps_close(lmp); + std::string output = ::testing::internal::GetCapturedStdout(); + EXPECT_THAT(output, HasSubstr("Total wall time:")); + if (verbose) std::cout << output; + lmp = nullptr; + } +}; + +TEST(LAMMPS_config, package_count) +{ + EXPECT_EQ(lammps_config_package_count(), NUM_LAMMPS_PACKAGES); +}; + +TEST(LAMMPS_config, has_package) +{ + EXPECT_EQ(lammps_config_has_package("MANYBODY"), LAMMPS_HAS_MANYBODY); +}; + From ac040dc85fabce789ef24fa924d73bcf88756240 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 12:17:49 -0400 Subject: [PATCH 29/43] update prototype to allow constant strings --- src/library.cpp | 2 +- src/library.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library.cpp b/src/library.cpp index 66a937148d..6c64e56bc2 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3724,7 +3724,7 @@ specific :doc:`LAMMPS package ` provided as argument. * \param name string with the name of the package * \return 1 if included, 0 if not. */ -int lammps_config_has_package(char * name) { +int lammps_config_has_package(const char *name) { return Info::has_package(name) ? 1 : 0; } diff --git a/src/library.h b/src/library.h index 6c01be7867..0c6ca184e5 100644 --- a/src/library.h +++ b/src/library.h @@ -152,7 +152,7 @@ void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *); * ---------------------------------------------------------------------- */ int lammps_config_has_mpi_support(); -int lammps_config_has_package(char *); +int lammps_config_has_package(const char *); int lammps_config_package_count(); int lammps_config_package_name(int, char *, int); int lammps_config_has_gzip_support(); From f5e98045576593076e3e81b8d4bfe3efdcb86fe4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 14:24:34 -0400 Subject: [PATCH 30/43] cosmetic --- src/library.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library.cpp b/src/library.cpp index 6c64e56bc2..98bd99ee77 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -3764,7 +3764,7 @@ the function returns 0 and *buffer* is set to an empty string, otherwise 1; * \param buf_size size of the provided string buffer * \return 1 if successful, otherwise 0 */ -int lammps_config_package_name(int idx, char * buffer, int buf_size) { +int lammps_config_package_name(int idx, char *buffer, int buf_size) { int maxidx = lammps_config_package_count(); if ((idx < 0) || (idx >= maxidx)) { buffer[0] = '\0'; From b4558124344d756946d79ae0949a5355e1574b01 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 14:25:17 -0400 Subject: [PATCH 31/43] more tests for properties and configuration --- unittest/c-library/test_library_config.cpp | 70 +++++++++++++++++-- .../c-library/test_library_properties.cpp | 49 ++++++++++--- 2 files changed, 104 insertions(+), 15 deletions(-) diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index 9356e3f035..b2e0d241b6 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -1,7 +1,7 @@ // unit tests for checking LAMMPS configuration settings through the library interface -#include "library.h" #include "lammps.h" +#include "library.h" #include #include "gmock/gmock.h" @@ -14,14 +14,15 @@ using ::testing::HasSubstr; using ::testing::StartsWith; +using ::testing::StrEq; -class LAMMPS_config : public ::testing::Test { +class LibraryConfig : public ::testing::Test { protected: void *lmp; std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); - LAMMPS_config(){}; - ~LAMMPS_config() override{}; + LibraryConfig(){}; + ~LibraryConfig() override{}; void SetUp() override { @@ -49,13 +50,70 @@ protected: } }; -TEST(LAMMPS_config, package_count) +TEST(LAMMPSConfig, package_count) { EXPECT_EQ(lammps_config_package_count(), NUM_LAMMPS_PACKAGES); }; -TEST(LAMMPS_config, has_package) +TEST(LAMMPSConfig, has_package) { EXPECT_EQ(lammps_config_has_package("MANYBODY"), LAMMPS_HAS_MANYBODY); }; +TEST(LAMMPSConfig, package_name) +{ + char buf[128]; + int numpkgs = lammps_config_package_count(); + if (numpkgs > 0) { + EXPECT_EQ(lammps_config_package_name(0, buf, 128), 1); + EXPECT_EQ(lammps_config_package_name(numpkgs + 10, buf, 128), 0); + EXPECT_THAT(buf, StrEq("")); + } else { + EXPECT_EQ(lammps_config_package_name(0, buf, 128), 1); + EXPECT_THAT(buf, StrEq("")); + } +}; + +TEST_F(LibraryConfig, has_style) +{ + EXPECT_EQ(lammps_has_style(lmp, "atom", "atomic"), 1); + EXPECT_EQ(lammps_has_style(lmp, "compute", "temp"), 1); + EXPECT_EQ(lammps_has_style(lmp, "fix", "nve"), 1); + EXPECT_EQ(lammps_has_style(lmp, "pair", "lj/cut"), 1); + EXPECT_EQ(lammps_has_style(lmp, "bond", "zero"), 1); + EXPECT_EQ(lammps_has_style(lmp, "dump", "custom"), 1); + EXPECT_EQ(lammps_has_style(lmp, "region", "sphere"), 1); + EXPECT_EQ(lammps_has_style(lmp, "xxxxx", "lj/cut"), 0); + EXPECT_EQ(lammps_has_style(lmp, "pair", "xxxxxx"), 0); +#if LAMMPS_HAS_MANYBODY + EXPECT_EQ(lammps_has_style(lmp, "pair", "sw"), 1); +#else + EXPECT_EQ(lammps_has_style(lmp, "pair", "sw"), 0); +#endif +}; + +TEST_F(LibraryConfig, style_count) +{ + EXPECT_GT(lammps_style_count(lmp, "atom"), 1); + EXPECT_GT(lammps_style_count(lmp, "bond"), 1); + EXPECT_GT(lammps_style_count(lmp, "angle"), 1); + EXPECT_GT(lammps_style_count(lmp, "dihedral"), 1); + EXPECT_GT(lammps_style_count(lmp, "improper"), 1); + EXPECT_GT(lammps_style_count(lmp, "pair"), 1); + EXPECT_GT(lammps_style_count(lmp, "kspace"), 1); + EXPECT_GT(lammps_style_count(lmp, "compute"), 1); + EXPECT_GT(lammps_style_count(lmp, "fix"), 1); + EXPECT_GT(lammps_style_count(lmp, "region"), 1); + EXPECT_GT(lammps_style_count(lmp, "dump"), 1); + EXPECT_GT(lammps_style_count(lmp, "integrate"), 1); + EXPECT_GT(lammps_style_count(lmp, "minimize"), 1); +}; + +TEST_F(LibraryConfig, style_name) +{ + char buf[128]; + int numstyles = lammps_style_count(lmp, "atom"); + EXPECT_EQ(lammps_style_name(lmp, "atom", 0, buf, 128), 1); + EXPECT_EQ(lammps_style_name(lmp, "atom", numstyles + 10, buf, 128), 0); + EXPECT_THAT(buf, StrEq("")); +}; diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 4d79b4feca..a29feb6988 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -1,7 +1,7 @@ // unit tests for checking and changing simulation properties through the library interface -#include "library.h" #include "lammps.h" +#include "library.h" #include #include "gmock/gmock.h" @@ -15,13 +15,13 @@ using ::testing::HasSubstr; using ::testing::StartsWith; -class LAMMPS_properties : public ::testing::Test { +class LibraryProperties : public ::testing::Test { protected: void *lmp; std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER); - LAMMPS_properties(){}; - ~LAMMPS_properties() override{}; + LibraryProperties(){}; + ~LibraryProperties() override{}; void SetUp() override { @@ -49,12 +49,12 @@ protected: } }; -TEST_F(LAMMPS_properties, version) +TEST_F(LibraryProperties, version) { EXPECT_GE(20200824, lammps_version(lmp)); }; -TEST_F(LAMMPS_properties, get_mpi_comm) +TEST_F(LibraryProperties, get_mpi_comm) { int f_comm = lammps_get_mpi_comm(lmp); if (lammps_config_has_mpi_support()) @@ -63,8 +63,9 @@ TEST_F(LAMMPS_properties, get_mpi_comm) EXPECT_EQ(f_comm, -1); }; -TEST_F(LAMMPS_properties, natoms) +TEST_F(LibraryProperties, natoms) { + if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); @@ -72,9 +73,9 @@ TEST_F(LAMMPS_properties, natoms) EXPECT_EQ(lammps_get_natoms(lmp), 29); }; -TEST_F(LAMMPS_properties, thermo) +TEST_F(LibraryProperties, thermo) { - if (!lammps_has_style(lmp,"atom","full")) GTEST_SKIP(); + if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; if (!verbose) ::testing::internal::CaptureStdout(); lammps_file(lmp, input.c_str()); @@ -86,3 +87,33 @@ TEST_F(LAMMPS_properties, thermo) EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695); EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0); }; + +TEST_F(LibraryProperties, box) +{ + if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP(); + std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, input.c_str()); + lammps_command(lmp, "run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + double boxlo[3], boxhi[3], xy, yz, xz; + int pflags[3], boxflag; + lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); + EXPECT_DOUBLE_EQ(boxlo[0], -6.024572); + EXPECT_DOUBLE_EQ(boxlo[1], -7.692866); + EXPECT_DOUBLE_EQ(boxlo[2], -8.086924); + EXPECT_DOUBLE_EQ(boxhi[0], 8.975428); + EXPECT_DOUBLE_EQ(boxhi[1], 7.307134); + EXPECT_DOUBLE_EQ(boxhi[2], 6.913076); + EXPECT_DOUBLE_EQ(xy, 0.0); + EXPECT_DOUBLE_EQ(yz, 0.0); + EXPECT_DOUBLE_EQ(xz, 0.0); + EXPECT_EQ(pflags[0], 1); + EXPECT_EQ(pflags[1], 1); + EXPECT_EQ(pflags[2], 1); + EXPECT_EQ(boxflag, 0); + + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0); +}; From 4185608e9249de7a7283e930979ac50bbfb9951a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 14:56:56 -0400 Subject: [PATCH 32/43] complete testing for LAMMPS configuration queries --- unittest/c-library/CMakeLists.txt | 22 +++++++++++++++++-- unittest/c-library/test_library_config.cpp | 25 ++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index 704447643a..c0af60099e 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -12,21 +12,39 @@ target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest: target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) add_test(LibraryProperties test_library_properties) +set(TEST_CONFIG_DEFS -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) set(PKG_COUNT 0) foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) if(PKG_${PKG}) MATH(EXPR PKG_COUNT "${PKG_COUNT}+1") endif() endforeach() +list(APPEND TEST_CONFIG_DEFS -DNUM_LAMMPS_PACKAGES=${PKG_COUNT}) if(PKG_MANYBODY) set(HAS_MANYBODY 1) else() set(HAS_MANYBODY 0) endif() +list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_MANYBODY=${HAS_MANYBODY}) + +if(BUILD_MPI) + set(HAS_MPI 1) +else() + set(HAS_MPI 0) +endif() +list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_MPI=${HAS_MPI}) + +foreach(WITH "JPEG" "PNG" "GZIP" "FFMPEG") + if(WITH_${WITH}) + set(HAS_${WITH} 1) + else() + set(HAS_${WITH} 0) + endif() + list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_${WITH}=${HAS_${WITH}}) +endforeach() add_executable(test_library_config test_library_config.cpp test_main.cpp) target_link_libraries(test_library_config PRIVATE lammps GTest::GTest GTest::GMock) -target_compile_definitions(test_library_config PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR} - -DNUM_LAMMPS_PACKAGES=${PKG_COUNT} -DLAMMPS_HAS_MANYBODY=${HAS_MANYBODY}) +target_compile_definitions(test_library_config PRIVATE ${TEST_CONFIG_DEFS}) add_test(LibraryConfig test_library_config) diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index b2e0d241b6..064ce83836 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -117,3 +117,28 @@ TEST_F(LibraryConfig, style_name) EXPECT_EQ(lammps_style_name(lmp, "atom", numstyles + 10, buf, 128), 0); EXPECT_THAT(buf, StrEq("")); }; + +TEST(LAMMPSConfig, mpi_support) +{ + EXPECT_EQ(lammps_config_has_mpi_support(), LAMMPS_HAS_MPI); +}; + +TEST(LAMMPSConfig, png_support) +{ + EXPECT_EQ(lammps_config_has_png_support(), LAMMPS_HAS_PNG); +}; + +TEST(LAMMPSConfig, jpeg_support) +{ + EXPECT_EQ(lammps_config_has_jpeg_support(), LAMMPS_HAS_JPEG); +}; + +TEST(LAMMPSConfig, gzip_support) +{ + EXPECT_EQ(lammps_config_has_gzip_support(), LAMMPS_HAS_GZIP); +}; + +TEST(LAMMPSConfig, ffmpeg_support) +{ + EXPECT_EQ(lammps_config_has_ffmpeg_support(), LAMMPS_HAS_FFMPEG); +}; From a1b2f821079a515ea8d35a4bc1193910abd136dc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:01:28 -0400 Subject: [PATCH 33/43] test for exceptions add example --- doc/src/pg_lib_config.rst | 38 ++++++++++++++++++++-- src/library.cpp | 6 ++-- unittest/c-library/CMakeLists.txt | 7 ++++ unittest/c-library/test_library_config.cpp | 5 +++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/doc/src/pg_lib_config.rst b/doc/src/pg_lib_config.rst index 9576e31dcd..f0ff7cbc43 100644 --- a/doc/src/pg_lib_config.rst +++ b/doc/src/pg_lib_config.rst @@ -1,9 +1,41 @@ Retrieving LAMMPS configuration information =========================================== -The following library functions can be used to query the -LAMMPS library about compile time settings and included -packages and styles. +The following library functions can be used to query the LAMMPS library +about compile time settings and included packages and styles. This +enables programs that use the library interface to run LAMMPS +simulations to determine, whether the linked LAMMPS library is compatible +with the requirements of the application without crashing during the +LAMMPS functions (e.g. due to missing pair styles from packages) or to +choose between different options (e.g. whether to use ``lj/cut``, +``lj/cut/opt``, ``lj/cut/omp`` or ``lj/cut/intel``). Most of the +functions can be called directly without first creating a LAMMPS +instance. While crashes within LAMMPS may be recovered from through +enabling :ref:`exceptions `, avoiding them proactively is +a safer approach. + +.. code-block:: C + :caption: Handle errors using a LAMMPS library with exceptions + + #include "library.h" + #include + + int main(int argc, char **argv) + { + void *handle; + + handle = lammps_open_no_mpi(0, NULL, NULL); + lammps_file(handle, "in.missing"); + if (lammps_has_error(handle)) { + char errmsg[256]; + int errtype; + errtype = lammps_get_last_error_message(handle, errmsg, 256); + fprintf(stderr, "LAMMPS failed with error: %s\n", errmsg); + return 1; + } + lammps_close(handle); + return 0; + } ----------------------- diff --git a/src/library.cpp b/src/library.cpp index 98bd99ee77..4a1c596fa4 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -4266,10 +4266,10 @@ the failing MPI ranks to send messages. * \param buf_size size of the provided string buffer * \return 1 when all ranks had the error, 1 on a single rank error. */ -int lammps_get_last_error_message(void *handle, char * buffer, int buf_size) { +int lammps_get_last_error_message(void *handle, char *buffer, int buf_size) { #ifdef LAMMPS_EXCEPTIONS - LAMMPS * lmp = (LAMMPS *) handle; - Error * error = lmp->error; + LAMMPS *lmp = (LAMMPS *) handle; + Error *error = lmp->error; if(!error->get_last_error().empty()) { int error_type = error->get_last_error_type(); diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index c0af60099e..ee4916427a 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -35,6 +35,13 @@ else() endif() list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_MPI=${HAS_MPI}) +if(LAMMPS_EXCEPTION) + set(HAS_EXCEPTIONS 1) +else() + set(HAS_EXCEPTIONS 0) +endif() +list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_EXCEPTIONS=${HAS_EXCEPTIONS}) + foreach(WITH "JPEG" "PNG" "GZIP" "FFMPEG") if(WITH_${WITH}) set(HAS_${WITH} 1) diff --git a/unittest/c-library/test_library_config.cpp b/unittest/c-library/test_library_config.cpp index 064ce83836..0e81683159 100644 --- a/unittest/c-library/test_library_config.cpp +++ b/unittest/c-library/test_library_config.cpp @@ -118,6 +118,11 @@ TEST_F(LibraryConfig, style_name) EXPECT_THAT(buf, StrEq("")); }; +TEST(LAMMPSConfig, exceptions) +{ + EXPECT_EQ(lammps_config_has_exceptions(), LAMMPS_HAS_EXCEPTIONS); +}; + TEST(LAMMPSConfig, mpi_support) { EXPECT_EQ(lammps_config_has_mpi_support(), LAMMPS_HAS_MPI); From f70717710e40a85d35775f05ba1ac5f7d7711971 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:07:09 -0400 Subject: [PATCH 34/43] fix for zstd support. add styles to list at top and document .zst extension requirement --- doc/src/dump.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/src/dump.rst b/doc/src/dump.rst index 3f6a8812c3..c94d9a8007 100644 --- a/doc/src/dump.rst +++ b/doc/src/dump.rst @@ -36,8 +36,7 @@ Syntax * ID = user-assigned name for the dump * group-ID = ID of the group of atoms to be dumped -* style = *atom* or *atom/gz* or *atom/mpiio* or *cfg* or *cfg/gz* or - *cfg/mpiio* or *custom* or *custom/gz* or *custom/mpiio* or *dcd* or *h5md* or *image* or *local* or *local/gz* or *molfile* or *movie* or *netcdf* or *netcdf/mpiio* or *vtk* or *xtc* or *xyz* or *xyz/gz* or *xyz/mpiio* +* style = *atom* or *atom/gz* or *atom/zstd or *atom/mpiio* or *cfg* or *cfg/gz* or *cfg/zstd* or *cfg/mpiio* or *custom* or *custom/gz* or *custom/zstd* or *custom/mpiio* or *dcd* or *h5md* or *image* or *local* or *local/gz* or *local/zstd* or *molfile* or *movie* or *netcdf* or *netcdf/mpiio* or *vtk* or *xtc* or *xyz* or *xyz/gz* or *xyz/zstd* or *xyz/mpiio* * N = dump every this many timesteps * file = name of file to write dump info to * args = list of arguments for a particular style @@ -138,7 +137,7 @@ Examples dump 2 subgroup atom 50 dump.run.mpiio.bin dump 4a all custom 100 dump.myforce.* id type x y vx fx dump 4b flow custom 100 dump.%.myforce id type c_myF[3] v_ke - dump 4b flow custom 100 dump.%.myforce id type c_myF[\*] v_ke + dump 4b flow custom 100 dump.%.myforce id type c_myF[*] v_ke dump 2 inner cfg 10 dump.snap.*.cfg mass type xs ys zs vx vy vz dump snap all cfg 100 dump.config.*.cfg mass type xs ys zs id type c_Stress[2] dump 1 all xtc 1000 file.xtc @@ -204,8 +203,9 @@ of the required filename suffix. Similarly, the *atom/zstd*\ , *cfg/zstd*\ , *custom/zstd*\ , *local/zstd*, and *xyz/zstd* styles are identical to the gz styles, but use the Zstd -compression library instead. See the :doc:`dump_modify ` doc -page for details on how to control the compression level in both variants. +compression library instead and require the ".zst" suffix. See the +:doc:`dump_modify ` doc page for details on how to control +the compression level in both variants. As explained below, the *atom/mpiio*\ , *cfg/mpiio*\ , *custom/mpiio*\ , and *xyz/mpiio* styles are identical in command syntax and in the format From b1e0990c46a91be3d98702e2ca0c249d0f9d1fbe Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:11:27 -0400 Subject: [PATCH 35/43] update lammps config settings calls example --- doc/src/pg_lib_config.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/doc/src/pg_lib_config.rst b/doc/src/pg_lib_config.rst index f0ff7cbc43..d33afe3b5b 100644 --- a/doc/src/pg_lib_config.rst +++ b/doc/src/pg_lib_config.rst @@ -15,7 +15,7 @@ enabling :ref:`exceptions `, avoiding them proactively is a safer approach. .. code-block:: C - :caption: Handle errors using a LAMMPS library with exceptions + :caption: Example for using configuration settings functions #include "library.h" #include @@ -33,6 +33,16 @@ a safer approach. fprintf(stderr, "LAMMPS failed with error: %s\n", errmsg); return 1; } + /* write compressed dump file depending on available of options */ + if (lammps_has_style(handle, "dump", "atom/zstd")) { + lammps_command(handle, "dump d1 all atom/zstd 100 dump.zst"); + } else if (lammps_has_style(handle, "dump", "atom/gz")) { + lammps_command(handle, "dump d1 all atom/gz 100 dump.gz"); + } else if (lammps_config_has_gzip_support()) { + lammps_command(handle, "dump d1 all atom 100 dump.gz"); + } else { + lammps_command(handle, "dump d1 all atom 100 dump"); + } lammps_close(handle); return 0; } From 5634dd4394b507df889d6c56b05178a4829bc67f Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:15:53 -0400 Subject: [PATCH 36/43] correct formatting of examples --- doc/src/compute_reduce.rst | 2 +- doc/src/compute_stress_mop.rst | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/compute_reduce.rst b/doc/src/compute_reduce.rst index c7815305c0..660ef87042 100644 --- a/doc/src/compute_reduce.rst +++ b/doc/src/compute_reduce.rst @@ -53,7 +53,7 @@ Examples compute 1 all reduce sum c_force compute 1 all reduce/region subbox sum c_force compute 2 all reduce min c_press[2] f_ave v_myKE - compute 2 all reduce min c_press[\*] f_ave v_myKE + compute 2 all reduce min c_press[*] f_ave v_myKE compute 3 fluid reduce max c_index[1] c_index[2] c_dist replace 1 3 replace 2 3 Description diff --git a/doc/src/compute_stress_mop.rst b/doc/src/compute_stress_mop.rst index f164a33c26..d68bafa48b 100644 --- a/doc/src/compute_stress_mop.rst +++ b/doc/src/compute_stress_mop.rst @@ -28,14 +28,16 @@ Syntax origin = *lower* or *center* or *upper* or coordinate value (distance units) is the position of the first plane delta = value (distance units) is the distance between planes +.. code-block:: LAMMPS + compute 1 all stress/mop x lower total compute 1 liquid stress/mop z 0.0 kin conf - fix 1 all ave/time 10 1000 10000 c_1[\*] file mop.time + fix 1 all ave/time 10 1000 10000 c_1[*] file mop.time fix 1 all ave/time 10 1000 10000 c_1[2] file mop.time compute 1 all stress/mop/profile x lower 0.1 total compute 1 liquid stress/mop/profile z 0.0 0.25 kin conf - fix 1 all ave/time 500 20 10000 c_1[\*] ave running overwrite file mopp.time mode vector + fix 1 all ave/time 500 20 10000 c_1[*] ave running overwrite file mopp.time mode vector Description """"""""""" From df9f0e244b15019181182e1c9e7c702071751a41 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:18:14 -0400 Subject: [PATCH 37/43] add false positive --- doc/utils/sphinx-config/false_positives.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index b13d7a3ff3..5046316ec8 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -3455,6 +3455,7 @@ zmin zmq zN zs +zst zsu zu zx From 93bd851ab02d7e7d832f7e21e924620857d22b12 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 17:39:31 -0400 Subject: [PATCH 38/43] fix typo --- unittest/c-library/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index ee4916427a..a2e2bcde64 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -35,7 +35,7 @@ else() endif() list(APPEND TEST_CONFIG_DEFS -DLAMMPS_HAS_MPI=${HAS_MPI}) -if(LAMMPS_EXCEPTION) +if(LAMMPS_EXCEPTIONS) set(HAS_EXCEPTIONS 1) else() set(HAS_EXCEPTIONS 0) From 5c7f67201be78b5169a3a93b36f577b12315df2a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 20:27:10 -0400 Subject: [PATCH 39/43] make naming more consistent --- unittest/c-library/test_library_commands.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/unittest/c-library/test_library_commands.cpp b/unittest/c-library/test_library_commands.cpp index c9633301fc..d9c750975d 100644 --- a/unittest/c-library/test_library_commands.cpp +++ b/unittest/c-library/test_library_commands.cpp @@ -16,11 +16,11 @@ const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 "create_atoms 1 single 1.0 1.0 ${zpos}"}; const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"}; -class LAMMPS_commands : public ::testing::Test { +class LibraryCommands : public ::testing::Test { protected: void *lmp; - LAMMPS_commands(){}; - ~LAMMPS_commands() override{}; + LibraryCommands(){}; + ~LibraryCommands() override{}; void SetUp() override { @@ -47,7 +47,7 @@ protected: } }; -TEST_F(LAMMPS_commands, from_file) +TEST_F(LibraryCommands, from_file) { FILE *fp; const char demo_file[] = "in.test"; @@ -80,7 +80,7 @@ TEST_F(LAMMPS_commands, from_file) unlink(cont_file); }; -TEST_F(LAMMPS_commands, from_line) +TEST_F(LibraryCommands, from_line) { EXPECT_EQ(lammps_get_natoms(lmp), 0); if (!verbose) ::testing::internal::CaptureStdout(); @@ -91,7 +91,7 @@ TEST_F(LAMMPS_commands, from_line) EXPECT_EQ(lammps_get_natoms(lmp), 1); }; -TEST_F(LAMMPS_commands, from_list) +TEST_F(LibraryCommands, from_list) { EXPECT_EQ(lammps_get_natoms(lmp), 0); if (!verbose) ::testing::internal::CaptureStdout(); @@ -101,7 +101,7 @@ TEST_F(LAMMPS_commands, from_list) EXPECT_EQ(lammps_get_natoms(lmp), 2); }; -TEST_F(LAMMPS_commands, from_string) +TEST_F(LibraryCommands, from_string) { std::string cmds(""); From 1e54a9fcf1f4bb4271b854b6b30521f5414947b4 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 20:27:29 -0400 Subject: [PATCH 40/43] complete tests for extracting and resetting the box --- .../c-library/test_library_properties.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index a29feb6988..1dfbc99f19 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -112,8 +112,51 @@ TEST_F(LibraryProperties, box) EXPECT_EQ(pflags[1], 1); EXPECT_EQ(pflags[2], 1); EXPECT_EQ(boxflag, 0); - EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0); EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695); EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "change_box all boundary p p f triclinic xy final 0.5"); + lammps_command(lmp, "fix box all box/relax x 0.0 y 0.0"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); + EXPECT_DOUBLE_EQ(boxlo[0], -6.024572); + EXPECT_DOUBLE_EQ(boxlo[1], -7.692866); + EXPECT_DOUBLE_EQ(boxlo[2], -8.086924); + EXPECT_DOUBLE_EQ(boxhi[0], 8.975428); + EXPECT_DOUBLE_EQ(boxhi[1], 7.307134); + EXPECT_DOUBLE_EQ(boxhi[2], 6.913076); + EXPECT_DOUBLE_EQ(xy, 0.5); + EXPECT_DOUBLE_EQ(yz, 0.0); + EXPECT_DOUBLE_EQ(xz, 0.0); + EXPECT_EQ(pflags[0], 1); + EXPECT_EQ(pflags[1], 1); + EXPECT_EQ(pflags[2], 0); + EXPECT_EQ(boxflag, 1); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellbeta"), 90.0); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellgamma"), 88.090847567003621); + + boxlo[0] = -6.1; + boxhi[1] = 7.3; + xy = 0.1; + lammps_reset_box(lmp, boxlo, boxhi, xy, yz, xz); + lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); + EXPECT_DOUBLE_EQ(boxlo[0], -6.1); + EXPECT_DOUBLE_EQ(boxlo[1], -7.692866); + EXPECT_DOUBLE_EQ(boxlo[2], -8.086924); + EXPECT_DOUBLE_EQ(boxhi[0], 8.975428); + EXPECT_DOUBLE_EQ(boxhi[1], 7.3); + EXPECT_DOUBLE_EQ(boxhi[2], 6.913076); + EXPECT_DOUBLE_EQ(xy, 0.1); + EXPECT_DOUBLE_EQ(yz, 0.0); + EXPECT_DOUBLE_EQ(xz, 0.0); + EXPECT_EQ(pflags[0], 1); + EXPECT_EQ(pflags[1], 1); + EXPECT_EQ(pflags[2], 0); + EXPECT_EQ(boxflag, 1); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3390.3580784497199); + EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellgamma"), 89.61785205109274); }; From d27d4912af06a9d0106e99edc77910060d09f1da Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 20:53:19 -0400 Subject: [PATCH 41/43] test lammps_extract_settings() --- unittest/c-library/CMakeLists.txt | 2 +- .../c-library/test_library_properties.cpp | 58 ++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/unittest/c-library/CMakeLists.txt b/unittest/c-library/CMakeLists.txt index a2e2bcde64..fe70cb1584 100644 --- a/unittest/c-library/CMakeLists.txt +++ b/unittest/c-library/CMakeLists.txt @@ -12,7 +12,7 @@ target_link_libraries(test_library_properties PRIVATE lammps GTest::GTest GTest: target_compile_definitions(test_library_properties PRIVATE -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) add_test(LibraryProperties test_library_properties) -set(TEST_CONFIG_DEFS -DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR}) +set(TEST_CONFIG_DEFS "-DTEST_INPUT_FOLDER=${CMAKE_CURRENT_SOURCE_DIR};-DLAMMPS_${LAMMPS_SIZES}") set(PKG_COUNT 0) foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) if(PKG_${PKG}) diff --git a/unittest/c-library/test_library_properties.cpp b/unittest/c-library/test_library_properties.cpp index 1dfbc99f19..3b1393e5c6 100644 --- a/unittest/c-library/test_library_properties.cpp +++ b/unittest/c-library/test_library_properties.cpp @@ -140,8 +140,8 @@ TEST_F(LibraryProperties, box) EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellgamma"), 88.090847567003621); boxlo[0] = -6.1; - boxhi[1] = 7.3; - xy = 0.1; + boxhi[1] = 7.3; + xy = 0.1; lammps_reset_box(lmp, boxlo, boxhi, xy, yz, xz); lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag); EXPECT_DOUBLE_EQ(boxlo[0], -6.1); @@ -160,3 +160,57 @@ TEST_F(LibraryProperties, box) EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3390.3580784497199); EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellgamma"), 89.61785205109274); }; +TEST_F(LibraryProperties, setting) +{ +#if defined(LAMMPS_SMALLSMALL) + EXPECT_EQ(lammps_extract_setting(lmp, "bigint"), 4); +#else + EXPECT_EQ(lammps_extract_setting(lmp, "bigint"), 8); +#endif +#if defined(LAMMPS_BIGBIG) + EXPECT_EQ(lammps_extract_setting(lmp, "tagint"), 8); + EXPECT_EQ(lammps_extract_setting(lmp, "imageint"), 8); +#else + EXPECT_EQ(lammps_extract_setting(lmp, "tagint"), 4); + EXPECT_EQ(lammps_extract_setting(lmp, "imageint"), 4); +#endif + + EXPECT_EQ(lammps_extract_setting(lmp, "box_exist"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "dimension 2"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "dimension"), 2); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "dimension 3"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "molecule_flag"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "q_flag"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "mu_flag"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "rmass_flag"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "UNKNOWN"), -1); + + if (lammps_has_style(lmp, "atom", "full")) { + std::string input = INPUT_DIR + PATH_SEP + "in.fourmol"; + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_file(lmp, input.c_str()); + lammps_command(lmp, "run 2 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "triclinic"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "box_exist"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "dimension"), 3); + EXPECT_EQ(lammps_extract_setting(lmp, "nlocal"), 29); + EXPECT_EQ(lammps_extract_setting(lmp, "nghost"), 518); + EXPECT_EQ(lammps_extract_setting(lmp, "nall"), 547); + EXPECT_EQ(lammps_extract_setting(lmp, "nmax"), 16384); + EXPECT_EQ(lammps_extract_setting(lmp, "molecule_flag"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "q_flag"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "mu_flag"), 0); + EXPECT_EQ(lammps_extract_setting(lmp, "rmass_flag"), 0); + if (!verbose) ::testing::internal::CaptureStdout(); + lammps_command(lmp, "change_box all triclinic"); + lammps_command(lmp, "fix rmass all property/atom rmass ghost yes"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + EXPECT_EQ(lammps_extract_setting(lmp, "triclinic"), 1); + EXPECT_EQ(lammps_extract_setting(lmp, "rmass_flag"), 1); + } +}; From 39681acfa40758c1c6cc328fb7dad009f00af10c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 14 Sep 2020 21:03:39 -0400 Subject: [PATCH 42/43] add cross reference --- src/library.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/library.cpp b/src/library.cpp index 4a1c596fa4..7abc0df38a 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -865,7 +865,8 @@ Please also see :cpp:func:`lammps_extract_setting`, This table lists the supported names, their data types, length of the data area, and a short description. The ``bigint`` type may be defined to be either an ``int`` or an ``int64_t``. This is selected at -:ref:`compile time `. +:ref:`compile time ` and can be queried through calling +:cpp:func:`lammps_extract_setting`. .. list-table:: :header-rows: 1 From 2f3c73217b0a78e23f843a984cbb6f67d02f8993 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 15 Sep 2020 10:50:44 -0400 Subject: [PATCH 43/43] detect if dt has been changed from default and print warning if reset by units command --- src/USER-EFF/pair_eff_cut.cpp | 2 +- src/USER-SMD/fix_smd_adjust_dt.cpp | 1 + src/fix_dt_reset.cpp | 1 + src/input.cpp | 1 + src/update.cpp | 31 ++++++++++++++++++++++-------- src/update.h | 1 + 6 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/USER-EFF/pair_eff_cut.cpp b/src/USER-EFF/pair_eff_cut.cpp index f4e7af6584..72281c4a50 100644 --- a/src/USER-EFF/pair_eff_cut.cpp +++ b/src/USER-EFF/pair_eff_cut.cpp @@ -869,7 +869,7 @@ void PairEffCut::init_style() // make sure to use the appropriate timestep when using real units if (update->whichflag == 1) { - if (force->qqr2e == 332.06371 && update->dt == 1.0) + if (utils::strmatch(update->unit_style,"^real") && update->dt_default) error->all(FLERR,"Must lower the default real units timestep for pEFF "); } diff --git a/src/USER-SMD/fix_smd_adjust_dt.cpp b/src/USER-SMD/fix_smd_adjust_dt.cpp index b5dab3d3a1..2acf6bd3ec 100644 --- a/src/USER-SMD/fix_smd_adjust_dt.cpp +++ b/src/USER-SMD/fix_smd_adjust_dt.cpp @@ -186,6 +186,7 @@ void FixSMDTlsphDtReset::end_of_step() { update->dt = dt; + update->dt_default = 0; if (force->pair) force->pair->reset_dt(); for (int i = 0; i < modify->nfix; i++) diff --git a/src/fix_dt_reset.cpp b/src/fix_dt_reset.cpp index 360f0d2998..4a9465e696 100644 --- a/src/fix_dt_reset.cpp +++ b/src/fix_dt_reset.cpp @@ -190,6 +190,7 @@ void FixDtReset::end_of_step() update->update_time(); update->dt = dt; + update->dt_default = 0; if (respaflag) update->integrate->reset_dt(); if (force->pair) force->pair->reset_dt(); for (int i = 0; i < modify->nfix; i++) modify->fix[i]->reset_dt(); diff --git a/src/input.cpp b/src/input.cpp index 6456f6c229..3a136cd44b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1871,6 +1871,7 @@ void Input::timestep() { if (narg != 1) error->all(FLERR,"Illegal timestep command"); update->dt = utils::numeric(FLERR,arg[0],false,lmp); + update->dt_default = 0; } /* ---------------------------------------------------------------------- */ diff --git a/src/update.cpp b/src/update.cpp index 399584473c..d591e05131 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -12,18 +12,22 @@ ------------------------------------------------------------------------- */ #include "update.h" -#include -#include "integrate.h" -#include "min.h" + #include "style_integrate.h" // IWYU pragma: keep #include "style_minimize.h" // IWYU pragma: keep -#include "neighbor.h" -#include "force.h" -#include "modify.h" -#include "fix.h" + +#include "comm.h" #include "compute.h" -#include "output.h" +#include "integrate.h" #include "error.h" +#include "fix.h" +#include "force.h" +#include "min.h" +#include "modify.h" +#include "neighbor.h" +#include "output.h" + +#include using namespace LAMMPS_NS; @@ -48,6 +52,7 @@ Update::Update(LAMMPS *lmp) : Pointers(lmp) eflag_global = vflag_global = -1; + dt_default = 1; unit_style = NULL; set_units("lj"); @@ -121,6 +126,8 @@ void Update::set_units(const char *style) // http://physics.nist.gov/cuu/Constants/Table/allascii.txt // using thermochemical calorie = 4.184 J + double dt_old = dt; + if (strcmp(style,"lj") == 0) { force->boltz = 1.0; force->hplanck = 1.0; @@ -295,6 +302,14 @@ void Update::set_units(const char *style) int n = strlen(style) + 1; unit_style = new char[n]; strcpy(unit_style,style); + + // check if timestep was changed from default value + if (!dt_default && (comm->me == 0)) { + error->warning(FLERR,fmt::format("Changing timestep from {:.6} to {:.6} " + "due to changing units to {}", + dt_old, dt, unit_style)); + } + dt_default = 1; } /* ---------------------------------------------------------------------- */ diff --git a/src/update.h b/src/update.h index 558719f4cc..1d1e04b8bd 100644 --- a/src/update.h +++ b/src/update.h @@ -37,6 +37,7 @@ class Update : protected Pointers { int setupflag; // set when setup() is computing forces int post_integrate; // 1 if now at post_integrate() in timestep int multireplica; // 1 if min across replicas, else 0 + int dt_default; // 1 if dt is at default value, else 0 bigint eflag_global,eflag_atom; // timestep global/peratom eng is tallied on bigint vflag_global,vflag_atom; // ditto for virial