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"
61std::filesystem::path
pathjoin(
const std::filesystem::path & p);
63template <
typename... Args>
65pathjoin(
const std::filesystem::path & p, Args... args)
73bool parsesToReal(
const std::string & input, Real * parsed_real =
nullptr);
86 const std::string & dir_name,
87 const std::string & extra_error_msg =
"");
90std::string
docsDir(
const std::string & app_name);
102std::string
replaceAll(std::string str,
const std::string & from,
const std::string & to);
117void escape(std::string & str);
132std::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());
135std::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());
142template <
typename Iterator>
144join(Iterator begin, Iterator end,
const std::string & delimiter)
146 std::ostringstream oss;
156join(
const T & strings,
const std::string & delimiter)
158 return join(strings.begin(), strings.end(), delimiter);
164std::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);
193bool checkFileWriteable(
const std::string & filename,
bool throw_on_unwritable =
true);
237bool hasExtension(
const std::string & filename, std::string ext,
bool strip_exodus_ext =
false);
246std::string
getExtension(
const std::string & filename,
const bool rfind =
false);
252std::string
stripExtension(
const std::string & s,
const bool rfind =
false);
262std::pair<std::filesystem::path, std::filesystem::path>
263splitFileName(
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()};
289void makedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
299void removedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
318std::string
shortName(
const std::string & name);
323std::string
baseName(
const std::string & name);
361template <
typename T1,
typename T2>
363doesMapContainValue(
const std::map<T1, T2> & the_map,
const T2 & value)
365 for (
typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
367 if (iter->second == value)
382absoluteFuzzyEqual(
const Point & v1,
407absoluteFuzzyEqual(
const T & var1,
431absoluteFuzzyGreaterEqual(
const T & var1,
455absoluteFuzzyGreaterThan(
const T & var1,
479absoluteFuzzyLessEqual(
const T & var1,
502absoluteFuzzyLessThan(
const T & var1,
517template <
typename T,
typename T2,
typename T3 = Real>
519relativeFuzzyEqual(
const T & var1,
528 "Mathematical types must be same for arguments to relativelyFuzzEqual");
530 return absoluteFuzzyEqual(
537 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
546 if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
555 mooseAssert(var1.size() == var2.size(),
"These must be the same size");
557 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
580relativeFuzzyGreaterEqual(
const T & var1,
584 return (absoluteFuzzyGreaterEqual(
605relativeFuzzyGreaterThan(
const T & var1,
609 return (absoluteFuzzyGreaterThan(
631relativeFuzzyLessEqual(
const T & var1,
635 return (absoluteFuzzyLessEqual(
656relativeFuzzyLessThan(
const T & var1,
660 return (absoluteFuzzyLessThan(
672getUnion(
const std::vector<T> & vector1,
const std::vector<T> & vector2, std::vector<T> & common)
674 std::unordered_set<T> unique_elements;
675 unique_elements.reserve(vector1.size() + vector2.size());
676 unique_elements.insert(vector1.begin(), vector1.end());
677 unique_elements.insert(vector2.begin(), vector2.end());
680 common.assign(unique_elements.begin(), unique_elements.end());
697 template <
typename C>
698 static Yes test(
decltype(&C::size));
699 template <
typename C>
703 static constexpr bool value =
sizeof(test<T>(0)) ==
sizeof(Yes);
714isZero(
const T & value,
const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
716 if constexpr (Has_size<T>::value)
718 for (
const auto & element :
value)
719 if (!isZero(element, tolerance))
787 std::string & message,
788 const char * color = COLOR_CYAN,
789 bool dont_indent_first_line =
true,
790 const std::string & post_prefix =
": ");
797std::list<std::string>
listDir(
const std::string path,
bool files_only =
false);
808std::list<std::string>
getFilesInDirs(
const std::list<std::string> & directory_list,
809 const bool files_only =
true);
823bool wildCardMatch(std::string name, std::string search_string);
832 const std::string & pattern,
838expandAllMatches(
const std::vector<T> & candidates, std::vector<T> & patterns)
840 std::set<T> expanded;
841 for (
const auto & p : patterns)
843 unsigned int found = 0;
844 for (
const auto & c : candidates)
851 throw std::invalid_argument(p);
853 patterns.assign(expanded.begin(), expanded.end());
868convert(
const std::string & str,
bool throw_on_failure =
false)
875 catch (std::exception
const & e)
877 if (throw_on_failure)
887void createSymlink(
const std::string & target,
const std::string & link);
900concatenate(T c1,
const T & c2)
902 c1.insert(c2.begin(), c2.end());
911concatenate(std::vector<T> c1,
const std::vector<T> & c2)
913 c1.insert(c1.end(), c2.begin(), c2.end());
922concatenate(std::vector<T> c1,
const T & item)
931bool beginsWith(
const std::string & value,
const std::string & begin_value);
943numDigits(
const T & num)
945 return num > 9 ?
static_cast<int>(std::log10(
static_cast<double>(num))) + 1 : 1;
958int stringToInteger(
const std::string & input,
bool throw_on_failure =
false);
972 dof_id_type num_chunks,
973 dof_id_type chunk_id,
974 dof_id_type & num_local_items,
975 dof_id_type & local_items_begin,
976 dof_id_type & local_items_end);
992std::string
realpath(
const std::string & path);
1002 static constexpr bool value =
false;
1005struct IsLikeReal<
Real>
1007 static constexpr bool value =
true;
1012 static constexpr bool value =
true;
1018template <
typename T>
1021 static constexpr bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1022 TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1026const static struct AnyType
1030template <
typename T1,
typename T2>
1032wildcardEqual(
const T1 & a,
const T2 & b)
1037template <
typename T>
1039wildcardEqual(
const T &, AnyType)
1043template <
typename T>
1045wildcardEqual(AnyType,
const T &)
1054template <
typename C,
typename It,
typename M1,
typename M2>
1056findPair(C & container, It start_iterator,
const M1 & first,
const M2 & second)
1058 return std::find_if(
1062 { return wildcardEqual(first, item.first) && wildcardEqual(second, item.second); });
1089template <
typename T, std::
size_t N,
bool value_init = true>
1090#if METAPHYSICL_MAJOR_VERSION < 2
1091class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1093 typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1095class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, N>
1097 typedef MetaPhysicL::DynamicStdArrayWrapper<T, N> Parent;
1101 SemidynamicVector(std::size_t size) : Parent()
1103 Parent::resize(size);
1104 if constexpr (value_init)
1109 void resize(std::size_t new_size)
1111 [[maybe_unused]]
const auto old_dynamic_n = Parent::size();
1113 Parent::resize(new_size);
1115 if constexpr (value_init)
1116 for (
const auto i :
make_range(old_dynamic_n, _dynamic_n))
1120 void push_back(
const T & v)
1122 const auto old_dynamic_n = Parent::size();
1123 Parent::resize(old_dynamic_n + 1);
1124 _data[old_dynamic_n] = v;
1127 template <
typename... Args>
1128 void emplace_back(Args &&... args)
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)...));
1135 std::size_t max_size()
const {
return N; }
1137 using Parent::_data;
1138 using Parent::_dynamic_n;
1153template <
typename T>
1155get(
const std::unique_ptr<T> & u)
1160template <
typename T>
1167template <
typename T>
1169get(
const std::shared_ptr<T> & s)
1178template <
class InputIterator>
1180setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1182 while (first1 != last1 && first2 != last2)
1184 if (*first1 == *first2)
1187 if (*first1 < *first2)
1189 else if (*first1 > *first2)
1197setsIntersect(
const T & s1,
const T & s2)
1199 return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1208isDigits(
const std::string & str)
1210 return std::all_of(str.begin(), str.end(), [](
unsigned char c) { return std::isdigit(c); });
1219isFloat(
const std::string & str)
1224 strtof(str.c_str(), &ptr);
1225 return (*ptr) ==
'\0';
1236bool startsWith(
const std::string & string1,
const std::string & string2);
1242void replaceStart(std::string & string1,
const std::string & string2,
const std::string & string3);
1252template <
typename T>
1255template <
typename T, std::
size_t N,
bool value_init>
1256struct ADType<
MooseUtils::SemidynamicVector<T, N, value_init>>
1258 typedef MooseUtils::SemidynamicVector<typename ADType<T>::type,
N, value_init> type;
1270std::string
removeSubstring(
const std::string & main,
const std::string & sub);
DualNumber< Real, DNDerivativeType, true > ADReal
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void removeSubstring(std::string &main, const std::string &sub)
for(PetscInt i=0;i< nvars;++i)
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
A MultiMooseEnum object to hold "execute_on" flags.
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts.
MaterialBases compute MaterialProperties.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
GCC9 currently hits a "no type named 'value_type'" error during build if this is removed and iterator...
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
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.
void replaceStart(std::string &string1, const std::string &string2, const std::string &string3)
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)
int stringToInteger(const std::string &input, bool throw_on_failure)
bool isFinitePoint(const Point &point)
std::string mooseDocsURL(const std::string &path)
bool checkForGitLFSPointer(std::ifstream &file)
std::string & removeColor(std::string &msg)
std::string realpath(const std::string &path)
void removedirs(const std::string &dir_name, bool throw_on_failure)
std::filesystem::path pathjoin(const std::filesystem::path &p)
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext)
unsigned short getTermWidth(bool use_environment)
std::string canonicalPath(const std::string &path)
void indentMessage(const std::string &prefix, std::string &message, const char *color, bool indent_first_line, const std::string &post_prefix)
std::string removeExtraWhitespace(const std::string &input)
std::string getCurrentWorkingDir()
std::string camelCaseToUnderscore(const std::string &camel_case_name)
std::string baseName(const std::string &name)
bool pathContains(const std::string &expression, const std::string &string_to_find, const std::string &delims)
void createSymlink(const std::string &target, const std::string &link)
void makedirs(const std::string &dir_name, bool throw_on_failure)
std::string installedInputsDir(const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg)
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count)
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 serialEnd(const libMesh::Parallel::Communicator &comm, bool warn)
std::string getExtension(const std::string &filename, const bool rfind)
bool isAllLowercase(const std::string &str)
bool pathExists(const std::string &path)
int levenshteinDist(const std::string &s1, const std::string &s2)
std::string docsDir(const std::string &app_name)
bool startsWith(const std::string &string1, const std::string &string2)
bool parsesToReal(const std::string &input, Real *parsed_real)
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
processor_id_type linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
void escape(std::string &str)
std::string convertLatestCheckpoint(std::string orig)
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c, std::size_t p)
ExecFlagEnum getDefaultExecFlagEnum()
bool beginsWith(const std::string &value, const std::string &begin_value)
void parallelBarrierNotify(const Parallel::Communicator &comm, bool messaging)
BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
void MaterialPropertyStorageDump(const HashMap< const libMesh::Elem *, HashMap< unsigned int, MaterialProperties > > &props)
std::string prettyCppType(const std::string &cpp_type)
std::string stripExtension(const std::string &s, const bool rfind)
std::string findTestRoot()
std::size_t fileSize(const std::string &filename)
bool wildCardMatch(std::string name, std::string search_string)
std::list< std::string > listDir(const std::string path, bool files_only)
void serialBegin(const libMesh::Parallel::Communicator &comm, bool warn)
std::string getLatestCheckpointFilePrefix(const std::list< std::string > &checkpoint_files)
void clearSymlink(const std::string &link)
bool checkFileReadable(const std::string &filename, bool check_line_endings, bool throw_on_unreadable, bool check_for_git_lfs_pointer)
std::string runTestsExecutable()
std::string shortName(const std::string &name)
std::vector< std::string > rsplit(const std::string &str, const std::string &delimiter, std::size_t max_count)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
uint8_t processor_id_type
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::string name(const ElemQuality q)
const Elem & get(const ElemType type_in)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
auto index_range(const T &sizable)
std::string demangle(const char *name)
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)