366 lines
10 KiB
C
366 lines
10 KiB
C
#include "sphlite_c_api.h"
|
|
#include "sphlite_fortran_mangle.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
extern void SPHLITE_FC_sphft_initialize(int *ierr);
|
|
extern void SPHLITE_FC_sphft_finalize(int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_version(
|
|
int *major, int *minor, int *patch, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_last_error_chars(
|
|
int *code, int *chars, const int *capacity, int *actual, int *ierr);
|
|
extern void SPHLITE_FC_sphft_read_inp_chars(
|
|
const int *chars, const int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_build_model(int *ierr);
|
|
extern void SPHLITE_FC_sphft_estimate_stable_dt(
|
|
double *dtcrit, int *ierr);
|
|
extern void SPHLITE_FC_sphft_advance_explicit(
|
|
const double *dt, int *ierr);
|
|
extern void SPHLITE_FC_sphft_run_explicit(int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_current_time(
|
|
double *time, int *step, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_particle_count(
|
|
int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_particle_state_capacity(
|
|
int *count, int *ndim, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_particle_state(
|
|
const int *max_particles,
|
|
int *particle_id_ext,
|
|
int *phase,
|
|
int *status,
|
|
int *material_id,
|
|
int *section_id,
|
|
double *x,
|
|
double *v,
|
|
double *a,
|
|
double *rho,
|
|
double *pressure,
|
|
double *internal_energy,
|
|
double *temperature,
|
|
double *h,
|
|
int *count,
|
|
int *ierr);
|
|
extern void SPHLITE_FC_sphft_set_output_directory_chars(
|
|
const int *chars, const int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_set_output_interval(const int *interval, int *ierr);
|
|
extern void SPHLITE_FC_sphft_write_output(const int *step, const double *time, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_input_warning_count(int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_write_csv_chars(
|
|
const int *chars, const int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_write_restart_chars(
|
|
const int *chars, const int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_read_restart_chars(
|
|
const int *chars, const int *count, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_water_summary(
|
|
double *mass,
|
|
double *momentum,
|
|
double *max_pressure,
|
|
double *min_density,
|
|
double *max_density,
|
|
int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_water_dt_limits(
|
|
double *dt_cfl, double *dt_accel, double *dt_viscous, int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_gas_summary(
|
|
double *volume,
|
|
double *center,
|
|
double *mean_pressure,
|
|
double *max_pressure,
|
|
int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_gas_bubble_metrics(
|
|
double *equivalent_radius,
|
|
double *radius_rate,
|
|
double *center,
|
|
int *ierr);
|
|
extern void SPHLITE_FC_sphft_get_gas_dt_limits(
|
|
double *dt_cfl, double *dt_accel, double *dtcrit, int *ierr);
|
|
|
|
static int sphlite_call_path(
|
|
const char *path,
|
|
void (*fortran_call)(const int *chars, const int *count, int *ierr))
|
|
{
|
|
size_t i;
|
|
size_t length;
|
|
int count;
|
|
int ierr;
|
|
int *chars;
|
|
|
|
if (path == NULL) {
|
|
return -1;
|
|
}
|
|
length = strlen(path);
|
|
if (length == 0 || length > 1024) {
|
|
return -1;
|
|
}
|
|
|
|
chars = (int *)malloc(length * sizeof(int));
|
|
if (chars == NULL) {
|
|
return -1;
|
|
}
|
|
for (i = 0; i < length; ++i) {
|
|
chars[i] = (unsigned char)path[i];
|
|
}
|
|
count = (int)length;
|
|
ierr = 0;
|
|
fortran_call(chars, &count, &ierr);
|
|
free(chars);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_initialize(void)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_initialize(&ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_finalize(void)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_finalize(&ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_version(int *major, int *minor, int *patch)
|
|
{
|
|
int ierr = 0;
|
|
if (major == NULL || minor == NULL || patch == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_version(major, minor, patch, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_last_error(int *code, char *message, int message_capacity)
|
|
{
|
|
int ierr = 0;
|
|
int actual = 0;
|
|
int *chars;
|
|
int i;
|
|
|
|
if (code == NULL || message == NULL || message_capacity <= 0) {
|
|
return -1;
|
|
}
|
|
chars = (int *)malloc((size_t)message_capacity * sizeof(int));
|
|
if (chars == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_last_error_chars(code, chars, &message_capacity, &actual, &ierr);
|
|
for (i = 0; i < message_capacity; ++i) {
|
|
if (chars[i] == 0) {
|
|
message[i] = '\0';
|
|
break;
|
|
}
|
|
message[i] = (char)chars[i];
|
|
}
|
|
message[message_capacity - 1] = '\0';
|
|
free(chars);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_read_inp(const char *filename)
|
|
{
|
|
return sphlite_call_path(
|
|
filename, SPHLITE_FC_sphft_read_inp_chars);
|
|
}
|
|
|
|
int sphlite_build_model(void)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_build_model(&ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_estimate_stable_dt(double *dtcrit)
|
|
{
|
|
int ierr = 0;
|
|
if (dtcrit == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_estimate_stable_dt(dtcrit, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_advance_explicit(double dt)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_advance_explicit(&dt, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_run_explicit(void)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_run_explicit(&ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_current_time(double *time, int *step)
|
|
{
|
|
int ierr = 0;
|
|
if (time == NULL || step == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_current_time(time, step, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_particle_count(int *count)
|
|
{
|
|
int ierr = 0;
|
|
if (count == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_particle_count(count, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_input_warning_count(int *count)
|
|
{
|
|
int ierr = 0;
|
|
if (count == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_input_warning_count(count, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_set_output_directory(const char *path)
|
|
{
|
|
return sphlite_call_path(path, SPHLITE_FC_sphft_set_output_directory_chars);
|
|
}
|
|
|
|
int sphlite_set_output_interval(int interval)
|
|
{
|
|
int ierr = 0;
|
|
if (interval <= 0) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_set_output_interval(&interval, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_write_output(int step, double time)
|
|
{
|
|
int ierr = 0;
|
|
SPHLITE_FC_sphft_write_output(&step, &time, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_particle_state(int max_particles,
|
|
int *particle_id_ext,
|
|
int *phase,
|
|
int *status,
|
|
int *material_id,
|
|
int *section_id,
|
|
double *x,
|
|
double *v,
|
|
double *a,
|
|
double *rho,
|
|
double *pressure,
|
|
double *internal_energy,
|
|
double *temperature,
|
|
double *h,
|
|
int *count)
|
|
{
|
|
int ierr = 0;
|
|
if (max_particles <= 0 || particle_id_ext == NULL || phase == NULL ||
|
|
status == NULL || material_id == NULL || section_id == NULL ||
|
|
x == NULL || v == NULL || a == NULL || rho == NULL ||
|
|
pressure == NULL || internal_energy == NULL || temperature == NULL ||
|
|
h == NULL || count == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_particle_state(&max_particles, particle_id_ext, phase,
|
|
status, material_id, section_id, x, v, a, rho, pressure,
|
|
internal_energy, temperature, h, count, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_write_csv(const char *filename)
|
|
{
|
|
return sphlite_call_path(
|
|
filename, SPHLITE_FC_sphft_write_csv_chars);
|
|
}
|
|
|
|
int sphlite_write_restart(const char *filename)
|
|
{
|
|
return sphlite_call_path(
|
|
filename, SPHLITE_FC_sphft_write_restart_chars);
|
|
}
|
|
|
|
int sphlite_read_restart(const char *filename)
|
|
{
|
|
return sphlite_call_path(
|
|
filename, SPHLITE_FC_sphft_read_restart_chars);
|
|
}
|
|
|
|
int sphlite_get_water_summary(double *mass,
|
|
double *momentum,
|
|
double *max_pressure,
|
|
double *min_density,
|
|
double *max_density)
|
|
{
|
|
int ierr = 0;
|
|
if (mass == NULL || momentum == NULL || max_pressure == NULL ||
|
|
min_density == NULL || max_density == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_water_summary(mass, momentum, max_pressure,
|
|
min_density, max_density, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_water_dt_limits(double *dt_cfl,
|
|
double *dt_accel,
|
|
double *dt_viscous)
|
|
{
|
|
int ierr = 0;
|
|
if (dt_cfl == NULL || dt_accel == NULL || dt_viscous == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_water_dt_limits(dt_cfl, dt_accel, dt_viscous, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_gas_summary(double *volume,
|
|
double *center,
|
|
double *mean_pressure,
|
|
double *max_pressure)
|
|
{
|
|
int ierr = 0;
|
|
if (volume == NULL || center == NULL || mean_pressure == NULL ||
|
|
max_pressure == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_gas_summary(volume, center, mean_pressure,
|
|
max_pressure, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_gas_bubble_metrics(double *equivalent_radius,
|
|
double *radius_rate,
|
|
double *center)
|
|
{
|
|
int ierr = 0;
|
|
if (equivalent_radius == NULL || radius_rate == NULL || center == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_gas_bubble_metrics(equivalent_radius, radius_rate,
|
|
center, &ierr);
|
|
return ierr;
|
|
}
|
|
|
|
int sphlite_get_gas_dt_limits(double *dt_cfl,
|
|
double *dt_accel,
|
|
double *dtcrit)
|
|
{
|
|
int ierr = 0;
|
|
if (dt_cfl == NULL || dt_accel == NULL || dtcrit == NULL) {
|
|
return -1;
|
|
}
|
|
SPHLITE_FC_sphft_get_gas_dt_limits(dt_cfl, dt_accel, dtcrit, &ierr);
|
|
return ierr;
|
|
}
|