Commit 2536f28e authored by Anne Gunn's avatar Anne Gunn
Browse files

Per comments from Axel, continued the evolution of the output messages.

- Converted Compute message with imputed value to fmt::format style.
- Condensed most error-> output messages to oneliners where fmt::format
is called within the call to the error method. For a couple, the
formatting string/value list were complex enough that I continued using
a temporary string variable to make the code easier to read.
parent 52748f57
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include "domain.h"
#include "error.h"
#include "fix.h"
#include "fmt/format.h"
#include "force.h"
#include "improper.h"
#include "kspace.h"
@@ -218,9 +219,7 @@ double ComputePressureBocs::find_index(double * grid, double value)

  if (value >= grid[i] && value <= (grid[i] + spacing)) { return i; }

  char errmsg[256];
  snprintf(errmsg,256,"find_index could not find value in grid for value: %f",value);
  error->all(FLERR,errmsg);
  error->all(FLERR, fmt::format("find_index could not find value in grid for value: {}", value));
  for (int i = 0; i < gridsize; ++i)
  {
    fprintf(stderr, "grid %d: %f\n",i,grid[i]);
+51 −45
Original line number Diff line number Diff line
@@ -644,6 +644,7 @@ void FixBocs::init()
// NJD MRD 2 functions
int FixBocs::read_F_table( char *filename, int p_basis_type )
{
  std::string message;
  double **data;
  bool badInput = false;
  int numEntries = 0;
@@ -655,8 +656,9 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
    // through the file.
    // NB: LAMMPS coding guidelines prefer cstdio so we are intentionally
    // foregoing  reading with getline
    std::string message = fmt::format("INFO: About to read data file: {}", filename);
    error->message(FLERR, message);
    if (comm->me == 0) {
        error->message(FLERR, fmt::format("INFO: About to read data file: {}", filename));
    }

    // Data file lines hold two floating point numbers.
    // Line length we allocate should be long enough without being too long.
@@ -670,8 +672,10 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
    fclose(fpi);

    numEntries = inputLines.size();
    message = fmt::format("INFO: Read {} lines from file", numEntries);
    error->message(FLERR, message);
    if (comm->me == 0) {
      error->message(FLERR, fmt::format("INFO: Read {} lines from file", numEntries));
    }


    // Allocate memory for the two dimensional matrix
    // that holds data from the input file.
@@ -694,29 +698,34 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
      test_sscanf = sscanf(inputLines.at(i).c_str()," %f , %f ",&f1, &f2);
      if (test_sscanf == 2)
      {
        //message = fmt::format("INFO: f1 = {}, f2 = {}", f1, f2);
        //error->message(FLERR,message);
        //if (comm->me == 0) {
        //    error->message(FLERR, fmt::format("INFO: f1 = {}, f2 = {}", f1, f2));
        //}
        data[VOLUME][i] = (double)f1;
        data[PRESSURE_CORRECTION][i] = (double)f2;
        if (i == 1)
        {
          // second entry is used to compute the validation interval used below
          stdVolumeInterval = data[VOLUME][i] - data[VOLUME][i-1];
          //message = fmt::format("INFO: standard volume interval computed: {}", stdVolumeInterval);
          //error->message(FLERR,message);
          //if (comm->me == 0) {
          //    error->message(FLERR, fmt::format("INFO: standard volume interval computed: {}", stdVolumeInterval));
          //}
        }
        else if (i > 1)
        {
          // after second entry, all intervals are validated
          currVolumeInterval = data[VOLUME][i] - data[VOLUME][i-1];
          //message = fmt::format("INFO: current volume interval: {}", currVolumeInterval);
          //error->message(FLERR,message);
          //if (comm->me == 0) {
          //    error->message(FLERR, fmt::format("INFO: current volume interval: {}", currVolumeInterval));
          //}
          if (fabs(currVolumeInterval - stdVolumeInterval) > volumeIntervalTolerance) {
            message = fmt::format("ERROR: Bad volume interval. Spline analysis requires uniform"
            if (comm->me == 0) {
                message = fmt::format("Bad volume interval. Spline analysis requires uniform"
                                      " volume distribution, found inconsistent volume"
                                      " differential, line {} of file {}\n\tline: {}",
                                      lineNum, filename, inputLines.at(i));
            error->message(FLERR,message);
                error->warning(FLERR, message);
            }
            badInput = true;
            numBadVolumeIntervals++;
          }
@@ -725,10 +734,12 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
      }
      else
      {
        message = fmt::format("ERROR: Bad input format: did not find 2 comma separated numeric"
        if (comm->me == 0) {
          message = fmt::format("Bad input format: did not find 2 comma separated numeric"
                                " values in line {} of file {}\n\tline: {}",
                                lineNum, filename, inputLines.at(i));
        error->message(FLERR,message);
          error->warning(FLERR, message);
        }
        badInput = true;
      }
      if (badInput)
@@ -737,19 +748,16 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
      }
    }

    if (numBadVolumeIntervals) {
      message = fmt::format("INFO: total number bad volume intervals = {}", numBadVolumeIntervals);
      error->message(FLERR,message);
    if (numBadVolumeIntervals > 0 && comm->me == 0) {
      error->message(FLERR, fmt::format("INFO: total number bad volume intervals = {}", numBadVolumeIntervals));
    }
  }
  else {
    std::string errmsg = fmt::format("ERROR: Unable to open file: {}", filename);
    error->all(FLERR,errmsg);
    error->all(FLERR,fmt::format("ERROR: Unable to open file: {}", filename));
  }

  if (badInput) {
    std::string errmsg = fmt::format("Bad volume / pressure-correction data: {}\nSee details above", filename);
    error->message(FLERR,errmsg);
  if (badInput && comm->me == 0) {
    error->warning(FLERR,fmt::format("Bad volume / pressure-correction data: {}\nSee details above", filename));
  }

  if (p_basis_type == BASIS_LINEAR_SPLINE)
@@ -764,8 +772,7 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
  }
  else
  {
    std::string errmsg = fmt::format("ERROR: invalid p_basis_type value of {} in read_F_table", p_basis_type);
    error->all(FLERR,errmsg);
    error->all(FLERR,fmt::format("ERROR: invalid p_basis_type value of {} in read_F_table", p_basis_type));
  }

  memory->destroy(data);
@@ -773,10 +780,9 @@ int FixBocs::read_F_table( char *filename, int p_basis_type )
}

int FixBocs::build_linear_splines(double **data) {
  std::string message;
  //message = fmt::format("INFO: entering build_linear_splines, spline_length = {}", spline_length);
  //error->message(FLERR, message);

  //if (comm->me == 0) {
    //error->message(FLERR, fmt::format("INFO: entering build_linear_splines, spline_length = {}", spline_length));
  //}
  splines = (double **) calloc(NUM_LINEAR_SPLINE_COLUMNS,sizeof(double *));
  splines[VOLUME] = (double *) calloc(spline_length,sizeof(double));
  splines[PRESSURE_CORRECTION] = (double *) calloc(spline_length,sizeof(double));
@@ -787,18 +793,18 @@ int FixBocs::build_linear_splines(double **data) {
    splines[PRESSURE_CORRECTION][i] = data[PRESSURE_CORRECTION][i];
  }

  message = fmt::format("INFO: leaving build_linear_splines, spline_length = {}", spline_length);
  error->message(FLERR, message);
  if (comm->me == 0) {
    error->message(FLERR, fmt::format("INFO: leaving build_linear_splines, spline_length = {}", spline_length));
  }

  return spline_length;
}

int FixBocs::build_cubic_splines(double **data)
{
  std::string message;
  //message = fmt::format("INFO: entering build_cubic_splines, spline_length = {}", spline_length);
  //error->message(FLERR, message);

  //if (comm->me == 0) {
    //error->message(FLERR, fmt::format("INFO: entering build_cubic_splines, spline_length = {}", spline_length));
  //}
  int n = spline_length;
  double *a, *b, *d, *h, *alpha, *c, *l, *mu, *z;
  // 2020-07-17 ag:
@@ -866,16 +872,15 @@ int FixBocs::build_cubic_splines(double **data)
    d[j] = (c[j+1]-c[j])/(3.0 * h[j]);
  }

  memory->create(splines, NUM_CUBIC_SPLINE_COLUMNS, n-1, "splines");
  int numSplines = 0;
  for (int idx = 0; idx < n - 1; ++idx)
  int numSplines = n - 1;
  memory->create(splines, NUM_CUBIC_SPLINE_COLUMNS, numSplines, "splines");
  for (int idx = 0; idx < numSplines; ++idx)
  {
    splines[0][idx] = data[0][idx];
    splines[1][idx] = a[idx];
    splines[2][idx] = b[idx];
    splines[3][idx] = c[idx];
    splines[4][idx] = d[idx];
    numSplines++;
  }

  memory->destroy(a);
@@ -889,8 +894,9 @@ int FixBocs::build_cubic_splines(double **data)
  memory->destroy(mu);
  memory->destroy(z);

  message = fmt::format("INFO: leaving build_cubic_splines, numSplines = {}", numSplines);
  error->message(FLERR, message);
  if (comm->me == 0) {
    error->message(FLERR, fmt::format("INFO: leaving build_cubic_splines, numSplines = {}", numSplines));
  }

  // Tell the caller how many splines we created
  return numSplines;