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"
34#ifdef LIBMESH_ENABLE_TIMESTAMPS
35# define LIBMESH_TIME __TIME__
36# define LIBMESH_DATE __DATE__
38# define LIBMESH_TIME "notime"
39# define LIBMESH_DATE "nodate"
60#ifdef LIBMESH_HAVE_MPI
61# include "libmesh/ignore_warnings.h"
63# include "libmesh/restore_warnings.h"
67#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
68#include "libmesh/float128_shims.h"
72#include "libmesh/libmesh_base.h"
73#include "libmesh/libmesh_exceptions.h"
76#include "libmesh/ostream_proxy.h"
80#include "libmesh/libmesh_nullptr.h"
109namespace MacroFunctions
111void here(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
112void stop(
const char * file,
int line,
const char * date,
const char * time);
113void report_error(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
136DIE A HORRIBLE DEATH HERE...
144typedef LIBMESH_DEFAULT_SCALAR_TYPE
Real;
150#ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
152# if defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) || \
153 defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
154# error Cannot define multiple precision levels
158#ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
160# if defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
161# error Cannot define multiple precision levels
165#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
169#if !defined (LIBMESH_DEFAULT_SINGLE_PRECISION) && \
170 !defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) && \
171 !defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
200inline std::complex<T>
libmesh_conj(std::complex<T> a) {
return std::conj(a); }
252#if defined (LIBMESH_USE_REAL_NUMBERS)
254#elif defined (LIBMESH_USE_COMPLEX_NUMBERS)
257DIE A HORRIBLE DEATH HERE...
265#define MPI_ERRORVECTORREAL MPI_FLOAT
268#ifdef LIBMESH_HAVE_MPI
291#define libmesh_here() \
293 libMesh::MacroFunctions::here(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
302#define libmesh_stop() \
304 libMesh::MacroFunctions::stop(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
310#define libmesh_dbg_var(var) var
312#define libmesh_dbg_var(var)
317#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
318#define libmesh_inf_var(var) var
320#define libmesh_inf_var(var)
327#define libmesh_assert_msg(asserted, msg) ((void) 0)
328#define libmesh_exceptionless_assert_msg(asserted, msg) ((void) 0)
329#define libmesh_assert_equal_to_msg(expr1,expr2, msg) ((void) 0)
330#define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) ((void) 0)
331#define libmesh_assert_less_msg(expr1,expr2, msg) ((void) 0)
332#define libmesh_assert_greater_msg(expr1,expr2, msg) ((void) 0)
333#define libmesh_assert_less_equal_msg(expr1,expr2, msg) ((void) 0)
334#define libmesh_assert_greater_equal_msg(expr1,expr2, msg) ((void) 0)
338#define libmesh_assertion_types(expr1,expr2) \
339 typedef typename std::decay<decltype(expr1)>::type libmesh_type1; \
340 typedef typename std::decay<decltype(expr2)>::type libmesh_type2
342#define libmesh_assert_msg(asserted, msg) \
345 libmesh_error_msg("Assertion `" #asserted "' failed.\n" << msg); \
348#define libmesh_exceptionless_assert_msg(asserted, msg) \
351 libMesh::Threads::lock_singleton_spin_mutex(); \
352 libMesh::err << "Assertion `" #asserted "' failed." << std::endl; \
353 libMesh::Threads::unlock_singleton_spin_mutex(); \
354 libmesh_exceptionless_error(); \
357#define libmesh_assert_equal_to_msg(expr1,expr2, msg) \
359 if (!((expr1) == (expr2))) { \
360 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
363#define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) \
365 if (!((expr1) != (expr2))) { \
366 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
369template <
template <
class>
class Comp>
372 template <
typename T1,
typename T2>
375 typedef typename std::decay<T1>::type DT1;
376 typedef typename std::decay<T2>::type DT2;
377 return (Comp<DT2>()(
static_cast<DT2
>(e1), e2) &&
378 Comp<DT1>()(e1,
static_cast<DT1
>(e2)));
381 template <
typename T1>
384 return Comp<T1>()(e1, e2);
388#define libmesh_assert_less_msg(expr1,expr2, msg) \
390 if (!libMesh::casting_compare<std::less>()(expr1, expr2)) { \
391 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
394#define libmesh_assert_greater_msg(expr1,expr2, msg) \
396 if (!libMesh::casting_compare<std::greater>()(expr1, expr2)) { \
397 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
400#define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
402 if (!libMesh::casting_compare<std::less_equal>()(expr1, expr2)) { \
403 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
406#define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
408 if (!libMesh::casting_compare<std::greater_equal>()(expr1, expr2)) { \
409 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
415#define libmesh_assert(asserted) libmesh_assert_msg(asserted, "")
416#define libmesh_exceptionless_assert(asserted) libmesh_exceptionless_assert_msg(asserted, "")
417#define libmesh_assert_equal_to(expr1,expr2) libmesh_assert_equal_to_msg(expr1,expr2, "")
418#define libmesh_assert_not_equal_to(expr1,expr2) libmesh_assert_not_equal_to_msg(expr1,expr2, "")
419#define libmesh_assert_less(expr1,expr2) libmesh_assert_less_msg(expr1,expr2, "")
420#define libmesh_assert_greater(expr1,expr2) libmesh_assert_greater_msg(expr1,expr2, "")
421#define libmesh_assert_less_equal(expr1,expr2) libmesh_assert_less_equal_msg(expr1,expr2, "")
422#define libmesh_assert_greater_equal(expr1,expr2) libmesh_assert_greater_equal_msg(expr1,expr2, "")
441#define libmesh_error_msg(msg) \
443 std::stringstream message_stream; \
444 message_stream << msg << '\n'; \
445 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
446 LIBMESH_THROW(libMesh::LogicError(message_stream.str())); \
449#define libmesh_error() libmesh_error_msg("")
451#define libmesh_error_msg_if(cond, msg) \
454 libmesh_error_msg(msg); \
457#define libmesh_exceptionless_error_msg(msg) \
459 libMesh::Threads::lock_singleton_spin_mutex(); \
460 libMesh::err << msg << '\n'; \
461 libMesh::Threads::unlock_singleton_spin_mutex(); \
462 libmesh_try { libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); } \
463 libmesh_catch (...) {} \
467#define libmesh_exceptionless_error() libmesh_exceptionless_error_msg("")
469#define libmesh_not_implemented_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::NotImplemented(message_stream.str())); \
477#define libmesh_not_implemented() libmesh_not_implemented_msg("")
479#define libmesh_file_error_msg(filename, msg) \
481 std::stringstream message_stream; \
482 message_stream << msg << '\n'; \
483 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
484 LIBMESH_THROW(libMesh::FileError(filename, message_stream.str())); \
487#define libmesh_file_error(filename) libmesh_file_error_msg(filename,"")
489#define libmesh_convergence_failure() \
491 LIBMESH_THROW(libMesh::ConvergenceFailure()); \
494#define libmesh_degenerate_mapping_msg(msg) \
496 std::stringstream message_stream; \
497 message_stream << msg << '\n'; \
498 LIBMESH_THROW(libMesh::DegenerateMap(message_stream.str())); \
501#define libmesh_degenerate_mapping(filename) libmesh_degenerate_mapping_msg("")
503#define libmesh_terminate() \
505 LIBMESH_THROW(libMesh::TerminationException()); \
520#define libmesh_example_requires(condition, option) \
522 if (!(condition)) { \
523 libMesh::out << "Configuring libMesh with " << option << " is required to run this example." << std::endl; \
529#undef libmesh_do_once
530#define libmesh_do_once(do_this) \
532 static bool did_this_already = false; \
533 if (!did_this_already) { \
534 did_this_already = true; \
541#ifdef LIBMESH_ENABLE_WARNINGS
542#define libmesh_warning(message) \
543 libmesh_do_once(libMesh::out << message \
544 << __FILE__ << ", line " << __LINE__ << ", compiled " << LIBMESH_DATE << " at " << LIBMESH_TIME << " ***" << std::endl;)
546#define libmesh_warning(message) ((void) 0)
551#undef libmesh_experimental
552#define libmesh_experimental() \
553 libmesh_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: ");
557#undef libmesh_deprecated
558#ifndef LIBMESH_ENABLE_DEPRECATED
559#define libmesh_deprecated() \
560 libmesh_error_msg("*** Error, This code is deprecated, and likely to be removed in future library versions! ");
562#define libmesh_deprecated() \
563 libmesh_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! ");
575#ifdef LIBMESH_HAVE_CXX17_SPLICING
579 target.merge(std::move(source));
585 target.insert(source.begin(), source.end());
593 std::string
demangle(
const char * name);
602template <
typename Tnew,
typename Told>
605#if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI) && defined(LIBMESH_ENABLE_EXCEPTIONS)
608 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
611 catch (std::bad_cast &)
614 <<
" reference to " <<
demangle(
typeid(Tnew).name())
617 <<
" appears to be a "
618 <<
demangle(
typeid(*(&oldvar)).name()) << std::endl;
622 return(
static_cast<Tnew
>(oldvar));
628template <
typename Tnew,
typename Told>
631#if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI)
632 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
636 <<
" pointer to " <<
demangle(
typeid(Tnew).name())
639 <<
" appears to be a "
640 <<
demangle(
typeid(*oldvar).name()) << std::endl;
645 return(
static_cast<Tnew
>(oldvar));
650#ifdef LIBMESH_ENABLE_DEPRECATED
651template <
typename Tnew,
typename Told>
654 libmesh_deprecated();
657 return cast_ptr<Tnew>(oldvar);
669template <
typename Tnew,
typename Told>
670inline Tnew cast_int (Told oldvar)
672 libmesh_assert_equal_to
673 (oldvar,
static_cast<Told
>(
static_cast<Tnew
>(oldvar)));
675 return(
static_cast<Tnew
>(oldvar));
679template <
typename Tnew,
typename Told>
683 return cast_int<Tnew>(oldvar);
697template <
typename Tnew,
typename Told>
700 if constexpr (!std::is_same_v<Tnew, Told>)
702 const Tnew returnval =
static_cast<Tnew
>(oldvar);
704 libmesh_error_msg_if (oldvar !=
static_cast<Told
>(returnval),
705 "restrict_int failed: " << oldvar <<
" does not fit in type " <<
typeid(returnval).name());
723#define LIBMESH_VERSION_ID(major,minor,patch) (((major) << 16) | ((minor) << 8) | ((patch) & 0xFF))
728#define libmesh_override override
732#define libmesh_delete =delete
736#define libmesh_final final
741#ifdef LIBMESH_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE
742#define libmesh_fallthrough() [[fallthrough]]
743#elif defined(LIBMESH_HAVE_DOUBLE_UNDERSCORE_ATTRIBUTE_FALLTHROUGH)
744#define libmesh_fallthrough() __attribute__((fallthrough))
746#define libmesh_fallthrough() ((void) 0)
769 using namespace TIMPI;
785#ifdef LIBMESH_IS_COMPILING_ITSELF
786# include "libmesh/libmesh_augment_std_namespace.h"
791#define LIBMESH_EXPORT __declspec(dllexport)
793#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
static constexpr std::size_t libmesh_dim
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
bool warned_about_auto_ptr
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)
std::string demangle(const char *name)
Mostly system independent demangler.
std::complex< Real > Complex
void libmesh_ignore(const Args &...)
bool isfinite(std::complex< T > a)
bool isnan(std::complex< T > a)
Tnew libmesh_cast_int(Told oldvar)
void libmesh_merge_move(T &target, T &source)
static constexpr Real TOLERANCE
bool isinf(std::complex< T > a)
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)
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