Skip to content

Commit

Permalink
Add a routine that checks timestamps (idaholab#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Schunert committed Nov 30, 2019
1 parent b06e722 commit 3143822
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/userobjects/LAMMPSFileRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class LAMMPSFileRunner : public MDRunBase
std::pair<std::string, std::string> & filenames,
std::pair<Real, Real> & timestamps);

bool isTimestamp(std::string ts_candidate) const;

/// whether a sequence of input files or a single input file is read
bool _time_sequence;

Expand All @@ -60,4 +62,3 @@ class LAMMPSFileRunner : public MDRunBase
/// Conversion from FEM time to MD time_stamp
const Function * _time_conversion;
};

21 changes: 18 additions & 3 deletions src/userobjects/LAMMPSFileRunner.C
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "MooseUtils.h"
#include "Function.h"
#include <sstream>
#include <cstring>
#include <cctype>

registerMooseObject("MagpieApp", LAMMPSFileRunner);

Expand Down Expand Up @@ -136,9 +138,13 @@ LAMMPSFileRunner::findBracketingLAMMPSFiles(Real md_time,
" failed. LAMMPS filename must be base.<t>.xyz where <t> is the timestamp.");
std::stringstream sstr(elements[1]);

if (sstr >> timestamp || sstr.eof())
if (sstr.fail())
continue;
if (!isTimestamp(elements[1]))
continue;
sstr >> timestamp;

// if (sstr >> timestamp || sstr.eof())
// if (sstr.fail())
// continue;

// increase the counter & check if this file is a candidate for before/after
++lammps_files_found;
Expand Down Expand Up @@ -259,6 +265,15 @@ LAMMPSFileRunner::readLAMMPSFile(FileName filename)
_md_particles.id.shrink_to_fit();
}

bool
LAMMPSFileRunner::isTimestamp(std::string ts_candidate) const
{
for (auto & s : ts_candidate)
if (!isdigit(s))
return false;
return true;
}

void
LAMMPSFileRunner::readLAMMPSFileHistory(std::pair<FileName, FileName> filenames,
std::pair<Real, Real> timestamps,
Expand Down

0 comments on commit 3143822

Please sign in to comment.