libmesh解析
本工作只是尝试解析原libmesh的代码,供学习使用
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 
libmesh_common.h
浏览该文件的文档.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2023 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 // These flags should never be used together. -DDEBUG means "turn on
24 // all the ridiculously expensive error checking"; -DNDEBUG means
25 // "turn off all the somewhat affordable error checking"
26 #if defined(DEBUG) && defined(NDEBUG)
27 # error DEBUG and NDEBUG should never be defined simultaneously
28 #endif
29 
30 // The library configuration options
31 #include "libmesh/libmesh_config.h"
32 
33 // Use actual timestamps or constant dummies (to aid ccache)
34 #ifdef LIBMESH_ENABLE_TIMESTAMPS
35 # define LIBMESH_TIME __TIME__
36 # define LIBMESH_DATE __DATE__
37 #else
38 # define LIBMESH_TIME "notime"
39 # define LIBMESH_DATE "nodate"
40 #endif
41 
42 // C/C++ includes everyone should know about
43 #include <cstdlib>
44 #ifdef __PGI
45 // BSK, Thu Feb 20 08:32:06 CST 2014 - For some reason, unless PGI gets
46 // <cmath> early this nonsense shows up:
47 // "/software/x86_64/pgi/12.9/linux86-64/12.9/include/CC/cmath", line 57: error:
48 // the global scope has no "abs"
49 // using _STLP_VENDOR_CSTD::abs;
50 // So include <cmath> as early as possible under the PGI compilers.
51 # include <cmath>
52 #endif
53 #include <complex>
54 #include <typeinfo> // std::bad_cast
55 #include <type_traits> // std::decay
56 #include <functional> // std::less, etc
57 
58 // Include the MPI definition
59 #ifdef LIBMESH_HAVE_MPI
60 # include "libmesh/ignore_warnings.h"
61 # include <mpi.h>
62 # include "libmesh/restore_warnings.h"
63 #endif
64 
65 // Quad precision if we need it
66 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
67 #include "libmesh/float128_shims.h"
68 #endif
69 
70 // _basic_ library functionality
71 #include "libmesh/libmesh_base.h"
72 #include "libmesh/libmesh_exceptions.h"
73 
74 // Proxy class for libMesh::out/err output
75 #include "libmesh/ostream_proxy.h"
76 
77 // Make sure the libmesh_nullptr define is available for backwards
78 // compatibility, although we no longer use it in the library.
79 #include "libmesh/libmesh_nullptr.h"
80 
81 // C++ headers
82 #include <iomanip> // setprecision, in assertion macros
83 
84 namespace libMesh
85 {
86 namespace Threads
87 {
88 // For thread-safe error-messaging. Definitions in threads.h
91 }
92 
93 // Let's define a couple output streams - these will default
94 // to cout/cerr, but LibMeshInit (or the user) can also set them to
95 // something more sophisticated.
96 //
97 // We use a proxy class rather than references so they can be
98 // reseated at runtime.
99 
100 extern OStreamProxy out;
101 extern OStreamProxy err;
102 
103 // A namespace for functions used in the bodies of the macros below.
104 // The macros generally call these functions with __FILE__, __LINE__,
105 // __DATE__, and __TIME__ in the appropriate order. These should not
106 // be called by users directly! The implementations can be found in
107 // libmesh_common.C.
108 namespace MacroFunctions
109 {
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);
113 }
114 
115 // Undefine any existing macros
116 #ifdef Real
117 # undef Real
118 #endif
119 
120 //#ifdef REAL
121 //# undef REAL
122 //#endif
123 
124 #ifdef Complex
125 # undef Complex
126 #endif
127 
128 #ifdef COMPLEX
129 # undef COMPLEX
130 #endif
131 
132 // Check to see if TOLERANCE has been defined by another
133 // package, if so we might want to change the name...
134 #ifdef TOLERANCE
135 DIE A HORRIBLE DEATH HERE...
136 # undef TOLERANCE
137 #endif
138 
139 
140 
141 // Define the type to use for real numbers
142 
143 typedef LIBMESH_DEFAULT_SCALAR_TYPE Real;
144 
145 // Define a corresponding tolerance. This is what should be
146 // considered "good enough" when doing floating point comparisons.
147 // For example, v == 0 is changed to std::abs(v) < TOLERANCE.
148 
149 #ifdef LIBMESH_DEFAULT_SINGLE_PRECISION
150 static constexpr Real TOLERANCE = 2.5e-3;
151 # if defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) || \
152  defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
153 # error Cannot define multiple precision levels
154 # endif
155 #endif
156 
157 #ifdef LIBMESH_DEFAULT_TRIPLE_PRECISION
158 static constexpr Real TOLERANCE = 1.e-8;
159 # if defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
160 # error Cannot define multiple precision levels
161 # endif
162 #endif
163 
164 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
165 static constexpr Real TOLERANCE = 1.e-11;
166 #endif
167 
168 #if !defined (LIBMESH_DEFAULT_SINGLE_PRECISION) && \
169  !defined (LIBMESH_DEFAULT_TRIPLE_PRECISION) && \
170  !defined (LIBMESH_DEFAULT_QUADRUPLE_PRECISION)
171 static constexpr Real TOLERANCE = 1.e-6;
172 #endif
173 
174 // Define the type to use for complex numbers
175 // Always use std::complex<double>, as required by Petsc?
176 // If your version of Petsc doesn't support
177 // std::complex<other_precision>, then you'd better just leave
178 // Real==double
179 typedef std::complex<Real> Complex;
180 typedef std::complex<Real> COMPLEX;
181 
182 
183 // Helper functions for complex/real numbers
184 // to clean up #ifdef LIBMESH_USE_COMPLEX_NUMBERS elsewhere
185 template<typename T> inline T libmesh_real(T a) { return a; }
186 template<typename T> inline T libmesh_conj(T a) { return a; }
187 
188 template<typename T>
189 inline T libmesh_real(std::complex<T> a) { return std::real(a); }
190 
191 template<typename T>
192 inline std::complex<T> libmesh_conj(std::complex<T> a) { return std::conj(a); }
193 
194 // std::isnan() is in <cmath> as of C++11.
195 template <typename T>
196 inline bool libmesh_isnan(T x) { return std::isnan(x); }
197 
198 template <typename T>
199 inline bool libmesh_isnan(std::complex<T> a)
200 { return (std::isnan(std::real(a)) || std::isnan(std::imag(a))); }
201 
202 // std::isinf() is in <cmath> as of C++11.
203 template <typename T>
204 inline bool libmesh_isinf(T x) { return std::isinf(x); }
205 
206 template <typename T>
207 inline bool libmesh_isinf(std::complex<T> a)
208 { return (std::isinf(std::real(a)) || std::isinf(std::imag(a))); }
209 
210 // Define the value type for unknowns in simulations.
211 // This is either Real or Complex, depending on how
212 // the library was configures
213 #if defined (LIBMESH_USE_REAL_NUMBERS)
214 typedef Real Number;
215 #elif defined (LIBMESH_USE_COMPLEX_NUMBERS)
216 typedef Complex Number;
217 #else
218 DIE A HORRIBLE DEATH HERE...
219 #endif
220 
221 
222 // Define the value type for error estimates.
223 // Since AMR/C decisions don't have to be precise,
224 // we default to float for memory efficiency.
225 typedef float ErrorVectorReal;
226 #define MPI_ERRORVECTORREAL MPI_FLOAT
227 
228 
229 #ifdef LIBMESH_HAVE_MPI
230 
234 extern MPI_Comm GLOBAL_COMM_WORLD;
235 #else
236 
241 extern int GLOBAL_COMM_WORLD;
242 #endif
243 
244 // This global variable is to help us deprecate AutoPtr. We can't
245 // just use libmesh_deprecated() because then you get one print out
246 // per template instantiation, instead of one total print out.
247 extern bool warned_about_auto_ptr;
248 
249 // These are useful macros that behave like functions in the code.
250 // If you want to make sure you are accessing a section of code just
251 // stick a libmesh_here(); in it, for example
252 #define libmesh_here() \
253  do { \
254  libMesh::MacroFunctions::here(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
255  } while (0)
256 
257 // the libmesh_stop() macro will stop the code until a SIGCONT signal
258 // is received. This is useful, for example, when determining the
259 // memory used by a given operation. A libmesh_stop() could be
260 // inserted before and after a questionable operation and the delta
261 // memory can be obtained from a ps or top. This macro only works for
262 // serial cases.
263 #define libmesh_stop() \
264  do { \
265  libMesh::MacroFunctions::stop(__FILE__, __LINE__, LIBMESH_DATE, LIBMESH_TIME); \
266  } while (0)
267 
268 // The libmesh_dbg_var() macro indicates that an argument to a function
269 // is used only in debug mode (i.e., when NDEBUG is not defined).
270 #ifndef NDEBUG
271 #define libmesh_dbg_var(var) var
272 #else
273 #define libmesh_dbg_var(var)
274 #endif
275 
276 // The libmesh_inf_var() macro indicates that an argument to a function
277 // is used only when infinite elements are enabled
278 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
279 #define libmesh_inf_var(var) var
280 #else
281 #define libmesh_inf_var(var)
282 #endif
283 
284 // The libmesh_assert() macro acts like C's assert(), but throws a
285 // libmesh_error() (including stack trace, etc) instead of just exiting
286 #ifdef NDEBUG
287 
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)
296 
297 #else
298 
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
302 
303 #define libmesh_assert_msg(asserted, msg) \
304  do { \
305  if (!(asserted)) { \
306  libmesh_error_msg(msg); \
307  } } while (0)
308 
309 #define libmesh_exceptionless_assert_msg(asserted, msg) \
310  do { \
311  if (!(asserted)) { \
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(); \
316  } } while (0)
317 
318 #define libmesh_assert_equal_to_msg(expr1,expr2, msg) \
319  do { \
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); \
322  } } while (0)
323 
324 #define libmesh_assert_not_equal_to_msg(expr1,expr2, msg) \
325  do { \
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); \
328  } } while (0)
329 
330 template <template <class> class Comp>
332 
333  template <typename T1, typename T2>
334  bool operator()(const T1 & e1, const T2 & e2) const
335  {
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)));
340  }
341 
342  template <typename T1>
343  bool operator()(const T1 & e1, const T1 & e2) const
344  {
345  return Comp<T1>()(e1, e2);
346  }
347 };
348 
349 #define libmesh_assert_less_msg(expr1,expr2, msg) \
350  do { \
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); \
353  } } while (0)
354 
355 #define libmesh_assert_greater_msg(expr1,expr2, msg) \
356  do { \
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); \
359  } } while (0)
360 
361 #define libmesh_assert_less_equal_msg(expr1,expr2, msg) \
362  do { \
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); \
365  } } while (0)
366 
367 #define libmesh_assert_greater_equal_msg(expr1,expr2, msg) \
368  do { \
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); \
371  } } while (0)
372 
373 #endif
374 
375 
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, "")
384 
385 // The libmesh_error() macro prints a message and throws a LogicError
386 // exception
387 //
388 // The libmesh_not_implemented() macro prints a message and throws a
389 // NotImplemented exception
390 //
391 // The libmesh_file_error(const std::string & filename) macro prints a message
392 // and throws a FileError exception
393 //
394 // The libmesh_convergence_failure() macro
395 // throws a ConvergenceFailure exception
396 #define libmesh_error_msg(msg) \
397  do { \
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())); \
404  } while (0)
405 
406 #define libmesh_error() libmesh_error_msg("")
407 
408 #define libmesh_error_msg_if(cond, msg) \
409  do { \
410  if (cond) \
411  libmesh_error_msg(msg); \
412  } while (0)
413 
414 #define libmesh_exceptionless_error_msg(msg) \
415  do { \
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(); \
421  std::terminate(); \
422  } while (0)
423 
424 #define libmesh_exceptionless_error() libmesh_exceptionless_error_msg("")
425 
426 #define libmesh_not_implemented_msg(msg) \
427  do { \
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())); \
434  } while (0)
435 
436 #define libmesh_not_implemented() libmesh_not_implemented_msg("")
437 
438 #define libmesh_file_error_msg(filename, msg) \
439  do { \
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())); \
446  } while (0)
447 
448 #define libmesh_file_error(filename) libmesh_file_error_msg(filename,"")
449 
450 #define libmesh_convergence_failure() \
451  do { \
452  LIBMESH_THROW(libMesh::ConvergenceFailure()); \
453  } while (0)
454 
455 // The libmesh_example_requires() macro prints a message and calls
456 // "return 77;" if the condition specified by the macro is not true. This
457 // macro is used in the example executables, which should run when the
458 // configure-time libMesh options support them but which should exit
459 // without failure otherwise.
460 //
461 // This macro only works in main(), because we have no better way than
462 // "return" from main to immediately exit successfully - std::exit()
463 // gets seen by at least some MPI stacks as failure.
464 //
465 // 77 is the automake code for a skipped test.
466 
467 #define libmesh_example_requires(condition, option) \
468  do { \
469  if (!(condition)) { \
470  libMesh::out << "Configuring libMesh with " << option << " is required to run this example." << std::endl; \
471  return 77; \
472  } } while (0)
473 
474 // The libmesh_do_once macro helps us avoid redundant repeated
475 // repetitions of the same warning messages
476 #undef libmesh_do_once
477 #define libmesh_do_once(do_this) \
478  do { \
479  static bool did_this_already = false; \
480  if (!did_this_already) { \
481  did_this_already = true; \
482  do_this; \
483  } } while (0)
484 
485 
486 // The libmesh_warning macro outputs a file/line/time stamped warning
487 // message, if warnings are enabled.
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;)
492 #else
493 #define libmesh_warning(message) ((void) 0)
494 #endif
495 
496 // The libmesh_experimental macro warns that you are using
497 // bleeding-edge code
498 #undef libmesh_experimental
499 #define libmesh_experimental() \
500  libmesh_warning("*** Warning, This code is untested, experimental, or likely to see future API changes: ");
501 
502 
503 // The libmesh_deprecated macro warns that you are using obsoleted code
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! ");
508 #else
509 #define libmesh_deprecated() \
510  libmesh_warning("*** Warning, This code is deprecated, and likely to be removed in future library versions! ");
511 #endif
512 
513 // A function template for ignoring unused variables. This is a way
514 // to shut up unused variable compiler warnings on a case by case
515 // basis.
516 template<class ...Args> inline void libmesh_ignore( const Args&... ) { }
517 
518 
519 // A workaround for the lack of C++17 merge() support in some
520 // compilers
521 
522 #ifdef LIBMESH_HAVE_CXX17_SPLICING
523 template <typename T>
524 void libmesh_merge_move(T & target, T & source)
525 {
526  target.merge(std::move(source));
527 }
528 #else
529 template <typename T>
530 void libmesh_merge_move(T & target, T & source)
531 {
532  target.insert(source.begin(), source.end());
533  source.clear(); // Avoid forwards-incompatibility
534 }
535 #endif // LIBMESH_HAVE_CXX17_SPLICING
536 
537 
538 // cast_ref and cast_ptr do a dynamic cast and assert
539 // the result, if we have RTTI enabled and we're in debug or
540 // development modes, but they just do a faster static cast if we're
541 // in optimized mode.
542 //
543 // Use these casts when you're certain that a cast will succeed in
544 // correct code but you want to be able to double-check.
545 template <typename Tnew, typename Told>
546 inline Tnew cast_ref(Told & oldvar)
547 {
548 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI) && defined(LIBMESH_ENABLE_EXCEPTIONS)
549  try
550  {
551  Tnew newvar = dynamic_cast<Tnew>(oldvar);
552  return newvar;
553  }
554  catch (std::bad_cast &)
555  {
556  libMesh::err << "Failed to convert " << typeid(Told).name()
557  << " reference to " << typeid(Tnew).name()
558  << std::endl;
559  libMesh::err << "The " << typeid(Told).name()
560  << " appears to be a "
561  << typeid(*(&oldvar)).name() << std::endl;
562  libmesh_error();
563  }
564 #else
565  return(static_cast<Tnew>(oldvar));
566 #endif
567 }
568 
569 // We use two different function names to avoid an odd overloading
570 // ambiguity bug with icc 10.1.008
571 template <typename Tnew, typename Told>
572 inline Tnew cast_ptr (Told * oldvar)
573 {
574 #if !defined(NDEBUG) && defined(LIBMESH_HAVE_RTTI)
575  Tnew newvar = dynamic_cast<Tnew>(oldvar);
576  if (!newvar)
577  {
578  libMesh::err << "Failed to convert " << typeid(Told).name()
579  << " pointer to " << typeid(Tnew).name()
580  << std::endl;
581  libMesh::err << "The " << typeid(Told).name()
582  << " appears to be a "
583  << typeid(*oldvar).name() << std::endl;
584  libmesh_error();
585  }
586  return newvar;
587 #else
588  return(static_cast<Tnew>(oldvar));
589 #endif
590 }
591 
592 
593 #ifdef LIBMESH_ENABLE_DEPRECATED
594 template <typename Tnew, typename Told>
595 inline Tnew libmesh_cast_ptr (Told * oldvar)
596 {
597  libmesh_deprecated();
598 
599  // we use the less redundantly named libMesh::cast_ptr now
600  return cast_ptr<Tnew>(oldvar);
601 }
602 #endif // LIBMESH_ENABLE_DEPRECATED
603 
604 
605 // cast_int asserts that the value of the castee is within the
606 // bounds which are exactly representable by the output type, if we're
607 // in debug or development modes, but it just does a faster static
608 // cast if we're in optimized mode.
609 //
610 // Use these casts when you're certain that a cast will succeed in
611 // correct code but you want to be able to double-check.
612 template <typename Tnew, typename Told>
613 inline Tnew cast_int (Told oldvar)
614 {
615  libmesh_assert_equal_to
616  (oldvar, static_cast<Told>(static_cast<Tnew>(oldvar)));
617 
618  return(static_cast<Tnew>(oldvar));
619 }
620 
621 
622 template <typename Tnew, typename Told>
623 inline Tnew libmesh_cast_int (Told oldvar)
624 {
625  // we use the less redundantly named libMesh::cast_int now
626  return cast_int<Tnew>(oldvar);
627 }
628 
634 template <class T>
635 constexpr std::false_type always_false{};
636 
637 // build a integer representation of version
638 #define LIBMESH_VERSION_ID(major,minor,patch) (((major) << 16) | ((minor) << 8) | ((patch) & 0xFF))
639 
640 
641 // libmesh_override is simply a synonym for override as we now require
642 // a C++11 compiler that supports this keyword.
643 #define libmesh_override override
644 
645 // libmesh_delete is simply a synonym for '=delete' as we now require
646 // a C++11 compiler that supports this keyword.
647 #define libmesh_delete =delete
648 
649 // libmesh_final is simply a synonym for 'final' as we now require
650 // a C++11 compiler that supports this keyword.
651 #define libmesh_final final
652 
653 // Define backwards-compatible fallthrough attribute. We could
654 // eventually also add support for other compiler-specific fallthrough
655 // attributes.
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))
660 #else
661 #define libmesh_fallthrough() ((void) 0)
662 #endif
663 
664 } // namespace libMesh
665 
666 
667 // Backwards compatibility
668 namespace libMeshEnums
669 {
670 using namespace libMesh;
671 }
672 
673 // Backwards compatibility with pre-TIMPI reference
674 namespace TIMPI {}
675 
676 namespace libMesh {
677  namespace Parallel {
678  using namespace TIMPI;
679  }
680 }
681 
682 
683 // Here we add missing types to the standard namespace. For example,
684 // std::max(double, float) etc... are well behaved but not defined
685 // by the standard. This also includes workarounds for super-strict
686 // implementations, for example Sun Studio and PGI C++. However,
687 // this necessarily requires breaking the ISO-C++ standard, and is
688 // really just a hack. As such, only do it if we are building the
689 // libmesh library itself. Specifically, *DO NOT* export this to
690 // user code or install this header.
691 //
692 // We put this at the end of libmesh_common.h so we can make use of
693 // any exotic definitions of Real above.
694 #ifdef LIBMESH_IS_COMPILING_ITSELF
695 # include "libmesh/libmesh_augment_std_namespace.h"
696 #endif
697 
698 
699 #ifdef _MSC_VER
700 #define LIBMESH_EXPORT __declspec(dllexport)
701 #else
702 #define LIBMESH_EXPORT
703 #endif
704 
705 
706 #endif // LIBMESH_LIBMESH_COMMON_H
T libmesh_real(T a)
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
T libmesh_conj(T a)
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.
Definition: libmesh.C:198
Tnew libmesh_cast_ptr(Told *oldvar)
bool libmesh_isnan(T x)
DIE A HORRIBLE DEATH HERE typedef float ErrorVectorReal
bool libmesh_isinf(T x)
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...
OStreamProxy out
std::complex< Real > Complex
void lock_singleton_spin_mutex()
OStreamProxy err
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)