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)
382 absoluteFuzzyEqual(
const T & var1,
406 absoluteFuzzyGreaterEqual(
const T & var1,
430 absoluteFuzzyGreaterThan(
const T & var1,
454 absoluteFuzzyLessEqual(
const T & var1,
477 absoluteFuzzyLessThan(
const T & var1,
492 template <
typename T,
typename T2,
typename T3 = Real>
494 relativeFuzzyEqual(
const T & var1,
503 "Mathematical types must be same for arguments to relativelyFuzzEqual");
505 return absoluteFuzzyEqual(
512 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
521 if (!relativeFuzzyEqual(var1(i, j), var2(i, j), tol))
530 mooseAssert(var1.size() == var2.size(),
"These must be the same size");
532 if (!relativeFuzzyEqual(var1(i), var2(i), tol))
555 relativeFuzzyGreaterEqual(
const T & var1,
559 return (absoluteFuzzyGreaterEqual(
580 relativeFuzzyGreaterThan(
const T & var1,
584 return (absoluteFuzzyGreaterThan(
606 relativeFuzzyLessEqual(
const T & var1,
610 return (absoluteFuzzyLessEqual(
631 relativeFuzzyLessThan(
const T & var1,
635 return (absoluteFuzzyLessThan(
645 template <
typename T>
647 getUnion(
const std::vector<T> & vector1,
const std::vector<T> & vector2, std::vector<T> & common)
649 std::unordered_set<T> unique_elements;
650 unique_elements.reserve(vector1.size() + vector2.size());
652 for (
const T & entry : vector1)
653 unique_elements.insert(entry);
654 for (
const T & entry : vector2)
655 unique_elements.insert(entry);
659 common.assign(unique_elements.begin(), unique_elements.end());
667 template <
typename T>
676 template <
typename C>
677 static Yes test(decltype(&C::size));
678 template <
typename C>
682 static constexpr
bool value =
sizeof(test<T>(0)) ==
sizeof(Yes);
691 template <
typename T>
693 isZero(
const T & value,
const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
695 if constexpr (Has_size<T>::value)
697 for (
const auto & element : value)
698 if (!isZero(element, tolerance))
766 std::string & message,
767 const char * color = COLOR_CYAN,
768 bool dont_indent_first_line =
true,
769 const std::string & post_prefix =
": ");
776 std::list<std::string>
listDir(
const std::string path,
bool files_only =
false);
787 std::list<std::string>
getFilesInDirs(
const std::list<std::string> & directory_list,
788 const bool files_only =
true);
802 bool wildCardMatch(std::string name, std::string search_string);
811 const std::string & pattern,
815 template <
typename T>
817 expandAllMatches(
const std::vector<T> & candidates, std::vector<T> & patterns)
819 std::set<T> expanded;
820 for (
const auto & p : patterns)
822 unsigned int found = 0;
823 for (
const auto & c : candidates)
830 throw std::invalid_argument(p);
832 patterns.assign(expanded.begin(), expanded.end());
845 template <
typename T>
847 convert(
const std::string & str,
bool throw_on_failure =
false)
854 catch (std::exception
const & e)
856 if (throw_on_failure)
866 void createSymlink(
const std::string & target,
const std::string & link);
877 template <
typename T>
879 concatenate(T c1,
const T & c2)
881 c1.insert(c2.begin(), c2.end());
888 template <
typename T>
890 concatenate(std::vector<T> c1,
const std::vector<T> & c2)
892 c1.insert(c1.end(), c2.begin(), c2.end());
899 template <
typename T>
901 concatenate(std::vector<T> c1,
const T & item)
910 std::string
stringJoin(
const std::vector<std::string> & values,
911 const std::string & separator =
" ");
916 bool beginsWith(
const std::string & value,
const std::string & begin_value);
926 template <
typename T>
928 numDigits(
const T & num)
930 return num > 9 ?
static_cast<int>(std::log10(static_cast<double>(num))) + 1 : 1;
943 int stringToInteger(
const std::string & input,
bool throw_on_failure =
false);
977 std::string
realpath(
const std::string & path);
984 template <
typename T>
987 static constexpr
bool value =
false;
990 struct IsLikeReal<
Real>
992 static constexpr
bool value =
true;
997 static constexpr
bool value =
true;
1003 template <
typename T>
1006 static constexpr
bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>::value ||
1007 TIMPI::Has_buffer_type<TIMPI::Packing<T>>::value;
1011 const static struct AnyType
1015 template <
typename T1,
typename T2>
1017 wildcardEqual(
const T1 & a,
const T2 & b)
1022 template <
typename T>
1024 wildcardEqual(
const T &, AnyType)
1028 template <
typename T>
1030 wildcardEqual(AnyType,
const T &)
1039 template <
typename C,
typename It,
typename M1,
typename M2>
1041 findPair(C & container, It start_iterator,
const M1 & first,
const M2 & second)
1043 return std::find_if(start_iterator,
1046 return wildcardEqual(first, item.first) &&
1047 wildcardEqual(second, item.second);
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>>
1079 typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>> Parent;
1081 class SemidynamicVector :
public MetaPhysicL::DynamicStdArrayWrapper<T, N>
1083 typedef MetaPhysicL::DynamicStdArrayWrapper<T, N> Parent;
1087 SemidynamicVector(std::size_t size) : Parent()
1089 Parent::resize(size);
1090 if constexpr (value_init)
1095 void resize(std::size_t new_size)
1097 [[maybe_unused]]
const auto old_dynamic_n = Parent::size();
1099 Parent::resize(new_size);
1101 if constexpr (value_init)
1102 for (
const auto i :
make_range(old_dynamic_n, _dynamic_n))
1106 void push_back(
const T & v)
1108 const auto old_dynamic_n = Parent::size();
1109 Parent::resize(old_dynamic_n + 1);
1110 _data[old_dynamic_n] = v;
1113 template <
typename... Args>
1114 void emplace_back(Args &&... args)
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)...));
1121 std::size_t max_size()
const {
return N; }
1123 using Parent::_data;
1124 using Parent::_dynamic_n;
1139 template <
typename T>
1141 get(
const std::unique_ptr<T> & u)
1146 template <
typename T>
1153 template <
typename T>
1155 get(
const std::shared_ptr<T> & s)
1164 template <
class InputIterator>
1166 setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
1168 while (first1 != last1 && first2 != last2)
1170 if (*first1 == *first2)
1173 if (*first1 < *first2)
1175 else if (*first1 > *first2)
1183 setsIntersect(
const T & s1,
const T & s2)
1185 return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1194 isDigits(
const std::string & str)
1196 return std::all_of(str.begin(), str.end(), [](
unsigned char c) {
return std::isdigit(c); });
1205 isFloat(
const std::string & str)
1210 strtof(str.c_str(), &ptr);
1211 return (*ptr) ==
'\0';
1222 bool startsWith(
const std::string & string1,
const std::string & string2);
1228 void replaceStart(std::string & string1,
const std::string & string2,
const std::string & string3);
1238 template <
typename T>
1241 template <
typename T, std::
size_t N,
bool value_init>
1242 struct ADType<
MooseUtils::SemidynamicVector<T, N, value_init>>
1244 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)
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator)
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)