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

reset error util

parent 2287b028
......@@ -35,11 +35,11 @@
#ifndef ERRORUTIL_HPP
#define ERRORUTIL_HPP
#include <LibUtilities/LibUtilitiesDeclspec.h>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <iostream>
#include <stdexcept>
#include <boost/lexical_cast.hpp>
#include <boost/optional.hpp>
#include <LibUtilities/LibUtilitiesDeclspec.h>
#if defined(NEKTAR_USE_MPI)
#include <mpi.h>
......@@ -51,101 +51,97 @@
namespace ErrorUtil
{
static boost::optional<std::ostream &> outStream;
static boost::optional<std::ostream&> outStream;
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)
inline static void SetErrorStream(std::ostream& o)
{
outStream = o;
}
inline static bool HasCustomErrorStream()
{
return outStream ? true : false;
}
};
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") +
enum ErrType
{
efatal,
ewarning
};
class NekError : public std::runtime_error
{
public:
NekError(const std::string& message) : std::runtime_error(message) {}
};
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)
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("Where : ") + boost::lexical_cast<std::string>(routine) + std::string("[") + boost::lexical_cast<std::string>(lineNumber) + std::string("]\n") + std::string("Message : ") +
#endif
msg;
msg;
// Default rank is zero. If MPI used and initialised, populate with
// the correct rank. Messages are only printed on rank zero.
int rank = 0;
// Default rank is zero. If MPI used and initialised, populate with
// the correct rank. Messages are only printed on rank zero.
int rank = 0;
#if defined(NEKTAR_USE_MPI)
int flag = 0;
if (DoComm)
{
MPI_Initialized(&flag);
if (flag)
int flag = 0;
if(DoComm)
{
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Initialized(&flag);
if(flag)
{
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
}
}
}
#endif
std::string btMessage("");
std::string btMessage("");
#if defined(NEKTAR_FULLDEBUG)
#ifndef _WIN32
void *btArray[40];
int btSize;
char **btStrings;
void *btArray[40];
int btSize;
char **btStrings;
btSize = backtrace(btArray, 40);
btStrings = backtrace_symbols(btArray, btSize);
btSize = backtrace(btArray, 40);
btStrings = backtrace_symbols(btArray, btSize);
for (int i = 0; i < btSize; ++i)
{
btMessage += std::string(btStrings[i]) + "\n";
}
free(btStrings);
for (int i = 0 ; i < btSize ; ++i)
{
btMessage += std::string(btStrings[i]) + "\n";
}
free(btStrings);
#endif
#endif
switch (type)
{
switch (type)
{
case efatal:
if (!rank)
{
if (outStream)
{
(*outStream) << btMessage;
(*outStream) << "Fatal : " << baseMsg << std::endl;
}
else
{
std::cerr << std::endl
<< "Fatal : " << baseMsg << std::endl;
std::cerr << btMessage;
std::cerr << std::endl << "Fatal : " << baseMsg
<< std::endl;
}
}
#if defined(NEKTAR_USE_MPI)
if (DoComm)
if(DoComm)
{
if (flag)
{
......@@ -160,30 +156,30 @@ inline static void Error(ErrType type, const char *routine, int lineNumber,
{
if (outStream)
{
(*outStream) << btMessage;
(*outStream) << "Warning: " << baseMsg << std::endl;
}
else
{
std::cerr << btMessage;
std::cerr << "Warning: " << baseMsg << std::endl;
}
}
break;
default:
std::cerr << "Unknown warning type: " << baseMsg << std::endl;
}
}
}
inline static void Error(ErrType type, const char *routine, int lineNumber,
const std::string &msg, unsigned int level)
{
Error(type, routine, lineNumber, msg.c_str(), level);
}
inline static void Error(ErrType type, const char *routine, int lineNumber, const std::string& msg, unsigned int level)
{
Error(type, routine, lineNumber, msg.c_str(), level);
}
inline static void Error(ErrType type, const char *routine, int lineNumber,
const char *msg)
{
Error(type, routine, lineNumber, msg, 0);
}
inline static void Error(ErrType type, const char *routine, int lineNumber, const char *msg)
{
Error(type, routine, lineNumber, msg, 0);
}
} // end of namespace
/// Assert Level 0 -- Fundamental assert which
......@@ -192,63 +188,68 @@ inline static void Error(ErrType type, const char *routine, int lineNumber,
/// considered code critical, even under
/// 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) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 0); \
}
#define ROOTONLY_NEKERROR(type, msg) \
ErrorUtil::Error(type, __FILE__, __LINE__, msg, 0,true);
#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
/// DEBUG compilation mode. This level assert is designed for aiding
/// in standard debug (-g) mode
#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG)
#define ASSERTL1(condition, msg) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \
}
#define WARNINGL1(condition, msg) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 1); \
}
#define ASSERTL1(condition,msg) \
if(!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 1); \
}
#define WARNINGL1(condition,msg) \
if(!(condition)) \
{ \
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
/// mode. This level assert is designed to provide addition safety
/// checks within the code (such as bounds checking, etc.).
#ifdef NEKTAR_FULLDEBUG
#define ASSERTL2(condition, msg) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \
}
#define WARNINGL2(condition, msg) \
if (!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::ewarning, __FILE__, __LINE__, msg, 2); \
}
#define ASSERTL2(condition,msg) \
if(!(condition)) \
{ \
ErrorUtil::Error(ErrorUtil::efatal, __FILE__, __LINE__, msg, 2); \
}
#define WARNINGL2(condition,msg) \
if(!(condition)) \
{ \
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
#define ASSERTL2(condition, msg)
#define WARNINGL2(condition, msg)
#endif // NEKTAR_FULLDEBUG
#endif //ERRORUTIL_HPP
#endif // ERRORUTIL_HPP
......@@ -90,11 +90,9 @@ Array<OneD, NekDouble> CADSurfOCE::locuv(Array<OneD, NekDouble> p)
uvr[1] = p2.Y();
gp_Pnt p3 = m_sas->Value(p2);
if (p3.Distance(loc) > 1e-6)
{
cout << "large locuv distance " << p3.Distance(loc)/1000.0 << " " << m_id
<< endl;
}
WARNINGL2(p3.Distance(loc) < 1e-3, "large locuv distance " +
boost::lexical_cast<string>(p3.Distance(loc)/1000.0) + " " +
boost::lexical_cast<string>(m_id));
// if the uv returned is slightly off the surface
//(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