Merge pull request #889 from akohlmey/cplusplus-compliance

Collected changes to restore C++ standard compliance
This commit is contained in:
Steve Plimpton
2018-05-07 10:42:22 -06:00
committed by GitHub
25 changed files with 153 additions and 111 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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;
}
/* ----------------------------------------------------------------------

View File

@ -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;

View File

@ -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) {

View File

@ -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();

View File

@ -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;

View File

@ -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);
}

View File

@ -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";

View File

@ -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>;

View File

@ -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) {

View File

@ -255,5 +255,5 @@ static inline double fdiv_zero(const double n, const double d) {
return n / d;
}
};
}
#endif

View File

@ -59,7 +59,6 @@ static const char cite_pair_edpd[] =
" volume = {51},\n"
" pages = {11038--11040}\n"
"}\n\n";
;
/* ---------------------------------------------------------------------- */

View File

@ -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");
}

View File

@ -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] +

View File

@ -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++)

View File

@ -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];
double *L = new double[n*n];
double *D = new double[n];
int i,j,k;
for(i=0; i<n; ++i) D[i]=0.;
for(i=0; i<n*n; ++i) L[i]=0.;
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.;
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) {
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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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
/* ----------------------------------------------------------------------

View File

@ -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;

View File

@ -23,7 +23,7 @@ namespace LAMMPS_NS {
// forward declaration
namespace UEF_utils {
class UEFBox;
};
}
class FixNHUef : public FixNH {
public:

View File

@ -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
}

View File

@ -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) {

View File

@ -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++)