diff --git a/library/LibUtilities/BasicUtils/ErrorUtil.hpp b/library/LibUtilities/BasicUtils/ErrorUtil.hpp index b3bb4b84afa81905373b4223d1bf263cb20a14b8..95fa0df023fec879792d494f49610da46fd98a8e 100644 --- a/library/LibUtilities/BasicUtils/ErrorUtil.hpp +++ b/library/LibUtilities/BasicUtils/ErrorUtil.hpp @@ -35,11 +35,11 @@ #ifndef ERRORUTIL_HPP #define ERRORUTIL_HPP -#include -#include -#include #include #include +#include +#include +#include #if defined(NEKTAR_USE_MPI) #include @@ -51,101 +51,97 @@ namespace ErrorUtil { -static boost::optional outStream; + static boost::optional 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(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(level) + + std::string(" assertion violation\n") + #if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULLDEBUG) - std::string("Where : ") + boost::lexical_cast(routine) + - std::string("[") + boost::lexical_cast(lineNumber) + - std::string("]\n") + std::string("Message : ") + + std::string("Where : ") + boost::lexical_cast(routine) + std::string("[") + boost::lexical_cast(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 diff --git a/library/NekMeshUtils/CADSystem/OCE/CADSurfOCE.cpp b/library/NekMeshUtils/CADSystem/OCE/CADSurfOCE.cpp index e0d9b838e7359d115b154b05abbe64819336e981..463da3eca8f56486b176fd84523eb76ba0e1d16e 100644 --- a/library/NekMeshUtils/CADSystem/OCE/CADSurfOCE.cpp +++ b/library/NekMeshUtils/CADSystem/OCE/CADSurfOCE.cpp @@ -90,11 +90,9 @@ Array CADSurfOCE::locuv(Array 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(p3.Distance(loc)/1000.0) + " " + + boost::lexical_cast(m_id)); // if the uv returned is slightly off the surface //(which ShapeAnalysis_Surface can do sometimes)