www.mooseframework.org
Namespaces | Functions
MooseUtils.C File Reference

Go to the source code of this file.

Namespaces

 MooseUtils
 

Functions

std::string getLatestCheckpointFileHelper (const std::list< std::string > &checkpoint_files, const std::vector< std::string > extensions, bool keep_extension)
 
int MooseUtils::levenshteinDist (const std::string &s1, const std::string &s2)
 Computes and returns the Levenshtein distance between strings s1 and s2. More...
 
void MooseUtils::escape (std::string &str)
 This function will escape all of the standard C++ escape characters so that they can be printed. More...
 
std::string MooseUtils::trim (const std::string &str, const std::string &white_space=" \t\n\v\f\r")
 Standard scripting language trim function. More...
 
bool MooseUtils::pathContains (const std::string &expression, const std::string &string_to_find, const std::string &delims="/")
 This function tokenizes a path and checks to see if it contains the string to look for. More...
 
bool MooseUtils::checkFileReadable (const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true)
 Checks to see if a file is readable (exists and permissions) More...
 
bool MooseUtils::checkFileWriteable (const std::string &filename, bool throw_on_unwritable=true)
 Check if the file is writable (path exists and permissions) More...
 
void MooseUtils::parallelBarrierNotify (const Parallel::Communicator &comm)
 
void MooseUtils::serialBegin (const libMesh::Parallel::Communicator &comm)
 This function marks the begin of a section of code that is executed in serial rank by rank. More...
 
void MooseUtils::serialEnd (const libMesh::Parallel::Communicator &comm)
 Closes a section of code that is executed in serial rank by rank, and that was opened with a call to serialBegin. More...
 
bool MooseUtils::hasExtension (const std::string &filename, std::string ext, bool strip_exodus_ext=false)
 Function tests if the supplied filename as the desired extension. More...
 
std::pair< std::string, std::string > MooseUtils::splitFileName (std::string full_file)
 Function for splitting path and filename. More...
 
std::string MooseUtils::camelCaseToUnderscore (const std::string &camel_case_name)
 Function for converting a camel case name to a name containing underscores. More...
 
std::string MooseUtils::underscoreToCamelCase (const std::string &underscore_name, bool leading_upper_case)
 Function for converting an underscore name to a camel case name. More...
 
std::string MooseUtils::shortName (const std::string &name)
 Function for stripping name after the file / in parser block. More...
 
std::string MooseUtils::baseName (const std::string &name)
 Function for string the information before the final / in a parser block. More...
 
bool MooseUtils::absoluteFuzzyEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::absoluteFuzzyGreaterEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::absoluteFuzzyGreaterThan (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::absoluteFuzzyLessEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::absoluteFuzzyLessThan (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::relativeFuzzyEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::relativeFuzzyGreaterEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::relativeFuzzyGreaterThan (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::relativeFuzzyLessEqual (const Real &var1, const Real &var2, const Real &tol)
 
bool MooseUtils::relativeFuzzyLessThan (const Real &var1, const Real &var2, const Real &tol)
 
void MooseUtils::MaterialPropertyStorageDump (const HashMap< const libMesh::Elem *, HashMap< unsigned int, MaterialProperties >> &props)
 Function to dump the contents of MaterialPropertyStorage for debugging purposes. More...
 
std::string & MooseUtils::removeColor (std::string &msg)
 remove ANSI escape sequences for teminal color from msg More...
 
void MooseUtils::indentMessage (const std::string &prefix, std::string &message, const char *color=COLOR_CYAN)
 Indents the supplied message given the prefix and color. More...
 
std::list< std::string > MooseUtils::getFilesInDirs (const std::list< std::string > &directory_list)
 Retrieves the names of all of the files contained within the list of directories passed into the routine. More...
 
std::string MooseUtils::getLatestMeshCheckpointFile (const std::list< std::string > &checkpoint_files)
 Returns the most recent checkpoint or mesh file given a list of files. More...
 
std::string MooseUtils::getLatestAppCheckpointFileBase (const std::list< std::string > &checkpoint_files)
 
bool MooseUtils::wildCardMatch (std::string name, std::string search_string)
 
std::string MooseUtils::toUpper (const std::string &name)
 Convert supplied string to upper case. More...
 

Function Documentation

std::string getLatestCheckpointFileHelper ( const std::list< std::string > &  checkpoint_files,
const std::vector< std::string >  extensions,
bool  keep_extension 
)

Definition at line 565 of file MooseUtils.C.

Referenced by MooseUtils::getLatestAppCheckpointFileBase(), and MooseUtils::getLatestMeshCheckpointFile().

568 {
569  // Create storage for newest restart files
570  // Note that these might have the same modification time if the simulation was fast.
571  // In that case we're going to save all of the "newest" files and sort it out momentarily
572  time_t newest_time = 0;
573  std::list<std::string> newest_restart_files;
574 
575  // Loop through all possible files and store the newest
576  for (const auto & cp_file : checkpoint_files)
577  {
578  if (find_if(extensions.begin(), extensions.end(), [cp_file](const std::string & ext) {
579  return MooseUtils::hasExtension(cp_file, ext);
580  }) != extensions.end())
581  {
582  struct stat stats;
583  stat(cp_file.c_str(), &stats);
584 
585  time_t mod_time = stats.st_mtime;
586  if (mod_time > newest_time)
587  {
588  newest_restart_files.clear(); // If the modification time is greater, clear the list
589  newest_time = mod_time;
590  }
591 
592  if (mod_time == newest_time)
593  newest_restart_files.push_back(cp_file);
594  }
595  }
596 
597  // Loop through all of the newest files according the number in the file name
598  int max_file_num = -1;
599  std::string max_base;
600  std::string max_file;
601 
602  pcrecpp::RE re_file_num(".*?(\\d+)(?:_mesh)?$"); // Pull out the embedded number from the file
603 
604  // Now, out of the newest files find the one with the largest number in it
605  for (const auto & res_file : newest_restart_files)
606  {
607  auto dot_pos = res_file.find_last_of(".");
608  auto the_base = res_file.substr(0, dot_pos);
609  int file_num = 0;
610 
611  re_file_num.FullMatch(the_base, &file_num);
612 
613  if (file_num > max_file_num)
614  {
615  max_file_num = file_num;
616  max_base = the_base;
617  max_file = res_file;
618  }
619  }
620 
621  // Error if nothing was located
622  if (max_file_num == -1)
623  {
624  max_base.clear();
625  max_file.clear();
626  }
627 
628  return keep_extension ? max_file : max_base;
629 }
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext=false)
Function tests if the supplied filename as the desired extension.
Definition: MooseUtils.C:227