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)
84 const std::string & dir_name,
85 const std::string & extra_error_msg =
"");
88 std::string
docsDir(
const std::string & app_name);
100 std::string
replaceAll(std::string str,
const std::string & from,
const std::string & to);
115 void escape(std::string & str);
130 std::vector<std::string>
split(
const std::string & str,
133 std::vector<std::string>
rsplit(
const std::string & str,
140 template <
typename Iterator>
144 std::ostringstream oss;
145 std::copy(begin, end, infix_ostream_iterator<std::string>(oss,
delimiter.c_str()));
152 template <
typename T>
162 std::size_t
fileSize(
const std::string & filename);
168 const std::string & string_to_find,
169 const std::string & delims =
"/");
181 bool check_line_endings =
false,
182 bool throw_on_unreadable =
true,
183 bool check_for_git_lfs_pointer =
true);
191 bool checkFileWriteable(
const std::string & filename,
bool throw_on_unwritable =
true);
235 bool hasExtension(
const std::string & filename, std::string ext,
bool strip_exodus_ext =
false);
244 std::string
getExtension(
const std::string & filename,
const bool rfind =
false);
250 std::string
stripExtension(
const std::string & s,
const bool rfind =
false);
259 template <
typename T>
260 std::pair<std::filesystem::path, std::filesystem::path>
263 const auto p = std::filesystem::path(std::string(full_file));
265 if (!p.has_filename())
268 const auto d = p.parent_path();
269 return {d.empty() ?
"." : d, p.filename()};
287 void makedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
297 void removedirs(
const std::string & dir_name,
bool throw_on_failure =
false);
316 std::string
shortName(
const std::string & name);
321 std::string
baseName(
const std::string & name);
341 template <
typename T>
354 template <
typename T1,
typename T2>
358 for (
typename std::map<T1, T2>::const_iterator iter = the_map.begin(); iter != the_map.end();
360 if (iter->second ==
value)
490 template <
typename T,
typename T2,
typename T3 = Real>
501 "Mathematical types must be same for arguments to relativelyFuzzEqual");
528 mooseAssert(var1.size() == var2.size(),
"These must be the same size");
643 template <
typename T>
645 getUnion(
const std::vector<T> & vector1,
const std::vector<T> & vector2, std::vector<T> & common)
647 std::unordered_set<T> unique_elements;
648 unique_elements.reserve(vector1.size() + vector2.size());
650 for (
const T & entry : vector1)
651 unique_elements.insert(entry);
652 for (
const T & entry : vector2)
653 unique_elements.insert(entry);
657 common.assign(unique_elements.begin(), unique_elements.end());
665 template <
typename T>
674 template <
typename C>
675 static Yes test(decltype(&C::size));
676 template <
typename C>
680 static constexpr
bool value =
sizeof(test<T>(0)) ==
sizeof(
Yes);
689 template <
typename T>
691 isZero(
const T & value,
const Real tolerance = TOLERANCE * TOLERANCE * TOLERANCE)
695 for (
const auto & element :
value)
696 if (!
isZero(element, tolerance))
764 std::string & message,
765 const char * color = COLOR_CYAN,
766 bool dont_indent_first_line =
true,
767 const std::string & post_prefix =
": ");
774 std::list<std::string>
listDir(
const std::string path,
bool files_only =
false);
785 std::list<std::string>
getFilesInDirs(
const std::list<std::string> & directory_list,
786 const bool files_only =
true);
800 bool wildCardMatch(std::string name, std::string search_string);
809 const std::string & pattern,
813 template <
typename T>
817 std::set<T> expanded;
818 for (
const auto & p : patterns)
820 unsigned int found = 0;
821 for (
const auto & c : candidates)
828 throw std::invalid_argument(p);
830 patterns.assign(expanded.begin(), expanded.end());
838 template <
typename T>
840 convert(
const std::string & str,
bool throw_on_failure =
false)
842 std::stringstream ss(str);
844 if ((ss >> val).fail() || !ss.eof())
846 std::string msg = std::string(
"Unable to convert '") + str +
"' to type " +
849 if (throw_on_failure)
850 throw std::invalid_argument(msg);
865 int convert<int>(
const std::string & str,
bool throw_on_failure);
881 bool throw_on_failure);
886 void createSymlink(
const std::string & target,
const std::string & link);
897 template <
typename T>
901 c1.insert(c2.begin(), c2.end());
908 template <
typename T>
912 c1.insert(c1.end(), c2.begin(), c2.end());
919 template <
typename T>
930 std::string
stringJoin(
const std::vector<std::string> & values,
931 const std::string & separator =
" ");
936 bool beginsWith(
const std::string & value,
const std::string & begin_value);
946 template <
typename T>
950 return num > 9 ?
static_cast<int>(std::log10(static_cast<double>(num))) + 1 : 1;
963 int stringToInteger(
const std::string & input,
bool throw_on_failure =
false);
997 std::string
realpath(
const std::string & path);
1004 template <
typename T>
1023 template <
typename T>
1026 static constexpr
bool value = std::is_base_of<TIMPI::DataType, TIMPI::StandardType<T>>
::value ||
1027 TIMPI::Has_buffer_type<TIMPI::Packing<T>>
::value;
1035 template <
typename T1,
typename T2>
1042 template <
typename T>
1048 template <
typename T>
1059 template <
typename C,
typename It,
typename M1,
typename M2>
1061 findPair(C & container, It start_iterator,
const M1 & first,
const M2 & second)
1063 return std::find_if(start_iterator,
1095 template <
typename T, std::
size_t N,
bool value_init = true>
1098 typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N>>
Parent;
1103 Parent::resize(size);
1104 if constexpr (value_init)
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))
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>
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)...));
1137 using Parent::_data;
1138 using Parent::_dynamic_n;
1153 template <
typename T>
1155 get(
const std::unique_ptr<T> & u)
1160 template <
typename T>
1167 template <
typename T>
1169 get(
const std::shared_ptr<T> & s)
1178 template <
class InputIterator>
1180 setsIntersect(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)
1199 return setsIntersect(s1.begin(), s1.end(), s2.begin(), s2.end());
1210 return std::all_of(str.begin(), str.end(), [](
unsigned char c) {
return std::isdigit(c); });
1224 strtof(str.c_str(), &ptr);
1225 return (*ptr) ==
'\0';
1236 bool startsWith(
const std::string & string1,
const std::string & string2);
1242 void replaceStart(std::string & string1,
const std::string & string2,
const std::string & string3);
1252 template <
typename T>
1255 template <
typename T, std::
size_t N,
bool value_init>
std::string name(const ElemQuality q)
bool parsesToReal(const std::string &input)
Check if the input string can be parsed into a Real.
std::string docsDir(const std::string &app_name)
Returns the directory of any installed docs/site.
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
bool globCompare(const std::string &candidate, const std::string &pattern, std::size_t c=0, std::size_t p=0)
std::string join(Iterator begin, Iterator end, const std::string &delimiter)
Python-like join function for strings over an iterator range.
T convert(const std::string &str, bool throw_on_failure=false)
convert takes a string representation of a number type and converts it to the number.
A MultiMooseEnum object to hold "execute_on" flags.
Taken from https://stackoverflow.com/a/257382 Evaluating constexpr (Has_size<T>::value) in a template...
void serialEnd(const libMesh::Parallel::Communicator &comm, bool warn=true)
Closes a section of code that is executed in serial rank by rank, and that was opened with a call to ...
static Yes test(decltype(&C::size))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
bool beginsWith(const std::string &value, const std::string &begin_value)
HashMap is an abstraction for dictionary data type, we make it thread-safe by locking inserts...
SemidynamicVector(std::size_t size)
int stringToInteger(const std::string &input, bool throw_on_failure=false)
Robust string to integer conversion that fails for cases such at "1foo".
bool relativeFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within a relative tolerance...
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)
Function to dump the contents of MaterialPropertyStorage for debugging purposes.
static constexpr Real TOLERANCE
std::string installedInputsDir(const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg="")
Returns the directory of any installed inputs or the empty string if none are found.
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
bool isAllLowercase(const std::string &str)
bool doesMapContainValue(const std::map< T1, T2 > &the_map, const T2 &value)
This routine is a simple helper function for searching a map by values instead of keys...
bool startsWith(const std::string &string1, const std::string &string2)
void push_back(const T &v)
std::size_t max_size() const
bool setsIntersect(InputIterator first1, InputIterator last1, InputIterator first2, InputIterator last2)
This method detects whether two sets intersect without building a result set.
std::pair< std::filesystem::path, std::filesystem::path > splitFileName(const T &full_file)
Function for splitting path and filename.
static constexpr bool value
std::list< std::string > getFilesInDirs(const std::list< std::string > &directory_list, const bool files_only=true)
Retrieves the names of all of the files contained within the list of directories passed into the rout...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
void removedirs(const std::string &dir_name, bool throw_on_failure=false)
Recursively remove directories from inner-most when the directories are empty.
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)
Linearly partition a number of items.
bool checkForGitLFSPointer(std::ifstream &file)
Check if the file is a Git-LFS pointer.
bool relativeFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than or equal to another variable within a relative tole...
std::string realpath(const std::string &path)
Wrapper around PetscGetRealPath, which is a cross-platform replacement for realpath.
T concatenate(T c1, const T &c2)
Returns a container that contains the content of second passed in container inserted into the first p...
DualNumber< Real, DNDerivativeType, true > ADReal
bool isFloat(const std::string &str)
Courtesy https://stackoverflow.com/a/57163016 and https://stackoverflow.com/questions/447206/c-isfloa...
bool relativeFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within a relative t...
std::string convertLatestCheckpoint(std::string orig)
Replaces "LATEST" placeholders with the latest checkpoint file name.
std::string mooseDocsURL(const std::string &path)
Returns the URL of a page located on the MOOSE documentation site.
std::string hostname()
Get the hostname the current process is running on.
auto max(const L &left, const R &right)
std::string camelCaseToUnderscore(const std::string &camel_case_name)
Function for converting a camel case name to a name containing underscores.
std::string shortName(const std::string &name)
Function for stripping name after the file / in parser block.
Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size...
std::vector< std::string > split(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
Python like split functions for strings.
MooseUtils::SemidynamicVector< typename ADType< T >::type, N, value_init > type
Custom type trait that has a value of true for types that can be broadcasted.
ExecFlagEnum getDefaultExecFlagEnum()
Return the default ExecFlagEnum for MOOSE.
std::string getExtension(const std::string &filename, const bool rfind=false)
Gets the extension of the passed file name.
void replaceStart(std::string &string1, const std::string &string2, const std::string &string3)
Replace the starting string string2 of string1 with string3.
std::vector< std::string > rsplit(const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
uint8_t processor_id_type
Custom type trait that has a value of true for types that cam be use interchangeably with Real...
std::string stripExtension(const std::string &s, const bool rfind=false)
Removes any file extension from the given string s (i.e.
void resize(std::size_t new_size)
int convert< int >(const std::string &str, bool throw_on_failure)
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
void indentMessage(const std::string &prefix, std::string &message, const char *color=COLOR_CYAN, bool dont_indent_first_line=true, const std::string &post_prefix=": ")
Indents the supplied message given the prefix and color.
void parallelBarrierNotify(const libMesh::Parallel::Communicator &comm, bool messaging=true)
This function implements a parallel barrier function but writes progress to stdout.
std::string getLatestCheckpointFilePrefix(const std::list< std::string > &checkpoint_files)
Returns the most recent checkpoint prefix (the four numbers at the beginning) If a suitable file isn'...
void serialBegin(const libMesh::Parallel::Communicator &comm, bool warn=true)
This function marks the begin of a section of code that is executed in serial rank by rank...
std::string canonicalPath(const std::string &path)
Gets the canonical path of the given path.
bool checkFileReadable(const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
Checks to see if a file is readable (exists and permissions)
std::string runTestsExecutable()
Returns the location of either a local repo run_tests script - or an installed test executor script i...
bool absoluteFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within an absolute tolerance...
bool wildcardEqual(const T1 &a, const T2 &b)
void expandAllMatches(const std::vector< T > &candidates, std::vector< T > &patterns)
std::size_t fileSize(const std::string &filename)
Check the file size.
unsigned int convert< unsigned int >(const std::string &str, bool throw_on_failure)
std::string underscoreToCamelCase(const std::string &underscore_name, bool leading_upper_case)
Function for converting an underscore name to a camel case name.
MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
bool hasExtension(const std::string &filename, std::string ext, bool strip_exodus_ext=false)
Function tests if the supplied filename as the desired extension.
std::string & removeColor(std::string &msg)
remove ANSI escape sequences for terminal color from msg
std::string demangle(const char *name)
bool checkFileWriteable(const std::string &filename, bool throw_on_unwritable=true)
Check if the file is writable (path exists and permissions)
int main(int argc, char *argv[])
Initialize, create and run a MooseApp.
static constexpr bool value
auto findPair(C &container, It start_iterator, const M1 &first, const M2 &second)
Find a specific pair in a container matching on first, second or both pair components.
void clearSymlink(const std::string &link)
Remove a symbolic link, if the given filename is a link.
long long int convert< long long int >(const std::string &str, bool throw_on_failure)
processor_id_type linearPartitionChunk(dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
Return the chunk_id that is assigned to handle item_id.
void createSymlink(const std::string &target, const std::string &link)
Create a symbolic link, if the link already exists it is replaced.
short int convert< short int >(const std::string &str, bool throw_on_failure)
std::filesystem::path pathjoin(const std::filesystem::path &p)
void removeSubstring(std::string &main, const std::string &sub)
find, erase, length algorithm for removing a substring from a string
unsigned long int convert< unsigned long int >(const std::string &str, bool throw_on_failure)
std::string baseName(const std::string &name)
Function for string the information before the final / in a parser block.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int numDigits(const T &num)
Return the number of digits for a number.
void getUnion(const std::vector< T > &vector1, const std::vector< T > &vector2, std::vector< T > &common)
Function which takes the union of vector1 and vector2 and copies them to common . ...
bool wildCardMatch(std::string name, std::string search_string)
bool relativeFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within a relative tolerance.
Comparison helpers that support the MooseUtils::Any wildcard which will match any value...
bool absoluteFuzzyLessEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than or equal to another variable within an absolute tol...
IntRange< T > make_range(T beg, T end)
std::list< std::string > listDir(const std::string path, bool files_only=false)
void emplace_back(Args &&... args)
libMesh::BoundingBox buildBoundingBox(const Point &p1, const Point &p2)
Construct a valid bounding box from 2 arbitrary points.
bool absoluteFuzzyGreaterEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than or equal to another variable within an absolute ...
int levenshteinDist(const std::string &s1, const std::string &s2)
Computes and returns the Levenshtein distance between strings s1 and s2.
std::string getCurrentWorkingDir()
Returns the current working directory as a string.
void makedirs(const std::string &dir_name, bool throw_on_failure=false)
Recursively make directories.
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...
static constexpr bool value
std::string removeExtraWhitespace(const std::string &str)
Removes additional whitespace from a string.
static const struct MooseUtils::AnyType Any
long int convert< long int >(const std::string &str, bool throw_on_failure)
unsigned short int convert< unsigned short int >(const std::string &str, bool throw_on_failure)
bool pathContains(const std::string &expression, const std::string &string_to_find, const std::string &delims="/")
This function tokenizes a path and checks to see if it contains the string to look for...
bool isDigits(const std::string &str)
Courtesy https://stackoverflow.com/a/8889045 and https://en.cppreference.com/w/cpp/string/byte/isdigi...
bool pathExists(const std::string &path)
std::string replaceAll(std::string str, const std::string &from, const std::string &to)
Replaces all occurrences of from in str with to and returns the result.
bool relativeFuzzyLessThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is less than another variable within a relative tolerance...
std::string stringJoin(const std::vector< std::string > &values, const std::string &separator=" ")
Concatenates value into a single string separated by separator.
unsigned long long int convert< unsigned long long int >(const std::string &str, bool throw_on_failure)
MaterialBases compute MaterialProperties.
auto index_range(const T &sizable)
bool absoluteFuzzyGreaterThan(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether a variable is greater than another variable within an absolute tolerance...
void escape(std::string &str)
This function will escape all of the standard C++ escape characters so that they can be printed...
std::string prettyCppType(const std::string &cpp_type)
std::string findTestRoot()
Searches in the current working directory and then recursively up in each parent directory looking fo...
unsigned short getTermWidth(bool use_environment)
Returns the width of the terminal using sys/ioctl.