#include "sphlite_c_api.h" #include #include 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}; 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_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 != 4 || 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_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_finalize(); if (ierr != 0) return fail("finalize explosive failed"); return 0; }