Unverified Commit b5b71bbb authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

(re-)add example uses of {fmt}

parent 56cb761b
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -38,6 +38,10 @@
#include "error.h"
#include "memory.h"

#include <string>
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;
using namespace MathConst;

@@ -581,20 +585,11 @@ void CreateAtoms::command(int narg, char **arg)
  // print status

  MPI_Barrier(world);
  double time2 = MPI_Wtime();

  if (me == 0) {
    if (screen) {
      fprintf(screen,"Created " BIGINT_FORMAT " atoms\n",
              atom->natoms-natoms_previous);
      fprintf(screen,"  create_atoms CPU = %g secs\n",time2-time1);
    }
    if (logfile) {
      fprintf(logfile,"Created " BIGINT_FORMAT " atoms\n",
              atom->natoms-natoms_previous);
      fprintf(logfile,"  create_atoms CPU = %g secs\n",time2-time1);
    }
  }
  if (me == 0)
    utils::logmesg(lmp, fmt::format("Created {} atoms\n"
                        "  create_atoms CPU = {:<.3g} seconds\n",
                        atom->natoms - natoms_previous,
                        MPI_Wtime() - time1));
}

/* ----------------------------------------------------------------------
+16 −20
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include "style_bond.h"
#include "style_angle.h"
#include "style_dihedral.h"
@@ -34,6 +35,7 @@
#include "kspace.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -945,10 +947,9 @@ double Force::numeric(const char *file, int line, char *str)
    if (isdigit(str[i])) continue;
    if (str[i] == '-' || str[i] == '+' || str[i] == '.') continue;
    if (str[i] == 'e' || str[i] == 'E') continue;
    char msg[256];
    snprintf(msg,256,"Expected floating point parameter instead of "
                    "'%s' in input script or data file",str);
    error->all(file,line,msg);
    std::string msg = fmt::format("Expected floating point parameter "
                    "instead of '{}' in input script or data file",str);
    error->all(file,line,msg.c_str());
  }

  return atof(str);
@@ -971,10 +972,9 @@ int Force::inumeric(const char *file, int line, char *str)

  for (int i = 0; i < n; i++) {
    if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
    char msg[256];
    snprintf(msg,256,"Expected integer parameter instead of "
                    "'%s' in input script or data file",str);
    error->all(file,line,msg);
    std::string msg = fmt::format("Expected integer parameter instead "
                    "of '{}' in input script or data file",str);
    error->all(file,line,msg.c_str());
  }

  return atoi(str);
@@ -997,10 +997,9 @@ bigint Force::bnumeric(const char *file, int line, char *str)

  for (int i = 0; i < n; i++) {
    if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
    char msg[256];
    snprintf(msg,256,"Expected integer parameter instead of "
                    "'%s' in input script or data file",str);
    error->all(file,line,msg);
    std::string msg = fmt::format("Expected integer parameter instead "
                    "of '{}' in input script or data file",str);
    error->all(file,line,msg.c_str());
  }

  return ATOBIGINT(str);
@@ -1023,10 +1022,9 @@ tagint Force::tnumeric(const char *file, int line, char *str)

  for (int i = 0; i < n; i++) {
    if (isdigit(str[i]) || str[i] == '-' || str[i] == '+') continue;
    char msg[256];
    snprintf(msg,256,"Expected integer parameter instead of "
                    "'%s' in input script or data file",str);
    error->all(file,line,msg);
    std::string msg = fmt::format("Expected integer parameter instead "
                    "of '{}' in input script or data file",str);
    error->all(file,line,msg.c_str());
  }

  return ATOTAGINT(str);
@@ -1129,10 +1127,8 @@ void Force::potential_date(FILE *fp, const char *name)
    if (strcmp(word,"DATE:") == 0) {
      word = strtok(NULL," \t\n\r\f");
      if (word == NULL) return;
      if (screen)
        fprintf(screen,"Reading potential file %s with DATE: %s\n",name,word);
      if (logfile)
        fprintf(logfile,"Reading potential file %s with DATE: %s\n",name,word);
      utils::logmesg(lmp,fmt::format("Reading potential "
                     "file {} with DATE: {}",name,word));
      return;
    }
    word = strtok(NULL," \t\n\r\f");
+7 −18
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

#include "lmprestart.h"

@@ -498,36 +499,24 @@ void ReadRestart::command(int narg, char **arg)
  bigint nblocal = atom->nlocal;
  MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);

  if (me == 0) {
    if (screen) fprintf(screen,"  " BIGINT_FORMAT " atoms\n",natoms);
    if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " atoms\n",natoms);
  }
  if (me == 0)
    utils::logmesg(lmp,fmt::format("  {} atoms\n",natoms));

  if (natoms != atom->natoms)
    error->all(FLERR,"Did not assign all restart atoms correctly");

  if (me == 0) {
    if (atom->nbonds) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " bonds\n",atom->nbonds);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " bonds\n",atom->nbonds);
      utils::logmesg(lmp,fmt::format("  {} bonds\n",atom->nbonds));
    }
    if (atom->nangles) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " angles\n",
                          atom->nangles);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " angles\n",
                           atom->nangles);
      utils::logmesg(lmp,fmt::format("  {} angles\n",atom->nangles));
    }
    if (atom->ndihedrals) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " dihedrals\n",
                          atom->ndihedrals);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " dihedrals\n",
                           atom->ndihedrals);
      utils::logmesg(lmp,fmt::format("  {} dihedrals\n",atom->ndihedrals));
    }
    if (atom->nimpropers) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " impropers\n",
                          atom->nimpropers);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " impropers\n",
                           atom->nimpropers);
      utils::logmesg(lmp,fmt::format("  {} impropers\n",atom->nimpropers));
    }
  }

+7 −16
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
#include "accelerator_kokkos.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -733,8 +735,7 @@ void Replicate::command(int narg, char **arg)
  MPI_Allreduce(&nblocal,&natoms,1,MPI_LMP_BIGINT,MPI_SUM,world);

  if (me == 0) {
    if (screen) fprintf(screen,"  " BIGINT_FORMAT " atoms\n",natoms);
    if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " atoms\n",natoms);
    utils::logmesg(lmp,fmt::format("  {} atoms\n",natoms));
  }

  if (natoms != atom->natoms)
@@ -742,26 +743,16 @@ void Replicate::command(int narg, char **arg)

  if (me == 0) {
    if (atom->nbonds) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " bonds\n",atom->nbonds);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " bonds\n",atom->nbonds);
      utils::logmesg(lmp,fmt::format("  {} bonds\n",atom->nbonds));
    }
    if (atom->nangles) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " angles\n",
                          atom->nangles);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " angles\n",
                           atom->nangles);
      utils::logmesg(lmp,fmt::format("  {} angles\n",atom->nangles));
    }
    if (atom->ndihedrals) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " dihedrals\n",
                          atom->ndihedrals);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " dihedrals\n",
                           atom->ndihedrals);
      utils::logmesg(lmp,fmt::format("  {} dihedrals\n",atom->ndihedrals));
    }
    if (atom->nimpropers) {
      if (screen) fprintf(screen,"  " BIGINT_FORMAT " impropers\n",
                          atom->nimpropers);
      if (logfile) fprintf(logfile,"  " BIGINT_FORMAT " impropers\n",
                           atom->nimpropers);
      utils::logmesg(lmp,fmt::format("  {} impropers\n",atom->nimpropers));
    }
  }

+2 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "special.h"
#include "memory.h"
#include "error.h"
#include "utils.h"

using namespace LAMMPS_NS;

@@ -40,10 +41,7 @@ void ResetIDs::command(int narg, char ** /* arg */)
  // NOTE: check if any fixes exist which store atom IDs?
  // if so, this operation will mess up the fix

  if (comm->me == 0) {
    if (screen) fprintf(screen,"Resetting atom IDs ...\n");
    if (logfile) fprintf(logfile,"Resetting atom IDs ...\n");
  }
  if (comm->me == 0) utils::logmesg(lmp,"Resetting atom IDs ...\n");

  // create an atom map if one doesn't exist already

Loading