MFEM  v3.3
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
error.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_ERROR_HPP
13 #define MFEM_ERROR_HPP
14 
15 #include "../config/config.hpp"
16 #include <iomanip>
17 #include <sstream>
18 
19 namespace mfem
20 {
21 
22 void mfem_backtrace(int mode = 0, int depth = -1);
23 
24 void mfem_error(const char *msg = NULL);
25 
26 void mfem_warning(const char *msg = NULL);
27 
28 }
29 
30 #ifndef _MFEM_FUNC_NAME
31 #ifndef _WIN32
32 // This is nice because it shows the class and method name
33 #define _MFEM_FUNC_NAME __PRETTY_FUNCTION__
34 // This one is C99 standard.
35 //#define _MFEM_FUNC_NAME __func__
36 #else
37 // for Visual Studio C++
38 #define _MFEM_FUNC_NAME __FUNCSIG__
39 #endif
40 #endif
41 
42 #define MFEM_LOCATION \
43  "\n ... in function: " << _MFEM_FUNC_NAME << \
44  "\n ... at line " << __LINE__ << " of file: " << __FILE__ << '\n'
45 
46 // Common error message and abort macro
47 #define _MFEM_MESSAGE(msg, warn) \
48  { \
49  std::ostringstream mfemMsgStream; \
50  mfemMsgStream << std::setprecision(16); \
51  mfemMsgStream << std::setiosflags(std::ios_base::scientific); \
52  mfemMsgStream << msg << MFEM_LOCATION; \
53  if (!(warn)) \
54  mfem::mfem_error(mfemMsgStream.str().c_str()); \
55  else \
56  mfem::mfem_warning(mfemMsgStream.str().c_str()); \
57  }
58 
59 // Outputs lots of useful information and aborts.
60 // For all of these functions, "msg" is pushed to an ostream, so you can
61 // write useful (if complicated) error messages instead of writing
62 // out to the screen first, then calling abort. For example:
63 // MFEM_ABORT( "Unknown geometry type: " << type );
64 #define MFEM_ABORT(msg) _MFEM_MESSAGE("MFEM abort: " << msg, 0)
65 
66 // Does a check, and then outputs lots of useful information if the test fails
67 #define MFEM_VERIFY(x, msg) \
68  if (!(x)) \
69  { \
70  _MFEM_MESSAGE("Verification failed: (" \
71  << #x << ") is false: " << msg, 0); \
72  }
73 
74 // Use this if the only place your variable is used is in ASSERTs
75 // For example, this code snippet:
76 // int err = MPI_Reduce(ldata, maxdata, 5, MPI_INT, MPI_MAX, 0, MyComm);
77 // MFEM_CONTRACT_VAR(err);
78 // MFEM_ASSERT( err == 0, "MPI_Reduce gave an error with length "
79 // << ldata );
80 #define MFEM_CONTRACT_VAR(x) if (0 && &x == &x){}
81 
82 // Now set up some optional checks, but only if the right flags are on
83 #ifdef MFEM_DEBUG
84 
85 #define MFEM_ASSERT(x, msg) \
86  if (!(x)) \
87  { \
88  _MFEM_MESSAGE("Assertion failed: (" \
89  << #x << ") is false: " << msg, 0); \
90  }
91 
92 // A macro that exposes its argument in debug mode only.
93 #define MFEM_DEBUG_DO(x) x
94 
95 #else
96 
97 // Get rid of all this code, since we're not checking.
98 #define MFEM_ASSERT(x, msg)
99 
100 // A macro that exposes its argument in debug mode only.
101 #define MFEM_DEBUG_DO(x)
102 
103 #endif
104 
105 // Generate a warning message - always generated, regardless of MFEM_DEBUG.
106 #define MFEM_WARNING(msg) _MFEM_MESSAGE("MFEM Warning: " << msg, 1)
107 
108 #endif
void mfem_warning(const char *msg)
Definition: error.cpp:130
void mfem_error(const char *msg)
Definition: error.cpp:106
void mfem_backtrace(int mode, int depth)
Definition: error.cpp:37