Unverified Commit 43f6fa4b authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #2136 from rbberger/refactor-reading

Refactor value parsing code segments and add dump tests
parents d63f3d87 c7f8a6d1
Loading
Loading
Loading
Loading
+87 −0
Original line number Diff line number Diff line
@@ -166,8 +166,83 @@ void DumpAtom::write_data(int n, double *mybuf)

/* ---------------------------------------------------------------------- */

void DumpAtom::format_magic_string_binary()
{
  // use negative ntimestep as marker for new format
  bigint fmtlen = strlen(MAGIC_STRING);
  bigint marker = -fmtlen;
  fwrite(&marker, sizeof(bigint), 1, fp);
  fwrite(MAGIC_STRING, sizeof(char), fmtlen, fp);
}

/* ---------------------------------------------------------------------- */

void DumpAtom::format_endian_binary()
{
  int endian = ENDIAN;
  fwrite(&endian, sizeof(int), 1, fp);
}

/* ---------------------------------------------------------------------- */

void DumpAtom::format_revision_binary()
{
  int revision = FORMAT_REVISION;
  fwrite(&revision, sizeof(int), 1, fp);
}

/* ---------------------------------------------------------------------- */

void DumpAtom::header_unit_style_binary()
{
  int len = 0;
  if (unit_flag && !unit_count) {
    ++unit_count;
    len = strlen(update->unit_style);
    fwrite(&len, sizeof(int), 1, fp);
    fwrite(update->unit_style, sizeof(char), len, fp);
  } else {
    fwrite(&len, sizeof(int), 1, fp);
  }
}

/* ---------------------------------------------------------------------- */

void DumpAtom::header_columns_binary()
{
  int len = strlen(columns);
  fwrite(&len, sizeof(int), 1, fp);
  fwrite(columns, sizeof(char), len, fp);
}

/* ---------------------------------------------------------------------- */

void DumpAtom::header_time_binary()
{
  char flag = time_flag ? 1 : 0;
  fwrite(&flag, sizeof(char), 1, fp);

  if (time_flag) {
    double t = compute_time();
    fwrite(&t, sizeof(double), 1, fp);
  }
}

/* ---------------------------------------------------------------------- */

void DumpAtom::header_format_binary()
{
  format_magic_string_binary();
  format_endian_binary();
  format_revision_binary();
}

/* ---------------------------------------------------------------------- */

void DumpAtom::header_binary(bigint ndump)
{
  header_format_binary();

  fwrite(&update->ntimestep,sizeof(bigint),1,fp);
  fwrite(&ndump,sizeof(bigint),1,fp);
  fwrite(&domain->triclinic,sizeof(int),1,fp);
@@ -179,6 +254,11 @@ void DumpAtom::header_binary(bigint ndump)
  fwrite(&boxzlo,sizeof(double),1,fp);
  fwrite(&boxzhi,sizeof(double),1,fp);
  fwrite(&size_one,sizeof(int),1,fp);

  header_unit_style_binary();
  header_time_binary();
  header_columns_binary();

  if (multiproc) fwrite(&nclusterprocs,sizeof(int),1,fp);
  else fwrite(&nprocs,sizeof(int),1,fp);
}
@@ -187,6 +267,8 @@ void DumpAtom::header_binary(bigint ndump)

void DumpAtom::header_binary_triclinic(bigint ndump)
{
  header_format_binary();

  fwrite(&update->ntimestep,sizeof(bigint),1,fp);
  fwrite(&ndump,sizeof(bigint),1,fp);
  fwrite(&domain->triclinic,sizeof(int),1,fp);
@@ -201,6 +283,11 @@ void DumpAtom::header_binary_triclinic(bigint ndump)
  fwrite(&boxxz,sizeof(double),1,fp);
  fwrite(&boxyz,sizeof(double),1,fp);
  fwrite(&size_one,sizeof(int),1,fp);

  header_unit_style_binary();
  header_time_binary();
  header_columns_binary();

  if (multiproc) fwrite(&nclusterprocs,sizeof(int),1,fp);
  else fwrite(&nprocs,sizeof(int),1,fp);
}
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ class DumpAtom : public Dump {
 public:
  DumpAtom(LAMMPS *, int, char**);

  const char * MAGIC_STRING = "DUMPATOM";
  const int    FORMAT_REVISION = 0x0002;
  const int    ENDIAN = 0x0001;

 protected:
  int scale_flag;            // 1 if atom coords are scaled, 0 if no
  int image_flag;            // 1 if append box count to atom coords, 0 if no
@@ -41,6 +45,14 @@ class DumpAtom : public Dump {
  int convert_string(int, double *);
  void write_data(int, double *);

  void header_format_binary();
  void header_unit_style_binary();
  void header_time_binary();
  void header_columns_binary();
  void format_magic_string_binary();
  void format_endian_binary();
  void format_revision_binary();

  typedef void (DumpAtom::*FnPtrHeader)(bigint);
  FnPtrHeader header_choice;           // ptr to write header functions
  void header_binary(bigint);
+89 −2
Original line number Diff line number Diff line
@@ -183,7 +183,7 @@ DumpCustom::DumpCustom(LAMMPS *lmp, int narg, char **arg) :
  columns[0] = '\0';
  for (int iarg = 0; iarg < nfield; iarg++) {
    strcat(columns,earg[iarg]);
    strcat(columns," ");
    if (iarg+1 < nfield) strcat(columns," ");
  }
}

@@ -302,7 +302,7 @@ void DumpCustom::init_style()
      strcpy(vformat[i],ptr);
    }

    vformat[i] = strcat(vformat[i]," ");
    if (i+1 < size_one) vformat[i] = strcat(vformat[i]," ");
  }

  // setup boundary string
@@ -381,8 +381,83 @@ void DumpCustom::write_header(bigint ndump)

/* ---------------------------------------------------------------------- */

void DumpCustom::format_magic_string_binary()
{
  // use negative ntimestep as marker for new format
  bigint fmtlen = strlen(MAGIC_STRING);
  bigint marker = -fmtlen;
  fwrite(&marker, sizeof(bigint), 1, fp);
  fwrite(MAGIC_STRING, sizeof(char), fmtlen, fp);
}

/* ---------------------------------------------------------------------- */

void DumpCustom::format_endian_binary()
{
  int endian = ENDIAN;
  fwrite(&endian, sizeof(int), 1, fp);
}

/* ---------------------------------------------------------------------- */

void DumpCustom::format_revision_binary()
{
  int revision = FORMAT_REVISION;
  fwrite(&revision, sizeof(int), 1, fp);
}

/* ---------------------------------------------------------------------- */

void DumpCustom::header_unit_style_binary()
{
  int len = 0;
  if (unit_flag && !unit_count) {
    ++unit_count;
    len = strlen(update->unit_style);
    fwrite(&len, sizeof(int), 1, fp);
    fwrite(update->unit_style, sizeof(char), len, fp);
  } else {
    fwrite(&len, sizeof(int), 1, fp);
  }
}

/* ---------------------------------------------------------------------- */

void DumpCustom::header_columns_binary()
{
  int len = strlen(columns);
  fwrite(&len, sizeof(int), 1, fp);
  fwrite(columns, sizeof(char), len, fp);
}

/* ---------------------------------------------------------------------- */

void DumpCustom::header_time_binary()
{
  char flag = time_flag ? 1 : 0;
  fwrite(&flag, sizeof(char), 1, fp);

  if (time_flag) {
    double t = compute_time();
    fwrite(&t, sizeof(double), 1, fp);
  }
}

/* ---------------------------------------------------------------------- */

void DumpCustom::header_format_binary()
{
  format_magic_string_binary();
  format_endian_binary();
  format_revision_binary();
}

/* ---------------------------------------------------------------------- */

void DumpCustom::header_binary(bigint ndump)
{
  header_format_binary();

  fwrite(&update->ntimestep,sizeof(bigint),1,fp);
  fwrite(&ndump,sizeof(bigint),1,fp);
  fwrite(&domain->triclinic,sizeof(int),1,fp);
@@ -394,6 +469,11 @@ void DumpCustom::header_binary(bigint ndump)
  fwrite(&boxzlo,sizeof(double),1,fp);
  fwrite(&boxzhi,sizeof(double),1,fp);
  fwrite(&size_one,sizeof(int),1,fp);

  header_unit_style_binary();
  header_time_binary();
  header_columns_binary();

  if (multiproc) fwrite(&nclusterprocs,sizeof(int),1,fp);
  else fwrite(&nprocs,sizeof(int),1,fp);
}
@@ -402,6 +482,8 @@ void DumpCustom::header_binary(bigint ndump)

void DumpCustom::header_binary_triclinic(bigint ndump)
{
  header_format_binary();

  fwrite(&update->ntimestep,sizeof(bigint),1,fp);
  fwrite(&ndump,sizeof(bigint),1,fp);
  fwrite(&domain->triclinic,sizeof(int),1,fp);
@@ -416,6 +498,11 @@ void DumpCustom::header_binary_triclinic(bigint ndump)
  fwrite(&boxxz,sizeof(double),1,fp);
  fwrite(&boxyz,sizeof(double),1,fp);
  fwrite(&size_one,sizeof(int),1,fp);

  header_unit_style_binary();
  header_time_binary();
  header_columns_binary();

  if (multiproc) fwrite(&nclusterprocs,sizeof(int),1,fp);
  else fwrite(&nprocs,sizeof(int),1,fp);
}
+12 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ class DumpCustom : public Dump {
  DumpCustom(class LAMMPS *, int, char **);
  virtual ~DumpCustom();

  const char * MAGIC_STRING = "DUMPCUSTOM";
  const int    FORMAT_REVISION = 0x0002;
  const int    ENDIAN = 0x0001;

 protected:
  int nevery;                // dump frequency for output
  int iregion;               // -1 if no region, else which region
@@ -107,6 +111,14 @@ class DumpCustom : public Dump {
  int add_custom(char *, int);
  virtual int modify_param(int, char **);

  void header_format_binary();
  void header_unit_style_binary();
  void header_time_binary();
  void header_columns_binary();
  void format_magic_string_binary();
  void format_endian_binary();
  void format_revision_binary();

  typedef void (DumpCustom::*FnPtrHeader)(bigint);
  FnPtrHeader header_choice;           // ptr to write header functions
  void header_binary(bigint);
+20 −0
Original line number Diff line number Diff line
@@ -1243,6 +1243,26 @@ string Info::get_openmp_info()
#endif
}

string Info::get_mpi_vendor() {
  #if defined(MPI_STUBS)
  return "MPI STUBS";
  #elif defined(OPEN_MPI)
  return "Open MPI";
  #elif defined(MPICH_NAME)
  return "MPICH";
  #elif defined(I_MPI_VERSION)
  return "Intel MPI";
  #elif defined(PLATFORM_MPI)
  return "Platform MPI";
  #elif defined(HP_MPI)
  return "HP MPI";
  #elif defined(MSMPI_VER)
  return "Microsoft MPI";
  #else
  return "Unknown";
  #endif
}

string Info::get_mpi_info(int &major, int &minor)
{
  int len;
Loading