Release SPHLite 0.1.0 framework

This commit is contained in:
Codex
2026-07-02 18:47:38 +08:00
commit ad31c2d5cc
54 changed files with 4710 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
#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
+47
View File
@@ -0,0 +1,47 @@
#ifndef SPHLITE_C_API_H
#define SPHLITE_C_API_H
#ifdef _WIN32
# ifdef SPHLITE_BUILD_SHARED
# define SPHLITE_API __declspec(dllexport)
# else
# define SPHLITE_API
# endif
#else
# define SPHLITE_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define SPHLITE_PHASE_WATER 1
#define SPHLITE_PHASE_GAS 2
#define SPHLITE_PHASE_EXPLOSIVE 3
#define SPHLITE_PHASE_SOLID 4
#define SPHLITE_PHASE_SHELL 5
#define SPHLITE_PHASE_BOUNDARY 6
#define SPHLITE_PHASE_COUPLING 7
#define SPHLITE_PHASE_SOLID_FAILED 8
#define SPHLITE_PHASE_SHELL_FAILED 9
SPHLITE_API int sphlite_initialize(void);
SPHLITE_API int sphlite_finalize(void);
SPHLITE_API int sphlite_get_version(int *major, int *minor, int *patch);
SPHLITE_API int sphlite_get_last_error(int *code, char *message, int message_capacity);
SPHLITE_API int sphlite_read_inp(const char *filename);
SPHLITE_API int sphlite_build_model(void);
SPHLITE_API int sphlite_estimate_stable_dt(double *dtcrit);
SPHLITE_API int sphlite_advance_explicit(double dt);
SPHLITE_API int sphlite_run_explicit(void);
SPHLITE_API int sphlite_get_current_time(double *time, int *step);
SPHLITE_API int sphlite_get_particle_count(int *count);
SPHLITE_API int sphlite_write_csv(const char *filename);
SPHLITE_API int sphlite_write_restart(const char *filename);
SPHLITE_API int sphlite_read_restart(const char *filename);
#ifdef __cplusplus
}
#endif
#endif