20#ifndef LIBMESH_LIBMESH_COMMON_H
21#define LIBMESH_LIBMESH_COMMON_H
26#if defined(DEBUG) && defined(NDEBUG)
27# error DEBUG and NDEBUG should never be defined simultaneously
31#include "libmesh/libmesh_config.h"
35#include "libmesh/libmesh_device.h"
38#ifdef LIBMESH_ENABLE_TIMESTAMPS
39# define LIBMESH_TIME __TIME__
40# define LIBMESH_DATE __DATE__
42# define LIBMESH_TIME "notime"
43# define LIBMESH_DATE "nodate"
64#ifdef LIBMESH_HAVE_MPI
65# include "libmesh/ignore_warnings.h"
67# include "libmesh/restore_warnings.h"
71#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
72#include "libmesh/float128_shims.h"
76#include "libmesh/libmesh_base.h"
77#include "libmesh/libmesh_exceptions.h"
80#include "libmesh/ostream_proxy.h"
84#include "libmesh/libmesh_nullptr.h"
113namespace MacroFunctions
115void here(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
116void stop(
const char * file,
int line,
const char * date,
const char * time);
117void report_error(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
140DIE A HORRIBLE DEATH HERE...
148typedef LIBMESH_DEFAULT_SCALAR_TYPE
Real;
154#ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
156# if defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) || \
157 defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
158# error Cannot define multiple precision levels
162#ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
164# if defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
165# error Cannot define multiple precision levels
169#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
173#if !defined (LIBMESH_DEFAULT_SINGLE_PRECISION) && \
174 !defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) && \
175 !defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
193template<
typename T> LIBMESH_DEVICE_INLINE T
libmesh_real(T a) {
return a; }
194template<
typename T> LIBMESH_DEVICE_INLINE T
libmesh_imag(T ) {
return 0; }
195template<
typename T> LIBMESH_DEVICE_INLINE T
libmesh_conj(T a) {
return a; }
204LIBMESH_DEVICE_INLINE std::complex<T>
libmesh_conj(std::complex<T> a) {
return std::conj(a); }
235LIBMESH_DEVICE_INLINE
bool isfinite(std::complex<T> a)
241LIBMESH_DEVICE_INLINE
bool isinf(std::complex<T> a)
247LIBMESH_DEVICE_INLINE
bool isnan(std::complex<T> a)
256#if defined (LIBMESH_USE_REAL_NUMBERS)
258#elif defined (LIBMESH_USE_COMPLEX_NUMBERS)
261DIE A HORRIBLE DEATH HERE...
269#define MPI_ERRORVECTORREAL MPI_FLOAT
272#ifdef LIBMESH_HAVE_MPI
295#define libmesh_here() \
297 libMesh::MacroFunctions::here(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
306#define libmesh_stop() \
308 libMesh::MacroFunctions::stop(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
314#define libmesh_dbg_var(var) var
316#define libmesh_dbg_var(var)
321#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
322#define libmesh_inf_var(var) var
324#define libmesh_inf_var(var)
337#define libmesh_assert_msg(asserted, msg) ((void) 0)
338#define libmesh_exceptionless_assert_msg(asserted, msg) ((void) 0)
339#define libmesh_assert_equal_to_msg(expr1,expr2, msg) ((void) 0)
340#define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) ((void) 0)
341#define libmesh_assert_less_msg(expr1,expr2, msg) ((void) 0)
342#define libmesh_assert_greater_msg(expr1,expr2, msg) ((void) 0)
343#define libmesh_assert_less_equal_msg(expr1,expr2, msg) ((void) 0)
344#define libmesh_assert_greater_equal_msg(expr1,expr2, msg) ((void) 0)
346#elif defined(ACSM_KOKKOS_COMPILATION)
349#define libmesh_assert_msg(asserted, msg) LIBMESH_DEVICE_ASSERT(asserted)
350#define libmesh_exceptionless_assert_msg(asserted, msg) LIBMESH_DEVICE_ASSERT(asserted)
351#define libmesh_assert_equal_to_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) == (expr2))
352#define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) != (expr2))
353#define libmesh_assert_less_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) < (expr2))
354#define libmesh_assert_greater_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) > (expr2))
355#define libmesh_assert_less_equal_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) <= (expr2))
356#define libmesh_assert_greater_equal_msg(expr1,expr2, msg) LIBMESH_DEVICE_ASSERT((expr1) >= (expr2))
360#define libmesh_assertion_types(expr1,expr2) \
361 typedef typename std::decay<decltype(expr1)>::type libmesh_type1; \
362 typedef typename std::decay<decltype(expr2)>::type libmesh_type2
364#define libmesh_assert_msg(asserted, msg) \
367 libmesh_error_msg("Assertion `" #asserted "' failed.\n" << msg); \
370#define libmesh_exceptionless_assert_msg(asserted, msg) \
373 libMesh::Threads::lock_singleton_spin_mutex(); \
374 libMesh::err << "Assertion `" #asserted "' failed." << std::endl; \
375 libMesh::Threads::unlock_singleton_spin_mutex(); \
376 libmesh_exceptionless_error(); \
379#define libmesh_assert_equal_to_msg(expr1,expr2, msg) \
381 if (!((expr1) == (expr2))) { \
382 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
385#define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) \
387 if (!((expr1) != (expr2))) { \
388 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
391template <
template <
class>
class Comp>
394 template <
typename T1,
typename T2>
397 typedef typename std::decay<T1>::type DT1;
398 typedef typename std::decay<T2>::type DT2;
399 return (Comp<DT2>()(
static_cast<DT2
>(e1), e2) &&
400 Comp<DT1>()(e1,
static_cast<DT1
>(e2)));
403 template <
typename T1>
406 return Comp<T1>()(e1, e2);
410#define libmesh_assert_less_msg(expr1,expr2, msg) \
412 if (!libMesh::casting_compare<std::less>()(expr1, expr2)) { \
413 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
416#define libmesh_assert_greater_msg(expr1,expr2, msg) \
418 if (!libMesh::casting_compare<std::greater>()(expr1, expr2)) { \
419 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
422#define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
424 if (!libMesh::casting_compare<std::less_equal>()(expr1, expr2)) { \
425 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
428#define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
430 if (!libMesh::casting_compare<std::greater_equal>()(expr1, expr2)) { \
431 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
437#define libmesh_assert(asserted) libmesh_assert_msg(asserted, "")
438#define libmesh_exceptionless_assert(asserted) libmesh_exceptionless_assert_msg(asserted, "")
439#define libmesh_assert_equal_to(expr1,expr2) libmesh_assert_equal_to_msg(expr1,expr2, "")
440#define libmesh_assert_not_equal_to(expr1,expr2) libmesh_assert_not_equal_to_msg(expr1,expr2, "")
441#define libmesh_assert_less(expr1,expr2) libmesh_assert_less_msg(expr1,expr2, "")
442#define libmesh_assert_greater(expr1,expr2) libmesh_assert_greater_msg(expr1,expr2, "")
443#define libmesh_assert_less_equal(expr1,expr2) libmesh_assert_less_equal_msg(expr1,expr2, "")
444#define libmesh_assert_greater_equal(expr1,expr2) libmesh_assert_greater_equal_msg(expr1,expr2, "")
463#if LIBMESH_IN_DEVICE_CODE
464#define libmesh_error_msg(msg) \
466 LIBMESH_DEVICE_ERROR_MSG(msg); \
469#define libmesh_error_msg(msg) \
471 std::stringstream message_stream; \
472 message_stream << msg << '\n'; \
473 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
474 LIBMESH_THROW(libMesh::LogicError(message_stream.str())); \
478#define libmesh_error() libmesh_error_msg("")
480#define libmesh_error_msg_if(cond, msg) \
483 libmesh_error_msg(msg); \
486#define libmesh_exceptionless_error_msg(msg) \
488 libMesh::Threads::lock_singleton_spin_mutex(); \
489 libMesh::err << msg << '\n'; \
490 libMesh::Threads::unlock_singleton_spin_mutex(); \
491 libmesh_try { libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); } \
492 libmesh_catch (...) {} \
496#define libmesh_exceptionless_error() libmesh_exceptionless_error_msg("")
498#define libmesh_not_implemented_msg(msg) \
500 std::stringstream message_stream; \
501 message_stream << msg << '\n'; \
502 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
503 LIBMESH_THROW(libMesh::NotImplemented(message_stream.str())); \
506#define libmesh_not_implemented() libmesh_not_implemented_msg("")
508#define libmesh_file_error_msg(filename, msg) \
510 std::stringstream message_stream; \
511 message_stream << msg << '\n'; \
512 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
513 LIBMESH_THROW(libMesh::FileError(filename, message_stream.str())); \
516#define libmesh_file_error(filename) libmesh_file_error_msg(filename,"")
518#define libmesh_convergence_failure() \
520 LIBMESH_THROW(libMesh::ConvergenceFailure()); \
523#define libmesh_degenerate_mapping_msg(msg) \
525 std::stringstream message_stream; \
526 message_stream << msg << '\n'; \
527 LIBMESH_THROW(libMesh::DegenerateMap(message_stream.str())); \
530#define libmesh_degenerate_mapping(filename) libmesh_degenerate_mapping_msg("")
532#define libmesh_terminate() \
534 LIBMESH_THROW(libMesh::TerminationException()); \
549#define libmesh_example_requires(condition, option) \
551 if (!(condition)) { \
552 libMesh::out << "Configuring libMesh with " << option << " is required to run this example." << std::endl; \
558#undef libmesh_do_once
559#define libmesh_do_once(do_this) \
561 static bool did_this_already = false; \
562 if (!did_this_already) { \
563 did_this_already = true; \
570#ifdef LIBMESH_ENABLE_WARNINGS
571#define libmesh_warning(message) \
572 libmesh_do_once(libMesh::out << message \
573 << __FILE__ << ", line " << __LINE__ << ", compiled " << LIBMESH_DATE << " at " << LIBMESH_TIME << " ***" << std::endl;)
575#define libmesh_warning(message) ((void) 0)
580#undef libmesh_experimental
581#define libmesh_experimental() \
582 libmesh_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: ");
586#undef libmesh_deprecated
587#ifndef LIBMESH_ENABLE_DEPRECATED
588#define libmesh_deprecated() \
589 libmesh_error_msg("*** Error, This code is deprecated, and likely to be removed in future library versions! ");
591#define libmesh_deprecated() \
592 libmesh_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! ");
603#ifdef LIBMESH_HAVE_CXX17_SPLICING
607 target.merge(std::move(source));
613 target.insert(source.begin(), source.end());
621 std::string
demangle(
const char * name);
630template <
typename Tnew,
typename Told>
633#if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI) && defined(LIBMESH_ENABLE_EXCEPTIONS)
636 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
639 catch (std::bad_cast &)
642 <<
" reference to " <<
demangle(
typeid(Tnew).name())
645 <<
" appears to be a "
646 <<
demangle(
typeid(*(&oldvar)).name()) << std::endl;
650 return(
static_cast<Tnew
>(oldvar));
656template <
typename Tnew,
typename Told>
659#if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI)
660 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
664 <<
" pointer to " <<
demangle(
typeid(Tnew).name())
667 <<
" appears to be a "
668 <<
demangle(
typeid(*oldvar).name()) << std::endl;
673 return(
static_cast<Tnew
>(oldvar));
678#ifdef LIBMESH_ENABLE_DEPRECATED
679template <
typename Tnew,
typename Told>
682 libmesh_deprecated();
685 return cast_ptr<Tnew>(oldvar);
697template <
typename Tnew,
typename Told>
698inline Tnew cast_int (Told oldvar)
700 libmesh_assert_equal_to
701 (oldvar,
static_cast<Told
>(
static_cast<Tnew
>(oldvar)));
703 return(
static_cast<Tnew
>(oldvar));
707template <
typename Tnew,
typename Told>
711 return cast_int<Tnew>(oldvar);
725template <
typename Tnew,
typename Told>
728 if constexpr (!std::is_same_v<Tnew, Told>)
730 const Tnew returnval =
static_cast<Tnew
>(oldvar);
732 libmesh_error_msg_if (oldvar !=
static_cast<Told
>(returnval),
733 "restrict_int failed: " << oldvar <<
" does not fit in type " <<
typeid(returnval).name());
750#define LIBMESH_VERSION_ID(major,minor,patch) (((major) << 16) | ((minor) << 8) | ((patch) & 0xFF))
755#define libmesh_override override
759#define libmesh_delete =delete
763#define libmesh_final final
768#ifdef LIBMESH_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE
769#define libmesh_fallthrough() [[fallthrough]]
770#elif defined(LIBMESH_HAVE_DOUBLE_UNDERSCORE_ATTRIBUTE_FALLTHROUGH)
771#define libmesh_fallthrough() __attribute__((fallthrough))
773#define libmesh_fallthrough() ((void) 0)
796 using namespace TIMPI;
812#ifdef LIBMESH_IS_COMPILING_ITSELF
813# include "libmesh/libmesh_augment_std_namespace.h"
818#define LIBMESH_EXPORT __declspec(dllexport)
820#define LIBMESH_EXPORT
This class is intended to be reseatable like a pointer-to-ostream for flexibility,...
constexpr PassKey()=default
void here(const char *file, int line, const char *date, const char *time, std::ostream &os=libMesh::err)
void stop(const char *file, int line, const char *date, const char *time)
void report_error(const char *file, int line, const char *date, const char *time, std::ostream &os=libMesh::err)
void lock_singleton_spin_mutex()
void unlock_singleton_spin_mutex()
The libMesh namespace provides an interface to certain functionality in the library.
std::complex< Real > COMPLEX
LIBMESH_DEVICE_INLINE bool libmesh_isinf(T x)
static constexpr std::size_t libmesh_dim
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
bool warned_about_auto_ptr
LIBMESH_DEVICE_INLINE bool isfinite(std::complex< T > a)
Tnew restrict_int(Told oldvar)
restrict_int checks that the value of the castee is within the bounds which are exactly representable...
Tnew cast_ref(Told &oldvar)
LIBMESH_DEVICE_INLINE bool isnan(std::complex< T > a)
std::string demangle(const char *name)
Mostly system independent demangler.
std::complex< Real > Complex
void libmesh_ignore(const Args &...)
LIBMESH_DEVICE_INLINE T libmesh_imag(T)
LIBMESH_DEVICE_INLINE bool libmesh_isnan(T x)
LIBMESH_DEVICE_INLINE T libmesh_real(T a)
LIBMESH_DEVICE_INLINE bool isinf(std::complex< T > a)
Tnew libmesh_cast_int(Told oldvar)
void libmesh_merge_move(T &target, T &source)
static constexpr Real TOLERANCE
MPI_Comm GLOBAL_COMM_WORLD
MPI Communicator used to initialize libMesh.
Tnew cast_ptr(Told *oldvar)
constexpr std::false_type always_false
This is a helper variable template for cases when we want to use a default compile-time error with co...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Tnew libmesh_cast_ptr(Told *oldvar)
LIBMESH_DEVICE_INLINE T libmesh_conj(T a)
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
bool operator()(const T1 &e1, const T2 &e2) const
bool operator()(const T1 &e1, const T1 &e2) const