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 
71 bool parsesToReal(const std::string & input);
72 
75 std::string runTestsExecutable();
76 
80 std::string findTestRoot();
81 
83 std::string installedInputsDir(const std::string & app_name,
84  const std::string & dir_name,
85  const std::string & extra_error_msg = "");
86 
88 std::string docsDir(const std::string & app_name);
89 
97 std::string mooseDocsURL(const std::string & path);
98 
100 std::string replaceAll(std::string str, const std::string & from, const std::string & to);
101 
105 std::string convertLatestCheckpoint(std::string orig);
106 
108 int levenshteinDist(const std::string & s1, const std::string & s2);
109 
115 void escape(std::string & str);
116 
122 std::string removeExtraWhitespace(const std::string & str);
123 
130 std::vector<std::string> split(const std::string & str,
131  const std::string & delimiter,
132  std::size_t max_count = std::numeric_limits<std::size_t>::max());
133 std::vector<std::string> rsplit(const std::string & str,
134  const std::string & delimiter,
135  std::size_t max_count = std::numeric_limits<std::size_t>::max());
136 
140 template <typename Iterator>
141 std::string
142 join(Iterator begin, Iterator end, const std::string & delimiter)
143 {
144  std::ostringstream oss;
145  std::copy(begin, end, infix_ostream_iterator<std::string>(oss, delimiter.c_str()));
146  return oss.str();
147 }
148 
152 template <typename T>
153 std::string
154 join(const T & strings, const std::string & delimiter)
155 {
156  return join(strings.begin(), strings.end(), delimiter);
157 }
158 
162 std::size_t fileSize(const std::string & filename);
163 
167 bool pathContains(const std::string & expression,
168  const std::string & string_to_find,
169  const std::string & delims = "/");
170 
180 bool checkFileReadable(const std::string & filename,
181  bool check_line_endings = false,
182  bool throw_on_unreadable = true,
183  bool check_for_git_lfs_pointer = true);
184 
191 bool checkFileWriteable(const std::string & filename, bool throw_on_unwritable = true);
192 
202 bool checkForGitLFSPointer(std::ifstream & file);
203 
208 void parallelBarrierNotify(const libMesh::Parallel::Communicator & comm, bool messaging = true);
209 
218 void serialBegin(const libMesh::Parallel::Communicator & comm, bool warn = true);
219 
226 void serialEnd(const libMesh::Parallel::Communicator & comm, bool warn = true);
227 
235 bool hasExtension(const std::string & filename, std::string ext, bool strip_exodus_ext = false);
236 
244 std::string getExtension(const std::string & filename, const bool rfind = false);
245 
250 std::string stripExtension(const std::string & s, const bool rfind = false);
251 
259 template <typename T>
260 std::pair<std::filesystem::path, std::filesystem::path>
261 splitFileName(const T & full_file)
262 {
263  const auto p = std::filesystem::path(std::string(full_file));
264  // Error if path ends with /
265  if (!p.has_filename())
266  mooseError("Invalid full file name: ", p);
267 
268  const auto d = p.parent_path();
269  return {d.empty() ? "." : d, p.filename()};
270 }
271 
277 std::string getCurrentWorkingDir();
278 
287 void makedirs(const std::string & dir_name, bool throw_on_failure = false);
288 
297 void removedirs(const std::string & dir_name, bool throw_on_failure = false);
298 
304 std::string camelCaseToUnderscore(const std::string & camel_case_name);
305 
311 std::string underscoreToCamelCase(const std::string & underscore_name, bool leading_upper_case);
312 
316 std::string shortName(const std::string & name);
317 
321 std::string baseName(const std::string & name);
322 
326 std::string hostname();
327 
331 unsigned short getTermWidth(bool use_environment);
332 
336 std::string prettyCppType(const std::string & cpp_type);
337 
341 template <typename T>
342 std::string
343 prettyCppType(const T * obj = nullptr)
344 {
345  if (obj)
346  return prettyCppType(libMesh::demangle(typeid(*obj).name()));
347  else
348  return prettyCppType(libMesh::demangle(typeid(T).name()));
349 }
350 
354 template <typename T1, typename T2>
355 bool
356 doesMapContainValue(const std::map<T1, T2> & the_map, const T2 & value)
357 {
358  for (typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
359  ++iter)
360  if (iter->second == value)
361  return true;
362  return false;
363 }
364 
372 template <
373  typename T,
374  typename T2,
375  typename T3 = T,
376  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
378  int>::type = 0>
379 bool
380 absoluteFuzzyEqual(const T & var1,
381  const T2 & var2,
382  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
383 {
384  return (std::abs(MetaPhysicL::raw_value(var1) - MetaPhysicL::raw_value(var2)) <=
386 }
387 
396 template <
397  typename T,
398  typename T2,
399  typename T3 = T,
400  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
402  int>::type = 0>
403 bool
405  const T2 & var2,
406  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
407 {
408  return (MetaPhysicL::raw_value(var1) >=
410 }
411 
420 template <
421  typename T,
422  typename T2,
423  typename T3 = T,
424  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
426  int>::type = 0>
427 bool
429  const T2 & var2,
430  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
431 {
432  return (MetaPhysicL::raw_value(var1) >
434 }
435 
444 template <
445  typename T,
446  typename T2,
447  typename T3 = T,
448  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
450  int>::type = 0>
451 bool
452 absoluteFuzzyLessEqual(const T & var1,
453  const T2 & var2,
454  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
455 {
456  return (MetaPhysicL::raw_value(var1) <=
458 }
459 
467 template <
468  typename T,
469  typename T2,
470  typename T3 = T,
471  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
473  int>::type = 0>
474 bool
475 absoluteFuzzyLessThan(const T & var1,
476  const T2 & var2,
477  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
478 {
479  return (MetaPhysicL::raw_value(var1) <
481 }
482 
490 template <typename T, typename T2, typename T3 = Real>
491 bool
492 relativeFuzzyEqual(const T & var1,
493  const T2 & var2,
494  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
495 {
496  if constexpr (libMesh::ScalarTraits<T>::value ||
498  {
501  "Mathematical types must be same for arguments to relativelyFuzzEqual");
503  return absoluteFuzzyEqual(
504  var1,
505  var2,
507  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 1)
508  {
509  for (const auto i : make_range(Moose::dim))
510  if (!relativeFuzzyEqual(var1(i), var2(i), tol))
511  return false;
512 
513  return true;
514  }
515  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 2)
516  {
517  for (const auto i : make_range(Moose::dim))
518  for (const auto j : make_range(Moose::dim))
519  if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
520  return false;
521 
522  return true;
523  }
524  }
525  else
526  {
527  // We dare to dream
528  mooseAssert(var1.size() == var2.size(), "These must be the same size");
529  for (const auto i : index_range(var1))
530  if (!relativeFuzzyEqual(var1(i), var2(i), tol))
531  return false;
532 
533  return true;
534  }
535 }
536 
545 template <
546  typename T,
547  typename T2,
548  typename T3 = T,
549  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
551  int>::type = 0>
552 bool
554  const T2 & var2,
555  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
556 {
558  var1,
559  var2,
561 }
562 
570 template <
571  typename T,
572  typename T2,
573  typename T3 = T,
574  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
576  int>::type = 0>
577 bool
579  const T2 & var2,
580  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
581 {
582  return (absoluteFuzzyGreaterThan(
583  var1,
584  var2,
586 }
587 
596 template <
597  typename T,
598  typename T2,
599  typename T3 = T,
600  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
602  int>::type = 0>
603 bool
604 relativeFuzzyLessEqual(const T & var1,
605  const T2 & var2,
606  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
607 {
608  return (absoluteFuzzyLessEqual(
609  var1,
610  var2,
612 }
613 
621 template <
622  typename T,
623  typename T2,
624  typename T3 = T,
625  typename std::enable_if<libMesh::ScalarTraits<T>::value && libMesh::ScalarTraits<T2>::value &&
627  int>::type = 0>
628 bool
629 relativeFuzzyLessThan(const T & var1,
630  const T2 & var2,
631  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
632 {
633  return (absoluteFuzzyLessThan(
634  var1,
635  var2,
637 }
638 
643 template <typename T>
644 void
645 getUnion(const std::vector<T> & vector1, const std::vector<T> & vector2, std::vector<T> & common)
646 {
647  std::unordered_set<T> unique_elements;
648  unique_elements.reserve(vector1.size() + vector2.size());
649 
650  for (const T & entry : vector1)
651  unique_elements.insert(entry);
652  for (const T & entry : vector2)
653  unique_elements.insert(entry);
654 
655  // Now populate the common vector with the union
656  common.clear();
657  common.assign(unique_elements.begin(), unique_elements.end());
658 }
659 
665 template <typename T>
666 class Has_size
667 {
668  using Yes = char;
669  struct No
670  {
671  char x[2];
672  };
673 
674  template <typename C>
675  static Yes test(decltype(&C::size));
676  template <typename C>
677  static No test(...);
678 
679 public:
680  static constexpr bool value = sizeof(test<T>(0)) == sizeof(Yes);
681 };
682 
689 template <typename T>
690 bool
691 isZero(const T & value, const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
692 {
693  if constexpr (Has_size<T>::value)
694  {
695  for (const auto & element : value)
696  if (!isZero(element, tolerance))
697  return false;
698 
699  return true;
700  }
701  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 0)
703  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 1)
704  {
705  for (const auto i : make_range(Moose::dim))
707  return false;
708 
709  return true;
710  }
711  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 2)
712  {
713  for (const auto i : make_range(Moose::dim))
714  for (const auto j : make_range(Moose::dim))
716  return false;
717 
718  return true;
719  }
720 }
721 
733 
763 void indentMessage(const std::string & prefix,
764  std::string & message,
765  const char * color = COLOR_CYAN,
766  bool dont_indent_first_line = true,
767  const std::string & post_prefix = ": ");
768 
772 std::string & removeColor(std::string & msg);
773 
774 std::list<std::string> listDir(const std::string path, bool files_only = false);
775 
776 bool pathExists(const std::string & path);
777 
785 std::list<std::string> getFilesInDirs(const std::list<std::string> & directory_list,
786  const bool files_only = true);
787 
793 std::string getLatestCheckpointFilePrefix(const std::list<std::string> & checkpoint_files);
794 
795 /*
796  * Checks to see if a string matches a search string
797  * @param name The name to check
798  * @param search_string The search string to check name against
799  */
800 bool wildCardMatch(std::string name, std::string search_string);
801 
802 /*
803  * Checks to see if a candidate string matches a pattern string, permitting glob
804  * wildcards (* and ?) anywhere in the pattern.
805  * @param candidate The name to check
806  * @param pattern The search string to check name candidate
807  */
808 bool globCompare(const std::string & candidate,
809  const std::string & pattern,
810  std::size_t c = 0,
811  std::size_t p = 0);
812 
813 template <typename T>
814 void
815 expandAllMatches(const std::vector<T> & candidates, std::vector<T> & patterns)
816 {
817  std::set<T> expanded;
818  for (const auto & p : patterns)
819  {
820  unsigned int found = 0;
821  for (const auto & c : candidates)
822  if (globCompare(c, p))
823  {
824  expanded.insert(c);
825  found++;
826  }
827  if (!found)
828  throw std::invalid_argument(p);
829  }
830  patterns.assign(expanded.begin(), expanded.end());
831 }
832 
838 template <typename T>
839 T
840 convert(const std::string & str, bool throw_on_failure = false)
841 {
842  std::stringstream ss(str);
843  T val;
844  if ((ss >> val).fail() || !ss.eof())
845  {
846  std::string msg = std::string("Unable to convert '") + str + "' to type " +
847  libMesh::demangle(typeid(T).name());
848 
849  if (throw_on_failure)
850  throw std::invalid_argument(msg);
851  else
852  mooseError(msg);
853  }
854 
855  return val;
856 }
857 
858 template <>
859 short int convert<short int>(const std::string & str, bool throw_on_failure);
860 
861 template <>
862 unsigned short int convert<unsigned short int>(const std::string & str, bool throw_on_failure);
863 
864 template <>
865 int convert<int>(const std::string & str, bool throw_on_failure);
866 
867 template <>
868 unsigned int convert<unsigned int>(const std::string & str, bool throw_on_failure);
869 
870 template <>
871 long int convert<long int>(const std::string & str, bool throw_on_failure);
872 
873 template <>
874 unsigned long int convert<unsigned long int>(const std::string & str, bool throw_on_failure);
875 
876 template <>
877 long long int convert<long long int>(const std::string & str, bool throw_on_failure);
878 
879 template <>
880 unsigned long long int convert<unsigned long long int>(const std::string & str,
881  bool throw_on_failure);
882 
886 void createSymlink(const std::string & target, const std::string & link);
887 
891 void clearSymlink(const std::string & link);
892 
897 template <typename T>
898 T
899 concatenate(T c1, const T & c2)
900 {
901  c1.insert(c2.begin(), c2.end());
902  return c1;
903 }
904 
908 template <typename T>
909 std::vector<T>
910 concatenate(std::vector<T> c1, const std::vector<T> & c2)
911 {
912  c1.insert(c1.end(), c2.begin(), c2.end());
913  return c1;
914 }
915 
919 template <typename T>
920 std::vector<T>
921 concatenate(std::vector<T> c1, const T & item)
922 {
923  c1.push_back(item);
924  return c1;
925 }
926 
930 std::string stringJoin(const std::vector<std::string> & values,
931  const std::string & separator = " ");
932 
936 bool beginsWith(const std::string & value, const std::string & begin_value);
937 
946 template <typename T>
947 int
948 numDigits(const T & num)
949 {
950  return num > 9 ? static_cast<int>(std::log10(static_cast<double>(num))) + 1 : 1;
951 }
952 
957 
963 int stringToInteger(const std::string & input, bool throw_on_failure = false);
964 
976 void linearPartitionItems(dof_id_type num_items,
977  dof_id_type num_chunks,
978  dof_id_type chunk_id,
979  dof_id_type & num_local_items,
980  dof_id_type & local_items_begin,
981  dof_id_type & local_items_end);
982 
992 linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id);
993 
997 std::string realpath(const std::string & path);
998 
1004 template <typename T>
1006 {
1007  static constexpr bool value = false;
1008 };
1009 template <>
1011 {
1012  static constexpr bool value = true;
1013 };
1014 template <>
1016 {
1017  static constexpr bool value = true;
1018 };
1019 
1023 template <typename T>
1025 {
1026  static constexpr bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1027  TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1028 };
1029 
1031 const static struct AnyType
1032 {
1033 } Any;
1034 
1035 template <typename T1, typename T2>
1036 bool
1037 wildcardEqual(const T1 & a, const T2 & b)
1038 {
1039  return a == b;
1040 }
1041 
1042 template <typename T>
1043 bool
1045 {
1046  return true;
1047 }
1048 template <typename T>
1049 bool
1051 {
1052  return true;
1053 }
1055 
1059 template <typename C, typename It, typename M1, typename M2>
1060 auto
1061 findPair(C & container, It start_iterator, const M1 & first, const M2 & second)
1062 {
1063  return std::find_if(start_iterator,
1064  container.end(),
1065  [&](auto & item) {
1066  return wildcardEqual(first, item.first) &&
1067  wildcardEqual(second, item.second);
1068  });
1069 }
1070 
1086 libMesh::BoundingBox buildBoundingBox(const Point & p1, const Point & p2);
1087 
1095 template <typename T, std::size_t N, bool value_init = true>
1096 class SemidynamicVector : public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1097 {
1098  typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1099 
1100 public:
1101  SemidynamicVector(std::size_t size) : Parent()
1102  {
1103  Parent::resize(size);
1104  if constexpr (value_init)
1105  for (const auto i : make_range(size))
1106  _data[i] = T{};
1107  }
1108 
1109  void resize(std::size_t new_size)
1110  {
1111  [[maybe_unused]] const auto old_dynamic_n = Parent::size();
1112 
1113  Parent::resize(new_size);
1114 
1115  if constexpr (value_init)
1116  for (const auto i : make_range(old_dynamic_n, _dynamic_n))
1117  _data[i] = T{};
1118  }
1119 
1120  void push_back(const T & v)
1121  {
1122  const auto old_dynamic_n = Parent::size();
1123  Parent::resize(old_dynamic_n + 1);
1124  _data[old_dynamic_n] = v;
1125  }
1126 
1127  template <typename... Args>
1128  void emplace_back(Args &&... args)
1129  {
1130  const auto old_dynamic_n = Parent::size();
1131  Parent::resize(old_dynamic_n + 1);
1132  (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1133  }
1134 
1135  std::size_t max_size() const { return N; }
1136 
1137  using Parent::_data;
1138  using Parent::_dynamic_n;
1139 };
1140 
1153 template <typename T>
1154 T *
1155 get(const std::unique_ptr<T> & u)
1156 {
1157  return u.get();
1158 }
1159 
1160 template <typename T>
1161 T *
1162 get(T * p)
1163 {
1164  return p;
1165 }
1166 
1167 template <typename T>
1168 T *
1169 get(const std::shared_ptr<T> & s)
1170 {
1171  return s.get();
1172 }
1173 
1178 template <class InputIterator>
1179 bool
1180 setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1181 {
1182  while (first1 != last1 && first2 != last2)
1183  {
1184  if (*first1 == *first2)
1185  return true;
1186 
1187  if (*first1 < *first2)
1188  ++first1;
1189  else if (*first1 > *first2)
1190  ++first2;
1191  }
1192  return false;
1193 }
1194 
1195 template <class T>
1196 bool
1197 setsIntersect(const T & s1, const T & s2)
1198 {
1199  return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1200 }
1201 
1207 inline bool
1208 isDigits(const std::string & str)
1209 {
1210  return std::all_of(str.begin(), str.end(), [](unsigned char c) { return std::isdigit(c); });
1211 }
1212 
1218 inline bool
1219 isFloat(const std::string & str)
1220 {
1221  if (str.empty())
1222  return false;
1223  char * ptr;
1224  strtof(str.c_str(), &ptr);
1225  return (*ptr) == '\0';
1226 }
1227 
1231 std::string canonicalPath(const std::string & path);
1232 
1236 bool startsWith(const std::string & string1, const std::string & string2);
1237 
1242 void replaceStart(std::string & string1, const std::string & string2, const std::string & string3);
1243 
1247 bool isAllLowercase(const std::string & str);
1248 } // MooseUtils namespace
1249 
1250 namespace Moose
1251 {
1252 template <typename T>
1253 struct ADType;
1254 
1255 template <typename T, std::size_t N, bool value_init>
1256 struct ADType<MooseUtils::SemidynamicVector<T, N, value_init>>
1257 {
1259 };
1260 }
1261 
1265 void removeSubstring(std::string & main, const std::string & sub);
1266 
1270 std::string removeSubstring(const std::string & main, const std::string & sub);
std::string name(const ElemQuality q)
bool parsesToReal(const std::string &input)
Check if the input string can be parsed into a Real.
Definition: MooseUtils.C:89
std::string docsDir(const std::string &app_name)
Returns the directory of any installed docs/site.
Definition: MooseUtils.C:121
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:928
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
Definition: MooseUtils.h:142
T convert(const std::string &str, bool throw_on_failure=false)
convert takes a string representation of a number type and converts it to the number.
Definition: MooseUtils.h:840
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:666
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:367
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:380
bool beginsWith(const std::string &value, const std::string &begin_value)
Definition: MooseUtils.C:1061
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:1101
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:1073
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:578
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
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:684
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:99
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691
bool isAllLowercase(const std::string &str)
Definition: MooseUtils.C:1288
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:356
bool startsWith(const std::string &string1, const std::string &string2)
Definition: MooseUtils.C:1272
void push_back(const T &v)
Definition: MooseUtils.h:1120
std::size_t max_size() const
Definition: MooseUtils.h:1135
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:1180
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
Definition: MooseUtils.h:261
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:73
static constexpr bool value
Definition: MooseUtils.h:1026
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:804
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:154
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:501
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:1079
bool checkForGitLFSPointer(std::ifstream &file)
Check if the file is a Git-LFS pointer.
Definition: MooseUtils.C:286
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:604
std::string realpath(const std::string &path)
Wrapper around PetscGetRealPath, which is a cross-platform replacement for realpath.
Definition: MooseUtils.C:1231
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:899
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:1219
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:553
std::string convertLatestCheckpoint(std::string orig)
Replaces "LATEST" placeholders with the latest checkpoint file name.
Definition: MooseUtils.C:153
std::string mooseDocsURL(const std::string &path)
Returns the URL of a page located on the MOOSE documentation site.
Definition: MooseUtils.C:135
std::string hostname()
Get the hostname the current process is running on.
Definition: MooseUtils.C:620
auto max(const L &left, const R &right)
std::string camelCaseToUnderscore(const std::string &camel_case_name)
Function for converting a camel case name to a name containing underscores.
Definition: MooseUtils.C:564
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Definition: MooseUtils.C:608
Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size...
Definition: MooseUtils.h:1096
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:1126
MooseUtils::SemidynamicVector< typename ADType< T >::type, N, value_init > type
Definition: MooseUtils.h:1258
Custom type trait that has a value of true for types that can be broadcasted.
Definition: MooseUtils.h:1024
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
Definition: MooseUtils.C:1067
std::string getExtension(const std::string &filename, const bool rfind=false)
Gets the extension of the passed file name.
Definition: MooseUtils.C:407
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:1280
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:1146
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:1005
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:423
void resize(std::size_t new_size)
Definition: MooseUtils.h:1109
int convert< int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1009
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:734
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:323
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:815
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:353
std::string canonicalPath(const std::string &path)
Gets the canonical path of the given path.
Definition: MooseUtils.C:1266
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:250
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:475
bool wildcardEqual(const T1 &a, const T2 &b)
Definition: MooseUtils.h:1037
void expandAllMatches(const std::vector< T > &candidates, std::vector< T > &patterns)
Definition: MooseUtils.h:815
std::size_t fileSize(const std::string &filename)
Check the file size.
Definition: MooseUtils.C:1201
unsigned int convert< unsigned int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1016
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:576
MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
Definition: MooseUtils.h:1098
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:383
std::string & removeColor(std::string &msg)
remove ANSI escape sequences for terminal color from msg
Definition: MooseUtils.C:718
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:303
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:680
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:1061
void clearSymlink(const std::string &link)
Remove a symbolic link, if the given filename is a link.
Definition: MooseUtils.C:1179
long long int convert< long long int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1037
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:1105
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:1166
short int convert< short int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:995
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:1296
unsigned long int convert< unsigned long int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1030
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
Definition: MooseUtils.C:614
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:948
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:645
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:884
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:492
Comparison helpers that support the MooseUtils::Any wildcard which will match any value...
Definition: MooseUtils.h:1031
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:452
IntRange< T > make_range(T beg, T end)
std::list< std::string > listDir(const std::string path, bool files_only=false)
Definition: MooseUtils.C:778
void emplace_back(Args &&... args)
Definition: MooseUtils.h:1128
libMesh::BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
Definition: MooseUtils.C:1237
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:404
int levenshteinDist(const std::string &s1, const std::string &s2)
Computes and returns the Levenshtein distance between strings s1 and s2.
Definition: MooseUtils.C:172
std::string getCurrentWorkingDir()
Returns the current working directory as a string.
Definition: MooseUtils.C:432
void makedirs(const std::string &dir_name, bool throw_on_failure=false)
Recursively make directories.
Definition: MooseUtils.C:445
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:1007
std::string removeExtraWhitespace(const std::string &str)
Removes additional whitespace from a string.
Definition: MooseUtils.C:221
static const struct MooseUtils::AnyType Any
long int convert< long int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1023
unsigned short int convert< unsigned short int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1002
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:227
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:1208
bool pathExists(const std::string &path)
Definition: MooseUtils.C:243
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:141
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:629
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:1050
unsigned long long int convert< unsigned long long int >(const std::string &str, bool throw_on_failure)
Definition: MooseUtils.C:1044
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:428
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:203
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1246
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:636