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
406 absoluteFuzzyGreaterEqual(const T & var1,
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
430 absoluteFuzzyGreaterThan(const T & var1,
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,
508  tol * (std::abs(MetaPhysicL::raw_value(var1)) + std::abs(MetaPhysicL::raw_value(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
555 relativeFuzzyGreaterEqual(const T & var1,
556  const T2 & var2,
557  const T3 & tol = libMesh::TOLERANCE * libMesh::TOLERANCE)
558 {
559  return (absoluteFuzzyGreaterEqual(
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
580 relativeFuzzyGreaterThan(const T & var1,
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)
704  return MooseUtils::absoluteFuzzyEqual(MetaPhysicL::raw_value(value), 0, tolerance);
705  else if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 1)
706  {
707  for (const auto i : make_range(Moose::dim))
708  if (!MooseUtils::absoluteFuzzyEqual(MetaPhysicL::raw_value(value(i)), 0, tolerance))
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))
717  if (!MooseUtils::absoluteFuzzyEqual(MetaPhysicL::raw_value(value(i, j)), 0, tolerance))
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>
985 struct IsLikeReal
986 {
987  static constexpr bool value = false;
988 };
989 template <>
990 struct IsLikeReal<Real>
991 {
992  static constexpr bool value = true;
993 };
994 template <>
995 struct IsLikeReal<ADReal>
996 {
997  static constexpr bool value = true;
998 };
999 
1003 template <typename T>
1004 struct canBroadcast
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
1024 wildcardEqual(const T &, AnyType)
1025 {
1026  return true;
1027 }
1028 template <typename T>
1029 bool
1030 wildcardEqual(AnyType, const T &)
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 #if METAPHYSICL_MAJOR_VERSION < 2
1077 class SemidynamicVector : public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1078 {
1079  typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1080 #else
1081 class SemidynamicVector : public MetaPhysicL::DynamicStdArrayWrapper<T, N>
1082 {
1083  typedef MetaPhysicL::DynamicStdArrayWrapper<T, N> Parent;
1084 #endif
1085 
1086 public:
1087  SemidynamicVector(std::size_t size) : Parent()
1088  {
1089  Parent::resize(size);
1090  if constexpr (value_init)
1091  for (const auto i : make_range(size))
1092  _data[i] = T{};
1093  }
1094 
1095  void resize(std::size_t new_size)
1096  {
1097  [[maybe_unused]] const auto old_dynamic_n = Parent::size();
1098 
1099  Parent::resize(new_size);
1100 
1101  if constexpr (value_init)
1102  for (const auto i : make_range(old_dynamic_n, _dynamic_n))
1103  _data[i] = T{};
1104  }
1105 
1106  void push_back(const T & v)
1107  {
1108  const auto old_dynamic_n = Parent::size();
1109  Parent::resize(old_dynamic_n + 1);
1110  _data[old_dynamic_n] = v;
1111  }
1112 
1113  template <typename... Args>
1114  void emplace_back(Args &&... args)
1115  {
1116  const auto old_dynamic_n = Parent::size();
1117  Parent::resize(old_dynamic_n + 1);
1118  (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1119  }
1120 
1121  std::size_t max_size() const { return N; }
1122 
1123  using Parent::_data;
1124  using Parent::_dynamic_n;
1125 };
1126 
1139 template <typename T>
1140 T *
1141 get(const std::unique_ptr<T> & u)
1142 {
1143  return u.get();
1144 }
1145 
1146 template <typename T>
1147 T *
1148 get(T * p)
1149 {
1150  return p;
1151 }
1152 
1153 template <typename T>
1154 T *
1155 get(const std::shared_ptr<T> & s)
1156 {
1157  return s.get();
1158 }
1159 
1164 template <class InputIterator>
1165 bool
1166 setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1167 {
1168  while (first1 != last1 && first2 != last2)
1169  {
1170  if (*first1 == *first2)
1171  return true;
1172 
1173  if (*first1 < *first2)
1174  ++first1;
1175  else if (*first1 > *first2)
1176  ++first2;
1177  }
1178  return false;
1179 }
1180 
1181 template <class T>
1182 bool
1183 setsIntersect(const T & s1, const T & s2)
1184 {
1185  return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1186 }
1187 
1193 inline bool
1194 isDigits(const std::string & str)
1195 {
1196  return std::all_of(str.begin(), str.end(), [](unsigned char c) { return std::isdigit(c); });
1197 }
1198 
1204 inline bool
1205 isFloat(const std::string & str)
1206 {
1207  if (str.empty())
1208  return false;
1209  char * ptr;
1210  strtof(str.c_str(), &ptr);
1211  return (*ptr) == '\0';
1212 }
1213 
1217 std::string canonicalPath(const std::string & path);
1218 
1222 bool startsWith(const std::string & string1, const std::string & string2);
1223 
1228 void replaceStart(std::string & string1, const std::string & string2, const std::string & string3);
1229 
1233 bool isAllLowercase(const std::string & str);
1234 } // MooseUtils namespace
1235 
1236 namespace Moose
1237 {
1238 template <typename T>
1239 struct ADType;
1240 
1241 template <typename T, std::size_t N, bool value_init>
1242 struct ADType<MooseUtils::SemidynamicVector<T, N, value_init>>
1243 {
1244  typedef MooseUtils::SemidynamicVector<typename ADType<T>::type, N, value_init> type;
1245 };
1246 }
1247 
1251 void removeSubstring(std::string & main, const std::string & sub);
1252 
1256 std::string removeSubstring(const std::string & main, const std::string & sub);
void makedirs(const std::string &dir_name, bool throw_on_failure)
Definition: MooseUtils.C:449
std::string name(const ElemQuality q)
std::string docsDir(const std::string &app_name)
Definition: MooseUtils.C:125
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
Definition: EigenADReal.h:50
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
std::list< std::string > listDir(const std::string path, bool files_only)
Definition: MooseUtils.C:782
bool beginsWith(const std::string &value, const std::string &begin_value)
Definition: MooseUtils.C:966
void serialEnd(const libMesh::Parallel::Communicator &comm, bool warn)
Definition: MooseUtils.C:371
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
Definition: HashMap.h:18
bool pathContains(const std::string &expression, const std::string &string_to_find, const std::string &delims)
Definition: MooseUtils.C:231
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)
Definition: MooseUtils.C:688
static constexpr Real TOLERANCE
bool isAllLowercase(const std::string &str)
Definition: MooseUtils.C:1193
bool startsWith(const std::string &string1, const std::string &string2)
Definition: MooseUtils.C:1177
auto raw_value(const Eigen::Map< T > &in)
Definition: EigenADReal.h:100
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
We need to instantiate the following CompareTypes to tell the compiler that ADReal is a subtype of Ch...
std::string installedInputsDir(const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg)
Definition: MooseUtils.C:103
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)
Definition: MooseUtils.C:984
bool checkForGitLFSPointer(std::ifstream &file)
Definition: MooseUtils.C:290
std::string realpath(const std::string &path)
Definition: MooseUtils.C:1136
DualNumber< Real, DNDerivativeType, true > ADReal
Definition: ADRealForward.h:42
std::string removeExtraWhitespace(const std::string &input)
Definition: MooseUtils.C:225
std::string convertLatestCheckpoint(std::string orig)
Definition: MooseUtils.C:157
std::string mooseDocsURL(const std::string &path)
Definition: MooseUtils.C:139
std::string hostname()
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)
Definition: MooseUtils.C:568
std::string shortName(const std::string &name)
Definition: MooseUtils.C:612
void removeSubstring(std::string &main, const std::string &sub)
Definition: MooseUtils.C:1201
ExecFlagEnum getDefaultExecFlagEnum()
Definition: MooseUtils.C:972
void replaceStart(std::string &string1, const std::string &string2, const std::string &string3)
Definition: MooseUtils.C:1185
void indentMessage(const std::string &prefix, std::string &message, const char *color, bool indent_first_line, const std::string &post_prefix)
Definition: MooseUtils.C:738
uint8_t processor_id_type
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string getLatestCheckpointFilePrefix(const std::list< std::string > &checkpoint_files)
Definition: MooseUtils.C:819
std::string stripExtension(const std::string &s, const bool rfind)
Definition: MooseUtils.C:427
std::string canonicalPath(const std::string &path)
Definition: MooseUtils.C:1171
std::string runTestsExecutable()
Definition: MooseUtils.C:65
std::size_t fileSize(const std::string &filename)
Definition: MooseUtils.C:1106
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
Definition: MooseUtils.C:580
std::string & removeColor(std::string &msg)
Definition: MooseUtils.C:722
std::string demangle(const char *name)
int main(int argc, char *argv[])
Initialize, create and run a MooseApp.
Definition: MooseMain.h:31
charT const * delimiter
Definition: InfixIterator.h:34
void clearSymlink(const std::string &link)
Definition: MooseUtils.C:1084
std::vector< std::string > rsplit(const std::string &str, const std::string &delimiter, std::size_t max_count)
Definition: MooseUtils.C:1051
processor_id_type linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
Definition: MooseUtils.C:1010
void createSymlink(const std::string &target, const std::string &link)
Definition: MooseUtils.C:1071
std::filesystem::path pathjoin(const std::filesystem::path &p)
Definition: MooseUtils.C:59
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext)
Definition: MooseUtils.C:387
std::string baseName(const std::string &name)
Definition: MooseUtils.C:618
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void serialBegin(const libMesh::Parallel::Communicator &comm, bool warn)
Definition: MooseUtils.C:357
bool wildCardMatch(std::string name, std::string search_string)
Definition: MooseUtils.C:888
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c, std::size_t p)
Definition: MooseUtils.C:932
IntRange< T > make_range(T beg, T end)
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator)
Definition: MooseUtils.C:955
BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Definition: MooseUtils.C:1142
int levenshteinDist(const std::string &s1, const std::string &s2)
Definition: MooseUtils.C:176
std::string getCurrentWorkingDir()
Definition: MooseUtils.C:436
std::string getExtension(const std::string &filename, const bool rfind)
Definition: MooseUtils.C:411
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list, const bool files_only)
Definition: MooseUtils.C:808
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable)
Definition: MooseUtils.C:307
void removedirs(const std::string &dir_name, bool throw_on_failure)
Definition: MooseUtils.C:505
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...
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
Definition: MooseUtils.C:1031
bool parsesToReal(const std::string &input, Real *parsed_real)
Definition: MooseUtils.C:89
bool pathExists(const std::string &path)
Definition: MooseUtils.C:247
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
Definition: MooseUtils.C:145
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
Definition: MooseUtils.C:254
MaterialBases compute MaterialProperties.
Definition: MaterialBase.h:62
auto index_range(const T &sizable)
int stringToInteger(const std::string &input, bool throw_on_failure)
Definition: MooseUtils.C:978
void escape(std::string &str)
Definition: MooseUtils.C:207
std::string prettyCppType(const std::string &cpp_type)
Definition: MooseUtils.C:1151
uint8_t dof_id_type
std::string findTestRoot()
Definition: MooseUtils.C:75
unsigned short getTermWidth(bool use_environment)
Definition: MooseUtils.C:640
void parallelBarrierNotify(const Parallel::Communicator &comm, bool messaging)
Definition: MooseUtils.C:327