https://mooseframework.inl.gov
MooseUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 // MOOSE includes
13 #include "MooseTypes.h"
14 #include "HashMap.h"
15 #include "InfixIterator.h"
16 #include "MooseEnumItem.h"
17 #include "MooseError.h"
18 #include "Moose.h"
19 #include "ExecutablePath.h"
20 #include "ConsoleUtils.h"
21 #include "MooseStringUtils.h"
22 
23 #include "libmesh/compare_types.h"
24 #include "libmesh/bounding_box.h"
25 #include "libmesh/int_range.h"
26 #include "libmesh/tensor_tools.h"
27 #include "metaphysicl/raw_type.h"
28 #include "metaphysicl/metaphysicl_version.h"
29 #include "metaphysicl/dualnumber_decl.h"
30 #include "metaphysicl/dynamic_std_array_wrapper.h"
31 #include "timpi/standard_type.h"
32 
33 // C++ includes
34 #include <string>
35 #include <vector>
36 #include <map>
37 #include <list>
38 #include <filesystem>
39 #include <deque>
40 #include <regex>
41 
42 // Forward Declarations
43 class InputParameters;
44 class ExecFlagEnum;
45 class MaterialProperties;
46 class MaterialBase;
47 
48 namespace libMesh
49 {
50 class Elem;
51 namespace Parallel
52 {
53 class Communicator;
54 }
55 }
56 class MultiMooseEnum;
57 
58 namespace MooseUtils
59 {
60 
61 std::filesystem::path pathjoin(const std::filesystem::path & p);
62 
63 template <typename... Args>
64 std::filesystem::path
65 pathjoin(const std::filesystem::path & p, Args... args)
66 {
67  return p / pathjoin(args...);
68 }
69 
73 bool parsesToReal(const std::string & input, Real * parsed_real = nullptr);
74 
77 std::string runTestsExecutable();
78 
82 std::string findTestRoot();
83 
85 std::string installedInputsDir(const std::string & app_name,
86  const std::string & dir_name,
87  const std::string & extra_error_msg = "");
88 
90 std::string docsDir(const std::string & app_name);
91 
99 std::string mooseDocsURL(const std::string & path);
100 
102 std::string replaceAll(std::string str, const std::string & from, const std::string & to);
103 
107 std::string convertLatestCheckpoint(std::string orig);
108 
110 int levenshteinDist(const std::string & s1, const std::string & s2);
111 
117 void escape(std::string & str);
118 
124 std::string removeExtraWhitespace(const std::string & str);
125 
132 std::vector<std::string> split(const std::string & str,
133  const std::string & delimiter,
134  std::size_t max_count = std::numeric_limits<std::size_t>::max());
135 std::vector<std::string> rsplit(const std::string & str,
136  const std::string & delimiter,
137  std::size_t max_count = std::numeric_limits<std::size_t>::max());
138 
142 template <typename Iterator>
143 std::string
144 join(Iterator begin, Iterator end, const std::string & delimiter)
145 {
146  std::ostringstream oss;
147  std::copy(begin, end, infix_ostream_iterator<std::string>(oss, delimiter.c_str()));
148  return oss.str();
149 }
150 
154 template <typename T>
155 std::string
156 join(const T & strings, const std::string & delimiter)
157 {
158  return join(strings.begin(), strings.end(), delimiter);
159 }
160 
164 std::size_t fileSize(const std::string & filename);
165 
169 bool pathContains(const std::string & expression,
170  const std::string & string_to_find,
171  const std::string & delims = "/");
172 
182 bool checkFileReadable(const std::string & filename,
183  bool check_line_endings = false,
184  bool throw_on_unreadable = true,
185  bool check_for_git_lfs_pointer = true);
186 
193 bool checkFileWriteable(const std::string & filename, bool throw_on_unwritable = true);
194 
204 bool checkForGitLFSPointer(std::ifstream & file);
205 
210 void parallelBarrierNotify(const libMesh::Parallel::Communicator & comm, bool messaging = true);
211 
220 void serialBegin(const libMesh::Parallel::Communicator & comm, bool warn = true);
221 
228 void serialEnd(const libMesh::Parallel::Communicator & comm, bool warn = true);
229 
237 bool hasExtension(const std::string & filename, std::string ext, bool strip_exodus_ext = false);
238 
246 std::string getExtension(const std::string & filename, const bool rfind = false);
247 
252 std::string stripExtension(const std::string & s, const bool rfind = false);
253 
261 template <typename T>
262 std::pair<std::filesystem::path, std::filesystem::path>
263 splitFileName(const T & full_file)
264 {
265  const auto p = std::filesystem::path(std::string(full_file));
266  // Error if path ends with /
267  if (!p.has_filename())
268  mooseError("Invalid full file name: ", p);
269 
270  const auto d = p.parent_path();
271  return {d.empty() ? "." : d, p.filename()};
272 }
273 
279 std::string getCurrentWorkingDir();
280 
289 void makedirs(const std::string & dir_name, bool throw_on_failure = false);
290 
299 void removedirs(const std::string & dir_name, bool throw_on_failure = false);
300 
306 std::string camelCaseToUnderscore(const std::string & camel_case_name);
307 
313 std::string underscoreToCamelCase(const std::string & underscore_name, bool leading_upper_case);
314 
318 std::string shortName(const std::string & name);
319 
323 std::string baseName(const std::string & name);
324 
328 std::string hostname();
329 
333 unsigned short getTermWidth(bool use_environment);
334 
338 std::string prettyCppType(const std::string & cpp_type);
339 
343 template <typename T>
344 std::string
345 prettyCppType(const T * obj = nullptr)
346 {
347  if (obj)
348  return prettyCppType(libMesh::demangle(typeid(*obj).name()));
349  else
350  return prettyCppType(libMesh::demangle(typeid(T).name()));
351 }
352 
356 template <typename T1, typename T2>
357 bool
358 doesMapContainValue(const std::map<T1, T2> & the_map, const T2 & value)
359 {
360  for (typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
361  ++iter)
362  if (iter->second == value)
363  return true;
364  return false;
365 }
366 
374 template <
375  typename T,
376  typename T2,
377  typename T3 = T,
378  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
380  int>::type = 0>
381 bool
382 absoluteFuzzyEqual(const T & var1,
383  const T2 & var2,
384  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
385 {
386  return (std::abs(MetaPhysicL::raw_value(var1) - MetaPhysicL::raw_value(var2)) <=
388 }
389 
398 template <
399  typename T,
400  typename T2,
401  typename T3 = T,
402  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
404  int>::type = 0>
405 bool
407  const T2 & var2,
408  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
409 {
410  return (MetaPhysicL::raw_value(var1) >=
412 }
413 
422 template <
423  typename T,
424  typename T2,
425  typename T3 = T,
426  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
428  int>::type = 0>
429 bool
431  const T2 & var2,
432  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
433 {
434  return (MetaPhysicL::raw_value(var1) >
436 }
437 
446 template <
447  typename T,
448  typename T2,
449  typename T3 = T,
450  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
452  int>::type = 0>
453 bool
454 absoluteFuzzyLessEqual(const T & var1,
455  const T2 & var2,
456  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
457 {
458  return (MetaPhysicL::raw_value(var1) <=
460 }
461 
469 template <
470  typename T,
471  typename T2,
472  typename T3 = T,
473  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
475  int>::type = 0>
476 bool
477 absoluteFuzzyLessThan(const T & var1,
478  const T2 & var2,
479  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
480 {
481  return (MetaPhysicL::raw_value(var1) <
483 }
484 
492 template <typename T, typename T2, typename T3 = Real>
493 bool
494 relativeFuzzyEqual(const T & var1,
495  const T2 & var2,
496  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
497 {
498  if constexpr (libMesh::ScalarTraits<T>::value ||
500  {
503  "Mathematical types must be same for arguments to relativelyFuzzEqual");
505  return absoluteFuzzyEqual(
506  var1,
507  var2,
509  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 1)
510  {
511  for (const auto i : make_range(Moose::dim))
512  if (!relativeFuzzyEqual(var1(i), var2(i), tol))
513  return false;
514 
515  return true;
516  }
517  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 2)
518  {
519  for (const auto i : make_range(Moose::dim))
520  for (const auto j : make_range(Moose::dim))
521  if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
522  return false;
523 
524  return true;
525  }
526  }
527  else
528  {
529  // We dare to dream
530  mooseAssert(var1.size() == var2.size(), "These must be the same size");
531  for (const auto i : index_range(var1))
532  if (!relativeFuzzyEqual(var1(i), var2(i), tol))
533  return false;
534 
535  return true;
536  }
537 }
538 
547 template <
548  typename T,
549  typename T2,
550  typename T3 = T,
551  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
553  int>::type = 0>
554 bool
556  const T2 & var2,
557  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
558 {
560  var1,
561  var2,
563 }
564 
572 template <
573  typename T,
574  typename T2,
575  typename T3 = T,
576  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
578  int>::type = 0>
579 bool
581  const T2 & var2,
582  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
583 {
584  return (absoluteFuzzyGreaterThan(
585  var1,
586  var2,
588 }
589 
598 template <
599  typename T,
600  typename T2,
601  typename T3 = T,
602  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
604  int>::type = 0>
605 bool
606 relativeFuzzyLessEqual(const T & var1,
607  const T2 & var2,
608  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
609 {
610  return (absoluteFuzzyLessEqual(
611  var1,
612  var2,
614 }
615 
623 template <
624  typename T,
625  typename T2,
626  typename T3 = T,
627  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
629  int>::type = 0>
630 bool
631 relativeFuzzyLessThan(const T & var1,
632  const T2 & var2,
633  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
634 {
635  return (absoluteFuzzyLessThan(
636  var1,
637  var2,
639 }
640 
645 template <typename T>
646 void
647 getUnion(const std::vector<T> & vector1, const std::vector<T> & vector2, std::vector<T> & common)
648 {
649  std::unordered_set<T> unique_elements;
650  unique_elements.reserve(vector1.size() + vector2.size());
651 
652  for (const T & entry : vector1)
653  unique_elements.insert(entry);
654  for (const T & entry : vector2)
655  unique_elements.insert(entry);
656 
657  // Now populate the common vector with the union
658  common.clear();
659  common.assign(unique_elements.begin(), unique_elements.end());
660 }
661 
667 template <typename T>
668 class Has_size
669 {
670  using Yes = char;
671  struct No
672  {
673  char x[2];
674  };
675 
676  template <typename C>
677  static Yes test(decltype(&C::size));
678  template <typename C>
679  static No test(...);
680 
681 public:
682  static constexpr bool value = sizeof(test<T>(0)) == sizeof(Yes);
683 };
684 
691 template <typename T>
692 bool
693 isZero(const T & value, const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
694 {
695  if constexpr (Has_size<T>::value)
696  {
697  for (const auto & element : value)
698  if (!isZero(element, tolerance))
699  return false;
700 
701  return true;
702  }
703  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 0)
705  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 1)
706  {
707  for (const auto i : make_range(Moose::dim))
709  return false;
710 
711  return true;
712  }
713  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 2)
714  {
715  for (const auto i : make_range(Moose::dim))
716  for (const auto j : make_range(Moose::dim))
718  return false;
719 
720  return true;
721  }
722 }
723 
735 
765 void indentMessage(const std::string & prefix,
766  std::string & message,
767  const char * color = COLOR_CYAN,
768  bool dont_indent_first_line = true,
769  const std::string & post_prefix = ": ");
770 
774 std::string & removeColor(std::string & msg);
775 
776 std::list<std::string> listDir(const std::string path, bool files_only = false);
777 
778 bool pathExists(const std::string & path);
779 
787 std::list<std::string> getFilesInDirs(const std::list<std::string> & directory_list,
788  const bool files_only = true);
789 
795 std::string getLatestCheckpointFilePrefix(const std::list<std::string> & checkpoint_files);
796 
797 /*
798  * Checks to see if a string matches a search string
799  * @param name The name to check
800  * @param search_string The search string to check name against
801  */
802 bool wildCardMatch(std::string name, std::string search_string);
803 
804 /*
805  * Checks to see if a candidate string matches a pattern string, permitting glob
806  * wildcards (* and ?) anywhere in the pattern.
807  * @param candidate The name to check
808  * @param pattern The search string to check name candidate
809  */
810 bool globCompare(const std::string & candidate,
811  const std::string & pattern,
812  std::size_t c = 0,
813  std::size_t p = 0);
814 
815 template <typename T>
816 void
817 expandAllMatches(const std::vector<T> & candidates, std::vector<T> & patterns)
818 {
819  std::set<T> expanded;
820  for (const auto & p : patterns)
821  {
822  unsigned int found = 0;
823  for (const auto & c : candidates)
824  if (globCompare(c, p))
825  {
826  expanded.insert(c);
827  found++;
828  }
829  if (!found)
830  throw std::invalid_argument(p);
831  }
832  patterns.assign(expanded.begin(), expanded.end());
833 }
834 
845 template <typename T>
846 T
847 convert(const std::string & str, bool throw_on_failure = false)
848 {
849  T val;
850  try
851  {
852  convert(str, val, true);
853  }
854  catch (std::exception const & e)
855  {
856  if (throw_on_failure)
857  throw;
858  mooseError(e.what());
859  }
860  return val;
861 }
862 
866 void createSymlink(const std::string & target, const std::string & link);
867 
871 void clearSymlink(const std::string & link);
872 
877 template <typename T>
878 T
879 concatenate(T c1, const T & c2)
880 {
881  c1.insert(c2.begin(), c2.end());
882  return c1;
883 }
884 
888 template <typename T>
889 std::vector<T>
890 concatenate(std::vector<T> c1, const std::vector<T> & c2)
891 {
892  c1.insert(c1.end(), c2.begin(), c2.end());
893  return c1;
894 }
895 
899 template <typename T>
900 std::vector<T>
901 concatenate(std::vector<T> c1, const T & item)
902 {
903  c1.push_back(item);
904  return c1;
905 }
906 
910 std::string stringJoin(const std::vector<std::string> & values,
911  const std::string & separator = " ");
912 
916 bool beginsWith(const std::string & value, const std::string & begin_value);
917 
926 template <typename T>
927 int
928 numDigits(const T & num)
929 {
930  return num > 9 ? static_cast<int>(std::log10(static_cast<double>(num))) + 1 : 1;
931 }
932 
937 
943 int stringToInteger(const std::string & input, bool throw_on_failure = false);
944 
956 void linearPartitionItems(dof_id_type num_items,
957  dof_id_type num_chunks,
958  dof_id_type chunk_id,
959  dof_id_type & num_local_items,
960  dof_id_type & local_items_begin,
961  dof_id_type & local_items_end);
962 
972 linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id);
973 
977 std::string realpath(const std::string & path);
978 
984 template <typename T>
986 {
987  static constexpr bool value = false;
988 };
989 template <>
991 {
992  static constexpr bool value = true;
993 };
994 template <>
996 {
997  static constexpr bool value = true;
998 };
999 
1003 template <typename T>
1005 {
1006  static constexpr bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1007  TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1008 };
1009 
1011 const static struct AnyType
1012 {
1013 } Any;
1014 
1015 template <typename T1, typename T2>
1016 bool
1017 wildcardEqual(const T1 & a, const T2 & b)
1018 {
1019  return a == b;
1020 }
1021 
1022 template <typename T>
1023 bool
1025 {
1026  return true;
1027 }
1028 template <typename T>
1029 bool
1031 {
1032  return true;
1033 }
1035 
1039 template <typename C, typename It, typename M1, typename M2>
1040 auto
1041 findPair(C & container, It start_iterator, const M1 & first, const M2 & second)
1042 {
1043  return std::find_if(start_iterator,
1044  container.end(),
1045  [&](auto & item) {
1046  return wildcardEqual(first, item.first) &&
1047  wildcardEqual(second, item.second);
1048  });
1049 }
1050 
1066 libMesh::BoundingBox buildBoundingBox(const Point & p1, const Point & p2);
1067 
1075 template <typename T, std::size_t N, bool value_init = true>
1076 class SemidynamicVector : public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1077 {
1078  typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1079 
1080 public:
1081  SemidynamicVector(std::size_t size) : Parent()
1082  {
1083  Parent::resize(size);
1084  if constexpr (value_init)
1085  for (const auto i : make_range(size))
1086  _data[i] = T{};
1087  }
1088 
1089  void resize(std::size_t new_size)
1090  {
1091  [[maybe_unused]] const auto old_dynamic_n = Parent::size();
1092 
1093  Parent::resize(new_size);
1094 
1095  if constexpr (value_init)
1096  for (const auto i : make_range(old_dynamic_n, _dynamic_n))
1097  _data[i] = T{};
1098  }
1099 
1100  void push_back(const T & v)
1101  {
1102  const auto old_dynamic_n = Parent::size();
1103  Parent::resize(old_dynamic_n + 1);
1104  _data[old_dynamic_n] = v;
1105  }
1106 
1107  template <typename... Args>
1108  void emplace_back(Args &&... args)
1109  {
1110  const auto old_dynamic_n = Parent::size();
1111  Parent::resize(old_dynamic_n + 1);
1112  (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1113  }
1114 
1115  std::size_t max_size() const { return N; }
1116 
1117  using Parent::_data;
1118  using Parent::_dynamic_n;
1119 };
1120 
1133 template <typename T>
1134 T *
1135 get(const std::unique_ptr<T> & u)
1136 {
1137  return u.get();
1138 }
1139 
1140 template <typename T>
1141 T *
1142 get(T * p)
1143 {
1144  return p;
1145 }
1146 
1147 template <typename T>
1148 T *
1149 get(const std::shared_ptr<T> & s)
1150 {
1151  return s.get();
1152 }
1153 
1158 template <class InputIterator>
1159 bool
1160 setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1161 {
1162  while (first1 != last1 && first2 != last2)
1163  {
1164  if (*first1 == *first2)
1165  return true;
1166 
1167  if (*first1 < *first2)
1168  ++first1;
1169  else if (*first1 > *first2)
1170  ++first2;
1171  }
1172  return false;
1173 }
1174 
1175 template <class T>
1176 bool
1177 setsIntersect(const T & s1, const T & s2)
1178 {
1179  return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1180 }
1181 
1187 inline bool
1188 isDigits(const std::string & str)
1189 {
1190  return std::all_of(str.begin(), str.end(), [](unsigned char c) { return std::isdigit(c); });
1191 }
1192 
1198 inline bool
1199 isFloat(const std::string & str)
1200 {
1201  if (str.empty())
1202  return false;
1203  char * ptr;
1204  strtof(str.c_str(), &ptr);
1205  return (*ptr) == '\0';
1206 }
1207 
1211 std::string canonicalPath(const std::string & path);
1212 
1216 bool startsWith(const std::string & string1, const std::string & string2);
1217 
1222 void replaceStart(std::string & string1, const std::string & string2, const std::string & string3);
1223 
1227 bool isAllLowercase(const std::string & str);
1228 } // MooseUtils namespace
1229 
1230 namespace Moose
1231 {
1232 template <typename T>
1233 struct ADType;
1234 
1235 template <typename T, std::size_t N, bool value_init>
1236 struct ADType<MooseUtils::SemidynamicVector<T, N, value_init>>
1237 {
1239 };
1240 }
1241 
1245 void removeSubstring(std::string & main, const std::string & sub);
1246 
1250 std::string removeSubstring(const std::string & main, const std::string & sub);
std::string name(const ElemQuality q)
std::string docsDir(const std::string &app_name)
Returns the directory of any installed docs/site.
Definition: MooseUtils.C:125
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:42
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c=0, std::size_t p=0)
Definition: MooseUtils.C:932
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
Definition: MooseUtils.h:144
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
Taken from https://stackoverflow.com/a/257382 Evaluating constexpr (Has_size<T>::value) in a template...
Definition: MooseUtils.h:668
void serialEnd(const libMesh::Parallel::Communicator &comm, bool warn=true)
Closes a section of code that is executed in serial rank by rank, and that was opened with a call to ...
Definition: MooseUtils.C:371
static Yes test(decltype(&C::size))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:382
bool beginsWith(const std::string &value, const std::string &begin_value)
Definition: MooseUtils.C:966
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Definition: HashMap.h:18
SemidynamicVector(std::size_t size)
Definition: MooseUtils.h:1081
int stringToInteger(const std::string &input, bool throw_on_failure=false)
Robust string to integer conversion that fails for cases such at "1foo".
Definition: MooseUtils.C:978
bool relativeFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within a relative tolerance...
Definition: MooseUtils.h:580
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
void MaterialPropertyStorageDump(const HashMap< const libMesh::Elem *, HashMap< unsigned int, MaterialProperties >> &props)
Function to dump the contents of MaterialPropertyStorage for debugging purposes.
Definition: MooseUtils.C:688
static constexpr Real TOLERANCE
std::string installedInputsDir(const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg="")
Returns the directory of any installed inputs or the empty string if none are found.
Definition: MooseUtils.C:103
bool parsesToReal(const std::string &input, Real *parsed_real=nullptr)
Check if the input string can be parsed into a Real.
Definition: MooseUtils.C:89
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:693
bool isAllLowercase(const std::string &str)
Definition: MooseUtils.C:1193
bool doesMapContainValue(const std::map< T1, T2 > &the_map, const T2 &value)
This routine is a simple helper function for searching a map by values instead of keys...
Definition: MooseUtils.h:358
bool startsWith(const std::string &string1, const std::string &string2)
Definition: MooseUtils.C:1177
void push_back(const T &v)
Definition: MooseUtils.h:1100
std::size_t max_size() const
Definition: MooseUtils.h:1115
bool setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
This method detects whether two sets intersect without building a result set.
Definition: MooseUtils.h:1160
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
Definition: MooseUtils.h:263
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
static constexpr bool value
Definition: MooseUtils.h:1006
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list, const bool files_only=true)
Retrieves the names of all of the files contained within the list of directories passed into the rout...
Definition: MooseUtils.C:808
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:162
void removedirs(const std::string &dir_name, bool throw_on_failure=false)
Recursively remove directories from inner-most when the directories are empty.
Definition: MooseUtils.C:505
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
void linearPartitionItems(dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
Linearly partition a number of items.
Definition: MooseUtils.C:984
bool checkForGitLFSPointer(std::ifstream &file)
Check if the file is a Git-LFS pointer.
Definition: MooseUtils.C:290
bool relativeFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than or equal to another variable within a relative tole...
Definition: MooseUtils.h:606
std::string realpath(const std::string &path)
Wrapper around PetscGetRealPath, which is a cross-platform replacement for realpath.
Definition: MooseUtils.C:1136
T concatenate(T c1, const T &c2)
Returns a container that contains the content of second passed in container inserted into the first p...
Definition: MooseUtils.h:879
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:46
bool isFloat(const std::string &str)
Courtesy https://stackoverflow.com/a/57163016 and https://stackoverflow.com/questions/447206/c-isfloa...
Definition: MooseUtils.h:1199
bool relativeFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within a relative t...
Definition: MooseUtils.h:555
std::string convertLatestCheckpoint(std::string orig)
Replaces "LATEST" placeholders with the latest checkpoint file name.
Definition: MooseUtils.C:157
std::string mooseDocsURL(const std::string &path)
Returns the URL of a page located on the MOOSE documentation site.
Definition: MooseUtils.C:139
std::string hostname()
Get the hostname the current process is running on.
Definition: MooseUtils.C:624
auto max(const L &left, const R &right)
bool convert(const std::string &str, T &value, const bool throw_on_failure)
Takes the string representation of a value and converts it to the value.
std::string camelCaseToUnderscore(const std::string &camel_case_name)
Function for converting a camel case name to a name containing underscores.
Definition: MooseUtils.C:568
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:612
Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size...
Definition: MooseUtils.h:1076
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Python like split functions for strings.
Definition: MooseUtils.C:1031
MooseUtils::SemidynamicVector< typename ADType< T >::type, N, value_init > type
Definition: MooseUtils.h:1238
Custom type trait that has a value of true for types that can be broadcasted.
Definition: MooseUtils.h:1004
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
Definition: MooseUtils.C:972
std::string getExtension(const std::string &filename, const bool rfind=false)
Gets the extension of the passed file name.
Definition: MooseUtils.C:411
void replaceStart(std::string &string1, const std::string &string2, const std::string &string3)
Replace the starting string string2 of string1 with string3.
Definition: MooseUtils.C:1185
std::vector< std::string > rsplit(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Definition: MooseUtils.C:1051
uint8_t processor_id_type
Custom type trait that has a value of true for types that cam be use interchangeably with Real...
Definition: MooseUtils.h:985
std::string stripExtension(const std::string &s, const bool rfind=false)
Removes any file extension from the given string s (i.e.
Definition: MooseUtils.C:427
void resize(std::size_t new_size)
Definition: MooseUtils.h:1089
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN, bool dont_indent_first_line=true, const std::string &post_prefix=": ")
Indents the supplied message given the prefix and color.
Definition: MooseUtils.C:738
void parallelBarrierNotify(const libMesh::Parallel::Communicator &comm, bool messaging=true)
This function implements a parallel barrier function but writes progress to stdout.
Definition: MooseUtils.C:327
std::string getLatestCheckpointFilePrefix(const std::list< std::string > &checkpoint_files)
Returns the most recent checkpoint prefix (the four numbers at the beginning) If a suitable file isn&#39;...
Definition: MooseUtils.C:819
void serialBegin(const libMesh::Parallel::Communicator &comm, bool warn=true)
This function marks the begin of a section of code that is executed in serial rank by rank...
Definition: MooseUtils.C:357
std::string canonicalPath(const std::string &path)
Gets the canonical path of the given path.
Definition: MooseUtils.C:1171
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
Definition: MooseUtils.C:254
std::string runTestsExecutable()
Returns the location of either a local repo run_tests script - or an installed test executor script i...
Definition: MooseUtils.C:65
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
Definition: MooseUtils.h:477
bool wildcardEqual(const T1 &a, const T2 &b)
Definition: MooseUtils.h:1017
void expandAllMatches(const std::vector< T > &candidates, std::vector< T > &patterns)
Definition: MooseUtils.h:817
std::size_t fileSize(const std::string &filename)
Check the file size.
Definition: MooseUtils.C:1106
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
Function for converting an underscore name to a camel case name.
Definition: MooseUtils.C:580
MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
Definition: MooseUtils.h:1078
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:387
std::string & removeColor(std::string &msg)
remove ANSI escape sequences for terminal color from msg
Definition: MooseUtils.C:722
std::string demangle(const char *name)
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable=true)
Check if the file is writable (path exists and permissions)
Definition: MooseUtils.C:307
int main(int argc, char *argv[])
Initialize, create and run a MooseApp.
Definition: MooseMain.h:31
charT const * delimiter
Definition: InfixIterator.h:34
static constexpr bool value
Definition: MooseUtils.h:682
auto findPair(C &container, It start_iterator, const M1 &first, const M2 &second)
Find a specific pair in a container matching on first, second or both pair components.
Definition: MooseUtils.h:1041
void clearSymlink(const std::string &link)
Remove a symbolic link, if the given filename is a link.
Definition: MooseUtils.C:1084
processor_id_type linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
Return the chunk_id that is assigned to handle item_id.
Definition: MooseUtils.C:1010
void createSymlink(const std::string &target, const std::string &link)
Create a symbolic link, if the link already exists it is replaced.
Definition: MooseUtils.C:1071
std::filesystem::path pathjoin(const std::filesystem::path &p)
Definition: MooseUtils.C:59
void removeSubstring(std::string &main, const std::string &sub)
find, erase, length algorithm for removing a substring from a string
Definition: MooseUtils.C:1201
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:618
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int numDigits(const T &num)
Return the number of digits for a number.
Definition: MooseUtils.h:928
void getUnion(const std::vector< T > &vector1, const std::vector< T > &vector2, std::vector< T > &common)
Function which takes the union of vector1 and vector2 and copies them to common . ...
Definition: MooseUtils.h:647
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:888
bool relativeFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within a relative tolerance.
Definition: MooseUtils.h:494
Comparison helpers that support the MooseUtils::Any wildcard which will match any value...
Definition: MooseUtils.h:1011
bool absoluteFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than or equal to another variable within an absolute tol...
Definition: MooseUtils.h:454
IntRange< T > make_range(T beg, T end)
std::list< std::string > listDir(const std::string path, bool files_only=false)
Definition: MooseUtils.C:782
void emplace_back(Args &&... args)
Definition: MooseUtils.h:1108
libMesh::BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
Definition: MooseUtils.C:1142
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within an absolute ...
Definition: MooseUtils.h:406
int levenshteinDist(const std::string &s1, const std::string &s2)
Computes and returns the Levenshtein distance between strings s1 and s2.
Definition: MooseUtils.C:176
std::string getCurrentWorkingDir()
Returns the current working directory as a string.
Definition: MooseUtils.C:436
void makedirs(const std::string &dir_name, bool throw_on_failure=false)
Recursively make directories.
Definition: MooseUtils.C:449
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
static constexpr bool value
Definition: MooseUtils.h:987
std::string removeExtraWhitespace(const std::string &str)
Removes additional whitespace from a string.
Definition: MooseUtils.C:225
static const struct MooseUtils::AnyType Any
bool 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...
Definition: MooseUtils.C:231
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
Definition: MooseUtils.h:1188
bool pathExists(const std::string &path)
Definition: MooseUtils.C:247
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
Replaces all occurrences of from in str with to and returns the result.
Definition: MooseUtils.C:145
bool relativeFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within a relative tolerance...
Definition: MooseUtils.h:631
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.
Definition: MooseUtils.C:955
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
auto index_range(const T &sizable)
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
Definition: MooseUtils.h:430
void escape(std::string &str)
This function will escape all of the standard C++ escape characters so that they can be printed...
Definition: MooseUtils.C:207
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1151
uint8_t dof_id_type
std::string findTestRoot()
Searches in the current working directory and then recursively up in each parent directory looking fo...
Definition: MooseUtils.C:75
unsigned short getTermWidth(bool use_environment)
Returns the width of the terminal using sys/ioctl.
Definition: MooseUtils.C:640