libMesh
libmesh_common.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_LIBMESH_COMMON_H
21 #define LIBMESH_LIBMESH_COMMON_H
22 
23 // The library configuration options
24 #include "libmesh/libmesh_config.h"
25 
26 // Use actual timestamps or constant dummies (to aid ccache)
27 #ifdef LIBMESH_ENABLE_TIMESTAMPS
28 # define LIBMESH_TIME __TIME__
29 # define LIBMESH_DATE __DATE__
30 #else
31 # define LIBMESH_TIME "notime"
32 # define LIBMESH_DATE "nodate"
33 #endif
34 
35 // C/C++ includes everyone should know about
36 #include <cstdlib>
37 #ifdef __PGI
38 // BSK, Thu Feb 20 08:32:06 CST 2014 - For some reason, unless PGI gets
39 // <cmath> early this nonsense shows up:
40 // "/software/x86_64/pgi/12.9/linux86-64/12.9/include/CC/cmath", line 57: error:
41 // the global scope has no "abs"
42 // using _STLP_VENDOR_CSTD::abs;
43 // So include <cmath> as early as possible under the PGI compilers.
44 # include <cmath>
45 #endif
46 #include <complex>
47 #include <typeinfo> // std::bad_cast
48 #include <type_traits> // std::decay
49 #include <functional> // std::less, etc
50 
51 // Include the MPI definition
52 #ifdef LIBMESH_HAVE_MPI
53 # include "libmesh/ignore_warnings.h"
54 # include <mpi.h>
55 # include "libmesh/restore_warnings.h"
56 #endif
57 
58 // Quad precision if we need it
59 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
60 #include "libmesh/float128_shims.h"
61 #endif
62 
63 // _basic_ library functionality
64 #include "libmesh/libmesh_base.h"
65 #include "libmesh/libmesh_exceptions.h"
66 
67 // Proxy class for libMesh::out/err output
68 #include "libmesh/ostream_proxy.h"
69 
70 // Make sure the libmesh_nullptr define is available for backwards
71 // compatibility, although we no longer use it in the library.
72 #include "libmesh/libmesh_nullptr.h"
73 
74 namespace libMesh
75 {
76 
77 // A namespace for functions used in the bodies of the macros below.
78 // The macros generally call these functions with __FILE__, __LINE__,
79 // __DATE__, and __TIME__ in the appropriate order. These should not
80 // be called by users directly! The implementations can be found in
81 // libmesh_common.C.
82 namespace MacroFunctions
83 {
84 void here(const char * file, int line, const char * date, const char * time);
85 void stop(const char * file, int line, const char * date, const char * time);
86 void report_error(const char * file, int line, const char * date, const char * time);
87 }
88 
89 // Undefine any existing macros
90 #ifdef Real
91 # undef Real
92 #endif
93 
94 //#ifdef REAL
95 //# undef REAL
96 //#endif
97 
98 #ifdef Complex
99 # undef Complex
100 #endif
101 
102 #ifdef COMPLEX
103 # undef COMPLEX
104 #endif
105 
106 #ifdef MPI_REAL
107 # undef MPI_REAL
108 #endif
109 
110 // Check to see if TOLERANCE has been defined by another
111 // package, if so we might want to change the name...
112 #ifdef TOLERANCE
113 DIE A HORRIBLE DEATH HERE...
114 # undef TOLERANCE
115 #endif
116 
117 
118 
119 // Define the type to use for real numbers
120 
121 typedef LIBMESH_DEFAULT_SCALAR_TYPE Real;
122 
123 // Define a corresponding tolerance. This is what should be
124 // considered "good enough" when doing floating point comparisons.
125 // For example, v == 0 is changed to std::abs(v) < TOLERANCE.
126 
127 #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
128 static const Real TOLERANCE = 2.5e-3;
129 # define MPI_REAL MPI_FLOAT
130 # if defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) || \
131  defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
132 # error Cannot define multiple precision levels
133 # endif
134 #endif
135 #ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
136 static const Real TOLERANCE = 1.e-8;
137 # define MPI_REAL MPI_LONG_DOUBLE
138 # if defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
139 # error Cannot define multiple precision levels
140 # endif
141 #endif
142 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
143 static const Real TOLERANCE = 1.e-11;
144 # ifdef LIBMESH_HAVE_MPI
145 # define MPI_REAL libMesh::Parallel::StandardType<Real>()
146 # endif
147 #endif
148 #if !defined (LIBMESH_DEFAULT_SINGLE_PRECISION) && \
149  !defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) && \
150  !defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
151 static const Real TOLERANCE = 1.e-6;
152 # define MPI_REAL MPI_DOUBLE
153 #endif
154 
155 // Define the type to use for complex numbers
156 // Always use std::complex<double>, as required by Petsc?
157 // If your version of Petsc doesn't support
158 // std::complex<other_precision>, then you'd better just leave
159 // Real==double
160 typedef std::complex<Real> Complex;
161 typedef std::complex<Real> COMPLEX;
162 
163 
164 // Helper functions for complex/real numbers
165 // to clean up #ifdef LIBMESH_USE_COMPLEX_NUMBERS elsewhere
166 template<typename T> inline T libmesh_real(T a) { return a; }
167 template<typename T> inline T libmesh_conj(T a) { return a; }
168 
169 template<typename T>
170 inline T libmesh_real(std::complex<T> a) { return std::real(a); }
171 
172 template<typename T>
173 inline std::complex<T> libmesh_conj(std::complex<T> a) { return std::conj(a); }
174 
175 // std::isnan() is in <cmath> as of C++11.
176 template <typename T>
177 inline bool libmesh_isnan(T x) { return std::isnan(x); }
178 
179 template <typename T>
180 inline bool libmesh_isnan(std::complex<T> a)
181 { return (std::isnan(std::real(a)) || std::isnan(std::imag(a))); }
182 
183 // std::isinf() is in <cmath> as of C++11.
184 template <typename T>
185 inline bool libmesh_isinf(T x) { return std::isinf(x); }
186 
187 template <typename T>
188 inline bool libmesh_isinf(std::complex<T> a)
189 { return (std::isinf(std::real(a)) || std::isinf(std::imag(a))); }
190 
191 // Define the value type for unknowns in simulations.
192 // This is either Real or Complex, depending on how
193 // the library was configures
194 #if defined (LIBMESH_USE_REAL_NUMBERS)
195 typedef Real Number;
196 #elif defined (LIBMESH_USE_COMPLEX_NUMBERS)
197 typedef Complex Number;
198 #else
199 DIE A HORRIBLE DEATH HERE...
200 #endif
201 
202 
203 // Define the value type for error estimates.
204 // Since AMR/C decisions don't have to be precise,
205 // we default to float for memory efficiency.
206 typedef float ErrorVectorReal;
207 #define MPI_ERRORVECTORREAL MPI_FLOAT
208 
209 
210 #ifdef LIBMESH_HAVE_MPI
211 
215 extern MPI_Comm GLOBAL_COMM_WORLD;
216 #else
217 
222 extern int GLOBAL_COMM_WORLD;
223 #endif
224 
225 // Let's define a couple output streams - these will default
226 // to cout/cerr, but LibMeshInit (or the user) can also set them to
227 // something more sophisticated.
228 //
229 // We use a proxy class rather than references so they can be
230 // reseated at runtime.
231 
232 extern OStreamProxy out;
233 extern OStreamProxy err;
234 
235 // This global variable is to help us deprecate AutoPtr. We can't
236 // just use libmesh_deprecated() because then you get one print out
237 // per template instantiation, instead of one total print out.
238 extern bool warned_about_auto_ptr;
239 
240 // These are useful macros that behave like functions in the code.
241 // If you want to make sure you are accessing a section of code just
242 // stick a libmesh_here(); in it, for example
243 #define libmesh_here() \
244  do { \
245  libMesh::MacroFunctions::here(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
246  } while (0)
247 
248 // the libmesh_stop() macro will stop the code until a SIGCONT signal
249 // is received. This is useful, for example, when determining the
250 // memory used by a given operation. A libmesh_stop() could be
251 // inserted before and after a questionable operation and the delta
252 // memory can be obtained from a ps or top. This macro only works for
253 // serial cases.
254 #define libmesh_stop() \
255  do { \
256  libMesh::MacroFunctions::stop(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
257  } while (0)
258 
259 // The libmesh_dbg_var() macro indicates that an argument to a function
260 // is used only in debug mode (i.e., when NDEBUG is not defined).
261 #ifndef NDEBUG
262 #define libmesh_dbg_var(var) var
263 #else
264 #define libmesh_dbg_var(var)
265 #endif
266 
267 // The libmesh_assert() macro acts like C's assert(), but throws a
268 // libmesh_error() (including stack trace, etc) instead of just exiting
269 #ifdef NDEBUG
270 
271 #define libmesh_assert_msg(asserted, msg) ((void) 0)
272 #define libmesh_exceptionless_assert_msg(asserted, msg) ((void) 0)
273 #define libmesh_assert_equal_to_msg(expr1,expr2, msg) ((void) 0)
274 #define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) ((void) 0)
275 #define libmesh_assert_less_msg(expr1,expr2, msg) ((void) 0)
276 #define libmesh_assert_greater_msg(expr1,expr2, msg) ((void) 0)
277 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) ((void) 0)
278 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) ((void) 0)
279 
280 #else
281 
282 #define libmesh_assertion_types(expr1,expr2) \
283  typedef typename std::decay<decltype(expr1)>::type libmesh_type1; \
284  typedef typename std::decay<decltype(expr2)>::type libmesh_type2
285 
286 #define libmesh_assert_msg(asserted, msg) \
287  do { \
288  if (!(asserted)) { \
289  libMesh::err << "Assertion `" #asserted "' failed." << std::endl; \
290  libmesh_error_msg(msg); \
291  } } while (0)
292 
293 #define libmesh_exceptionless_assert_msg(asserted, msg) \
294  do { \
295  if (!(asserted)) { \
296  libMesh::err << "Assertion `" #asserted "' failed." << std::endl; \
297  libmesh_exceptionless_error(); \
298  } } while (0)
299 
300 #define libmesh_assert_equal_to_msg(expr1,expr2, msg) \
301  do { \
302  if (!((expr1) == (expr2))) { \
303  libMesh::err << "Assertion `" #expr1 " == " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
304  libmesh_error(); \
305  } } while (0)
306 
307 #define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) \
308  do { \
309  if (!((expr1) != (expr2))) { \
310  libMesh::err << "Assertion `" #expr1 " != " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
311  libmesh_error(); \
312  } } while (0)
313 
314 // Older Clang has a parsing bug that can't seem to handle the handle the decay statement when
315 // expanding these macros. We'll just fall back to the previous behavior with those older compilers
316 #if defined(__clang__) && (__clang_major__ <= 3)
317 
318 #define libmesh_assert_less_msg(expr1,expr2, msg) \
319  do { \
320  if (!((expr1) < (expr2))) { \
321  libMesh::err << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
322  libmesh_error(); \
323  } } while (0)
324 
325 #define libmesh_assert_greater_msg(expr1,expr2, msg) \
326  do { \
327  if (!((expr1) > (expr2))) { \
328  libMesh::err << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
329  libmesh_error(); \
330  } } while (0)
331 
332 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
333  do { \
334  if (!((expr1) <= (expr2))) { \
335  libMesh::err << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
336  libmesh_error(); \
337  } } while (0)
338 
339 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
340  do { \
341  if (!((expr1) >= (expr2))) { \
342  libMesh::err << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
343  libmesh_error(); \
344  } } while (0)
345 
346 // Newer clangs and all other supported compilers
347 #else
348 
349 template <template <class> class Comp>
351 
352  template <typename T1, typename T2>
353  bool operator()(const T1 & e1, const T2 & e2) const
354  {
355  typedef typename std::decay<T1>::type DT1;
356  typedef typename std::decay<T2>::type DT2;
357  return (Comp<DT2>()(static_cast<DT2>(e1), e2) &&
358  Comp<DT1>()(e1, static_cast<DT1>(e2)));
359  }
360 
361  template <typename T1>
362  bool operator()(const T1 & e1, const T1 & e2) const
363  {
364  return Comp<T1>()(e1, e2);
365  }
366 };
367 
368 #define libmesh_assert_less_msg(expr1,expr2, msg) \
369  do { \
370  if (!libMesh::casting_compare<std::less>()(expr1, expr2)) { \
371  libMesh::err << "Assertion `" #expr1 " < " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
372  libmesh_error(); \
373  } } while (0)
374 
375 #define libmesh_assert_greater_msg(expr1,expr2, msg) \
376  do { \
377  if (!libMesh::casting_compare<std::greater>()(expr1, expr2)) { \
378  libMesh::err << "Assertion `" #expr1 " > " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
379  libmesh_error(); \
380  } } while (0)
381 
382 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
383  do { \
384  if (!libMesh::casting_compare<std::less_equal>()(expr1, expr2)) { \
385  libMesh::err << "Assertion `" #expr1 " <= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
386  libmesh_error(); \
387  } } while (0)
388 
389 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
390  do { \
391  if (!libMesh::casting_compare<std::greater_equal>()(expr1, expr2)) { \
392  libMesh::err << "Assertion `" #expr1 " >= " #expr2 "' failed.\n" #expr1 " = " << (expr1) << "\n" #expr2 " = " << (expr2) << '\n' << msg << std::endl; \
393  libmesh_error(); \
394  } } while (0)
395 
396 #endif // clang <4.0
397 
398 #endif
399 
400 
401 #define libmesh_assert(asserted) libmesh_assert_msg(asserted, "")
402 #define libmesh_exceptionless_assert(asserted) libmesh_exceptionless_assert_msg(asserted, "")
403 #define libmesh_assert_equal_to(expr1,expr2) libmesh_assert_equal_to_msg(expr1,expr2, "")
404 #define libmesh_assert_not_equal_to(expr1,expr2) libmesh_assert_not_equal_to_msg(expr1,expr2, "")
405 #define libmesh_assert_less(expr1,expr2) libmesh_assert_less_msg(expr1,expr2, "")
406 #define libmesh_assert_greater(expr1,expr2) libmesh_assert_greater_msg(expr1,expr2, "")
407 #define libmesh_assert_less_equal(expr1,expr2) libmesh_assert_less_equal_msg(expr1,expr2, "")
408 #define libmesh_assert_greater_equal(expr1,expr2) libmesh_assert_greater_equal_msg(expr1,expr2, "")
409 
410 // The libmesh_error() macro prints a message and throws a LogicError
411 // exception
412 //
413 // The libmesh_not_implemented() macro prints a message and throws a
414 // NotImplemented exception
415 //
416 // The libmesh_file_error(const std::string & filename) macro prints a message
417 // and throws a FileError exception
418 //
419 // The libmesh_convergence_failure() macro
420 // throws a ConvergenceFailure exception
421 #define libmesh_error_msg(msg) \
422  do { \
423  libMesh::err << msg << std::endl; \
424  std::stringstream msg_stream; \
425  msg_stream << msg; \
426  libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
427  LIBMESH_THROW(libMesh::LogicError(msg_stream.str())); \
428  } while (0)
429 
430 #define libmesh_error() libmesh_error_msg("")
431 
432 #define libmesh_exceptionless_error_msg(msg) \
433  do { \
434  libMesh::err << msg << std::endl; \
435  libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
436  std::terminate(); \
437  } while (0)
438 
439 #define libmesh_exceptionless_error() libmesh_exceptionless_error_msg("")
440 
441 #define libmesh_not_implemented_msg(msg) \
442  do { \
443  libMesh::err << msg << std::endl; \
444  libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
445  LIBMESH_THROW(libMesh::NotImplemented()); \
446  } while (0)
447 
448 #define libmesh_not_implemented() libmesh_not_implemented_msg("")
449 
450 #define libmesh_file_error_msg(filename, msg) \
451  do { \
452  libMesh::err << "Error with file `" << filename << "'" << std::endl; \
453  libMesh::MacroFunctions::report_error(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
454  libMesh::err << msg << std::endl; \
455  LIBMESH_THROW(libMesh::FileError(filename)); \
456  } while (0)
457 
458 #define libmesh_file_error(filename) libmesh_file_error_msg(filename,"")
459 
460 #define libmesh_convergence_failure() \
461  do { \
462  LIBMESH_THROW(libMesh::ConvergenceFailure()); \
463  } while (0)
464 
465 // The libmesh_example_requires() macro prints a message and calls
466 // "return 77;" if the condition specified by the macro is not true. This
467 // macro is used in the example executables, which should run when the
468 // configure-time libMesh options support them but which should exit
469 // without failure otherwise.
470 //
471 // This macro only works in main(), because we have no better way than
472 // "return" from main to immediately exit successfully - std::exit()
473 // gets seen by at least some MPI stacks as failure.
474 //
475 // 77 is the automake code for a skipped test.
476 
477 #define libmesh_example_requires(condition, option) \
478  do { \
479  if (!(condition)) { \
480  libMesh::out << "Configuring libMesh with " << option << " is required to run this example." << std::endl; \
481  return 77; \
482  } } while (0)
483 
484 // The libmesh_do_once macro helps us avoid redundant repeated
485 // repetitions of the same warning messages
486 #undef libmesh_do_once
487 #define libmesh_do_once(do_this) \
488  do { \
489  static bool did_this_already = false; \
490  if (!did_this_already) { \
491  did_this_already = true; \
492  do_this; \
493  } } while (0)
494 
495 
496 // The libmesh_warning macro outputs a file/line/time stamped warning
497 // message, if warnings are enabled.
498 #ifdef LIBMESH_ENABLE_WARNINGS
499 #define libmesh_warning(message) \
500  libmesh_do_once(libMesh::out << message \
501  << __FILE__ << ", line " << __LINE__ << ", compiled " << LIBMESH_DATE << " at " << LIBMESH_TIME << " ***" << std::endl;)
502 #else
503 #define libmesh_warning(message) ((void) 0)
504 #endif
505 
506 // The libmesh_experimental macro warns that you are using
507 // bleeding-edge code
508 #undef libmesh_experimental
509 #define libmesh_experimental() \
510  libmesh_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: ");
511 
512 
513 // The libmesh_deprecated macro warns that you are using obsoleted code
514 #undef libmesh_deprecated
515 #ifndef LIBMESH_ENABLE_DEPRECATED
516 #define libmesh_deprecated() \
517  libmesh_error_msg("*** Error, This code is deprecated, and likely to be removed in future library versions! ");
518 #else
519 #define libmesh_deprecated() \
520  libmesh_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! ");
521 #endif
522 
523 // A function template for ignoring unused variables. This is a way
524 // to shut up unused variable compiler warnings on a case by case
525 // basis.
526 template<class ...Args> inline void libmesh_ignore( const Args&... ) { }
527 
528 
529 // cast_ref and cast_ptr do a dynamic cast and assert
530 // the result, if we have RTTI enabled and we're in debug or
531 // development modes, but they just do a faster static cast if we're
532 // in optimized mode.
533 //
534 // Use these casts when you're certain that a cast will succeed in
535 // correct code but you want to be able to double-check.
536 template <typename Tnew, typename Told>
537 inline Tnew cast_ref(Told & oldvar)
538 {
539 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI) && defined(LIBMESH_ENABLE_EXCEPTIONS)
540  try
541  {
542  Tnew newvar = dynamic_cast<Tnew>(oldvar);
543  return newvar;
544  }
545  catch (std::bad_cast &)
546  {
547  libMesh::err << "Failed to convert " << typeid(Told).name()
548  << " reference to " << typeid(Tnew).name()
549  << std::endl;
550  libMesh::err << "The " << typeid(Told).name()
551  << " appears to be a "
552  << typeid(*(&oldvar)).name() << std::endl;
553  libmesh_error();
554  }
555 #else
556  return(static_cast<Tnew>(oldvar));
557 #endif
558 }
559 
560 #ifdef LIBMESH_ENABLE_DEPRECATED
561 template <typename Tnew, typename Told>
562 inline Tnew libmesh_cast_ref(Told & oldvar)
563 {
564  // we use the less redundantly named libMesh::cast_ref now
565  libmesh_deprecated();
566  return cast_ref<Tnew>(oldvar);
567 }
568 #endif
569 
570 // We use two different function names to avoid an odd overloading
571 // ambiguity bug with icc 10.1.008
572 template <typename Tnew, typename Told>
573 inline Tnew cast_ptr (Told * oldvar)
574 {
575 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI)
576  Tnew newvar = dynamic_cast<Tnew>(oldvar);
577  if (!newvar)
578  {
579  libMesh::err << "Failed to convert " << typeid(Told).name()
580  << " pointer to " << typeid(Tnew).name()
581  << std::endl;
582  libMesh::err << "The " << typeid(Told).name()
583  << " appears to be a "
584  << typeid(*oldvar).name() << std::endl;
585  libmesh_error();
586  }
587  return newvar;
588 #else
589  return(static_cast<Tnew>(oldvar));
590 #endif
591 }
592 
593 
594 template <typename Tnew, typename Told>
595 inline Tnew libmesh_cast_ptr (Told * oldvar)
596 {
597  // we use the less redundantly named libMesh::cast_ptr now
598  return cast_ptr<Tnew>(oldvar);
599 }
600 
601 
602 // cast_int asserts that the value of the castee is within the
603 // bounds which are exactly representable by the output type, if we're
604 // in debug or development modes, but it just does a faster static
605 // cast if we're in optimized mode.
606 //
607 // Use these casts when you're certain that a cast will succeed in
608 // correct code but you want to be able to double-check.
609 template <typename Tnew, typename Told>
610 inline Tnew cast_int (Told oldvar)
611 {
612  libmesh_assert_equal_to
613  (oldvar, static_cast<Told>(static_cast<Tnew>(oldvar)));
614 
615  return(static_cast<Tnew>(oldvar));
616 }
617 
618 
619 template <typename Tnew, typename Told>
620 inline Tnew libmesh_cast_int (Told oldvar)
621 {
622  // we use the less redundantly named libMesh::cast_int now
623  return cast_int<Tnew>(oldvar);
624 }
625 
626 
627 // build a integer representation of version
628 #define LIBMESH_VERSION_ID(major,minor,patch) (((major) << 16) | ((minor) << 8) | ((patch) & 0xFF))
629 
630 
631 // libmesh_override is simply a synonym for override as we now require
632 // a C++11 compiler that supports this keyword.
633 #define libmesh_override override
634 
635 // libmesh_delete is simply a synonym for '=delete' as we now require
636 // a C++11 compiler that supports this keyword.
637 #define libmesh_delete =delete
638 
639 // libmesh_final is simply a synonym for 'final' as we now require
640 // a C++11 compiler that supports this keyword.
641 #define libmesh_final final
642 
643 // Define backwards-compatible fallthrough attribute. We could
644 // eventually also add support for other compiler-specific fallthrough
645 // attributes.
646 #ifdef LIBMESH_HAVE_CXX17_FALLTHROUGH_ATTRIBUTE
647 #define libmesh_fallthrough() [[fallthrough]]
648 #elif defined(LIBMESH_HAVE_DOUBLE_UNDERSCORE_ATTRIBUTE_FALLTHROUGH)
649 #define libmesh_fallthrough() __attribute__((fallthrough))
650 #else
651 #define libmesh_fallthrough() ((void) 0)
652 #endif
653 
654 } // namespace libMesh
655 
656 
657 // Backwards compatibility
658 namespace libMeshEnums
659 {
660 using namespace libMesh;
661 }
662 
663 // Backwards compatibility with pre-TIMPI reference
664 namespace TIMPI {}
665 
666 namespace libMesh {
667  namespace Parallel {
668  using namespace TIMPI;
669  }
670 }
671 
672 
673 // Here we add missing types to the standard namespace. For example,
674 // std::max(double, float) etc... are well behaved but not defined
675 // by the standard. This also includes workarounds for super-strict
676 // implementations, for example Sun Studio and PGI C++. However,
677 // this necessarily requires breaking the ISO-C++ standard, and is
678 // really just a hack. As such, only do it if we are building the
679 // libmesh library itself. Specifically, *DO NOT* export this to
680 // user code or install this header.
681 //
682 // We put this at the end of libmesh_common.h so we can make use of
683 // any exotic definitions of Real above.
684 #ifdef LIBMESH_IS_COMPILING_ITSELF
685 # include "libmesh/libmesh_augment_std_namespace.h"
686 #endif
687 
688 
689 #endif // LIBMESH_LIBMESH_COMMON_H
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::libmesh_cast_int
Tnew libmesh_cast_int(Told oldvar)
Definition: libmesh_common.h:620
libMesh::GLOBAL_COMM_WORLD
MPI_Comm GLOBAL_COMM_WORLD
MPI Communicator used to initialize libMesh.
Definition: libmesh_common.h:222
libMesh::libmesh_cast_ptr
Tnew libmesh_cast_ptr(Told *oldvar)
Definition: libmesh_common.h:595
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::warned_about_auto_ptr
bool warned_about_auto_ptr
libMesh::ErrorVectorReal
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
Definition: libmesh_common.h:206
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::libmesh_conj
T libmesh_conj(T a)
Definition: libmesh_common.h:167
libMesh::cast_ptr
Tnew cast_ptr(Told *oldvar)
Definition: libmesh_common.h:573
libMesh::cast_ref
Tnew cast_ref(Told &oldvar)
Definition: libmesh_common.h:537
libMesh::casting_compare::operator()
bool operator()(const T1 &e1, const T1 &e2) const
Definition: libmesh_common.h:362
libMesh::MacroFunctions::stop
void stop(const char *file, int line, const char *date, const char *time)
Definition: libmesh_common.C:53
libMesh::COMPLEX
std::complex< Real > COMPLEX
Definition: libmesh_common.h:161
libMesh::libmesh_isnan
bool libmesh_isnan(T x)
Definition: libmesh_common.h:177
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
libMeshEnums
Definition: libmesh_common.h:658
libMesh::libmesh_isinf
bool libmesh_isinf(T x)
Definition: libmesh_common.h:185
libMesh::cast_int
Tnew cast_int(Told oldvar)
Definition: libmesh_common.h:610
libMesh::BasicOStreamProxy
This class is intended to be reseatable like a pointer-to-ostream for flexibility,...
Definition: ostream_proxy.h:42
libMesh::casting_compare
Definition: libmesh_common.h:350
A
static PetscErrorCode Mat * A
Definition: petscdmlibmeshimpl.C:1026
libMesh::casting_compare::operator()
bool operator()(const T1 &e1, const T2 &e2) const
Definition: libmesh_common.h:353
libMesh::MacroFunctions::here
void here(const char *file, int line, const char *date, const char *time)
Definition: libmesh_common.C:41
libMesh::Complex
std::complex< Real > Complex
Definition: libmesh_common.h:160
libMesh::libmesh_cast_ref
Tnew libmesh_cast_ref(Told &oldvar)
Definition: libmesh_common.h:562
TIMPI
Definition: libmesh_common.h:664
libMesh::MacroFunctions::report_error
void report_error(const char *file, int line, const char *date, const char *time)
Definition: libmesh_common.C:69
libMesh::err
OStreamProxy err
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
std::imag
boost::multiprecision::float128 imag(const boost::multiprecision::float128)
Definition: float128_shims.h:83
libMesh::Quality::name
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
std::real
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
Definition: float128_shims.h:77