Add coupling output restart and APIs

This commit is contained in:
Codex
2026-07-04 09:59:52 +08:00
parent 5be6b178bc
commit 5d9933d014
22 changed files with 2636 additions and 89 deletions
+133
View File
@@ -0,0 +1,133 @@
#include "sphlite_c_api.h"
#include <math.h>
#include <stdio.h>
static int fail(const char *message)
{
fprintf(stderr, "%s\n", message);
return 1;
}
int main(void)
{
char path[1024];
char name[128];
int ierr;
int region_count = 0;
int region_type = 0;
int export_mode = 0;
int import_mode = 0;
int enabled = 0;
int particle_count = 0;
int facet_count = 0;
int ext_ids[3] = {0, 0, 0};
int internal_indices[3] = {0, 0, 0};
int phases[3] = {0, 0, 0};
int statuses[3] = {0, 0, 0};
int materials[3] = {0, 0, 0};
int sections[3] = {0, 0, 0};
int facet_ids[3] = {0, 0, 0};
int facet_particles[3] = {0, 0, 0};
int indices[1] = {1};
int facets[1] = {1};
double particle_scalars[SPHLITE_COUPLING_PARTICLE_SCALAR_COUNT * 3] = {0.0};
double particle_vectors[3 * SPHLITE_COUPLING_PARTICLE_VECTOR_COUNT * 3] = {0.0};
double facet_vectors[3 * SPHLITE_COUPLING_FACET_VECTOR_COUNT * 3] = {0.0};
double facet_areas[3] = {0.0, 0.0, 0.0};
double forces[3] = {2.0, 0.0, 0.0};
double loads[3] = {0.0, 3.0, 0.0};
double target[3] = {0.0, 0.0, 1.0};
double diagnostics[SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT] = {0.0};
int counts[SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT] = {0};
if (sphlite_coupling_get_region_count(NULL) != -1) {
return fail("C coupling null region count did not return -1");
}
if (sphlite_coupling_get_region_info(1, NULL, (int)sizeof(name),
&region_type, &export_mode, &import_mode, &enabled, &particle_count,
&facet_count) != -1) {
return fail("C coupling null region name did not return -1");
}
if (sphlite_coupling_get_region_info(1, name, 1, &region_type,
&export_mode, &import_mode, &enabled, &particle_count,
&facet_count) != -1) {
return fail("C coupling small name capacity did not return -1");
}
if (sphlite_coupling_export_particles(1, 3, &particle_count, NULL,
internal_indices, phases, statuses, materials, sections,
particle_scalars, particle_vectors) != -1) {
return fail("C coupling null particle export buffer did not return -1");
}
if (sphlite_coupling_get_diagnostics(diagnostics,
SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT - 1, counts,
SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT) != -1) {
return fail("C coupling small diagnostics buffer did not return -1");
}
forces[0] = HUGE_VAL;
if (sphlite_coupling_apply_particle_forces(1, 1, indices, forces) != -1) {
return fail("C coupling nonfinite force did not return -1");
}
forces[0] = 2.0;
ierr = sphlite_initialize();
if (ierr != 0) return fail("C coupling initialize failed");
snprintf(path, sizeof(path), "%s/coupling_shell_region_080.inp",
SPHLITE_TEST_DATA_DIR);
ierr = sphlite_read_inp(path);
if (ierr != 0) return fail("C coupling read input failed");
ierr = sphlite_build_model();
if (ierr != 0) return fail("C coupling build model failed");
ierr = sphlite_coupling_get_region_count(&region_count);
if (ierr != 0 || region_count != 2) return fail("C coupling region count mismatch");
ierr = sphlite_coupling_get_region_info(2, name, (int)sizeof(name),
&region_type, &export_mode, &import_mode, &enabled, &particle_count,
&facet_count);
if (ierr != 0) return fail("C coupling region info failed");
if (export_mode != SPHLITE_COUPLING_EXPORT_BOTH ||
import_mode != SPHLITE_COUPLING_IMPORT_FORCE ||
enabled != 1 || particle_count != 3 || facet_count != 3) {
return fail("C coupling region info content mismatch");
}
ierr = sphlite_coupling_get_region_info(99, name, (int)sizeof(name),
&region_type, &export_mode, &import_mode, &enabled, &particle_count,
&facet_count);
if (ierr == 0) return fail("C coupling illegal region did not fail");
ierr = sphlite_coupling_export_particles(2, 3, &particle_count, ext_ids,
internal_indices, phases, statuses, materials, sections,
particle_scalars, particle_vectors);
if (ierr != 0 || particle_count != 3 || ext_ids[0] != 1) {
return fail("C coupling particle export mismatch");
}
ierr = sphlite_coupling_export_particles(2, 2, &particle_count, ext_ids,
internal_indices, phases, statuses, materials, sections,
particle_scalars, particle_vectors);
if (ierr == 0) return fail("C coupling small particle export did not fail");
ierr = sphlite_coupling_export_facets(1, 3, &facet_count, facet_ids,
facet_particles, materials, sections, facet_vectors, facet_areas);
if (ierr != 0 || facet_count != 3 || facet_ids[0] != 1 ||
facet_areas[0] <= 0.0) {
return fail("C coupling facet export mismatch");
}
ierr = sphlite_coupling_apply_particle_forces(2, 1, indices, forces);
if (ierr != 0) return fail("C coupling particle force import failed");
ierr = sphlite_coupling_apply_facet_loads(1, 1, facets, loads);
if (ierr != 0) return fail("C coupling facet load import failed");
ierr = sphlite_coupling_apply_motion_boundary(2, 2,
SPHLITE_COUPLING_MOTION_VELOCITY, SPHLITE_COUPLING_MOTION_DIRECT,
target);
if (ierr != 0) return fail("C coupling motion import failed");
ierr = sphlite_coupling_get_diagnostics(diagnostics,
SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT, counts,
SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT);
if (ierr != 0 || counts[3] != 2) return fail("C coupling diagnostics mismatch");
ierr = sphlite_coupling_clear_imports();
if (ierr != 0) return fail("C coupling clear imports failed");
ierr = sphlite_finalize();
if (ierr != 0) return fail("C coupling finalize failed");
return 0;
}