81 lines
1.3 KiB
C++
81 lines
1.3 KiB
C++
#ifndef SPHLITE_HPP
|
|
#define SPHLITE_HPP
|
|
|
|
#include "sphlite_c_api.h"
|
|
|
|
#include <stdexcept>
|
|
#include <string>
|
|
|
|
namespace sphlite {
|
|
|
|
struct Version {
|
|
int major;
|
|
int minor;
|
|
int patch;
|
|
};
|
|
|
|
class Error : public std::runtime_error {
|
|
public:
|
|
explicit Error(const std::string &message) : std::runtime_error(message) {}
|
|
};
|
|
|
|
inline std::string last_error_message()
|
|
{
|
|
int code = 0;
|
|
char message[256];
|
|
if (sphlite_get_last_error(&code, message, static_cast<int>(sizeof(message))) != 0) {
|
|
return "SPHLite C API parameter error";
|
|
}
|
|
return std::string(message);
|
|
}
|
|
|
|
inline void check(int ierr)
|
|
{
|
|
if (ierr != 0) {
|
|
throw Error(last_error_message());
|
|
}
|
|
}
|
|
|
|
inline void initialize()
|
|
{
|
|
check(sphlite_initialize());
|
|
}
|
|
|
|
inline void finalize()
|
|
{
|
|
check(sphlite_finalize());
|
|
}
|
|
|
|
inline Version version()
|
|
{
|
|
Version result = {0, 0, 0};
|
|
check(sphlite_get_version(&result.major, &result.minor, &result.patch));
|
|
return result;
|
|
}
|
|
|
|
inline void read_inp(const std::string &filename)
|
|
{
|
|
check(sphlite_read_inp(filename.c_str()));
|
|
}
|
|
|
|
inline void build_model()
|
|
{
|
|
check(sphlite_build_model());
|
|
}
|
|
|
|
inline int particle_count()
|
|
{
|
|
int count = 0;
|
|
check(sphlite_get_particle_count(&count));
|
|
return count;
|
|
}
|
|
|
|
inline void run_explicit()
|
|
{
|
|
check(sphlite_run_explicit());
|
|
}
|
|
|
|
} // namespace sphlite
|
|
|
|
#endif
|