23#include "libmesh/compare_types.h"
24#include "libmesh/bounding_box.h"
25#include "libmesh/fe_type.h"
26#include "libmesh/int_range.h"
27#include "libmesh/tensor_tools.h"
28#include "metaphysicl/raw_type.h"
29#include "metaphysicl/metaphysicl_version.h"
30#include "metaphysicl/dualnumber_decl.h"
31#include "metaphysicl/dynamic_std_array_wrapper.h"
62std::filesystem::path
pathjoin(
const std::filesystem::path & p);
64template <
typename... Args>
66pathjoin(
const std::filesystem::path & p, Args... args)
74bool parsesToReal(
const std::string & input, Real * parsed_real =
nullptr);
90 const std::string & dir_name,
91 const std::string & extra_error_msg =
"");
94std::string
docsDir(
const std::string & app_name);
106std::string
replaceAll(std::string str,
const std::string & from,
const std::string & to);
121void escape(std::string & str);
136std::vector<std::string>
split(
const std::string & str,
137 const std::string & delimiter,
138 std::size_t max_count = std::numeric_limits<std::size_t>::max());
139std::vector<std::string>
rsplit(
const std::string & str,
140 const std::string & delimiter,
141 std::size_t max_count = std::numeric_limits<std::size_t>::max());
146template <
typename Iterator>
148join(Iterator begin, Iterator end,
const std::string & delimiter)
150 std::ostringstream oss;
160join(
const T & strings,
const std::string & delimiter)
162 return join(strings.begin(), strings.end(), delimiter);
168std::size_t
fileSize(
const std::string & filename);
174 const std::string & string_to_find,
175 const std::string & delims =
"/");
187 bool check_line_endings =
false,
188 bool throw_on_unreadable =
true,
189 bool check_for_git_lfs_pointer =
true);
197bool checkFileWriteable(
const std::string & filename,
bool throw_on_unwritable =
true);
241bool hasExtension(
const std::string & filename, std::string ext,
bool strip_exodus_ext =
false);
250std::string
getExtension(
const std::string & filename,
const bool rfind =
false);
256std::string
stripExtension(
const std::string & s,
const bool rfind =
false);
266std::pair<std::filesystem::path, std::filesystem::path>
267splitFileName(
const T & full_file)
269 const auto p = std::filesystem::path(std::string(full_file));
271 if (!p.has_filename())
274 const auto d = p.parent_path();
275 return {d.empty() ?
"." : d, p.filename()};
293void makedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
303void removedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
322std::string
shortName(
const std::string & name);
327std::string
baseName(
const std::string & name);
365template <
typename T1,
typename T2>
367doesMapContainValue(
const std::map<T1, T2> & the_map,
const T2 & value)
369 for (
typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
371 if (iter->second == value)
386absoluteFuzzyEqual(
const Point & v1,
411absoluteFuzzyEqual(
const T & var1,
435absoluteFuzzyGreaterEqual(
const T & var1,
459absoluteFuzzyGreaterThan(
const T & var1,
483absoluteFuzzyLessEqual(
const T & var1,
506absoluteFuzzyLessThan(
const T & var1,
521template <
typename T,
typename T2,
typename T3 = Real>
523relativeFuzzyEqual(
const T & var1,
532 "Mathematical types must be same for arguments to relativelyFuzzEqual");
534 return absoluteFuzzyEqual(
541 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
550 if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
559 mooseAssert(var1.size() == var2.size(),
"These must be the same size");
561 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
584relativeFuzzyGreaterEqual(
const T & var1,
588 return (absoluteFuzzyGreaterEqual(
609relativeFuzzyGreaterThan(
const T & var1,
613 return (absoluteFuzzyGreaterThan(
635relativeFuzzyLessEqual(
const T & var1,
639 return (absoluteFuzzyLessEqual(
660relativeFuzzyLessThan(
const T & var1,
664 return (absoluteFuzzyLessThan(
676getUnion(
const std::vector<T> & vector1,
const std::vector<T> & vector2, std::vector<T> & common)
678 std::unordered_set<T> unique_elements;
679 unique_elements.reserve(vector1.size() + vector2.size());
680 unique_elements.insert(vector1.begin(), vector1.end());
681 unique_elements.insert(vector2.begin(), vector2.end());
684 common.assign(unique_elements.begin(), unique_elements.end());
701 template <
typename C>
702 static Yes test(
decltype(&C::size));
703 template <
typename C>
707 static constexpr bool value =
sizeof(test<T>(0)) ==
sizeof(Yes);
718isZero(
const T & value,
const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
720 if constexpr (Has_size<T>::value)
722 for (
const auto & element :
value)
723 if (!isZero(element, tolerance))
791 std::string & message,
792 const char * color = COLOR_CYAN,
793 bool dont_indent_first_line =
true,
794 const std::string & post_prefix =
": ");
801std::list<std::string>
listDir(
const std::string path,
bool files_only =
false);
812std::list<std::string>
getFilesInDirs(
const std::list<std::string> & directory_list,
813 const bool files_only =
true);
827bool wildCardMatch(std::string name, std::string search_string);
836 const std::string & pattern,
842expandAllMatches(
const std::vector<T> & candidates, std::vector<T> & patterns)
844 std::set<T> expanded;
845 for (
const auto & p : patterns)
847 unsigned int found = 0;
848 for (
const auto & c : candidates)
855 throw std::invalid_argument(p);
857 patterns.assign(expanded.begin(), expanded.end());
872convert(
const std::string & str,
bool throw_on_failure =
false)
879 catch (std::exception
const & e)
881 if (throw_on_failure)
891void createSymlink(
const std::string & target,
const std::string & link);
904concatenate(T c1,
const T & c2)
906 c1.insert(c2.begin(), c2.end());
915concatenate(std::vector<T> c1,
const std::vector<T> & c2)
917 c1.insert(c1.end(), c2.begin(), c2.end());
926concatenate(std::vector<T> c1,
const T & item)
935bool beginsWith(
const std::string & value,
const std::string & begin_value);
947numDigits(
const T & num)
949 return num > 9 ?
static_cast<int>(std::log10(
static_cast<double>(num))) + 1 : 1;
962int stringToInteger(
const std::string & input,
bool throw_on_failure =
false);
976 dof_id_type num_chunks,
977 dof_id_type chunk_id,
978 dof_id_type & num_local_items,
979 dof_id_type & local_items_begin,
980 dof_id_type & local_items_end);
996std::string
realpath(
const std::string & path);
1003template <
typename T>
1006 static constexpr bool value =
false;
1009struct IsLikeReal<
Real>
1011 static constexpr bool value =
true;
1016 static constexpr bool value =
true;
1022template <
typename T>
1025 static constexpr bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1026 TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1030const static struct AnyType
1034template <
typename T1,
typename T2>
1036wildcardEqual(
const T1 & a,
const T2 & b)
1041template <
typename T>
1043wildcardEqual(
const T &, AnyType)
1047template <
typename T>
1049wildcardEqual(AnyType,
const T &)
1058template <
typename C,
typename It,
typename M1,
typename M2>
1060findPair(C & container, It start_iterator,
const M1 & first,
const M2 & second)
1062 return std::find_if(
1066 { return wildcardEqual(first, item.first) && wildcardEqual(second, item.second); });
1093template <
typename T, std::
size_t N,
bool value_init = true>
1094#if METAPHYSICL_MAJOR_VERSION < 2
1095class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
1097 typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1099class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, N>
1101 typedef MetaPhysicL::DynamicStdArrayWrapper<T, N> Parent;
1105 SemidynamicVector(std::size_t size) : Parent()
1107 Parent::resize(size);
1108 if constexpr (value_init)
1113 void resize(std::size_t new_size)
1115 [[maybe_unused]]
const auto old_dynamic_n = Parent::size();
1117 Parent::resize(new_size);
1119 if constexpr (value_init)
1120 for (
const auto i :
make_range(old_dynamic_n, _dynamic_n))
1124 void push_back(
const T & v)
1126 const auto old_dynamic_n = Parent::size();
1127 Parent::resize(old_dynamic_n + 1);
1128 _data[old_dynamic_n] = v;
1131 template <
typename... Args>
1132 void emplace_back(Args &&... args)
1134 const auto old_dynamic_n = Parent::size();
1135 Parent::resize(old_dynamic_n + 1);
1136 (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1139 std::size_t max_size()
const {
return N; }
1141 using Parent::_data;
1142 using Parent::_dynamic_n;
1157template <
typename T>
1159get(
const std::unique_ptr<T> & u)
1164template <
typename T>
1171template <
typename T>
1173get(
const std::shared_ptr<T> & s)
1182template <
class InputIterator>
1184setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1186 while (first1 != last1 && first2 != last2)
1188 if (*first1 == *first2)
1191 if (*first1 < *first2)
1193 else if (*first1 > *first2)
1201setsIntersect(
const T & s1,
const T & s2)
1203 return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1212isDigits(
const std::string & str)
1214 return std::all_of(str.begin(), str.end(), [](
unsigned char c) { return std::isdigit(c); });
1223isFloat(
const std::string & str)
1228 strtof(str.c_str(), &ptr);
1229 return (*ptr) ==
'\0';
1240bool startsWith(
const std::string & string1,
const std::string & string2);
1246void replaceStart(std::string & string1,
const std::string & string2,
const std::string & string3);
1256template <
typename T>
1259template <
typename T, std::
size_t N,
bool value_init>
1260struct ADType<
MooseUtils::SemidynamicVector<T, N, value_init>>
1262 typedef MooseUtils::SemidynamicVector<typename ADType<T>::type,
N, value_init> type;
1274std::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)
libMesh::FEType variableFEType(const InputParameters ¶ms)
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)