Commit aa1ce09b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

more cleanup, checks and generalization of QEQ parameter file parsing

parent 44ccdb86
Loading
Loading
Loading
Loading
+22 −17
Original line number Diff line number Diff line
@@ -692,11 +692,13 @@ void FixQEq::vector_add( double* dest, double c, double* v, int k )

void FixQEq::read_file(char *file)
{
  int itype,ntypes;
  int i;
  int params_per_line = 6;
  char **words = new char*[params_per_line+1];

  ntypes = atom->ntypes;
  int ntypes = atom->ntypes;
  int *setflag = new int[ntypes+1];
  for (i=0; i < params_per_line; ++i) setflag[i] = 0;

  memory->create(chi,ntypes+1,"qeq:chi");
  memory->create(eta,ntypes+1,"qeq:eta");
@@ -719,10 +721,10 @@ void FixQEq::read_file(char *file)
  // read each line out of file, skipping blank lines or leading '#'
  // store line of params if all 3 element tags are in element list

  int n,nwords,ielement,eof;
  int n,nwords,eof,nlo,nhi;
  char line[MAXLINE],*ptr;

  eof = ielement = 0;
  eof = 0;

  while (1) {
    if (comm->me == 0) {
@@ -737,10 +739,6 @@ void FixQEq::read_file(char *file)
    MPI_Bcast(&n,1,MPI_INT,0,world);
    MPI_Bcast(line,n,MPI_CHAR,0,world);

    ielement ++;
    if (ielement > ntypes)
      error->all(FLERR,"Invalid fix qeq parameter file");

    // strip comment, skip line if blank

    if ((ptr = strchr(line,'#'))) *ptr = '\0';
@@ -752,21 +750,28 @@ void FixQEq::read_file(char *file)
    if (nwords < 6)
      error->all(FLERR,"Invalid fix qeq parameter file");


    // words = ptrs to first 6 words in line

    for (n=0, words[n] = strtok(line," \t\n\r\f");
         n < 6;
         words[++n] = strtok(NULL," \t\n\r\f"));

    itype = force->inumeric(FLERR,words[0]);
    if ((itype < 1) || (itype > atom->ntypes))
      error->all(FLERR,"Invalid fix qeq parameter file");
    chi[itype]   = force->numeric(FLERR,words[1]);
    eta[itype]   = force->numeric(FLERR,words[2]);
    gamma[itype] = force->numeric(FLERR,words[3]);
    zeta[itype]  = force->numeric(FLERR,words[4]);
    zcore[itype] = force->numeric(FLERR,words[5]);
    force->bounds(FLERR,words[0],ntypes,nlo,nhi);
    for (n=nlo; n <=nhi; ++n) {
      chi[n]     = force->numeric(FLERR,words[1]);
      eta[n]     = force->numeric(FLERR,words[2]);
      gamma[n]   = force->numeric(FLERR,words[3]);
      zeta[n]    = force->numeric(FLERR,words[4]);
      zcore[n]   = force->numeric(FLERR,words[5]);
      setflag[n] = 1;
    }
  }

  // check if all types are set
  for (n=1; n <= ntypes; ++n)
    if (setflag[n] == 0)
      error->all(FLERR,"Invalid fix qeq parameter file");

  delete [] words;
  delete [] setflag;
}