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"
55 #include <type_traits>
59 #ifdef LIBMESH_HAVE_MPI
60 # include "libmesh/ignore_warnings.h"
62 # include "libmesh/restore_warnings.h"
66 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
67 #include "libmesh/float128_shims.h"
71 #include "libmesh/libmesh_base.h"
72 #include "libmesh/libmesh_exceptions.h"
75 #include "libmesh/ostream_proxy.h"
79 #include "libmesh/libmesh_nullptr.h"
100 extern OStreamProxy
out;
101 extern OStreamProxy
err;
108 namespace MacroFunctions
110 void here(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
111 void stop(
const char * file,
int line,
const char * date,
const char * time);
112 void report_error(
const char * file,
int line,
const char * date,
const char * time, std::ostream & os =
libMesh::err);
135 DIE A HORRIBLE DEATH HERE...
143 typedef LIBMESH_DEFAULT_SCALAR_TYPE
Real;
149 #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
151 # if defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) || \
152 defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
153 # error Cannot define multiple precision levels
157 #ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
159 # if defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
160 # error Cannot define multiple precision levels
164 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
168 #if !defined (LIBMESH_DEFAULT_SINGLE_PRECISION) && \
169 !defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) && \
170 !defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
192 inline std::complex<T>
libmesh_conj(std::complex<T> a) {
return std::conj(a); }
195 template <
typename T>
198 template <
typename T>
203 template <
typename T>
206 template <
typename T>
213 #if defined (LIBMESH_USE_REAL_NUMBERS)
215 #elif defined (LIBMESH_USE_COMPLEX_NUMBERS)
218 DIE A HORRIBLE DEATH HERE...
226 #define MPI_ERRORVECTORREAL MPI_FLOAT
229 #ifdef LIBMESH_HAVE_MPI
252 #define libmesh_here() \
254 libMesh::MacroFunctions::here(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
263 #define libmesh_stop() \
265 libMesh::MacroFunctions::stop(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
271 #define libmesh_dbg_var(var) var
273 #define libmesh_dbg_var(var)
278 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
279 #define libmesh_inf_var(var) var
281 #define libmesh_inf_var(var)
288 #define libmesh_assert_msg(asserted, msg) ((void) 0)
289 #define libmesh_exceptionless_assert_msg(asserted, msg) ((void) 0)
290 #define libmesh_assert_equal_to_msg(expr1,expr2, msg) ((void) 0)
291 #define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) ((void) 0)
292 #define libmesh_assert_less_msg(expr1,expr2, msg) ((void) 0)
293 #define libmesh_assert_greater_msg(expr1,expr2, msg) ((void) 0)
294 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) ((void) 0)
295 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) ((void) 0)
299 #define libmesh_assertion_types(expr1,expr2) \
300 typedef typename std::decay<decltype(expr1)>::type libmesh_type1; \
301 typedef typename std::decay<decltype(expr2)>::type libmesh_type2
303 #define libmesh_assert_msg(asserted, msg) \
306 libmesh_error_msg(msg); \
309 #define libmesh_exceptionless_assert_msg(asserted, msg) \
312 libMesh::Threads::lock_singleton_spin_mutex(); \
313 libMesh::err << "Assertion `" #asserted "' failed." << std::endl; \
314 libMesh::Threads::unlock_singleton_spin_mutex(); \
315 libmesh_exceptionless_error(); \
318 #define libmesh_assert_equal_to_msg(expr1,expr2, msg) \
320 if (!((expr1) == (expr2))) { \
321 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
324 #define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) \
326 if (!((expr1) != (expr2))) { \
327 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
330 template <
template <
class>
class Comp>
333 template <
typename T1,
typename T2>
336 typedef typename std::decay<T1>::type DT1;
337 typedef typename std::decay<T2>::type DT2;
338 return (Comp<DT2>()(static_cast<DT2>(e1), e2) &&
339 Comp<DT1>()(e1, static_cast<DT1>(e2)));
342 template <
typename T1>
345 return Comp<T1>()(e1, e2);
349 #define libmesh_assert_less_msg(expr1,expr2, msg) \
351 if (!libMesh::casting_compare<std::less>()(expr1, expr2)) { \
352 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
355 #define libmesh_assert_greater_msg(expr1,expr2, msg) \
357 if (!libMesh::casting_compare<std::greater>()(expr1, expr2)) { \
358 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
361 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
363 if (!libMesh::casting_compare<std::less_equal>()(expr1, expr2)) { \
364 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
367 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
369 if (!libMesh::casting_compare<std::greater_equal>()(expr1, expr2)) { \
370 libmesh_error_msg(std::setprecision(17) << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl); \
376 #define libmesh_assert(asserted) libmesh_assert_msg(asserted, "")
377 #define libmesh_exceptionless_assert(asserted) libmesh_exceptionless_assert_msg(asserted, "")
378 #define libmesh_assert_equal_to(expr1,expr2) libmesh_assert_equal_to_msg(expr1,expr2, "")
379 #define libmesh_assert_not_equal_to(expr1,expr2) libmesh_assert_not_equal_to_msg(expr1,expr2, "")
380 #define libmesh_assert_less(expr1,expr2) libmesh_assert_less_msg(expr1,expr2, "")
381 #define libmesh_assert_greater(expr1,expr2) libmesh_assert_greater_msg(expr1,expr2, "")
382 #define libmesh_assert_less_equal(expr1,expr2) libmesh_assert_less_equal_msg(expr1,expr2, "")
383 #define libmesh_assert_greater_equal(expr1,expr2) libmesh_assert_greater_equal_msg(expr1,expr2, "")
396 #define libmesh_error_msg(msg) \
398 std::stringstream message_stream; \
399 message_stream << msg << '\n'; \
400 libMesh::Threads::lock_singleton_spin_mutex(); \
401 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
402 libMesh::Threads::unlock_singleton_spin_mutex(); \
403 LIBMESH_THROW(libMesh::LogicError(message_stream.str())); \
406 #define libmesh_error() libmesh_error_msg("")
408 #define libmesh_error_msg_if(cond, msg) \
411 libmesh_error_msg(msg); \
414 #define libmesh_exceptionless_error_msg(msg) \
416 libMesh::Threads::lock_singleton_spin_mutex(); \
417 libMesh::err << msg << '\n'; \
418 libmesh_try { libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); } \
419 libmesh_catch (...) {} \
420 libMesh::Threads::unlock_singleton_spin_mutex(); \
424 #define libmesh_exceptionless_error() libmesh_exceptionless_error_msg("")
426 #define libmesh_not_implemented_msg(msg) \
428 std::stringstream message_stream; \
429 message_stream << msg << '\n'; \
430 libMesh::Threads::lock_singleton_spin_mutex(); \
431 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
432 libMesh::Threads::unlock_singleton_spin_mutex(); \
433 LIBMESH_THROW(libMesh::NotImplemented(message_stream.str())); \
436 #define libmesh_not_implemented() libmesh_not_implemented_msg("")
438 #define libmesh_file_error_msg(filename, msg) \
440 std::stringstream message_stream; \
441 message_stream << msg << '\n'; \
442 libMesh::Threads::lock_singleton_spin_mutex(); \
443 libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME, message_stream); \
444 libMesh::Threads::unlock_singleton_spin_mutex(); \
445 LIBMESH_THROW(libMesh::FileError(filename, message_stream.str())); \
448 #define libmesh_file_error(filename) libmesh_file_error_msg(filename,"")
450 #define libmesh_convergence_failure() \
452 LIBMESH_THROW(libMesh::ConvergenceFailure()); \
467 #define libmesh_example_requires(condition, option) \
469 if (!(condition)) { \
470 libMesh::out << "Configuring libMesh with " << option << " is required to run this example." << std::endl; \
476 #undef libmesh_do_once
477 #define libmesh_do_once(do_this) \
479 static bool did_this_already = false; \
480 if (!did_this_already) { \
481 did_this_already = true; \
488 #ifdef LIBMESH_ENABLE_WARNINGS
489 #define libmesh_warning(message) \
490 libmesh_do_once(libMesh::out << message \
491 << __FILE__ << ", line " << __LINE__ << ", compiled " << LIBMESH_DATE << " at " << LIBMESH_TIME << " ***" << std::endl;)
493 #define libmesh_warning(message) ((void) 0)
498 #undef libmesh_experimental
499 #define libmesh_experimental() \
500 libmesh_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: ");
504 #undef libmesh_deprecated
505 #ifndef LIBMESH_ENABLE_DEPRECATED
506 #define libmesh_deprecated() \
507 libmesh_error_msg("*** Error, This code is deprecated, and likely to be removed in future library versions! ");
509 #define libmesh_deprecated() \
510 libmesh_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! ");
522 #ifdef LIBMESH_HAVE_CXX17_SPLICING
523 template <
typename T>
526 target.merge(std::move(source));
529 template <
typename T>
532 target.insert(source.begin(), source.end());
535 #endif // LIBMESH_HAVE_CXX17_SPLICING
545 template <
typename Tnew,
typename Told>
548 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI) && defined(LIBMESH_ENABLE_EXCEPTIONS)
551 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
554 catch (std::bad_cast &)
556 libMesh::err <<
"Failed to convert " <<
typeid(Told).name()
557 <<
" reference to " <<
typeid(Tnew).name()
560 <<
" appears to be a "
561 <<
typeid(*(&oldvar)).name() << std::endl;
565 return(static_cast<Tnew>(oldvar));
571 template <
typename Tnew,
typename Told>
574 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI)
575 Tnew newvar =
dynamic_cast<Tnew
>(oldvar);
578 libMesh::err <<
"Failed to convert " <<
typeid(Told).name()
579 <<
" pointer to " <<
typeid(Tnew).name()
582 <<
" appears to be a "
583 <<
typeid(*oldvar).name() << std::endl;
588 return(static_cast<Tnew>(oldvar));
593 #ifdef LIBMESH_ENABLE_DEPRECATED
594 template <
typename Tnew,
typename Told>
597 libmesh_deprecated();
600 return cast_ptr<Tnew>(oldvar);
602 #endif // LIBMESH_ENABLE_DEPRECATED
612 template <
typename Tnew,
typename Told>
615 libmesh_assert_equal_to
616 (oldvar, static_cast<Told>(static_cast<Tnew>(oldvar)));
618 return(static_cast<Tnew>(oldvar));
622 template <
typename Tnew,
typename Told>
626 return cast_int<Tnew>(oldvar);
638 #define LIBMESH_VERSION_ID(major,minor,patch) (((major) << 16) | ((minor) << 8) | ((patch) & 0xFF))
643 #define libmesh_override override
647 #define libmesh_delete =delete
651 #define libmesh_final final
656 #ifdef LIBMESH_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE
657 #define libmesh_fallthrough() [[fallthrough]]
658 #elif defined(LIBMESH_HAVE_DOUBLE_UNDERSCORE_ATTRIBUTE_FALLTHROUGH)
659 #define libmesh_fallthrough() __attribute__((fallthrough))
661 #define libmesh_fallthrough() ((void) 0)
668 namespace libMeshEnums
670 using namespace libMesh;
678 using namespace TIMPI;
694 #ifdef LIBMESH_IS_COMPILING_ITSELF
695 # include "libmesh/libmesh_augment_std_namespace.h"
700 #define LIBMESH_EXPORT __declspec(dllexport)
702 #define LIBMESH_EXPORT
706 #endif // LIBMESH_LIBMESH_COMMON_H
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
static constexpr Real TOLERANCE
void libmesh_merge_move(T &target, T &source)
Tnew cast_ref(Told &oldvar)
Tnew cast_ptr(Told *oldvar)
bool warned_about_auto_ptr
MPI_Comm GLOBAL_COMM_WORLD
MPI Communicator used to initialize libMesh.
Tnew libmesh_cast_ptr(Told *oldvar)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
Tnew cast_int(Told oldvar)
void libmesh_ignore(const Args &...)
std::complex< Real > COMPLEX
void unlock_singleton_spin_mutex()
void report_error(const char *file, int line, const char *date, const char *time, std::ostream &os)
void stop(const char *file, int line, const char *date, const char *time)
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...
std::complex< Real > Complex
void lock_singleton_spin_mutex()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool operator()(const T1 &e1, const T1 &e2) const
bool operator()(const T1 &e1, const T2 &e2) const
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
void here(const char *file, int line, const char *date, const char *time, std::ostream &os)
Tnew libmesh_cast_int(Told oldvar)