426 lines
20 KiB
C
426 lines
20 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;
|
|
double gas_extended_mass = 0.0;
|
|
double gas_momentum[3] = {0.0, 0.0, 0.0};
|
|
double gas_density_range[2] = {0.0, 0.0};
|
|
double gas_dt_limits[3] = {0.0, 0.0, 0.0};
|
|
double gas_source_mass = 0.0;
|
|
double gas_source_momentum[3] = {0.0, 0.0, 0.0};
|
|
double gas_source_energy = 0.0;
|
|
int explosive_particle_count = 0;
|
|
int explosive_reacted_count = 0;
|
|
double explosive_lambda_range[3] = {0.0, 0.0, 0.0};
|
|
double explosive_released_totals[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
|
|
double explosive_detonation_range[2] = {0.0, 0.0};
|
|
double explosive_release_mass_values[4] = {0.0, 0.0, 0.0, 0.0};
|
|
double explosive_release_energy_values[2] = {0.0, 0.0};
|
|
double explosive_release_momentum_values[3] = {0.0, 0.0, 0.0};
|
|
int solid_active_count = 0;
|
|
int solid_failed_count = 0;
|
|
double solid_values[SPHLITE_SOLID_SUMMARY_VALUE_COUNT] = {0.0};
|
|
double solid_particle_values[4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT] = {0.0};
|
|
int solid_failure_status[4] = {0};
|
|
int solid_reference_neighbor_count[4] = {0};
|
|
int solid_reference_degenerate[4] = {0};
|
|
int solid_correction_status[4] = {0};
|
|
int solid_state_count = 0;
|
|
double solid_diagnostics[SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT] = {0.0};
|
|
double solid_reference_values[SPHLITE_SOLID_REFERENCE_VALUE_COUNT] = {0.0};
|
|
int solid_reference_neighbor_min = 0;
|
|
int solid_correction_status_max = 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_extended_summary(NULL, gas_momentum,
|
|
gas_density_range, gas_dt_limits) != -1) {
|
|
return fail("null gas extended mass pointer did not return -1");
|
|
}
|
|
if (sphlite_get_gas_source_summary(&gas_source_mass, NULL,
|
|
&gas_source_energy) != -1) {
|
|
return fail("null gas source momentum pointer did not return -1");
|
|
}
|
|
if (sphlite_get_explosive_summary(NULL, &explosive_reacted_count,
|
|
explosive_lambda_range, explosive_released_totals,
|
|
explosive_detonation_range) != -1) {
|
|
return fail("null explosive summary particle pointer did not return -1");
|
|
}
|
|
if (sphlite_get_explosive_summary(&explosive_particle_count,
|
|
&explosive_reacted_count, NULL, explosive_released_totals,
|
|
explosive_detonation_range) != -1) {
|
|
return fail("null explosive summary lambda pointer did not return -1");
|
|
}
|
|
if (sphlite_get_explosive_release_balance(NULL,
|
|
explosive_release_energy_values, explosive_release_momentum_values) != -1) {
|
|
return fail("null explosive release mass pointer did not return -1");
|
|
}
|
|
if (sphlite_get_explosive_release_balance(explosive_release_mass_values,
|
|
NULL, explosive_release_momentum_values) != -1) {
|
|
return fail("null explosive release energy pointer did not return -1");
|
|
}
|
|
if (sphlite_get_explosive_release_balance(explosive_release_mass_values,
|
|
explosive_release_energy_values, NULL) != -1) {
|
|
return fail("null explosive release momentum pointer did not return -1");
|
|
}
|
|
if (sphlite_get_solid_summary(NULL, &solid_failed_count, solid_values,
|
|
SPHLITE_SOLID_SUMMARY_VALUE_COUNT) != -1) {
|
|
return fail("null Solid active-count pointer did not return -1");
|
|
}
|
|
if (sphlite_get_solid_summary(&solid_active_count, &solid_failed_count, NULL,
|
|
SPHLITE_SOLID_SUMMARY_VALUE_COUNT) != -1) {
|
|
return fail("null Solid summary values pointer did not return -1");
|
|
}
|
|
if (sphlite_get_solid_summary(&solid_active_count, &solid_failed_count,
|
|
solid_values, SPHLITE_SOLID_SUMMARY_VALUE_COUNT - 1) != -1) {
|
|
return fail("small Solid summary capacity did not return -1");
|
|
}
|
|
if (sphlite_get_solid_particle_state(4, NULL,
|
|
4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT, solid_failure_status,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count) != -1) {
|
|
return fail("null Solid state values did not return -1");
|
|
}
|
|
if (sphlite_get_solid_particle_state(4, solid_particle_values,
|
|
SPHLITE_SOLID_PARTICLE_VALUE_COUNT - 1, solid_failure_status,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count) != -1) {
|
|
return fail("small Solid state capacity did not return -1");
|
|
}
|
|
if (sphlite_get_solid_particle_state(4, solid_particle_values,
|
|
4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT, NULL,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count) != -1) {
|
|
return fail("null Solid failure status did not return -1");
|
|
}
|
|
if (sphlite_get_solid_diagnostics(NULL,
|
|
SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT) != -1) {
|
|
return fail("null Solid diagnostics did not return -1");
|
|
}
|
|
if (sphlite_get_solid_diagnostics(solid_diagnostics,
|
|
SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT - 1) != -1) {
|
|
return fail("small Solid diagnostics capacity did not return -1");
|
|
}
|
|
if (sphlite_get_solid_reference_quality(NULL, &solid_correction_status_max,
|
|
solid_reference_values, SPHLITE_SOLID_REFERENCE_VALUE_COUNT) != -1) {
|
|
return fail("null Solid reference min did not return -1");
|
|
}
|
|
if (sphlite_get_solid_reference_quality(&solid_reference_neighbor_min,
|
|
&solid_correction_status_max, solid_reference_values, 0) != -1) {
|
|
return fail("small Solid reference capacity 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");
|
|
}
|
|
if (sphlite_get_solid_summary(&solid_active_count, &solid_failed_count,
|
|
solid_values, SPHLITE_SOLID_SUMMARY_VALUE_COUNT) != 2) {
|
|
return fail("uninitialized Solid summary did not return Fortran state error");
|
|
}
|
|
if (sphlite_get_solid_particle_state(4, solid_particle_values,
|
|
4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT, solid_failure_status,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count) != 2) {
|
|
return fail("uninitialized Solid state did not return Fortran state error");
|
|
}
|
|
if (sphlite_get_solid_diagnostics(solid_diagnostics,
|
|
SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT) != 2) {
|
|
return fail("uninitialized Solid diagnostics did not return 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_solid_summary(&solid_active_count, &solid_failed_count,
|
|
solid_values, SPHLITE_SOLID_SUMMARY_VALUE_COUNT);
|
|
if (ierr != 2) return fail("unbuilt Solid summary did not return Fortran state error");
|
|
ierr = sphlite_get_solid_particle_state(4, solid_particle_values,
|
|
4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT, solid_failure_status,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count);
|
|
if (ierr != 2) return fail("unbuilt Solid state 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 != 8 || 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");
|
|
}
|
|
|
|
ierr = sphlite_get_solid_summary(&solid_active_count, &solid_failed_count,
|
|
solid_values, SPHLITE_SOLID_SUMMARY_VALUE_COUNT);
|
|
if (ierr != 0) return fail("Solid summary query failed");
|
|
if (solid_active_count != 4 || solid_failed_count != 0 ||
|
|
solid_values[0] <= 0.0) {
|
|
return fail("Solid summary content mismatch");
|
|
}
|
|
if (solid_values[13] <= 0.0 || solid_values[15] <= 0.0) {
|
|
return fail("Solid dt summary content mismatch");
|
|
}
|
|
ierr = sphlite_get_solid_particle_state(4, solid_particle_values,
|
|
4 * SPHLITE_SOLID_PARTICLE_VALUE_COUNT, solid_failure_status,
|
|
solid_reference_neighbor_count, solid_reference_degenerate,
|
|
solid_correction_status, &solid_state_count);
|
|
if (ierr != 0 || solid_state_count != 4) return fail("Solid state query failed");
|
|
if (solid_failure_status[0] != SPHLITE_STATUS_ACTIVE ||
|
|
solid_reference_neighbor_count[0] < 0 ||
|
|
solid_correction_status[0] < 0) {
|
|
return fail("Solid state content mismatch");
|
|
}
|
|
ierr = sphlite_get_solid_diagnostics(solid_diagnostics,
|
|
SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT);
|
|
if (ierr != 0) return fail("Solid diagnostics query failed");
|
|
if (solid_diagnostics[0] < 0.0 || solid_diagnostics[1] < 0.0 ||
|
|
solid_diagnostics[2] < 0.0) {
|
|
return fail("Solid diagnostics content mismatch");
|
|
}
|
|
ierr = sphlite_get_solid_reference_quality(&solid_reference_neighbor_min,
|
|
&solid_correction_status_max, solid_reference_values,
|
|
SPHLITE_SOLID_REFERENCE_VALUE_COUNT);
|
|
if (ierr != 0) return fail("Solid reference quality query failed");
|
|
if (solid_reference_neighbor_min < 0 || solid_correction_status_max < 0) {
|
|
return fail("Solid reference quality 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_get_gas_extended_summary(&gas_extended_mass, gas_momentum,
|
|
gas_density_range, gas_dt_limits);
|
|
if (ierr != 0) return fail("gas extended summary query failed");
|
|
if (gas_extended_mass <= 0.0 || gas_density_range[1] < gas_density_range[0]) {
|
|
return fail("gas extended summary content mismatch");
|
|
}
|
|
ierr = sphlite_get_gas_source_summary(&gas_source_mass, gas_source_momentum,
|
|
&gas_source_energy);
|
|
if (ierr != 0) return fail("gas source summary query failed");
|
|
if (gas_source_mass != 0.0 || gas_source_energy != 0.0) {
|
|
return fail("gas source summary default mismatch");
|
|
}
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("finalize gas failed");
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("initialize explosive failed");
|
|
snprintf(path, sizeof(path), "%s/explosive_conversion_phase_040.inp",
|
|
SPHLITE_TEST_DATA_DIR);
|
|
ierr = sphlite_read_inp(path);
|
|
if (ierr != 0) return fail("read explosive input failed");
|
|
ierr = sphlite_set_ignition_point(0.0, 0.0, 0.0, 0.0);
|
|
if (ierr != 0) return fail("set explosive ignition failed");
|
|
ierr = sphlite_build_model();
|
|
if (ierr != 0) return fail("build explosive model failed");
|
|
ierr = sphlite_run_explicit();
|
|
if (ierr != 0) return fail("run explosive model failed");
|
|
ierr = sphlite_get_explosive_summary(&explosive_particle_count,
|
|
&explosive_reacted_count, explosive_lambda_range,
|
|
explosive_released_totals, explosive_detonation_range);
|
|
if (ierr != 0) return fail("explosive summary query failed");
|
|
if (explosive_particle_count <= 0 || explosive_reacted_count <= 0) {
|
|
return fail("explosive summary count mismatch");
|
|
}
|
|
if (explosive_lambda_range[1] <= 0.0 || explosive_released_totals[1] <= 0.0) {
|
|
return fail("explosive summary content mismatch");
|
|
}
|
|
ierr = sphlite_get_explosive_release_balance(explosive_release_mass_values,
|
|
explosive_release_energy_values, explosive_release_momentum_values);
|
|
if (ierr != 0) return fail("explosive release balance query failed");
|
|
if (explosive_release_mass_values[0] <= 0.0 ||
|
|
explosive_release_mass_values[1] <= 0.0 ||
|
|
explosive_release_energy_values[0] <= 0.0) {
|
|
return fail("explosive release balance content mismatch");
|
|
}
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("finalize explosive failed");
|
|
return 0;
|
|
}
|