120 lines
3.0 KiB
C++
Executable File
120 lines
3.0 KiB
C++
Executable File
#ifndef ERRORS_H
|
|
#define ERRORS_H
|
|
|
|
#include <math.h>
|
|
#include <exception>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include "blitz/array.h"
|
|
|
|
#include "simulation/mpi_communication.h"
|
|
|
|
#if defined debug_level3 || defined debug_level2 || defined debug_level1 || \
|
|
defined debug_level0
|
|
inline void DEBUG(const std::string& message) {
|
|
std::cout << "#DEBUG<" << MpiCommunication::mpi_rank << ">: " << message
|
|
<< std::endl;
|
|
}
|
|
|
|
#if defined debug_level0
|
|
inline void DEBUG_LEVEL_0(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_1(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
|
#elif defined debug_level1
|
|
inline void DEBUG_LEVEL_0(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_1(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
|
|
|
#elif defined debug_level2
|
|
inline void DEBUG_LEVEL_0(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_1(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_2(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
|
|
|
#else
|
|
inline void DEBUG_LEVEL_0(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_1(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_2(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
inline void DEBUG_LEVEL_3(const std::string& message) {
|
|
DEBUG(message);
|
|
}
|
|
#endif
|
|
|
|
#else
|
|
inline void DEBUG(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_0(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_1(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_2(const std::string& message) {}
|
|
inline void DEBUG_LEVEL_3(const std::string& message) {}
|
|
#endif
|
|
|
|
inline void SIM_INFO(const std::string& message) {
|
|
if (MpiCommunication::mpi_rank == 0) {
|
|
std::cout << "#INFO: " << message << std::endl;
|
|
}
|
|
}
|
|
|
|
inline void ERROR(const std::string& message) {
|
|
fprintf(stderr, "ERROR <%d> %s\n", MpiCommunication::mpi_rank,
|
|
message.c_str());
|
|
exit(EXIT_FAILURE);
|
|
// throw std::runtime_error(message);
|
|
}
|
|
|
|
template <class T>
|
|
void ASSERT_POSITIVE(T* value, const std::string& message) {
|
|
if (!(*value > 0)) {
|
|
ERROR(message);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void ASSERT_NOTNEGATIVE(T* value, const std::string& message) {
|
|
if (!(*value >= 0)) {
|
|
ERROR(message);
|
|
}
|
|
}
|
|
|
|
template <class T>
|
|
void ASSERT_EXISTS(T* value, const std::string& message) {
|
|
if (!value) {
|
|
ERROR(message);
|
|
}
|
|
}
|
|
|
|
inline void ASSERT_FINITE(double value, const std::string& message) {
|
|
if (!std::isfinite(value)) {
|
|
ERROR(message);
|
|
}
|
|
}
|
|
|
|
inline void ASSERT_FINITE(const blitz::TinyVector<double, 3>& value,
|
|
const std::string& message) {
|
|
if (!std::isfinite(value(0)) || !std::isfinite(value(1)) ||
|
|
!std::isfinite(value(2))) {
|
|
ERROR(message);
|
|
}
|
|
}
|
|
|
|
#endif /* ERRORS_H */
|