diff --git a/src/GRANULAR/fix_pour.cpp b/src/GRANULAR/fix_pour.cpp index 6ef6759f7fe1ca2db57e2018b87dc7522fd417fa..d20b359fb25cb2c067882736c26b3eea2e8dd0dd 100644 --- a/src/GRANULAR/fix_pour.cpp +++ b/src/GRANULAR/fix_pour.cpp @@ -671,7 +671,7 @@ void FixPour::pre_exchange() if (ninserted_atoms) { atom->natoms += ninserted_atoms; - if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + if (atom->natoms < 0) error->all(FLERR,"Too many total atoms"); if (mode == MOLECULE) { atom->nbonds += onemols[imol]->nbonds * ninserted_mols; diff --git a/src/KSPACE/ewald_disp.cpp b/src/KSPACE/ewald_disp.cpp index c107fc85c75603f722e1dde093e835d6057b89aa..2f0874cf117f527a97e425bf7feac3c1a60b2264 100644 --- a/src/KSPACE/ewald_disp.cpp +++ b/src/KSPACE/ewald_disp.cpp @@ -52,7 +52,7 @@ EwaldDisp::EwaldDisp(LAMMPS *lmp, int narg, char **arg) : KSpace(lmp, narg, arg) ewaldflag = dispersionflag = dipoleflag = 1; accuracy_relative = fabs(force->numeric(FLERR,arg[0])); - memset(function, 0, EWALD_NORDER*sizeof(int)); + memset(function, 0, EWALD_NFUNCS*sizeof(int)); kenergy = kvirial = NULL; cek_local = cek_global = NULL; ekr_local = NULL; diff --git a/src/KSPACE/pppm_disp.cpp b/src/KSPACE/pppm_disp.cpp index 7134ed4326b68f858da964969d70c5ee93b7b1b7..fcb483b6803f0de0353aada6a52b65e8fa30be30 100755 --- a/src/KSPACE/pppm_disp.cpp +++ b/src/KSPACE/pppm_disp.cpp @@ -245,7 +245,7 @@ void PPPMDisp::init() int *ptr = pair ? (int *) pair->extract("ewald_order",tmp) : NULL; double *p_cutoff = pair ? (double *) pair->extract("cut_coul",tmp) : NULL; double *p_cutoff_lj = pair ? (double *) pair->extract("cut_LJ",tmp) : NULL; - if (!(ptr||*p_cutoff||*p_cutoff_lj)) + if (!(ptr||p_cutoff||p_cutoff_lj)) error->all(FLERR,"KSpace style is incompatible with Pair style"); cutoff = *p_cutoff; cutoff_lj = *p_cutoff_lj; diff --git a/src/MANYBODY/pair_airebo.cpp b/src/MANYBODY/pair_airebo.cpp index 2afd694dfddf09be75edd07457b3b90c5fc3d7f7..58bbeffbfc22697b8a13e1a8a1ac924b9a713cc0 100644 --- a/src/MANYBODY/pair_airebo.cpp +++ b/src/MANYBODY/pair_airebo.cpp @@ -620,19 +620,19 @@ void PairAIREBO::FLJ(int eflag, int vflag) if (wik*wkj > best) { best = wik*wkj; npath = 3; - atomk = k; - delikS[0] = delik[0]; - delikS[1] = delik[1]; - delikS[2] = delik[2]; - rikS = rik; - wikS = wik; - dwikS = dwik; - deljkS[0] = deljk[0]; - deljkS[1] = deljk[1]; - deljkS[2] = deljk[2]; - rkjS = rkj; - wkjS = wkj; - dwkjS = dwkj; + atomk = k; + delikS[0] = delik[0]; + delikS[1] = delik[1]; + delikS[2] = delik[2]; + rikS = rik; + wikS = wik; + dwikS = dwik; + deljkS[0] = deljk[0]; + deljkS[1] = deljk[1]; + deljkS[2] = deljk[2]; + rkjS = rkj; + wkjS = wkj; + dwkjS = dwkj; if (best == 1.0) { done = 1; break; @@ -803,7 +803,7 @@ void PairAIREBO::FLJ(int eflag, int vflag) if (vflag_atom) v_tally3(atomi,atomj,atomk,fi,fj,delikS,deljkS); - } else { + } else if (npath == 4) { fpair1 = dC*dwikS*wkmS*wmjS / rikS; fi[0] = delikS[0]*fpair1; fi[1] = delikS[1]*fpair1; diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index 94fbe62a99154323062721e6417e83e415484e7e..20febf3a3791064250c9d72000f4538c96883700 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -5108,11 +5108,7 @@ void PairBOP::read_table(char *filename) fgets(s,MAXLINE,fp); sscanf(s,"%lf%lf",&sigma_delta[i],&pi_delta[i]); fgets(s,MAXLINE,fp); - if(nws==3) { - sscanf(s,"%lf%lf%lf",&sigma_f[i],&sigma_k[i],&small3[i]); - } else { - sscanf(s,"%lf%lf%lf",&sigma_f[i],&sigma_k[i],&small3[i]); - } + sscanf(s,"%lf%lf%lf",&sigma_f[i],&sigma_k[i],&small3[i]); } if(nws==3) { for(i=0;i<bop_types;i++) diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index 60616e4f1fabb6e30dbe70397f7764d2a5535d2e..82f69c76b6365f4b98c286038bdeaab218426bd5 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -79,6 +79,8 @@ PairEAM::~PairEAM() memory->destroy(cutsq); delete [] map; delete [] type2frho; + map = NULL; + type2frho = NULL; memory->destroy(type2rhor); memory->destroy(type2z2r); } @@ -91,6 +93,7 @@ PairEAM::~PairEAM() memory->destroy(funcfl[i].zr); } memory->sfree(funcfl); + funcfl = NULL; } if (setfl) { @@ -101,6 +104,7 @@ PairEAM::~PairEAM() memory->destroy(setfl->rhor); memory->destroy(setfl->z2r); delete setfl; + setfl = NULL; } if (fs) { @@ -111,6 +115,7 @@ PairEAM::~PairEAM() memory->destroy(fs->rhor); memory->destroy(fs->z2r); delete fs; + fs = NULL; } memory->destroy(frho); diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index d65ea8bda02befbdfc606373b83db37476c3c13c..d41e3ef325131b5ab453830e83b17889262fcd2c 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -1308,7 +1308,7 @@ void FixGCMC::attempt_molecule_insertion() fixshake->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat); atom->natoms += natoms_per_molecule; - if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + if (atom->natoms < 0) error->all(FLERR,"Too many total atoms"); atom->nbonds += onemols[imol]->nbonds; atom->nangles += onemols[imol]->nangles; @@ -1957,7 +1957,7 @@ void FixGCMC::attempt_molecule_insertion_full() fixshake->set_molecule(nlocalprev,maxtag_all,imol,com_coord,vnew,quat); atom->natoms += natoms_per_molecule; - if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + if (atom->natoms < 0) error->all(FLERR,"Too many total atoms"); atom->nbonds += onemols[imol]->nbonds; atom->nangles += onemols[imol]->nangles; diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index 0b35627ebe8915973b8b8ccf551f3f36435ebd74..7aa3f72ce04e885349f777bbb04428b0454e75c9 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -563,7 +563,7 @@ void FixDeposit::pre_exchange() if (success) { atom->natoms += natom; - if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + if (atom->natoms < 0) error->all(FLERR,"Too many total atoms"); if (mode == MOLECULE) { atom->nbonds += onemols[imol]->nbonds; diff --git a/src/MISC/fix_oneway.cpp b/src/MISC/fix_oneway.cpp index 2ed15f81ed060d0bf19fbf76ba3d5b883a84f5cb..2f25b714b053935a0620629606a91826376272b0 100644 --- a/src/MISC/fix_oneway.cpp +++ b/src/MISC/fix_oneway.cpp @@ -43,7 +43,7 @@ FixOneWay::FixOneWay(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg) if (nevery < 1) error->all(FLERR,"Illegal fix oneway command"); int len = strlen(arg[4]); - regionstr = new char[len]; + regionstr = new char[len+1]; strcpy(regionstr,arg[4]); if (strcmp(arg[5], "x") == 0) direction = X|PLUS; diff --git a/src/MOLECULE/angle_cosine_periodic.cpp b/src/MOLECULE/angle_cosine_periodic.cpp index b288c470295ff61709e87a031d0a77d718c53dd0..8198f3d4b4dab6953e147b670622dfd34bc282d8 100644 --- a/src/MOLECULE/angle_cosine_periodic.cpp +++ b/src/MOLECULE/angle_cosine_periodic.cpp @@ -57,7 +57,7 @@ void AngleCosinePeriodic::compute(int eflag, int vflag) int i,i1,i2,i3,n,m,type,b_factor; double delx1,dely1,delz1,delx2,dely2,delz2; double eangle,f1[3],f3[3]; - double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22; + double rsq1,rsq2,r1,r2,c,a,a11,a12,a22; double tn,tn_1,tn_2,un,un_1,un_2; eangle = 0.0; @@ -120,10 +120,6 @@ void AngleCosinePeriodic::compute(int eflag, int vflag) un_1 = 2.0; un_2 = 0.0; - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - s = 1.0/s; - // force & energy tn_2 = c; diff --git a/src/MOLECULE/improper_umbrella.cpp b/src/MOLECULE/improper_umbrella.cpp index 0eadf1686ac541d24d69dbb032ddb5ca2216d8d6..28b3fe8924fbf6b9d40e3ddc67d908d619d230d4 100644 --- a/src/MOLECULE/improper_umbrella.cpp +++ b/src/MOLECULE/improper_umbrella.cpp @@ -145,8 +145,8 @@ void ImproperUmbrella::compute(int eflag, int vflag) } } - if (c > 1.0) s = 1.0; - if (c < -1.0) s = -1.0; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/OPT/pair_eam_alloy_opt.h b/src/OPT/pair_eam_alloy_opt.h index c6056e3cff46821a4208d529f84b76930a4749b3..3fdfc449e9e48820a8f9815d8306f2d65325553f 100644 --- a/src/OPT/pair_eam_alloy_opt.h +++ b/src/OPT/pair_eam_alloy_opt.h @@ -28,6 +28,7 @@ namespace LAMMPS_NS { class PairEAMAlloyOpt : public PairEAMAlloy, public PairEAMOpt { public: PairEAMAlloyOpt(class LAMMPS *); + virtual ~PairEAMAlloyOpt() {} }; } diff --git a/src/OPT/pair_eam_fs_opt.h b/src/OPT/pair_eam_fs_opt.h index f8fba9871755867c84372af6a06de0f1c6276b2c..f0288d5c57011fdfb684cf0264d4c1b368086e98 100644 --- a/src/OPT/pair_eam_fs_opt.h +++ b/src/OPT/pair_eam_fs_opt.h @@ -28,6 +28,7 @@ namespace LAMMPS_NS { class PairEAMFSOpt : public PairEAMFS, public PairEAMOpt { public: PairEAMFSOpt(class LAMMPS *); + virtual ~PairEAMFSOpt() {} }; } diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 8cb0be74625f0b817ac55286ee56c20bd8770cb9..6e5399ba8263bbea09a013d5127272c3268de4b9 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -207,7 +207,7 @@ void NEB::run() update->endstep = update->laststep = update->firststep + n1steps; update->nsteps = n1steps; update->max_eval = n1steps; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many timesteps for NEB"); update->minimize->setup(); @@ -275,7 +275,7 @@ void NEB::run() update->endstep = update->laststep = update->firststep + n2steps; update->nsteps = n2steps; update->max_eval = n2steps; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many timesteps"); update->minimize->init(); diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index de3447db98ae57bd3c8185e83f81a09fc1996e69..57aaf485f49a7e46de181f729d2e58700cafaacf 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -220,7 +220,7 @@ void PRD::command(int narg, char **arg) update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; update->restrict_output = 1; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many timesteps"); lmp->init(); @@ -568,7 +568,7 @@ void PRD::quench() update->whichflag = 2; update->nsteps = maxiter; update->endstep = update->laststep = update->firststep + maxiter; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many iterations"); // full init works diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index 80381a7a3bac5321507151084a195845fbc0eb82..0f46867f99bc587ac44b42f3a84908995c7e67bc 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -199,7 +199,7 @@ void TAD::command(int narg, char **arg) update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; update->restrict_output = 1; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many timesteps"); lmp->init(); @@ -406,7 +406,7 @@ void TAD::command(int narg, char **arg) timer->get_wall(Timer::TOTAL),nprocs_universe,nsteps,atom->natoms); } - if (me_universe == 0) fclose(ulogfile_neb); + if ((me_universe == 0) && ulogfile_neb) fclose(ulogfile_neb); if (me == 0) { if (screen) fprintf(screen,"\nTAD done\n"); @@ -478,7 +478,7 @@ void TAD::quench() update->whichflag = 2; update->nsteps = maxiter; update->endstep = update->laststep = update->firststep + maxiter; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many iterations"); // full init works diff --git a/src/REPLICA/temper.cpp b/src/REPLICA/temper.cpp index 45e100ad521787acac40639f28a5f2b28e759482..8771ab53758642a83d3f8a3694e6435777c6bfc4 100644 --- a/src/REPLICA/temper.cpp +++ b/src/REPLICA/temper.cpp @@ -107,7 +107,7 @@ void Temper::command(int narg, char **arg) update->nsteps = nsteps; update->beginstep = update->firststep = update->ntimestep; update->endstep = update->laststep = update->firststep + nsteps; - if (update->laststep < 0 || update->laststep > MAXBIGINT) + if (update->laststep < 0) error->all(FLERR,"Too many timesteps"); lmp->init(); diff --git a/src/SHOCK/fix_append_atoms.cpp b/src/SHOCK/fix_append_atoms.cpp index 571e77b12998c43e7e9d6f97a86989a66748f0c1..f01fbdfbbb38e51a5ccd973815d61f899cb3e8e9 100644 --- a/src/SHOCK/fix_append_atoms.cpp +++ b/src/SHOCK/fix_append_atoms.cpp @@ -506,7 +506,7 @@ void FixAppendAtoms::pre_exchange() if (addtotal) { domain->reset_box(); atom->natoms += addtotal; - if (atom->natoms < 0 || atom->natoms > MAXBIGINT) + if (atom->natoms < 0) error->all(FLERR,"Too many total atoms"); if (atom->tag_enable) atom->tag_extend(); if (atom->map_style) { diff --git a/src/SHOCK/fix_wall_piston.cpp b/src/SHOCK/fix_wall_piston.cpp index 2f908bccb44264d1aba900121961ce11aae88a96..9217a24f6f57f7895c4c98469ad6cad8f3d2fcb6 100644 --- a/src/SHOCK/fix_wall_piston.cpp +++ b/src/SHOCK/fix_wall_piston.cpp @@ -41,6 +41,7 @@ FixWallPiston::FixWallPiston(LAMMPS *lmp, int narg, char **arg) : if (narg < 4) error->all(FLERR,"Illegal fix wall/piston command"); randomt = NULL; + gfactor1 = gfactor2 = NULL; tempflag = 0; scaleflag = 1; roughflag = 0; @@ -150,6 +151,15 @@ FixWallPiston::FixWallPiston(LAMMPS *lmp, int narg, char **arg) : /* ---------------------------------------------------------------------- */ +FixWallPiston::~FixWallPiston() +{ + delete[] gfactor2; + delete[] gfactor1; + delete randomt; +} + +/* ---------------------------------------------------------------------- */ + int FixWallPiston::setmask() { int mask = 0; diff --git a/src/SHOCK/fix_wall_piston.h b/src/SHOCK/fix_wall_piston.h index 8ad3c25b579f6b1d0459e66e4c90f9dcde098cb9..28135b235903057841928c0844f97038794f08bf 100644 --- a/src/SHOCK/fix_wall_piston.h +++ b/src/SHOCK/fix_wall_piston.h @@ -26,6 +26,7 @@ namespace LAMMPS_NS { class FixWallPiston : public Fix { public: FixWallPiston(class LAMMPS *, int, char **); + virtual ~FixWallPiston(); int setmask(); void post_integrate(); void initial_integrate(int); diff --git a/src/USER-MISC/compute_basal_atom.cpp b/src/USER-MISC/compute_basal_atom.cpp index 85a08d1838997e6d03bd2fed90bd9d8d015679dc..cf90b50d8a39140796768d4bd8be4c4734b8485a 100644 --- a/src/USER-MISC/compute_basal_atom.cpp +++ b/src/USER-MISC/compute_basal_atom.cpp @@ -243,7 +243,7 @@ void ComputeBasalAtom::compute_peratom() j1[1]=2; j1[2]=2; } - xmean5 = ymean5 = zmean5 = xmean6 = ymean6 = zmean6 = xmean7 = ymean7 = zmean7 = 0; + xmean5 = ymean5 = zmean5 = xmean6 = ymean6 = zmean6 = xmean7 = ymean7 = zmean7 = 0.0; for (j = 0; j < chi[0]; j++) { for (k = j+1; k < chi[0]; k++) { //get cross products @@ -261,27 +261,29 @@ void ComputeBasalAtom::compute_peratom() y7[count] = y4[count]*copysign(1.0,z4[count]); z7[count] = z4[count]*copysign(1.0,z4[count]); //get average cross products - xmean5 = xmean5 + x5[count]; - ymean5 = ymean5 + y5[count]; - zmean5 = zmean5 + z5[count]; - xmean6 = xmean6 + x6[count]; - ymean6 = ymean6 + y6[count]; - zmean6 = zmean6 + z6[count]; - xmean7 = xmean7 + x7[count]; - ymean7 = ymean7 + y7[count]; - zmean6 = zmean6 + z7[count]; + xmean5 += x5[count]; + ymean5 += y5[count]; + zmean5 += z5[count]; + xmean6 += x6[count]; + ymean6 += y6[count]; + zmean6 += z6[count]; + xmean7 += x7[count]; + ymean7 += y7[count]; + zmean6 += z7[count]; count++; } } - xmean5 = xmean5/count; - xmean6 = xmean6/count; - xmean7 = xmean7/count; - ymean5 = ymean5/count; - ymean6 = ymean6/count; - ymean7 = ymean7/count; - zmean5 = zmean5/count; - zmean6 = zmean6/count; - zmean7 = zmean7/count; + if (count > 0) { + xmean5 /= count; + xmean6 /= count; + xmean7 /= count; + ymean5 /= count; + ymean6 /= count; + ymean7 /= count; + zmean5 /= count; + zmean6 /= count; + zmean7 /= count; + } var5 = var6 = var7 = 0.0; //find standard deviations for (j=0;j<count;j++){ diff --git a/src/USER-MISC/dihedral_table.cpp b/src/USER-MISC/dihedral_table.cpp index 7ce69f6834946a71f04050db06345b5d93497a3c..befaffc3634f9c5ac56936dfcbdc75a6e9b5e743 100644 --- a/src/USER-MISC/dihedral_table.cpp +++ b/src/USER-MISC/dihedral_table.cpp @@ -81,7 +81,7 @@ static int solve_cyc_tridiag( const double diag[], size_t d_stride, const double offdiag[], size_t o_stride, const double b[], size_t b_stride, double x[], size_t x_stride, - size_t N) + size_t N, bool warn) { int status = GSL_SUCCESS; double * delta = (double *) malloc (N * sizeof (double)); @@ -91,8 +91,15 @@ static int solve_cyc_tridiag( const double diag[], size_t d_stride, double * z = (double *) malloc (N * sizeof (double)); if (delta == 0 || gamma == 0 || alpha == 0 || c == 0 || z == 0) { - cerr << "Internal Cyclic Spline Error: failed to allocate working space\n"; - exit(GSL_ENOMEM); + if (warn) + fprintf(stderr,"Internal Cyclic Spline Error: failed to allocate working space\n"); + + if (delta) free(delta); + if (gamma) free(gamma); + if (alpha) free(alpha); + if (c) free(c); + if (z) free(z); + return GSL_ENOMEM; } else { @@ -104,6 +111,11 @@ static int solve_cyc_tridiag( const double diag[], size_t d_stride, if (N == 1) { x[0] = b[0] / diag[0]; + free(delta); + free(gamma); + free(alpha); + free(c); + free(z); return GSL_SUCCESS; } @@ -165,21 +177,14 @@ static int solve_cyc_tridiag( const double diag[], size_t d_stride, } } - if (z != 0) - free (z); - if (c != 0) - free (c); - if (alpha != 0) - free (alpha); - if (gamma != 0) - free (gamma); - if (delta != 0) - free (delta); - - if (status == GSL_EZERODIV) { - cerr <<"Internal Cyclic Spline Error: Matrix must be positive definite.\n"; - exit(GSL_EZERODIV); - } + free (z); + free (c); + free (alpha); + free (gamma); + free (delta); + + if ((status == GSL_EZERODIV) && warn) + fprintf(stderr, "Internal Cyclic Spline Error: Matrix must be positive definite.\n"); return status; } //solve_cyc_tridiag() @@ -188,11 +193,11 @@ static int solve_cyc_tridiag( const double diag[], size_t d_stride, spline and splint routines modified from Numerical Recipes ------------------------------------------------------------------------- */ -static void cyc_spline(double const *xa, - double const *ya, - int n, - double period, - double *y2a) +static int cyc_spline(double const *xa, + double const *ya, + int n, + double period, + double *y2a, bool warn) { double *diag = new double[n]; @@ -234,18 +239,25 @@ static void cyc_spline(double const *xa, ((ya[i] - ya[im1]) / (xa[i] - xa_im1)); } - // Because this matix is tridiagonal (and cyclic), we can use the following + // Because this matrix is tridiagonal (and cyclic), we can use the following // cheap method to invert it. - solve_cyc_tridiag(diag, 1, + if (solve_cyc_tridiag(diag, 1, offdiag, 1, rhs, 1, y2a, 1, - n); - + n, warn) != GSL_SUCCESS) { + if (warn) + fprintf(stderr,"Error in inverting matrix for splines.\n"); + + delete [] diag; + delete [] offdiag; + delete [] rhs; + return 1; + } delete [] diag; delete [] offdiag; delete [] rhs; - + return 0; } // cyc_spline() /* ---------------------------------------------------------------------- */ @@ -913,6 +925,11 @@ void DihedralTable::coeff(int narg, char **arg) tb->ffile[I] = ffile_tmp[i]; I++; } + + // clean up temporary storage + delete[] phifile_tmp; + delete[] ffile_tmp; + delete[] efile_tmp; } // spline read-in and compute r,e,f vectors within table @@ -1147,10 +1164,14 @@ void DihedralTable::spline_table(Table *tb) memory->create(tb->e2file,tb->ninput,"dihedral:e2file"); memory->create(tb->f2file,tb->ninput,"dihedral:f2file"); - cyc_spline(tb->phifile, tb->efile, tb->ninput, MY_2PI, tb->e2file); + if (cyc_spline(tb->phifile, tb->efile, tb->ninput, + MY_2PI,tb->e2file,comm->me == 0)) + error->one(FLERR,"Error computing dihedral spline tables"); if (! tb->f_unspecified) { - cyc_spline(tb->phifile, tb->ffile, tb->ninput, MY_2PI, tb->f2file); + if (cyc_spline(tb->phifile, tb->ffile, tb->ninput, + MY_2PI, tb->f2file, comm->me == 0)) + error->one(FLERR,"Error computing dihedral spline tables"); } // CHECK to help make sure the user calculated forces in a way @@ -1302,9 +1323,9 @@ void DihedralTable::compute_table(Table *tb) - cyc_spline(tb->phi, tb->e, tablength, MY_2PI, tb->e2); + cyc_spline(tb->phi, tb->e, tablength, MY_2PI, tb->e2, comm->me == 0); if (! tb->f_unspecified) - cyc_spline(tb->phi, tb->f, tablength, MY_2PI, tb->f2); + cyc_spline(tb->phi, tb->f, tablength, MY_2PI, tb->f2, comm->me == 0); } @@ -1339,13 +1360,13 @@ void DihedralTable::param_extract(Table *tb, char *line) else if (strcmp(word,"CHECKU") == 0) { word = strtok(NULL," \t\n\r\f"); memory->sfree(checkU_fname); - memory->create(checkU_fname,strlen(word),"dihedral_table:checkU"); + memory->create(checkU_fname,strlen(word)+1,"dihedral_table:checkU"); strcpy(checkU_fname, word); } else if (strcmp(word,"CHECKF") == 0) { word = strtok(NULL," \t\n\r\f"); memory->sfree(checkF_fname); - memory->create(checkF_fname,strlen(word),"dihedral_table:checkF"); + memory->create(checkF_fname,strlen(word)+1,"dihedral_table:checkF"); strcpy(checkF_fname, word); } // COMMENTING OUT: equilibrium angles are not supported diff --git a/src/USER-MISC/fix_ave_spatial_sphere.cpp b/src/USER-MISC/fix_ave_spatial_sphere.cpp index c654db7ef80a8fd7453c6952a9db2fa14deb0ad2..bf82173be2813a0b215cae822e704c3f3ea753f9 100644 --- a/src/USER-MISC/fix_ave_spatial_sphere.cpp +++ b/src/USER-MISC/fix_ave_spatial_sphere.cpp @@ -827,7 +827,7 @@ void FixAveSpatialSphere::end_of_step() fflush(fp); if (overwrite) { long fileend = ftell(fp); - ftruncate(fileno(fp),fileend); + if (fileend > 0) ftruncate(fileno(fp),fileend); } } } diff --git a/src/USER-MISC/fix_ipi.cpp b/src/USER-MISC/fix_ipi.cpp index 58251a814e8fe26bfb5f5a8517d68d70ba8bf61f..07dbeb2500cff75e4c92f8382111ebbbb0a1a322 100644 --- a/src/USER-MISC/fix_ipi.cpp +++ b/src/USER-MISC/fix_ipi.cpp @@ -18,6 +18,7 @@ #include "mpi.h" #include "stdio.h" #include "string.h" +#include "stdlib.h" #include "fix_ipi.h" #include "atom.h" #include "force.h" @@ -187,8 +188,8 @@ FixIPI::FixIPI(LAMMPS *lmp, int narg, char **arg) : if (strcmp(arg[1],"all")) error->warning(FLERR,"Fix ipi always uses group all"); - strcpy(host, arg[3]); - port=force->inumeric(FLERR,arg[4]); + host = strdup(arg[3]); + port = force->inumeric(FLERR,arg[4]); inet = ((narg > 5) && (strcmp(arg[5],"unix") ==0) ) ? 0 : 1; master = (comm->me==0) ? 1 : 0; @@ -218,6 +219,7 @@ FixIPI::FixIPI(LAMMPS *lmp, int narg, char **arg) : FixIPI::~FixIPI() { if (bsize) delete[] buffer; + free(host); modify->delete_compute("IPI_TEMP"); modify->delete_compute("IPI_PRESS"); } diff --git a/src/USER-MISC/fix_ipi.h b/src/USER-MISC/fix_ipi.h index 010f0ba17dd20adfaafa0d40631c39c028a0fc0a..0859a513c5b13f4f8ccf9646285e893a133e15fb 100644 --- a/src/USER-MISC/fix_ipi.h +++ b/src/USER-MISC/fix_ipi.h @@ -34,7 +34,7 @@ class FixIPI : public Fix { virtual void final_integrate(); protected: - char host[1024]; int port; int inet, master, hasdata; + char *host; int port; int inet, master, hasdata; int ipisock, me; double *buffer; long bsize; int kspace_flag; }; diff --git a/src/USER-MISC/fix_srp.cpp b/src/USER-MISC/fix_srp.cpp index 833dc41d2892c72a1e0b7fe751cd57e4620dfff3..613204a55e55272e23e0634485e825e1ab054e32 100644 --- a/src/USER-MISC/fix_srp.cpp +++ b/src/USER-MISC/fix_srp.cpp @@ -178,7 +178,9 @@ void FixSRP::setup_pre_force(int zz) for (int n = 0; n < nbondlist; n++) { // consider only the user defined bond type - if(bondlist[n][2] != btype) continue; + // btype of zero considers all bonds + if(btype > 0 && bondlist[n][2] != btype) + continue; i = bondlist[n][0]; j = bondlist[n][1]; diff --git a/src/USER-MISC/fix_ti_spring.cpp b/src/USER-MISC/fix_ti_spring.cpp index 139795557ca3e18fa5c1b1b20bf31697675238d5..529e6509788d87c5913127a10e71561caf88798e 100755 --- a/src/USER-MISC/fix_ti_spring.cpp +++ b/src/USER-MISC/fix_ti_spring.cpp @@ -76,8 +76,8 @@ FixTISpring::FixTISpring(LAMMPS *lmp, int narg, char **arg) : t_switch = atoi(arg[4]); // Switching time. t_equil = atoi(arg[5]); // Equilibration time. t0 = update->ntimestep; // Initial time. - if (t_switch < 0.0) error->all(FLERR,"Illegal fix ti/spring command"); - if (t_equil < 0.0) error->all(FLERR,"Illegal fix ti/spring command"); + if (t_switch <= 0.0) error->all(FLERR,"Illegal fix ti/spring command"); + if (t_equil <= 0.0) error->all(FLERR,"Illegal fix ti/spring command"); // Coupling parameter initialization. sf = 1; diff --git a/src/USER-MISC/fix_ttm_mod.cpp b/src/USER-MISC/fix_ttm_mod.cpp index d66e49d6a25cf31775ad1d3df81ecae4083e725c..3a6aafe700bffa9478c85a525525a586c7444613 100644 --- a/src/USER-MISC/fix_ttm_mod.cpp +++ b/src/USER-MISC/fix_ttm_mod.cpp @@ -225,6 +225,10 @@ FixTTMMod::FixTTMMod(LAMMPS *lmp, int narg, char **arg) : t_surface_l = surface_l; mult_factor = intensity; duration = 0.0; + v_0_sq = v_0*v_0; + // error checks + if (nxnodes <= 0 || nynodes <= 0 || nznodes <= 0) + error->all(FLERR,"Fix ttm number of nodes must be > 0"); surface_double = double(t_surface_l)*(domain->xprd/nxnodes); if ((C_limit+esheat_0) < 0.0) error->all(FLERR,"Fix ttm electronic_specific_heat must be >= 0.0"); @@ -234,10 +238,6 @@ FixTTMMod::FixTTMMod(LAMMPS *lmp, int narg, char **arg) : if (gamma_s < 0.0) error->all(FLERR,"Fix ttm gamma_s must be >= 0.0"); if (v_0 < 0.0) error->all(FLERR,"Fix ttm v_0 must be >= 0.0"); if (ionic_density <= 0.0) error->all(FLERR,"Fix ttm ionic_density must be > 0.0"); - v_0_sq = v_0*v_0; - // error check - if (nxnodes <= 0 || nynodes <= 0 || nznodes <= 0) - error->all(FLERR,"Fix ttm number of nodes must be > 0"); if (seed <= 0) error->all(FLERR,"Invalid random number seed in fix ttm command"); if (surface_l < 0) error->all(FLERR,"Surface coordinates must be >= 0"); if (surface_l >= surface_r) error->all(FLERR, "Left surface coordinate must be less than right surface coordinate"); diff --git a/src/USER-MISC/improper_fourier.cpp b/src/USER-MISC/improper_fourier.cpp index edfd95f20f02a1da94f6c12e86b2c3ce9f525831..f3fe065d6ed6d81f3e2d91b003de1b2865046016 100644 --- a/src/USER-MISC/improper_fourier.cpp +++ b/src/USER-MISC/improper_fourier.cpp @@ -173,8 +173,8 @@ void ImproperFourier::addone(const int &i1,const int &i2,const int &i3,const int } } - if (c > 1.0) s = 1.0; - if (c < -1.0) s = -1.0; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/USER-MISC/pair_srp.cpp b/src/USER-MISC/pair_srp.cpp index ec7730a1f210043df899a7965772e20b3d57bf4a..fedbe0a302539c8634cbdfeb689bbed29443bb4b 100644 --- a/src/USER-MISC/pair_srp.cpp +++ b/src/USER-MISC/pair_srp.cpp @@ -59,6 +59,8 @@ static const char cite_srp[] = " pages = {134903}\n" "}\n\n"; +static int srp_instance = 0; + /* ---------------------------------------------------------------------- set size of pair comms in constructor ---------------------------------------------------------------------- */ @@ -71,6 +73,10 @@ PairSRP::PairSRP(LAMMPS *lmp) : Pair(lmp) nextra = 1; segment = NULL; + fix_id = strdup("XX_FIX_SRP"); + fix_id[0] = '0' + srp_instance / 10; + fix_id[1] = '0' + srp_instance % 10; + ++srp_instance; } /* ---------------------------------------------------------------------- @@ -112,9 +118,10 @@ PairSRP::~PairSRP() } // check nfix in case all fixes have already been deleted - if (modify->nfix) modify->delete_fix("mysrp"); -} - + if (modify->nfix) modify->delete_fix(fix_id); + free(fix_id); +} + /* ---------------------------------------------------------------------- compute bond-bond repulsions ------------------------------------------------------------------------- */ @@ -336,8 +343,14 @@ void PairSRP::settings(int narg, char **arg) error->all(FLERR,"Illegal pair_style command"); cut_global = force->numeric(FLERR,arg[0]); - btype = force->inumeric(FLERR,arg[1]); - if (btype > atom->nbondtypes) error->all(FLERR,"Illegal pair_style command"); + // wildcard + if (strcmp(arg[1],"*") == 0) + btype = 0; + else { + btype = force->inumeric(FLERR,arg[1]); + if ((btype > atom->nbondtypes) || (btype <= 0)) + error->all(FLERR,"Illegal pair_style command"); + } // settings midpoint = 0; @@ -426,7 +439,7 @@ void PairSRP::init_style() // invoke here instead of constructor // to make restart possible char **fixarg = new char*[3]; - fixarg[0] = (char *) "mysrp"; + fixarg[0] = fix_id; fixarg[1] = (char *) "all"; fixarg[2] = (char *) "SRP"; modify->add_fix(3,fixarg); diff --git a/src/USER-MISC/pair_srp.h b/src/USER-MISC/pair_srp.h index 998f8a17e21d541f4e4b859669186cef45a3fa2f..ecd352cdeb89f0d4416f7874c61f5d69334ff933 100644 --- a/src/USER-MISC/pair_srp.h +++ b/src/USER-MISC/pair_srp.h @@ -54,6 +54,7 @@ class PairSRP : public Pair { int bptype; int btype; class Fix *f_srp; + char *fix_id; int exclude,maxcount; int **segment; }; diff --git a/src/USER-MOLFILE/molfile_interface.cpp b/src/USER-MOLFILE/molfile_interface.cpp index d0aff40f322fc227a651f99e804e8436a0780339..b9ee2238a981d8a0c9b83a4b07f982dd9bc5d942 100644 --- a/src/USER-MOLFILE/molfile_interface.cpp +++ b/src/USER-MOLFILE/molfile_interface.cpp @@ -756,10 +756,13 @@ int MolfileInterface::timestep(float *coords, float *vels, *simtime = t->physical_time; } - if (rv == MOLFILE_EOF) + if (rv == MOLFILE_EOF) { + delete t; return 1; + } } + delete t; return 0; } diff --git a/src/USER-OMP/angle_cosine_periodic_omp.cpp b/src/USER-OMP/angle_cosine_periodic_omp.cpp index 311152f06c0ce85b2ede936a4651ec8658789a3d..3bd4ef1212cc0edbf06ee7528490007ab7cb8033 100644 --- a/src/USER-OMP/angle_cosine_periodic_omp.cpp +++ b/src/USER-OMP/angle_cosine_periodic_omp.cpp @@ -91,7 +91,7 @@ void AngleCosinePeriodicOMP::eval(int nfrom, int nto, ThrData * const thr) int i,i1,i2,i3,n,m,type,b_factor; double delx1,dely1,delz1,delx2,dely2,delz2; double eangle,f1[3],f3[3]; - double rsq1,rsq2,r1,r2,c,s,a,a11,a12,a22; + double rsq1,rsq2,r1,r2,c,a,a11,a12,a22; double tn,tn_1,tn_2,un,un_1,un_2; const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0]; @@ -149,10 +149,6 @@ void AngleCosinePeriodicOMP::eval(int nfrom, int nto, ThrData * const thr) un_1 = 2.0; un_2 = 0.0; - s = sqrt(1.0 - c*c); - if (s < SMALL) s = SMALL; - s = 1.0/s; - // force & energy tn_2 = c; diff --git a/src/USER-OMP/improper_fourier_omp.cpp b/src/USER-OMP/improper_fourier_omp.cpp index 49fcef23d45578267a807770daed838ea040766d..6c32c8e538b3edd7b62847bf2175f1e279f7bb3c 100644 --- a/src/USER-OMP/improper_fourier_omp.cpp +++ b/src/USER-OMP/improper_fourier_omp.cpp @@ -206,8 +206,8 @@ void ImproperFourierOMP::add1_thr(const int i1,const int i2, } } - if (c > 1.0) s = 1.0; - if (c < -1.0) s = -1.0; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/USER-OMP/improper_umbrella_omp.cpp b/src/USER-OMP/improper_umbrella_omp.cpp index 689dbdfe65689a38548e3b22d7cccdd0e39c853e..f100d3a0a9fcad9290ac82af43deda5d4985e5cf 100644 --- a/src/USER-OMP/improper_umbrella_omp.cpp +++ b/src/USER-OMP/improper_umbrella_omp.cpp @@ -171,8 +171,8 @@ void ImproperUmbrellaOMP::eval(int nfrom, int nto, ThrData * const thr) } } - if (c > 1.0) s = 1.0; - if (c < -1.0) s = -1.0; + if (c > 1.0) c = 1.0; + if (c < -1.0) c = -1.0; s = sqrt(1.0 - c*c); if (s < SMALL) s = SMALL; diff --git a/src/USER-OMP/neigh_full_omp.cpp b/src/USER-OMP/neigh_full_omp.cpp index ee36e5610e3c3c334cd59e41c213eb3332fbac0c..e61611d41cad4c3179913f7efbade7ed6b6a53aa 100644 --- a/src/USER-OMP/neigh_full_omp.cpp +++ b/src/USER-OMP/neigh_full_omp.cpp @@ -599,7 +599,6 @@ void Neighbor::full_multi_omp(NeighList *list) onemols[imol]->nspecial[iatom], tag[j]-tagprev); else which = 0; - which = find_special(special[i],nspecial[i],tag[j]); if (which == 0) neighptr[n++] = j; else if (domain->minimum_image_check(delx,dely,delz)) neighptr[n++] = j; diff --git a/src/USER-OMP/pair_airebo_omp.cpp b/src/USER-OMP/pair_airebo_omp.cpp index c63ac3cd35c31343b3e88347b95f77aba7926492..f2149088c171a6b98c5f87a7ed3a3f85203229f8 100644 --- a/src/USER-OMP/pair_airebo_omp.cpp +++ b/src/USER-OMP/pair_airebo_omp.cpp @@ -2067,19 +2067,19 @@ void PairAIREBOOMP::FLJ_thr(int ifrom, int ito, int evflag, int eflag, if (wik*wkj > best) { best = wik*wkj; npath = 3; - atomk = k; - delikS[0] = delik[0]; - delikS[1] = delik[1]; - delikS[2] = delik[2]; - rikS = rik; - wikS = wik; - dwikS = dwik; - deljkS[0] = deljk[0]; - deljkS[1] = deljk[1]; - deljkS[2] = deljk[2]; - rkjS = rkj; - wkjS = wkj; - dwkjS = dwkj; + atomk = k; + delikS[0] = delik[0]; + delikS[1] = delik[1]; + delikS[2] = delik[2]; + rikS = rik; + wikS = wik; + dwikS = dwik; + deljkS[0] = deljk[0]; + deljkS[1] = deljk[1]; + deljkS[2] = deljk[2]; + rkjS = rkj; + wkjS = wkj; + dwkjS = dwkj; if (best == 1.0) { done = 1; break; @@ -2128,13 +2128,13 @@ void PairAIREBOOMP::FLJ_thr(int ifrom, int ito, int evflag, int eflag, atomm = m; delkmS[0] = delkm[0]; delkmS[1] = delkm[1]; - delkmS[2] = delkm[2]; + delkmS[2] = delkm[2]; rkmS = rkm; wkmS = wkm; dwkmS = dwkm; deljmS[0] = deljm[0]; deljmS[1] = deljm[1]; - deljmS[2] = deljm[2]; + deljmS[2] = deljm[2]; rmjS = rmj; wmjS = wmj; dwmjS = dwmj; @@ -2250,7 +2250,7 @@ void PairAIREBOOMP::FLJ_thr(int ifrom, int ito, int evflag, int eflag, if (vflag_atom) v_tally3_thr(atomi,atomj,atomk,fi,fj,delikS,deljkS,thr); - } else { + } else if (npath == 4) { fpair1 = dC*dwikS*wkmS*wmjS / rikS; fi[0] = delikS[0]*fpair1; fi[1] = delikS[1]*fpair1; diff --git a/src/USER-OMP/pair_brownian_omp.cpp b/src/USER-OMP/pair_brownian_omp.cpp index 56d9dee308d63986c9a94cfd9b4d8e72312830f2..8412644ff3ccda8939b8c64aa637ef2a7239f1a6 100644 --- a/src/USER-OMP/pair_brownian_omp.cpp +++ b/src/USER-OMP/pair_brownian_omp.cpp @@ -48,6 +48,7 @@ PairBrownianOMP::PairBrownianOMP(LAMMPS *lmp) : suffix_flag |= Suffix::OMP; respa_enable = 0; random_thr = NULL; + nthreads = 0; } /* ---------------------------------------------------------------------- */ @@ -55,7 +56,7 @@ PairBrownianOMP::PairBrownianOMP(LAMMPS *lmp) : PairBrownianOMP::~PairBrownianOMP() { if (random_thr) { - for (int i=1; i < comm->nthreads; ++i) + for (int i=1; i < nthreads; ++i) delete random_thr[i]; delete[] random_thr; @@ -72,7 +73,6 @@ void PairBrownianOMP::compute(int eflag, int vflag) } else evflag = vflag_fdotr = 0; const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; const int inum = list->inum; // This section of code adjusts R0/RT0/RS0 if necessary due to changes @@ -116,13 +116,24 @@ void PairBrownianOMP::compute(int eflag, int vflag) } } + // number of threads has changed. reallocate pool of pRNGs + if (nthreads != comm->nthreads) { + if (random_thr) { + for (int i=1; i < nthreads; ++i) + delete random_thr[i]; - if (!random_thr) + delete[] random_thr; + } + + nthreads = comm->nthreads; random_thr = new RanMars*[nthreads]; + for (int i=1; i < nthreads; ++i) + random_thr[i] = NULL; - // to ensure full compatibility with the serial Brownian style - // we use is random number generator instance for thread 0 - random_thr[0] = random; + // to ensure full compatibility with the serial Brownian style + // we use is random number generator instance for thread 0 + random_thr[0] = random; + } #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) @@ -137,9 +148,10 @@ void PairBrownianOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && tid > 0) + if ((tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); + if (flaglog) { if (evflag) { if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr); @@ -395,8 +407,8 @@ double PairBrownianOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairBrownian::memory_usage(); - bytes += comm->nthreads * sizeof(RanMars*); - bytes += comm->nthreads * sizeof(RanMars); + bytes += nthreads * sizeof(RanMars*); + bytes += nthreads * sizeof(RanMars); return bytes; } diff --git a/src/USER-OMP/pair_brownian_omp.h b/src/USER-OMP/pair_brownian_omp.h index cdabe08ba1eb688daa6e8e5e8fd0ef6cdcde4519..c49560cbcac27e065cf4013be60d3e624b118e62 100644 --- a/src/USER-OMP/pair_brownian_omp.h +++ b/src/USER-OMP/pair_brownian_omp.h @@ -40,6 +40,7 @@ class PairBrownianOMP : public PairBrownian, public ThrOMP { protected: class RanMars **random_thr; + int nthreads; private: template <int LOGFLAG, int EVFLAG, int NEWTON_PAIR> diff --git a/src/USER-OMP/pair_brownian_poly_omp.cpp b/src/USER-OMP/pair_brownian_poly_omp.cpp index 0ac97a935b1f96d97119fc358272428cb2108d2c..e0124204de7bbed26dcb9ab30cfe46ae37686cab 100644 --- a/src/USER-OMP/pair_brownian_poly_omp.cpp +++ b/src/USER-OMP/pair_brownian_poly_omp.cpp @@ -48,6 +48,7 @@ PairBrownianPolyOMP::PairBrownianPolyOMP(LAMMPS *lmp) : suffix_flag |= Suffix::OMP; respa_enable = 0; random_thr = NULL; + nthreads = 0; } /* ---------------------------------------------------------------------- */ @@ -55,7 +56,7 @@ PairBrownianPolyOMP::PairBrownianPolyOMP(LAMMPS *lmp) : PairBrownianPolyOMP::~PairBrownianPolyOMP() { if (random_thr) { - for (int i=1; i < comm->nthreads; ++i) + for (int i=1; i < nthreads; ++i) delete random_thr[i]; delete[] random_thr; @@ -72,7 +73,6 @@ void PairBrownianPolyOMP::compute(int eflag, int vflag) } else evflag = vflag_fdotr = 0; const int nall = atom->nlocal + atom->nghost; - const int nthreads = comm->nthreads; const int inum = list->inum; // This section of code adjusts R0/RT0/RS0 if necessary due to changes @@ -117,12 +117,24 @@ void PairBrownianPolyOMP::compute(int eflag, int vflag) } - if (!random_thr) + // number of threads has changed. reallocate pool of pRNGs + if (nthreads != comm->nthreads) { + if (random_thr) { + for (int i=1; i < nthreads; ++i) + delete random_thr[i]; + + delete[] random_thr; + } + + nthreads = comm->nthreads; random_thr = new RanMars*[nthreads]; + for (int i=1; i < nthreads; ++i) + random_thr[i] = NULL; - // to ensure full compatibility with the serial BrownianPoly style - // we use is random number generator instance for thread 0 - random_thr[0] = random; + // to ensure full compatibility with the serial BrownianPoly style + // we use is random number generator instance for thread 0 + random_thr[0] = random; + } #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) @@ -137,9 +149,10 @@ void PairBrownianPolyOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && tid > 0) + if ((tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); + if (flaglog) { if (evflag) eval<1,1>(ifrom, ito, thr); @@ -384,8 +397,8 @@ double PairBrownianPolyOMP::memory_usage() { double bytes = memory_usage_thr(); bytes += PairBrownianPoly::memory_usage(); - bytes += comm->nthreads * sizeof(RanMars*); - bytes += comm->nthreads * sizeof(RanMars); + bytes += nthreads * sizeof(RanMars*); + bytes += nthreads * sizeof(RanMars); return bytes; } diff --git a/src/USER-OMP/pair_brownian_poly_omp.h b/src/USER-OMP/pair_brownian_poly_omp.h index 663696c6c6185b2a234f5cde9e4b143cb25ea80d..df2c0b34bd4319d77f2facb7d03d9ef135715a06 100644 --- a/src/USER-OMP/pair_brownian_poly_omp.h +++ b/src/USER-OMP/pair_brownian_poly_omp.h @@ -40,6 +40,7 @@ class PairBrownianPolyOMP : public PairBrownianPoly, public ThrOMP { protected: class RanMars **random_thr; + int nthreads; private: template <int LOGFLAG, int EVFLAG> diff --git a/src/USER-OMP/pair_dpd_omp.cpp b/src/USER-OMP/pair_dpd_omp.cpp index 23408469e3e94311c3395ae48b17a6d5bbf77b6b..625d5bc19fb96cb6398c960ce8761f015f372652 100644 --- a/src/USER-OMP/pair_dpd_omp.cpp +++ b/src/USER-OMP/pair_dpd_omp.cpp @@ -74,12 +74,13 @@ void PairDPDOMP::compute(int eflag, int vflag) nthreads = comm->nthreads; random_thr = new RanMars*[nthreads]; for (int i=1; i < nthreads; ++i) - random_thr[i] = NULL; + random_thr[i] = NULL; // to ensure full compatibility with the serial DPD style // we use the serial random number generator instance for thread 0 random_thr[0] = random; } + #if defined(_OPENMP) #pragma omp parallel default(none) shared(eflag,vflag) #endif @@ -93,7 +94,7 @@ void PairDPDOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && (tid > 0) && (random_thr[tid] == NULL)) + if ((tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); diff --git a/src/USER-OMP/pair_dpd_tstat_omp.cpp b/src/USER-OMP/pair_dpd_tstat_omp.cpp index ca5b70186bb69bac1a22f4897075be519ffa3181..37b2994e3d747d076df2e90c5f517502d3056e96 100644 --- a/src/USER-OMP/pair_dpd_tstat_omp.cpp +++ b/src/USER-OMP/pair_dpd_tstat_omp.cpp @@ -93,7 +93,7 @@ void PairDPDTstatOMP::compute(int eflag, int vflag) // generate a random number generator instance for // all threads != 0. make sure we use unique seeds. - if (random_thr && (tid > 0) && (random_thr[tid] == NULL)) + if ((tid > 0) && (random_thr[tid] == NULL)) random_thr[tid] = new RanMars(Pair::lmp, seed + comm->me + comm->nprocs*tid); diff --git a/src/USER-OMP/thr_data.h b/src/USER-OMP/thr_data.h index 3f1d866a807e60c0f09e1180ce765166e26d9996..3cea1b0018df5e76ce12f87149529128f1dfd7d4 100644 --- a/src/USER-OMP/thr_data.h +++ b/src/USER-OMP/thr_data.h @@ -35,7 +35,7 @@ class ThrData { public: ThrData(int tid, class Timer *t); - ~ThrData() {}; + ~ThrData() { delete _timer; _timer = NULL; }; void check_tid(int); // thread id consistency check int get_tid() const { return _tid; }; // our thread id. @@ -140,7 +140,7 @@ class ThrData { // disabled default methods private: - ThrData() : _tid(-1) {}; + ThrData() : _tid(-1), _timer(NULL) {}; }; //////////////////////////////////////////////////////////////////////// diff --git a/src/USER-PHONON/fix_phonon.h b/src/USER-PHONON/fix_phonon.h index 891235cfec6f5df719144f241dad3ebabfb41424..f1a8af48126886f1c1437b6cdea584fff57b01c8 100644 --- a/src/USER-PHONON/fix_phonon.h +++ b/src/USER-PHONON/fix_phonon.h @@ -31,6 +31,17 @@ FixStyle(phonon,FixPhonon) #ifndef FIX_PHONON_H #define FIX_PHONON_H +#include "lmptype.h" +#include "mpi.h" + +#ifdef FFT_SINGLE +typedef float FFT_SCALAR; +#define MPI_FFT_SCALAR MPI_FLOAT +#else +typedef double FFT_SCALAR; +#define MPI_FFT_SCALAR MPI_DOUBLE +#endif + #include <complex> #include "fix.h" #include <map> @@ -72,7 +83,7 @@ class FixPhonon : public Fix { int mynpt,mynq,fft_nsend; int *fft_cnts, *fft_disp; int fft_dim, fft_dim2; - double *fft_data; + FFT_SCALAR *fft_data; tagint itag; // index variables int idx, idq; // more index variables diff --git a/src/USER-SMD/fix_smd_tlsph_reference_configuration.cpp b/src/USER-SMD/fix_smd_tlsph_reference_configuration.cpp index 5c20b803e8ee73b9d353dfcf0b00bac705b8e9b1..79c22e1056d3f2387f2cd2690a3ae31e99c1204b 100644 --- a/src/USER-SMD/fix_smd_tlsph_reference_configuration.cpp +++ b/src/USER-SMD/fix_smd_tlsph_reference_configuration.cpp @@ -330,6 +330,7 @@ void FixSMD_TLSPH_ReferenceConfiguration::setup(int vflag) { int nall, countall; MPI_Allreduce(&n, &nall, 1, MPI_INT, MPI_SUM, world); MPI_Allreduce(&count, &countall, 1, MPI_INT, MPI_SUM, world); + if (countall < 1) countall = 1; if (comm->me == 0) { if (screen) { diff --git a/src/compute_rdf.cpp b/src/compute_rdf.cpp index 7c5f433bb52cff29f636fe651b0c1eeb5581d85e..65bd4eabe26ac80aa3290a2d3619d005f68b54df 100644 --- a/src/compute_rdf.cpp +++ b/src/compute_rdf.cpp @@ -95,6 +95,7 @@ ComputeRDF::ComputeRDF(LAMMPS *lmp, int narg, char **arg) : typecount = new int[ntypes+1]; icount = new int[npairs]; jcount = new int[npairs]; + duplicates = new int[npairs]; } /* ---------------------------------------------------------------------- */ @@ -113,13 +114,14 @@ ComputeRDF::~ComputeRDF() delete [] typecount; delete [] icount; delete [] jcount; + delete [] duplicates; } /* ---------------------------------------------------------------------- */ void ComputeRDF::init() { - int i,m; + int i,j,m; if (force->pair) delr = force->pair->cutforce / nbin; else error->all(FLERR,"Compute rdf requires a pair style be defined"); @@ -143,12 +145,17 @@ void ComputeRDF::init() // icount = # of I atoms participating in I,J pairs for each histogram // jcount = # of J atoms participating in I,J pairs for each histogram + // duplicates = # of atoms in both groups I and J for each histogram for (m = 0; m < npairs; m++) { icount[m] = 0; for (i = ilo[m]; i <= ihi[m]; i++) icount[m] += typecount[i]; jcount[m] = 0; for (i = jlo[m]; i <= jhi[m]; i++) jcount[m] += typecount[i]; + duplicates[m] = 0; + for (i = ilo[m]; i <= ihi[m]; i++) + for (j = jlo[m]; j <= jhi[m]; j++) + if (i == j) duplicates[m] += typecount[i]; } int *scratch = new int[npairs]; @@ -156,6 +163,8 @@ void ComputeRDF::init() for (i = 0; i < npairs; i++) icount[i] = scratch[i]; MPI_Allreduce(jcount,scratch,npairs,MPI_INT,MPI_SUM,world); for (i = 0; i < npairs; i++) jcount[i] = scratch[i]; + MPI_Allreduce(duplicates,scratch,npairs,MPI_INT,MPI_SUM,world); + for (i = 0; i < npairs; i++) duplicates[i] = scratch[i]; delete [] scratch; // need an occasional half neighbor list @@ -265,25 +274,28 @@ void ComputeRDF::compute_array() MPI_Allreduce(hist[0],histall[0],npairs*nbin,MPI_DOUBLE,MPI_SUM,world); // convert counts to g(r) and coord(r) and copy into output array - // nideal = # of J atoms surrounding single I atom in a single bin - // assuming J atoms are at uniform density + // vfrac = fraction of volume in shell m + // npairs = number of pairs, corrected for duplicates + // duplicates = pairs in which both atoms are the same - double constant,nideal,gr,ncoord,rlower,rupper; + double constant,vfrac,gr,ncoord,rlower,rupper,normfac; if (domain->dimension == 3) { constant = 4.0*MY_PI / (3.0*domain->xprd*domain->yprd*domain->zprd); for (m = 0; m < npairs; m++) { + normfac = (icount[m] > 0) ? static_cast<double>(jcount[m]) + - static_cast<double>(duplicates[m])/icount[m] : 0.0; ncoord = 0.0; for (ibin = 0; ibin < nbin; ibin++) { rlower = ibin*delr; rupper = (ibin+1)*delr; - nideal = constant * - (rupper*rupper*rupper - rlower*rlower*rlower) * jcount[m]; - if (icount[m]*nideal != 0.0) - gr = histall[m][ibin] / (icount[m]*nideal); + vfrac = constant * (rupper*rupper*rupper - rlower*rlower*rlower); + if (vfrac * normfac != 0.0) + gr = histall[m][ibin] / (vfrac * normfac * icount[m]); else gr = 0.0; - ncoord += gr*nideal; + if (icount[m] != 0) + ncoord += gr * vfrac * normfac; array[ibin][1+2*m] = gr; array[ibin][2+2*m] = ncoord; } @@ -294,14 +306,17 @@ void ComputeRDF::compute_array() for (m = 0; m < npairs; m++) { ncoord = 0.0; + normfac = (icount[m] > 0) ? static_cast<double>(jcount[m]) + - static_cast<double>(duplicates[m])/icount[m] : 0.0; for (ibin = 0; ibin < nbin; ibin++) { rlower = ibin*delr; rupper = (ibin+1)*delr; - nideal = constant * (rupper*rupper - rlower*rlower) * jcount[m]; - if (icount[m]*nideal != 0.0) - gr = histall[m][ibin] / (icount[m]*nideal); + vfrac = constant * (rupper*rupper - rlower*rlower); + if (vfrac * normfac != 0.0) + gr = histall[m][ibin] / (vfrac * normfac * icount[m]); else gr = 0.0; - ncoord += gr*nideal; + if (icount[m] != 0) + ncoord += gr * vfrac * normfac; array[ibin][1+2*m] = gr; array[ibin][2+2*m] = ncoord; } diff --git a/src/compute_rdf.h b/src/compute_rdf.h index 794fcc9ee65219976c8afa65fc9d5d35fbc45f45..9d0956212bd18659a6a0e3a96f4eeb0e3088a0d1 100644 --- a/src/compute_rdf.h +++ b/src/compute_rdf.h @@ -45,6 +45,7 @@ class ComputeRDF : public Compute { int *typecount; int *icount,*jcount; + int *duplicates; class NeighList *list; // half neighbor list }; diff --git a/src/fix_ave_spatial.cpp b/src/fix_ave_spatial.cpp index 521f0956bdfe287dc98f84f7d6639b3c7c440c0b..62b7f057afc51752e49f50763f29d77dfe8eae7d 100644 --- a/src/fix_ave_spatial.cpp +++ b/src/fix_ave_spatial.cpp @@ -888,7 +888,7 @@ void FixAveSpatial::end_of_step() fflush(fp); if (overwrite) { long fileend = ftell(fp); - ftruncate(fileno(fp),fileend); + if (fileend > 0) ftruncate(fileno(fp),fileend); } } } diff --git a/src/fix_ave_time.cpp b/src/fix_ave_time.cpp index 9c3b9e6753f51b957b497c08c94ca1120cb700da..d502f6a9637759b403ae3d6881ff77565301ad67 100644 --- a/src/fix_ave_time.cpp +++ b/src/fix_ave_time.cpp @@ -907,7 +907,7 @@ void FixAveTime::invoke_vector(bigint ntimestep) fflush(fp); if (overwrite) { long fileend = ftell(fp); - ftruncate(fileno(fp),fileend); + if (fileend > 0) ftruncate(fileno(fp),fileend); } } } diff --git a/src/info.cpp b/src/info.cpp index 7b6117acb8d8f3bef15e11c43b7b1370560d9e48..c34eb401cd37a89f38c91ae3f531a92e8fca3f27 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -104,6 +104,7 @@ void Info::command(int narg, char **arg) ++idx; } else if ((idx+1 < narg) && (strncmp(arg[idx],"out",3) == 0) && (strncmp(arg[idx+1],"screen",3) == 0)) { + if ((out != screen) && (out != logfile)) fclose(out); out = screen; idx += 2; } else if ((idx+1 < narg) && (strncmp(arg[idx],"out",3) == 0) @@ -547,7 +548,7 @@ bool Info::is_available(const char *category, const char *name) int match = 0; if (strcmp(category,"command") == 0) { - if (input->command_map->find(name) != input->command_map->end()); + if (input->command_map->find(name) != input->command_map->end()) match = 1; } else if (strcmp(category,"compute") == 0) { diff --git a/src/pair.cpp b/src/pair.cpp index a87b674608b79e854f823b188e682338da19aea3..665615edd0c5e3fd07c54a5eebdd99676d9b80fc 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -119,6 +119,7 @@ Pair::~Pair() { num_tally_compute = 0; memory->sfree((void *)list_tally_compute); + list_tally_compute = NULL; if (copymode) return; diff --git a/src/velocity.cpp b/src/velocity.cpp index 8b83b007b55aee3a5ac02edff46afd6f6eed6932..37785af5c3c4555c6a0c0fa265ebe48d7390af61 100644 --- a/src/velocity.cpp +++ b/src/velocity.cpp @@ -364,7 +364,8 @@ void Velocity::create(double t_desired, int seed) // no-bias compute calculates temp only for new thermal velocities double t; - if (bias_flag == 0) t = temperature->compute_scalar(); + if ((bias_flag == 0) || (temperature_nobias == NULL)) + t = temperature->compute_scalar(); else t = temperature_nobias->compute_scalar(); rescale(t,t_desired);