forked from pelahi/VELOCIraptor-STF
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rodrigo Tobar <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <sstream> | ||
|
||
#ifdef USEOPENMP | ||
#include <omp.h> | ||
#endif // USEOPENMP | ||
|
||
#include "exceptions.h" | ||
|
||
#include "allvars.h" | ||
|
||
namespace vr | ||
{ | ||
|
||
static std::string build_error_message(const Particle &part, const std::string &function) | ||
{ | ||
std::ostringstream os; | ||
os << "Particle density not positive, cannot continue.\n\n" | ||
<< "Particle information: " | ||
<< "id=" << part.GetID() << ", pid=" << part.GetPID() | ||
<< ", type=" << part.GetType() | ||
<< ", pos=(" << part.X() << ", " << part.Y() << ", " << part.Z() | ||
<< "), vel=(" << part.Vx() << ", " << part.Vy() << ", " << part.Vz() | ||
<< "), mass=" << part.GetMass() | ||
<< ", density=" << part.GetDensity() << '\n'; | ||
os << "Execution context: MPI enabled="; | ||
#ifdef USEMPI | ||
os << "yes, rank=" << ThisTask << '/' << NProcs; | ||
#else | ||
os << "no"; | ||
#endif // USEMPI | ||
os << ", OpenMP enabled="; | ||
#ifdef USEOPENMP | ||
os << "yes, thread=" << omp_get_thread_num() << '/' << omp_get_num_threads(); | ||
#else | ||
os << "no"; | ||
#endif // USEOPENMP | ||
return os.str(); | ||
} | ||
|
||
non_positive_density::non_positive_density(const Particle &part, const std::string &function) | ||
: exception(build_error_message(part, function)) | ||
{ | ||
} | ||
|
||
} // namespace vr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <exception> | ||
#include <string> | ||
|
||
// Forward declaration | ||
namespace NBody | ||
{ | ||
class Particle; | ||
} | ||
|
||
namespace vr | ||
{ | ||
|
||
/// Base class for all exceptions in velociraptor | ||
class exception : public std::exception | ||
{ | ||
public: | ||
exception(std::string what) | ||
: m_what(std::move(what)) | ||
{} | ||
|
||
const char *what() const noexcept override | ||
{ | ||
return m_what.c_str(); | ||
} | ||
|
||
private: | ||
std::string m_what; | ||
}; | ||
|
||
/// Exception thrown when a particle with non-positive density is found | ||
class non_positive_density : public exception | ||
{ | ||
public: | ||
non_positive_density(const NBody::Particle &part, const std::string &function); | ||
}; | ||
|
||
} // namespace vr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters