107 lines
3.6 KiB
C
107 lines
3.6 KiB
C
#include "sphlite_c_api.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static int fail(const char *message)
|
|
{
|
|
fprintf(stderr, "%s\n", message);
|
|
return 1;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char path[1024];
|
|
int ierr;
|
|
int major = 0;
|
|
int minor = 0;
|
|
int patch = 0;
|
|
int count = 0;
|
|
int warnings = 0;
|
|
int step = 0;
|
|
int ids[4];
|
|
int phase[4];
|
|
int status[4];
|
|
int material_id[4];
|
|
int section_id[4];
|
|
double x[12];
|
|
double v[12];
|
|
double a[12];
|
|
double rho[4];
|
|
double pressure[4];
|
|
double internal_energy[4];
|
|
double temperature[4];
|
|
double h[4];
|
|
double time = 0.0;
|
|
|
|
if (SPHLITE_PHASE_SOLID != 4 || SPHLITE_STATUS_ACTIVE != 0) {
|
|
return fail("C constants are not locked");
|
|
}
|
|
if (sphlite_get_particle_count(NULL) != -1) {
|
|
return fail("null particle count pointer did not return -1");
|
|
}
|
|
if (sphlite_get_last_error(NULL, path, (int)sizeof(path)) != -1) {
|
|
return fail("null last-error code pointer did not return -1");
|
|
}
|
|
if (sphlite_set_output_interval(0) != -1) {
|
|
return fail("non-positive output interval did not return -1");
|
|
}
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("initialize failed");
|
|
|
|
ierr = sphlite_get_version(&major, &minor, &patch);
|
|
if (ierr != 0) return fail("get_version failed");
|
|
if (major != 0 || minor != 2 || patch != 0) return fail("unexpected version");
|
|
|
|
snprintf(path, sizeof(path), "%s/minimal_particles_011.inp", SPHLITE_TEST_DATA_DIR);
|
|
ierr = sphlite_read_inp(path);
|
|
if (ierr != 0) return fail("read_inp failed");
|
|
|
|
ierr = sphlite_build_model();
|
|
if (ierr != 0) return fail("build_model failed");
|
|
|
|
ierr = sphlite_get_particle_count(&count);
|
|
if (ierr != 0 || count != 4) return fail("particle count mismatch");
|
|
ierr = sphlite_get_input_warning_count(&warnings);
|
|
if (ierr != 0 || warnings != 0) return fail("warning count mismatch");
|
|
|
|
if (sphlite_get_particle_state(1, ids, phase, status, material_id, section_id,
|
|
x, v, a, rho, pressure, internal_energy, temperature, h, &count) == 0) {
|
|
return fail("small particle-state buffer did not fail");
|
|
}
|
|
|
|
ierr = sphlite_get_particle_state(4, ids, phase, status, material_id, section_id,
|
|
x, v, a, rho, pressure, internal_energy, temperature, h, &count);
|
|
if (ierr != 0 || count != 4) return fail("particle state query failed");
|
|
if (ids[0] != 1 || phase[0] != SPHLITE_PHASE_SOLID ||
|
|
status[0] != SPHLITE_STATUS_ACTIVE) {
|
|
return fail("particle state content mismatch");
|
|
}
|
|
|
|
if (sphlite_get_particle_state(4, NULL, phase, status, material_id, section_id,
|
|
x, v, a, rho, pressure, internal_energy, temperature, h, &count) != -1) {
|
|
return fail("null particle-state array did not return -1");
|
|
}
|
|
|
|
ierr = sphlite_advance_explicit(1.0e-6);
|
|
if (ierr != 0) return fail("advance explicit failed");
|
|
ierr = sphlite_get_current_time(&time, &step);
|
|
if (ierr != 0 || step != 1 || time <= 0.0) return fail("time query failed");
|
|
|
|
ierr = sphlite_set_output_directory(SPHLITE_TEST_WORK_DIR);
|
|
if (ierr != 0) return fail("set output directory failed");
|
|
ierr = sphlite_write_output(step, time);
|
|
if (ierr != 0) return fail("write output failed");
|
|
|
|
snprintf(path, sizeof(path), "%s/restart_c_api.tmp", SPHLITE_TEST_WORK_DIR);
|
|
ierr = sphlite_write_restart(path);
|
|
if (ierr != 0) return fail("write restart failed");
|
|
ierr = sphlite_read_restart(path);
|
|
if (ierr != 0) return fail("read restart failed");
|
|
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("finalize failed");
|
|
return 0;
|
|
}
|