remove parser_error exception class ambiguity completely

This commit is contained in:
Axel Kohlmeyer
2021-10-23 04:24:54 -04:00
parent 47eab736bb
commit 71a24580b8
9 changed files with 43 additions and 98 deletions

View File

@ -28,7 +28,6 @@
#include "random_mars.h" #include "random_mars.h"
#include "respa.h" #include "respa.h"
#include "potential_file_reader.h" #include "potential_file_reader.h"
#include "tokenizer.h"
#include "update.h" #include "update.h"
#include <cmath> #include <cmath>
@ -46,18 +45,6 @@ using namespace FixConst;
static constexpr int OFFSET = 16384; static constexpr int OFFSET = 16384;
static constexpr double SHIFT = 0.0; static constexpr double SHIFT = 0.0;
// helper class
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) : FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) :
@ -503,10 +490,10 @@ void FixTTM::read_electron_temperatures(const std::string &filename)
// check correctness of input data // check correctness of input data
if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid)) if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid))
throw parser_error("Fix ttm invalid grid index in fix ttm grid file"); throw TokenizerException("Fix ttm invalid grid index in fix ttm grid file","");
if (T_tmp < 0.0) if (T_tmp < 0.0)
throw parser_error("Fix ttm electron temperatures must be > 0.0"); throw TokenizerException("Fix ttm electron temperatures must be > 0.0","");
T_electron[iz][iy][ix] = T_tmp; T_electron[iz][iy][ix] = T_tmp;
T_initial_set[iz][iy][ix] = 1; T_initial_set[iz][iy][ix] = 1;

View File

@ -41,18 +41,6 @@ static constexpr int MAXLINE = 256;
static constexpr int CHUNK = 1024; static constexpr int CHUNK = 1024;
static constexpr int OFFSET = 16384; static constexpr int OFFSET = 16384;
// helper class
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixTTMGrid::FixTTMGrid(LAMMPS *lmp, int narg, char **arg) : FixTTMGrid::FixTTMGrid(LAMMPS *lmp, int narg, char **arg) :
@ -318,7 +306,7 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename)
int iz = values.next_int(); int iz = values.next_int();
if (ix < 0 || ix >= nxgrid || iy < 0 || iy >= nygrid || iz < 0 || iz >= nzgrid) if (ix < 0 || ix >= nxgrid || iy < 0 || iy >= nygrid || iz < 0 || iz >= nzgrid)
throw parser_error("Fix ttm/grid invalid grid index in input"); throw TokenizerException("Fix ttm/grid invalid grid index in input","");
if (ix >= nxlo_in && ix <= nxhi_in && iy >= nylo_in && iy <= nyhi_in if (ix >= nxlo_in && ix <= nxhi_in && iy >= nylo_in && iy <= nyhi_in
&& iz >= nzlo_in && iz <= nzhi_in) { && iz >= nzlo_in && iz <= nzhi_in) {
@ -326,7 +314,7 @@ void FixTTMGrid::read_electron_temperatures(const std::string &filename)
T_initial_set[iz][iy][ix] = 1; T_initial_set[iz][iy][ix] = 1;
} }
} else { } else {
throw parser_error("Incorrect format in fix ttm electron grid file"); throw TokenizerException("Incorrect format in fix ttm electron grid file","");
} }
} catch (std::exception &e) { } catch (std::exception &e) {
error->one(FLERR,e.what()); error->one(FLERR,e.what());

View File

@ -41,18 +41,6 @@ using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
using namespace MathConst; using namespace MathConst;
// helper class
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
// OFFSET avoids outside-of-box atoms being rounded to grid pts incorrectly // OFFSET avoids outside-of-box atoms being rounded to grid pts incorrectly
// SHIFT = 0.0 assigns atoms to lower-left grid pt // SHIFT = 0.0 assigns atoms to lower-left grid pt
// SHIFT = 0.5 assigns atoms to nearest grid pt // SHIFT = 0.5 assigns atoms to nearest grid pt
@ -596,10 +584,10 @@ void FixTTMMod::read_electron_temperatures(const std::string &filename)
// check correctness of input data // check correctness of input data
if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid)) if ((ix < 0) || (ix >= nxgrid) || (iy < 0) || (iy >= nygrid) || (iz < 0) || (iz >= nzgrid))
throw parser_error("Fix ttm invalid grid index in fix ttm/mod grid file"); throw TokenizerException("Fix ttm invalid grid index in fix ttm/mod grid file","");
if (T_tmp < 0.0) if (T_tmp < 0.0)
throw parser_error("Fix ttm electron temperatures must be > 0.0"); throw TokenizerException("Fix ttm electron temperatures must be > 0.0","");
T_electron[iz][iy][ix] = T_tmp; T_electron[iz][iy][ix] = T_tmp;
T_initial_set[iz][iy][ix] = 1; T_initial_set[iz][iy][ix] = 1;

View File

@ -43,10 +43,10 @@ using namespace FixConst;
#define MAXLINE 1024 #define MAXLINE 1024
namespace { namespace {
class parser_error : public std::exception { class qeq_parser_error : public std::exception {
std::string message; std::string message;
public: public:
parser_error(const std::string &mesg) { message = mesg; } explicit qeq_parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); } const char *what() const noexcept { return message.c_str(); }
}; };
} }
@ -761,8 +761,8 @@ void FixQEq::read_file(char *file)
FILE *fp = utils::open_potential(file,lmp,nullptr); FILE *fp = utils::open_potential(file,lmp,nullptr);
if (fp == nullptr) if (fp == nullptr)
throw parser_error(fmt::format("Cannot open fix qeq parameter file {}:" throw qeq_parser_error(fmt::format("Cannot open fix qeq parameter file {}: {}",
" {}", file,utils::getsyserror())); file,utils::getsyserror()));
TextFileReader reader(fp, "qeq parameter"); TextFileReader reader(fp, "qeq parameter");
while (1) { while (1) {
@ -770,12 +770,12 @@ void FixQEq::read_file(char *file)
if (values.count() == 0) continue; if (values.count() == 0) continue;
if (values.count() < 6) if (values.count() < 6)
throw parser_error("Invalid qeq parameter file"); throw qeq_parser_error("Invalid qeq parameter file");
auto word = values.next_string(); auto word = values.next_string();
utils::bounds(FLERR,word,1,ntypes,nlo,nhi,nullptr); utils::bounds(FLERR,word,1,ntypes,nlo,nhi,nullptr);
if ((nlo < 0) || (nhi < 0)) if ((nlo < 0) || (nhi < 0))
throw parser_error("Invalid atom type range"); throw qeq_parser_error(fmt::format("Invalid atom type range: {}",word));
val = values.next_double(); val = values.next_double();
for (int n=nlo; n <= nhi; ++n) chi[n] = val; for (int n=nlo; n <= nhi; ++n) chi[n] = val;

View File

@ -43,15 +43,6 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
static const char cite_fix_acks2_reax[] = static const char cite_fix_acks2_reax[] =
"fix acks2/reaxff command:\n\n" "fix acks2/reaxff command:\n\n"
"@Article{O'Hearn2020,\n" "@Article{O'Hearn2020,\n"
@ -175,26 +166,27 @@ void FixACKS2ReaxFF::pertype_parameters(char *arg)
const char *line = reader.next_line(); const char *line = reader.next_line();
if (!line) if (!line)
throw parser_error("Invalid parameter file for fix acks2/reaxff"); throw TokenizerException("Invalid parameter file for fix acks2/reaxff","");
ValueTokenizer values(line); ValueTokenizer values(line);
if (values.count() != 1) if (values.count() != 1)
throw parser_error("Fix acks2/reaxff: Incorrect format of parameter file"); throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format","");
bond_softness = values.next_double(); bond_softness = values.next_double();
for (int i = 1; i <= ntypes; i++) { for (int i = 1; i <= ntypes; i++) {
const char *line = reader.next_line(); const char *line = reader.next_line();
if (!line) if (!line)
throw parser_error("Invalid parameter file for fix acks2/reaxff"); throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format","");
ValueTokenizer values(line); ValueTokenizer values(line);
if (values.count() != 5) if (values.count() != 5)
throw parser_error("Fix acks2/reaxff: Incorrect format of parameter file"); throw TokenizerException("Fix acks2/reaxff: Incorrect parameter file format","");
int itype = values.next_int(); int itype = values.next_int();
if ((itype < 1) || (itype > ntypes)) if ((itype < 1) || (itype > ntypes))
throw parser_error("Fix acks2/reaxff: invalid atom type in parameter file"); throw TokenizerException("Fix acks2/reaxff: invalid atom type in parameter file",
std::to_string(itype));
chi[itype] = values.next_double(); chi[itype] = values.next_double();
eta[itype] = values.next_double(); eta[itype] = values.next_double();

View File

@ -45,19 +45,11 @@
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <exception> #include <exception>
#include <string>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
using namespace FixConst; using namespace FixConst;
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
static constexpr double EV_TO_KCAL_PER_MOL = 14.4; static constexpr double EV_TO_KCAL_PER_MOL = 14.4;
static constexpr double SMALL = 1.0e-14; static constexpr double SMALL = 1.0e-14;
@ -243,15 +235,16 @@ void FixQEqReaxFF::pertype_parameters(char *arg)
for (int i = 1; i <= ntypes; i++) { for (int i = 1; i <= ntypes; i++) {
const char *line = reader.next_line(); const char *line = reader.next_line();
if (!line) if (!line)
throw parser_error("Invalid param file for fix qeq/reaxff"); throw TokenizerException("Fix qeq/reaxff: Invalid param file format","");
ValueTokenizer values(line); ValueTokenizer values(line);
if (values.count() != 4) if (values.count() != 4)
throw parser_error("Fix qeq/reaxff: Incorrect format of param file"); throw TokenizerException("Fix qeq/reaxff: Incorrect format of param file","");
int itype = values.next_int(); int itype = values.next_int();
if ((itype < 1) || (itype > ntypes)) if ((itype < 1) || (itype > ntypes))
throw parser_error("Fix qeq/reaxff: invalid atom type in param file"); throw TokenizerException("Fix qeq/reaxff: invalid atom type in param file",
std::to_string(itype));
chi[itype] = values.next_double(); chi[itype] = values.next_double();
eta[itype] = values.next_double(); eta[itype] = values.next_double();

View File

@ -40,15 +40,6 @@ using LAMMPS_NS::utils::sfgets;
using LAMMPS_NS::utils::logmesg; using LAMMPS_NS::utils::logmesg;
using LAMMPS_NS::ValueTokenizer; using LAMMPS_NS::ValueTokenizer;
namespace {
class parser_error : public std::exception {
std::string message;
public:
parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); }
};
}
namespace ReaxFF { namespace ReaxFF {
static std::unordered_set<std::string> inactive_keywords = { static std::unordered_set<std::string> inactive_keywords = {
"ensemble_type", "nsteps", "dt", "proc_by_dim", "random_vel", "ensemble_type", "nsteps", "dt", "proc_by_dim", "random_vel",
@ -63,6 +54,15 @@ namespace ReaxFF {
"energy_update_freq", "atom_info", "atom_velocities", "atom_forces", "energy_update_freq", "atom_info", "atom_velocities", "atom_forces",
"bond_info", "angle_info" }; "bond_info", "angle_info" };
class control_parser_error : public std::exception {
std::string message;
public:
explicit control_parser_error(const std::string &format, const std::string &keyword) {
message = fmt::format(format, keyword);
}
const char *what() const noexcept { return message.c_str(); }
};
// NOTE: this function is run on MPI rank 0 only // NOTE: this function is run on MPI rank 0 only
void Read_Control_File(const char *control_file, control_params *control) void Read_Control_File(const char *control_file, control_params *control)
@ -92,7 +92,7 @@ namespace ReaxFF {
auto keyword = values.next_string(); auto keyword = values.next_string();
if (!values.has_next()) if (!values.has_next())
throw parser_error(fmt::format("No value(s) for control parameter: {}\n",keyword)); throw control_parser_error("No value(s) for control parameter: {}\n", keyword);
if (inactive_keywords.find(keyword) != inactive_keywords.end()) { if (inactive_keywords.find(keyword) != inactive_keywords.end()) {
error->warning(FLERR,fmt::format("Ignoring inactive control " error->warning(FLERR,fmt::format("Ignoring inactive control "
@ -114,8 +114,7 @@ namespace ReaxFF {
error->warning(FLERR,"Support for writing native trajectories has " error->warning(FLERR,"Support for writing native trajectories has "
"been removed after LAMMPS version 8 April 2021"); "been removed after LAMMPS version 8 April 2021");
} else { } else {
throw parser_error(fmt::format("Unknown parameter {} in " throw control_parser_error("Unknown parameter {} in control file", keyword);
"control file", keyword));
} }
} }
} catch (LAMMPS_NS::EOFException &) { } catch (LAMMPS_NS::EOFException &) {

View File

@ -41,16 +41,14 @@ using LAMMPS_NS::utils::open_potential;
using LAMMPS_NS::utils::getsyserror; using LAMMPS_NS::utils::getsyserror;
using LAMMPS_NS::utils::uppercase; using LAMMPS_NS::utils::uppercase;
namespace { namespace ReaxFF {
class parser_error : public std::exception {
class ffield_parser_error : public std::exception {
std::string message; std::string message;
public: public:
parser_error(const std::string &mesg) { message = mesg; } explicit ffield_parser_error(const std::string &mesg) { message = mesg; }
const char *what() const noexcept { return message.c_str(); } const char *what() const noexcept { return message.c_str(); }
}; };
}
namespace ReaxFF {
void Read_Force_Field(const char *filename, reax_interaction *reax, void Read_Force_Field(const char *filename, reax_interaction *reax,
control_params *control, MPI_Comm world) control_params *control, MPI_Comm world)
@ -63,7 +61,7 @@ namespace ReaxFF {
// read and parse the force field only on rank 0 // read and parse the force field only on rank 0
#define THROW_ERROR(txt) \ #define THROW_ERROR(txt) \
throw parser_error(fmt::format("{}:{}: {}",filename,lineno,txt)) throw ffield_parser_error(fmt::format("{}:{}: {}",filename,lineno,txt))
if (control->me == 0) { if (control->me == 0) {
FILE *fp = LAMMPS_NS::utils::open_potential(filename, lmp, nullptr); FILE *fp = LAMMPS_NS::utils::open_potential(filename, lmp, nullptr);
@ -165,7 +163,7 @@ namespace ReaxFF {
// copy element symbol in uppercase and truncate stored element symbol if necessary // copy element symbol in uppercase and truncate stored element symbol if necessary
auto element = uppercase(values.next_string()); auto element = uppercase(values.next_string());
strncpy(sbp[i].name,element.c_str(),4); strncpy(sbp[i].name,element.c_str(),3);
sbp[i].name[3] = '\0'; sbp[i].name[3] = '\0';
sbp[i].r_s = values.next_double(); sbp[i].r_s = values.next_double();

View File

@ -60,7 +60,7 @@ class TokenizerException : public std::exception {
* *
* \param msg String with error message * \param msg String with error message
* \param token String of the token/word that caused the error */ * \param token String of the token/word that caused the error */
TokenizerException(const std::string &msg, const std::string &token); explicit TokenizerException(const std::string &msg, const std::string &token);
~TokenizerException() noexcept {} ~TokenizerException() noexcept {}
@ -74,7 +74,7 @@ class InvalidIntegerException : public TokenizerException {
/** Thrown during converting string to integer number /** Thrown during converting string to integer number
* *
* \param token String of the token/word that caused the error */ * \param token String of the token/word that caused the error */
InvalidIntegerException(const std::string &token) : explicit InvalidIntegerException(const std::string &token) :
TokenizerException("Not a valid integer number", token) TokenizerException("Not a valid integer number", token)
{ {
} }
@ -85,7 +85,7 @@ class InvalidFloatException : public TokenizerException {
/** Thrown during converting string to floating point number /** Thrown during converting string to floating point number
* *
* \param token String of the token/word that caused the error */ * \param token String of the token/word that caused the error */
InvalidFloatException(const std::string &token) : explicit InvalidFloatException(const std::string &token) :
TokenizerException("Not a valid floating-point number", token) TokenizerException("Not a valid floating-point number", token)
{ {
} }