Commit 76927fc7 authored by Michael Turner's avatar Michael Turner

reset error util

parent 2287b028
...@@ -35,11 +35,11 @@ ...@@ -35,11 +35,11 @@
#ifndef ERRORUTIL_HPP #ifndef ERRORUTIL_HPP
#define ERRORUTIL_HPP #define ERRORUTIL_HPP
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <iostream> #include <iostream>
#include <stdexcept> #include <stdexcept>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#if defined(NEKTAR_USE_MPI) #if defined(NEKTAR_USE_MPI)
#include <mpi.h> #include <mpi.h>
...@@ -51,101 +51,97 @@ ...@@ -51,101 +51,97 @@
namespace ErrorUtil namespace ErrorUtil
{ {
static boost::optional<std::ostream &> outStream; static boost::optional<std::ostream&> outStream;
inline static void SetErrorStream(std::ostream &o) inline static void SetErrorStream(std::ostream& o)
{
outStream = o;
}
inline static bool HasCustomErrorStream()
{
return outStream ? true : false;
}
enum ErrType
{
efatal,
ewarning
};
class NekError : public std::runtime_error
{
public:
NekError(const std::string &message) : std::runtime_error(message)
{ {
outStream = o;
}
inline static bool HasCustomErrorStream()
{
return outStream ? true : false;
} }
};
inline static void Error(ErrType type, const char *routine, int lineNumber, enum ErrType
const char *msg, unsigned int level, {
bool DoComm = false) efatal,
{ ewarning
// The user of outStream is primarily for the unit tests. };
// The unit tests often generate errors on purpose to make sure
// invalid usage is flagged appropriately. Printing the error class NekError : public std::runtime_error
// messages to cerr made the unit test output hard to parse. {
public:
std::string baseMsg = NekError(const std::string& message) : std::runtime_error(message) {}
std::string("Level ") + boost::lexical_cast<std::string>(level) + };
std::string(" assertion violation\n") +
inline static void Error(ErrType type, const char *routine, int lineNumber, const char *msg, unsigned int level, bool DoComm = false)
{
// The user of outStream is primarily for the unit tests.
// The unit tests often generate errors on purpose to make sure
// invalid usage is flagged appropriately. Printing the error
// messages to cerr made the unit test output hard to parse.
std::string baseMsg = std::string("Level ") +
boost::lexical_cast<std::string>(level) +
std::string(" assertion violation\n") +
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
std::string("[") + boost::lexical_cast<std::string>(lineNumber) +
std::string("]\n") + std::string("Message : ") +
#endif #endif
msg; msg;
// Default rank is zero. If MPI used and initialised, populate with // Default rank is zero. If MPI used and initialised, populate with
// the correct rank. Messages are only printed on rank zero. // the correct rank. Messages are only printed on rank zero.
int rank = 0; int rank = 0;
#if defined(NEKTAR_USE_MPI) #if defined(NEKTAR_USE_MPI)
int flag = 0; int flag = 0;
if (DoComm) if(DoComm)
{
MPI_Initialized(&flag);
if (flag)
{ {
MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Initialized(&flag);
if(flag)
{
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
}
} }
}
#endif #endif
std::string btMessage(""); std::string btMessage("");
#if defined(NEKTAR_FULLDEBUG) #if defined(NEKTAR_FULLDEBUG)
#ifndef _WIN32 #ifndef _WIN32
void *btArray[40]; void *btArray[40];
int btSize; int btSize;
char **btStrings; char **btStrings;
btSize = backtrace(btArray, 40); btSize = backtrace(btArray, 40);
btStrings = backtrace_symbols(btArray, btSize); btStrings = backtrace_symbols(btArray, btSize);
for (int i = 0; i < btSize; ++i) for (int i = 0 ; i < btSize ; ++i)
{ {
btMessage += std::string(btStrings[i]) + "\n"; btMessage += std::string(btStrings[i]) + "\n";
} }
free(btStrings); free(btStrings);
#endif #endif
#endif #endif
switch (type) switch (type)
{ {
case efatal: case efatal:
if (!rank) if (!rank)
{ {
if (outStream) if (outStream)
{ {
(*outStream) << btMessage;
(*outStream) << "Fatal : " << baseMsg << std::endl; (*outStream) << "Fatal : " << baseMsg << std::endl;
} }
else else
{ {
std::cerr << std::endl std::cerr << btMessage;
<< "Fatal : " << baseMsg << std::endl; std::cerr << std::endl << "Fatal : " << baseMsg
<< std::endl;
} }
} }
#if defined(NEKTAR_USE_MPI) #if defined(NEKTAR_USE_MPI)
if (DoComm) if(DoComm)
{ {
if (flag) if (flag)
{ {
...@@ -160,30 +156,30 @@ inline static void Error(ErrType type, const char *routine, int lineNumber, ...@@ -160,30 +156,30 @@ inline static void Error(ErrType type, const char *routine, int lineNumber,
{ {
if (outStream) if (outStream)
{ {
(*outStream) << btMessage;
(*outStream) << "Warning: " << baseMsg << std::endl; (*outStream) << "Warning: " << baseMsg << std::endl;
} }
else else
{ {
std::cerr << btMessage;
std::cerr << "Warning: " << baseMsg << std::endl; std::cerr << "Warning: " << baseMsg << std::endl;
} }
} }
break; break;
default: default:
std::cerr << "Unknown warning type: " << baseMsg << std::endl; std::cerr << "Unknown warning type: " << baseMsg << std::endl;
}
} }
}
inline static void Error(ErrType type, const char *routine, int lineNumber, inline static void Error(ErrType type, const char *routine, int lineNumber, const std::string& msg, unsigned int level)
const std::string &msg, unsigned int level) {
{ Error(type, routine, lineNumber, msg.c_str(), level);
Error(type, routine, lineNumber, msg.c_str(), level); }
}
inline static void Error(ErrType type, const char *routine, int lineNumber, inline static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
const char *msg) {
{ Error(type, routine, lineNumber, msg, 0);
Error(type, routine, lineNumber, msg, 0); }
}
} // end of namespace } // end of namespace
/// Assert Level 0 -- Fundamental assert which /// Assert Level 0 -- Fundamental assert which
...@@ -192,63 +188,68 @@ inline static void Error(ErrType type, const char *routine, int lineNumber, ...@@ -192,63 +188,68 @@ inline static void Error(ErrType type, const char *routine, int lineNumber,
/// considered code critical, even under /// considered code critical, even under
/// optimized compilation. /// optimized compilation.
#define NEKERROR(type, msg) ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0); #define NEKERROR(type, msg) \
ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0);
#define ROOTONLY_NEKERROR(type, msg) \
ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0, true);
#define ASSERTL0(condition, msg) \ #define ROOTONLY_NEKERROR(type, msg) \
if (!(condition)) \ ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0,true);
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 0); \ #define ASSERTL0(condition,msg) \
} if(!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 0); \
}
#define WARNINGL0(condition,msg) \
if(!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
}
#define WARNINGL0(condition, msg) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 0); \
}
/// Assert Level 1 -- Debugging which is used whether in FULLDEBUG or /// Assert Level 1 -- Debugging which is used whether in FULLDEBUG or
/// DEBUG compilation mode. This level assert is designed for aiding /// DEBUG compilation mode. This level assert is designed for aiding
/// in standard debug (-g) mode /// in standard debug (-g) mode
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
#define ASSERTL1(condition, msg) \ #define ASSERTL1(condition,msg) \
if (!(condition)) \ if(!(condition)) \
{ \ { \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \ ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \
} }
#define WARNINGL1(condition, msg) \ #define WARNINGL1(condition,msg) \
if (!(condition)) \ if(!(condition)) \
{ \ { \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 1); \ ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 1); \
} }
#else //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
#define ASSERTL1(condition,msg)
#define WARNINGL1(condition,msg)
#endif //defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
#else // defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
#define ASSERTL1(condition, msg)
#define WARNINGL1(condition, msg)
#endif // defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
/// Assert Level 2 -- Debugging which is used FULLDEBUG compilation /// Assert Level 2 -- Debugging which is used FULLDEBUG compilation
/// mode. This level assert is designed to provide addition safety /// mode. This level assert is designed to provide addition safety
/// checks within the code (such as bounds checking, etc.). /// checks within the code (such as bounds checking, etc.).
#ifdef NEKTAR_FULLDEBUG #ifdef NEKTAR_FULLDEBUG
#define ASSERTL2(condition, msg) \ #define ASSERTL2(condition,msg) \
if (!(condition)) \ if(!(condition)) \
{ \ { \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \ ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \
} }
#define WARNINGL2(condition, msg) \ #define WARNINGL2(condition,msg) \
if (!(condition)) \ if(!(condition)) \
{ \ { \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 2); \ ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 2); \
} }
#else //NEKTAR_FULLDEBUG
#define ASSERTL2(condition,msg)
#define WARNINGL2(condition,msg)
#endif //NEKTAR_FULLDEBUG
#else // NEKTAR_FULLDEBUG #endif //ERRORUTIL_HPP
#define ASSERTL2(condition, msg)
#define WARNINGL2(condition, msg)
#endif // NEKTAR_FULLDEBUG
#endif // ERRORUTIL_HPP
...@@ -90,11 +90,9 @@ Array<OneD, NekDouble> CADSurfOCE::locuv(Array<OneD, NekDouble> p) ...@@ -90,11 +90,9 @@ Array<OneD, NekDouble> CADSurfOCE::locuv(Array<OneD, NekDouble> p)
uvr[1] = p2.Y(); uvr[1] = p2.Y();
gp_Pnt p3 = m_sas->Value(p2); gp_Pnt p3 = m_sas->Value(p2);
if (p3.Distance(loc) > 1e-6) WARNINGL2(p3.Distance(loc) < 1e-3, "large locuv distance " +
{ boost::lexical_cast<string>(p3.Distance(loc)/1000.0) + " " +
cout << "large locuv distance " << p3.Distance(loc)/1000.0 << " " << m_id boost::lexical_cast<string>(m_id));
<< endl;
}
// if the uv returned is slightly off the surface // if the uv returned is slightly off the surface
//(which ShapeAnalysis_Surface can do sometimes) //(which ShapeAnalysis_Surface can do sometimes)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment