diff --git a/src/GPU/gpu_extra.h b/src/GPU/gpu_extra.h index ddb0b5ceaa51cf1bae036d014f6aa24220bdc98d..56a4f15f1bff5a18ee050badf8acfb420c97b28b 100644 --- a/src/GPU/gpu_extra.h +++ b/src/GPU/gpu_extra.h @@ -61,13 +61,13 @@ namespace GPU_EXTRA { else error->all(FLERR,"Unknown error in GPU library"); } - }; + } inline void gpu_ready(LAMMPS_NS::Modify *modify, LAMMPS_NS::Error *error) { int ifix = modify->find_fix("package_gpu"); if (ifix < 0) error->all(FLERR,"The package gpu command is required for gpu styles"); - }; + } } #endif diff --git a/src/KIM/pair_kim.cpp b/src/KIM/pair_kim.cpp index 46e843158abe6649ba751b7480bba01e4ba94ebe..fe638214baabe8205172d78d898bd21ee75096e5 100644 --- a/src/KIM/pair_kim.cpp +++ b/src/KIM/pair_kim.cpp @@ -1264,15 +1264,15 @@ void *PairKIM::extract(const char *str, int &dim) int ier; int dummyint; int isIndexed = 0; - int maxLine = 1024; + const int MAXLINE = 1024; int rank; int validParam = 0; int numParams; - int *speciesIndex = new int[maxLine]; - char *paramStr = new char[maxLine]; + int *speciesIndex = new int[MAXLINE]; + char *paramStr = new char[MAXLINE]; char *paramName; char *indexStr; - char message[maxLine]; + char message[MAXLINE]; int offset; double* paramPtr; @@ -1354,7 +1354,7 @@ void *PairKIM::extract(const char *str, int &dim) } kim_error(__LINE__,"get_rank",kimerror); - int *shape = new int[maxLine]; + int *shape = new int[MAXLINE]; dummyint = (*pkim).get_shape(paramName, shape, &kimerror); if (kimerror == KIM_STATUS_FAIL) { diff --git a/src/KSPACE/msm.cpp b/src/KSPACE/msm.cpp index cc1ea027eec3a115ebc58400663863194ca3b93e..9f3221449bb2329923cfa9ed987beb6f26e58e3f 100644 --- a/src/KSPACE/msm.cpp +++ b/src/KSPACE/msm.cpp @@ -2261,7 +2261,7 @@ void MSM::restriction(int n) double ***qgrid2 = qgrid[n+1]; int k = 0; - int index[p+2]; + int *index = new int[p+2]; for (int nu=-p; nu<=p; nu++) { if (nu%2 == 0 && nu != 0) continue; phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]); @@ -2317,7 +2317,7 @@ void MSM::restriction(int n) } qgrid2[kp][jp][ip] += q2sum; } - + delete[] index; } /* ---------------------------------------------------------------------- @@ -2348,7 +2348,7 @@ void MSM::prolongation(int n) double ***v5grid2 = v5grid[n+1]; int k = 0; - int index[p+2]; + int *index = new int[p+2]; for (int nu=-p; nu<=p; nu++) { if (nu%2 == 0 && nu != 0) continue; phi1d[0][k] = compute_phi(nu*delxinv[n+1]/delxinv[n]); @@ -2420,7 +2420,7 @@ void MSM::prolongation(int n) } } - + delete[] index; } /* ---------------------------------------------------------------------- diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index e38a05c6edffb4eab8a6e34089c86762d94971de..b4f9c02206f926d39307b19317bd7e00b9cd16eb 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -310,10 +310,10 @@ double PairComb3::init_one(int i, int j) void PairComb3::read_lib() { - unsigned int maxlib = 1024; + const unsigned int MAXLIB = 1024; int i,j,k,l,nwords,m; int ii,jj,kk,ll,mm,iii; - char s[maxlib]; + char s[MAXLIB]; char **words = new char*[80]; // open libraray file on proc 0 @@ -327,8 +327,8 @@ void PairComb3::read_lib() } // read and store at the same time - fgets(s,maxlib,fp); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -339,7 +339,7 @@ void PairComb3::read_lib() ccutoff[4] = atof(words[4]); ccutoff[5] = atof(words[5]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -351,7 +351,7 @@ void PairComb3::read_lib() ch_a[5] = atof(words[5]); ch_a[6] = atof(words[6]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -359,7 +359,7 @@ void PairComb3::read_lib() nsplrad = atoi(words[1]); nspltor = atoi(words[2]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -367,7 +367,7 @@ void PairComb3::read_lib() maxy = atoi(words[1]); maxz = atoi(words[2]); - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -376,7 +376,7 @@ void PairComb3::read_lib() maxconj = atoi(words[2]); for (l=0; l<nsplpcn; l++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -385,14 +385,14 @@ void PairComb3::read_lib() dvmaxxcn[l] = atof(words[3]); } - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; ntab = atoi(words[0]); for (i=0; i<ntab+1; i++){ - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -405,7 +405,7 @@ void PairComb3::read_lib() for (i=0; i<maxx+1; i++) for (j=0; j<maxy+1; j++) for (k=0; k<maxz+1; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -423,7 +423,7 @@ void PairComb3::read_lib() for (i=0; i<maxx; i++) for (j=0; j<maxy; j++) for (k=0; k<maxz; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -432,7 +432,7 @@ void PairComb3::read_lib() jj = atoi(words[2]); kk = atoi(words[3]); for(iii=0; iii<2; iii++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -447,7 +447,7 @@ void PairComb3::read_lib() for (i=0; i<maxxc+1; i++) for (j=0; j<maxyc+1; j++) for (k=0; k<maxconj; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -465,7 +465,7 @@ void PairComb3::read_lib() for (i=0; i<maxxc; i++) for (j=0; j<maxyc; j++) for (k=0; k<maxconj-1; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -474,7 +474,7 @@ void PairComb3::read_lib() jj = atoi(words[2]); kk = atoi(words[3])-1; for (iii=0; iii<2; iii++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -489,7 +489,7 @@ void PairComb3::read_lib() for (i=0; i<maxxc+1; i++) for (j=0; j<maxyc+1; j++) for (k=0; k<maxconj; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -507,7 +507,7 @@ void PairComb3::read_lib() for (i=0; i<maxxc; i++) for (j=0; j<maxyc; j++) for (k=0; k<maxconj-1; k++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; @@ -516,7 +516,7 @@ void PairComb3::read_lib() jj = atoi(words[2]); kk = atoi(words[3])-1; for(iii=0; iii<2; iii++) { - fgets(s,maxlib,fp); + fgets(s,MAXLIB,fp); nwords = 0; words[nwords++] = strtok(s," \t\n\r\f"); while ((words[nwords++] = strtok(NULL," \t\n\r\f")))continue; diff --git a/src/MC/fix_gcmc.cpp b/src/MC/fix_gcmc.cpp index 08fe7de5cb4a12402698e60410e9936609d8bf49..6221e6d52c26b359d9efd7d87460a1ed3ceacaf3 100644 --- a/src/MC/fix_gcmc.cpp +++ b/src/MC/fix_gcmc.cpp @@ -1349,7 +1349,7 @@ void FixGCMC::attempt_molecule_insertion() MathExtra::quat_to_mat(quat,rotmat); double insertion_energy = 0.0; - bool procflag[natoms_per_molecule]; + bool *procflag = new bool[natoms_per_molecule]; for (int i = 0; i < natoms_per_molecule; i++) { MathExtra::matvec(rotmat,onemols[imol]->x[i],molcoords[i]); @@ -1472,6 +1472,7 @@ void FixGCMC::attempt_molecule_insertion() update_gas_atoms_list(); ninsertion_successes += 1.0; } + delete[] procflag; } /* ---------------------------------------------------------------------- @@ -1934,7 +1935,7 @@ void FixGCMC::attempt_molecule_deletion_full() grow_molecule_arrays(nmolq); int m = 0; - int tmpmask[atom->nlocal]; + int *tmpmask = new int[atom->nlocal]; for (int i = 0; i < atom->nlocal; i++) { if (atom->molecule[i] == deletion_molecule) { tmpmask[i] = atom->mask[i]; @@ -1982,6 +1983,7 @@ void FixGCMC::attempt_molecule_deletion_full() if (force->kspace) force->kspace->qsum_qsq(); } update_gas_atoms_list(); + delete[] tmpmask; } /* ---------------------------------------------------------------------- @@ -2426,9 +2428,9 @@ void FixGCMC::update_gas_atoms_list() for (int i = 0; i < nlocal; i++) maxmol = MAX(maxmol,molecule[i]); tagint maxmol_all; MPI_Allreduce(&maxmol,&maxmol_all,1,MPI_LMP_TAGINT,MPI_MAX,world); - double comx[maxmol_all]; - double comy[maxmol_all]; - double comz[maxmol_all]; + double *comx = new double[maxmol_all]; + double *comy = new double[maxmol_all]; + double *comz = new double[maxmol_all]; for (int imolecule = 0; imolecule < maxmol_all; imolecule++) { for (int i = 0; i < nlocal; i++) { if (molecule[i] == imolecule) { @@ -2458,7 +2460,9 @@ void FixGCMC::update_gas_atoms_list() } } } - + delete[] comx; + delete[] comy; + delete[] comz; } else { for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { diff --git a/src/PYTHON/fix_python_move.cpp b/src/PYTHON/fix_python_move.cpp index 7331a75db68448ed1b3dbd6a892981637e851daa..b330ab79450b805e595e6b5d52710722d962ee32 100644 --- a/src/PYTHON/fix_python_move.cpp +++ b/src/PYTHON/fix_python_move.cpp @@ -47,7 +47,7 @@ FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) : PyGILState_STATE gstate = PyGILState_Ensure(); // add current directory to PYTHONPATH - PyObject * py_path = PySys_GetObject("path"); + PyObject * py_path = PySys_GetObject((char *)"path"); PyList_Append(py_path, PY_STRING_FROM_STRING(".")); @@ -136,7 +136,7 @@ void FixPythonMove::init() { PyGILState_STATE gstate = PyGILState_Ensure(); PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_init = PyObject_GetAttrString(py_move_obj,"init"); + PyObject *py_init = PyObject_GetAttrString(py_move_obj,(char *)"init"); if (!py_init) { PyErr_Print(); PyErr_Clear(); diff --git a/src/REPLICA/neb.cpp b/src/REPLICA/neb.cpp index 35225b3c1e2bd6f192896a96294bc42b4477c76c..c9aedf74018409a5913ed1055d554775e4704746 100644 --- a/src/REPLICA/neb.cpp +++ b/src/REPLICA/neb.cpp @@ -303,7 +303,7 @@ void NEB::run() update->minimize->setup(); if (me_universe == 0) { - if (uscreen) + if (uscreen) { if (verbose) { fprintf(uscreen,"Step MaxReplicaForce MaxAtomForce " "GradV0 GradV1 GradVc EBF EBR RDT " @@ -317,7 +317,8 @@ void NEB::run() "EBF EBR RDT " "RD1 PE1 RD2 PE2 ... RDN PEN\n"); } - if (ulogfile) + } + if (ulogfile) { if (verbose) { fprintf(ulogfile,"Step MaxReplicaForce MaxAtomForce " "GradV0 GradV1 GradVc EBF EBR RDT " @@ -331,6 +332,7 @@ void NEB::run() "EBF EBR RDT " "RD1 PE1 RD2 PE2 ... RDN PEN\n"); } + } } print_status(); @@ -588,7 +590,7 @@ void NEB::print_status() MPI_Allgather(&fnorminf,1,MPI_DOUBLE,&fmaxatomInRepl[0],1,MPI_DOUBLE,roots); } - double one[numall]; + double one[7]; one[0] = fneb->veng; one[1] = fneb->plen; one[2] = fneb->nlen; diff --git a/src/RIGID/fix_rigid.cpp b/src/RIGID/fix_rigid.cpp index 554412330c955fd187dbb61ee9857c849c1c65ca..3d9e24ced96d2a274f782177508b93fedfe99aeb 100644 --- a/src/RIGID/fix_rigid.cpp +++ b/src/RIGID/fix_rigid.cpp @@ -2342,7 +2342,7 @@ void FixRigid::write_restart_file(char *file) sprintf(outfile,"%s.rigid",file); FILE *fp = fopen(outfile,"w"); if (fp == NULL) { - char str[128]; + char str[192]; sprintf(str,"Cannot open fix rigid restart file %s",outfile); error->one(FLERR,str); } diff --git a/src/USER-DPD/fix_rx.cpp b/src/USER-DPD/fix_rx.cpp index b8b002a7fa11df5e5a2f5fe93ba3ad82be8f1c70..c370f8abe6ebe0fb35fae63730a909ae44dcf335 100644 --- a/src/USER-DPD/fix_rx.cpp +++ b/src/USER-DPD/fix_rx.cpp @@ -260,6 +260,7 @@ void FixRX::post_constructor() error->all(FLERR,"fix rx cannot be combined with fix property/atom"); char **tmpspecies = new char*[maxspecies]; + int tmpmaxstrlen = 0; for(int jj=0; jj < maxspecies; jj++) tmpspecies[jj] = NULL; @@ -320,6 +321,7 @@ void FixRX::post_constructor() error->all(FLERR,"Exceeded the maximum number of species permitted in fix rx."); tmpspecies[nUniqueSpecies] = new char[strlen(word)+1]; strcpy(tmpspecies[nUniqueSpecies],word); + tmpmaxstrlen = MAX(tmpmaxstrlen,strlen(word)); nUniqueSpecies++; } word = strtok(NULL, " \t\n\r\f"); @@ -354,9 +356,9 @@ void FixRX::post_constructor() newarg2[0] = id_fix_species_old; newarg2[1] = group->names[igroup]; newarg2[2] = (char *) "property/atom"; + char *str1 = new char[tmpmaxstrlen+3]; + char *str2 = new char[tmpmaxstrlen+6]; for(int ii=0; ii<nspecies; ii++){ - char str1[2+strlen(tmpspecies[ii])+1]; - char str2[2+strlen(tmpspecies[ii])+4]; strcpy(str1,"d_"); strcpy(str2,"d_"); strncat(str1,tmpspecies[ii],strlen(tmpspecies[ii])); @@ -367,6 +369,8 @@ void FixRX::post_constructor() strcpy(newarg[ii+3],str1); strcpy(newarg2[ii+3],str2); } + delete[] str1; + delete[] str2; newarg[nspecies+3] = (char *) "ghost"; newarg[nspecies+4] = (char *) "yes"; newarg2[nspecies+3] = (char *) "ghost"; diff --git a/src/USER-DRUDE/fix_drude_transform.cpp b/src/USER-DRUDE/fix_drude_transform.cpp index 29c1ff88211085fb9769e3d292b6bc3352d9d02d..34742a0683311a8e1286b4e122897434d845209b 100644 --- a/src/USER-DRUDE/fix_drude_transform.cpp +++ b/src/USER-DRUDE/fix_drude_transform.cpp @@ -75,7 +75,7 @@ void FixDrudeTransform<inverse>::setup(int) { if (!rmass) { if (!mcoeff) mcoeff = new double[ntypes+1]; - double mcoeff_loc[ntypes+1]; + double *mcoeff_loc = new double[ntypes+1]; for (int itype=0; itype<=ntypes; itype++) mcoeff_loc[itype] = 2.; // an impossible value: mcoeff is at most 1. for (int i=0; i<nlocal; i++) { if (drudetype[type[i]] == DRUDE_TYPE) { @@ -95,6 +95,7 @@ void FixDrudeTransform<inverse>::setup(int) { // mcoeff is 2 for non polarizable // 0 < mcoeff < 1 for drude // mcoeff < 0 for core + delete[] mcoeff_loc; } } @@ -313,6 +314,6 @@ void FixDrudeTransform<inverse>::unpack_forward_comm(int n, int first, double *b } /* ---------------------------------------------------------------------- */ -template class FixDrudeTransform<false>; -template class FixDrudeTransform<true>; +template class LAMMPS_NS::FixDrudeTransform<false>; +template class LAMMPS_NS::FixDrudeTransform<true>; diff --git a/src/USER-LB/fix_lb_momentum.cpp b/src/USER-LB/fix_lb_momentum.cpp index 6cf2d3bfd09a5b8f857a44cc73ced2f3ad78c182..490b95ef719a132448c2925ba2879c9f1874f163 100644 --- a/src/USER-LB/fix_lb_momentum.cpp +++ b/src/USER-LB/fix_lb_momentum.cpp @@ -102,8 +102,8 @@ void FixLbMomentum::end_of_step() double masslb,masslbloc; double momentumlbloc[3],momentumlb[3]; double vcmtotal[3]; - int numvel = fix_lb_fluid->numvel; - double etacov[numvel]; + const int numvel = fix_lb_fluid->numvel; + double etacov[19]; // = double etacov[numvel]; i.e. 15 or 19 double rho; if (linear) { diff --git a/src/USER-MEAMC/meam.h b/src/USER-MEAMC/meam.h index 8a439a2118394c01bc6bb6787152e6e4ec587d68..42fd722e016ce4dce882599cb1ff37fe24dd7422 100644 --- a/src/USER-MEAMC/meam.h +++ b/src/USER-MEAMC/meam.h @@ -255,5 +255,5 @@ static inline double fdiv_zero(const double n, const double d) { return n / d; } -}; +} #endif diff --git a/src/USER-MESO/pair_edpd.cpp b/src/USER-MESO/pair_edpd.cpp index f1d9c215b4207670e657c7fb2249b590235b23b9..351637a842018c6469c09a1929e5552487c20695 100644 --- a/src/USER-MESO/pair_edpd.cpp +++ b/src/USER-MESO/pair_edpd.cpp @@ -59,7 +59,6 @@ static const char cite_pair_edpd[] = " volume = {51},\n" " pages = {11038--11040}\n" "}\n\n"; -; /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MESO/pair_tdpd.cpp b/src/USER-MESO/pair_tdpd.cpp index 0d0d2a3a0ad5ab7f7fd6545aaa07f91e2c5f2abe..b8bbf6d622f51e16f15813cbeb1af08a692adceb 100644 --- a/src/USER-MESO/pair_tdpd.cpp +++ b/src/USER-MESO/pair_tdpd.cpp @@ -280,7 +280,9 @@ void PairTDPD::coeff(int narg, char **arg) double power_one = force->numeric(FLERR,arg[4]); double cut_one = force->numeric(FLERR,arg[5]); double cutcc_one = force->numeric(FLERR,arg[6]); - double kappa_one[cc_species],epsilon_one[cc_species],powercc_one[cc_species]; + double *kappa_one = new double[cc_species]; + double *epsilon_one = new double[cc_species]; + double *powercc_one = new double[cc_species]; for(int k=0; k<cc_species; k++) { kappa_one[k] = force->numeric(FLERR,arg[7+3*k]); epsilon_one[k] = force->numeric(FLERR,arg[8+3*k]); @@ -304,6 +306,9 @@ void PairTDPD::coeff(int narg, char **arg) setflag[i][j] = 1; count++; } + delete[] kappa_one; + delete[] epsilon_one; + delete[] powercc_one; if (count == 0) error->all(FLERR,"Incorrect args for pair coefficients"); } diff --git a/src/USER-MISC/compute_basal_atom.cpp b/src/USER-MISC/compute_basal_atom.cpp index 1da43a6bafb18693cfbb70450d2a68a53f14820c..4d8627a11fb66534b0e982413790156d4efaf524 100644 --- a/src/USER-MISC/compute_basal_atom.cpp +++ b/src/USER-MISC/compute_basal_atom.cpp @@ -204,8 +204,11 @@ void ComputeBasalAtom::compute_peratom() double bond_angle; double norm_j, norm_k; chi[0] = chi[1] = chi[2] = chi[3] = chi[4] = chi[5] = chi[6] = chi[7] = 0; - double x_ij, y_ij, z_ij, x_ik, y_ik, z_ik,x3[n0],y3[n0],z3[n0], - xmean5, ymean5, zmean5, xmean6, ymean6, zmean6, xmean7, ymean7, zmean7; + double x_ij, y_ij, z_ij, x_ik, y_ik, z_ik, xmean5, ymean5, zmean5, + xmean6, ymean6, zmean6, xmean7, ymean7, zmean7; + double *x3 = new double[n0]; + double *y3 = new double[n0]; + double *z3 = new double[n0]; for (j = 0; j < n0; j++) { x_ij = x[i][0]-x[nearest_n0[j]][0]; y_ij = x[i][1]-x[nearest_n0[j]][1]; @@ -411,9 +414,12 @@ void ComputeBasalAtom::compute_peratom() } } } - } - //if there are less than two ~180 degree bond angles, the algorithm returns null - else BPV[i][0] = BPV[i][1] = BPV[i][2] = 0.0; + //if there are less than two ~180 degree bond angles, the algorithm returns null + } else BPV[i][0] = BPV[i][1] = BPV[i][2] = 0.0; + + delete[] x3; + delete[] y3; + delete[] z3; //normalize BPV: double Mag = sqrt(BPV[i][0]*BPV[i][0] + diff --git a/src/USER-MISC/fix_filter_corotate.cpp b/src/USER-MISC/fix_filter_corotate.cpp index a5f0e5704116c78b88793c35722b5f208ef74269..91c70335133e4fdf6a37c0ec212d5d38dc9501fb 100644 --- a/src/USER-MISC/fix_filter_corotate.cpp +++ b/src/USER-MISC/fix_filter_corotate.cpp @@ -1527,7 +1527,10 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) //derivative: //dn1dx: - double sum1[3][3*N]; + + double **sum1; + memory->create(sum1,3,3*N,"filter_corotate:sum1"); + for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) sum1[i][j] = 0; @@ -1564,10 +1567,12 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn1dx[i][j] = norm1*sum; } } + memory->destroy(sum1); //dn2dx: norm2 * I3mn2n2T * (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) - double sum2[3][3*N]; + double **sum2; + memory->create(sum2,3,3*N,"filter_corotate:sum2"); for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) sum2[i][j] = 0; @@ -1618,7 +1623,8 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) //dn2dx: norm2 * I3mn2n2T * (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) //sum3 = (I3mn1n1T*sum2 - rkn1pn1rk*dn1dx) - double sum3[3][3*N]; + double **sum3; + memory->create(sum3,3,3*N,"filter_corotate:sum3"); for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) { double sum = 0; @@ -1627,6 +1633,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) sum3[i][j] = sum; } + memory->destroy(sum2); //dn2dx = norm2 * I3mn2n2T * sum3 for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) { @@ -1636,6 +1643,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn2dx[i][j] = norm2*sum; } + memory->destroy(sum3); //dn3dx = norm3 * I3mn3n3T * cross double I3mn3n3T[3][3]; //(I_3 - n3n3T) for (int i=0; i<3; i++) { @@ -1644,7 +1652,8 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) I3mn3n3T[i][i] += 1.0; } - double cross[3][3*N]; + double **cross; + memory->create(cross,3,3*N,"filter_corotate:cross"); for (int j=0; j<3*N; j++) { cross[0][j] = dn1dx[1][j]*n2[2] -dn1dx[2][j]*n2[1] + @@ -1663,6 +1672,7 @@ void FixFilterCorotate::general_cluster(int index, int index_in_list) dn3dx[i][j] = norm3*sum; } + memory->destroy(cross); for (int l=0; l<N; l++) for (int i=0; i<3; i++) for (int j=0; j<3*N; j++) diff --git a/src/USER-MISC/fix_gle.cpp b/src/USER-MISC/fix_gle.cpp index 5857bafc2ef9fb07062812b3992d1460d969fd3c..584b33bfe7da1bc93d041ee15388d7e72ebe36d5 100644 --- a/src/USER-MISC/fix_gle.cpp +++ b/src/USER-MISC/fix_gle.cpp @@ -44,6 +44,7 @@ using namespace FixConst; enum{NOBIAS,BIAS}; enum{CONSTANT,EQUAL,ATOM}; + //#define GLE_DEBUG 1 #define MAXLINE 1024 @@ -62,35 +63,37 @@ namespace GLE { //"stabilized" cholesky decomposition. does a LDL^t decomposition, then sets to zero the negative diagonal elements and gets MM^t void StabCholesky(int n, const double* MMt, double* M) { - double L[n*n], D[n]; - - int i,j,k; - for(i=0; i<n; ++i) D[i]=0.; - for(i=0; i<n*n; ++i) L[i]=0.; - - for(i=0; i<n; ++i) - { - L[midx(n,i,i)]=1.; - for (j=0; j<i; j++) - { - L[midx(n,i,j)]=MMt[midx(n,i,j)]; - for (k=0; k<j; ++k) L[midx(n,i,j)]-=L[midx(n,i,k)]*L[midx(n,j,k)]*D[k]; - if (D[j]!=0.) L[midx(n,i,j)]/=D[j]; - else L[midx(n,i,j)]=0.0; - } - D[i]=MMt[midx(n,i,i)]; - for (k=0; k<i; ++k) D[i]-=L[midx(n,i,k)]*L[midx(n,i,k)]*D[k]; + double *L = new double[n*n]; + double *D = new double[n]; + + int i,j,k; + for (i=0; i<n; ++i) D[i]=0.0; + for (i=0; i<n*n; ++i) L[i]=0.0; + + for (i=0; i<n; ++i) { + L[midx(n,i,i)]=1.0; + for (j=0; j<i; j++) { + L[midx(n,i,j)]=MMt[midx(n,i,j)]; + for (k=0; k<j; ++k) L[midx(n,i,j)]-=L[midx(n,i,k)]*L[midx(n,j,k)]*D[k]; + if (D[j]!=0.) L[midx(n,i,j)]/=D[j]; + else L[midx(n,i,j)]=0.0; } + D[i]=MMt[midx(n,i,i)]; + for (k=0; k<i; ++k) D[i]-=L[midx(n,i,k)]*L[midx(n,i,k)]*D[k]; + } - for(i=0; i<n; ++i) - { + for (i=0; i<n; ++i) { #ifdef GLE_DEBUG - if (D[i]<0) fprintf(stderr,"GLE Cholesky: Negative diagonal term %le, has been set to zero.\n", D[i]); + if (D[i]<0) fprintf(stderr,"GLE Cholesky: Negative diagonal term %le, has been set to zero.\n", D[i]); #endif - D[i]=(D[i]>0.?sqrt(D[i]):0.); - } + D[i]=(D[i]>0.0) ? sqrt(D[i]):0.0; + } + + for (i=0; i<n; ++i) + for (j=0; j<n; j++) M[midx(n,i,j)]=L[midx(n,i,j)]*D[j]; - for(i=0; i<n; ++i) for (j=0; j<n; j++) M[midx(n,i,j)]=L[midx(n,i,j)]*D[j]; + delete[] D; + delete[] L; } void MyMult(int n, int m, int r, const double* A, const double* B, double* C, double cf=0.0) @@ -162,26 +165,32 @@ void MyPrint(int n, const double* A) //matrix exponential by scaling and squaring. void MatrixExp(int n, const double* M, double* EM, int j=8, int k=8) { - double tc[j+1], SM[n*n], TMP[n*n]; - double onetotwok=pow(0.5,1.0*k); + double *tc = new double[j+1]; + double *SM = new double[n*n]; + double *TMP = new double[n*n]; + double onetotwok=pow(0.5,1.0*k); - tc[0]=1; - for (int i=0; i<j; ++i) tc[i+1]=tc[i]/(i+1.0); + tc[0]=1; + for (int i=0; i<j; ++i) tc[i+1]=tc[i]/(i+1.0); - for (int i=0; i<n*n; ++i) { SM[i]=M[i]*onetotwok; EM[i]=0.0; TMP[i]=0.0; } + for (int i=0; i<n*n; ++i) { SM[i]=M[i]*onetotwok; EM[i]=0.0; TMP[i]=0.0; } - for (int i=0; i<n; ++i) EM[midx(n,i,i)]=tc[j]; + for (int i=0; i<n; ++i) EM[midx(n,i,i)]=tc[j]; - //taylor exp of scaled matrix - for (int p=j-1; p>=0; p--) - { - MyMult(n, n, n, SM, EM, TMP); for (int i=0; i<n*n; ++i) EM[i]=TMP[i]; - for (int i=0; i<n; ++i) EM[midx(n,i,i)]+=tc[p]; - } + //taylor exp of scaled matrix + for (int p=j-1; p>=0; p--) { + MyMult(n, n, n, SM, EM, TMP); for (int i=0; i<n*n; ++i) EM[i]=TMP[i]; + for (int i=0; i<n; ++i) EM[midx(n,i,i)]+=tc[p]; + } - for (int p=0; p<k; p++) - { MyMult(n, n, n, EM, EM, TMP); for (int i=0; i<n*n; ++i) EM[i]=TMP[i]; } + for (int p=0; p<k; p++) { + MyMult(n, n, n, EM, EM, TMP); + for (int i=0; i<n*n; ++i) EM[i]=TMP[i]; + } + delete[] tc; + delete[] SM; + delete[] TMP; } } diff --git a/src/USER-MISC/fix_ipi.cpp b/src/USER-MISC/fix_ipi.cpp index 090a330af66ff0fed4e87bd58e1ac7363067ec97..c4750ce49e211b22c6f3b1ddc8e8d812f1843402 100644 --- a/src/USER-MISC/fix_ipi.cpp +++ b/src/USER-MISC/fix_ipi.cpp @@ -428,7 +428,7 @@ void FixIPI::final_integrate() int nat=bsize/3; double **f= atom->f; - double lbuf[bsize]; + double *lbuf = new double[bsize]; // reassembles the force vector from the local arrays int nlocal = atom->nlocal; @@ -440,6 +440,7 @@ void FixIPI::final_integrate() lbuf[3*(atom->tag[i]-1)+2]=f[i][2]*forceconv; } MPI_Allreduce(lbuf,buffer,bsize,MPI_DOUBLE,MPI_SUM,world); + delete[] lbuf; for (int i = 0; i < 9; ++i) vir[i]=0.0; diff --git a/src/USER-MISC/pair_lj_sf_dipole_sf.cpp b/src/USER-MISC/pair_lj_sf_dipole_sf.cpp index cc92bfc30f9f906b7202c266df8d015163122366..523b2ca71a7b466f35939a67c7b5e9ac77501cac 100644 --- a/src/USER-MISC/pair_lj_sf_dipole_sf.cpp +++ b/src/USER-MISC/pair_lj_sf_dipole_sf.cpp @@ -539,7 +539,7 @@ double PairLJSFDipoleSF::single(int i, int j, int itype, int jtype, double rsq, double &fforce) { double r2inv,r6inv; - double pdotp,pidotr,pjdotr,pre1,delx,dely,delz; + double pdotp,pidotr,pjdotr,delx,dely,delz; double rinv, r3inv,r5inv, rcutlj2inv, rcutcoul2inv,rcutlj6inv; double qtmp,xtmp,ytmp,ztmp,bfac,pqfac,qpfac, ecoul, evdwl; diff --git a/src/USER-PHONON/fix_phonon.cpp b/src/USER-PHONON/fix_phonon.cpp index cf561178926cb00be0740eb5fd7348d7243286e7..3a37c67a3871f1e044ba568e256c8c57a56620c8 100644 --- a/src/USER-PHONON/fix_phonon.cpp +++ b/src/USER-PHONON/fix_phonon.cpp @@ -668,7 +668,8 @@ void FixPhonon::postprocess( ) } // to get Phi = KT.G^-1; normalization of FFTW data is done here - double boltz = force->boltz, kbtsqrt[sysdim], TempAve = 0.; + double boltz = force->boltz, TempAve = 0.; + double *kbtsqrt = new double[sysdim]; double TempFac = inv_neval * inv_nTemp; double NormFac = TempFac * double(ntotal); @@ -692,7 +693,7 @@ void FixPhonon::postprocess( ) MPI_Gatherv(Phi_q[0],mynq*fft_dim2*2,MPI_DOUBLE,Phi_all[0],recvcnts,displs,MPI_DOUBLE,0,world); // to collect all basis info and averaged it on root - double basis_root[fft_dim]; + double *basis_root = new double[fft_dim]; if (fft_dim > sysdim) MPI_Reduce(&basis[1][0], &basis_root[sysdim], fft_dim-sysdim, MPI_DOUBLE, MPI_SUM, 0, world); if (me == 0){ // output dynamic matrix by root @@ -772,7 +773,8 @@ void FixPhonon::postprocess( ) } fflush(flog); } - + delete[] kbtsqrt; + delete[] basis_root; } // end of postprocess /* ---------------------------------------------------------------------- diff --git a/src/USER-SMD/fix_smd_integrate_ulsph.h b/src/USER-SMD/fix_smd_integrate_ulsph.h index ea4f46ce530ea0d40606c1c3aa157707f2a91e5a..9d954bf529aaf00ddf1df307d7f3a0b1d012538f 100644 --- a/src/USER-SMD/fix_smd_integrate_ulsph.h +++ b/src/USER-SMD/fix_smd_integrate_ulsph.h @@ -48,7 +48,7 @@ class FixSMDIntegrateUlsph : public Fix { private: class NeighList *list; protected: - double dtv,dtf, vlimit, vlimitsq;; + double dtv,dtf, vlimit, vlimitsq; int mass_require; bool xsphFlag; bool adjust_radius_flag; diff --git a/src/USER-UEF/fix_nh_uef.h b/src/USER-UEF/fix_nh_uef.h index 43f5bb46a9f2c97c6f3a5f784506d3c9839aed56..0629db5aa176c96e74271aef1b43e08383e0279b 100644 --- a/src/USER-UEF/fix_nh_uef.h +++ b/src/USER-UEF/fix_nh_uef.h @@ -23,7 +23,7 @@ namespace LAMMPS_NS { // forward declaration namespace UEF_utils { class UEFBox; - }; + } class FixNHUef : public FixNH { public: diff --git a/src/image.cpp b/src/image.cpp index 599ac4a09132c1917f087cf2c89d6270dd696519..301a2af88f23588dfcdea129fe2c283ae6269cb0 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -1065,7 +1065,7 @@ void Image::write_PNG(FILE *fp) png_set_text(png_ptr,info_ptr,text_ptr,1); png_write_info(png_ptr,info_ptr); - png_bytep row_pointers[height]; + png_bytep *row_pointers = new png_bytep[height]; for (int i=0; i < height; ++i) row_pointers[i] = (png_bytep) &writeBuffer[(height-i-1)*3*width]; @@ -1073,6 +1073,7 @@ void Image::write_PNG(FILE *fp) png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); + delete[] row_pointers; #endif } diff --git a/src/library.cpp b/src/library.cpp index 865bf2a0a5d41bda4e5f5c8ec349e1b2903b96af..0162c560cea7e21b66cc759a481aae6420c86d51 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -933,7 +933,7 @@ void lammps_gather_atoms_concat(void *ptr, char *name, BEGIN_CAPTURE { - int i,j,offset; + int i,offset; // error if tags are not defined // NOTE: test that name = image or ids is not a 64-bit int in code? @@ -975,7 +975,6 @@ void lammps_gather_atoms_concat(void *ptr, char *name, lmp->memory->create(copy,count*natoms,"lib/gather:copy"); for (i = 0; i < count*natoms; i++) copy[i] = 0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { @@ -1117,7 +1116,6 @@ void lammps_gather_atoms_subset(void *ptr, char *name, lmp->memory->create(copy,count*ndata,"lib/gather:copy"); for (i = 0; i < count*ndata; i++) copy[i] = 0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { @@ -1163,7 +1161,6 @@ void lammps_gather_atoms_subset(void *ptr, char *name, lmp->memory->create(copy,count*ndata,"lib/gather:copy"); for (i = 0; i < count*ndata; i++) copy[i] = 0.0; - tagint *tag = lmp->atom->tag; int nlocal = lmp->atom->nlocal; if (count == 1) { diff --git a/src/molecule.cpp b/src/molecule.cpp index b03142e98498eeffeeb106965098fc925ef89634..56e56dab2cd16ef45c9c6068161c29a4815d51ca 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -1111,7 +1111,7 @@ void Molecule::special_generate() { int newton_bond = force->newton_bond; tagint atom1,atom2; - int count[natoms]; + int *count = new int[natoms]; // temporary array for special atoms @@ -1197,6 +1197,7 @@ void Molecule::special_generate() } } } + delete[] count; maxspecial = 0; for (int i = 0; i < natoms; i++)