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" 61 std::filesystem::path
pathjoin(
const std::filesystem::path & p);
63 template <
typename... Args>
65 pathjoin(
const std::filesystem::path & p, Args... args)
73 bool parsesToReal(
const std::string & input, Real * parsed_real =
nullptr);
86 const std::string & dir_name,
87 const std::string & extra_error_msg =
"");
90 std::string
docsDir(
const std::string & app_name);
102 std::string
replaceAll(std::string str,
const std::string & from,
const std::string & to);
117 void escape(std::string & str);
132 std::vector<std::string>
split(
const std::string & str,
135 std::vector<std::string>
rsplit(
const std::string & str,
142 template <
typename Iterator>
144 join(Iterator begin, Iterator end,
const std::string &
delimiter)
146 std::ostringstream oss;
147 std::copy(begin, end, infix_ostream_iterator<std::string>(oss,
delimiter.c_str()));
154 template <
typename T>
156 join(
const T & strings,
const std::string &
delimiter)
158 return join(strings.begin(), strings.end(),
delimiter);
164 std::size_t
fileSize(
const std::string & filename);
170 const std::string & string_to_find,
171 const std::string & delims =
"/");
183 bool check_line_endings =
false,
184 bool throw_on_unreadable =
true,
185 bool check_for_git_lfs_pointer =
true);
193 bool checkFileWriteable(
const std::string & filename,
bool throw_on_unwritable =
true);
237 bool hasExtension(
const std::string & filename, std::string ext,
bool strip_exodus_ext =
false);
246 std::string
getExtension(
const std::string & filename,
const bool rfind =
false);
252 std::string
stripExtension(
const std::string & s,
const bool rfind =
false);
261 template <
typename T>
262 std::pair<std::filesystem::path, std::filesystem::path>
263 splitFileName(
const T & full_file)
265 const auto p = std::filesystem::path(std::string(full_file));
267 if (!p.has_filename())
270 const auto d = p.parent_path();
271 return {d.empty() ?
"." : d, p.filename()};
289 void makedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
299 void removedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
318 std::string
shortName(
const std::string & name);
323 std::string
baseName(
const std::string & name);
343 template <
typename T>
356 template <
typename T1,
typename T2>
358 doesMapContainValue(
const std::map<T1, T2> & the_map,
const T2 & value)
360 for (
typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
362 if (iter->second == value)
377 absoluteFuzzyEqual(
const Point & v1,
402 absoluteFuzzyEqual(
const T & var1,
426 absoluteFuzzyGreaterEqual(
const T & var1,
450 absoluteFuzzyGreaterThan(
const T & var1,
474 absoluteFuzzyLessEqual(
const T & var1,
497 absoluteFuzzyLessThan(
const T & var1,
512 template <
typename T,
typename T2,
typename T3 = Real>
514 relativeFuzzyEqual(
const T & var1,
523 "Mathematical types must be same for arguments to relativelyFuzzEqual");
525 return absoluteFuzzyEqual(
532 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
541 if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
550 mooseAssert(var1.size() == var2.size(),
"These must be the same size");
552 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
575 relativeFuzzyGreaterEqual(
const T & var1,
579 return (absoluteFuzzyGreaterEqual(
600 relativeFuzzyGreaterThan(
const T & var1,
604 return (absoluteFuzzyGreaterThan(
626 relativeFuzzyLessEqual(
const T & var1,
630 return (absoluteFuzzyLessEqual(
651 relativeFuzzyLessThan(
const T & var1,
655 return (absoluteFuzzyLessThan(
665 template <
typename T>
667 getUnion(
const std::vector<T> & vector1,
const std::vector<T> & vector2, std::vector<T> & common)
669 std::unordered_set<T> unique_elements;
670 unique_elements.reserve(vector1.size() + vector2.size());
671 unique_elements.insert(vector1.begin(), vector1.end());
672 unique_elements.insert(vector2.begin(), vector2.end());
675 common.assign(unique_elements.begin(), unique_elements.end());
683 template <
typename T>
692 template <
typename C>
693 static Yes test(decltype(&C::size));
694 template <
typename C>
698 static constexpr
bool value =
sizeof(test<T>(0)) ==
sizeof(Yes);
707 template <
typename T>
709 isZero(
const T & value,
const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
711 if constexpr (Has_size<T>::value)
713 for (
const auto & element : value)
714 if (!isZero(element, tolerance))
782 std::string & message,
783 const char * color = COLOR_CYAN,
784 bool dont_indent_first_line =
true,
785 const std::string & post_prefix =
": ");
792 std::list<std::string>
listDir(
const std::string path,
bool files_only =
false);
803 std::list<std::string>
getFilesInDirs(
const std::list<std::string> & directory_list,
804 const bool files_only =
true);
818 bool wildCardMatch(std::string name, std::string search_string);
827 const std::string & pattern,
831 template <
typename T>
833 expandAllMatches(
const std::vector<T> & candidates, std::vector<T> & patterns)
835 std::set<T> expanded;
836 for (
const auto & p : patterns)
838 unsigned int found = 0;
839 for (
const auto & c : candidates)
846 throw std::invalid_argument(p);
848 patterns.assign(expanded.begin(), expanded.end());
861 template <
typename T>
863 convert(
const std::string & str,
bool throw_on_failure =
false)
870 catch (std::exception
const & e)
872 if (throw_on_failure)
882 void createSymlink(
const std::string & target,
const std::string & link);
893 template <
typename T>
895 concatenate(T c1,
const T & c2)
897 c1.insert(c2.begin(), c2.end());
904 template <
typename T>
906 concatenate(std::vector<T> c1,
const std::vector<T> & c2)
908 c1.insert(c1.end(), c2.begin(), c2.end());
915 template <
typename T>
917 concatenate(std::vector<T> c1,
const T & item)
926 bool beginsWith(
const std::string & value,
const std::string & begin_value);
936 template <
typename T>
938 numDigits(
const T & num)
940 return num > 9 ?
static_cast<int>(std::log10(static_cast<double>(num))) + 1 : 1;
953 int stringToInteger(
const std::string & input,
bool throw_on_failure =
false);
987 std::string
realpath(
const std::string & path);
994 template <
typename T>
997 static constexpr
bool value =
false;
1000 struct IsLikeReal<
Real>
1002 static constexpr
bool value =
true;
1005 struct IsLikeReal<
ADReal>
1007 static constexpr
bool value =
true;
1013 template <
typename T>
1016 static constexpr
bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1017 TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1021 const static struct AnyType
1025 template <
typename T1,
typename T2>
1027 wildcardEqual(
const T1 & a,
const T2 & b)
1032 template <
typename T>
1034 wildcardEqual(
const T &, AnyType)
1038 template <
typename T>
1040 wildcardEqual(AnyType,
const T &)
1049 template <
typename C,
typename It,
typename M1,
typename M2>
1051 findPair(C & container, It start_iterator,
const M1 & first,
const M2 & second)
1053 return std::find_if(start_iterator,
1056 return wildcardEqual(first, item.first) &&
1057 wildcardEqual(second, item.second);
1085 template <
typename T, std::
size_t N,
bool value_init = true>
1086 #if METAPHYSICL_MAJOR_VERSION < 2 1087 class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1089 typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1091 class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, N>
1093 typedef MetaPhysicL::DynamicStdArrayWrapper<T, N> Parent;
1097 SemidynamicVector(std::size_t size) : Parent()
1099 Parent::resize(size);
1100 if constexpr (value_init)
1105 void resize(std::size_t new_size)
1107 [[maybe_unused]]
const auto old_dynamic_n = Parent::size();
1109 Parent::resize(new_size);
1111 if constexpr (value_init)
1112 for (
const auto i :
make_range(old_dynamic_n, _dynamic_n))
1116 void push_back(
const T & v)
1118 const auto old_dynamic_n = Parent::size();
1119 Parent::resize(old_dynamic_n + 1);
1120 _data[old_dynamic_n] = v;
1123 template <
typename... Args>
1124 void emplace_back(Args &&... args)
1126 const auto old_dynamic_n = Parent::size();
1127 Parent::resize(old_dynamic_n + 1);
1128 (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1131 std::size_t max_size()
const {
return N; }
1133 using Parent::_data;
1134 using Parent::_dynamic_n;
1149 template <
typename T>
1151 get(
const std::unique_ptr<T> & u)
1156 template <
typename T>
1163 template <
typename T>
1165 get(
const std::shared_ptr<T> & s)
1174 template <
class InputIterator>
1176 setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1178 while (first1 != last1 && first2 != last2)
1180 if (*first1 == *first2)
1183 if (*first1 < *first2)
1185 else if (*first1 > *first2)
1193 setsIntersect(
const T & s1,
const T & s2)
1195 return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1204 isDigits(
const std::string & str)
1206 return std::all_of(str.begin(), str.end(), [](
unsigned char c) {
return std::isdigit(c); });
1215 isFloat(
const std::string & str)
1220 strtof(str.c_str(), &ptr);
1221 return (*ptr) ==
'\0';
1232 bool startsWith(
const std::string & string1,
const std::string & string2);
1238 void replaceStart(std::string & string1,
const std::string & string2,
const std::string & string3);
1248 template <
typename T>
1251 template <
typename T, std::
size_t N,
bool value_init>
1252 struct ADType<
MooseUtils::SemidynamicVector<T, N, value_init>>
1254 typedef MooseUtils::SemidynamicVector<typename ADType<T>::type,
N, value_init> type;
void makedirs(const std::string &dir_name, bool throw_on_failure)
std::string name(const ElemQuality q)
std::string docsDir(const std::string &app_name)
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
A MultiMooseEnum object to hold "execute_on" flags.
std::list< std::string > listDir(const std::string path, bool files_only)
bool beginsWith(const std::string &value, const std::string &begin_value)
void serialEnd(const libMesh::Parallel::Communicator &comm, bool warn)
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
bool pathContains(const std::string &expression, const std::string &string_to_find, const std::string &delims)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void MaterialPropertyStorageDump(const HashMap< const libMesh::Elem *, HashMap< unsigned int, MaterialProperties >> &props)
static constexpr Real TOLERANCE
bool isAllLowercase(const std::string &str)
bool startsWith(const std::string &string1, const std::string &string2)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
std::string installedInputsDir(const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg)
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)
bool checkForGitLFSPointer(std::ifstream &file)
std::string realpath(const std::string &path)
DualNumber< Real, DNDerivativeType, true > ADReal
std::string removeExtraWhitespace(const std::string &input)
std::string convertLatestCheckpoint(std::string orig)
std::string mooseDocsURL(const std::string &path)
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)
std::string shortName(const std::string &name)
void removeSubstring(std::string &main, const std::string &sub)
ExecFlagEnum getDefaultExecFlagEnum()
void replaceStart(std::string &string1, const std::string &string2, const std::string &string3)
void indentMessage(const std::string &prefix, std::string &message, const char *color, bool indent_first_line, const std::string &post_prefix)
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)
std::string stripExtension(const std::string &s, const bool rfind)
std::string canonicalPath(const std::string &path)
std::string runTestsExecutable()
std::size_t fileSize(const std::string &filename)
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
std::string & removeColor(std::string &msg)
std::string demangle(const char *name)
int main(int argc, char *argv[])
Initialize, create and run a MooseApp.
void clearSymlink(const std::string &link)
std::vector< std::string > rsplit(const std::string &str, const std::string &delimiter, std::size_t max_count)
processor_id_type linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
void createSymlink(const std::string &target, const std::string &link)
std::filesystem::path pathjoin(const std::filesystem::path &p)
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext)
std::string baseName(const std::string &name)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void serialBegin(const libMesh::Parallel::Communicator &comm, bool warn)
bool wildCardMatch(std::string name, std::string search_string)
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)
IntRange< T > make_range(T beg, T end)
BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
int levenshteinDist(const std::string &s1, const std::string &s2)
std::string getCurrentWorkingDir()
std::string getExtension(const std::string &filename, const bool rfind)
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list, const bool files_only)
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable)
void removedirs(const std::string &dir_name, bool throw_on_failure)
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)
bool parsesToReal(const std::string &input, Real *parsed_real)
bool pathExists(const std::string &path)
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
MaterialBases compute MaterialProperties.
auto index_range(const T &sizable)
int stringToInteger(const std::string &input, bool throw_on_failure)
void escape(std::string &str)
std::string prettyCppType(const std::string &cpp_type)
std::string findTestRoot()
unsigned short getTermWidth(bool use_environment)
void parallelBarrierNotify(const Parallel::Communicator &comm, bool messaging)