220 lines
8.8 KiB
C
220 lines
8.8 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;
|
|
double water_mass = 0.0;
|
|
double water_momentum[3] = {0.0, 0.0, 0.0};
|
|
double max_pressure = 0.0;
|
|
double min_density = 0.0;
|
|
double max_density = 0.0;
|
|
double dt_cfl = 0.0;
|
|
double dt_accel = 0.0;
|
|
double dt_viscous = 0.0;
|
|
double gas_volume = 0.0;
|
|
double gas_center[3] = {0.0, 0.0, 0.0};
|
|
double gas_mean_pressure = 0.0;
|
|
double gas_max_pressure = 0.0;
|
|
double gas_radius = 0.0;
|
|
double gas_radius_rate = 0.0;
|
|
double gas_dtcrit = 0.0;
|
|
|
|
if (SPHLITE_PHASE_SOLID != 4 || SPHLITE_PHASE_GAS != 2 ||
|
|
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");
|
|
}
|
|
if (sphlite_get_water_summary(NULL, water_momentum, &max_pressure,
|
|
&min_density, &max_density) != -1) {
|
|
return fail("null water summary mass pointer did not return -1");
|
|
}
|
|
if (sphlite_get_water_summary(&water_mass, NULL, &max_pressure,
|
|
&min_density, &max_density) != -1) {
|
|
return fail("null water summary momentum pointer did not return -1");
|
|
}
|
|
if (sphlite_get_water_dt_limits(NULL, &dt_accel, &dt_viscous) != -1) {
|
|
return fail("null water dt pointer did not return -1");
|
|
}
|
|
if (sphlite_get_water_dt_limits(&dt_cfl, &dt_accel, NULL) != -1) {
|
|
return fail("null water dt viscous pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_summary(NULL, gas_center, &gas_mean_pressure,
|
|
&gas_max_pressure) != -1) {
|
|
return fail("null gas summary volume pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_summary(&gas_volume, NULL, &gas_mean_pressure,
|
|
&gas_max_pressure) != -1) {
|
|
return fail("null gas summary center pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_bubble_metrics(NULL, &gas_radius_rate, gas_center) != -1) {
|
|
return fail("null gas radius pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_bubble_metrics(&gas_radius, &gas_radius_rate, NULL) != -1) {
|
|
return fail("null gas bubble center pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_dt_limits(NULL, &dt_accel, &gas_dtcrit) != -1) {
|
|
return fail("null gas dt cfl pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_summary(&gas_volume, gas_center, &gas_mean_pressure,
|
|
&gas_max_pressure) != 2) {
|
|
return fail("uninitialized gas summary did not return Fortran state error");
|
|
}
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("initialize failed");
|
|
|
|
ierr = sphlite_get_water_summary(&water_mass, water_momentum, &max_pressure,
|
|
&min_density, &max_density);
|
|
if (ierr != 2) return fail("unbuilt water summary did not return Fortran state error");
|
|
ierr = sphlite_get_gas_summary(&gas_volume, gas_center, &gas_mean_pressure,
|
|
&gas_max_pressure);
|
|
if (ierr != 2) return fail("unbuilt gas summary did not return Fortran state error");
|
|
ierr = sphlite_get_gas_dt_limits(&dt_cfl, &dt_accel, &gas_dtcrit);
|
|
if (ierr != 2) return fail("unbuilt gas dt did not return Fortran state error");
|
|
|
|
ierr = sphlite_get_version(&major, &minor, &patch);
|
|
if (ierr != 0) return fail("get_version failed");
|
|
if (major != 0 || minor != 3 || patch != 1) 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");
|
|
}
|
|
if (sphlite_get_particle_state(4, ids, phase, status, material_id, section_id,
|
|
x, v, a, rho, pressure, internal_energy, temperature, h, NULL) != -1) {
|
|
return fail("null particle-state count 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_advance_explicit(-1.0e-6);
|
|
if (ierr != 1) return fail("Fortran argument error was not returned to C");
|
|
|
|
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");
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("initialize water failed");
|
|
|
|
snprintf(path, sizeof(path), "%s/water_minimal_020.inp", SPHLITE_TEST_DATA_DIR);
|
|
ierr = sphlite_read_inp(path);
|
|
if (ierr != 0) return fail("read water input failed");
|
|
ierr = sphlite_build_model();
|
|
if (ierr != 0) return fail("build water model failed");
|
|
|
|
ierr = sphlite_get_water_summary(&water_mass, water_momentum, &max_pressure,
|
|
&min_density, &max_density);
|
|
if (ierr != 0) return fail("water summary query failed");
|
|
if (water_mass <= 0.0 || min_density <= 0.0 || max_density < min_density) {
|
|
return fail("water summary content mismatch");
|
|
}
|
|
|
|
ierr = sphlite_get_water_dt_limits(&dt_cfl, &dt_accel, &dt_viscous);
|
|
if (ierr != 0) return fail("water dt limits query failed");
|
|
if (dt_cfl <= 0.0 || dt_accel <= 0.0 || dt_viscous <= 0.0) {
|
|
return fail("water dt limits content mismatch");
|
|
}
|
|
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("finalize water failed");
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("initialize gas failed");
|
|
snprintf(path, sizeof(path), "%s/gas_ideal_minimal_030.inp", SPHLITE_TEST_DATA_DIR);
|
|
ierr = sphlite_read_inp(path);
|
|
if (ierr != 0) return fail("read gas input failed");
|
|
ierr = sphlite_build_model();
|
|
if (ierr != 0) return fail("build gas model failed");
|
|
ierr = sphlite_get_gas_summary(&gas_volume, gas_center, &gas_mean_pressure,
|
|
&gas_max_pressure);
|
|
if (ierr != 0) return fail("gas summary query failed");
|
|
if (gas_volume <= 0.0 || gas_max_pressure <= 0.0) {
|
|
return fail("gas summary content mismatch");
|
|
}
|
|
ierr = sphlite_get_gas_bubble_metrics(&gas_radius, &gas_radius_rate, gas_center);
|
|
if (ierr != 0) return fail("gas bubble query failed");
|
|
if (gas_radius <= 0.0) return fail("gas bubble content mismatch");
|
|
ierr = sphlite_get_gas_dt_limits(&dt_cfl, &dt_accel, &gas_dtcrit);
|
|
if (ierr != 0) return fail("gas dt query failed");
|
|
if (dt_cfl <= 0.0 || gas_dtcrit <= 0.0) return fail("gas dt content mismatch");
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("finalize gas failed");
|
|
return 0;
|
|
}
|